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 const struct sctp_cc_functions sctp_cc_functions[];
58 extern const 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 (uint32_t) (uintptr_t) chk->whoTo,
136 chk->rec.data.TSN_seq);
138 /* Clear any time so NO RTT is being done */
147 sctp_notify(struct sctp_inpcb *inp,
148 struct sctp_tcb *stcb,
149 struct sctp_nets *net,
155 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
161 if (icmp_type != ICMP_UNREACH) {
162 /* We only care about unreachable */
163 SCTP_TCB_UNLOCK(stcb);
166 if ((icmp_code == ICMP_UNREACH_NET) ||
167 (icmp_code == ICMP_UNREACH_HOST) ||
168 (icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
169 (icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
170 (icmp_code == ICMP_UNREACH_ISOLATED) ||
171 (icmp_code == ICMP_UNREACH_NET_PROHIB) ||
172 (icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
173 (icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
174 /* Mark the net unreachable. */
175 if (net->dest_state & SCTP_ADDR_REACHABLE) {
176 /* OK, that destination is NOT reachable. */
177 net->dest_state &= ~SCTP_ADDR_REACHABLE;
178 net->dest_state &= ~SCTP_ADDR_PF;
179 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
181 (void *)net, SCTP_SO_NOT_LOCKED);
183 SCTP_TCB_UNLOCK(stcb);
184 } else if ((icmp_code == ICMP_UNREACH_PROTOCOL) ||
185 (icmp_code == ICMP_UNREACH_PORT)) {
186 /* Treat it like an ABORT. */
187 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
188 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
189 so = SCTP_INP_SO(inp);
190 atomic_add_int(&stcb->asoc.refcnt, 1);
191 SCTP_TCB_UNLOCK(stcb);
192 SCTP_SOCKET_LOCK(so, 1);
194 atomic_subtract_int(&stcb->asoc.refcnt, 1);
196 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
197 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
198 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
199 SCTP_SOCKET_UNLOCK(so, 1);
200 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
202 /* no need to unlock here, since the TCB is gone */
203 } else if (icmp_code == ICMP_UNREACH_NEEDFRAG) {
204 /* Find the next (smaller) MTU */
207 * Old type router that does not tell us what the
208 * next MTU is. Rats we will have to guess (in a
209 * educated fashion of course).
211 next_mtu = sctp_get_prev_mtu(ip_len);
213 /* Stop the PMTU timer. */
214 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
216 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
217 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
221 /* Update the path MTU. */
222 if (net->mtu > next_mtu) {
225 net->mtu -= sizeof(struct udphdr);
228 /* Update the association MTU */
229 if (stcb->asoc.smallest_mtu > next_mtu) {
230 sctp_pathmtu_adjustment(stcb, next_mtu);
232 /* Finally, start the PMTU timer if it was running before. */
234 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
236 SCTP_TCB_UNLOCK(stcb);
238 SCTP_TCB_UNLOCK(stcb);
243 sctp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
245 struct ip *outer_ip, *inner_ip;
248 struct sctp_inpcb *inp;
249 struct sctp_tcb *stcb;
250 struct sctp_nets *net;
251 struct sctp_init_chunk *ch;
252 struct sockaddr_in src, dst;
254 if (sa->sa_family != AF_INET ||
255 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
258 if (PRC_IS_REDIRECT(cmd)) {
260 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
264 inner_ip = (struct ip *)vip;
265 icmp = (struct icmp *)((caddr_t)inner_ip -
266 (sizeof(struct icmp) - sizeof(struct ip)));
267 outer_ip = (struct ip *)((caddr_t)icmp - sizeof(struct ip));
268 sh = (struct sctphdr *)((caddr_t)inner_ip + (inner_ip->ip_hl << 2));
269 memset(&src, 0, sizeof(struct sockaddr_in));
270 src.sin_family = AF_INET;
271 src.sin_len = sizeof(struct sockaddr_in);
272 src.sin_port = sh->src_port;
273 src.sin_addr = inner_ip->ip_src;
274 memset(&dst, 0, sizeof(struct sockaddr_in));
275 dst.sin_family = AF_INET;
276 dst.sin_len = sizeof(struct sockaddr_in);
277 dst.sin_port = sh->dest_port;
278 dst.sin_addr = inner_ip->ip_dst;
280 * 'dst' holds the dest of the packet that failed to be
281 * sent. 'src' holds our local endpoint address. Thus we
282 * reverse the dst and the src in the lookup.
286 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst,
287 (struct sockaddr *)&src,
290 if ((stcb != NULL) &&
293 (inp->sctp_socket != NULL)) {
294 /* Check the verification tag */
295 if (ntohl(sh->v_tag) != 0) {
297 * This must be the verification tag used
298 * for sending out packets. We don't
299 * consider packets reflecting the
302 if (ntohl(sh->v_tag) != stcb->asoc.peer_vtag) {
303 SCTP_TCB_UNLOCK(stcb);
307 if (ntohs(outer_ip->ip_len) >=
309 8 + (inner_ip->ip_hl << 2) + 20) {
311 * In this case we can check if we
312 * got an INIT chunk and if the
313 * initiate tag matches.
315 ch = (struct sctp_init_chunk *)(sh + 1);
316 if ((ch->ch.chunk_type != SCTP_INITIATION) ||
317 (ntohl(ch->init.initiate_tag) != stcb->asoc.my_vtag)) {
318 SCTP_TCB_UNLOCK(stcb);
322 SCTP_TCB_UNLOCK(stcb);
326 sctp_notify(inp, stcb, net,
329 ntohs(inner_ip->ip_len),
330 ntohs(icmp->icmp_nextmtu));
332 if ((stcb == NULL) && (inp != NULL)) {
333 /* reduce ref-count */
335 SCTP_INP_DECR_REF(inp);
336 SCTP_INP_WUNLOCK(inp);
339 SCTP_TCB_UNLOCK(stcb);
349 sctp_getcred(SYSCTL_HANDLER_ARGS)
352 struct sockaddr_in addrs[2];
353 struct sctp_inpcb *inp;
354 struct sctp_nets *net;
355 struct sctp_tcb *stcb;
359 /* FIX, for non-bsd is this right? */
360 vrf_id = SCTP_DEFAULT_VRFID;
362 error = priv_check(req->td, PRIV_NETINET_GETCRED);
367 error = SYSCTL_IN(req, addrs, sizeof(addrs));
371 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
373 &inp, &net, 1, vrf_id);
374 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
375 if ((inp != NULL) && (stcb == NULL)) {
376 /* reduce ref-count */
378 SCTP_INP_DECR_REF(inp);
381 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
385 SCTP_TCB_UNLOCK(stcb);
387 * We use the write lock here, only since in the error leg we need
388 * it. If we used RLOCK, then we would have to
389 * wlock/decr/unlock/rlock. Which in theory could create a hole.
390 * Better to use higher wlock.
394 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
396 SCTP_INP_WUNLOCK(inp);
399 cru2x(inp->sctp_socket->so_cred, &xuc);
400 SCTP_INP_WUNLOCK(inp);
401 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
406 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
407 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
412 sctp_abort(struct socket *so)
414 struct sctp_inpcb *inp;
417 inp = (struct sctp_inpcb *)so->so_pcb;
422 flags = inp->sctp_flags;
423 #ifdef SCTP_LOG_CLOSING
424 sctp_log_closing(inp, NULL, 17);
426 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
427 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
428 #ifdef SCTP_LOG_CLOSING
429 sctp_log_closing(inp, NULL, 16);
431 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
432 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
434 SCTP_SB_CLEAR(so->so_snd);
436 * same for the rcv ones, they are only here for the
439 SCTP_SB_CLEAR(so->so_rcv);
441 /* Now null out the reference, we are completely detached. */
445 flags = inp->sctp_flags;
446 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
447 goto sctp_must_try_again;
454 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
456 struct sctp_inpcb *inp;
457 struct inpcb *ip_inp;
459 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
461 inp = (struct sctp_inpcb *)so->so_pcb;
463 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
466 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
467 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
472 error = sctp_inpcb_alloc(so, vrf_id);
476 inp = (struct sctp_inpcb *)so->so_pcb;
478 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
479 ip_inp = &inp->ip_inp.inp;
480 ip_inp->inp_vflag |= INP_IPV4;
481 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
482 SCTP_INP_WUNLOCK(inp);
487 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
489 struct sctp_inpcb *inp;
491 inp = (struct sctp_inpcb *)so->so_pcb;
493 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
497 if ((addr->sa_family != AF_INET) ||
498 (addr->sa_len != sizeof(struct sockaddr_in))) {
499 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
503 return (sctp_inpcb_bind(so, addr, NULL, p));
508 sctp_close(struct socket *so)
510 struct sctp_inpcb *inp;
513 inp = (struct sctp_inpcb *)so->so_pcb;
518 * Inform all the lower layer assoc that we are done.
521 flags = inp->sctp_flags;
522 #ifdef SCTP_LOG_CLOSING
523 sctp_log_closing(inp, NULL, 17);
525 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
526 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
527 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
528 (so->so_rcv.sb_cc > 0)) {
529 #ifdef SCTP_LOG_CLOSING
530 sctp_log_closing(inp, NULL, 13);
532 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
533 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
535 #ifdef SCTP_LOG_CLOSING
536 sctp_log_closing(inp, NULL, 14);
538 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
539 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
542 * The socket is now detached, no matter what the state of
543 * the SCTP association.
546 SCTP_SB_CLEAR(so->so_snd);
548 * same for the rcv ones, they are only here for the
551 SCTP_SB_CLEAR(so->so_rcv);
553 /* Now null out the reference, we are completely detached. */
557 flags = inp->sctp_flags;
558 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
559 goto sctp_must_try_again;
567 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
568 struct mbuf *control, struct thread *p);
572 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
573 struct mbuf *control, struct thread *p)
575 struct sctp_inpcb *inp;
578 inp = (struct sctp_inpcb *)so->so_pcb;
581 sctp_m_freem(control);
584 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
588 /* Got to have an to address if we are NOT a connected socket */
589 if ((addr == NULL) &&
590 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
591 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
593 } else if (addr == NULL) {
594 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
595 error = EDESTADDRREQ;
598 sctp_m_freem(control);
604 if (addr->sa_family != AF_INET) {
605 /* must be a v4 address! */
606 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
609 sctp_m_freem(control);
612 error = EDESTADDRREQ;
617 /* now what about control */
620 SCTP_PRINTF("huh? control set?\n");
621 sctp_m_freem(inp->control);
624 inp->control = control;
628 SCTP_BUF_NEXT(inp->pkt_last) = m;
631 inp->pkt_last = inp->pkt = m;
634 /* FreeBSD uses a flag passed */
635 ((flags & PRUS_MORETOCOME) == 0)
638 * note with the current version this code will only be used
639 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
640 * re-defining sosend to use the sctp_sosend. One can
641 * optionally switch back to this code (by changing back the
642 * definitions) but this is not advisable. This code is used
643 * by FreeBSD when sending a file with sendfile() though.
647 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
657 sctp_disconnect(struct socket *so)
659 struct sctp_inpcb *inp;
661 inp = (struct sctp_inpcb *)so->so_pcb;
663 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
667 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
668 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
669 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
671 SCTP_INP_RUNLOCK(inp);
674 struct sctp_association *asoc;
675 struct sctp_tcb *stcb;
677 stcb = LIST_FIRST(&inp->sctp_asoc_list);
679 SCTP_INP_RUNLOCK(inp);
680 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
685 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
686 /* We are about to be freed, out of here */
687 SCTP_TCB_UNLOCK(stcb);
688 SCTP_INP_RUNLOCK(inp);
691 if (((so->so_options & SO_LINGER) &&
692 (so->so_linger == 0)) ||
693 (so->so_rcv.sb_cc > 0)) {
694 if (SCTP_GET_STATE(asoc) !=
695 SCTP_STATE_COOKIE_WAIT) {
696 /* Left with Data unread */
699 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_NOWAIT, 1, MT_DATA);
705 struct sctp_paramhdr *ph;
707 ph = mtod(err, struct sctp_paramhdr *);
708 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
709 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
710 ph->param_length = htons(SCTP_BUF_LEN(err));
712 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
713 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
715 SCTP_INP_RUNLOCK(inp);
716 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
717 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
718 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
720 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
721 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
722 /* No unlock tcb assoc is gone */
725 if (TAILQ_EMPTY(&asoc->send_queue) &&
726 TAILQ_EMPTY(&asoc->sent_queue) &&
727 (asoc->stream_queue_cnt == 0)) {
728 /* there is nothing queued to send, so done */
729 if (asoc->locked_on_sending) {
732 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
733 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
734 /* only send SHUTDOWN 1st time thru */
735 struct sctp_nets *netp;
737 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
738 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
739 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
741 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
742 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
743 sctp_stop_timers_for_shutdown(stcb);
744 if (stcb->asoc.alternate) {
745 netp = stcb->asoc.alternate;
747 netp = stcb->asoc.primary_destination;
749 sctp_send_shutdown(stcb, netp);
750 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
751 stcb->sctp_ep, stcb, netp);
752 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
753 stcb->sctp_ep, stcb, netp);
754 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
758 * we still got (or just got) data to send,
759 * so set SHUTDOWN_PENDING
762 * XXX sockets draft says that SCTP_EOF
763 * should be sent with no data. currently,
764 * we will allow user data to be sent first
765 * and move to SHUTDOWN-PENDING
767 struct sctp_nets *netp;
769 if (stcb->asoc.alternate) {
770 netp = stcb->asoc.alternate;
772 netp = stcb->asoc.primary_destination;
775 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
776 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
778 if (asoc->locked_on_sending) {
779 /* Locked to send out the data */
780 struct sctp_stream_queue_pending *sp;
782 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
784 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
785 asoc->locked_on_sending->stream_no);
787 if ((sp->length == 0) && (sp->msg_is_complete == 0))
788 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
791 if (TAILQ_EMPTY(&asoc->send_queue) &&
792 TAILQ_EMPTY(&asoc->sent_queue) &&
793 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
797 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
798 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
799 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
800 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
801 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
802 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
803 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
805 SCTP_INP_RUNLOCK(inp);
806 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
807 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
810 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
813 soisdisconnecting(so);
814 SCTP_TCB_UNLOCK(stcb);
815 SCTP_INP_RUNLOCK(inp);
820 /* UDP model does not support this */
821 SCTP_INP_RUNLOCK(inp);
822 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
828 sctp_flush(struct socket *so, int how)
831 * We will just clear out the values and let subsequent close clear
832 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
833 * they will not be able to read the data, the socket will block
834 * that from happening.
836 struct sctp_inpcb *inp;
838 inp = (struct sctp_inpcb *)so->so_pcb;
840 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
844 /* For the 1 to many model this does nothing */
845 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
846 SCTP_INP_RUNLOCK(inp);
849 SCTP_INP_RUNLOCK(inp);
850 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
852 * First make sure the sb will be happy, we don't use these
853 * except maybe the count
856 SCTP_INP_READ_LOCK(inp);
857 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
858 SCTP_INP_READ_UNLOCK(inp);
859 SCTP_INP_WUNLOCK(inp);
860 so->so_rcv.sb_cc = 0;
861 so->so_rcv.sb_mbcnt = 0;
862 so->so_rcv.sb_mb = NULL;
864 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
866 * First make sure the sb will be happy, we don't use these
867 * except maybe the count
869 so->so_snd.sb_cc = 0;
870 so->so_snd.sb_mbcnt = 0;
871 so->so_snd.sb_mb = NULL;
878 sctp_shutdown(struct socket *so)
880 struct sctp_inpcb *inp;
882 inp = (struct sctp_inpcb *)so->so_pcb;
884 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
888 /* For UDP model this is a invalid call */
889 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
890 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
891 /* Restore the flags that the soshutdown took away. */
892 SOCKBUF_LOCK(&so->so_rcv);
893 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
894 SOCKBUF_UNLOCK(&so->so_rcv);
895 /* This proc will wakeup for read and do nothing (I hope) */
896 SCTP_INP_RUNLOCK(inp);
897 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
901 * Ok, if we reach here its the TCP model and it is either a
902 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
905 struct sctp_tcb *stcb;
906 struct sctp_association *asoc;
907 struct sctp_nets *netp;
910 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
911 SCTP_INP_RUNLOCK(inp);
916 stcb = LIST_FIRST(&inp->sctp_asoc_list);
919 * Ok, we hit the case that the shutdown call was
920 * made after an abort or something. Nothing to do
923 SCTP_INP_RUNLOCK(inp);
928 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
929 SCTP_TCB_UNLOCK(stcb);
930 SCTP_INP_RUNLOCK(inp);
933 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_WAIT) &&
934 (SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_ECHOED) &&
935 (SCTP_GET_STATE(asoc) != SCTP_STATE_OPEN)) {
937 * If we are not in or before ESTABLISHED, there is
938 * no protocol action required.
940 SCTP_TCB_UNLOCK(stcb);
941 SCTP_INP_RUNLOCK(inp);
944 if (stcb->asoc.alternate) {
945 netp = stcb->asoc.alternate;
947 netp = stcb->asoc.primary_destination;
949 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) &&
950 TAILQ_EMPTY(&asoc->send_queue) &&
951 TAILQ_EMPTY(&asoc->sent_queue) &&
952 (asoc->stream_queue_cnt == 0)) {
953 if (asoc->locked_on_sending) {
956 /* there is nothing queued to send, so I'm done... */
957 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
958 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
959 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
960 sctp_stop_timers_for_shutdown(stcb);
961 sctp_send_shutdown(stcb, netp);
962 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
963 stcb->sctp_ep, stcb, netp);
966 * We still got (or just got) data to send, so set
969 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
970 if (asoc->locked_on_sending) {
971 /* Locked to send out the data */
972 struct sctp_stream_queue_pending *sp;
974 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
976 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
977 asoc->locked_on_sending->stream_no);
979 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
980 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_PARTIAL_MSG_LEFT);
984 if (TAILQ_EMPTY(&asoc->send_queue) &&
985 TAILQ_EMPTY(&asoc->sent_queue) &&
986 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
990 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
991 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
992 sctp_abort_an_association(stcb->sctp_ep, stcb,
993 op_err, SCTP_SO_LOCKED);
994 SCTP_INP_RUNLOCK(inp);
998 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, netp);
1000 * XXX: Why do this in the case where we have still data
1003 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1004 SCTP_TCB_UNLOCK(stcb);
1005 SCTP_INP_RUNLOCK(inp);
1011 * copies a "user" presentable address and removes embedded scope, etc.
1012 * returns 0 on success, 1 on error
1015 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1018 struct sockaddr_in6 lsa6;
1020 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1023 memcpy(ss, sa, sa->sa_len);
1030 * NOTE: assumes addr lock is held
1033 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1034 struct sctp_tcb *stcb,
1036 struct sockaddr_storage *sas,
1039 struct sctp_ifn *sctp_ifn;
1040 struct sctp_ifa *sctp_ifa;
1045 int ipv4_local_scope, ipv4_addr_legal;
1049 int local_scope, site_scope, ipv6_addr_legal;
1052 struct sctp_vrf *vrf;
1059 /* Turn on all the appropriate scope */
1060 loopback_scope = stcb->asoc.scope.loopback_scope;
1062 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1063 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1066 local_scope = stcb->asoc.scope.local_scope;
1067 site_scope = stcb->asoc.scope.site_scope;
1068 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1071 /* Use generic values for endpoints. */
1074 ipv4_local_scope = 1;
1080 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1082 ipv6_addr_legal = 1;
1085 if (SCTP_IPV6_V6ONLY(inp)) {
1086 ipv4_addr_legal = 0;
1088 ipv4_addr_legal = 1;
1093 ipv6_addr_legal = 0;
1096 ipv4_addr_legal = 1;
1100 vrf = sctp_find_vrf(vrf_id);
1104 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1105 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1106 if ((loopback_scope == 0) &&
1107 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1108 /* Skip loopback if loopback_scope not set */
1111 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1114 * For the BOUND-ALL case, the list
1115 * associated with a TCB is Always
1116 * considered a reverse list.. i.e.
1117 * it lists addresses that are NOT
1118 * part of the association. If this
1119 * is one of those we must skip it.
1121 if (sctp_is_addr_restricted(stcb,
1126 switch (sctp_ifa->address.sa.sa_family) {
1129 if (ipv4_addr_legal) {
1130 struct sockaddr_in *sin;
1132 sin = &sctp_ifa->address.sin;
1133 if (sin->sin_addr.s_addr == 0) {
1141 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1142 &sin->sin_addr) != 0) {
1145 if ((ipv4_local_scope == 0) &&
1146 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1150 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1151 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1152 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1153 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1154 actual += sizeof(struct sockaddr_in6);
1157 memcpy(sas, sin, sizeof(*sin));
1158 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1159 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1160 actual += sizeof(*sin);
1164 if (actual >= limit) {
1174 if (ipv6_addr_legal) {
1175 struct sockaddr_in6 *sin6;
1177 sin6 = &sctp_ifa->address.sin6;
1178 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1186 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1187 &sin6->sin6_addr) != 0) {
1190 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1191 if (local_scope == 0)
1193 if (sin6->sin6_scope_id == 0) {
1194 if (sa6_recoverscope(sin6) != 0)
1212 if ((site_scope == 0) &&
1213 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1216 memcpy(sas, sin6, sizeof(*sin6));
1217 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1218 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1219 actual += sizeof(*sin6);
1220 if (actual >= limit) {
1235 struct sctp_laddr *laddr;
1237 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1239 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1243 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1245 switch (laddr->ifa->address.sa.sa_family) {
1248 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1253 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1260 sas = (struct sockaddr_storage *)((caddr_t)sas +
1261 laddr->ifa->address.sa.sa_len);
1262 actual += laddr->ifa->address.sa.sa_len;
1263 if (actual >= limit) {
1272 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1273 struct sctp_tcb *stcb,
1275 struct sockaddr_storage *sas)
1279 SCTP_IPI_ADDR_RLOCK();
1280 /* fill up addresses for the endpoint's default vrf */
1281 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1283 SCTP_IPI_ADDR_RUNLOCK();
1288 * NOTE: assumes addr lock is held
1291 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1294 struct sctp_vrf *vrf = NULL;
1297 * In both sub-set bound an bound_all cases we return the MAXIMUM
1298 * number of addresses that you COULD get. In reality the sub-set
1299 * bound may have an exclusion list for a given TCB OR in the
1300 * bound-all case a TCB may NOT include the loopback or other
1301 * addresses as well.
1303 vrf = sctp_find_vrf(vrf_id);
1307 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1308 struct sctp_ifn *sctp_ifn;
1309 struct sctp_ifa *sctp_ifa;
1311 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1312 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1313 /* Count them if they are the right type */
1314 switch (sctp_ifa->address.sa.sa_family) {
1318 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1319 cnt += sizeof(struct sockaddr_in6);
1321 cnt += sizeof(struct sockaddr_in);
1323 cnt += sizeof(struct sockaddr_in);
1329 cnt += sizeof(struct sockaddr_in6);
1338 struct sctp_laddr *laddr;
1340 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1341 switch (laddr->ifa->address.sa.sa_family) {
1345 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1346 cnt += sizeof(struct sockaddr_in6);
1348 cnt += sizeof(struct sockaddr_in);
1350 cnt += sizeof(struct sockaddr_in);
1356 cnt += sizeof(struct sockaddr_in6);
1368 sctp_count_max_addresses(struct sctp_inpcb *inp)
1372 SCTP_IPI_ADDR_RLOCK();
1373 /* count addresses for the endpoint's default VRF */
1374 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1375 SCTP_IPI_ADDR_RUNLOCK();
1380 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1381 size_t optsize, void *p, int delay)
1384 int creat_lock_on = 0;
1385 struct sctp_tcb *stcb = NULL;
1386 struct sockaddr *sa;
1387 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1389 int bad_addresses = 0;
1392 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1394 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1395 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1396 /* We are already connected AND the TCP model */
1397 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1398 return (EADDRINUSE);
1400 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1401 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1402 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1405 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1406 SCTP_INP_RLOCK(inp);
1407 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1408 SCTP_INP_RUNLOCK(inp);
1411 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1414 SCTP_INP_INCR_REF(inp);
1415 SCTP_ASOC_CREATE_LOCK(inp);
1417 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1418 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1419 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1423 totaddrp = (unsigned int *)optval;
1424 totaddr = *totaddrp;
1425 sa = (struct sockaddr *)(totaddrp + 1);
1426 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (unsigned int)(optsize - sizeof(int)), &bad_addresses);
1427 if ((stcb != NULL) || bad_addresses) {
1428 /* Already have or am bring up an association */
1429 SCTP_ASOC_CREATE_UNLOCK(inp);
1432 SCTP_TCB_UNLOCK(stcb);
1433 if (bad_addresses == 0) {
1434 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1440 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1445 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1447 struct in6pcb *inp6;
1449 inp6 = (struct in6pcb *)inp;
1450 if (SCTP_IPV6_V6ONLY(inp6)) {
1452 * if IPV6_V6ONLY flag, ignore connections destined
1453 * to a v4 addr or v4-mapped addr
1455 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1461 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1462 SCTP_PCB_FLAGS_UNBOUND) {
1463 /* Bind a ephemeral port */
1464 error = sctp_inpcb_bind(so, NULL, NULL, p);
1469 /* FIX ME: do we want to pass in a vrf on the connect call? */
1470 vrf_id = inp->def_vrf_id;
1473 /* We are GOOD to go */
1474 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1475 inp->sctp_ep.pre_open_stream_count,
1479 /* Gak! no memory */
1482 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1483 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1484 /* Set the connected flag so we can queue data */
1487 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1488 /* move to second address */
1489 switch (sa->sa_family) {
1492 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1497 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1505 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1506 /* Fill in the return id */
1508 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE,
1509 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
1512 a_id = (sctp_assoc_t *) optval;
1513 *a_id = sctp_get_associd(stcb);
1515 /* initialize authentication parameters for the assoc */
1516 sctp_initialize_auth_params(inp, stcb);
1519 /* doing delayed connection */
1520 stcb->asoc.delayed_connection = 1;
1521 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1523 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1524 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1526 SCTP_TCB_UNLOCK(stcb);
1527 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1528 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1529 /* Set the connected flag so we can queue data */
1533 if (creat_lock_on) {
1534 SCTP_ASOC_CREATE_UNLOCK(inp);
1536 SCTP_INP_DECR_REF(inp);
1540 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1541 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1542 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1543 SCTP_INP_RLOCK(inp); \
1544 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1546 SCTP_TCB_LOCK(stcb); \
1548 SCTP_INP_RUNLOCK(inp); \
1549 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1550 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1551 if (stcb == NULL) { \
1552 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1562 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1563 if (size < sizeof(type)) { \
1564 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1568 destp = (type *)srcp; \
1573 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1576 struct sctp_inpcb *inp = NULL;
1578 struct sctp_tcb *stcb = NULL;
1580 if (optval == NULL) {
1581 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1584 inp = (struct sctp_inpcb *)so->so_pcb;
1586 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1593 case SCTP_AUTOCLOSE:
1594 case SCTP_EXPLICIT_EOR:
1595 case SCTP_AUTO_ASCONF:
1596 case SCTP_DISABLE_FRAGMENTS:
1597 case SCTP_I_WANT_MAPPED_V4_ADDR:
1598 case SCTP_USE_EXT_RCVINFO:
1599 SCTP_INP_RLOCK(inp);
1601 case SCTP_DISABLE_FRAGMENTS:
1602 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1604 case SCTP_I_WANT_MAPPED_V4_ADDR:
1605 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1607 case SCTP_AUTO_ASCONF:
1608 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1609 /* only valid for bound all sockets */
1610 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1612 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1617 case SCTP_EXPLICIT_EOR:
1618 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1621 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1623 case SCTP_USE_EXT_RCVINFO:
1624 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1626 case SCTP_AUTOCLOSE:
1627 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1628 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1634 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1635 error = ENOPROTOOPT;
1636 } /* end switch (sopt->sopt_name) */
1637 if (*optsize < sizeof(val)) {
1638 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1642 SCTP_INP_RUNLOCK(inp);
1644 /* return the option value */
1645 *(int *)optval = val;
1646 *optsize = sizeof(val);
1649 case SCTP_GET_PACKET_LOG:
1651 #ifdef SCTP_PACKET_LOGGING
1655 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1656 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1659 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1664 case SCTP_REUSE_PORT:
1668 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1669 /* Can't do this for a 1-m socket */
1673 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1674 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1675 *optsize = sizeof(uint32_t);
1678 case SCTP_PARTIAL_DELIVERY_POINT:
1682 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1683 *value = inp->partial_delivery_point;
1684 *optsize = sizeof(uint32_t);
1687 case SCTP_FRAGMENT_INTERLEAVE:
1691 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1692 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1693 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1694 *value = SCTP_FRAG_LEVEL_2;
1696 *value = SCTP_FRAG_LEVEL_1;
1699 *value = SCTP_FRAG_LEVEL_0;
1701 *optsize = sizeof(uint32_t);
1704 case SCTP_INTERLEAVING_SUPPORTED:
1706 struct sctp_assoc_value *av;
1708 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1709 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1712 av->assoc_value = stcb->asoc.idata_supported;
1713 SCTP_TCB_UNLOCK(stcb);
1715 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1716 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1717 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1718 SCTP_INP_RLOCK(inp);
1719 if (inp->idata_supported) {
1720 av->assoc_value = 1;
1722 av->assoc_value = 0;
1724 SCTP_INP_RUNLOCK(inp);
1726 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1731 *optsize = sizeof(struct sctp_assoc_value);
1735 case SCTP_CMT_ON_OFF:
1737 struct sctp_assoc_value *av;
1739 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1740 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1742 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1743 SCTP_TCB_UNLOCK(stcb);
1745 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1746 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1747 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1748 SCTP_INP_RLOCK(inp);
1749 av->assoc_value = inp->sctp_cmt_on_off;
1750 SCTP_INP_RUNLOCK(inp);
1752 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1757 *optsize = sizeof(struct sctp_assoc_value);
1761 case SCTP_PLUGGABLE_CC:
1763 struct sctp_assoc_value *av;
1765 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1766 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1768 av->assoc_value = stcb->asoc.congestion_control_module;
1769 SCTP_TCB_UNLOCK(stcb);
1771 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1772 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1773 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1774 SCTP_INP_RLOCK(inp);
1775 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1776 SCTP_INP_RUNLOCK(inp);
1778 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1783 *optsize = sizeof(struct sctp_assoc_value);
1787 case SCTP_CC_OPTION:
1789 struct sctp_cc_option *cc_opt;
1791 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1792 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1796 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1799 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1800 *optsize = sizeof(struct sctp_cc_option);
1802 SCTP_TCB_UNLOCK(stcb);
1806 case SCTP_PLUGGABLE_SS:
1808 struct sctp_assoc_value *av;
1810 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1811 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1813 av->assoc_value = stcb->asoc.stream_scheduling_module;
1814 SCTP_TCB_UNLOCK(stcb);
1816 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1817 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1818 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1819 SCTP_INP_RLOCK(inp);
1820 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1821 SCTP_INP_RUNLOCK(inp);
1823 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1828 *optsize = sizeof(struct sctp_assoc_value);
1834 struct sctp_stream_value *av;
1836 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1837 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1839 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1840 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1841 &av->stream_value) < 0)) {
1842 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1845 *optsize = sizeof(struct sctp_stream_value);
1847 SCTP_TCB_UNLOCK(stcb);
1850 * Can't get stream value without
1853 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1858 case SCTP_GET_ADDR_LEN:
1860 struct sctp_assoc_value *av;
1862 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1865 if (av->assoc_value == AF_INET) {
1866 av->assoc_value = sizeof(struct sockaddr_in);
1871 if (av->assoc_value == AF_INET6) {
1872 av->assoc_value = sizeof(struct sockaddr_in6);
1877 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1879 *optsize = sizeof(struct sctp_assoc_value);
1883 case SCTP_GET_ASSOC_NUMBER:
1885 uint32_t *value, cnt;
1887 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1888 SCTP_INP_RLOCK(inp);
1889 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1890 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1891 /* Can't do this for a 1-1 socket */
1893 SCTP_INP_RUNLOCK(inp);
1897 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1900 SCTP_INP_RUNLOCK(inp);
1902 *optsize = sizeof(uint32_t);
1905 case SCTP_GET_ASSOC_ID_LIST:
1907 struct sctp_assoc_ids *ids;
1911 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1912 SCTP_INP_RLOCK(inp);
1913 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1914 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1915 /* Can't do this for a 1-1 socket */
1917 SCTP_INP_RUNLOCK(inp);
1921 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1922 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1924 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1927 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1932 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1936 SCTP_INP_RUNLOCK(inp);
1938 ids->gaids_number_of_ids = at;
1939 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1945 struct sctp_assoc_value *av;
1947 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1948 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1951 av->assoc_value = stcb->asoc.context;
1952 SCTP_TCB_UNLOCK(stcb);
1954 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1955 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1956 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1957 SCTP_INP_RLOCK(inp);
1958 av->assoc_value = inp->sctp_context;
1959 SCTP_INP_RUNLOCK(inp);
1961 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1966 *optsize = sizeof(struct sctp_assoc_value);
1972 uint32_t *default_vrfid;
1974 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1975 *default_vrfid = inp->def_vrf_id;
1976 *optsize = sizeof(uint32_t);
1979 case SCTP_GET_ASOC_VRF:
1981 struct sctp_assoc_value *id;
1983 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1984 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1987 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1989 id->assoc_value = stcb->asoc.vrf_id;
1990 *optsize = sizeof(struct sctp_assoc_value);
1994 case SCTP_GET_VRF_IDS:
1996 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
2000 case SCTP_GET_NONCE_VALUES:
2002 struct sctp_get_nonce_values *gnv;
2004 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
2005 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
2008 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
2009 gnv->gn_local_tag = stcb->asoc.my_vtag;
2010 SCTP_TCB_UNLOCK(stcb);
2011 *optsize = sizeof(struct sctp_get_nonce_values);
2013 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2018 case SCTP_DELAYED_SACK:
2020 struct sctp_sack_info *sack;
2022 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2023 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2025 sack->sack_delay = stcb->asoc.delayed_ack;
2026 sack->sack_freq = stcb->asoc.sack_freq;
2027 SCTP_TCB_UNLOCK(stcb);
2029 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2030 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2031 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2032 SCTP_INP_RLOCK(inp);
2033 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2034 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2035 SCTP_INP_RUNLOCK(inp);
2037 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2042 *optsize = sizeof(struct sctp_sack_info);
2046 case SCTP_GET_SNDBUF_USE:
2048 struct sctp_sockstat *ss;
2050 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2051 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2054 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2055 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2056 stcb->asoc.size_on_all_streams);
2057 SCTP_TCB_UNLOCK(stcb);
2058 *optsize = sizeof(struct sctp_sockstat);
2060 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2065 case SCTP_MAX_BURST:
2067 struct sctp_assoc_value *av;
2069 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2070 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2073 av->assoc_value = stcb->asoc.max_burst;
2074 SCTP_TCB_UNLOCK(stcb);
2076 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2077 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2078 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2079 SCTP_INP_RLOCK(inp);
2080 av->assoc_value = inp->sctp_ep.max_burst;
2081 SCTP_INP_RUNLOCK(inp);
2083 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2088 *optsize = sizeof(struct sctp_assoc_value);
2094 struct sctp_assoc_value *av;
2097 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2098 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2101 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2102 SCTP_TCB_UNLOCK(stcb);
2104 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2105 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2106 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2107 SCTP_INP_RLOCK(inp);
2108 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2109 ovh = SCTP_MED_OVERHEAD;
2111 ovh = SCTP_MED_V4_OVERHEAD;
2113 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2114 av->assoc_value = 0;
2116 av->assoc_value = inp->sctp_frag_point - ovh;
2117 SCTP_INP_RUNLOCK(inp);
2119 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2124 *optsize = sizeof(struct sctp_assoc_value);
2128 case SCTP_GET_STAT_LOG:
2129 error = sctp_fill_stat_log(optval, optsize);
2133 struct sctp_event_subscribe *events;
2135 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2136 memset(events, 0, sizeof(struct sctp_event_subscribe));
2137 SCTP_INP_RLOCK(inp);
2138 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2139 events->sctp_data_io_event = 1;
2141 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2142 events->sctp_association_event = 1;
2144 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2145 events->sctp_address_event = 1;
2147 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2148 events->sctp_send_failure_event = 1;
2150 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2151 events->sctp_peer_error_event = 1;
2153 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2154 events->sctp_shutdown_event = 1;
2156 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2157 events->sctp_partial_delivery_event = 1;
2159 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2160 events->sctp_adaptation_layer_event = 1;
2162 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2163 events->sctp_authentication_event = 1;
2165 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2166 events->sctp_sender_dry_event = 1;
2168 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2169 events->sctp_stream_reset_event = 1;
2170 SCTP_INP_RUNLOCK(inp);
2171 *optsize = sizeof(struct sctp_event_subscribe);
2174 case SCTP_ADAPTATION_LAYER:
2178 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2180 SCTP_INP_RLOCK(inp);
2181 *value = inp->sctp_ep.adaptation_layer_indicator;
2182 SCTP_INP_RUNLOCK(inp);
2183 *optsize = sizeof(uint32_t);
2186 case SCTP_SET_INITIAL_DBG_SEQ:
2190 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2191 SCTP_INP_RLOCK(inp);
2192 *value = inp->sctp_ep.initial_sequence_debug;
2193 SCTP_INP_RUNLOCK(inp);
2194 *optsize = sizeof(uint32_t);
2197 case SCTP_GET_LOCAL_ADDR_SIZE:
2201 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2202 SCTP_INP_RLOCK(inp);
2203 *value = sctp_count_max_addresses(inp);
2204 SCTP_INP_RUNLOCK(inp);
2205 *optsize = sizeof(uint32_t);
2208 case SCTP_GET_REMOTE_ADDR_SIZE:
2212 struct sctp_nets *net;
2214 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2215 /* FIXME MT: change to sctp_assoc_value? */
2216 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2220 /* Count the sizes */
2221 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2222 switch (net->ro._l_addr.sa.sa_family) {
2226 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2227 size += sizeof(struct sockaddr_in6);
2229 size += sizeof(struct sockaddr_in);
2232 size += sizeof(struct sockaddr_in);
2238 size += sizeof(struct sockaddr_in6);
2245 SCTP_TCB_UNLOCK(stcb);
2246 *value = (uint32_t) size;
2247 *optsize = sizeof(uint32_t);
2249 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2254 case SCTP_GET_PEER_ADDRESSES:
2256 * Get the address information, an array is passed in to
2257 * fill up we pack it.
2261 struct sockaddr_storage *sas;
2262 struct sctp_nets *net;
2263 struct sctp_getaddresses *saddr;
2265 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2266 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2269 left = (*optsize) - sizeof(struct sctp_getaddresses);
2270 *optsize = sizeof(struct sctp_getaddresses);
2271 sas = (struct sockaddr_storage *)&saddr->addr[0];
2273 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2274 switch (net->ro._l_addr.sa.sa_family) {
2278 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2279 cpsz = sizeof(struct sockaddr_in6);
2281 cpsz = sizeof(struct sockaddr_in);
2284 cpsz = sizeof(struct sockaddr_in);
2290 cpsz = sizeof(struct sockaddr_in6);
2301 /* not enough room. */
2304 #if defined(INET) && defined(INET6)
2305 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2306 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2307 /* Must map the address */
2308 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2309 (struct sockaddr_in6 *)sas);
2311 memcpy(sas, &net->ro._l_addr, cpsz);
2314 memcpy(sas, &net->ro._l_addr, cpsz);
2316 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2318 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2322 SCTP_TCB_UNLOCK(stcb);
2324 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2329 case SCTP_GET_LOCAL_ADDRESSES:
2331 size_t limit, actual;
2332 struct sockaddr_storage *sas;
2333 struct sctp_getaddresses *saddr;
2335 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2336 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2338 sas = (struct sockaddr_storage *)&saddr->addr[0];
2339 limit = *optsize - sizeof(sctp_assoc_t);
2340 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2342 SCTP_TCB_UNLOCK(stcb);
2344 *optsize = sizeof(struct sockaddr_storage) + actual;
2347 case SCTP_PEER_ADDR_PARAMS:
2349 struct sctp_paddrparams *paddrp;
2350 struct sctp_nets *net;
2351 struct sockaddr *addr;
2353 #if defined(INET) && defined(INET6)
2354 struct sockaddr_in sin_store;
2358 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2359 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2361 #if defined(INET) && defined(INET6)
2362 if (paddrp->spp_address.ss_family == AF_INET6) {
2363 struct sockaddr_in6 *sin6;
2365 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2366 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2367 in6_sin6_2_sin(&sin_store, sin6);
2368 addr = (struct sockaddr *)&sin_store;
2370 addr = (struct sockaddr *)&paddrp->spp_address;
2373 addr = (struct sockaddr *)&paddrp->spp_address;
2376 addr = (struct sockaddr *)&paddrp->spp_address;
2379 net = sctp_findnet(stcb, addr);
2382 * We increment here since
2383 * sctp_findassociation_ep_addr() wil do a
2384 * decrement if it finds the stcb as long as
2385 * the locked tcb (last argument) is NOT a
2389 SCTP_INP_INCR_REF(inp);
2390 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2392 SCTP_INP_DECR_REF(inp);
2395 if ((stcb != NULL) && (net == NULL)) {
2397 if (addr->sa_family == AF_INET) {
2398 struct sockaddr_in *sin;
2400 sin = (struct sockaddr_in *)addr;
2401 if (sin->sin_addr.s_addr != INADDR_ANY) {
2403 SCTP_TCB_UNLOCK(stcb);
2404 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2410 if (addr->sa_family == AF_INET6) {
2411 struct sockaddr_in6 *sin6;
2413 sin6 = (struct sockaddr_in6 *)addr;
2414 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2416 SCTP_TCB_UNLOCK(stcb);
2417 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2423 error = EAFNOSUPPORT;
2424 SCTP_TCB_UNLOCK(stcb);
2425 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2430 /* Applies to the specific association */
2431 paddrp->spp_flags = 0;
2433 paddrp->spp_hbinterval = net->heart_beat_delay;
2434 paddrp->spp_pathmaxrxt = net->failure_threshold;
2435 paddrp->spp_pathmtu = net->mtu;
2436 switch (net->ro._l_addr.sa.sa_family) {
2439 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2444 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2450 /* get flags for HB */
2451 if (net->dest_state & SCTP_ADDR_NOHB) {
2452 paddrp->spp_flags |= SPP_HB_DISABLE;
2454 paddrp->spp_flags |= SPP_HB_ENABLE;
2456 /* get flags for PMTU */
2457 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2458 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2460 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2462 if (net->dscp & 0x01) {
2463 paddrp->spp_dscp = net->dscp & 0xfc;
2464 paddrp->spp_flags |= SPP_DSCP;
2467 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2468 (net->flowlabel & 0x80000000)) {
2469 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2470 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2475 * No destination so return default
2478 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2479 paddrp->spp_pathmtu = 0;
2480 if (stcb->asoc.default_dscp & 0x01) {
2481 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2482 paddrp->spp_flags |= SPP_DSCP;
2485 if (stcb->asoc.default_flowlabel & 0x80000000) {
2486 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2487 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2490 /* default settings should be these */
2491 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2492 paddrp->spp_flags |= SPP_HB_DISABLE;
2494 paddrp->spp_flags |= SPP_HB_ENABLE;
2496 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2497 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2499 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2501 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2503 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2504 SCTP_TCB_UNLOCK(stcb);
2506 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2507 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2508 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2509 /* Use endpoint defaults */
2510 SCTP_INP_RLOCK(inp);
2511 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2512 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2513 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2514 /* get inp's default */
2515 if (inp->sctp_ep.default_dscp & 0x01) {
2516 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2517 paddrp->spp_flags |= SPP_DSCP;
2520 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2521 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2522 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2523 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2526 /* can't return this */
2527 paddrp->spp_pathmtu = 0;
2529 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2530 paddrp->spp_flags |= SPP_HB_ENABLE;
2532 paddrp->spp_flags |= SPP_HB_DISABLE;
2534 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2535 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2537 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2539 SCTP_INP_RUNLOCK(inp);
2541 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2546 *optsize = sizeof(struct sctp_paddrparams);
2550 case SCTP_GET_PEER_ADDR_INFO:
2552 struct sctp_paddrinfo *paddri;
2553 struct sctp_nets *net;
2554 struct sockaddr *addr;
2556 #if defined(INET) && defined(INET6)
2557 struct sockaddr_in sin_store;
2561 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2562 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2564 #if defined(INET) && defined(INET6)
2565 if (paddri->spinfo_address.ss_family == AF_INET6) {
2566 struct sockaddr_in6 *sin6;
2568 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2569 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2570 in6_sin6_2_sin(&sin_store, sin6);
2571 addr = (struct sockaddr *)&sin_store;
2573 addr = (struct sockaddr *)&paddri->spinfo_address;
2576 addr = (struct sockaddr *)&paddri->spinfo_address;
2579 addr = (struct sockaddr *)&paddri->spinfo_address;
2582 net = sctp_findnet(stcb, addr);
2585 * We increment here since
2586 * sctp_findassociation_ep_addr() wil do a
2587 * decrement if it finds the stcb as long as
2588 * the locked tcb (last argument) is NOT a
2592 SCTP_INP_INCR_REF(inp);
2593 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2595 SCTP_INP_DECR_REF(inp);
2599 if ((stcb != NULL) && (net != NULL)) {
2600 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2601 /* It's unconfirmed */
2602 paddri->spinfo_state = SCTP_UNCONFIRMED;
2603 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2605 paddri->spinfo_state = SCTP_ACTIVE;
2608 paddri->spinfo_state = SCTP_INACTIVE;
2610 paddri->spinfo_cwnd = net->cwnd;
2611 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2612 paddri->spinfo_rto = net->RTO;
2613 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2614 paddri->spinfo_mtu = net->mtu;
2615 switch (addr->sa_family) {
2618 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2623 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2629 SCTP_TCB_UNLOCK(stcb);
2630 *optsize = sizeof(struct sctp_paddrinfo);
2633 SCTP_TCB_UNLOCK(stcb);
2635 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2640 case SCTP_PCB_STATUS:
2642 struct sctp_pcbinfo *spcb;
2644 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2645 sctp_fill_pcbinfo(spcb);
2646 *optsize = sizeof(struct sctp_pcbinfo);
2651 struct sctp_nets *net;
2652 struct sctp_status *sstat;
2654 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2655 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2658 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2662 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2663 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2664 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2665 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2667 * We can't include chunks that have been passed to
2668 * the socket layer. Only things in queue.
2670 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2671 stcb->asoc.cnt_on_all_streams);
2674 sstat->sstat_instrms = stcb->asoc.streamincnt;
2675 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2676 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2677 memcpy(&sstat->sstat_primary.spinfo_address,
2678 &stcb->asoc.primary_destination->ro._l_addr,
2679 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2680 net = stcb->asoc.primary_destination;
2681 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2683 * Again the user can get info from sctp_constants.h
2684 * for what the state of the network is.
2686 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2687 /* It's unconfirmed */
2688 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2689 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2691 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2694 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2696 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2697 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2698 sstat->sstat_primary.spinfo_rto = net->RTO;
2699 sstat->sstat_primary.spinfo_mtu = net->mtu;
2700 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2703 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2708 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2714 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2715 SCTP_TCB_UNLOCK(stcb);
2716 *optsize = sizeof(struct sctp_status);
2721 struct sctp_rtoinfo *srto;
2723 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2724 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2727 srto->srto_initial = stcb->asoc.initial_rto;
2728 srto->srto_max = stcb->asoc.maxrto;
2729 srto->srto_min = stcb->asoc.minrto;
2730 SCTP_TCB_UNLOCK(stcb);
2732 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2733 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2734 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2735 SCTP_INP_RLOCK(inp);
2736 srto->srto_initial = inp->sctp_ep.initial_rto;
2737 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2738 srto->srto_min = inp->sctp_ep.sctp_minrto;
2739 SCTP_INP_RUNLOCK(inp);
2741 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2746 *optsize = sizeof(struct sctp_rtoinfo);
2752 struct sctp_timeouts *stimo;
2754 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2755 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2758 stimo->stimo_init = stcb->asoc.timoinit;
2759 stimo->stimo_data = stcb->asoc.timodata;
2760 stimo->stimo_sack = stcb->asoc.timosack;
2761 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2762 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2763 stimo->stimo_cookie = stcb->asoc.timocookie;
2764 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2765 SCTP_TCB_UNLOCK(stcb);
2766 *optsize = sizeof(struct sctp_timeouts);
2768 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2773 case SCTP_ASSOCINFO:
2775 struct sctp_assocparams *sasoc;
2777 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2778 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2781 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2782 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2783 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2784 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2785 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2786 SCTP_TCB_UNLOCK(stcb);
2788 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2789 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2790 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2791 SCTP_INP_RLOCK(inp);
2792 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2793 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2794 sasoc->sasoc_number_peer_destinations = 0;
2795 sasoc->sasoc_peer_rwnd = 0;
2796 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2797 SCTP_INP_RUNLOCK(inp);
2799 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2804 *optsize = sizeof(struct sctp_assocparams);
2808 case SCTP_DEFAULT_SEND_PARAM:
2810 struct sctp_sndrcvinfo *s_info;
2812 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2813 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2816 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2817 SCTP_TCB_UNLOCK(stcb);
2819 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2820 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2821 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2822 SCTP_INP_RLOCK(inp);
2823 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2824 SCTP_INP_RUNLOCK(inp);
2826 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2831 *optsize = sizeof(struct sctp_sndrcvinfo);
2837 struct sctp_initmsg *sinit;
2839 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2840 SCTP_INP_RLOCK(inp);
2841 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2842 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2843 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2844 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2845 SCTP_INP_RUNLOCK(inp);
2846 *optsize = sizeof(struct sctp_initmsg);
2849 case SCTP_PRIMARY_ADDR:
2850 /* we allow a "get" operation on this */
2852 struct sctp_setprim *ssp;
2854 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2855 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2858 union sctp_sockstore *addr;
2860 addr = &stcb->asoc.primary_destination->ro._l_addr;
2861 switch (addr->sa.sa_family) {
2865 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2866 in6_sin_2_v4mapsin6(&addr->sin,
2867 (struct sockaddr_in6 *)&ssp->ssp_addr);
2869 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2872 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2878 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2884 SCTP_TCB_UNLOCK(stcb);
2885 *optsize = sizeof(struct sctp_setprim);
2887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2892 case SCTP_HMAC_IDENT:
2894 struct sctp_hmacalgo *shmac;
2895 sctp_hmaclist_t *hmaclist;
2899 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2901 SCTP_INP_RLOCK(inp);
2902 hmaclist = inp->sctp_ep.local_hmacs;
2903 if (hmaclist == NULL) {
2904 /* no HMACs to return */
2905 *optsize = sizeof(*shmac);
2906 SCTP_INP_RUNLOCK(inp);
2909 /* is there room for all of the hmac ids? */
2910 size = sizeof(*shmac) + (hmaclist->num_algo *
2911 sizeof(shmac->shmac_idents[0]));
2912 if ((size_t)(*optsize) < size) {
2913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2915 SCTP_INP_RUNLOCK(inp);
2918 /* copy in the list */
2919 shmac->shmac_number_of_idents = hmaclist->num_algo;
2920 for (i = 0; i < hmaclist->num_algo; i++) {
2921 shmac->shmac_idents[i] = hmaclist->hmac[i];
2923 SCTP_INP_RUNLOCK(inp);
2927 case SCTP_AUTH_ACTIVE_KEY:
2929 struct sctp_authkeyid *scact;
2931 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2932 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2935 /* get the active key on the assoc */
2936 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2937 SCTP_TCB_UNLOCK(stcb);
2939 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2940 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2941 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2942 /* get the endpoint active key */
2943 SCTP_INP_RLOCK(inp);
2944 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2945 SCTP_INP_RUNLOCK(inp);
2947 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2952 *optsize = sizeof(struct sctp_authkeyid);
2956 case SCTP_LOCAL_AUTH_CHUNKS:
2958 struct sctp_authchunks *sac;
2959 sctp_auth_chklist_t *chklist = NULL;
2962 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2963 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2966 /* get off the assoc */
2967 chklist = stcb->asoc.local_auth_chunks;
2968 /* is there enough space? */
2969 size = sctp_auth_get_chklist_size(chklist);
2970 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2972 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2974 /* copy in the chunks */
2975 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2976 sac->gauth_number_of_chunks = (uint32_t) size;
2977 *optsize = sizeof(struct sctp_authchunks) + size;
2979 SCTP_TCB_UNLOCK(stcb);
2981 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2982 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2983 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2984 /* get off the endpoint */
2985 SCTP_INP_RLOCK(inp);
2986 chklist = inp->sctp_ep.local_auth_chunks;
2987 /* is there enough space? */
2988 size = sctp_auth_get_chklist_size(chklist);
2989 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2991 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2993 /* copy in the chunks */
2994 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2995 sac->gauth_number_of_chunks = (uint32_t) size;
2996 *optsize = sizeof(struct sctp_authchunks) + size;
2998 SCTP_INP_RUNLOCK(inp);
3000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3006 case SCTP_PEER_AUTH_CHUNKS:
3008 struct sctp_authchunks *sac;
3009 sctp_auth_chklist_t *chklist = NULL;
3012 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
3013 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
3016 /* get off the assoc */
3017 chklist = stcb->asoc.peer_auth_chunks;
3018 /* is there enough space? */
3019 size = sctp_auth_get_chklist_size(chklist);
3020 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
3022 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3024 /* copy in the chunks */
3025 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
3026 sac->gauth_number_of_chunks = (uint32_t) size;
3027 *optsize = sizeof(struct sctp_authchunks) + size;
3029 SCTP_TCB_UNLOCK(stcb);
3031 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3038 struct sctp_event *event;
3039 uint32_t event_type;
3041 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3042 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3044 switch (event->se_type) {
3045 case SCTP_ASSOC_CHANGE:
3046 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3048 case SCTP_PEER_ADDR_CHANGE:
3049 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3051 case SCTP_REMOTE_ERROR:
3052 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3054 case SCTP_SEND_FAILED:
3055 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3057 case SCTP_SHUTDOWN_EVENT:
3058 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3060 case SCTP_ADAPTATION_INDICATION:
3061 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3063 case SCTP_PARTIAL_DELIVERY_EVENT:
3064 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3066 case SCTP_AUTHENTICATION_EVENT:
3067 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3069 case SCTP_STREAM_RESET_EVENT:
3070 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3072 case SCTP_SENDER_DRY_EVENT:
3073 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3075 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3077 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3080 case SCTP_ASSOC_RESET_EVENT:
3081 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3083 case SCTP_STREAM_CHANGE_EVENT:
3084 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3086 case SCTP_SEND_FAILED_EVENT:
3087 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3091 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3095 if (event_type > 0) {
3097 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3098 SCTP_TCB_UNLOCK(stcb);
3100 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3101 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3102 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3103 SCTP_INP_RLOCK(inp);
3104 event->se_on = sctp_is_feature_on(inp, event_type);
3105 SCTP_INP_RUNLOCK(inp);
3107 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3113 *optsize = sizeof(struct sctp_event);
3117 case SCTP_RECVRCVINFO:
3121 if (*optsize < sizeof(int)) {
3122 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3125 SCTP_INP_RLOCK(inp);
3126 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3127 SCTP_INP_RUNLOCK(inp);
3130 /* return the option value */
3131 *(int *)optval = onoff;
3132 *optsize = sizeof(int);
3136 case SCTP_RECVNXTINFO:
3140 if (*optsize < sizeof(int)) {
3141 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3144 SCTP_INP_RLOCK(inp);
3145 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3146 SCTP_INP_RUNLOCK(inp);
3149 /* return the option value */
3150 *(int *)optval = onoff;
3151 *optsize = sizeof(int);
3155 case SCTP_DEFAULT_SNDINFO:
3157 struct sctp_sndinfo *info;
3159 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3160 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3163 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3164 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3165 info->snd_flags &= 0xfff0;
3166 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3167 info->snd_context = stcb->asoc.def_send.sinfo_context;
3168 SCTP_TCB_UNLOCK(stcb);
3170 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3171 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3172 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3173 SCTP_INP_RLOCK(inp);
3174 info->snd_sid = inp->def_send.sinfo_stream;
3175 info->snd_flags = inp->def_send.sinfo_flags;
3176 info->snd_flags &= 0xfff0;
3177 info->snd_ppid = inp->def_send.sinfo_ppid;
3178 info->snd_context = inp->def_send.sinfo_context;
3179 SCTP_INP_RUNLOCK(inp);
3181 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3186 *optsize = sizeof(struct sctp_sndinfo);
3190 case SCTP_DEFAULT_PRINFO:
3192 struct sctp_default_prinfo *info;
3194 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3195 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3198 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3199 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3200 SCTP_TCB_UNLOCK(stcb);
3202 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3203 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3204 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3205 SCTP_INP_RLOCK(inp);
3206 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3207 info->pr_value = inp->def_send.sinfo_timetolive;
3208 SCTP_INP_RUNLOCK(inp);
3210 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3215 *optsize = sizeof(struct sctp_default_prinfo);
3219 case SCTP_PEER_ADDR_THLDS:
3221 struct sctp_paddrthlds *thlds;
3222 struct sctp_nets *net;
3223 struct sockaddr *addr;
3225 #if defined(INET) && defined(INET6)
3226 struct sockaddr_in sin_store;
3230 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3231 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3233 #if defined(INET) && defined(INET6)
3234 if (thlds->spt_address.ss_family == AF_INET6) {
3235 struct sockaddr_in6 *sin6;
3237 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3238 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3239 in6_sin6_2_sin(&sin_store, sin6);
3240 addr = (struct sockaddr *)&sin_store;
3242 addr = (struct sockaddr *)&thlds->spt_address;
3245 addr = (struct sockaddr *)&thlds->spt_address;
3248 addr = (struct sockaddr *)&thlds->spt_address;
3251 net = sctp_findnet(stcb, addr);
3254 * We increment here since
3255 * sctp_findassociation_ep_addr() wil do a
3256 * decrement if it finds the stcb as long as
3257 * the locked tcb (last argument) is NOT a
3261 SCTP_INP_INCR_REF(inp);
3262 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3264 SCTP_INP_DECR_REF(inp);
3267 if ((stcb != NULL) && (net == NULL)) {
3269 if (addr->sa_family == AF_INET) {
3270 struct sockaddr_in *sin;
3272 sin = (struct sockaddr_in *)addr;
3273 if (sin->sin_addr.s_addr != INADDR_ANY) {
3275 SCTP_TCB_UNLOCK(stcb);
3276 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3282 if (addr->sa_family == AF_INET6) {
3283 struct sockaddr_in6 *sin6;
3285 sin6 = (struct sockaddr_in6 *)addr;
3286 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3288 SCTP_TCB_UNLOCK(stcb);
3289 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3295 error = EAFNOSUPPORT;
3296 SCTP_TCB_UNLOCK(stcb);
3297 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3303 thlds->spt_pathmaxrxt = net->failure_threshold;
3304 thlds->spt_pathpfthld = net->pf_threshold;
3306 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3307 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3309 thlds->spt_assoc_id = sctp_get_associd(stcb);
3310 SCTP_TCB_UNLOCK(stcb);
3312 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3313 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3314 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3315 /* Use endpoint defaults */
3316 SCTP_INP_RLOCK(inp);
3317 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3318 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3319 SCTP_INP_RUNLOCK(inp);
3321 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3326 *optsize = sizeof(struct sctp_paddrthlds);
3330 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3332 struct sctp_udpencaps *encaps;
3333 struct sctp_nets *net;
3334 struct sockaddr *addr;
3336 #if defined(INET) && defined(INET6)
3337 struct sockaddr_in sin_store;
3341 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3342 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3344 #if defined(INET) && defined(INET6)
3345 if (encaps->sue_address.ss_family == AF_INET6) {
3346 struct sockaddr_in6 *sin6;
3348 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3349 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3350 in6_sin6_2_sin(&sin_store, sin6);
3351 addr = (struct sockaddr *)&sin_store;
3353 addr = (struct sockaddr *)&encaps->sue_address;
3356 addr = (struct sockaddr *)&encaps->sue_address;
3359 addr = (struct sockaddr *)&encaps->sue_address;
3362 net = sctp_findnet(stcb, addr);
3365 * We increment here since
3366 * sctp_findassociation_ep_addr() wil do a
3367 * decrement if it finds the stcb as long as
3368 * the locked tcb (last argument) is NOT a
3372 SCTP_INP_INCR_REF(inp);
3373 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3375 SCTP_INP_DECR_REF(inp);
3378 if ((stcb != NULL) && (net == NULL)) {
3380 if (addr->sa_family == AF_INET) {
3381 struct sockaddr_in *sin;
3383 sin = (struct sockaddr_in *)addr;
3384 if (sin->sin_addr.s_addr != INADDR_ANY) {
3386 SCTP_TCB_UNLOCK(stcb);
3387 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3393 if (addr->sa_family == AF_INET6) {
3394 struct sockaddr_in6 *sin6;
3396 sin6 = (struct sockaddr_in6 *)addr;
3397 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3399 SCTP_TCB_UNLOCK(stcb);
3400 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3406 error = EAFNOSUPPORT;
3407 SCTP_TCB_UNLOCK(stcb);
3408 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3414 encaps->sue_port = net->port;
3416 encaps->sue_port = stcb->asoc.port;
3418 SCTP_TCB_UNLOCK(stcb);
3420 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3421 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3422 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3423 SCTP_INP_RLOCK(inp);
3424 encaps->sue_port = inp->sctp_ep.port;
3425 SCTP_INP_RUNLOCK(inp);
3427 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3432 *optsize = sizeof(struct sctp_udpencaps);
3436 case SCTP_ECN_SUPPORTED:
3438 struct sctp_assoc_value *av;
3440 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3441 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3444 av->assoc_value = stcb->asoc.ecn_supported;
3445 SCTP_TCB_UNLOCK(stcb);
3447 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3448 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3449 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3450 SCTP_INP_RLOCK(inp);
3451 av->assoc_value = inp->ecn_supported;
3452 SCTP_INP_RUNLOCK(inp);
3454 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3459 *optsize = sizeof(struct sctp_assoc_value);
3463 case SCTP_PR_SUPPORTED:
3465 struct sctp_assoc_value *av;
3467 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3468 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3471 av->assoc_value = stcb->asoc.prsctp_supported;
3472 SCTP_TCB_UNLOCK(stcb);
3474 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3475 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3476 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3477 SCTP_INP_RLOCK(inp);
3478 av->assoc_value = inp->prsctp_supported;
3479 SCTP_INP_RUNLOCK(inp);
3481 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3486 *optsize = sizeof(struct sctp_assoc_value);
3490 case SCTP_AUTH_SUPPORTED:
3492 struct sctp_assoc_value *av;
3494 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3495 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3498 av->assoc_value = stcb->asoc.auth_supported;
3499 SCTP_TCB_UNLOCK(stcb);
3501 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3502 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3503 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3504 SCTP_INP_RLOCK(inp);
3505 av->assoc_value = inp->auth_supported;
3506 SCTP_INP_RUNLOCK(inp);
3508 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3513 *optsize = sizeof(struct sctp_assoc_value);
3517 case SCTP_ASCONF_SUPPORTED:
3519 struct sctp_assoc_value *av;
3521 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3522 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3525 av->assoc_value = stcb->asoc.asconf_supported;
3526 SCTP_TCB_UNLOCK(stcb);
3528 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3529 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3530 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3531 SCTP_INP_RLOCK(inp);
3532 av->assoc_value = inp->asconf_supported;
3533 SCTP_INP_RUNLOCK(inp);
3535 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3540 *optsize = sizeof(struct sctp_assoc_value);
3544 case SCTP_RECONFIG_SUPPORTED:
3546 struct sctp_assoc_value *av;
3548 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3549 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3552 av->assoc_value = stcb->asoc.reconfig_supported;
3553 SCTP_TCB_UNLOCK(stcb);
3555 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3556 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3557 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3558 SCTP_INP_RLOCK(inp);
3559 av->assoc_value = inp->reconfig_supported;
3560 SCTP_INP_RUNLOCK(inp);
3562 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3567 *optsize = sizeof(struct sctp_assoc_value);
3571 case SCTP_NRSACK_SUPPORTED:
3573 struct sctp_assoc_value *av;
3575 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3576 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3579 av->assoc_value = stcb->asoc.nrsack_supported;
3580 SCTP_TCB_UNLOCK(stcb);
3582 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3583 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3584 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3585 SCTP_INP_RLOCK(inp);
3586 av->assoc_value = inp->nrsack_supported;
3587 SCTP_INP_RUNLOCK(inp);
3589 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3594 *optsize = sizeof(struct sctp_assoc_value);
3598 case SCTP_PKTDROP_SUPPORTED:
3600 struct sctp_assoc_value *av;
3602 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3603 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3606 av->assoc_value = stcb->asoc.pktdrop_supported;
3607 SCTP_TCB_UNLOCK(stcb);
3609 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3610 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3611 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3612 SCTP_INP_RLOCK(inp);
3613 av->assoc_value = inp->pktdrop_supported;
3614 SCTP_INP_RUNLOCK(inp);
3616 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3621 *optsize = sizeof(struct sctp_assoc_value);
3625 case SCTP_ENABLE_STREAM_RESET:
3627 struct sctp_assoc_value *av;
3629 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3630 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3633 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3634 SCTP_TCB_UNLOCK(stcb);
3636 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3637 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3638 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3639 SCTP_INP_RLOCK(inp);
3640 av->assoc_value = (uint32_t) inp->local_strreset_support;
3641 SCTP_INP_RUNLOCK(inp);
3643 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3648 *optsize = sizeof(struct sctp_assoc_value);
3652 case SCTP_PR_STREAM_STATUS:
3654 struct sctp_prstatus *sprstat;
3658 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3659 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3661 sid = sprstat->sprstat_sid;
3662 policy = sprstat->sprstat_policy;
3663 #if defined(SCTP_DETAILED_STR_STATS)
3664 if ((stcb != NULL) &&
3665 (sid < stcb->asoc.streamoutcnt) &&
3666 (policy != SCTP_PR_SCTP_NONE) &&
3667 ((policy <= SCTP_PR_SCTP_MAX) ||
3668 (policy == SCTP_PR_SCTP_ALL))) {
3669 if (policy == SCTP_PR_SCTP_ALL) {
3670 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3671 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3673 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3674 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3677 if ((stcb != NULL) &&
3678 (sid < stcb->asoc.streamoutcnt) &&
3679 (policy == SCTP_PR_SCTP_ALL)) {
3680 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3681 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3683 SCTP_TCB_UNLOCK(stcb);
3684 *optsize = sizeof(struct sctp_prstatus);
3686 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3691 case SCTP_PR_ASSOC_STATUS:
3693 struct sctp_prstatus *sprstat;
3696 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3697 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3699 policy = sprstat->sprstat_policy;
3700 if ((stcb != NULL) &&
3701 (policy != SCTP_PR_SCTP_NONE) &&
3702 ((policy <= SCTP_PR_SCTP_MAX) ||
3703 (policy == SCTP_PR_SCTP_ALL))) {
3704 if (policy == SCTP_PR_SCTP_ALL) {
3705 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3706 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3708 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3709 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3711 SCTP_TCB_UNLOCK(stcb);
3712 *optsize = sizeof(struct sctp_prstatus);
3714 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3721 struct sctp_assoc_value *av;
3723 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3724 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3727 av->assoc_value = stcb->asoc.max_cwnd;
3728 SCTP_TCB_UNLOCK(stcb);
3730 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3731 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3732 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3733 SCTP_INP_RLOCK(inp);
3734 av->assoc_value = inp->max_cwnd;
3735 SCTP_INP_RUNLOCK(inp);
3737 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3742 *optsize = sizeof(struct sctp_assoc_value);
3747 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3748 error = ENOPROTOOPT;
3750 } /* end switch (sopt->sopt_name) */
3758 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3763 struct sctp_tcb *stcb = NULL;
3764 struct sctp_inpcb *inp = NULL;
3767 if (optval == NULL) {
3768 SCTP_PRINTF("optval is NULL\n");
3769 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3772 inp = (struct sctp_inpcb *)so->so_pcb;
3774 SCTP_PRINTF("inp is NULL?\n");
3775 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3778 vrf_id = inp->def_vrf_id;
3783 case SCTP_AUTOCLOSE:
3784 case SCTP_AUTO_ASCONF:
3785 case SCTP_EXPLICIT_EOR:
3786 case SCTP_DISABLE_FRAGMENTS:
3787 case SCTP_USE_EXT_RCVINFO:
3788 case SCTP_I_WANT_MAPPED_V4_ADDR:
3789 /* copy in the option value */
3790 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3795 case SCTP_DISABLE_FRAGMENTS:
3796 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3798 case SCTP_AUTO_ASCONF:
3800 * NOTE: we don't really support this flag
3802 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3803 /* only valid for bound all sockets */
3804 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3806 /* forbidden by admin */
3807 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3810 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3812 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3816 case SCTP_EXPLICIT_EOR:
3817 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3819 case SCTP_USE_EXT_RCVINFO:
3820 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3822 case SCTP_I_WANT_MAPPED_V4_ADDR:
3823 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3824 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3826 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3831 set_opt = SCTP_PCB_FLAGS_NODELAY;
3833 case SCTP_AUTOCLOSE:
3834 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3835 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3836 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3839 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3841 * The value is in ticks. Note this does not effect
3842 * old associations, only new ones.
3844 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3847 SCTP_INP_WLOCK(inp);
3849 sctp_feature_on(inp, set_opt);
3851 sctp_feature_off(inp, set_opt);
3853 SCTP_INP_WUNLOCK(inp);
3855 case SCTP_REUSE_PORT:
3857 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3858 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3859 /* Can't set it after we are bound */
3863 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3864 /* Can't do this for a 1-m socket */
3869 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3871 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3874 case SCTP_PARTIAL_DELIVERY_POINT:
3878 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3879 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3880 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3884 inp->partial_delivery_point = *value;
3887 case SCTP_FRAGMENT_INTERLEAVE:
3888 /* not yet until we re-write sctp_recvmsg() */
3892 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3893 if (*level == SCTP_FRAG_LEVEL_2) {
3894 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3895 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3896 } else if (*level == SCTP_FRAG_LEVEL_1) {
3897 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3898 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3899 } else if (*level == SCTP_FRAG_LEVEL_0) {
3900 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3901 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3904 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3909 case SCTP_INTERLEAVING_SUPPORTED:
3911 struct sctp_assoc_value *av;
3913 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3914 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3917 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3919 SCTP_TCB_UNLOCK(stcb);
3921 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3922 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3923 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3924 SCTP_INP_WLOCK(inp);
3925 if (av->assoc_value == 0) {
3926 inp->idata_supported = 0;
3928 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3929 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3930 inp->idata_supported = 1;
3938 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3942 SCTP_INP_WUNLOCK(inp);
3944 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3950 case SCTP_CMT_ON_OFF:
3951 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3952 struct sctp_assoc_value *av;
3954 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3955 if (av->assoc_value > SCTP_CMT_MAX) {
3956 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3960 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3962 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
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_cmt_on_off = 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.sctp_cmt_on_off = av->assoc_value;
3979 SCTP_TCB_UNLOCK(stcb);
3981 SCTP_INP_RUNLOCK(inp);
3985 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3986 error = ENOPROTOOPT;
3989 case SCTP_PLUGGABLE_CC:
3991 struct sctp_assoc_value *av;
3992 struct sctp_nets *net;
3994 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3995 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3996 (av->assoc_value != SCTP_CC_HSTCP) &&
3997 (av->assoc_value != SCTP_CC_HTCP) &&
3998 (av->assoc_value != SCTP_CC_RTCC)) {
3999 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4003 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4005 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4006 stcb->asoc.congestion_control_module = av->assoc_value;
4007 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4008 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4009 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4012 SCTP_TCB_UNLOCK(stcb);
4014 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4015 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4016 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4017 (av->assoc_id == SCTP_ALL_ASSOC)) {
4018 SCTP_INP_WLOCK(inp);
4019 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
4020 SCTP_INP_WUNLOCK(inp);
4022 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4023 (av->assoc_id == SCTP_ALL_ASSOC)) {
4024 SCTP_INP_RLOCK(inp);
4025 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4026 SCTP_TCB_LOCK(stcb);
4027 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4028 stcb->asoc.congestion_control_module = av->assoc_value;
4029 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4030 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4031 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4034 SCTP_TCB_UNLOCK(stcb);
4036 SCTP_INP_RUNLOCK(inp);
4041 case SCTP_CC_OPTION:
4043 struct sctp_cc_option *cc_opt;
4045 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4046 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4048 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
4049 SCTP_INP_RLOCK(inp);
4050 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4051 SCTP_TCB_LOCK(stcb);
4052 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4053 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4055 SCTP_TCB_UNLOCK(stcb);
4057 SCTP_INP_RUNLOCK(inp);
4062 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4065 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4068 SCTP_TCB_UNLOCK(stcb);
4072 case SCTP_PLUGGABLE_SS:
4074 struct sctp_assoc_value *av;
4076 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4077 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4078 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4079 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4080 (av->assoc_value != SCTP_SS_PRIORITY) &&
4081 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4082 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4083 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4087 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4089 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4090 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4091 stcb->asoc.stream_scheduling_module = av->assoc_value;
4092 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4093 SCTP_TCB_UNLOCK(stcb);
4095 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4096 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4097 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4098 (av->assoc_id == SCTP_ALL_ASSOC)) {
4099 SCTP_INP_WLOCK(inp);
4100 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4101 SCTP_INP_WUNLOCK(inp);
4103 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4104 (av->assoc_id == SCTP_ALL_ASSOC)) {
4105 SCTP_INP_RLOCK(inp);
4106 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4107 SCTP_TCB_LOCK(stcb);
4108 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4109 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4110 stcb->asoc.stream_scheduling_module = av->assoc_value;
4111 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4112 SCTP_TCB_UNLOCK(stcb);
4114 SCTP_INP_RUNLOCK(inp);
4121 struct sctp_stream_value *av;
4123 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4124 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4126 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4127 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4128 av->stream_value) < 0)) {
4129 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4132 SCTP_TCB_UNLOCK(stcb);
4134 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4135 SCTP_INP_RLOCK(inp);
4136 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4137 SCTP_TCB_LOCK(stcb);
4138 if (av->stream_id < stcb->asoc.streamoutcnt) {
4139 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4141 &stcb->asoc.strmout[av->stream_id],
4144 SCTP_TCB_UNLOCK(stcb);
4146 SCTP_INP_RUNLOCK(inp);
4149 * Can't set stream value without
4152 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4158 case SCTP_CLR_STAT_LOG:
4159 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4164 struct sctp_assoc_value *av;
4166 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4167 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4170 stcb->asoc.context = av->assoc_value;
4171 SCTP_TCB_UNLOCK(stcb);
4173 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4174 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4175 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4176 (av->assoc_id == SCTP_ALL_ASSOC)) {
4177 SCTP_INP_WLOCK(inp);
4178 inp->sctp_context = av->assoc_value;
4179 SCTP_INP_WUNLOCK(inp);
4181 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4182 (av->assoc_id == SCTP_ALL_ASSOC)) {
4183 SCTP_INP_RLOCK(inp);
4184 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4185 SCTP_TCB_LOCK(stcb);
4186 stcb->asoc.context = av->assoc_value;
4187 SCTP_TCB_UNLOCK(stcb);
4189 SCTP_INP_RUNLOCK(inp);
4196 uint32_t *default_vrfid;
4198 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4199 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4200 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4204 inp->def_vrf_id = *default_vrfid;
4207 case SCTP_DEL_VRF_ID:
4209 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4213 case SCTP_ADD_VRF_ID:
4215 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4219 case SCTP_DELAYED_SACK:
4221 struct sctp_sack_info *sack;
4223 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4224 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4225 if (sack->sack_delay) {
4226 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4227 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4228 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4229 sack->sack_delay = TICKS_TO_MSEC(1);
4233 if (sack->sack_delay) {
4234 stcb->asoc.delayed_ack = sack->sack_delay;
4236 if (sack->sack_freq) {
4237 stcb->asoc.sack_freq = sack->sack_freq;
4239 SCTP_TCB_UNLOCK(stcb);
4241 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4242 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4243 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4244 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4245 SCTP_INP_WLOCK(inp);
4246 if (sack->sack_delay) {
4247 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4249 if (sack->sack_freq) {
4250 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4252 SCTP_INP_WUNLOCK(inp);
4254 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4255 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4256 SCTP_INP_RLOCK(inp);
4257 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4258 SCTP_TCB_LOCK(stcb);
4259 if (sack->sack_delay) {
4260 stcb->asoc.delayed_ack = sack->sack_delay;
4262 if (sack->sack_freq) {
4263 stcb->asoc.sack_freq = sack->sack_freq;
4265 SCTP_TCB_UNLOCK(stcb);
4267 SCTP_INP_RUNLOCK(inp);
4272 case SCTP_AUTH_CHUNK:
4274 struct sctp_authchunk *sauth;
4276 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4278 SCTP_INP_WLOCK(inp);
4279 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4280 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4283 SCTP_INP_WUNLOCK(inp);
4288 struct sctp_authkey *sca;
4289 struct sctp_keyhead *shared_keys;
4290 sctp_sharedkey_t *shared_key;
4291 sctp_key_t *key = NULL;
4294 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4295 if (sca->sca_keylength == 0) {
4296 size = optsize - sizeof(struct sctp_authkey);
4298 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4299 size = sca->sca_keylength;
4301 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4306 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4309 shared_keys = &stcb->asoc.shared_keys;
4310 /* clear the cached keys for this key id */
4311 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4313 * create the new shared key and
4317 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4319 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4321 SCTP_TCB_UNLOCK(stcb);
4325 shared_key = sctp_alloc_sharedkey();
4326 if (shared_key == NULL) {
4328 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4330 SCTP_TCB_UNLOCK(stcb);
4333 shared_key->key = key;
4334 shared_key->keyid = sca->sca_keynumber;
4335 error = sctp_insert_sharedkey(shared_keys, shared_key);
4336 SCTP_TCB_UNLOCK(stcb);
4338 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4339 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4340 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4341 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4342 SCTP_INP_WLOCK(inp);
4343 shared_keys = &inp->sctp_ep.shared_keys;
4345 * clear the cached keys on all
4346 * assocs for this key id
4348 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4350 * create the new shared key and
4354 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4356 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4358 SCTP_INP_WUNLOCK(inp);
4362 shared_key = sctp_alloc_sharedkey();
4363 if (shared_key == NULL) {
4365 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4367 SCTP_INP_WUNLOCK(inp);
4370 shared_key->key = key;
4371 shared_key->keyid = sca->sca_keynumber;
4372 error = sctp_insert_sharedkey(shared_keys, shared_key);
4373 SCTP_INP_WUNLOCK(inp);
4375 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4376 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4377 SCTP_INP_RLOCK(inp);
4378 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4379 SCTP_TCB_LOCK(stcb);
4380 shared_keys = &stcb->asoc.shared_keys;
4382 * clear the cached keys for
4385 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4387 * create the new shared key
4388 * and insert/replace it
4391 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4393 SCTP_TCB_UNLOCK(stcb);
4397 shared_key = sctp_alloc_sharedkey();
4398 if (shared_key == NULL) {
4400 SCTP_TCB_UNLOCK(stcb);
4403 shared_key->key = key;
4404 shared_key->keyid = sca->sca_keynumber;
4405 error = sctp_insert_sharedkey(shared_keys, shared_key);
4406 SCTP_TCB_UNLOCK(stcb);
4408 SCTP_INP_RUNLOCK(inp);
4413 case SCTP_HMAC_IDENT:
4415 struct sctp_hmacalgo *shmac;
4416 sctp_hmaclist_t *hmaclist;
4420 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4421 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4422 (shmac->shmac_number_of_idents > 0xffff)) {
4423 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4427 hmaclist = sctp_alloc_hmaclist((uint16_t) shmac->shmac_number_of_idents);
4428 if (hmaclist == NULL) {
4429 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4433 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4434 hmacid = shmac->shmac_idents[i];
4435 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4436 /* invalid HMACs were found */ ;
4437 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4439 sctp_free_hmaclist(hmaclist);
4440 goto sctp_set_hmac_done;
4443 for (i = 0; i < hmaclist->num_algo; i++) {
4444 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4445 /* already in list */
4449 if (i == hmaclist->num_algo) {
4450 /* not found in list */
4451 sctp_free_hmaclist(hmaclist);
4452 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4456 /* set it on the endpoint */
4457 SCTP_INP_WLOCK(inp);
4458 if (inp->sctp_ep.local_hmacs)
4459 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4460 inp->sctp_ep.local_hmacs = hmaclist;
4461 SCTP_INP_WUNLOCK(inp);
4465 case SCTP_AUTH_ACTIVE_KEY:
4467 struct sctp_authkeyid *scact;
4469 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4470 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4472 /* set the active key on the right place */
4474 /* set the active key on the assoc */
4475 if (sctp_auth_setactivekey(stcb,
4476 scact->scact_keynumber)) {
4477 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4478 SCTP_FROM_SCTP_USRREQ,
4482 SCTP_TCB_UNLOCK(stcb);
4484 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4485 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4486 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4487 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4488 SCTP_INP_WLOCK(inp);
4489 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4490 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4493 SCTP_INP_WUNLOCK(inp);
4495 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4496 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4497 SCTP_INP_RLOCK(inp);
4498 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4499 SCTP_TCB_LOCK(stcb);
4500 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4501 SCTP_TCB_UNLOCK(stcb);
4503 SCTP_INP_RUNLOCK(inp);
4508 case SCTP_AUTH_DELETE_KEY:
4510 struct sctp_authkeyid *scdel;
4512 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4513 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4515 /* delete the key from the right place */
4517 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4518 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4521 SCTP_TCB_UNLOCK(stcb);
4523 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4524 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4525 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4526 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4527 SCTP_INP_WLOCK(inp);
4528 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4529 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4532 SCTP_INP_WUNLOCK(inp);
4534 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4535 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4536 SCTP_INP_RLOCK(inp);
4537 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4538 SCTP_TCB_LOCK(stcb);
4539 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4540 SCTP_TCB_UNLOCK(stcb);
4542 SCTP_INP_RUNLOCK(inp);
4547 case SCTP_AUTH_DEACTIVATE_KEY:
4549 struct sctp_authkeyid *keyid;
4551 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4552 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4554 /* deactivate the key from the right place */
4556 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4557 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4560 SCTP_TCB_UNLOCK(stcb);
4562 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4563 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4564 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4565 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4566 SCTP_INP_WLOCK(inp);
4567 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4568 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4571 SCTP_INP_WUNLOCK(inp);
4573 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4574 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4575 SCTP_INP_RLOCK(inp);
4576 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4577 SCTP_TCB_LOCK(stcb);
4578 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4579 SCTP_TCB_UNLOCK(stcb);
4581 SCTP_INP_RUNLOCK(inp);
4586 case SCTP_ENABLE_STREAM_RESET:
4588 struct sctp_assoc_value *av;
4590 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4591 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4592 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4596 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4598 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4599 SCTP_TCB_UNLOCK(stcb);
4601 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4602 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4603 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4604 (av->assoc_id == SCTP_ALL_ASSOC)) {
4605 SCTP_INP_WLOCK(inp);
4606 inp->local_strreset_support = (uint8_t) av->assoc_value;
4607 SCTP_INP_WUNLOCK(inp);
4609 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4610 (av->assoc_id == SCTP_ALL_ASSOC)) {
4611 SCTP_INP_RLOCK(inp);
4612 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4613 SCTP_TCB_LOCK(stcb);
4614 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4615 SCTP_TCB_UNLOCK(stcb);
4617 SCTP_INP_RUNLOCK(inp);
4622 case SCTP_RESET_STREAMS:
4624 struct sctp_reset_streams *strrst;
4625 int i, send_out = 0;
4628 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4629 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4631 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4635 if (stcb->asoc.reconfig_supported == 0) {
4637 * Peer does not support the chunk type.
4639 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4641 SCTP_TCB_UNLOCK(stcb);
4644 if (sizeof(struct sctp_reset_streams) +
4645 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4647 SCTP_TCB_UNLOCK(stcb);
4650 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4652 if (stcb->asoc.stream_reset_outstanding) {
4653 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4655 SCTP_TCB_UNLOCK(stcb);
4659 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4662 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4663 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4665 SCTP_TCB_UNLOCK(stcb);
4668 if ((send_in == 0) && (send_out == 0)) {
4669 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4671 SCTP_TCB_UNLOCK(stcb);
4674 for (i = 0; i < strrst->srs_number_streams; i++) {
4676 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4677 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4682 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4683 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4689 SCTP_TCB_UNLOCK(stcb);
4696 if (strrst->srs_number_streams) {
4697 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4698 strm = strrst->srs_stream_list[i];
4699 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4700 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4706 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4707 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4708 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4715 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4716 strrst->srs_stream_list,
4717 send_in, 0, 0, 0, 0, 0);
4719 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4722 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4725 * For outgoing streams don't report any
4726 * problems in sending the request to the
4727 * application. XXX: Double check resetting
4732 SCTP_TCB_UNLOCK(stcb);
4735 case SCTP_ADD_STREAMS:
4737 struct sctp_add_streams *stradd;
4738 uint8_t addstream = 0;
4739 uint16_t add_o_strmcnt = 0;
4740 uint16_t add_i_strmcnt = 0;
4742 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4743 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4745 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4749 if (stcb->asoc.reconfig_supported == 0) {
4751 * Peer does not support the chunk type.
4753 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4755 SCTP_TCB_UNLOCK(stcb);
4758 if (stcb->asoc.stream_reset_outstanding) {
4759 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4761 SCTP_TCB_UNLOCK(stcb);
4764 if ((stradd->sas_outstrms == 0) &&
4765 (stradd->sas_instrms == 0)) {
4769 if (stradd->sas_outstrms) {
4771 /* We allocate here */
4772 add_o_strmcnt = stradd->sas_outstrms;
4773 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4774 /* You can't have more than 64k */
4779 if (stradd->sas_instrms) {
4784 * We allocate inside
4785 * sctp_send_str_reset_req()
4787 add_i_strmcnt = stradd->sas_instrms;
4788 cnt = add_i_strmcnt;
4789 cnt += stcb->asoc.streamincnt;
4790 if (cnt > 0x0000ffff) {
4791 /* You can't have more than 64k */
4795 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4796 /* More than you are allowed */
4801 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4802 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4804 SCTP_TCB_UNLOCK(stcb);
4807 case SCTP_RESET_ASSOC:
4812 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4813 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4815 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4819 if (stcb->asoc.reconfig_supported == 0) {
4821 * Peer does not support the chunk type.
4823 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4825 SCTP_TCB_UNLOCK(stcb);
4828 if (stcb->asoc.stream_reset_outstanding) {
4829 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4831 SCTP_TCB_UNLOCK(stcb);
4835 * Is there any data pending in the send or sent
4838 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4839 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4842 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4843 SCTP_TCB_UNLOCK(stcb);
4846 /* Do any streams have data queued? */
4847 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4848 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4852 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4853 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4854 SCTP_TCB_UNLOCK(stcb);
4857 case SCTP_CONNECT_X:
4858 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4859 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4863 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4865 case SCTP_CONNECT_X_DELAYED:
4866 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4867 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4871 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4873 case SCTP_CONNECT_X_COMPLETE:
4875 struct sockaddr *sa;
4877 /* FIXME MT: check correct? */
4878 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4881 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4882 SCTP_INP_RLOCK(inp);
4883 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4885 SCTP_TCB_LOCK(stcb);
4887 SCTP_INP_RUNLOCK(inp);
4890 * We increment here since
4891 * sctp_findassociation_ep_addr() wil do a
4892 * decrement if it finds the stcb as long as
4893 * the locked tcb (last argument) is NOT a
4896 SCTP_INP_INCR_REF(inp);
4897 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4899 SCTP_INP_DECR_REF(inp);
4904 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4908 if (stcb->asoc.delayed_connection == 1) {
4909 stcb->asoc.delayed_connection = 0;
4910 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4911 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4912 stcb->asoc.primary_destination,
4913 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4914 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4917 * already expired or did not use delayed
4920 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4923 SCTP_TCB_UNLOCK(stcb);
4926 case SCTP_MAX_BURST:
4928 struct sctp_assoc_value *av;
4930 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4931 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4934 stcb->asoc.max_burst = av->assoc_value;
4935 SCTP_TCB_UNLOCK(stcb);
4937 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4938 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4939 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4940 (av->assoc_id == SCTP_ALL_ASSOC)) {
4941 SCTP_INP_WLOCK(inp);
4942 inp->sctp_ep.max_burst = av->assoc_value;
4943 SCTP_INP_WUNLOCK(inp);
4945 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4946 (av->assoc_id == SCTP_ALL_ASSOC)) {
4947 SCTP_INP_RLOCK(inp);
4948 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4949 SCTP_TCB_LOCK(stcb);
4950 stcb->asoc.max_burst = av->assoc_value;
4951 SCTP_TCB_UNLOCK(stcb);
4953 SCTP_INP_RUNLOCK(inp);
4960 struct sctp_assoc_value *av;
4963 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4964 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4966 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4967 ovh = SCTP_MED_OVERHEAD;
4969 ovh = SCTP_MED_V4_OVERHEAD;
4972 if (av->assoc_value) {
4973 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4975 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4977 SCTP_TCB_UNLOCK(stcb);
4979 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4980 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4981 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4982 SCTP_INP_WLOCK(inp);
4984 * FIXME MT: I think this is not in
4985 * tune with the API ID
4987 if (av->assoc_value) {
4988 inp->sctp_frag_point = (av->assoc_value + ovh);
4990 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4992 SCTP_INP_WUNLOCK(inp);
4994 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5002 struct sctp_event_subscribe *events;
5004 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
5006 SCTP_INP_WLOCK(inp);
5007 if (events->sctp_data_io_event) {
5008 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5010 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5013 if (events->sctp_association_event) {
5014 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5016 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5019 if (events->sctp_address_event) {
5020 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5022 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5025 if (events->sctp_send_failure_event) {
5026 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5028 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5031 if (events->sctp_peer_error_event) {
5032 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5034 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5037 if (events->sctp_shutdown_event) {
5038 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5040 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5043 if (events->sctp_partial_delivery_event) {
5044 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5046 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5049 if (events->sctp_adaptation_layer_event) {
5050 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5052 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5055 if (events->sctp_authentication_event) {
5056 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5058 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5061 if (events->sctp_sender_dry_event) {
5062 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5064 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5067 if (events->sctp_stream_reset_event) {
5068 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5070 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5072 SCTP_INP_WUNLOCK(inp);
5074 SCTP_INP_RLOCK(inp);
5075 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5076 SCTP_TCB_LOCK(stcb);
5077 if (events->sctp_association_event) {
5078 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5080 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5082 if (events->sctp_address_event) {
5083 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5085 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5087 if (events->sctp_send_failure_event) {
5088 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5090 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5092 if (events->sctp_peer_error_event) {
5093 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5095 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5097 if (events->sctp_shutdown_event) {
5098 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5100 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5102 if (events->sctp_partial_delivery_event) {
5103 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5105 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5107 if (events->sctp_adaptation_layer_event) {
5108 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5110 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5112 if (events->sctp_authentication_event) {
5113 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5115 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5117 if (events->sctp_sender_dry_event) {
5118 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5120 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5122 if (events->sctp_stream_reset_event) {
5123 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5125 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5127 SCTP_TCB_UNLOCK(stcb);
5130 * Send up the sender dry event only for 1-to-1
5133 if (events->sctp_sender_dry_event) {
5134 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5135 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5136 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5138 SCTP_TCB_LOCK(stcb);
5139 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5140 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5141 (stcb->asoc.stream_queue_cnt == 0)) {
5142 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5144 SCTP_TCB_UNLOCK(stcb);
5148 SCTP_INP_RUNLOCK(inp);
5151 case SCTP_ADAPTATION_LAYER:
5153 struct sctp_setadaptation *adap_bits;
5155 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5156 SCTP_INP_WLOCK(inp);
5157 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5158 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5159 SCTP_INP_WUNLOCK(inp);
5163 case SCTP_SET_INITIAL_DBG_SEQ:
5167 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5168 SCTP_INP_WLOCK(inp);
5169 inp->sctp_ep.initial_sequence_debug = *vvv;
5170 SCTP_INP_WUNLOCK(inp);
5174 case SCTP_DEFAULT_SEND_PARAM:
5176 struct sctp_sndrcvinfo *s_info;
5178 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5179 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5182 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5183 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5185 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5188 SCTP_TCB_UNLOCK(stcb);
5190 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5191 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5192 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5193 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5194 SCTP_INP_WLOCK(inp);
5195 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5196 SCTP_INP_WUNLOCK(inp);
5198 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5199 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5200 SCTP_INP_RLOCK(inp);
5201 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5202 SCTP_TCB_LOCK(stcb);
5203 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5204 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5206 SCTP_TCB_UNLOCK(stcb);
5208 SCTP_INP_RUNLOCK(inp);
5213 case SCTP_PEER_ADDR_PARAMS:
5215 struct sctp_paddrparams *paddrp;
5216 struct sctp_nets *net;
5217 struct sockaddr *addr;
5219 #if defined(INET) && defined(INET6)
5220 struct sockaddr_in sin_store;
5224 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5225 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5227 #if defined(INET) && defined(INET6)
5228 if (paddrp->spp_address.ss_family == AF_INET6) {
5229 struct sockaddr_in6 *sin6;
5231 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5232 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5233 in6_sin6_2_sin(&sin_store, sin6);
5234 addr = (struct sockaddr *)&sin_store;
5236 addr = (struct sockaddr *)&paddrp->spp_address;
5239 addr = (struct sockaddr *)&paddrp->spp_address;
5242 addr = (struct sockaddr *)&paddrp->spp_address;
5245 net = sctp_findnet(stcb, addr);
5248 * We increment here since
5249 * sctp_findassociation_ep_addr() wil do a
5250 * decrement if it finds the stcb as long as
5251 * the locked tcb (last argument) is NOT a
5255 SCTP_INP_INCR_REF(inp);
5256 stcb = sctp_findassociation_ep_addr(&inp, addr,
5259 SCTP_INP_DECR_REF(inp);
5262 if ((stcb != NULL) && (net == NULL)) {
5264 if (addr->sa_family == AF_INET) {
5266 struct sockaddr_in *sin;
5268 sin = (struct sockaddr_in *)addr;
5269 if (sin->sin_addr.s_addr != INADDR_ANY) {
5270 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5271 SCTP_TCB_UNLOCK(stcb);
5278 if (addr->sa_family == AF_INET6) {
5279 struct sockaddr_in6 *sin6;
5281 sin6 = (struct sockaddr_in6 *)addr;
5282 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5283 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5284 SCTP_TCB_UNLOCK(stcb);
5291 error = EAFNOSUPPORT;
5292 SCTP_TCB_UNLOCK(stcb);
5293 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5298 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5300 SCTP_TCB_UNLOCK(stcb);
5301 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5304 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5306 SCTP_TCB_UNLOCK(stcb);
5307 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5311 /************************TCB SPECIFIC SET ******************/
5313 /************************NET SPECIFIC SET ******************/
5314 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5315 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5316 !(net->dest_state & SCTP_ADDR_NOHB)) {
5317 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5318 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5320 net->dest_state |= SCTP_ADDR_NOHB;
5322 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5323 if (paddrp->spp_hbinterval) {
5324 net->heart_beat_delay = paddrp->spp_hbinterval;
5325 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5326 net->heart_beat_delay = 0;
5328 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5329 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5330 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5331 net->dest_state &= ~SCTP_ADDR_NOHB;
5333 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5335 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5336 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5337 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5339 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5340 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5341 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5342 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5344 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5345 net->mtu = paddrp->spp_pathmtu;
5346 switch (net->ro._l_addr.sa.sa_family) {
5349 net->mtu += SCTP_MIN_V4_OVERHEAD;
5354 net->mtu += SCTP_MIN_OVERHEAD;
5360 if (net->mtu < stcb->asoc.smallest_mtu) {
5361 sctp_pathmtu_adjustment(stcb, net->mtu);
5364 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5365 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5366 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5368 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5370 if (paddrp->spp_pathmaxrxt) {
5371 if (net->dest_state & SCTP_ADDR_PF) {
5372 if (net->error_count > paddrp->spp_pathmaxrxt) {
5373 net->dest_state &= ~SCTP_ADDR_PF;
5376 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5377 (net->error_count > net->pf_threshold)) {
5378 net->dest_state |= SCTP_ADDR_PF;
5379 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5380 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5381 stcb->sctp_ep, stcb, net,
5382 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5383 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5386 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5387 if (net->error_count > paddrp->spp_pathmaxrxt) {
5388 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5389 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5392 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5393 net->dest_state |= SCTP_ADDR_REACHABLE;
5394 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5397 net->failure_threshold = paddrp->spp_pathmaxrxt;
5399 if (paddrp->spp_flags & SPP_DSCP) {
5400 net->dscp = paddrp->spp_dscp & 0xfc;
5404 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5405 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5406 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5407 net->flowlabel |= 0x80000000;
5412 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5413 if (paddrp->spp_pathmaxrxt != 0) {
5414 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5415 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5416 if (net->dest_state & SCTP_ADDR_PF) {
5417 if (net->error_count > paddrp->spp_pathmaxrxt) {
5418 net->dest_state &= ~SCTP_ADDR_PF;
5421 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5422 (net->error_count > net->pf_threshold)) {
5423 net->dest_state |= SCTP_ADDR_PF;
5424 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5425 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5426 stcb->sctp_ep, stcb, net,
5427 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5428 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5431 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5432 if (net->error_count > paddrp->spp_pathmaxrxt) {
5433 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5434 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5437 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5438 net->dest_state |= SCTP_ADDR_REACHABLE;
5439 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5442 net->failure_threshold = paddrp->spp_pathmaxrxt;
5445 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5446 if (paddrp->spp_hbinterval != 0) {
5447 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5448 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5449 stcb->asoc.heart_beat_delay = 0;
5451 /* Turn back on the timer */
5452 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5453 if (paddrp->spp_hbinterval != 0) {
5454 net->heart_beat_delay = paddrp->spp_hbinterval;
5455 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5456 net->heart_beat_delay = 0;
5458 if (net->dest_state & SCTP_ADDR_NOHB) {
5459 net->dest_state &= ~SCTP_ADDR_NOHB;
5461 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5462 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5463 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5465 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5467 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5468 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5469 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5470 net->dest_state |= SCTP_ADDR_NOHB;
5471 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5472 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5474 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5478 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5480 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5481 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5482 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5483 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5484 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5486 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5487 net->mtu = paddrp->spp_pathmtu;
5488 switch (net->ro._l_addr.sa.sa_family) {
5491 net->mtu += SCTP_MIN_V4_OVERHEAD;
5496 net->mtu += SCTP_MIN_OVERHEAD;
5502 if (net->mtu < stcb->asoc.smallest_mtu) {
5503 sctp_pathmtu_adjustment(stcb, net->mtu);
5506 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5508 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5509 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5510 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5511 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5513 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5515 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5517 if (paddrp->spp_flags & SPP_DSCP) {
5518 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5519 net->dscp = paddrp->spp_dscp & 0xfc;
5522 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5523 stcb->asoc.default_dscp |= 0x01;
5526 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5527 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5528 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5529 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5530 net->flowlabel |= 0x80000000;
5533 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5534 stcb->asoc.default_flowlabel |= 0x80000000;
5538 SCTP_TCB_UNLOCK(stcb);
5540 /************************NO TCB, SET TO default stuff ******************/
5541 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5542 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5543 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5544 SCTP_INP_WLOCK(inp);
5546 * For the TOS/FLOWLABEL stuff you
5547 * set it with the options on the
5550 if (paddrp->spp_pathmaxrxt != 0) {
5551 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5553 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5554 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5555 else if (paddrp->spp_hbinterval != 0) {
5556 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5557 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5558 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5560 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5561 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5562 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5563 } else if (paddrp->spp_hbinterval) {
5564 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5566 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5567 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5568 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5570 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5571 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5572 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5573 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5575 if (paddrp->spp_flags & SPP_DSCP) {
5576 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5577 inp->sctp_ep.default_dscp |= 0x01;
5580 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5581 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5582 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5583 inp->sctp_ep.default_flowlabel |= 0x80000000;
5587 SCTP_INP_WUNLOCK(inp);
5589 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5597 struct sctp_rtoinfo *srto;
5598 uint32_t new_init, new_min, new_max;
5600 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5601 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5604 if (srto->srto_initial)
5605 new_init = srto->srto_initial;
5607 new_init = stcb->asoc.initial_rto;
5609 new_max = srto->srto_max;
5611 new_max = stcb->asoc.maxrto;
5613 new_min = srto->srto_min;
5615 new_min = stcb->asoc.minrto;
5616 if ((new_min <= new_init) && (new_init <= new_max)) {
5617 stcb->asoc.initial_rto = new_init;
5618 stcb->asoc.maxrto = new_max;
5619 stcb->asoc.minrto = new_min;
5621 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5624 SCTP_TCB_UNLOCK(stcb);
5626 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5627 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5628 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5629 SCTP_INP_WLOCK(inp);
5630 if (srto->srto_initial)
5631 new_init = srto->srto_initial;
5633 new_init = inp->sctp_ep.initial_rto;
5635 new_max = srto->srto_max;
5637 new_max = inp->sctp_ep.sctp_maxrto;
5639 new_min = srto->srto_min;
5641 new_min = inp->sctp_ep.sctp_minrto;
5642 if ((new_min <= new_init) && (new_init <= new_max)) {
5643 inp->sctp_ep.initial_rto = new_init;
5644 inp->sctp_ep.sctp_maxrto = new_max;
5645 inp->sctp_ep.sctp_minrto = new_min;
5647 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5650 SCTP_INP_WUNLOCK(inp);
5652 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5658 case SCTP_ASSOCINFO:
5660 struct sctp_assocparams *sasoc;
5662 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5663 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5664 if (sasoc->sasoc_cookie_life) {
5665 /* boundary check the cookie life */
5666 if (sasoc->sasoc_cookie_life < 1000)
5667 sasoc->sasoc_cookie_life = 1000;
5668 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5669 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5673 if (sasoc->sasoc_asocmaxrxt)
5674 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5675 if (sasoc->sasoc_cookie_life) {
5676 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5678 SCTP_TCB_UNLOCK(stcb);
5680 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5681 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5682 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5683 SCTP_INP_WLOCK(inp);
5684 if (sasoc->sasoc_asocmaxrxt)
5685 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5686 if (sasoc->sasoc_cookie_life) {
5687 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5689 SCTP_INP_WUNLOCK(inp);
5691 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5699 struct sctp_initmsg *sinit;
5701 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5702 SCTP_INP_WLOCK(inp);
5703 if (sinit->sinit_num_ostreams)
5704 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5706 if (sinit->sinit_max_instreams)
5707 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5709 if (sinit->sinit_max_attempts)
5710 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5712 if (sinit->sinit_max_init_timeo)
5713 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5714 SCTP_INP_WUNLOCK(inp);
5717 case SCTP_PRIMARY_ADDR:
5719 struct sctp_setprim *spa;
5720 struct sctp_nets *net;
5721 struct sockaddr *addr;
5723 #if defined(INET) && defined(INET6)
5724 struct sockaddr_in sin_store;
5728 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5729 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5731 #if defined(INET) && defined(INET6)
5732 if (spa->ssp_addr.ss_family == AF_INET6) {
5733 struct sockaddr_in6 *sin6;
5735 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5736 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5737 in6_sin6_2_sin(&sin_store, sin6);
5738 addr = (struct sockaddr *)&sin_store;
5740 addr = (struct sockaddr *)&spa->ssp_addr;
5743 addr = (struct sockaddr *)&spa->ssp_addr;
5746 addr = (struct sockaddr *)&spa->ssp_addr;
5749 net = sctp_findnet(stcb, addr);
5752 * We increment here since
5753 * sctp_findassociation_ep_addr() wil do a
5754 * decrement if it finds the stcb as long as
5755 * the locked tcb (last argument) is NOT a
5759 SCTP_INP_INCR_REF(inp);
5760 stcb = sctp_findassociation_ep_addr(&inp, addr,
5763 SCTP_INP_DECR_REF(inp);
5767 if ((stcb != NULL) && (net != NULL)) {
5768 if (net != stcb->asoc.primary_destination) {
5769 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5770 /* Ok we need to set it */
5771 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5772 if ((stcb->asoc.alternate) &&
5773 (!(net->dest_state & SCTP_ADDR_PF)) &&
5774 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5775 sctp_free_remote_addr(stcb->asoc.alternate);
5776 stcb->asoc.alternate = NULL;
5779 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5783 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5788 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5792 SCTP_TCB_UNLOCK(stcb);
5796 case SCTP_SET_DYNAMIC_PRIMARY:
5798 union sctp_sockstore *ss;
5800 error = priv_check(curthread,
5801 PRIV_NETINET_RESERVEDPORT);
5805 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5806 /* SUPER USER CHECK? */
5807 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5810 case SCTP_SET_PEER_PRIMARY_ADDR:
5812 struct sctp_setpeerprim *sspp;
5813 struct sockaddr *addr;
5815 #if defined(INET) && defined(INET6)
5816 struct sockaddr_in sin_store;
5820 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5821 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5823 struct sctp_ifa *ifa;
5825 #if defined(INET) && defined(INET6)
5826 if (sspp->sspp_addr.ss_family == AF_INET6) {
5827 struct sockaddr_in6 *sin6;
5829 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5830 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5831 in6_sin6_2_sin(&sin_store, sin6);
5832 addr = (struct sockaddr *)&sin_store;
5834 addr = (struct sockaddr *)&sspp->sspp_addr;
5837 addr = (struct sockaddr *)&sspp->sspp_addr;
5840 addr = (struct sockaddr *)&sspp->sspp_addr;
5842 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5844 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5848 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5850 * Must validate the ifa found is in
5853 struct sctp_laddr *laddr;
5856 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5857 if (laddr->ifa == NULL) {
5858 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5862 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5863 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5866 if (laddr->ifa == ifa) {
5872 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5877 switch (addr->sa_family) {
5881 struct sockaddr_in *sin;
5883 sin = (struct sockaddr_in *)addr;
5884 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5885 &sin->sin_addr) != 0) {
5886 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5896 struct sockaddr_in6 *sin6;
5898 sin6 = (struct sockaddr_in6 *)addr;
5899 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5900 &sin6->sin6_addr) != 0) {
5901 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5909 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5914 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5915 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5918 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5920 SCTP_TCB_UNLOCK(stcb);
5922 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5927 case SCTP_BINDX_ADD_ADDR:
5929 struct sctp_getaddresses *addrs;
5932 td = (struct thread *)p;
5933 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5936 if (addrs->addr->sa_family == AF_INET) {
5937 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5938 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5942 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5943 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5949 if (addrs->addr->sa_family == AF_INET6) {
5950 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5951 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5955 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5956 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5957 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5963 error = EAFNOSUPPORT;
5966 sctp_bindx_add_address(so, inp, addrs->addr,
5967 addrs->sget_assoc_id, vrf_id,
5971 case SCTP_BINDX_REM_ADDR:
5973 struct sctp_getaddresses *addrs;
5976 td = (struct thread *)p;
5978 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5980 if (addrs->addr->sa_family == AF_INET) {
5981 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5982 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5986 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5987 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5993 if (addrs->addr->sa_family == AF_INET6) {
5994 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5995 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6000 (error = prison_local_ip6(td->td_ucred,
6001 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
6002 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6003 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6009 error = EAFNOSUPPORT;
6012 sctp_bindx_delete_address(inp, addrs->addr,
6013 addrs->sget_assoc_id, vrf_id,
6019 struct sctp_event *event;
6020 uint32_t event_type;
6022 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6023 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6024 switch (event->se_type) {
6025 case SCTP_ASSOC_CHANGE:
6026 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6028 case SCTP_PEER_ADDR_CHANGE:
6029 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6031 case SCTP_REMOTE_ERROR:
6032 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6034 case SCTP_SEND_FAILED:
6035 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6037 case SCTP_SHUTDOWN_EVENT:
6038 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6040 case SCTP_ADAPTATION_INDICATION:
6041 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6043 case SCTP_PARTIAL_DELIVERY_EVENT:
6044 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6046 case SCTP_AUTHENTICATION_EVENT:
6047 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6049 case SCTP_STREAM_RESET_EVENT:
6050 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6052 case SCTP_SENDER_DRY_EVENT:
6053 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6055 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6057 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6060 case SCTP_ASSOC_RESET_EVENT:
6061 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6063 case SCTP_STREAM_CHANGE_EVENT:
6064 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6066 case SCTP_SEND_FAILED_EVENT:
6067 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6071 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6075 if (event_type > 0) {
6078 sctp_stcb_feature_on(inp, stcb, event_type);
6079 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6080 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6081 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6082 (stcb->asoc.stream_queue_cnt == 0)) {
6083 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6087 sctp_stcb_feature_off(inp, stcb, event_type);
6089 SCTP_TCB_UNLOCK(stcb);
6092 * We don't want to send up a storm
6093 * of events, so return an error for
6096 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6097 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6098 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6099 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6100 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6101 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6105 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6106 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6107 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6108 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6109 SCTP_INP_WLOCK(inp);
6111 sctp_feature_on(inp, event_type);
6113 sctp_feature_off(inp, event_type);
6115 SCTP_INP_WUNLOCK(inp);
6117 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6118 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6119 SCTP_INP_RLOCK(inp);
6120 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6121 SCTP_TCB_LOCK(stcb);
6123 sctp_stcb_feature_on(inp, stcb, event_type);
6125 sctp_stcb_feature_off(inp, stcb, event_type);
6127 SCTP_TCB_UNLOCK(stcb);
6129 SCTP_INP_RUNLOCK(inp);
6135 case SCTP_RECVRCVINFO:
6139 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6140 SCTP_INP_WLOCK(inp);
6142 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6144 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6146 SCTP_INP_WUNLOCK(inp);
6149 case SCTP_RECVNXTINFO:
6153 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6154 SCTP_INP_WLOCK(inp);
6156 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6158 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6160 SCTP_INP_WUNLOCK(inp);
6163 case SCTP_DEFAULT_SNDINFO:
6165 struct sctp_sndinfo *info;
6168 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6169 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6172 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6173 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6174 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6175 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6176 stcb->asoc.def_send.sinfo_flags |= policy;
6177 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6178 stcb->asoc.def_send.sinfo_context = info->snd_context;
6180 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6183 SCTP_TCB_UNLOCK(stcb);
6185 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6186 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6187 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6188 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6189 SCTP_INP_WLOCK(inp);
6190 inp->def_send.sinfo_stream = info->snd_sid;
6191 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6192 inp->def_send.sinfo_flags = info->snd_flags;
6193 inp->def_send.sinfo_flags |= policy;
6194 inp->def_send.sinfo_ppid = info->snd_ppid;
6195 inp->def_send.sinfo_context = info->snd_context;
6196 SCTP_INP_WUNLOCK(inp);
6198 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6199 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6200 SCTP_INP_RLOCK(inp);
6201 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6202 SCTP_TCB_LOCK(stcb);
6203 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6204 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6205 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6206 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6207 stcb->asoc.def_send.sinfo_flags |= policy;
6208 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6209 stcb->asoc.def_send.sinfo_context = info->snd_context;
6211 SCTP_TCB_UNLOCK(stcb);
6213 SCTP_INP_RUNLOCK(inp);
6218 case SCTP_DEFAULT_PRINFO:
6220 struct sctp_default_prinfo *info;
6222 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6223 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6225 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6226 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6231 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6232 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6233 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6234 SCTP_TCB_UNLOCK(stcb);
6236 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6237 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6238 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6239 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6240 SCTP_INP_WLOCK(inp);
6241 inp->def_send.sinfo_flags &= 0xfff0;
6242 inp->def_send.sinfo_flags |= info->pr_policy;
6243 inp->def_send.sinfo_timetolive = info->pr_value;
6244 SCTP_INP_WUNLOCK(inp);
6246 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6247 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6248 SCTP_INP_RLOCK(inp);
6249 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6250 SCTP_TCB_LOCK(stcb);
6251 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6252 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6253 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6254 SCTP_TCB_UNLOCK(stcb);
6256 SCTP_INP_RUNLOCK(inp);
6261 case SCTP_PEER_ADDR_THLDS:
6262 /* Applies to the specific association */
6264 struct sctp_paddrthlds *thlds;
6265 struct sctp_nets *net;
6266 struct sockaddr *addr;
6268 #if defined(INET) && defined(INET6)
6269 struct sockaddr_in sin_store;
6273 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6274 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6276 #if defined(INET) && defined(INET6)
6277 if (thlds->spt_address.ss_family == AF_INET6) {
6278 struct sockaddr_in6 *sin6;
6280 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6281 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6282 in6_sin6_2_sin(&sin_store, sin6);
6283 addr = (struct sockaddr *)&sin_store;
6285 addr = (struct sockaddr *)&thlds->spt_address;
6288 addr = (struct sockaddr *)&thlds->spt_address;
6291 addr = (struct sockaddr *)&thlds->spt_address;
6294 net = sctp_findnet(stcb, addr);
6297 * We increment here since
6298 * sctp_findassociation_ep_addr() wil do a
6299 * decrement if it finds the stcb as long as
6300 * the locked tcb (last argument) is NOT a
6304 SCTP_INP_INCR_REF(inp);
6305 stcb = sctp_findassociation_ep_addr(&inp, addr,
6308 SCTP_INP_DECR_REF(inp);
6311 if ((stcb != NULL) && (net == NULL)) {
6313 if (addr->sa_family == AF_INET) {
6315 struct sockaddr_in *sin;
6317 sin = (struct sockaddr_in *)addr;
6318 if (sin->sin_addr.s_addr != INADDR_ANY) {
6319 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6320 SCTP_TCB_UNLOCK(stcb);
6327 if (addr->sa_family == AF_INET6) {
6328 struct sockaddr_in6 *sin6;
6330 sin6 = (struct sockaddr_in6 *)addr;
6331 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6332 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6333 SCTP_TCB_UNLOCK(stcb);
6340 error = EAFNOSUPPORT;
6341 SCTP_TCB_UNLOCK(stcb);
6342 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6348 net->failure_threshold = thlds->spt_pathmaxrxt;
6349 net->pf_threshold = thlds->spt_pathpfthld;
6350 if (net->dest_state & SCTP_ADDR_PF) {
6351 if ((net->error_count > net->failure_threshold) ||
6352 (net->error_count <= net->pf_threshold)) {
6353 net->dest_state &= ~SCTP_ADDR_PF;
6356 if ((net->error_count > net->pf_threshold) &&
6357 (net->error_count <= net->failure_threshold)) {
6358 net->dest_state |= SCTP_ADDR_PF;
6359 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6360 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6361 stcb->sctp_ep, stcb, net,
6362 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6363 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6366 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6367 if (net->error_count > net->failure_threshold) {
6368 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6369 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6372 if (net->error_count <= net->failure_threshold) {
6373 net->dest_state |= SCTP_ADDR_REACHABLE;
6374 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6378 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6379 net->failure_threshold = thlds->spt_pathmaxrxt;
6380 net->pf_threshold = thlds->spt_pathpfthld;
6381 if (net->dest_state & SCTP_ADDR_PF) {
6382 if ((net->error_count > net->failure_threshold) ||
6383 (net->error_count <= net->pf_threshold)) {
6384 net->dest_state &= ~SCTP_ADDR_PF;
6387 if ((net->error_count > net->pf_threshold) &&
6388 (net->error_count <= net->failure_threshold)) {
6389 net->dest_state |= SCTP_ADDR_PF;
6390 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6391 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6392 stcb->sctp_ep, stcb, net,
6393 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6394 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6397 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6398 if (net->error_count > net->failure_threshold) {
6399 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6400 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6403 if (net->error_count <= net->failure_threshold) {
6404 net->dest_state |= SCTP_ADDR_REACHABLE;
6405 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6409 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6410 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6412 SCTP_TCB_UNLOCK(stcb);
6414 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6415 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6416 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6417 SCTP_INP_WLOCK(inp);
6418 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6419 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6420 SCTP_INP_WUNLOCK(inp);
6422 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6428 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6430 struct sctp_udpencaps *encaps;
6431 struct sctp_nets *net;
6432 struct sockaddr *addr;
6434 #if defined(INET) && defined(INET6)
6435 struct sockaddr_in sin_store;
6439 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6440 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6442 #if defined(INET) && defined(INET6)
6443 if (encaps->sue_address.ss_family == AF_INET6) {
6444 struct sockaddr_in6 *sin6;
6446 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6447 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6448 in6_sin6_2_sin(&sin_store, sin6);
6449 addr = (struct sockaddr *)&sin_store;
6451 addr = (struct sockaddr *)&encaps->sue_address;
6454 addr = (struct sockaddr *)&encaps->sue_address;
6457 addr = (struct sockaddr *)&encaps->sue_address;
6460 net = sctp_findnet(stcb, addr);
6463 * We increment here since
6464 * sctp_findassociation_ep_addr() wil do a
6465 * decrement if it finds the stcb as long as
6466 * the locked tcb (last argument) is NOT a
6470 SCTP_INP_INCR_REF(inp);
6471 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6473 SCTP_INP_DECR_REF(inp);
6476 if ((stcb != NULL) && (net == NULL)) {
6478 if (addr->sa_family == AF_INET) {
6480 struct sockaddr_in *sin;
6482 sin = (struct sockaddr_in *)addr;
6483 if (sin->sin_addr.s_addr != INADDR_ANY) {
6484 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6485 SCTP_TCB_UNLOCK(stcb);
6492 if (addr->sa_family == AF_INET6) {
6493 struct sockaddr_in6 *sin6;
6495 sin6 = (struct sockaddr_in6 *)addr;
6496 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6497 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6498 SCTP_TCB_UNLOCK(stcb);
6505 error = EAFNOSUPPORT;
6506 SCTP_TCB_UNLOCK(stcb);
6507 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6513 net->port = encaps->sue_port;
6515 stcb->asoc.port = encaps->sue_port;
6517 SCTP_TCB_UNLOCK(stcb);
6519 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6520 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6521 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6522 SCTP_INP_WLOCK(inp);
6523 inp->sctp_ep.port = encaps->sue_port;
6524 SCTP_INP_WUNLOCK(inp);
6526 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6532 case SCTP_ECN_SUPPORTED:
6534 struct sctp_assoc_value *av;
6536 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6537 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6540 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6542 SCTP_TCB_UNLOCK(stcb);
6544 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6545 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6546 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6547 SCTP_INP_WLOCK(inp);
6548 if (av->assoc_value == 0) {
6549 inp->ecn_supported = 0;
6551 inp->ecn_supported = 1;
6553 SCTP_INP_WUNLOCK(inp);
6555 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6561 case SCTP_PR_SUPPORTED:
6563 struct sctp_assoc_value *av;
6565 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6566 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6569 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6571 SCTP_TCB_UNLOCK(stcb);
6573 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6574 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6575 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6576 SCTP_INP_WLOCK(inp);
6577 if (av->assoc_value == 0) {
6578 inp->prsctp_supported = 0;
6580 inp->prsctp_supported = 1;
6582 SCTP_INP_WUNLOCK(inp);
6584 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6590 case SCTP_AUTH_SUPPORTED:
6592 struct sctp_assoc_value *av;
6594 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6595 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6598 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6600 SCTP_TCB_UNLOCK(stcb);
6602 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6603 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6604 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6605 if ((av->assoc_value == 0) &&
6606 (inp->asconf_supported == 1)) {
6608 * AUTH is required for
6611 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6614 SCTP_INP_WLOCK(inp);
6615 if (av->assoc_value == 0) {
6616 inp->auth_supported = 0;
6618 inp->auth_supported = 1;
6620 SCTP_INP_WUNLOCK(inp);
6623 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6629 case SCTP_ASCONF_SUPPORTED:
6631 struct sctp_assoc_value *av;
6633 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6634 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6637 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6639 SCTP_TCB_UNLOCK(stcb);
6641 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6642 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6643 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6644 if ((av->assoc_value != 0) &&
6645 (inp->auth_supported == 0)) {
6647 * AUTH is required for
6650 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6653 SCTP_INP_WLOCK(inp);
6654 if (av->assoc_value == 0) {
6655 inp->asconf_supported = 0;
6656 sctp_auth_delete_chunk(SCTP_ASCONF,
6657 inp->sctp_ep.local_auth_chunks);
6658 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6659 inp->sctp_ep.local_auth_chunks);
6661 inp->asconf_supported = 1;
6662 sctp_auth_add_chunk(SCTP_ASCONF,
6663 inp->sctp_ep.local_auth_chunks);
6664 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6665 inp->sctp_ep.local_auth_chunks);
6667 SCTP_INP_WUNLOCK(inp);
6670 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6676 case SCTP_RECONFIG_SUPPORTED:
6678 struct sctp_assoc_value *av;
6680 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6681 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6684 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6686 SCTP_TCB_UNLOCK(stcb);
6688 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6689 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6690 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6691 SCTP_INP_WLOCK(inp);
6692 if (av->assoc_value == 0) {
6693 inp->reconfig_supported = 0;
6695 inp->reconfig_supported = 1;
6697 SCTP_INP_WUNLOCK(inp);
6699 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6705 case SCTP_NRSACK_SUPPORTED:
6707 struct sctp_assoc_value *av;
6709 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6710 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6713 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6715 SCTP_TCB_UNLOCK(stcb);
6717 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6718 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6719 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6720 SCTP_INP_WLOCK(inp);
6721 if (av->assoc_value == 0) {
6722 inp->nrsack_supported = 0;
6724 inp->nrsack_supported = 1;
6726 SCTP_INP_WUNLOCK(inp);
6728 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6734 case SCTP_PKTDROP_SUPPORTED:
6736 struct sctp_assoc_value *av;
6738 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6739 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6744 SCTP_TCB_UNLOCK(stcb);
6746 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6747 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6748 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6749 SCTP_INP_WLOCK(inp);
6750 if (av->assoc_value == 0) {
6751 inp->pktdrop_supported = 0;
6753 inp->pktdrop_supported = 1;
6755 SCTP_INP_WUNLOCK(inp);
6757 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6765 struct sctp_assoc_value *av;
6766 struct sctp_nets *net;
6768 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6769 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6772 stcb->asoc.max_cwnd = av->assoc_value;
6773 if (stcb->asoc.max_cwnd > 0) {
6774 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6775 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6776 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6777 net->cwnd = stcb->asoc.max_cwnd;
6778 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6779 net->cwnd = net->mtu - sizeof(struct sctphdr);
6784 SCTP_TCB_UNLOCK(stcb);
6786 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6787 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6788 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6789 SCTP_INP_WLOCK(inp);
6790 inp->max_cwnd = av->assoc_value;
6791 SCTP_INP_WUNLOCK(inp);
6793 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6801 error = ENOPROTOOPT;
6803 } /* end switch (opt) */
6808 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6810 void *optval = NULL;
6814 struct sctp_inpcb *inp;
6816 if ((sopt->sopt_level == SOL_SOCKET) &&
6817 (sopt->sopt_name == SO_SETFIB)) {
6818 inp = (struct sctp_inpcb *)so->so_pcb;
6820 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6823 SCTP_INP_WLOCK(inp);
6824 inp->fibnum = so->so_fibnum;
6825 SCTP_INP_WUNLOCK(inp);
6828 if (sopt->sopt_level != IPPROTO_SCTP) {
6829 /* wrong proto level... send back up to IP */
6831 if (INP_CHECK_SOCKAF(so, AF_INET6))
6832 error = ip6_ctloutput(so, sopt);
6834 #if defined(INET) && defined(INET6)
6838 error = ip_ctloutput(so, sopt);
6842 optsize = sopt->sopt_valsize;
6844 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6845 if (optval == NULL) {
6846 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6849 error = sooptcopyin(sopt, optval, optsize, optsize);
6851 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6855 p = (void *)sopt->sopt_td;
6856 if (sopt->sopt_dir == SOPT_SET) {
6857 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6858 } else if (sopt->sopt_dir == SOPT_GET) {
6859 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6861 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6864 if ((error == 0) && (optval != NULL)) {
6865 error = sooptcopyout(sopt, optval, optsize);
6866 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6867 } else if (optval != NULL) {
6868 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6876 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6879 int create_lock_on = 0;
6881 struct sctp_inpcb *inp;
6882 struct sctp_tcb *stcb = NULL;
6884 inp = (struct sctp_inpcb *)so->so_pcb;
6886 /* I made the same as TCP since we are not setup? */
6887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6888 return (ECONNRESET);
6891 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6894 switch (addr->sa_family) {
6898 struct sockaddr_in6 *sin6p;
6900 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6901 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6904 sin6p = (struct sockaddr_in6 *)addr;
6905 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6906 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6915 struct sockaddr_in *sinp;
6917 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6918 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6921 sinp = (struct sockaddr_in *)addr;
6922 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6923 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6930 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6931 return (EAFNOSUPPORT);
6933 SCTP_INP_INCR_REF(inp);
6934 SCTP_ASOC_CREATE_LOCK(inp);
6938 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6939 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6940 /* Should I really unlock ? */
6941 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6946 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6947 (addr->sa_family == AF_INET6)) {
6948 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6953 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6954 SCTP_PCB_FLAGS_UNBOUND) {
6955 /* Bind a ephemeral port */
6956 error = sctp_inpcb_bind(so, NULL, NULL, p);
6961 /* Now do we connect? */
6962 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6963 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6964 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6968 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6969 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6970 /* We are already connected AND the TCP model */
6971 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6975 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6976 SCTP_INP_RLOCK(inp);
6977 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6978 SCTP_INP_RUNLOCK(inp);
6981 * We increment here since sctp_findassociation_ep_addr()
6982 * will do a decrement if it finds the stcb as long as the
6983 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6985 SCTP_INP_INCR_REF(inp);
6986 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6988 SCTP_INP_DECR_REF(inp);
6990 SCTP_TCB_UNLOCK(stcb);
6994 /* Already have or am bring up an association */
6995 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
6999 vrf_id = inp->def_vrf_id;
7000 /* We are GOOD to go */
7001 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, inp->sctp_ep.pre_open_stream_count, p);
7003 /* Gak! no memory */
7006 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
7007 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
7008 /* Set the connected flag so we can queue data */
7011 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
7012 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7014 /* initialize authentication parameters for the assoc */
7015 sctp_initialize_auth_params(inp, stcb);
7017 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7018 SCTP_TCB_UNLOCK(stcb);
7020 if (create_lock_on) {
7021 SCTP_ASOC_CREATE_UNLOCK(inp);
7023 SCTP_INP_DECR_REF(inp);
7030 sctp_listen(struct socket *so, int backlog, struct thread *p)
7033 * Note this module depends on the protocol processing being called
7034 * AFTER any socket level flags and backlog are applied to the
7035 * socket. The traditional way that the socket flags are applied is
7036 * AFTER protocol processing. We have made a change to the
7037 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7038 * place if the socket API for SCTP is to work properly.
7042 struct sctp_inpcb *inp;
7044 inp = (struct sctp_inpcb *)so->so_pcb;
7046 /* I made the same as TCP since we are not setup? */
7047 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7048 return (ECONNRESET);
7050 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7051 /* See if we have a listener */
7052 struct sctp_inpcb *tinp;
7053 union sctp_sockstore store;
7055 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7057 struct sctp_laddr *laddr;
7059 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7060 memcpy(&store, &laddr->ifa->address, sizeof(store));
7061 switch (store.sa.sa_family) {
7064 store.sin.sin_port = inp->sctp_lport;
7069 store.sin6.sin6_port = inp->sctp_lport;
7075 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7076 if (tinp && (tinp != inp) &&
7077 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7078 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7079 (tinp->sctp_socket->so_qlimit)) {
7081 * we have a listener already and
7084 SCTP_INP_DECR_REF(tinp);
7085 return (EADDRINUSE);
7087 SCTP_INP_DECR_REF(tinp);
7091 /* Setup a local addr bound all */
7092 memset(&store, 0, sizeof(store));
7094 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7095 store.sa.sa_family = AF_INET6;
7096 store.sa.sa_len = sizeof(struct sockaddr_in6);
7100 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7101 store.sa.sa_family = AF_INET;
7102 store.sa.sa_len = sizeof(struct sockaddr_in);
7105 switch (store.sa.sa_family) {
7108 store.sin.sin_port = inp->sctp_lport;
7113 store.sin6.sin6_port = inp->sctp_lport;
7119 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7120 if (tinp && (tinp != inp) &&
7121 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7122 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7123 (tinp->sctp_socket->so_qlimit)) {
7125 * we have a listener already and its not
7128 SCTP_INP_DECR_REF(tinp);
7129 return (EADDRINUSE);
7131 SCTP_INP_DECR_REF(tinp);
7135 SCTP_INP_RLOCK(inp);
7136 #ifdef SCTP_LOCK_LOGGING
7137 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7138 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7142 error = solisten_proto_check(so);
7145 SCTP_INP_RUNLOCK(inp);
7148 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7149 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7151 * The unlucky case - We are in the tcp pool with this guy.
7152 * - Someone else is in the main inp slot. - We must move
7153 * this guy (the listener) to the main slot - We must then
7154 * move the guy that was listener to the TCP Pool.
7156 if (sctp_swap_inpcb_for_listen(inp)) {
7157 SCTP_INP_RUNLOCK(inp);
7158 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7159 return (EADDRINUSE);
7162 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7163 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7164 /* We are already connected AND the TCP model */
7165 SCTP_INP_RUNLOCK(inp);
7166 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7167 return (EADDRINUSE);
7169 SCTP_INP_RUNLOCK(inp);
7170 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7171 /* We must do a bind. */
7172 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7173 /* bind error, probably perm */
7178 /* It appears for 7.0 and on, we must always call this. */
7179 solisten_proto(so, backlog);
7180 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7181 /* remove the ACCEPTCONN flag for one-to-many sockets */
7182 so->so_options &= ~SO_ACCEPTCONN;
7185 /* turning off listen */
7186 so->so_options &= ~SO_ACCEPTCONN;
7192 static int sctp_defered_wakeup_cnt = 0;
7195 sctp_accept(struct socket *so, struct sockaddr **addr)
7197 struct sctp_tcb *stcb;
7198 struct sctp_inpcb *inp;
7199 union sctp_sockstore store;
7205 inp = (struct sctp_inpcb *)so->so_pcb;
7208 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7209 return (ECONNRESET);
7211 SCTP_INP_RLOCK(inp);
7212 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7213 SCTP_INP_RUNLOCK(inp);
7214 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7215 return (EOPNOTSUPP);
7217 if (so->so_state & SS_ISDISCONNECTED) {
7218 SCTP_INP_RUNLOCK(inp);
7219 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7220 return (ECONNABORTED);
7222 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7224 SCTP_INP_RUNLOCK(inp);
7225 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7226 return (ECONNRESET);
7228 SCTP_TCB_LOCK(stcb);
7229 SCTP_INP_RUNLOCK(inp);
7230 store = stcb->asoc.primary_destination->ro._l_addr;
7231 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
7232 SCTP_TCB_UNLOCK(stcb);
7233 switch (store.sa.sa_family) {
7237 struct sockaddr_in *sin;
7239 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7242 sin->sin_family = AF_INET;
7243 sin->sin_len = sizeof(*sin);
7244 sin->sin_port = store.sin.sin_port;
7245 sin->sin_addr = store.sin.sin_addr;
7246 *addr = (struct sockaddr *)sin;
7253 struct sockaddr_in6 *sin6;
7255 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7258 sin6->sin6_family = AF_INET6;
7259 sin6->sin6_len = sizeof(*sin6);
7260 sin6->sin6_port = store.sin6.sin6_port;
7261 sin6->sin6_addr = store.sin6.sin6_addr;
7262 if ((error = sa6_recoverscope(sin6)) != 0) {
7263 SCTP_FREE_SONAME(sin6);
7266 *addr = (struct sockaddr *)sin6;
7274 /* Wake any delayed sleep action */
7275 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7276 SCTP_INP_WLOCK(inp);
7277 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7278 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7279 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7280 SCTP_INP_WUNLOCK(inp);
7281 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7282 if (sowriteable(inp->sctp_socket)) {
7283 sowwakeup_locked(inp->sctp_socket);
7285 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7287 SCTP_INP_WLOCK(inp);
7289 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7290 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7291 SCTP_INP_WUNLOCK(inp);
7292 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7293 if (soreadable(inp->sctp_socket)) {
7294 sctp_defered_wakeup_cnt++;
7295 sorwakeup_locked(inp->sctp_socket);
7297 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7299 SCTP_INP_WLOCK(inp);
7301 SCTP_INP_WUNLOCK(inp);
7303 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7304 SCTP_TCB_LOCK(stcb);
7305 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7306 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7313 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7315 struct sockaddr_in *sin;
7317 struct sctp_inpcb *inp;
7318 struct sctp_ifa *sctp_ifa;
7321 * Do the malloc first in case it blocks.
7323 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7326 sin->sin_family = AF_INET;
7327 sin->sin_len = sizeof(*sin);
7328 inp = (struct sctp_inpcb *)so->so_pcb;
7330 SCTP_FREE_SONAME(sin);
7331 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7332 return (ECONNRESET);
7334 SCTP_INP_RLOCK(inp);
7335 sin->sin_port = inp->sctp_lport;
7336 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7337 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7338 struct sctp_tcb *stcb;
7339 struct sockaddr_in *sin_a;
7340 struct sctp_nets *net;
7343 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7349 SCTP_TCB_LOCK(stcb);
7350 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7351 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7353 /* this will make coverity happy */
7356 if (sin_a->sin_family == AF_INET) {
7361 if ((!fnd) || (sin_a == NULL)) {
7363 SCTP_TCB_UNLOCK(stcb);
7366 vrf_id = inp->def_vrf_id;
7367 sctp_ifa = sctp_source_address_selection(inp,
7369 (sctp_route_t *) & net->ro,
7372 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7373 sctp_free_ifa(sctp_ifa);
7375 SCTP_TCB_UNLOCK(stcb);
7377 /* For the bound all case you get back 0 */
7379 sin->sin_addr.s_addr = 0;
7383 /* Take the first IPv4 address in the list */
7384 struct sctp_laddr *laddr;
7387 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7388 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7389 struct sockaddr_in *sin_a;
7391 sin_a = &laddr->ifa->address.sin;
7392 sin->sin_addr = sin_a->sin_addr;
7398 SCTP_FREE_SONAME(sin);
7399 SCTP_INP_RUNLOCK(inp);
7400 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7404 SCTP_INP_RUNLOCK(inp);
7405 (*addr) = (struct sockaddr *)sin;
7410 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7412 struct sockaddr_in *sin;
7414 struct sockaddr_in *sin_a;
7415 struct sctp_inpcb *inp;
7416 struct sctp_tcb *stcb;
7417 struct sctp_nets *net;
7419 /* Do the malloc first in case it blocks. */
7420 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7423 sin->sin_family = AF_INET;
7424 sin->sin_len = sizeof(*sin);
7426 inp = (struct sctp_inpcb *)so->so_pcb;
7427 if ((inp == NULL) ||
7428 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7429 /* UDP type and listeners will drop out here */
7430 SCTP_FREE_SONAME(sin);
7431 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7434 SCTP_INP_RLOCK(inp);
7435 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7437 SCTP_TCB_LOCK(stcb);
7439 SCTP_INP_RUNLOCK(inp);
7441 SCTP_FREE_SONAME(sin);
7442 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7443 return (ECONNRESET);
7446 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7447 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7448 if (sin_a->sin_family == AF_INET) {
7450 sin->sin_port = stcb->rport;
7451 sin->sin_addr = sin_a->sin_addr;
7455 SCTP_TCB_UNLOCK(stcb);
7457 /* No IPv4 address */
7458 SCTP_FREE_SONAME(sin);
7459 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7462 (*addr) = (struct sockaddr *)sin;
7466 struct pr_usrreqs sctp_usrreqs = {
7467 .pru_abort = sctp_abort,
7468 .pru_accept = sctp_accept,
7469 .pru_attach = sctp_attach,
7470 .pru_bind = sctp_bind,
7471 .pru_connect = sctp_connect,
7472 .pru_control = in_control,
7473 .pru_close = sctp_close,
7474 .pru_detach = sctp_close,
7475 .pru_sopoll = sopoll_generic,
7476 .pru_flush = sctp_flush,
7477 .pru_disconnect = sctp_disconnect,
7478 .pru_listen = sctp_listen,
7479 .pru_peeraddr = sctp_peeraddr,
7480 .pru_send = sctp_sendm,
7481 .pru_shutdown = sctp_shutdown,
7482 .pru_sockaddr = sctp_ingetaddr,
7483 .pru_sosend = sctp_sosend,
7484 .pru_soreceive = sctp_soreceive