2 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * a) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
12 * b) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the distribution.
16 * c) Neither the name of Cisco Systems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <netinet/sctp_os.h>
38 #include <netinet/sctp_pcb.h>
39 #include <netinet/sctp_header.h>
40 #include <netinet/sctp_var.h>
42 #include <netinet6/sctp6_var.h>
44 #include <netinet/sctp_sysctl.h>
45 #include <netinet/sctp_output.h>
46 #include <netinet/sctp_uio.h>
47 #include <netinet/sctp_asconf.h>
48 #include <netinet/sctputil.h>
49 #include <netinet/sctp_indata.h>
50 #include <netinet/sctp_timer.h>
51 #include <netinet/sctp_auth.h>
52 #include <netinet/sctp_bsd_addr.h>
53 #include <netinet/udp.h>
57 extern struct sctp_cc_functions sctp_cc_functions[];
58 extern struct sctp_ss_functions sctp_ss_functions[];
65 /* Initialize and modify the sysctled variables */
67 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
68 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
70 * Allow a user to take no more than 1/2 the number of clusters or
71 * the SB_MAX whichever is smaller for the send window.
73 sb_max_adj = (u_long)((u_quad_t) (SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
74 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
75 (((uint32_t) nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
77 * Now for the recv window, should we take the same amount? or
78 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
79 * now I will just copy.
81 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
82 SCTP_BASE_VAR(first_time) = 0;
83 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
85 #if defined(SCTP_PACKET_LOGGING)
86 SCTP_BASE_VAR(packet_log_writers) = 0;
87 SCTP_BASE_VAR(packet_log_end) = 0;
88 bzero(&SCTP_BASE_VAR(packet_log_buffer), SCTP_PACKET_LOG_SIZE);
101 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
103 struct sctp_tmit_chunk *chk;
106 /* Adjust that too */
107 stcb->asoc.smallest_mtu = nxtsz;
108 /* now off to subtract IP_DF flag if needed */
109 overhead = IP_HDR_SIZE;
110 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
111 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
113 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
114 if ((chk->send_size + overhead) > nxtsz) {
115 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
118 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
119 if ((chk->send_size + overhead) > nxtsz) {
121 * For this guy we also mark for immediate resend
122 * since we sent to big of chunk
124 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
125 if (chk->sent < SCTP_DATAGRAM_RESEND) {
126 sctp_flight_size_decrease(chk);
127 sctp_total_flight_decrease(stcb, chk);
128 chk->sent = SCTP_DATAGRAM_RESEND;
129 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
130 chk->rec.data.doing_fast_retransmit = 0;
131 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
132 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
133 chk->whoTo->flight_size,
135 (uintptr_t) chk->whoTo,
136 chk->rec.data.TSN_seq);
138 /* Clear any time so NO RTT is being done */
147 sctp_notify_mbuf(struct sctp_inpcb *inp,
148 struct sctp_tcb *stcb,
149 struct sctp_nets *net,
154 int totsz, tmr_stopped = 0;
158 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
159 (ip == NULL) || (sh == NULL)) {
161 SCTP_TCB_UNLOCK(stcb);
165 /* First job is to verify the vtag matches what I would send */
166 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
167 SCTP_TCB_UNLOCK(stcb);
170 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
172 if (icmph->icmp_type != ICMP_UNREACH) {
173 /* We only care about unreachable */
174 SCTP_TCB_UNLOCK(stcb);
177 if (icmph->icmp_code != ICMP_UNREACH_NEEDFRAG) {
178 /* not a unreachable message due to frag. */
179 SCTP_TCB_UNLOCK(stcb);
182 totsz = ntohs(ip->ip_len);
184 nxtsz = ntohs(icmph->icmp_nextmtu);
187 * old type router that does not tell us what the next size
188 * mtu is. Rats we will have to guess (in a educated fashion
191 nxtsz = sctp_get_prev_mtu(totsz);
193 /* Stop any PMTU timer */
194 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
196 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
197 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
199 /* Adjust destination size limit */
200 if (net->mtu > nxtsz) {
203 net->mtu -= sizeof(struct udphdr);
206 /* now what about the ep? */
207 if (stcb->asoc.smallest_mtu > nxtsz) {
208 sctp_pathmtu_adjustment(stcb, nxtsz);
211 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
213 SCTP_TCB_UNLOCK(stcb);
217 sctp_notify(struct sctp_inpcb *inp,
221 struct sctp_tcb *stcb,
222 struct sctp_nets *net)
224 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
231 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
232 (sh == NULL) || (to == NULL)) {
234 SCTP_TCB_UNLOCK(stcb);
237 /* First job is to verify the vtag matches what I would send */
238 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
239 SCTP_TCB_UNLOCK(stcb);
242 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
244 if (icmph->icmp_type != ICMP_UNREACH) {
245 /* We only care about unreachable */
246 SCTP_TCB_UNLOCK(stcb);
249 if ((icmph->icmp_code == ICMP_UNREACH_NET) ||
250 (icmph->icmp_code == ICMP_UNREACH_HOST) ||
251 (icmph->icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
252 (icmph->icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
253 (icmph->icmp_code == ICMP_UNREACH_ISOLATED) ||
254 (icmph->icmp_code == ICMP_UNREACH_NET_PROHIB) ||
255 (icmph->icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
256 (icmph->icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
259 * Hmm reachablity problems we must examine closely. If its
260 * not reachable, we may have lost a network. Or if there is
261 * NO protocol at the other end named SCTP. well we consider
264 if (net->dest_state & SCTP_ADDR_REACHABLE) {
265 /* Ok that destination is NOT reachable */
266 net->dest_state &= ~SCTP_ADDR_REACHABLE;
267 net->dest_state &= ~SCTP_ADDR_PF;
268 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
270 (void *)net, SCTP_SO_NOT_LOCKED);
272 SCTP_TCB_UNLOCK(stcb);
273 } else if ((icmph->icmp_code == ICMP_UNREACH_PROTOCOL) ||
274 (icmph->icmp_code == ICMP_UNREACH_PORT)) {
276 * Here the peer is either playing tricks on us, including
277 * an address that belongs to someone who does not support
278 * SCTP OR was a userland implementation that shutdown and
279 * now is dead. In either case treat it like a OOTB abort
282 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
283 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
284 so = SCTP_INP_SO(inp);
285 atomic_add_int(&stcb->asoc.refcnt, 1);
286 SCTP_TCB_UNLOCK(stcb);
287 SCTP_SOCKET_LOCK(so, 1);
289 atomic_subtract_int(&stcb->asoc.refcnt, 1);
291 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
292 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
293 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
294 SCTP_SOCKET_UNLOCK(so, 1);
295 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
297 /* no need to unlock here, since the TCB is gone */
299 SCTP_TCB_UNLOCK(stcb);
307 sctp_ctlinput(cmd, sa, vip)
316 /* FIX, for non-bsd is this right? */
317 vrf_id = SCTP_DEFAULT_VRFID;
318 if (sa->sa_family != AF_INET ||
319 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
322 if (PRC_IS_REDIRECT(cmd)) {
324 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
328 struct sctp_inpcb *inp = NULL;
329 struct sctp_tcb *stcb = NULL;
330 struct sctp_nets *net = NULL;
331 struct sockaddr_in to, from;
333 sh = (struct sctphdr *)((caddr_t)ip + (ip->ip_hl << 2));
334 bzero(&to, sizeof(to));
335 bzero(&from, sizeof(from));
336 from.sin_family = to.sin_family = AF_INET;
337 from.sin_len = to.sin_len = sizeof(to);
338 from.sin_port = sh->src_port;
339 from.sin_addr = ip->ip_src;
340 to.sin_port = sh->dest_port;
341 to.sin_addr = ip->ip_dst;
344 * 'to' holds the dest of the packet that failed to be sent.
345 * 'from' holds our local endpoint address. Thus we reverse
346 * the to and the from in the lookup.
348 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&to,
349 (struct sockaddr *)&from,
350 &inp, &net, 1, vrf_id);
351 if (stcb != NULL && inp && (inp->sctp_socket != NULL)) {
352 if (cmd != PRC_MSGSIZE) {
353 sctp_notify(inp, ip, sh,
354 (struct sockaddr *)&to, stcb,
357 /* handle possible ICMP size messages */
358 sctp_notify_mbuf(inp, stcb, net, ip, sh);
361 if ((stcb == NULL) && (inp != NULL)) {
362 /* reduce ref-count */
364 SCTP_INP_DECR_REF(inp);
365 SCTP_INP_WUNLOCK(inp);
368 SCTP_TCB_UNLOCK(stcb);
378 sctp_getcred(SYSCTL_HANDLER_ARGS)
381 struct sockaddr_in addrs[2];
382 struct sctp_inpcb *inp;
383 struct sctp_nets *net;
384 struct sctp_tcb *stcb;
388 /* FIX, for non-bsd is this right? */
389 vrf_id = SCTP_DEFAULT_VRFID;
391 error = priv_check(req->td, PRIV_NETINET_GETCRED);
396 error = SYSCTL_IN(req, addrs, sizeof(addrs));
400 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
402 &inp, &net, 1, vrf_id);
403 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
404 if ((inp != NULL) && (stcb == NULL)) {
405 /* reduce ref-count */
407 SCTP_INP_DECR_REF(inp);
410 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
414 SCTP_TCB_UNLOCK(stcb);
416 * We use the write lock here, only since in the error leg we need
417 * it. If we used RLOCK, then we would have to
418 * wlock/decr/unlock/rlock. Which in theory could create a hole.
419 * Better to use higher wlock.
423 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
425 SCTP_INP_WUNLOCK(inp);
428 cru2x(inp->sctp_socket->so_cred, &xuc);
429 SCTP_INP_WUNLOCK(inp);
430 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
435 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
436 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
441 sctp_abort(struct socket *so)
443 struct sctp_inpcb *inp;
446 inp = (struct sctp_inpcb *)so->so_pcb;
451 flags = inp->sctp_flags;
452 #ifdef SCTP_LOG_CLOSING
453 sctp_log_closing(inp, NULL, 17);
455 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
456 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
457 #ifdef SCTP_LOG_CLOSING
458 sctp_log_closing(inp, NULL, 16);
460 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
461 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
463 SCTP_SB_CLEAR(so->so_snd);
465 * same for the rcv ones, they are only here for the
468 SCTP_SB_CLEAR(so->so_rcv);
470 /* Now null out the reference, we are completely detached. */
474 flags = inp->sctp_flags;
475 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
476 goto sctp_must_try_again;
483 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
485 struct sctp_inpcb *inp;
486 struct inpcb *ip_inp;
488 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
490 inp = (struct sctp_inpcb *)so->so_pcb;
492 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
495 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
496 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
501 error = sctp_inpcb_alloc(so, vrf_id);
505 inp = (struct sctp_inpcb *)so->so_pcb;
507 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
508 ip_inp = &inp->ip_inp.inp;
509 ip_inp->inp_vflag |= INP_IPV4;
510 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
511 SCTP_INP_WUNLOCK(inp);
516 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
518 struct sctp_inpcb *inp;
520 inp = (struct sctp_inpcb *)so->so_pcb;
522 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
526 if ((addr->sa_family != AF_INET) ||
527 (addr->sa_len != sizeof(struct sockaddr_in))) {
528 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
532 return (sctp_inpcb_bind(so, addr, NULL, p));
537 sctp_close(struct socket *so)
539 struct sctp_inpcb *inp;
542 inp = (struct sctp_inpcb *)so->so_pcb;
547 * Inform all the lower layer assoc that we are done.
550 flags = inp->sctp_flags;
551 #ifdef SCTP_LOG_CLOSING
552 sctp_log_closing(inp, NULL, 17);
554 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
555 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
556 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
557 (so->so_rcv.sb_cc > 0)) {
558 #ifdef SCTP_LOG_CLOSING
559 sctp_log_closing(inp, NULL, 13);
561 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
562 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
564 #ifdef SCTP_LOG_CLOSING
565 sctp_log_closing(inp, NULL, 14);
567 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
568 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
571 * The socket is now detached, no matter what the state of
572 * the SCTP association.
575 SCTP_SB_CLEAR(so->so_snd);
577 * same for the rcv ones, they are only here for the
580 SCTP_SB_CLEAR(so->so_rcv);
582 /* Now null out the reference, we are completely detached. */
586 flags = inp->sctp_flags;
587 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
588 goto sctp_must_try_again;
596 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
597 struct mbuf *control, struct thread *p);
601 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
602 struct mbuf *control, struct thread *p)
604 struct sctp_inpcb *inp;
607 inp = (struct sctp_inpcb *)so->so_pcb;
610 sctp_m_freem(control);
613 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
617 /* Got to have an to address if we are NOT a connected socket */
618 if ((addr == NULL) &&
619 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
620 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
622 } else if (addr == NULL) {
623 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
624 error = EDESTADDRREQ;
627 sctp_m_freem(control);
633 if (addr->sa_family != AF_INET) {
634 /* must be a v4 address! */
635 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
638 sctp_m_freem(control);
641 error = EDESTADDRREQ;
646 /* now what about control */
649 SCTP_PRINTF("huh? control set?\n");
650 sctp_m_freem(inp->control);
653 inp->control = control;
657 SCTP_BUF_NEXT(inp->pkt_last) = m;
660 inp->pkt_last = inp->pkt = m;
663 /* FreeBSD uses a flag passed */
664 ((flags & PRUS_MORETOCOME) == 0)
667 * note with the current version this code will only be used
668 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
669 * re-defining sosend to use the sctp_sosend. One can
670 * optionally switch back to this code (by changing back the
671 * definitions) but this is not advisable. This code is used
672 * by FreeBSD when sending a file with sendfile() though.
676 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
686 sctp_disconnect(struct socket *so)
688 struct sctp_inpcb *inp;
690 inp = (struct sctp_inpcb *)so->so_pcb;
692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
696 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
697 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
698 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
700 SCTP_INP_RUNLOCK(inp);
703 struct sctp_association *asoc;
704 struct sctp_tcb *stcb;
706 stcb = LIST_FIRST(&inp->sctp_asoc_list);
708 SCTP_INP_RUNLOCK(inp);
709 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
714 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
715 /* We are about to be freed, out of here */
716 SCTP_TCB_UNLOCK(stcb);
717 SCTP_INP_RUNLOCK(inp);
720 if (((so->so_options & SO_LINGER) &&
721 (so->so_linger == 0)) ||
722 (so->so_rcv.sb_cc > 0)) {
723 if (SCTP_GET_STATE(asoc) !=
724 SCTP_STATE_COOKIE_WAIT) {
725 /* Left with Data unread */
728 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_NOWAIT, 1, MT_DATA);
734 struct sctp_paramhdr *ph;
736 ph = mtod(err, struct sctp_paramhdr *);
737 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
738 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
739 ph->param_length = htons(SCTP_BUF_LEN(err));
741 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
742 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
744 SCTP_INP_RUNLOCK(inp);
745 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
746 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
747 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
749 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
750 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
751 /* No unlock tcb assoc is gone */
754 if (TAILQ_EMPTY(&asoc->send_queue) &&
755 TAILQ_EMPTY(&asoc->sent_queue) &&
756 (asoc->stream_queue_cnt == 0)) {
757 /* there is nothing queued to send, so done */
758 if (asoc->locked_on_sending) {
761 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
762 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
763 /* only send SHUTDOWN 1st time thru */
764 struct sctp_nets *netp;
766 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
767 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
768 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
770 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
771 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
772 sctp_stop_timers_for_shutdown(stcb);
773 if (stcb->asoc.alternate) {
774 netp = stcb->asoc.alternate;
776 netp = stcb->asoc.primary_destination;
778 sctp_send_shutdown(stcb, netp);
779 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
780 stcb->sctp_ep, stcb, netp);
781 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
782 stcb->sctp_ep, stcb, netp);
783 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
787 * we still got (or just got) data to send,
788 * so set SHUTDOWN_PENDING
791 * XXX sockets draft says that SCTP_EOF
792 * should be sent with no data. currently,
793 * we will allow user data to be sent first
794 * and move to SHUTDOWN-PENDING
796 struct sctp_nets *netp;
798 if (stcb->asoc.alternate) {
799 netp = stcb->asoc.alternate;
801 netp = stcb->asoc.primary_destination;
804 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
805 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
807 if (asoc->locked_on_sending) {
808 /* Locked to send out the data */
809 struct sctp_stream_queue_pending *sp;
811 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
813 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
814 asoc->locked_on_sending->stream_no);
816 if ((sp->length == 0) && (sp->msg_is_complete == 0))
817 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
820 if (TAILQ_EMPTY(&asoc->send_queue) &&
821 TAILQ_EMPTY(&asoc->sent_queue) &&
822 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
826 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
827 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
828 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
829 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
830 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
831 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
832 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
834 SCTP_INP_RUNLOCK(inp);
835 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
836 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
839 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
842 soisdisconnecting(so);
843 SCTP_TCB_UNLOCK(stcb);
844 SCTP_INP_RUNLOCK(inp);
849 /* UDP model does not support this */
850 SCTP_INP_RUNLOCK(inp);
851 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
857 sctp_flush(struct socket *so, int how)
860 * We will just clear out the values and let subsequent close clear
861 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
862 * they will not be able to read the data, the socket will block
863 * that from happening.
865 struct sctp_inpcb *inp;
867 inp = (struct sctp_inpcb *)so->so_pcb;
869 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
873 /* For the 1 to many model this does nothing */
874 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
875 SCTP_INP_RUNLOCK(inp);
878 SCTP_INP_RUNLOCK(inp);
879 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
881 * First make sure the sb will be happy, we don't use these
882 * except maybe the count
885 SCTP_INP_READ_LOCK(inp);
886 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
887 SCTP_INP_READ_UNLOCK(inp);
888 SCTP_INP_WUNLOCK(inp);
889 so->so_rcv.sb_cc = 0;
890 so->so_rcv.sb_mbcnt = 0;
891 so->so_rcv.sb_mb = NULL;
893 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
895 * First make sure the sb will be happy, we don't use these
896 * except maybe the count
898 so->so_snd.sb_cc = 0;
899 so->so_snd.sb_mbcnt = 0;
900 so->so_snd.sb_mb = NULL;
907 sctp_shutdown(struct socket *so)
909 struct sctp_inpcb *inp;
911 inp = (struct sctp_inpcb *)so->so_pcb;
913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
917 /* For UDP model this is a invalid call */
918 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
919 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
920 /* Restore the flags that the soshutdown took away. */
921 SOCKBUF_LOCK(&so->so_rcv);
922 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
923 SOCKBUF_UNLOCK(&so->so_rcv);
924 /* This proc will wakeup for read and do nothing (I hope) */
925 SCTP_INP_RUNLOCK(inp);
926 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
930 * Ok, if we reach here its the TCP model and it is either a
931 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
934 struct sctp_tcb *stcb;
935 struct sctp_association *asoc;
936 struct sctp_nets *netp;
939 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
940 SCTP_INP_RUNLOCK(inp);
945 stcb = LIST_FIRST(&inp->sctp_asoc_list);
948 * Ok, we hit the case that the shutdown call was
949 * made after an abort or something. Nothing to do
952 SCTP_INP_RUNLOCK(inp);
957 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
958 SCTP_TCB_UNLOCK(stcb);
959 SCTP_INP_RUNLOCK(inp);
962 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_WAIT) &&
963 (SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_ECHOED) &&
964 (SCTP_GET_STATE(asoc) != SCTP_STATE_OPEN)) {
966 * If we are not in or before ESTABLISHED, there is
967 * no protocol action required.
969 SCTP_TCB_UNLOCK(stcb);
970 SCTP_INP_RUNLOCK(inp);
973 if (stcb->asoc.alternate) {
974 netp = stcb->asoc.alternate;
976 netp = stcb->asoc.primary_destination;
978 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) &&
979 TAILQ_EMPTY(&asoc->send_queue) &&
980 TAILQ_EMPTY(&asoc->sent_queue) &&
981 (asoc->stream_queue_cnt == 0)) {
982 if (asoc->locked_on_sending) {
985 /* there is nothing queued to send, so I'm done... */
986 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
987 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
988 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
989 sctp_stop_timers_for_shutdown(stcb);
990 sctp_send_shutdown(stcb, netp);
991 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
992 stcb->sctp_ep, stcb, netp);
995 * We still got (or just got) data to send, so set
998 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
999 if (asoc->locked_on_sending) {
1000 /* Locked to send out the data */
1001 struct sctp_stream_queue_pending *sp;
1003 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
1005 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
1006 asoc->locked_on_sending->stream_no);
1008 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
1009 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_PARTIAL_MSG_LEFT);
1013 if (TAILQ_EMPTY(&asoc->send_queue) &&
1014 TAILQ_EMPTY(&asoc->sent_queue) &&
1015 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1016 struct mbuf *op_err;
1019 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
1020 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
1021 sctp_abort_an_association(stcb->sctp_ep, stcb,
1022 op_err, SCTP_SO_LOCKED);
1023 SCTP_INP_RUNLOCK(inp);
1027 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, netp);
1029 * XXX: Why do this in the case where we have still data
1032 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1033 SCTP_TCB_UNLOCK(stcb);
1034 SCTP_INP_RUNLOCK(inp);
1040 * copies a "user" presentable address and removes embedded scope, etc.
1041 * returns 0 on success, 1 on error
1044 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1047 struct sockaddr_in6 lsa6;
1049 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1052 memcpy(ss, sa, sa->sa_len);
1059 * NOTE: assumes addr lock is held
1062 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1063 struct sctp_tcb *stcb,
1065 struct sockaddr_storage *sas,
1068 struct sctp_ifn *sctp_ifn;
1069 struct sctp_ifa *sctp_ifa;
1074 int ipv4_local_scope, ipv4_addr_legal;
1078 int local_scope, site_scope, ipv6_addr_legal;
1081 struct sctp_vrf *vrf;
1088 /* Turn on all the appropriate scope */
1089 loopback_scope = stcb->asoc.scope.loopback_scope;
1091 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1092 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1095 local_scope = stcb->asoc.scope.local_scope;
1096 site_scope = stcb->asoc.scope.site_scope;
1097 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1100 /* Use generic values for endpoints. */
1103 ipv4_local_scope = 1;
1109 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1111 ipv6_addr_legal = 1;
1114 if (SCTP_IPV6_V6ONLY(inp)) {
1115 ipv4_addr_legal = 0;
1117 ipv4_addr_legal = 1;
1122 ipv6_addr_legal = 0;
1125 ipv4_addr_legal = 1;
1129 vrf = sctp_find_vrf(vrf_id);
1133 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1134 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1135 if ((loopback_scope == 0) &&
1136 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1137 /* Skip loopback if loopback_scope not set */
1140 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1143 * For the BOUND-ALL case, the list
1144 * associated with a TCB is Always
1145 * considered a reverse list.. i.e.
1146 * it lists addresses that are NOT
1147 * part of the association. If this
1148 * is one of those we must skip it.
1150 if (sctp_is_addr_restricted(stcb,
1155 switch (sctp_ifa->address.sa.sa_family) {
1158 if (ipv4_addr_legal) {
1159 struct sockaddr_in *sin;
1161 sin = &sctp_ifa->address.sin;
1162 if (sin->sin_addr.s_addr == 0) {
1170 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1171 &sin->sin_addr) != 0) {
1174 if ((ipv4_local_scope == 0) &&
1175 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1179 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1180 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1181 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1182 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1183 actual += sizeof(struct sockaddr_in6);
1186 memcpy(sas, sin, sizeof(*sin));
1187 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1188 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1189 actual += sizeof(*sin);
1193 if (actual >= limit) {
1203 if (ipv6_addr_legal) {
1204 struct sockaddr_in6 *sin6;
1206 sin6 = &sctp_ifa->address.sin6;
1207 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1215 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1216 &sin6->sin6_addr) != 0) {
1219 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1220 if (local_scope == 0)
1222 if (sin6->sin6_scope_id == 0) {
1223 if (sa6_recoverscope(sin6) != 0)
1241 if ((site_scope == 0) &&
1242 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1245 memcpy(sas, sin6, sizeof(*sin6));
1246 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1247 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1248 actual += sizeof(*sin6);
1249 if (actual >= limit) {
1264 struct sctp_laddr *laddr;
1266 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1268 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1272 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1274 switch (laddr->ifa->address.sa.sa_family) {
1277 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1282 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1289 sas = (struct sockaddr_storage *)((caddr_t)sas +
1290 laddr->ifa->address.sa.sa_len);
1291 actual += laddr->ifa->address.sa.sa_len;
1292 if (actual >= limit) {
1301 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1302 struct sctp_tcb *stcb,
1304 struct sockaddr_storage *sas)
1308 SCTP_IPI_ADDR_RLOCK();
1309 /* fill up addresses for the endpoint's default vrf */
1310 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1312 SCTP_IPI_ADDR_RUNLOCK();
1317 * NOTE: assumes addr lock is held
1320 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1323 struct sctp_vrf *vrf = NULL;
1326 * In both sub-set bound an bound_all cases we return the MAXIMUM
1327 * number of addresses that you COULD get. In reality the sub-set
1328 * bound may have an exclusion list for a given TCB OR in the
1329 * bound-all case a TCB may NOT include the loopback or other
1330 * addresses as well.
1332 vrf = sctp_find_vrf(vrf_id);
1336 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1337 struct sctp_ifn *sctp_ifn;
1338 struct sctp_ifa *sctp_ifa;
1340 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1341 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1342 /* Count them if they are the right type */
1343 switch (sctp_ifa->address.sa.sa_family) {
1347 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1348 cnt += sizeof(struct sockaddr_in6);
1350 cnt += sizeof(struct sockaddr_in);
1352 cnt += sizeof(struct sockaddr_in);
1358 cnt += sizeof(struct sockaddr_in6);
1367 struct sctp_laddr *laddr;
1369 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1370 switch (laddr->ifa->address.sa.sa_family) {
1374 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1375 cnt += sizeof(struct sockaddr_in6);
1377 cnt += sizeof(struct sockaddr_in);
1379 cnt += sizeof(struct sockaddr_in);
1385 cnt += sizeof(struct sockaddr_in6);
1397 sctp_count_max_addresses(struct sctp_inpcb *inp)
1401 SCTP_IPI_ADDR_RLOCK();
1402 /* count addresses for the endpoint's default VRF */
1403 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1404 SCTP_IPI_ADDR_RUNLOCK();
1409 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1410 size_t optsize, void *p, int delay)
1413 int creat_lock_on = 0;
1414 struct sctp_tcb *stcb = NULL;
1415 struct sockaddr *sa;
1416 int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1418 int bad_addresses = 0;
1421 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1423 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1424 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1425 /* We are already connected AND the TCP model */
1426 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1427 return (EADDRINUSE);
1429 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1430 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1431 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1434 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1435 SCTP_INP_RLOCK(inp);
1436 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1437 SCTP_INP_RUNLOCK(inp);
1440 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1443 SCTP_INP_INCR_REF(inp);
1444 SCTP_ASOC_CREATE_LOCK(inp);
1446 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1447 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1448 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1452 totaddrp = (int *)optval;
1453 totaddr = *totaddrp;
1454 sa = (struct sockaddr *)(totaddrp + 1);
1455 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (optsize - sizeof(int)), &bad_addresses);
1456 if ((stcb != NULL) || bad_addresses) {
1457 /* Already have or am bring up an association */
1458 SCTP_ASOC_CREATE_UNLOCK(inp);
1461 SCTP_TCB_UNLOCK(stcb);
1462 if (bad_addresses == 0) {
1463 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1469 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1474 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1476 struct in6pcb *inp6;
1478 inp6 = (struct in6pcb *)inp;
1479 if (SCTP_IPV6_V6ONLY(inp6)) {
1481 * if IPV6_V6ONLY flag, ignore connections destined
1482 * to a v4 addr or v4-mapped addr
1484 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1490 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1491 SCTP_PCB_FLAGS_UNBOUND) {
1492 /* Bind a ephemeral port */
1493 error = sctp_inpcb_bind(so, NULL, NULL, p);
1498 /* FIX ME: do we want to pass in a vrf on the connect call? */
1499 vrf_id = inp->def_vrf_id;
1502 /* We are GOOD to go */
1503 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1504 inp->sctp_ep.pre_open_stream_count,
1508 /* Gak! no memory */
1511 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1512 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1513 /* Set the connected flag so we can queue data */
1516 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1517 /* move to second address */
1518 switch (sa->sa_family) {
1521 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1526 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1534 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1535 /* Fill in the return id */
1537 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE,
1538 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
1541 a_id = (sctp_assoc_t *) optval;
1542 *a_id = sctp_get_associd(stcb);
1544 /* initialize authentication parameters for the assoc */
1545 sctp_initialize_auth_params(inp, stcb);
1548 /* doing delayed connection */
1549 stcb->asoc.delayed_connection = 1;
1550 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1552 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1553 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1555 SCTP_TCB_UNLOCK(stcb);
1556 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1557 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1558 /* Set the connected flag so we can queue data */
1562 if (creat_lock_on) {
1563 SCTP_ASOC_CREATE_UNLOCK(inp);
1565 SCTP_INP_DECR_REF(inp);
1569 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1570 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1571 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1572 SCTP_INP_RLOCK(inp); \
1573 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1575 SCTP_TCB_LOCK(stcb); \
1577 SCTP_INP_RUNLOCK(inp); \
1578 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1579 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1580 if (stcb == NULL) { \
1581 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1591 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1592 if (size < sizeof(type)) { \
1593 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1597 destp = (type *)srcp; \
1602 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1605 struct sctp_inpcb *inp = NULL;
1607 struct sctp_tcb *stcb = NULL;
1609 if (optval == NULL) {
1610 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1613 inp = (struct sctp_inpcb *)so->so_pcb;
1615 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1622 case SCTP_AUTOCLOSE:
1623 case SCTP_EXPLICIT_EOR:
1624 case SCTP_AUTO_ASCONF:
1625 case SCTP_DISABLE_FRAGMENTS:
1626 case SCTP_I_WANT_MAPPED_V4_ADDR:
1627 case SCTP_USE_EXT_RCVINFO:
1628 SCTP_INP_RLOCK(inp);
1630 case SCTP_DISABLE_FRAGMENTS:
1631 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1633 case SCTP_I_WANT_MAPPED_V4_ADDR:
1634 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1636 case SCTP_AUTO_ASCONF:
1637 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1638 /* only valid for bound all sockets */
1639 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1641 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1646 case SCTP_EXPLICIT_EOR:
1647 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1650 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1652 case SCTP_USE_EXT_RCVINFO:
1653 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1655 case SCTP_AUTOCLOSE:
1656 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1657 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1663 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1664 error = ENOPROTOOPT;
1665 } /* end switch (sopt->sopt_name) */
1666 if (*optsize < sizeof(val)) {
1667 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1671 SCTP_INP_RUNLOCK(inp);
1673 /* return the option value */
1674 *(int *)optval = val;
1675 *optsize = sizeof(val);
1678 case SCTP_GET_PACKET_LOG:
1680 #ifdef SCTP_PACKET_LOGGING
1684 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1685 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1688 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1693 case SCTP_REUSE_PORT:
1697 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1698 /* Can't do this for a 1-m socket */
1702 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1703 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1704 *optsize = sizeof(uint32_t);
1707 case SCTP_PARTIAL_DELIVERY_POINT:
1711 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1712 *value = inp->partial_delivery_point;
1713 *optsize = sizeof(uint32_t);
1716 case SCTP_FRAGMENT_INTERLEAVE:
1720 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1721 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1722 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1723 *value = SCTP_FRAG_LEVEL_2;
1725 *value = SCTP_FRAG_LEVEL_1;
1728 *value = SCTP_FRAG_LEVEL_0;
1730 *optsize = sizeof(uint32_t);
1733 case SCTP_CMT_ON_OFF:
1735 struct sctp_assoc_value *av;
1737 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1738 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1740 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1741 SCTP_TCB_UNLOCK(stcb);
1743 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1744 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1745 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1746 SCTP_INP_RLOCK(inp);
1747 av->assoc_value = inp->sctp_cmt_on_off;
1748 SCTP_INP_RUNLOCK(inp);
1750 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1755 *optsize = sizeof(struct sctp_assoc_value);
1759 case SCTP_PLUGGABLE_CC:
1761 struct sctp_assoc_value *av;
1763 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1764 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1766 av->assoc_value = stcb->asoc.congestion_control_module;
1767 SCTP_TCB_UNLOCK(stcb);
1769 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1770 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1771 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1772 SCTP_INP_RLOCK(inp);
1773 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1774 SCTP_INP_RUNLOCK(inp);
1776 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1781 *optsize = sizeof(struct sctp_assoc_value);
1785 case SCTP_CC_OPTION:
1787 struct sctp_cc_option *cc_opt;
1789 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1790 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1794 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1797 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1798 *optsize = sizeof(struct sctp_cc_option);
1800 SCTP_TCB_UNLOCK(stcb);
1804 case SCTP_PLUGGABLE_SS:
1806 struct sctp_assoc_value *av;
1808 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1809 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1811 av->assoc_value = stcb->asoc.stream_scheduling_module;
1812 SCTP_TCB_UNLOCK(stcb);
1814 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1815 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1816 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1817 SCTP_INP_RLOCK(inp);
1818 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1819 SCTP_INP_RUNLOCK(inp);
1821 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1826 *optsize = sizeof(struct sctp_assoc_value);
1832 struct sctp_stream_value *av;
1834 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1835 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1837 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1838 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1839 &av->stream_value) < 0)) {
1840 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1843 *optsize = sizeof(struct sctp_stream_value);
1845 SCTP_TCB_UNLOCK(stcb);
1848 * Can't get stream value without
1851 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1856 case SCTP_GET_ADDR_LEN:
1858 struct sctp_assoc_value *av;
1860 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1863 if (av->assoc_value == AF_INET) {
1864 av->assoc_value = sizeof(struct sockaddr_in);
1869 if (av->assoc_value == AF_INET6) {
1870 av->assoc_value = sizeof(struct sockaddr_in6);
1875 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1877 *optsize = sizeof(struct sctp_assoc_value);
1881 case SCTP_GET_ASSOC_NUMBER:
1883 uint32_t *value, cnt;
1885 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1886 SCTP_INP_RLOCK(inp);
1887 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1888 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1889 /* Can't do this for a 1-1 socket */
1891 SCTP_INP_RUNLOCK(inp);
1895 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1898 SCTP_INP_RUNLOCK(inp);
1900 *optsize = sizeof(uint32_t);
1903 case SCTP_GET_ASSOC_ID_LIST:
1905 struct sctp_assoc_ids *ids;
1906 unsigned int at, limit;
1908 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1909 SCTP_INP_RLOCK(inp);
1910 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1911 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1912 /* Can't do this for a 1-1 socket */
1914 SCTP_INP_RUNLOCK(inp);
1918 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1919 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1921 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1924 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1928 SCTP_INP_RUNLOCK(inp);
1930 ids->gaids_number_of_ids = at;
1931 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1937 struct sctp_assoc_value *av;
1939 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1940 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1943 av->assoc_value = stcb->asoc.context;
1944 SCTP_TCB_UNLOCK(stcb);
1946 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1947 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1948 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1949 SCTP_INP_RLOCK(inp);
1950 av->assoc_value = inp->sctp_context;
1951 SCTP_INP_RUNLOCK(inp);
1953 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1958 *optsize = sizeof(struct sctp_assoc_value);
1964 uint32_t *default_vrfid;
1966 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1967 *default_vrfid = inp->def_vrf_id;
1968 *optsize = sizeof(uint32_t);
1971 case SCTP_GET_ASOC_VRF:
1973 struct sctp_assoc_value *id;
1975 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1976 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1979 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1981 id->assoc_value = stcb->asoc.vrf_id;
1982 *optsize = sizeof(struct sctp_assoc_value);
1986 case SCTP_GET_VRF_IDS:
1988 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1992 case SCTP_GET_NONCE_VALUES:
1994 struct sctp_get_nonce_values *gnv;
1996 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1997 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
2000 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
2001 gnv->gn_local_tag = stcb->asoc.my_vtag;
2002 SCTP_TCB_UNLOCK(stcb);
2003 *optsize = sizeof(struct sctp_get_nonce_values);
2005 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2010 case SCTP_DELAYED_SACK:
2012 struct sctp_sack_info *sack;
2014 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2015 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2017 sack->sack_delay = stcb->asoc.delayed_ack;
2018 sack->sack_freq = stcb->asoc.sack_freq;
2019 SCTP_TCB_UNLOCK(stcb);
2021 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2022 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2023 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2024 SCTP_INP_RLOCK(inp);
2025 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2026 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2027 SCTP_INP_RUNLOCK(inp);
2029 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2034 *optsize = sizeof(struct sctp_sack_info);
2038 case SCTP_GET_SNDBUF_USE:
2040 struct sctp_sockstat *ss;
2042 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2043 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2046 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2047 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2048 stcb->asoc.size_on_all_streams);
2049 SCTP_TCB_UNLOCK(stcb);
2050 *optsize = sizeof(struct sctp_sockstat);
2052 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2057 case SCTP_MAX_BURST:
2059 struct sctp_assoc_value *av;
2061 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2062 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2065 av->assoc_value = stcb->asoc.max_burst;
2066 SCTP_TCB_UNLOCK(stcb);
2068 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2069 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2070 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2071 SCTP_INP_RLOCK(inp);
2072 av->assoc_value = inp->sctp_ep.max_burst;
2073 SCTP_INP_RUNLOCK(inp);
2075 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2080 *optsize = sizeof(struct sctp_assoc_value);
2086 struct sctp_assoc_value *av;
2089 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2090 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2093 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2094 SCTP_TCB_UNLOCK(stcb);
2096 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2097 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2098 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2099 SCTP_INP_RLOCK(inp);
2100 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2101 ovh = SCTP_MED_OVERHEAD;
2103 ovh = SCTP_MED_V4_OVERHEAD;
2105 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2106 av->assoc_value = 0;
2108 av->assoc_value = inp->sctp_frag_point - ovh;
2109 SCTP_INP_RUNLOCK(inp);
2111 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2116 *optsize = sizeof(struct sctp_assoc_value);
2120 case SCTP_GET_STAT_LOG:
2121 error = sctp_fill_stat_log(optval, optsize);
2125 struct sctp_event_subscribe *events;
2127 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2128 memset(events, 0, sizeof(struct sctp_event_subscribe));
2129 SCTP_INP_RLOCK(inp);
2130 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2131 events->sctp_data_io_event = 1;
2133 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2134 events->sctp_association_event = 1;
2136 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2137 events->sctp_address_event = 1;
2139 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2140 events->sctp_send_failure_event = 1;
2142 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2143 events->sctp_peer_error_event = 1;
2145 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2146 events->sctp_shutdown_event = 1;
2148 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2149 events->sctp_partial_delivery_event = 1;
2151 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2152 events->sctp_adaptation_layer_event = 1;
2154 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2155 events->sctp_authentication_event = 1;
2157 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2158 events->sctp_sender_dry_event = 1;
2160 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2161 events->sctp_stream_reset_event = 1;
2162 SCTP_INP_RUNLOCK(inp);
2163 *optsize = sizeof(struct sctp_event_subscribe);
2166 case SCTP_ADAPTATION_LAYER:
2170 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2172 SCTP_INP_RLOCK(inp);
2173 *value = inp->sctp_ep.adaptation_layer_indicator;
2174 SCTP_INP_RUNLOCK(inp);
2175 *optsize = sizeof(uint32_t);
2178 case SCTP_SET_INITIAL_DBG_SEQ:
2182 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2183 SCTP_INP_RLOCK(inp);
2184 *value = inp->sctp_ep.initial_sequence_debug;
2185 SCTP_INP_RUNLOCK(inp);
2186 *optsize = sizeof(uint32_t);
2189 case SCTP_GET_LOCAL_ADDR_SIZE:
2193 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2194 SCTP_INP_RLOCK(inp);
2195 *value = sctp_count_max_addresses(inp);
2196 SCTP_INP_RUNLOCK(inp);
2197 *optsize = sizeof(uint32_t);
2200 case SCTP_GET_REMOTE_ADDR_SIZE:
2204 struct sctp_nets *net;
2206 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2207 /* FIXME MT: change to sctp_assoc_value? */
2208 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2212 /* Count the sizes */
2213 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2214 switch (net->ro._l_addr.sa.sa_family) {
2218 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2219 size += sizeof(struct sockaddr_in6);
2221 size += sizeof(struct sockaddr_in);
2224 size += sizeof(struct sockaddr_in);
2230 size += sizeof(struct sockaddr_in6);
2237 SCTP_TCB_UNLOCK(stcb);
2238 *value = (uint32_t) size;
2239 *optsize = sizeof(uint32_t);
2241 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2246 case SCTP_GET_PEER_ADDRESSES:
2248 * Get the address information, an array is passed in to
2249 * fill up we pack it.
2253 struct sockaddr_storage *sas;
2254 struct sctp_nets *net;
2255 struct sctp_getaddresses *saddr;
2257 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2258 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2261 left = (*optsize) - sizeof(struct sctp_getaddresses);
2262 *optsize = sizeof(struct sctp_getaddresses);
2263 sas = (struct sockaddr_storage *)&saddr->addr[0];
2265 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2266 switch (net->ro._l_addr.sa.sa_family) {
2270 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2271 cpsz = sizeof(struct sockaddr_in6);
2273 cpsz = sizeof(struct sockaddr_in);
2276 cpsz = sizeof(struct sockaddr_in);
2282 cpsz = sizeof(struct sockaddr_in6);
2293 /* not enough room. */
2296 #if defined(INET) && defined(INET6)
2297 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2298 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2299 /* Must map the address */
2300 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2301 (struct sockaddr_in6 *)sas);
2303 memcpy(sas, &net->ro._l_addr, cpsz);
2306 memcpy(sas, &net->ro._l_addr, cpsz);
2308 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2310 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2314 SCTP_TCB_UNLOCK(stcb);
2316 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2321 case SCTP_GET_LOCAL_ADDRESSES:
2323 size_t limit, actual;
2324 struct sockaddr_storage *sas;
2325 struct sctp_getaddresses *saddr;
2327 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2328 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2330 sas = (struct sockaddr_storage *)&saddr->addr[0];
2331 limit = *optsize - sizeof(sctp_assoc_t);
2332 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2334 SCTP_TCB_UNLOCK(stcb);
2336 *optsize = sizeof(struct sockaddr_storage) + actual;
2339 case SCTP_PEER_ADDR_PARAMS:
2341 struct sctp_paddrparams *paddrp;
2342 struct sctp_nets *net;
2343 struct sockaddr *addr;
2345 #if defined(INET) && defined(INET6)
2346 struct sockaddr_in sin_store;
2350 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2351 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2353 #if defined(INET) && defined(INET6)
2354 if (paddrp->spp_address.ss_family == AF_INET6) {
2355 struct sockaddr_in6 *sin6;
2357 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2358 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2359 in6_sin6_2_sin(&sin_store, sin6);
2360 addr = (struct sockaddr *)&sin_store;
2362 addr = (struct sockaddr *)&paddrp->spp_address;
2365 addr = (struct sockaddr *)&paddrp->spp_address;
2368 addr = (struct sockaddr *)&paddrp->spp_address;
2371 net = sctp_findnet(stcb, addr);
2374 * We increment here since
2375 * sctp_findassociation_ep_addr() wil do a
2376 * decrement if it finds the stcb as long as
2377 * the locked tcb (last argument) is NOT a
2381 SCTP_INP_INCR_REF(inp);
2382 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2384 SCTP_INP_DECR_REF(inp);
2387 if ((stcb != NULL) && (net == NULL)) {
2389 if (addr->sa_family == AF_INET) {
2390 struct sockaddr_in *sin;
2392 sin = (struct sockaddr_in *)addr;
2393 if (sin->sin_addr.s_addr != INADDR_ANY) {
2395 SCTP_TCB_UNLOCK(stcb);
2396 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2402 if (addr->sa_family == AF_INET6) {
2403 struct sockaddr_in6 *sin6;
2405 sin6 = (struct sockaddr_in6 *)addr;
2406 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2408 SCTP_TCB_UNLOCK(stcb);
2409 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2415 error = EAFNOSUPPORT;
2416 SCTP_TCB_UNLOCK(stcb);
2417 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2422 /* Applies to the specific association */
2423 paddrp->spp_flags = 0;
2425 paddrp->spp_hbinterval = net->heart_beat_delay;
2426 paddrp->spp_pathmaxrxt = net->failure_threshold;
2427 paddrp->spp_pathmtu = net->mtu;
2428 switch (net->ro._l_addr.sa.sa_family) {
2431 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2436 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2442 /* get flags for HB */
2443 if (net->dest_state & SCTP_ADDR_NOHB) {
2444 paddrp->spp_flags |= SPP_HB_DISABLE;
2446 paddrp->spp_flags |= SPP_HB_ENABLE;
2448 /* get flags for PMTU */
2449 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2450 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2452 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2454 if (net->dscp & 0x01) {
2455 paddrp->spp_dscp = net->dscp & 0xfc;
2456 paddrp->spp_flags |= SPP_DSCP;
2459 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2460 (net->flowlabel & 0x80000000)) {
2461 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2462 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2467 * No destination so return default
2470 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2471 paddrp->spp_pathmtu = 0;
2472 if (stcb->asoc.default_dscp & 0x01) {
2473 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2474 paddrp->spp_flags |= SPP_DSCP;
2477 if (stcb->asoc.default_flowlabel & 0x80000000) {
2478 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2479 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2482 /* default settings should be these */
2483 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2484 paddrp->spp_flags |= SPP_HB_DISABLE;
2486 paddrp->spp_flags |= SPP_HB_ENABLE;
2488 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2489 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2491 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2493 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2495 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2496 SCTP_TCB_UNLOCK(stcb);
2498 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2499 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2500 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2501 /* Use endpoint defaults */
2502 SCTP_INP_RLOCK(inp);
2503 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2504 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2505 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2506 /* get inp's default */
2507 if (inp->sctp_ep.default_dscp & 0x01) {
2508 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2509 paddrp->spp_flags |= SPP_DSCP;
2512 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2513 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2514 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2515 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2518 /* can't return this */
2519 paddrp->spp_pathmtu = 0;
2521 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2522 paddrp->spp_flags |= SPP_HB_ENABLE;
2524 paddrp->spp_flags |= SPP_HB_DISABLE;
2526 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2527 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2529 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2531 SCTP_INP_RUNLOCK(inp);
2533 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2538 *optsize = sizeof(struct sctp_paddrparams);
2542 case SCTP_GET_PEER_ADDR_INFO:
2544 struct sctp_paddrinfo *paddri;
2545 struct sctp_nets *net;
2546 struct sockaddr *addr;
2548 #if defined(INET) && defined(INET6)
2549 struct sockaddr_in sin_store;
2553 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2554 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2556 #if defined(INET) && defined(INET6)
2557 if (paddri->spinfo_address.ss_family == AF_INET6) {
2558 struct sockaddr_in6 *sin6;
2560 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2561 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2562 in6_sin6_2_sin(&sin_store, sin6);
2563 addr = (struct sockaddr *)&sin_store;
2565 addr = (struct sockaddr *)&paddri->spinfo_address;
2568 addr = (struct sockaddr *)&paddri->spinfo_address;
2571 addr = (struct sockaddr *)&paddri->spinfo_address;
2574 net = sctp_findnet(stcb, addr);
2577 * We increment here since
2578 * sctp_findassociation_ep_addr() wil do a
2579 * decrement if it finds the stcb as long as
2580 * the locked tcb (last argument) is NOT a
2584 SCTP_INP_INCR_REF(inp);
2585 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2587 SCTP_INP_DECR_REF(inp);
2591 if ((stcb != NULL) && (net != NULL)) {
2592 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2593 /* It's unconfirmed */
2594 paddri->spinfo_state = SCTP_UNCONFIRMED;
2595 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2597 paddri->spinfo_state = SCTP_ACTIVE;
2600 paddri->spinfo_state = SCTP_INACTIVE;
2602 paddri->spinfo_cwnd = net->cwnd;
2603 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2604 paddri->spinfo_rto = net->RTO;
2605 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2606 paddri->spinfo_mtu = net->mtu;
2607 switch (addr->sa_family) {
2610 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2615 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2621 SCTP_TCB_UNLOCK(stcb);
2622 *optsize = sizeof(struct sctp_paddrinfo);
2625 SCTP_TCB_UNLOCK(stcb);
2627 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2632 case SCTP_PCB_STATUS:
2634 struct sctp_pcbinfo *spcb;
2636 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2637 sctp_fill_pcbinfo(spcb);
2638 *optsize = sizeof(struct sctp_pcbinfo);
2643 struct sctp_nets *net;
2644 struct sctp_status *sstat;
2646 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2647 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2650 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2654 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2655 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2656 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2657 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2659 * We can't include chunks that have been passed to
2660 * the socket layer. Only things in queue.
2662 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2663 stcb->asoc.cnt_on_all_streams);
2666 sstat->sstat_instrms = stcb->asoc.streamincnt;
2667 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2668 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2669 memcpy(&sstat->sstat_primary.spinfo_address,
2670 &stcb->asoc.primary_destination->ro._l_addr,
2671 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2672 net = stcb->asoc.primary_destination;
2673 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2675 * Again the user can get info from sctp_constants.h
2676 * for what the state of the network is.
2678 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2679 /* It's unconfirmed */
2680 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2681 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2683 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2686 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2688 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2689 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2690 sstat->sstat_primary.spinfo_rto = net->RTO;
2691 sstat->sstat_primary.spinfo_mtu = net->mtu;
2692 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2695 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2700 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2706 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2707 SCTP_TCB_UNLOCK(stcb);
2708 *optsize = sizeof(struct sctp_status);
2713 struct sctp_rtoinfo *srto;
2715 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2716 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2719 srto->srto_initial = stcb->asoc.initial_rto;
2720 srto->srto_max = stcb->asoc.maxrto;
2721 srto->srto_min = stcb->asoc.minrto;
2722 SCTP_TCB_UNLOCK(stcb);
2724 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2725 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2726 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2727 SCTP_INP_RLOCK(inp);
2728 srto->srto_initial = inp->sctp_ep.initial_rto;
2729 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2730 srto->srto_min = inp->sctp_ep.sctp_minrto;
2731 SCTP_INP_RUNLOCK(inp);
2733 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2738 *optsize = sizeof(struct sctp_rtoinfo);
2744 struct sctp_timeouts *stimo;
2746 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2747 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2750 stimo->stimo_init = stcb->asoc.timoinit;
2751 stimo->stimo_data = stcb->asoc.timodata;
2752 stimo->stimo_sack = stcb->asoc.timosack;
2753 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2754 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2755 stimo->stimo_cookie = stcb->asoc.timocookie;
2756 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2757 SCTP_TCB_UNLOCK(stcb);
2758 *optsize = sizeof(struct sctp_timeouts);
2760 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2765 case SCTP_ASSOCINFO:
2767 struct sctp_assocparams *sasoc;
2769 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2770 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2773 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2774 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2775 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2776 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2777 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2778 SCTP_TCB_UNLOCK(stcb);
2780 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2781 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2782 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2783 SCTP_INP_RLOCK(inp);
2784 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2785 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2786 sasoc->sasoc_number_peer_destinations = 0;
2787 sasoc->sasoc_peer_rwnd = 0;
2788 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2789 SCTP_INP_RUNLOCK(inp);
2791 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2796 *optsize = sizeof(struct sctp_assocparams);
2800 case SCTP_DEFAULT_SEND_PARAM:
2802 struct sctp_sndrcvinfo *s_info;
2804 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2805 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2808 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2809 SCTP_TCB_UNLOCK(stcb);
2811 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2812 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2813 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2814 SCTP_INP_RLOCK(inp);
2815 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2816 SCTP_INP_RUNLOCK(inp);
2818 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2823 *optsize = sizeof(struct sctp_sndrcvinfo);
2829 struct sctp_initmsg *sinit;
2831 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2832 SCTP_INP_RLOCK(inp);
2833 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2834 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2835 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2836 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2837 SCTP_INP_RUNLOCK(inp);
2838 *optsize = sizeof(struct sctp_initmsg);
2841 case SCTP_PRIMARY_ADDR:
2842 /* we allow a "get" operation on this */
2844 struct sctp_setprim *ssp;
2846 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2847 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2850 union sctp_sockstore *addr;
2852 addr = &stcb->asoc.primary_destination->ro._l_addr;
2853 switch (addr->sa.sa_family) {
2857 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2858 in6_sin_2_v4mapsin6(&addr->sin,
2859 (struct sockaddr_in6 *)&ssp->ssp_addr);
2861 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2864 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2870 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2876 SCTP_TCB_UNLOCK(stcb);
2877 *optsize = sizeof(struct sctp_setprim);
2879 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2884 case SCTP_HMAC_IDENT:
2886 struct sctp_hmacalgo *shmac;
2887 sctp_hmaclist_t *hmaclist;
2891 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2893 SCTP_INP_RLOCK(inp);
2894 hmaclist = inp->sctp_ep.local_hmacs;
2895 if (hmaclist == NULL) {
2896 /* no HMACs to return */
2897 *optsize = sizeof(*shmac);
2898 SCTP_INP_RUNLOCK(inp);
2901 /* is there room for all of the hmac ids? */
2902 size = sizeof(*shmac) + (hmaclist->num_algo *
2903 sizeof(shmac->shmac_idents[0]));
2904 if ((size_t)(*optsize) < size) {
2905 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2907 SCTP_INP_RUNLOCK(inp);
2910 /* copy in the list */
2911 shmac->shmac_number_of_idents = hmaclist->num_algo;
2912 for (i = 0; i < hmaclist->num_algo; i++) {
2913 shmac->shmac_idents[i] = hmaclist->hmac[i];
2915 SCTP_INP_RUNLOCK(inp);
2919 case SCTP_AUTH_ACTIVE_KEY:
2921 struct sctp_authkeyid *scact;
2923 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2924 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2927 /* get the active key on the assoc */
2928 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2929 SCTP_TCB_UNLOCK(stcb);
2931 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2932 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2933 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2934 /* get the endpoint active key */
2935 SCTP_INP_RLOCK(inp);
2936 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2937 SCTP_INP_RUNLOCK(inp);
2939 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2944 *optsize = sizeof(struct sctp_authkeyid);
2948 case SCTP_LOCAL_AUTH_CHUNKS:
2950 struct sctp_authchunks *sac;
2951 sctp_auth_chklist_t *chklist = NULL;
2954 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2955 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2958 /* get off the assoc */
2959 chklist = stcb->asoc.local_auth_chunks;
2960 /* is there enough space? */
2961 size = sctp_auth_get_chklist_size(chklist);
2962 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2964 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2966 /* copy in the chunks */
2967 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2968 sac->gauth_number_of_chunks = (uint32_t) size;
2969 *optsize = sizeof(struct sctp_authchunks) + size;
2971 SCTP_TCB_UNLOCK(stcb);
2973 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2974 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2975 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2976 /* get off the endpoint */
2977 SCTP_INP_RLOCK(inp);
2978 chklist = inp->sctp_ep.local_auth_chunks;
2979 /* is there enough space? */
2980 size = sctp_auth_get_chklist_size(chklist);
2981 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2983 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2985 /* copy in the chunks */
2986 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2987 sac->gauth_number_of_chunks = (uint32_t) size;
2988 *optsize = sizeof(struct sctp_authchunks) + size;
2990 SCTP_INP_RUNLOCK(inp);
2992 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2998 case SCTP_PEER_AUTH_CHUNKS:
3000 struct sctp_authchunks *sac;
3001 sctp_auth_chklist_t *chklist = NULL;
3004 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
3005 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
3008 /* get off the assoc */
3009 chklist = stcb->asoc.peer_auth_chunks;
3010 /* is there enough space? */
3011 size = sctp_auth_get_chklist_size(chklist);
3012 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
3014 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3016 /* copy in the chunks */
3017 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
3018 sac->gauth_number_of_chunks = (uint32_t) size;
3019 *optsize = sizeof(struct sctp_authchunks) + size;
3021 SCTP_TCB_UNLOCK(stcb);
3023 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3030 struct sctp_event *event;
3031 uint32_t event_type;
3033 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3034 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3036 switch (event->se_type) {
3037 case SCTP_ASSOC_CHANGE:
3038 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3040 case SCTP_PEER_ADDR_CHANGE:
3041 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3043 case SCTP_REMOTE_ERROR:
3044 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3046 case SCTP_SEND_FAILED:
3047 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3049 case SCTP_SHUTDOWN_EVENT:
3050 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3052 case SCTP_ADAPTATION_INDICATION:
3053 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3055 case SCTP_PARTIAL_DELIVERY_EVENT:
3056 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3058 case SCTP_AUTHENTICATION_EVENT:
3059 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3061 case SCTP_STREAM_RESET_EVENT:
3062 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3064 case SCTP_SENDER_DRY_EVENT:
3065 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3067 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3069 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3072 case SCTP_ASSOC_RESET_EVENT:
3073 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3075 case SCTP_STREAM_CHANGE_EVENT:
3076 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3078 case SCTP_SEND_FAILED_EVENT:
3079 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3083 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3087 if (event_type > 0) {
3089 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3090 SCTP_TCB_UNLOCK(stcb);
3092 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3093 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3094 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3095 SCTP_INP_RLOCK(inp);
3096 event->se_on = sctp_is_feature_on(inp, event_type);
3097 SCTP_INP_RUNLOCK(inp);
3099 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3105 *optsize = sizeof(struct sctp_event);
3109 case SCTP_RECVRCVINFO:
3113 if (*optsize < sizeof(int)) {
3114 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3117 SCTP_INP_RLOCK(inp);
3118 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3119 SCTP_INP_RUNLOCK(inp);
3122 /* return the option value */
3123 *(int *)optval = onoff;
3124 *optsize = sizeof(int);
3128 case SCTP_RECVNXTINFO:
3132 if (*optsize < sizeof(int)) {
3133 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3136 SCTP_INP_RLOCK(inp);
3137 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3138 SCTP_INP_RUNLOCK(inp);
3141 /* return the option value */
3142 *(int *)optval = onoff;
3143 *optsize = sizeof(int);
3147 case SCTP_DEFAULT_SNDINFO:
3149 struct sctp_sndinfo *info;
3151 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3152 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3155 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3156 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3157 info->snd_flags &= 0xfff0;
3158 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3159 info->snd_context = stcb->asoc.def_send.sinfo_context;
3160 SCTP_TCB_UNLOCK(stcb);
3162 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3163 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3164 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3165 SCTP_INP_RLOCK(inp);
3166 info->snd_sid = inp->def_send.sinfo_stream;
3167 info->snd_flags = inp->def_send.sinfo_flags;
3168 info->snd_flags &= 0xfff0;
3169 info->snd_ppid = inp->def_send.sinfo_ppid;
3170 info->snd_context = inp->def_send.sinfo_context;
3171 SCTP_INP_RUNLOCK(inp);
3173 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3178 *optsize = sizeof(struct sctp_sndinfo);
3182 case SCTP_DEFAULT_PRINFO:
3184 struct sctp_default_prinfo *info;
3186 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3187 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3190 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3191 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3192 SCTP_TCB_UNLOCK(stcb);
3194 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3195 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3196 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3197 SCTP_INP_RLOCK(inp);
3198 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3199 info->pr_value = inp->def_send.sinfo_timetolive;
3200 SCTP_INP_RUNLOCK(inp);
3202 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3207 *optsize = sizeof(struct sctp_default_prinfo);
3211 case SCTP_PEER_ADDR_THLDS:
3213 struct sctp_paddrthlds *thlds;
3214 struct sctp_nets *net;
3215 struct sockaddr *addr;
3217 #if defined(INET) && defined(INET6)
3218 struct sockaddr_in sin_store;
3222 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3223 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3225 #if defined(INET) && defined(INET6)
3226 if (thlds->spt_address.ss_family == AF_INET6) {
3227 struct sockaddr_in6 *sin6;
3229 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3230 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3231 in6_sin6_2_sin(&sin_store, sin6);
3232 addr = (struct sockaddr *)&sin_store;
3234 addr = (struct sockaddr *)&thlds->spt_address;
3237 addr = (struct sockaddr *)&thlds->spt_address;
3240 addr = (struct sockaddr *)&thlds->spt_address;
3243 net = sctp_findnet(stcb, addr);
3246 * We increment here since
3247 * sctp_findassociation_ep_addr() wil do a
3248 * decrement if it finds the stcb as long as
3249 * the locked tcb (last argument) is NOT a
3253 SCTP_INP_INCR_REF(inp);
3254 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3256 SCTP_INP_DECR_REF(inp);
3259 if ((stcb != NULL) && (net == NULL)) {
3261 if (addr->sa_family == AF_INET) {
3262 struct sockaddr_in *sin;
3264 sin = (struct sockaddr_in *)addr;
3265 if (sin->sin_addr.s_addr != INADDR_ANY) {
3267 SCTP_TCB_UNLOCK(stcb);
3268 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3274 if (addr->sa_family == AF_INET6) {
3275 struct sockaddr_in6 *sin6;
3277 sin6 = (struct sockaddr_in6 *)addr;
3278 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3280 SCTP_TCB_UNLOCK(stcb);
3281 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3287 error = EAFNOSUPPORT;
3288 SCTP_TCB_UNLOCK(stcb);
3289 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3295 thlds->spt_pathmaxrxt = net->failure_threshold;
3296 thlds->spt_pathpfthld = net->pf_threshold;
3298 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3299 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3301 thlds->spt_assoc_id = sctp_get_associd(stcb);
3302 SCTP_TCB_UNLOCK(stcb);
3304 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3305 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3306 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3307 /* Use endpoint defaults */
3308 SCTP_INP_RLOCK(inp);
3309 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3310 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3311 SCTP_INP_RUNLOCK(inp);
3313 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3318 *optsize = sizeof(struct sctp_paddrthlds);
3322 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3324 struct sctp_udpencaps *encaps;
3325 struct sctp_nets *net;
3326 struct sockaddr *addr;
3328 #if defined(INET) && defined(INET6)
3329 struct sockaddr_in sin_store;
3333 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3334 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3336 #if defined(INET) && defined(INET6)
3337 if (encaps->sue_address.ss_family == AF_INET6) {
3338 struct sockaddr_in6 *sin6;
3340 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3341 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3342 in6_sin6_2_sin(&sin_store, sin6);
3343 addr = (struct sockaddr *)&sin_store;
3345 addr = (struct sockaddr *)&encaps->sue_address;
3348 addr = (struct sockaddr *)&encaps->sue_address;
3351 addr = (struct sockaddr *)&encaps->sue_address;
3354 net = sctp_findnet(stcb, addr);
3357 * We increment here since
3358 * sctp_findassociation_ep_addr() wil do a
3359 * decrement if it finds the stcb as long as
3360 * the locked tcb (last argument) is NOT a
3364 SCTP_INP_INCR_REF(inp);
3365 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3367 SCTP_INP_DECR_REF(inp);
3370 if ((stcb != NULL) && (net == NULL)) {
3372 if (addr->sa_family == AF_INET) {
3373 struct sockaddr_in *sin;
3375 sin = (struct sockaddr_in *)addr;
3376 if (sin->sin_addr.s_addr != INADDR_ANY) {
3378 SCTP_TCB_UNLOCK(stcb);
3379 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3385 if (addr->sa_family == AF_INET6) {
3386 struct sockaddr_in6 *sin6;
3388 sin6 = (struct sockaddr_in6 *)addr;
3389 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3391 SCTP_TCB_UNLOCK(stcb);
3392 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3398 error = EAFNOSUPPORT;
3399 SCTP_TCB_UNLOCK(stcb);
3400 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3406 encaps->sue_port = net->port;
3408 encaps->sue_port = stcb->asoc.port;
3410 SCTP_TCB_UNLOCK(stcb);
3412 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3413 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3414 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3415 SCTP_INP_RLOCK(inp);
3416 encaps->sue_port = inp->sctp_ep.port;
3417 SCTP_INP_RUNLOCK(inp);
3419 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3424 *optsize = sizeof(struct sctp_udpencaps);
3428 case SCTP_ECN_SUPPORTED:
3430 struct sctp_assoc_value *av;
3432 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3433 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3436 av->assoc_value = stcb->asoc.ecn_supported;
3437 SCTP_TCB_UNLOCK(stcb);
3439 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3440 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3441 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3442 SCTP_INP_RLOCK(inp);
3443 av->assoc_value = inp->ecn_supported;
3444 SCTP_INP_RUNLOCK(inp);
3446 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3451 *optsize = sizeof(struct sctp_assoc_value);
3455 case SCTP_PR_SUPPORTED:
3457 struct sctp_assoc_value *av;
3459 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3460 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3463 av->assoc_value = stcb->asoc.prsctp_supported;
3464 SCTP_TCB_UNLOCK(stcb);
3466 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3467 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3468 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3469 SCTP_INP_RLOCK(inp);
3470 av->assoc_value = inp->prsctp_supported;
3471 SCTP_INP_RUNLOCK(inp);
3473 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3478 *optsize = sizeof(struct sctp_assoc_value);
3482 case SCTP_AUTH_SUPPORTED:
3484 struct sctp_assoc_value *av;
3486 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3487 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3490 av->assoc_value = stcb->asoc.auth_supported;
3491 SCTP_TCB_UNLOCK(stcb);
3493 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3494 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3495 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3496 SCTP_INP_RLOCK(inp);
3497 av->assoc_value = inp->auth_supported;
3498 SCTP_INP_RUNLOCK(inp);
3500 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3505 *optsize = sizeof(struct sctp_assoc_value);
3509 case SCTP_ASCONF_SUPPORTED:
3511 struct sctp_assoc_value *av;
3513 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3514 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3517 av->assoc_value = stcb->asoc.asconf_supported;
3518 SCTP_TCB_UNLOCK(stcb);
3520 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3521 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3522 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3523 SCTP_INP_RLOCK(inp);
3524 av->assoc_value = inp->asconf_supported;
3525 SCTP_INP_RUNLOCK(inp);
3527 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3532 *optsize = sizeof(struct sctp_assoc_value);
3536 case SCTP_RECONFIG_SUPPORTED:
3538 struct sctp_assoc_value *av;
3540 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3541 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3544 av->assoc_value = stcb->asoc.reconfig_supported;
3545 SCTP_TCB_UNLOCK(stcb);
3547 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3548 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3549 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3550 SCTP_INP_RLOCK(inp);
3551 av->assoc_value = inp->reconfig_supported;
3552 SCTP_INP_RUNLOCK(inp);
3554 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3559 *optsize = sizeof(struct sctp_assoc_value);
3563 case SCTP_NRSACK_SUPPORTED:
3565 struct sctp_assoc_value *av;
3567 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3568 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3571 av->assoc_value = stcb->asoc.nrsack_supported;
3572 SCTP_TCB_UNLOCK(stcb);
3574 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3575 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3576 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3577 SCTP_INP_RLOCK(inp);
3578 av->assoc_value = inp->nrsack_supported;
3579 SCTP_INP_RUNLOCK(inp);
3581 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3586 *optsize = sizeof(struct sctp_assoc_value);
3590 case SCTP_PKTDROP_SUPPORTED:
3592 struct sctp_assoc_value *av;
3594 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3595 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3598 av->assoc_value = stcb->asoc.pktdrop_supported;
3599 SCTP_TCB_UNLOCK(stcb);
3601 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3602 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3603 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3604 SCTP_INP_RLOCK(inp);
3605 av->assoc_value = inp->pktdrop_supported;
3606 SCTP_INP_RUNLOCK(inp);
3608 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3613 *optsize = sizeof(struct sctp_assoc_value);
3617 case SCTP_ENABLE_STREAM_RESET:
3619 struct sctp_assoc_value *av;
3621 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3622 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3625 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3626 SCTP_TCB_UNLOCK(stcb);
3628 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3629 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3630 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3631 SCTP_INP_RLOCK(inp);
3632 av->assoc_value = (uint32_t) inp->local_strreset_support;
3633 SCTP_INP_RUNLOCK(inp);
3635 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3640 *optsize = sizeof(struct sctp_assoc_value);
3644 case SCTP_PR_STREAM_STATUS:
3646 struct sctp_prstatus *sprstat;
3650 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3651 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3653 sid = sprstat->sprstat_sid;
3654 policy = sprstat->sprstat_policy;
3655 #if defined(SCTP_DETAILED_STR_STATS)
3656 if ((stcb != NULL) &&
3657 (sid < stcb->asoc.streamoutcnt) &&
3658 (policy != SCTP_PR_SCTP_NONE) &&
3659 ((policy <= SCTP_PR_SCTP_MAX) ||
3660 (policy == SCTP_PR_SCTP_ALL))) {
3661 if (policy == SCTP_PR_SCTP_ALL) {
3662 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3663 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3665 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3666 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3669 if ((stcb != NULL) &&
3670 (sid < stcb->asoc.streamoutcnt) &&
3671 (policy == SCTP_PR_SCTP_ALL)) {
3672 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3673 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3675 SCTP_TCB_UNLOCK(stcb);
3676 *optsize = sizeof(struct sctp_prstatus);
3678 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3683 case SCTP_PR_ASSOC_STATUS:
3685 struct sctp_prstatus *sprstat;
3688 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3689 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3691 policy = sprstat->sprstat_policy;
3692 if ((stcb != NULL) &&
3693 (policy != SCTP_PR_SCTP_NONE) &&
3694 ((policy <= SCTP_PR_SCTP_MAX) ||
3695 (policy == SCTP_PR_SCTP_ALL))) {
3696 if (policy == SCTP_PR_SCTP_ALL) {
3697 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3698 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3700 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3701 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3703 SCTP_TCB_UNLOCK(stcb);
3704 *optsize = sizeof(struct sctp_prstatus);
3706 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3713 struct sctp_assoc_value *av;
3715 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3716 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3719 av->assoc_value = stcb->asoc.max_cwnd;
3720 SCTP_TCB_UNLOCK(stcb);
3722 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3723 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3724 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3725 SCTP_INP_RLOCK(inp);
3726 av->assoc_value = inp->max_cwnd;
3727 SCTP_INP_RUNLOCK(inp);
3729 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3734 *optsize = sizeof(struct sctp_assoc_value);
3739 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3740 error = ENOPROTOOPT;
3742 } /* end switch (sopt->sopt_name) */
3750 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3755 struct sctp_tcb *stcb = NULL;
3756 struct sctp_inpcb *inp = NULL;
3759 if (optval == NULL) {
3760 SCTP_PRINTF("optval is NULL\n");
3761 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3764 inp = (struct sctp_inpcb *)so->so_pcb;
3766 SCTP_PRINTF("inp is NULL?\n");
3767 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3770 vrf_id = inp->def_vrf_id;
3775 case SCTP_AUTOCLOSE:
3776 case SCTP_AUTO_ASCONF:
3777 case SCTP_EXPLICIT_EOR:
3778 case SCTP_DISABLE_FRAGMENTS:
3779 case SCTP_USE_EXT_RCVINFO:
3780 case SCTP_I_WANT_MAPPED_V4_ADDR:
3781 /* copy in the option value */
3782 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3787 case SCTP_DISABLE_FRAGMENTS:
3788 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3790 case SCTP_AUTO_ASCONF:
3792 * NOTE: we don't really support this flag
3794 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3795 /* only valid for bound all sockets */
3796 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3798 /* forbidden by admin */
3799 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3802 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3804 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3808 case SCTP_EXPLICIT_EOR:
3809 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3811 case SCTP_USE_EXT_RCVINFO:
3812 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3814 case SCTP_I_WANT_MAPPED_V4_ADDR:
3815 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3816 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3818 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3823 set_opt = SCTP_PCB_FLAGS_NODELAY;
3825 case SCTP_AUTOCLOSE:
3826 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3827 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3828 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3831 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3833 * The value is in ticks. Note this does not effect
3834 * old associations, only new ones.
3836 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3839 SCTP_INP_WLOCK(inp);
3841 sctp_feature_on(inp, set_opt);
3843 sctp_feature_off(inp, set_opt);
3845 SCTP_INP_WUNLOCK(inp);
3847 case SCTP_REUSE_PORT:
3849 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3850 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3851 /* Can't set it after we are bound */
3855 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3856 /* Can't do this for a 1-m socket */
3861 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3863 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3866 case SCTP_PARTIAL_DELIVERY_POINT:
3870 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3871 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3872 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3876 inp->partial_delivery_point = *value;
3879 case SCTP_FRAGMENT_INTERLEAVE:
3880 /* not yet until we re-write sctp_recvmsg() */
3884 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3885 if (*level == SCTP_FRAG_LEVEL_2) {
3886 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3887 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3888 } else if (*level == SCTP_FRAG_LEVEL_1) {
3889 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3890 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3891 } else if (*level == SCTP_FRAG_LEVEL_0) {
3892 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3893 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3896 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3901 case SCTP_CMT_ON_OFF:
3902 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3903 struct sctp_assoc_value *av;
3905 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3906 if (av->assoc_value > SCTP_CMT_MAX) {
3907 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3911 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3913 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3914 SCTP_TCB_UNLOCK(stcb);
3916 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3917 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3918 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3919 (av->assoc_id == SCTP_ALL_ASSOC)) {
3920 SCTP_INP_WLOCK(inp);
3921 inp->sctp_cmt_on_off = av->assoc_value;
3922 SCTP_INP_WUNLOCK(inp);
3924 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3925 (av->assoc_id == SCTP_ALL_ASSOC)) {
3926 SCTP_INP_RLOCK(inp);
3927 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3928 SCTP_TCB_LOCK(stcb);
3929 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3930 SCTP_TCB_UNLOCK(stcb);
3932 SCTP_INP_RUNLOCK(inp);
3936 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3937 error = ENOPROTOOPT;
3940 case SCTP_PLUGGABLE_CC:
3942 struct sctp_assoc_value *av;
3943 struct sctp_nets *net;
3945 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3946 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3947 (av->assoc_value != SCTP_CC_HSTCP) &&
3948 (av->assoc_value != SCTP_CC_HTCP) &&
3949 (av->assoc_value != SCTP_CC_RTCC)) {
3950 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3954 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3956 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3957 stcb->asoc.congestion_control_module = av->assoc_value;
3958 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3959 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3960 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3963 SCTP_TCB_UNLOCK(stcb);
3965 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3966 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3967 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3968 (av->assoc_id == SCTP_ALL_ASSOC)) {
3969 SCTP_INP_WLOCK(inp);
3970 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3971 SCTP_INP_WUNLOCK(inp);
3973 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3974 (av->assoc_id == SCTP_ALL_ASSOC)) {
3975 SCTP_INP_RLOCK(inp);
3976 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3977 SCTP_TCB_LOCK(stcb);
3978 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3979 stcb->asoc.congestion_control_module = av->assoc_value;
3980 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3981 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3982 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3985 SCTP_TCB_UNLOCK(stcb);
3987 SCTP_INP_RUNLOCK(inp);
3992 case SCTP_CC_OPTION:
3994 struct sctp_cc_option *cc_opt;
3996 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
3997 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
3999 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
4000 SCTP_INP_RLOCK(inp);
4001 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4002 SCTP_TCB_LOCK(stcb);
4003 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4004 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4006 SCTP_TCB_UNLOCK(stcb);
4008 SCTP_INP_RUNLOCK(inp);
4013 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4016 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4019 SCTP_TCB_UNLOCK(stcb);
4023 case SCTP_PLUGGABLE_SS:
4025 struct sctp_assoc_value *av;
4027 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4028 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4029 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4030 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4031 (av->assoc_value != SCTP_SS_PRIORITY) &&
4032 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4033 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4034 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4038 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4040 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4041 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4042 stcb->asoc.stream_scheduling_module = av->assoc_value;
4043 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4044 SCTP_TCB_UNLOCK(stcb);
4046 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4047 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4048 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4049 (av->assoc_id == SCTP_ALL_ASSOC)) {
4050 SCTP_INP_WLOCK(inp);
4051 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4052 SCTP_INP_WUNLOCK(inp);
4054 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4055 (av->assoc_id == SCTP_ALL_ASSOC)) {
4056 SCTP_INP_RLOCK(inp);
4057 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4058 SCTP_TCB_LOCK(stcb);
4059 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4060 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4061 stcb->asoc.stream_scheduling_module = av->assoc_value;
4062 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4063 SCTP_TCB_UNLOCK(stcb);
4065 SCTP_INP_RUNLOCK(inp);
4072 struct sctp_stream_value *av;
4074 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4075 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4077 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4078 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4079 av->stream_value) < 0)) {
4080 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4083 SCTP_TCB_UNLOCK(stcb);
4085 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4086 SCTP_INP_RLOCK(inp);
4087 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4088 SCTP_TCB_LOCK(stcb);
4089 if (av->stream_id < stcb->asoc.streamoutcnt) {
4090 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4092 &stcb->asoc.strmout[av->stream_id],
4095 SCTP_TCB_UNLOCK(stcb);
4097 SCTP_INP_RUNLOCK(inp);
4100 * Can't set stream value without
4103 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4109 case SCTP_CLR_STAT_LOG:
4110 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4115 struct sctp_assoc_value *av;
4117 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4118 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4121 stcb->asoc.context = av->assoc_value;
4122 SCTP_TCB_UNLOCK(stcb);
4124 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4125 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4126 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4127 (av->assoc_id == SCTP_ALL_ASSOC)) {
4128 SCTP_INP_WLOCK(inp);
4129 inp->sctp_context = av->assoc_value;
4130 SCTP_INP_WUNLOCK(inp);
4132 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4133 (av->assoc_id == SCTP_ALL_ASSOC)) {
4134 SCTP_INP_RLOCK(inp);
4135 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4136 SCTP_TCB_LOCK(stcb);
4137 stcb->asoc.context = av->assoc_value;
4138 SCTP_TCB_UNLOCK(stcb);
4140 SCTP_INP_RUNLOCK(inp);
4147 uint32_t *default_vrfid;
4149 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4150 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4151 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4155 inp->def_vrf_id = *default_vrfid;
4158 case SCTP_DEL_VRF_ID:
4160 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4164 case SCTP_ADD_VRF_ID:
4166 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4170 case SCTP_DELAYED_SACK:
4172 struct sctp_sack_info *sack;
4174 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4175 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4176 if (sack->sack_delay) {
4177 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4178 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4179 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4180 sack->sack_delay = TICKS_TO_MSEC(1);
4184 if (sack->sack_delay) {
4185 stcb->asoc.delayed_ack = sack->sack_delay;
4187 if (sack->sack_freq) {
4188 stcb->asoc.sack_freq = sack->sack_freq;
4190 SCTP_TCB_UNLOCK(stcb);
4192 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4193 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4194 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4195 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4196 SCTP_INP_WLOCK(inp);
4197 if (sack->sack_delay) {
4198 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4200 if (sack->sack_freq) {
4201 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4203 SCTP_INP_WUNLOCK(inp);
4205 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4206 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4207 SCTP_INP_RLOCK(inp);
4208 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4209 SCTP_TCB_LOCK(stcb);
4210 if (sack->sack_delay) {
4211 stcb->asoc.delayed_ack = sack->sack_delay;
4213 if (sack->sack_freq) {
4214 stcb->asoc.sack_freq = sack->sack_freq;
4216 SCTP_TCB_UNLOCK(stcb);
4218 SCTP_INP_RUNLOCK(inp);
4223 case SCTP_AUTH_CHUNK:
4225 struct sctp_authchunk *sauth;
4227 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4229 SCTP_INP_WLOCK(inp);
4230 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4231 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4234 SCTP_INP_WUNLOCK(inp);
4239 struct sctp_authkey *sca;
4240 struct sctp_keyhead *shared_keys;
4241 sctp_sharedkey_t *shared_key;
4242 sctp_key_t *key = NULL;
4245 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4246 if (sca->sca_keylength == 0) {
4247 size = optsize - sizeof(struct sctp_authkey);
4249 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4250 size = sca->sca_keylength;
4252 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4257 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4260 shared_keys = &stcb->asoc.shared_keys;
4261 /* clear the cached keys for this key id */
4262 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4264 * create the new shared key and
4268 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4270 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4272 SCTP_TCB_UNLOCK(stcb);
4276 shared_key = sctp_alloc_sharedkey();
4277 if (shared_key == NULL) {
4279 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4281 SCTP_TCB_UNLOCK(stcb);
4284 shared_key->key = key;
4285 shared_key->keyid = sca->sca_keynumber;
4286 error = sctp_insert_sharedkey(shared_keys, shared_key);
4287 SCTP_TCB_UNLOCK(stcb);
4289 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4290 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4291 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4292 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4293 SCTP_INP_WLOCK(inp);
4294 shared_keys = &inp->sctp_ep.shared_keys;
4296 * clear the cached keys on all
4297 * assocs for this key id
4299 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4301 * create the new shared key and
4305 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4307 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4309 SCTP_INP_WUNLOCK(inp);
4313 shared_key = sctp_alloc_sharedkey();
4314 if (shared_key == NULL) {
4316 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4318 SCTP_INP_WUNLOCK(inp);
4321 shared_key->key = key;
4322 shared_key->keyid = sca->sca_keynumber;
4323 error = sctp_insert_sharedkey(shared_keys, shared_key);
4324 SCTP_INP_WUNLOCK(inp);
4326 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4327 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4328 SCTP_INP_RLOCK(inp);
4329 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4330 SCTP_TCB_LOCK(stcb);
4331 shared_keys = &stcb->asoc.shared_keys;
4333 * clear the cached keys for
4336 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4338 * create the new shared key
4339 * and insert/replace it
4342 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4344 SCTP_TCB_UNLOCK(stcb);
4348 shared_key = sctp_alloc_sharedkey();
4349 if (shared_key == NULL) {
4351 SCTP_TCB_UNLOCK(stcb);
4354 shared_key->key = key;
4355 shared_key->keyid = sca->sca_keynumber;
4356 error = sctp_insert_sharedkey(shared_keys, shared_key);
4357 SCTP_TCB_UNLOCK(stcb);
4359 SCTP_INP_RUNLOCK(inp);
4364 case SCTP_HMAC_IDENT:
4366 struct sctp_hmacalgo *shmac;
4367 sctp_hmaclist_t *hmaclist;
4371 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4372 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4373 (shmac->shmac_number_of_idents > 0xffff)) {
4374 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4378 hmaclist = sctp_alloc_hmaclist((uint16_t) shmac->shmac_number_of_idents);
4379 if (hmaclist == NULL) {
4380 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4384 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4385 hmacid = shmac->shmac_idents[i];
4386 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4387 /* invalid HMACs were found */ ;
4388 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4390 sctp_free_hmaclist(hmaclist);
4391 goto sctp_set_hmac_done;
4394 for (i = 0; i < hmaclist->num_algo; i++) {
4395 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4396 /* already in list */
4400 if (i == hmaclist->num_algo) {
4401 /* not found in list */
4402 sctp_free_hmaclist(hmaclist);
4403 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4407 /* set it on the endpoint */
4408 SCTP_INP_WLOCK(inp);
4409 if (inp->sctp_ep.local_hmacs)
4410 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4411 inp->sctp_ep.local_hmacs = hmaclist;
4412 SCTP_INP_WUNLOCK(inp);
4416 case SCTP_AUTH_ACTIVE_KEY:
4418 struct sctp_authkeyid *scact;
4420 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4421 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4423 /* set the active key on the right place */
4425 /* set the active key on the assoc */
4426 if (sctp_auth_setactivekey(stcb,
4427 scact->scact_keynumber)) {
4428 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4429 SCTP_FROM_SCTP_USRREQ,
4433 SCTP_TCB_UNLOCK(stcb);
4435 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4436 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4437 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4438 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4439 SCTP_INP_WLOCK(inp);
4440 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4441 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4444 SCTP_INP_WUNLOCK(inp);
4446 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4447 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4448 SCTP_INP_RLOCK(inp);
4449 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4450 SCTP_TCB_LOCK(stcb);
4451 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4452 SCTP_TCB_UNLOCK(stcb);
4454 SCTP_INP_RUNLOCK(inp);
4459 case SCTP_AUTH_DELETE_KEY:
4461 struct sctp_authkeyid *scdel;
4463 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4464 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4466 /* delete the key from the right place */
4468 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4469 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4472 SCTP_TCB_UNLOCK(stcb);
4474 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4475 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4476 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4477 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4478 SCTP_INP_WLOCK(inp);
4479 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4480 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4483 SCTP_INP_WUNLOCK(inp);
4485 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4486 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4487 SCTP_INP_RLOCK(inp);
4488 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4489 SCTP_TCB_LOCK(stcb);
4490 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4491 SCTP_TCB_UNLOCK(stcb);
4493 SCTP_INP_RUNLOCK(inp);
4498 case SCTP_AUTH_DEACTIVATE_KEY:
4500 struct sctp_authkeyid *keyid;
4502 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4503 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4505 /* deactivate the key from the right place */
4507 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4508 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4511 SCTP_TCB_UNLOCK(stcb);
4513 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4514 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4515 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4516 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4517 SCTP_INP_WLOCK(inp);
4518 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4519 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4522 SCTP_INP_WUNLOCK(inp);
4524 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4525 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4526 SCTP_INP_RLOCK(inp);
4527 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4528 SCTP_TCB_LOCK(stcb);
4529 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4530 SCTP_TCB_UNLOCK(stcb);
4532 SCTP_INP_RUNLOCK(inp);
4537 case SCTP_ENABLE_STREAM_RESET:
4539 struct sctp_assoc_value *av;
4541 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4542 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4543 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4547 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4549 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4550 SCTP_TCB_UNLOCK(stcb);
4552 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4553 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4554 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4555 (av->assoc_id == SCTP_ALL_ASSOC)) {
4556 SCTP_INP_WLOCK(inp);
4557 inp->local_strreset_support = (uint8_t) av->assoc_value;
4558 SCTP_INP_WUNLOCK(inp);
4560 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4561 (av->assoc_id == SCTP_ALL_ASSOC)) {
4562 SCTP_INP_RLOCK(inp);
4563 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4564 SCTP_TCB_LOCK(stcb);
4565 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4566 SCTP_TCB_UNLOCK(stcb);
4568 SCTP_INP_RUNLOCK(inp);
4573 case SCTP_RESET_STREAMS:
4575 struct sctp_reset_streams *strrst;
4576 int i, send_out = 0;
4579 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4580 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4582 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4586 if (stcb->asoc.reconfig_supported == 0) {
4588 * Peer does not support the chunk type.
4590 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4592 SCTP_TCB_UNLOCK(stcb);
4595 if (sizeof(struct sctp_reset_streams) +
4596 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4598 SCTP_TCB_UNLOCK(stcb);
4601 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4603 if (stcb->asoc.stream_reset_outstanding) {
4604 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4606 SCTP_TCB_UNLOCK(stcb);
4610 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4613 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4614 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4616 SCTP_TCB_UNLOCK(stcb);
4619 if ((send_in == 0) && (send_out == 0)) {
4620 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4622 SCTP_TCB_UNLOCK(stcb);
4625 for (i = 0; i < strrst->srs_number_streams; i++) {
4627 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4628 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4633 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4634 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4640 SCTP_TCB_UNLOCK(stcb);
4647 if (strrst->srs_number_streams) {
4648 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4649 strm = strrst->srs_stream_list[i];
4650 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4651 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4657 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4658 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4659 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4666 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4667 strrst->srs_stream_list,
4668 send_in, 0, 0, 0, 0, 0);
4670 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4673 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4676 * For outgoing streams don't report any
4677 * problems in sending the request to the
4678 * application. XXX: Double check resetting
4683 SCTP_TCB_UNLOCK(stcb);
4686 case SCTP_ADD_STREAMS:
4688 struct sctp_add_streams *stradd;
4689 uint8_t addstream = 0;
4690 uint16_t add_o_strmcnt = 0;
4691 uint16_t add_i_strmcnt = 0;
4693 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4694 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4696 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4700 if (stcb->asoc.reconfig_supported == 0) {
4702 * Peer does not support the chunk type.
4704 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4706 SCTP_TCB_UNLOCK(stcb);
4709 if (stcb->asoc.stream_reset_outstanding) {
4710 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4712 SCTP_TCB_UNLOCK(stcb);
4715 if ((stradd->sas_outstrms == 0) &&
4716 (stradd->sas_instrms == 0)) {
4720 if (stradd->sas_outstrms) {
4722 /* We allocate here */
4723 add_o_strmcnt = stradd->sas_outstrms;
4724 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4725 /* You can't have more than 64k */
4730 if (stradd->sas_instrms) {
4735 * We allocate inside
4736 * sctp_send_str_reset_req()
4738 add_i_strmcnt = stradd->sas_instrms;
4739 cnt = add_i_strmcnt;
4740 cnt += stcb->asoc.streamincnt;
4741 if (cnt > 0x0000ffff) {
4742 /* You can't have more than 64k */
4746 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4747 /* More than you are allowed */
4752 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4753 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4755 SCTP_TCB_UNLOCK(stcb);
4758 case SCTP_RESET_ASSOC:
4763 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4764 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4766 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4770 if (stcb->asoc.reconfig_supported == 0) {
4772 * Peer does not support the chunk type.
4774 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4776 SCTP_TCB_UNLOCK(stcb);
4779 if (stcb->asoc.stream_reset_outstanding) {
4780 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4782 SCTP_TCB_UNLOCK(stcb);
4786 * Is there any data pending in the send or sent
4789 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4790 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4793 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4794 SCTP_TCB_UNLOCK(stcb);
4797 /* Do any streams have data queued? */
4798 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4799 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4803 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4804 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4805 SCTP_TCB_UNLOCK(stcb);
4808 case SCTP_CONNECT_X:
4809 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4810 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4814 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4816 case SCTP_CONNECT_X_DELAYED:
4817 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4818 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4822 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4824 case SCTP_CONNECT_X_COMPLETE:
4826 struct sockaddr *sa;
4828 /* FIXME MT: check correct? */
4829 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4832 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4833 SCTP_INP_RLOCK(inp);
4834 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4836 SCTP_TCB_LOCK(stcb);
4838 SCTP_INP_RUNLOCK(inp);
4841 * We increment here since
4842 * sctp_findassociation_ep_addr() wil do a
4843 * decrement if it finds the stcb as long as
4844 * the locked tcb (last argument) is NOT a
4847 SCTP_INP_INCR_REF(inp);
4848 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4850 SCTP_INP_DECR_REF(inp);
4855 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4859 if (stcb->asoc.delayed_connection == 1) {
4860 stcb->asoc.delayed_connection = 0;
4861 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4862 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4863 stcb->asoc.primary_destination,
4864 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4865 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4868 * already expired or did not use delayed
4871 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4874 SCTP_TCB_UNLOCK(stcb);
4877 case SCTP_MAX_BURST:
4879 struct sctp_assoc_value *av;
4881 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4882 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4885 stcb->asoc.max_burst = av->assoc_value;
4886 SCTP_TCB_UNLOCK(stcb);
4888 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4889 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4890 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4891 (av->assoc_id == SCTP_ALL_ASSOC)) {
4892 SCTP_INP_WLOCK(inp);
4893 inp->sctp_ep.max_burst = av->assoc_value;
4894 SCTP_INP_WUNLOCK(inp);
4896 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4897 (av->assoc_id == SCTP_ALL_ASSOC)) {
4898 SCTP_INP_RLOCK(inp);
4899 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4900 SCTP_TCB_LOCK(stcb);
4901 stcb->asoc.max_burst = av->assoc_value;
4902 SCTP_TCB_UNLOCK(stcb);
4904 SCTP_INP_RUNLOCK(inp);
4911 struct sctp_assoc_value *av;
4914 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4915 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4917 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4918 ovh = SCTP_MED_OVERHEAD;
4920 ovh = SCTP_MED_V4_OVERHEAD;
4923 if (av->assoc_value) {
4924 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4926 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4928 SCTP_TCB_UNLOCK(stcb);
4930 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4931 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4932 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4933 SCTP_INP_WLOCK(inp);
4935 * FIXME MT: I think this is not in
4936 * tune with the API ID
4938 if (av->assoc_value) {
4939 inp->sctp_frag_point = (av->assoc_value + ovh);
4941 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4943 SCTP_INP_WUNLOCK(inp);
4945 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4953 struct sctp_event_subscribe *events;
4955 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4957 SCTP_INP_WLOCK(inp);
4958 if (events->sctp_data_io_event) {
4959 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4961 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4964 if (events->sctp_association_event) {
4965 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4967 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4970 if (events->sctp_address_event) {
4971 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4973 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4976 if (events->sctp_send_failure_event) {
4977 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4979 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4982 if (events->sctp_peer_error_event) {
4983 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4985 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4988 if (events->sctp_shutdown_event) {
4989 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4991 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4994 if (events->sctp_partial_delivery_event) {
4995 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4997 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5000 if (events->sctp_adaptation_layer_event) {
5001 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5003 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5006 if (events->sctp_authentication_event) {
5007 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5009 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5012 if (events->sctp_sender_dry_event) {
5013 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5015 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5018 if (events->sctp_stream_reset_event) {
5019 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5021 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5023 SCTP_INP_WUNLOCK(inp);
5025 SCTP_INP_RLOCK(inp);
5026 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5027 SCTP_TCB_LOCK(stcb);
5028 if (events->sctp_association_event) {
5029 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5031 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5033 if (events->sctp_address_event) {
5034 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5036 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5038 if (events->sctp_send_failure_event) {
5039 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5041 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5043 if (events->sctp_peer_error_event) {
5044 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5046 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5048 if (events->sctp_shutdown_event) {
5049 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5051 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5053 if (events->sctp_partial_delivery_event) {
5054 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5056 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5058 if (events->sctp_adaptation_layer_event) {
5059 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5061 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5063 if (events->sctp_authentication_event) {
5064 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5066 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5068 if (events->sctp_sender_dry_event) {
5069 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5071 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5073 if (events->sctp_stream_reset_event) {
5074 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5076 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5078 SCTP_TCB_UNLOCK(stcb);
5081 * Send up the sender dry event only for 1-to-1
5084 if (events->sctp_sender_dry_event) {
5085 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5086 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5087 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5089 SCTP_TCB_LOCK(stcb);
5090 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5091 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5092 (stcb->asoc.stream_queue_cnt == 0)) {
5093 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5095 SCTP_TCB_UNLOCK(stcb);
5099 SCTP_INP_RUNLOCK(inp);
5102 case SCTP_ADAPTATION_LAYER:
5104 struct sctp_setadaptation *adap_bits;
5106 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5107 SCTP_INP_WLOCK(inp);
5108 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5109 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5110 SCTP_INP_WUNLOCK(inp);
5114 case SCTP_SET_INITIAL_DBG_SEQ:
5118 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5119 SCTP_INP_WLOCK(inp);
5120 inp->sctp_ep.initial_sequence_debug = *vvv;
5121 SCTP_INP_WUNLOCK(inp);
5125 case SCTP_DEFAULT_SEND_PARAM:
5127 struct sctp_sndrcvinfo *s_info;
5129 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5130 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5133 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5134 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5136 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5139 SCTP_TCB_UNLOCK(stcb);
5141 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5142 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5143 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5144 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5145 SCTP_INP_WLOCK(inp);
5146 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5147 SCTP_INP_WUNLOCK(inp);
5149 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5150 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5151 SCTP_INP_RLOCK(inp);
5152 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5153 SCTP_TCB_LOCK(stcb);
5154 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5155 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5157 SCTP_TCB_UNLOCK(stcb);
5159 SCTP_INP_RUNLOCK(inp);
5164 case SCTP_PEER_ADDR_PARAMS:
5166 struct sctp_paddrparams *paddrp;
5167 struct sctp_nets *net;
5168 struct sockaddr *addr;
5170 #if defined(INET) && defined(INET6)
5171 struct sockaddr_in sin_store;
5175 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5176 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5178 #if defined(INET) && defined(INET6)
5179 if (paddrp->spp_address.ss_family == AF_INET6) {
5180 struct sockaddr_in6 *sin6;
5182 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5183 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5184 in6_sin6_2_sin(&sin_store, sin6);
5185 addr = (struct sockaddr *)&sin_store;
5187 addr = (struct sockaddr *)&paddrp->spp_address;
5190 addr = (struct sockaddr *)&paddrp->spp_address;
5193 addr = (struct sockaddr *)&paddrp->spp_address;
5196 net = sctp_findnet(stcb, addr);
5199 * We increment here since
5200 * sctp_findassociation_ep_addr() wil do a
5201 * decrement if it finds the stcb as long as
5202 * the locked tcb (last argument) is NOT a
5206 SCTP_INP_INCR_REF(inp);
5207 stcb = sctp_findassociation_ep_addr(&inp, addr,
5210 SCTP_INP_DECR_REF(inp);
5213 if ((stcb != NULL) && (net == NULL)) {
5215 if (addr->sa_family == AF_INET) {
5217 struct sockaddr_in *sin;
5219 sin = (struct sockaddr_in *)addr;
5220 if (sin->sin_addr.s_addr != INADDR_ANY) {
5221 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5222 SCTP_TCB_UNLOCK(stcb);
5229 if (addr->sa_family == AF_INET6) {
5230 struct sockaddr_in6 *sin6;
5232 sin6 = (struct sockaddr_in6 *)addr;
5233 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5234 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5235 SCTP_TCB_UNLOCK(stcb);
5242 error = EAFNOSUPPORT;
5243 SCTP_TCB_UNLOCK(stcb);
5244 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5249 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5251 SCTP_TCB_UNLOCK(stcb);
5252 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5255 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5257 SCTP_TCB_UNLOCK(stcb);
5258 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5262 /************************TCB SPECIFIC SET ******************/
5264 /************************NET SPECIFIC SET ******************/
5265 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5266 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5267 !(net->dest_state & SCTP_ADDR_NOHB)) {
5268 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5269 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5271 net->dest_state |= SCTP_ADDR_NOHB;
5273 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5274 if (paddrp->spp_hbinterval) {
5275 net->heart_beat_delay = paddrp->spp_hbinterval;
5276 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5277 net->heart_beat_delay = 0;
5279 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5280 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5281 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5282 net->dest_state &= ~SCTP_ADDR_NOHB;
5284 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5286 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5287 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5288 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5290 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5291 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5292 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5293 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5295 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5296 net->mtu = paddrp->spp_pathmtu;
5297 switch (net->ro._l_addr.sa.sa_family) {
5300 net->mtu += SCTP_MIN_V4_OVERHEAD;
5305 net->mtu += SCTP_MIN_OVERHEAD;
5311 if (net->mtu < stcb->asoc.smallest_mtu) {
5312 sctp_pathmtu_adjustment(stcb, net->mtu);
5315 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5316 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5317 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5319 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5321 if (paddrp->spp_pathmaxrxt) {
5322 if (net->dest_state & SCTP_ADDR_PF) {
5323 if (net->error_count > paddrp->spp_pathmaxrxt) {
5324 net->dest_state &= ~SCTP_ADDR_PF;
5327 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5328 (net->error_count > net->pf_threshold)) {
5329 net->dest_state |= SCTP_ADDR_PF;
5330 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5331 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5332 stcb->sctp_ep, stcb, net,
5333 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5334 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5337 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5338 if (net->error_count > paddrp->spp_pathmaxrxt) {
5339 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5340 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5343 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5344 net->dest_state |= SCTP_ADDR_REACHABLE;
5345 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5348 net->failure_threshold = paddrp->spp_pathmaxrxt;
5350 if (paddrp->spp_flags & SPP_DSCP) {
5351 net->dscp = paddrp->spp_dscp & 0xfc;
5355 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5356 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5357 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5358 net->flowlabel |= 0x80000000;
5363 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5364 if (paddrp->spp_pathmaxrxt != 0) {
5365 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5366 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5367 if (net->dest_state & SCTP_ADDR_PF) {
5368 if (net->error_count > paddrp->spp_pathmaxrxt) {
5369 net->dest_state &= ~SCTP_ADDR_PF;
5372 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5373 (net->error_count > net->pf_threshold)) {
5374 net->dest_state |= SCTP_ADDR_PF;
5375 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5376 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5377 stcb->sctp_ep, stcb, net,
5378 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5379 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5382 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5383 if (net->error_count > paddrp->spp_pathmaxrxt) {
5384 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5385 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5388 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5389 net->dest_state |= SCTP_ADDR_REACHABLE;
5390 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5393 net->failure_threshold = paddrp->spp_pathmaxrxt;
5396 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5397 if (paddrp->spp_hbinterval != 0) {
5398 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5399 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5400 stcb->asoc.heart_beat_delay = 0;
5402 /* Turn back on the timer */
5403 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5404 if (paddrp->spp_hbinterval != 0) {
5405 net->heart_beat_delay = paddrp->spp_hbinterval;
5406 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5407 net->heart_beat_delay = 0;
5409 if (net->dest_state & SCTP_ADDR_NOHB) {
5410 net->dest_state &= ~SCTP_ADDR_NOHB;
5412 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5413 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5414 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5416 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5418 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5419 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5420 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5421 net->dest_state |= SCTP_ADDR_NOHB;
5422 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5423 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5425 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5429 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5431 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5432 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5433 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5434 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5435 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5437 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5438 net->mtu = paddrp->spp_pathmtu;
5439 switch (net->ro._l_addr.sa.sa_family) {
5442 net->mtu += SCTP_MIN_V4_OVERHEAD;
5447 net->mtu += SCTP_MIN_OVERHEAD;
5453 if (net->mtu < stcb->asoc.smallest_mtu) {
5454 sctp_pathmtu_adjustment(stcb, net->mtu);
5457 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5459 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5460 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5461 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5462 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5464 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5466 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5468 if (paddrp->spp_flags & SPP_DSCP) {
5469 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5470 net->dscp = paddrp->spp_dscp & 0xfc;
5473 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5474 stcb->asoc.default_dscp |= 0x01;
5477 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5478 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5479 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5480 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5481 net->flowlabel |= 0x80000000;
5484 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5485 stcb->asoc.default_flowlabel |= 0x80000000;
5489 SCTP_TCB_UNLOCK(stcb);
5491 /************************NO TCB, SET TO default stuff ******************/
5492 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5493 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5494 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5495 SCTP_INP_WLOCK(inp);
5497 * For the TOS/FLOWLABEL stuff you
5498 * set it with the options on the
5501 if (paddrp->spp_pathmaxrxt != 0) {
5502 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5504 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5505 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5506 else if (paddrp->spp_hbinterval != 0) {
5507 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5508 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5509 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5511 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5512 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5513 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5514 } else if (paddrp->spp_hbinterval) {
5515 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5517 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5518 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5519 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5521 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5522 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5523 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5524 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5526 if (paddrp->spp_flags & SPP_DSCP) {
5527 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5528 inp->sctp_ep.default_dscp |= 0x01;
5531 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5532 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5533 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5534 inp->sctp_ep.default_flowlabel |= 0x80000000;
5538 SCTP_INP_WUNLOCK(inp);
5540 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5548 struct sctp_rtoinfo *srto;
5549 uint32_t new_init, new_min, new_max;
5551 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5552 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5555 if (srto->srto_initial)
5556 new_init = srto->srto_initial;
5558 new_init = stcb->asoc.initial_rto;
5560 new_max = srto->srto_max;
5562 new_max = stcb->asoc.maxrto;
5564 new_min = srto->srto_min;
5566 new_min = stcb->asoc.minrto;
5567 if ((new_min <= new_init) && (new_init <= new_max)) {
5568 stcb->asoc.initial_rto = new_init;
5569 stcb->asoc.maxrto = new_max;
5570 stcb->asoc.minrto = new_min;
5572 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5575 SCTP_TCB_UNLOCK(stcb);
5577 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5578 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5579 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5580 SCTP_INP_WLOCK(inp);
5581 if (srto->srto_initial)
5582 new_init = srto->srto_initial;
5584 new_init = inp->sctp_ep.initial_rto;
5586 new_max = srto->srto_max;
5588 new_max = inp->sctp_ep.sctp_maxrto;
5590 new_min = srto->srto_min;
5592 new_min = inp->sctp_ep.sctp_minrto;
5593 if ((new_min <= new_init) && (new_init <= new_max)) {
5594 inp->sctp_ep.initial_rto = new_init;
5595 inp->sctp_ep.sctp_maxrto = new_max;
5596 inp->sctp_ep.sctp_minrto = new_min;
5598 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5601 SCTP_INP_WUNLOCK(inp);
5603 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5609 case SCTP_ASSOCINFO:
5611 struct sctp_assocparams *sasoc;
5613 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5614 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5615 if (sasoc->sasoc_cookie_life) {
5616 /* boundary check the cookie life */
5617 if (sasoc->sasoc_cookie_life < 1000)
5618 sasoc->sasoc_cookie_life = 1000;
5619 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5620 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5624 if (sasoc->sasoc_asocmaxrxt)
5625 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5626 if (sasoc->sasoc_cookie_life) {
5627 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5629 SCTP_TCB_UNLOCK(stcb);
5631 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5632 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5633 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5634 SCTP_INP_WLOCK(inp);
5635 if (sasoc->sasoc_asocmaxrxt)
5636 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5637 if (sasoc->sasoc_cookie_life) {
5638 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5640 SCTP_INP_WUNLOCK(inp);
5642 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5650 struct sctp_initmsg *sinit;
5652 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5653 SCTP_INP_WLOCK(inp);
5654 if (sinit->sinit_num_ostreams)
5655 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5657 if (sinit->sinit_max_instreams)
5658 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5660 if (sinit->sinit_max_attempts)
5661 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5663 if (sinit->sinit_max_init_timeo)
5664 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5665 SCTP_INP_WUNLOCK(inp);
5668 case SCTP_PRIMARY_ADDR:
5670 struct sctp_setprim *spa;
5671 struct sctp_nets *net;
5672 struct sockaddr *addr;
5674 #if defined(INET) && defined(INET6)
5675 struct sockaddr_in sin_store;
5679 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5680 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5682 #if defined(INET) && defined(INET6)
5683 if (spa->ssp_addr.ss_family == AF_INET6) {
5684 struct sockaddr_in6 *sin6;
5686 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5687 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5688 in6_sin6_2_sin(&sin_store, sin6);
5689 addr = (struct sockaddr *)&sin_store;
5691 addr = (struct sockaddr *)&spa->ssp_addr;
5694 addr = (struct sockaddr *)&spa->ssp_addr;
5697 addr = (struct sockaddr *)&spa->ssp_addr;
5700 net = sctp_findnet(stcb, addr);
5703 * We increment here since
5704 * sctp_findassociation_ep_addr() wil do a
5705 * decrement if it finds the stcb as long as
5706 * the locked tcb (last argument) is NOT a
5710 SCTP_INP_INCR_REF(inp);
5711 stcb = sctp_findassociation_ep_addr(&inp, addr,
5714 SCTP_INP_DECR_REF(inp);
5718 if ((stcb != NULL) && (net != NULL)) {
5719 if (net != stcb->asoc.primary_destination) {
5720 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5721 /* Ok we need to set it */
5722 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5723 if ((stcb->asoc.alternate) &&
5724 (!(net->dest_state & SCTP_ADDR_PF)) &&
5725 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5726 sctp_free_remote_addr(stcb->asoc.alternate);
5727 stcb->asoc.alternate = NULL;
5730 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5734 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5739 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5743 SCTP_TCB_UNLOCK(stcb);
5747 case SCTP_SET_DYNAMIC_PRIMARY:
5749 union sctp_sockstore *ss;
5751 error = priv_check(curthread,
5752 PRIV_NETINET_RESERVEDPORT);
5756 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5757 /* SUPER USER CHECK? */
5758 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5761 case SCTP_SET_PEER_PRIMARY_ADDR:
5763 struct sctp_setpeerprim *sspp;
5764 struct sockaddr *addr;
5766 #if defined(INET) && defined(INET6)
5767 struct sockaddr_in sin_store;
5771 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5772 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5774 struct sctp_ifa *ifa;
5776 #if defined(INET) && defined(INET6)
5777 if (sspp->sspp_addr.ss_family == AF_INET6) {
5778 struct sockaddr_in6 *sin6;
5780 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5781 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5782 in6_sin6_2_sin(&sin_store, sin6);
5783 addr = (struct sockaddr *)&sin_store;
5785 addr = (struct sockaddr *)&sspp->sspp_addr;
5788 addr = (struct sockaddr *)&sspp->sspp_addr;
5791 addr = (struct sockaddr *)&sspp->sspp_addr;
5793 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5795 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5799 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5801 * Must validate the ifa found is in
5804 struct sctp_laddr *laddr;
5807 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5808 if (laddr->ifa == NULL) {
5809 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5813 if (laddr->ifa == ifa) {
5819 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5824 switch (addr->sa_family) {
5828 struct sockaddr_in *sin;
5830 sin = (struct sockaddr_in *)addr;
5831 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5832 &sin->sin_addr) != 0) {
5833 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5843 struct sockaddr_in6 *sin6;
5845 sin6 = (struct sockaddr_in6 *)addr;
5846 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5847 &sin6->sin6_addr) != 0) {
5848 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5856 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5861 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5862 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5866 SCTP_TCB_UNLOCK(stcb);
5868 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5873 case SCTP_BINDX_ADD_ADDR:
5875 struct sctp_getaddresses *addrs;
5878 td = (struct thread *)p;
5879 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5882 if (addrs->addr->sa_family == AF_INET) {
5883 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5884 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5888 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5889 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5895 if (addrs->addr->sa_family == AF_INET6) {
5896 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5897 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5901 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5902 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5903 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5909 error = EAFNOSUPPORT;
5912 sctp_bindx_add_address(so, inp, addrs->addr,
5913 addrs->sget_assoc_id, vrf_id,
5917 case SCTP_BINDX_REM_ADDR:
5919 struct sctp_getaddresses *addrs;
5922 td = (struct thread *)p;
5924 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5926 if (addrs->addr->sa_family == AF_INET) {
5927 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5928 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5932 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5933 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5939 if (addrs->addr->sa_family == AF_INET6) {
5940 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5941 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5946 (error = prison_local_ip6(td->td_ucred,
5947 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5948 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5949 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5955 error = EAFNOSUPPORT;
5958 sctp_bindx_delete_address(inp, addrs->addr,
5959 addrs->sget_assoc_id, vrf_id,
5965 struct sctp_event *event;
5966 uint32_t event_type;
5968 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5969 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5970 switch (event->se_type) {
5971 case SCTP_ASSOC_CHANGE:
5972 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5974 case SCTP_PEER_ADDR_CHANGE:
5975 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5977 case SCTP_REMOTE_ERROR:
5978 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5980 case SCTP_SEND_FAILED:
5981 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5983 case SCTP_SHUTDOWN_EVENT:
5984 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5986 case SCTP_ADAPTATION_INDICATION:
5987 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5989 case SCTP_PARTIAL_DELIVERY_EVENT:
5990 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5992 case SCTP_AUTHENTICATION_EVENT:
5993 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5995 case SCTP_STREAM_RESET_EVENT:
5996 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5998 case SCTP_SENDER_DRY_EVENT:
5999 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6001 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6003 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6006 case SCTP_ASSOC_RESET_EVENT:
6007 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6009 case SCTP_STREAM_CHANGE_EVENT:
6010 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6012 case SCTP_SEND_FAILED_EVENT:
6013 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6017 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6021 if (event_type > 0) {
6024 sctp_stcb_feature_on(inp, stcb, event_type);
6025 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6026 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6027 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6028 (stcb->asoc.stream_queue_cnt == 0)) {
6029 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6033 sctp_stcb_feature_off(inp, stcb, event_type);
6035 SCTP_TCB_UNLOCK(stcb);
6038 * We don't want to send up a storm
6039 * of events, so return an error for
6042 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6043 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6044 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6045 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6046 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6047 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6051 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6052 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6053 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6054 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6055 SCTP_INP_WLOCK(inp);
6057 sctp_feature_on(inp, event_type);
6059 sctp_feature_off(inp, event_type);
6061 SCTP_INP_WUNLOCK(inp);
6063 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6064 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6065 SCTP_INP_RLOCK(inp);
6066 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6067 SCTP_TCB_LOCK(stcb);
6069 sctp_stcb_feature_on(inp, stcb, event_type);
6071 sctp_stcb_feature_off(inp, stcb, event_type);
6073 SCTP_TCB_UNLOCK(stcb);
6075 SCTP_INP_RUNLOCK(inp);
6081 case SCTP_RECVRCVINFO:
6085 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6086 SCTP_INP_WLOCK(inp);
6088 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6090 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6092 SCTP_INP_WUNLOCK(inp);
6095 case SCTP_RECVNXTINFO:
6099 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6100 SCTP_INP_WLOCK(inp);
6102 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6104 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6106 SCTP_INP_WUNLOCK(inp);
6109 case SCTP_DEFAULT_SNDINFO:
6111 struct sctp_sndinfo *info;
6114 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6115 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6118 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6119 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6120 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6121 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6122 stcb->asoc.def_send.sinfo_flags |= policy;
6123 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6124 stcb->asoc.def_send.sinfo_context = info->snd_context;
6126 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6129 SCTP_TCB_UNLOCK(stcb);
6131 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6132 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6133 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6134 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6135 SCTP_INP_WLOCK(inp);
6136 inp->def_send.sinfo_stream = info->snd_sid;
6137 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6138 inp->def_send.sinfo_flags = info->snd_flags;
6139 inp->def_send.sinfo_flags |= policy;
6140 inp->def_send.sinfo_ppid = info->snd_ppid;
6141 inp->def_send.sinfo_context = info->snd_context;
6142 SCTP_INP_WUNLOCK(inp);
6144 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6145 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6146 SCTP_INP_RLOCK(inp);
6147 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6148 SCTP_TCB_LOCK(stcb);
6149 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6150 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6151 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6152 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6153 stcb->asoc.def_send.sinfo_flags |= policy;
6154 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6155 stcb->asoc.def_send.sinfo_context = info->snd_context;
6157 SCTP_TCB_UNLOCK(stcb);
6159 SCTP_INP_RUNLOCK(inp);
6164 case SCTP_DEFAULT_PRINFO:
6166 struct sctp_default_prinfo *info;
6168 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6169 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6171 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6172 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6177 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6178 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6179 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6180 SCTP_TCB_UNLOCK(stcb);
6182 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6183 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6184 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6185 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6186 SCTP_INP_WLOCK(inp);
6187 inp->def_send.sinfo_flags &= 0xfff0;
6188 inp->def_send.sinfo_flags |= info->pr_policy;
6189 inp->def_send.sinfo_timetolive = info->pr_value;
6190 SCTP_INP_WUNLOCK(inp);
6192 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6193 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6194 SCTP_INP_RLOCK(inp);
6195 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6196 SCTP_TCB_LOCK(stcb);
6197 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6198 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6199 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6200 SCTP_TCB_UNLOCK(stcb);
6202 SCTP_INP_RUNLOCK(inp);
6207 case SCTP_PEER_ADDR_THLDS:
6208 /* Applies to the specific association */
6210 struct sctp_paddrthlds *thlds;
6211 struct sctp_nets *net;
6212 struct sockaddr *addr;
6214 #if defined(INET) && defined(INET6)
6215 struct sockaddr_in sin_store;
6219 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6220 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6222 #if defined(INET) && defined(INET6)
6223 if (thlds->spt_address.ss_family == AF_INET6) {
6224 struct sockaddr_in6 *sin6;
6226 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6227 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6228 in6_sin6_2_sin(&sin_store, sin6);
6229 addr = (struct sockaddr *)&sin_store;
6231 addr = (struct sockaddr *)&thlds->spt_address;
6234 addr = (struct sockaddr *)&thlds->spt_address;
6237 addr = (struct sockaddr *)&thlds->spt_address;
6240 net = sctp_findnet(stcb, addr);
6243 * We increment here since
6244 * sctp_findassociation_ep_addr() wil do a
6245 * decrement if it finds the stcb as long as
6246 * the locked tcb (last argument) is NOT a
6250 SCTP_INP_INCR_REF(inp);
6251 stcb = sctp_findassociation_ep_addr(&inp, addr,
6254 SCTP_INP_DECR_REF(inp);
6257 if ((stcb != NULL) && (net == NULL)) {
6259 if (addr->sa_family == AF_INET) {
6261 struct sockaddr_in *sin;
6263 sin = (struct sockaddr_in *)addr;
6264 if (sin->sin_addr.s_addr != INADDR_ANY) {
6265 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6266 SCTP_TCB_UNLOCK(stcb);
6273 if (addr->sa_family == AF_INET6) {
6274 struct sockaddr_in6 *sin6;
6276 sin6 = (struct sockaddr_in6 *)addr;
6277 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6278 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6279 SCTP_TCB_UNLOCK(stcb);
6286 error = EAFNOSUPPORT;
6287 SCTP_TCB_UNLOCK(stcb);
6288 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6294 net->failure_threshold = thlds->spt_pathmaxrxt;
6295 net->pf_threshold = thlds->spt_pathpfthld;
6296 if (net->dest_state & SCTP_ADDR_PF) {
6297 if ((net->error_count > net->failure_threshold) ||
6298 (net->error_count <= net->pf_threshold)) {
6299 net->dest_state &= ~SCTP_ADDR_PF;
6302 if ((net->error_count > net->pf_threshold) &&
6303 (net->error_count <= net->failure_threshold)) {
6304 net->dest_state |= SCTP_ADDR_PF;
6305 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6306 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6307 stcb->sctp_ep, stcb, net,
6308 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6309 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6312 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6313 if (net->error_count > net->failure_threshold) {
6314 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6315 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6318 if (net->error_count <= net->failure_threshold) {
6319 net->dest_state |= SCTP_ADDR_REACHABLE;
6320 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6324 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6325 net->failure_threshold = thlds->spt_pathmaxrxt;
6326 net->pf_threshold = thlds->spt_pathpfthld;
6327 if (net->dest_state & SCTP_ADDR_PF) {
6328 if ((net->error_count > net->failure_threshold) ||
6329 (net->error_count <= net->pf_threshold)) {
6330 net->dest_state &= ~SCTP_ADDR_PF;
6333 if ((net->error_count > net->pf_threshold) &&
6334 (net->error_count <= net->failure_threshold)) {
6335 net->dest_state |= SCTP_ADDR_PF;
6336 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6337 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6338 stcb->sctp_ep, stcb, net,
6339 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6340 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6343 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6344 if (net->error_count > net->failure_threshold) {
6345 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6346 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6349 if (net->error_count <= net->failure_threshold) {
6350 net->dest_state |= SCTP_ADDR_REACHABLE;
6351 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6355 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6356 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6358 SCTP_TCB_UNLOCK(stcb);
6360 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6361 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6362 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6363 SCTP_INP_WLOCK(inp);
6364 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6365 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6366 SCTP_INP_WUNLOCK(inp);
6368 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6374 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6376 struct sctp_udpencaps *encaps;
6377 struct sctp_nets *net;
6378 struct sockaddr *addr;
6380 #if defined(INET) && defined(INET6)
6381 struct sockaddr_in sin_store;
6385 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6386 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6388 #if defined(INET) && defined(INET6)
6389 if (encaps->sue_address.ss_family == AF_INET6) {
6390 struct sockaddr_in6 *sin6;
6392 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6393 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6394 in6_sin6_2_sin(&sin_store, sin6);
6395 addr = (struct sockaddr *)&sin_store;
6397 addr = (struct sockaddr *)&encaps->sue_address;
6400 addr = (struct sockaddr *)&encaps->sue_address;
6403 addr = (struct sockaddr *)&encaps->sue_address;
6406 net = sctp_findnet(stcb, addr);
6409 * We increment here since
6410 * sctp_findassociation_ep_addr() wil do a
6411 * decrement if it finds the stcb as long as
6412 * the locked tcb (last argument) is NOT a
6416 SCTP_INP_INCR_REF(inp);
6417 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6419 SCTP_INP_DECR_REF(inp);
6422 if ((stcb != NULL) && (net == NULL)) {
6424 if (addr->sa_family == AF_INET) {
6426 struct sockaddr_in *sin;
6428 sin = (struct sockaddr_in *)addr;
6429 if (sin->sin_addr.s_addr != INADDR_ANY) {
6430 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6431 SCTP_TCB_UNLOCK(stcb);
6438 if (addr->sa_family == AF_INET6) {
6439 struct sockaddr_in6 *sin6;
6441 sin6 = (struct sockaddr_in6 *)addr;
6442 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6443 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6444 SCTP_TCB_UNLOCK(stcb);
6451 error = EAFNOSUPPORT;
6452 SCTP_TCB_UNLOCK(stcb);
6453 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6459 net->port = encaps->sue_port;
6461 stcb->asoc.port = encaps->sue_port;
6463 SCTP_TCB_UNLOCK(stcb);
6465 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6466 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6467 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6468 SCTP_INP_WLOCK(inp);
6469 inp->sctp_ep.port = encaps->sue_port;
6470 SCTP_INP_WUNLOCK(inp);
6472 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6478 case SCTP_ECN_SUPPORTED:
6480 struct sctp_assoc_value *av;
6482 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6483 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6486 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6488 SCTP_TCB_UNLOCK(stcb);
6490 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6491 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6492 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6493 SCTP_INP_WLOCK(inp);
6494 if (av->assoc_value == 0) {
6495 inp->ecn_supported = 0;
6497 inp->ecn_supported = 1;
6499 SCTP_INP_WUNLOCK(inp);
6501 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6507 case SCTP_PR_SUPPORTED:
6509 struct sctp_assoc_value *av;
6511 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6512 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6515 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6517 SCTP_TCB_UNLOCK(stcb);
6519 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6520 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6521 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6522 SCTP_INP_WLOCK(inp);
6523 if (av->assoc_value == 0) {
6524 inp->prsctp_supported = 0;
6526 inp->prsctp_supported = 1;
6528 SCTP_INP_WUNLOCK(inp);
6530 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6536 case SCTP_AUTH_SUPPORTED:
6538 struct sctp_assoc_value *av;
6540 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6541 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6544 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6546 SCTP_TCB_UNLOCK(stcb);
6548 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6549 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6550 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6551 if ((av->assoc_value == 0) &&
6552 (inp->asconf_supported == 1)) {
6554 * AUTH is required for
6557 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6560 SCTP_INP_WLOCK(inp);
6561 if (av->assoc_value == 0) {
6562 inp->auth_supported = 0;
6564 inp->auth_supported = 1;
6566 SCTP_INP_WUNLOCK(inp);
6569 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6575 case SCTP_ASCONF_SUPPORTED:
6577 struct sctp_assoc_value *av;
6579 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6580 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6583 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6585 SCTP_TCB_UNLOCK(stcb);
6587 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6588 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6589 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6590 if ((av->assoc_value != 0) &&
6591 (inp->auth_supported == 0)) {
6593 * AUTH is required for
6596 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6599 SCTP_INP_WLOCK(inp);
6600 if (av->assoc_value == 0) {
6601 inp->asconf_supported = 0;
6602 sctp_auth_delete_chunk(SCTP_ASCONF,
6603 inp->sctp_ep.local_auth_chunks);
6604 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6605 inp->sctp_ep.local_auth_chunks);
6607 inp->asconf_supported = 1;
6608 sctp_auth_add_chunk(SCTP_ASCONF,
6609 inp->sctp_ep.local_auth_chunks);
6610 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6611 inp->sctp_ep.local_auth_chunks);
6613 SCTP_INP_WUNLOCK(inp);
6616 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6622 case SCTP_RECONFIG_SUPPORTED:
6624 struct sctp_assoc_value *av;
6626 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6627 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6630 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6632 SCTP_TCB_UNLOCK(stcb);
6634 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6635 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6636 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6637 SCTP_INP_WLOCK(inp);
6638 if (av->assoc_value == 0) {
6639 inp->reconfig_supported = 0;
6641 inp->reconfig_supported = 1;
6643 SCTP_INP_WUNLOCK(inp);
6645 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6651 case SCTP_NRSACK_SUPPORTED:
6653 struct sctp_assoc_value *av;
6655 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6656 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6659 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6661 SCTP_TCB_UNLOCK(stcb);
6663 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6664 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6665 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6666 SCTP_INP_WLOCK(inp);
6667 if (av->assoc_value == 0) {
6668 inp->nrsack_supported = 0;
6670 inp->nrsack_supported = 1;
6672 SCTP_INP_WUNLOCK(inp);
6674 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6680 case SCTP_PKTDROP_SUPPORTED:
6682 struct sctp_assoc_value *av;
6684 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6685 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6688 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6690 SCTP_TCB_UNLOCK(stcb);
6692 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6693 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6694 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6695 SCTP_INP_WLOCK(inp);
6696 if (av->assoc_value == 0) {
6697 inp->pktdrop_supported = 0;
6699 inp->pktdrop_supported = 1;
6701 SCTP_INP_WUNLOCK(inp);
6703 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6711 struct sctp_assoc_value *av;
6712 struct sctp_nets *net;
6714 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6715 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6718 stcb->asoc.max_cwnd = av->assoc_value;
6719 if (stcb->asoc.max_cwnd > 0) {
6720 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6721 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6722 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6723 net->cwnd = stcb->asoc.max_cwnd;
6724 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6725 net->cwnd = net->mtu - sizeof(struct sctphdr);
6730 SCTP_TCB_UNLOCK(stcb);
6732 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6733 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6734 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6735 SCTP_INP_WLOCK(inp);
6736 inp->max_cwnd = av->assoc_value;
6737 SCTP_INP_WUNLOCK(inp);
6739 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6746 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6747 error = ENOPROTOOPT;
6749 } /* end switch (opt) */
6754 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6756 void *optval = NULL;
6760 struct sctp_inpcb *inp;
6762 if ((sopt->sopt_level == SOL_SOCKET) &&
6763 (sopt->sopt_name == SO_SETFIB)) {
6764 inp = (struct sctp_inpcb *)so->so_pcb;
6766 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6769 SCTP_INP_WLOCK(inp);
6770 inp->fibnum = so->so_fibnum;
6771 SCTP_INP_WUNLOCK(inp);
6774 if (sopt->sopt_level != IPPROTO_SCTP) {
6775 /* wrong proto level... send back up to IP */
6777 if (INP_CHECK_SOCKAF(so, AF_INET6))
6778 error = ip6_ctloutput(so, sopt);
6780 #if defined(INET) && defined(INET6)
6784 error = ip_ctloutput(so, sopt);
6788 optsize = sopt->sopt_valsize;
6790 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6791 if (optval == NULL) {
6792 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6795 error = sooptcopyin(sopt, optval, optsize, optsize);
6797 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6801 p = (void *)sopt->sopt_td;
6802 if (sopt->sopt_dir == SOPT_SET) {
6803 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6804 } else if (sopt->sopt_dir == SOPT_GET) {
6805 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6807 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6810 if ((error == 0) && (optval != NULL)) {
6811 error = sooptcopyout(sopt, optval, optsize);
6812 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6813 } else if (optval != NULL) {
6814 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6822 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6825 int create_lock_on = 0;
6827 struct sctp_inpcb *inp;
6828 struct sctp_tcb *stcb = NULL;
6830 inp = (struct sctp_inpcb *)so->so_pcb;
6832 /* I made the same as TCP since we are not setup? */
6833 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6834 return (ECONNRESET);
6837 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6840 switch (addr->sa_family) {
6844 struct sockaddr_in6 *sin6p;
6846 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6847 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6850 sin6p = (struct sockaddr_in6 *)addr;
6851 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6852 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6861 struct sockaddr_in *sinp;
6863 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6864 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6867 sinp = (struct sockaddr_in *)addr;
6868 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6869 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6876 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6877 return (EAFNOSUPPORT);
6879 SCTP_INP_INCR_REF(inp);
6880 SCTP_ASOC_CREATE_LOCK(inp);
6884 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6885 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6886 /* Should I really unlock ? */
6887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6892 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6893 (addr->sa_family == AF_INET6)) {
6894 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6899 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6900 SCTP_PCB_FLAGS_UNBOUND) {
6901 /* Bind a ephemeral port */
6902 error = sctp_inpcb_bind(so, NULL, NULL, p);
6907 /* Now do we connect? */
6908 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6909 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6910 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6914 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6915 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6916 /* We are already connected AND the TCP model */
6917 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6921 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6922 SCTP_INP_RLOCK(inp);
6923 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6924 SCTP_INP_RUNLOCK(inp);
6927 * We increment here since sctp_findassociation_ep_addr()
6928 * will do a decrement if it finds the stcb as long as the
6929 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6931 SCTP_INP_INCR_REF(inp);
6932 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6934 SCTP_INP_DECR_REF(inp);
6936 SCTP_TCB_UNLOCK(stcb);
6940 /* Already have or am bring up an association */
6941 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
6945 vrf_id = inp->def_vrf_id;
6946 /* We are GOOD to go */
6947 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, inp->sctp_ep.pre_open_stream_count, p);
6949 /* Gak! no memory */
6952 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
6953 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
6954 /* Set the connected flag so we can queue data */
6957 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
6958 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
6960 /* initialize authentication parameters for the assoc */
6961 sctp_initialize_auth_params(inp, stcb);
6963 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
6964 SCTP_TCB_UNLOCK(stcb);
6966 if (create_lock_on) {
6967 SCTP_ASOC_CREATE_UNLOCK(inp);
6969 SCTP_INP_DECR_REF(inp);
6976 sctp_listen(struct socket *so, int backlog, struct thread *p)
6979 * Note this module depends on the protocol processing being called
6980 * AFTER any socket level flags and backlog are applied to the
6981 * socket. The traditional way that the socket flags are applied is
6982 * AFTER protocol processing. We have made a change to the
6983 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
6984 * place if the socket API for SCTP is to work properly.
6988 struct sctp_inpcb *inp;
6990 inp = (struct sctp_inpcb *)so->so_pcb;
6992 /* I made the same as TCP since we are not setup? */
6993 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6994 return (ECONNRESET);
6996 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
6997 /* See if we have a listener */
6998 struct sctp_inpcb *tinp;
6999 union sctp_sockstore store;
7001 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7003 struct sctp_laddr *laddr;
7005 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7006 memcpy(&store, &laddr->ifa->address, sizeof(store));
7007 switch (store.sa.sa_family) {
7010 store.sin.sin_port = inp->sctp_lport;
7015 store.sin6.sin6_port = inp->sctp_lport;
7021 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7022 if (tinp && (tinp != inp) &&
7023 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7024 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7025 (tinp->sctp_socket->so_qlimit)) {
7027 * we have a listener already and
7030 SCTP_INP_DECR_REF(tinp);
7031 return (EADDRINUSE);
7033 SCTP_INP_DECR_REF(tinp);
7037 /* Setup a local addr bound all */
7038 memset(&store, 0, sizeof(store));
7040 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7041 store.sa.sa_family = AF_INET6;
7042 store.sa.sa_len = sizeof(struct sockaddr_in6);
7046 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7047 store.sa.sa_family = AF_INET;
7048 store.sa.sa_len = sizeof(struct sockaddr_in);
7051 switch (store.sa.sa_family) {
7054 store.sin.sin_port = inp->sctp_lport;
7059 store.sin6.sin6_port = inp->sctp_lport;
7065 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7066 if (tinp && (tinp != inp) &&
7067 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7068 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7069 (tinp->sctp_socket->so_qlimit)) {
7071 * we have a listener already and its not
7074 SCTP_INP_DECR_REF(tinp);
7075 return (EADDRINUSE);
7077 SCTP_INP_DECR_REF(tinp);
7081 SCTP_INP_RLOCK(inp);
7082 #ifdef SCTP_LOCK_LOGGING
7083 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7084 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7088 error = solisten_proto_check(so);
7091 SCTP_INP_RUNLOCK(inp);
7094 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7095 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7097 * The unlucky case - We are in the tcp pool with this guy.
7098 * - Someone else is in the main inp slot. - We must move
7099 * this guy (the listener) to the main slot - We must then
7100 * move the guy that was listener to the TCP Pool.
7102 if (sctp_swap_inpcb_for_listen(inp)) {
7103 SCTP_INP_RUNLOCK(inp);
7104 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7105 return (EADDRINUSE);
7108 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7109 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7110 /* We are already connected AND the TCP model */
7111 SCTP_INP_RUNLOCK(inp);
7112 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7113 return (EADDRINUSE);
7115 SCTP_INP_RUNLOCK(inp);
7116 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7117 /* We must do a bind. */
7118 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7119 /* bind error, probably perm */
7124 /* It appears for 7.0 and on, we must always call this. */
7125 solisten_proto(so, backlog);
7126 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7127 /* remove the ACCEPTCONN flag for one-to-many sockets */
7128 so->so_options &= ~SO_ACCEPTCONN;
7131 /* turning off listen */
7132 so->so_options &= ~SO_ACCEPTCONN;
7138 static int sctp_defered_wakeup_cnt = 0;
7141 sctp_accept(struct socket *so, struct sockaddr **addr)
7143 struct sctp_tcb *stcb;
7144 struct sctp_inpcb *inp;
7145 union sctp_sockstore store;
7151 inp = (struct sctp_inpcb *)so->so_pcb;
7154 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7155 return (ECONNRESET);
7157 SCTP_INP_RLOCK(inp);
7158 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7159 SCTP_INP_RUNLOCK(inp);
7160 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7161 return (EOPNOTSUPP);
7163 if (so->so_state & SS_ISDISCONNECTED) {
7164 SCTP_INP_RUNLOCK(inp);
7165 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7166 return (ECONNABORTED);
7168 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7170 SCTP_INP_RUNLOCK(inp);
7171 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7172 return (ECONNRESET);
7174 SCTP_TCB_LOCK(stcb);
7175 SCTP_INP_RUNLOCK(inp);
7176 store = stcb->asoc.primary_destination->ro._l_addr;
7177 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
7178 SCTP_TCB_UNLOCK(stcb);
7179 switch (store.sa.sa_family) {
7183 struct sockaddr_in *sin;
7185 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7188 sin->sin_family = AF_INET;
7189 sin->sin_len = sizeof(*sin);
7190 sin->sin_port = store.sin.sin_port;
7191 sin->sin_addr = store.sin.sin_addr;
7192 *addr = (struct sockaddr *)sin;
7199 struct sockaddr_in6 *sin6;
7201 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7204 sin6->sin6_family = AF_INET6;
7205 sin6->sin6_len = sizeof(*sin6);
7206 sin6->sin6_port = store.sin6.sin6_port;
7207 sin6->sin6_addr = store.sin6.sin6_addr;
7208 if ((error = sa6_recoverscope(sin6)) != 0) {
7209 SCTP_FREE_SONAME(sin6);
7212 *addr = (struct sockaddr *)sin6;
7220 /* Wake any delayed sleep action */
7221 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7222 SCTP_INP_WLOCK(inp);
7223 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7224 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7225 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7226 SCTP_INP_WUNLOCK(inp);
7227 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7228 if (sowriteable(inp->sctp_socket)) {
7229 sowwakeup_locked(inp->sctp_socket);
7231 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7233 SCTP_INP_WLOCK(inp);
7235 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7236 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7237 SCTP_INP_WUNLOCK(inp);
7238 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7239 if (soreadable(inp->sctp_socket)) {
7240 sctp_defered_wakeup_cnt++;
7241 sorwakeup_locked(inp->sctp_socket);
7243 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7245 SCTP_INP_WLOCK(inp);
7247 SCTP_INP_WUNLOCK(inp);
7249 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7250 SCTP_TCB_LOCK(stcb);
7251 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7252 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7259 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7261 struct sockaddr_in *sin;
7263 struct sctp_inpcb *inp;
7264 struct sctp_ifa *sctp_ifa;
7267 * Do the malloc first in case it blocks.
7269 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7272 sin->sin_family = AF_INET;
7273 sin->sin_len = sizeof(*sin);
7274 inp = (struct sctp_inpcb *)so->so_pcb;
7276 SCTP_FREE_SONAME(sin);
7277 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7278 return (ECONNRESET);
7280 SCTP_INP_RLOCK(inp);
7281 sin->sin_port = inp->sctp_lport;
7282 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7283 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7284 struct sctp_tcb *stcb;
7285 struct sockaddr_in *sin_a;
7286 struct sctp_nets *net;
7289 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7295 SCTP_TCB_LOCK(stcb);
7296 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7297 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7299 /* this will make coverity happy */
7302 if (sin_a->sin_family == AF_INET) {
7307 if ((!fnd) || (sin_a == NULL)) {
7309 SCTP_TCB_UNLOCK(stcb);
7312 vrf_id = inp->def_vrf_id;
7313 sctp_ifa = sctp_source_address_selection(inp,
7315 (sctp_route_t *) & net->ro,
7318 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7319 sctp_free_ifa(sctp_ifa);
7321 SCTP_TCB_UNLOCK(stcb);
7323 /* For the bound all case you get back 0 */
7325 sin->sin_addr.s_addr = 0;
7329 /* Take the first IPv4 address in the list */
7330 struct sctp_laddr *laddr;
7333 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7334 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7335 struct sockaddr_in *sin_a;
7337 sin_a = &laddr->ifa->address.sin;
7338 sin->sin_addr = sin_a->sin_addr;
7344 SCTP_FREE_SONAME(sin);
7345 SCTP_INP_RUNLOCK(inp);
7346 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7350 SCTP_INP_RUNLOCK(inp);
7351 (*addr) = (struct sockaddr *)sin;
7356 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7358 struct sockaddr_in *sin;
7360 struct sockaddr_in *sin_a;
7361 struct sctp_inpcb *inp;
7362 struct sctp_tcb *stcb;
7363 struct sctp_nets *net;
7365 /* Do the malloc first in case it blocks. */
7366 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7369 sin->sin_family = AF_INET;
7370 sin->sin_len = sizeof(*sin);
7372 inp = (struct sctp_inpcb *)so->so_pcb;
7373 if ((inp == NULL) ||
7374 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7375 /* UDP type and listeners will drop out here */
7376 SCTP_FREE_SONAME(sin);
7377 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7380 SCTP_INP_RLOCK(inp);
7381 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7383 SCTP_TCB_LOCK(stcb);
7385 SCTP_INP_RUNLOCK(inp);
7387 SCTP_FREE_SONAME(sin);
7388 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7389 return (ECONNRESET);
7392 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7393 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7394 if (sin_a->sin_family == AF_INET) {
7396 sin->sin_port = stcb->rport;
7397 sin->sin_addr = sin_a->sin_addr;
7401 SCTP_TCB_UNLOCK(stcb);
7403 /* No IPv4 address */
7404 SCTP_FREE_SONAME(sin);
7405 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7408 (*addr) = (struct sockaddr *)sin;
7412 struct pr_usrreqs sctp_usrreqs = {
7413 .pru_abort = sctp_abort,
7414 .pru_accept = sctp_accept,
7415 .pru_attach = sctp_attach,
7416 .pru_bind = sctp_bind,
7417 .pru_connect = sctp_connect,
7418 .pru_control = in_control,
7419 .pru_close = sctp_close,
7420 .pru_detach = sctp_close,
7421 .pru_sopoll = sopoll_generic,
7422 .pru_flush = sctp_flush,
7423 .pru_disconnect = sctp_disconnect,
7424 .pru_listen = sctp_listen,
7425 .pru_peeraddr = sctp_peeraddr,
7426 .pru_send = sctp_sendm,
7427 .pru_shutdown = sctp_shutdown,
7428 .pru_sockaddr = sctp_ingetaddr,
7429 .pru_sosend = sctp_sosend,
7430 .pru_soreceive = sctp_soreceive