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);
94 sctp_finish(void *unused __unused)
98 VNET_SYSUNINIT(sctp, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, sctp_finish, NULL);
102 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
104 struct sctp_tmit_chunk *chk;
107 /* Adjust that too */
108 stcb->asoc.smallest_mtu = nxtsz;
109 /* now off to subtract IP_DF flag if needed */
110 overhead = IP_HDR_SIZE;
111 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
112 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
114 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
115 if ((chk->send_size + overhead) > nxtsz) {
116 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
119 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
120 if ((chk->send_size + overhead) > nxtsz) {
122 * For this guy we also mark for immediate resend
123 * since we sent to big of chunk
125 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
126 if (chk->sent < SCTP_DATAGRAM_RESEND) {
127 sctp_flight_size_decrease(chk);
128 sctp_total_flight_decrease(stcb, chk);
129 chk->sent = SCTP_DATAGRAM_RESEND;
130 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
131 chk->rec.data.doing_fast_retransmit = 0;
132 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
133 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
134 chk->whoTo->flight_size,
136 (uint32_t) (uintptr_t) chk->whoTo,
137 chk->rec.data.TSN_seq);
139 /* Clear any time so NO RTT is being done */
148 sctp_notify(struct sctp_inpcb *inp,
149 struct sctp_tcb *stcb,
150 struct sctp_nets *net,
156 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
162 if (icmp_type != ICMP_UNREACH) {
163 /* We only care about unreachable */
164 SCTP_TCB_UNLOCK(stcb);
167 if ((icmp_code == ICMP_UNREACH_NET) ||
168 (icmp_code == ICMP_UNREACH_HOST) ||
169 (icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
170 (icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
171 (icmp_code == ICMP_UNREACH_ISOLATED) ||
172 (icmp_code == ICMP_UNREACH_NET_PROHIB) ||
173 (icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
174 (icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
175 /* Mark the net unreachable. */
176 if (net->dest_state & SCTP_ADDR_REACHABLE) {
177 /* OK, that destination is NOT reachable. */
178 net->dest_state &= ~SCTP_ADDR_REACHABLE;
179 net->dest_state &= ~SCTP_ADDR_PF;
180 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
182 (void *)net, SCTP_SO_NOT_LOCKED);
184 SCTP_TCB_UNLOCK(stcb);
185 } else if ((icmp_code == ICMP_UNREACH_PROTOCOL) ||
186 (icmp_code == ICMP_UNREACH_PORT)) {
187 /* Treat it like an ABORT. */
188 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
189 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
190 so = SCTP_INP_SO(inp);
191 atomic_add_int(&stcb->asoc.refcnt, 1);
192 SCTP_TCB_UNLOCK(stcb);
193 SCTP_SOCKET_LOCK(so, 1);
195 atomic_subtract_int(&stcb->asoc.refcnt, 1);
197 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
198 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
199 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
200 SCTP_SOCKET_UNLOCK(so, 1);
201 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
203 /* no need to unlock here, since the TCB is gone */
204 } else if (icmp_code == ICMP_UNREACH_NEEDFRAG) {
205 /* Find the next (smaller) MTU */
208 * Old type router that does not tell us what the
209 * next MTU is. Rats we will have to guess (in a
210 * educated fashion of course).
212 next_mtu = sctp_get_prev_mtu(ip_len);
214 /* Stop the PMTU timer. */
215 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
217 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
218 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
222 /* Update the path MTU. */
223 if (net->mtu > next_mtu) {
226 net->mtu -= sizeof(struct udphdr);
229 /* Update the association MTU */
230 if (stcb->asoc.smallest_mtu > next_mtu) {
231 sctp_pathmtu_adjustment(stcb, next_mtu);
233 /* Finally, start the PMTU timer if it was running before. */
235 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
237 SCTP_TCB_UNLOCK(stcb);
239 SCTP_TCB_UNLOCK(stcb);
244 sctp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
250 struct sctp_inpcb *inp;
251 struct sctp_tcb *stcb;
252 struct sctp_nets *net;
253 struct sctp_init_chunk *ch;
254 struct sockaddr_in src, dst;
256 if (sa->sa_family != AF_INET ||
257 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
260 if (PRC_IS_REDIRECT(cmd)) {
262 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
266 inner_ip = (struct ip *)vip;
267 icmp = (struct icmp *)((caddr_t)inner_ip -
268 (sizeof(struct icmp) - sizeof(struct ip)));
269 outer_ip = (struct ip *)((caddr_t)icmp - sizeof(struct ip));
270 sh = (struct sctphdr *)((caddr_t)inner_ip + (inner_ip->ip_hl << 2));
271 memset(&src, 0, sizeof(struct sockaddr_in));
272 src.sin_family = AF_INET;
273 src.sin_len = sizeof(struct sockaddr_in);
274 src.sin_port = sh->src_port;
275 src.sin_addr = inner_ip->ip_src;
276 memset(&dst, 0, sizeof(struct sockaddr_in));
277 dst.sin_family = AF_INET;
278 dst.sin_len = sizeof(struct sockaddr_in);
279 dst.sin_port = sh->dest_port;
280 dst.sin_addr = inner_ip->ip_dst;
282 * 'dst' holds the dest of the packet that failed to be
283 * sent. 'src' holds our local endpoint address. Thus we
284 * reverse the dst and the src in the lookup.
288 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst,
289 (struct sockaddr *)&src,
292 if ((stcb != NULL) &&
295 /* Check the verification tag */
296 if (ntohl(sh->v_tag) != 0) {
298 * This must be the verification tag used
299 * for sending out packets. We don't
300 * consider packets reflecting the
303 if (ntohl(sh->v_tag) != stcb->asoc.peer_vtag) {
304 SCTP_TCB_UNLOCK(stcb);
308 if (ntohs(outer_ip->ip_len) >=
310 8 + (inner_ip->ip_hl << 2) + 20) {
312 * In this case we can check if we
313 * got an INIT chunk and if the
314 * initiate tag matches.
316 ch = (struct sctp_init_chunk *)(sh + 1);
317 if ((ch->ch.chunk_type != SCTP_INITIATION) ||
318 (ntohl(ch->init.initiate_tag) != stcb->asoc.my_vtag)) {
319 SCTP_TCB_UNLOCK(stcb);
323 SCTP_TCB_UNLOCK(stcb);
327 sctp_notify(inp, stcb, net,
330 ntohs(inner_ip->ip_len),
331 ntohs(icmp->icmp_nextmtu));
333 if ((stcb == NULL) && (inp != NULL)) {
334 /* reduce ref-count */
336 SCTP_INP_DECR_REF(inp);
337 SCTP_INP_WUNLOCK(inp);
340 SCTP_TCB_UNLOCK(stcb);
350 sctp_getcred(SYSCTL_HANDLER_ARGS)
353 struct sockaddr_in addrs[2];
354 struct sctp_inpcb *inp;
355 struct sctp_nets *net;
356 struct sctp_tcb *stcb;
360 /* FIX, for non-bsd is this right? */
361 vrf_id = SCTP_DEFAULT_VRFID;
363 error = priv_check(req->td, PRIV_NETINET_GETCRED);
368 error = SYSCTL_IN(req, addrs, sizeof(addrs));
372 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
374 &inp, &net, 1, vrf_id);
375 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
376 if ((inp != NULL) && (stcb == NULL)) {
377 /* reduce ref-count */
379 SCTP_INP_DECR_REF(inp);
382 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
386 SCTP_TCB_UNLOCK(stcb);
388 * We use the write lock here, only since in the error leg we need
389 * it. If we used RLOCK, then we would have to
390 * wlock/decr/unlock/rlock. Which in theory could create a hole.
391 * Better to use higher wlock.
395 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
397 SCTP_INP_WUNLOCK(inp);
400 cru2x(inp->sctp_socket->so_cred, &xuc);
401 SCTP_INP_WUNLOCK(inp);
402 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
407 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
408 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
413 sctp_abort(struct socket *so)
415 struct sctp_inpcb *inp;
418 inp = (struct sctp_inpcb *)so->so_pcb;
423 flags = inp->sctp_flags;
424 #ifdef SCTP_LOG_CLOSING
425 sctp_log_closing(inp, NULL, 17);
427 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
428 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
429 #ifdef SCTP_LOG_CLOSING
430 sctp_log_closing(inp, NULL, 16);
432 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
433 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
435 SCTP_SB_CLEAR(so->so_snd);
437 * same for the rcv ones, they are only here for the
440 SCTP_SB_CLEAR(so->so_rcv);
442 /* Now null out the reference, we are completely detached. */
446 flags = inp->sctp_flags;
447 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
448 goto sctp_must_try_again;
455 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
457 struct sctp_inpcb *inp;
458 struct inpcb *ip_inp;
460 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
462 inp = (struct sctp_inpcb *)so->so_pcb;
464 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
467 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
468 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
473 error = sctp_inpcb_alloc(so, vrf_id);
477 inp = (struct sctp_inpcb *)so->so_pcb;
479 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
480 ip_inp = &inp->ip_inp.inp;
481 ip_inp->inp_vflag |= INP_IPV4;
482 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
483 SCTP_INP_WUNLOCK(inp);
488 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
490 struct sctp_inpcb *inp;
492 inp = (struct sctp_inpcb *)so->so_pcb;
494 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
498 if ((addr->sa_family != AF_INET) ||
499 (addr->sa_len != sizeof(struct sockaddr_in))) {
500 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
504 return (sctp_inpcb_bind(so, addr, NULL, p));
509 sctp_close(struct socket *so)
511 struct sctp_inpcb *inp;
514 inp = (struct sctp_inpcb *)so->so_pcb;
519 * Inform all the lower layer assoc that we are done.
522 flags = inp->sctp_flags;
523 #ifdef SCTP_LOG_CLOSING
524 sctp_log_closing(inp, NULL, 17);
526 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
527 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
528 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
529 (so->so_rcv.sb_cc > 0)) {
530 #ifdef SCTP_LOG_CLOSING
531 sctp_log_closing(inp, NULL, 13);
533 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
534 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
536 #ifdef SCTP_LOG_CLOSING
537 sctp_log_closing(inp, NULL, 14);
539 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
540 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
543 * The socket is now detached, no matter what the state of
544 * the SCTP association.
547 SCTP_SB_CLEAR(so->so_snd);
549 * same for the rcv ones, they are only here for the
552 SCTP_SB_CLEAR(so->so_rcv);
554 /* Now null out the reference, we are completely detached. */
558 flags = inp->sctp_flags;
559 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
560 goto sctp_must_try_again;
568 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
569 struct mbuf *control, struct thread *p);
573 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
574 struct mbuf *control, struct thread *p)
576 struct sctp_inpcb *inp;
579 inp = (struct sctp_inpcb *)so->so_pcb;
582 sctp_m_freem(control);
585 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
589 /* Got to have an to address if we are NOT a connected socket */
590 if ((addr == NULL) &&
591 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
592 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
594 } else if (addr == NULL) {
595 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
596 error = EDESTADDRREQ;
599 sctp_m_freem(control);
605 if (addr->sa_family != AF_INET) {
606 /* must be a v4 address! */
607 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
610 sctp_m_freem(control);
613 error = EDESTADDRREQ;
618 /* now what about control */
621 SCTP_PRINTF("huh? control set?\n");
622 sctp_m_freem(inp->control);
625 inp->control = control;
629 SCTP_BUF_NEXT(inp->pkt_last) = m;
632 inp->pkt_last = inp->pkt = m;
635 /* FreeBSD uses a flag passed */
636 ((flags & PRUS_MORETOCOME) == 0)
639 * note with the current version this code will only be used
640 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
641 * re-defining sosend to use the sctp_sosend. One can
642 * optionally switch back to this code (by changing back the
643 * definitions) but this is not advisable. This code is used
644 * by FreeBSD when sending a file with sendfile() though.
648 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
658 sctp_disconnect(struct socket *so)
660 struct sctp_inpcb *inp;
662 inp = (struct sctp_inpcb *)so->so_pcb;
664 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
668 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
669 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
670 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
672 SCTP_INP_RUNLOCK(inp);
675 struct sctp_association *asoc;
676 struct sctp_tcb *stcb;
678 stcb = LIST_FIRST(&inp->sctp_asoc_list);
680 SCTP_INP_RUNLOCK(inp);
681 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
686 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
687 /* We are about to be freed, out of here */
688 SCTP_TCB_UNLOCK(stcb);
689 SCTP_INP_RUNLOCK(inp);
692 if (((so->so_options & SO_LINGER) &&
693 (so->so_linger == 0)) ||
694 (so->so_rcv.sb_cc > 0)) {
695 if (SCTP_GET_STATE(asoc) !=
696 SCTP_STATE_COOKIE_WAIT) {
697 /* Left with Data unread */
700 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_NOWAIT, 1, MT_DATA);
706 struct sctp_paramhdr *ph;
708 ph = mtod(err, struct sctp_paramhdr *);
709 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
710 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
711 ph->param_length = htons(SCTP_BUF_LEN(err));
713 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
714 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
716 SCTP_INP_RUNLOCK(inp);
717 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
718 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
719 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
721 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
722 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
723 /* No unlock tcb assoc is gone */
726 if (TAILQ_EMPTY(&asoc->send_queue) &&
727 TAILQ_EMPTY(&asoc->sent_queue) &&
728 (asoc->stream_queue_cnt == 0)) {
729 /* there is nothing queued to send, so done */
730 if (asoc->locked_on_sending) {
733 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
734 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
735 /* only send SHUTDOWN 1st time thru */
736 struct sctp_nets *netp;
738 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
739 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
740 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
742 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
743 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
744 sctp_stop_timers_for_shutdown(stcb);
745 if (stcb->asoc.alternate) {
746 netp = stcb->asoc.alternate;
748 netp = stcb->asoc.primary_destination;
750 sctp_send_shutdown(stcb, netp);
751 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
752 stcb->sctp_ep, stcb, netp);
753 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
754 stcb->sctp_ep, stcb, netp);
755 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
759 * we still got (or just got) data to send,
760 * so set SHUTDOWN_PENDING
763 * XXX sockets draft says that SCTP_EOF
764 * should be sent with no data. currently,
765 * we will allow user data to be sent first
766 * and move to SHUTDOWN-PENDING
768 struct sctp_nets *netp;
770 if (stcb->asoc.alternate) {
771 netp = stcb->asoc.alternate;
773 netp = stcb->asoc.primary_destination;
776 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
777 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
779 if (asoc->locked_on_sending) {
780 /* Locked to send out the data */
781 struct sctp_stream_queue_pending *sp;
783 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
785 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
786 asoc->locked_on_sending->stream_no);
788 if ((sp->length == 0) && (sp->msg_is_complete == 0))
789 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
792 if (TAILQ_EMPTY(&asoc->send_queue) &&
793 TAILQ_EMPTY(&asoc->sent_queue) &&
794 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
798 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
799 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
800 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
801 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
802 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
803 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
804 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
806 SCTP_INP_RUNLOCK(inp);
807 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
808 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
811 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
814 soisdisconnecting(so);
815 SCTP_TCB_UNLOCK(stcb);
816 SCTP_INP_RUNLOCK(inp);
821 /* UDP model does not support this */
822 SCTP_INP_RUNLOCK(inp);
823 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
829 sctp_flush(struct socket *so, int how)
832 * We will just clear out the values and let subsequent close clear
833 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
834 * they will not be able to read the data, the socket will block
835 * that from happening.
837 struct sctp_inpcb *inp;
839 inp = (struct sctp_inpcb *)so->so_pcb;
841 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
845 /* For the 1 to many model this does nothing */
846 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
847 SCTP_INP_RUNLOCK(inp);
850 SCTP_INP_RUNLOCK(inp);
851 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
853 * First make sure the sb will be happy, we don't use these
854 * except maybe the count
857 SCTP_INP_READ_LOCK(inp);
858 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
859 SCTP_INP_READ_UNLOCK(inp);
860 SCTP_INP_WUNLOCK(inp);
861 so->so_rcv.sb_cc = 0;
862 so->so_rcv.sb_mbcnt = 0;
863 so->so_rcv.sb_mb = NULL;
865 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
867 * First make sure the sb will be happy, we don't use these
868 * except maybe the count
870 so->so_snd.sb_cc = 0;
871 so->so_snd.sb_mbcnt = 0;
872 so->so_snd.sb_mb = NULL;
879 sctp_shutdown(struct socket *so)
881 struct sctp_inpcb *inp;
883 inp = (struct sctp_inpcb *)so->so_pcb;
885 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
889 /* For UDP model this is a invalid call */
890 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
891 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
892 /* Restore the flags that the soshutdown took away. */
893 SOCKBUF_LOCK(&so->so_rcv);
894 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
895 SOCKBUF_UNLOCK(&so->so_rcv);
896 /* This proc will wakeup for read and do nothing (I hope) */
897 SCTP_INP_RUNLOCK(inp);
898 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
902 * Ok, if we reach here its the TCP model and it is either a
903 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
906 struct sctp_tcb *stcb;
907 struct sctp_association *asoc;
908 struct sctp_nets *netp;
911 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
912 SCTP_INP_RUNLOCK(inp);
917 stcb = LIST_FIRST(&inp->sctp_asoc_list);
920 * Ok, we hit the case that the shutdown call was
921 * made after an abort or something. Nothing to do
924 SCTP_INP_RUNLOCK(inp);
929 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
930 SCTP_TCB_UNLOCK(stcb);
931 SCTP_INP_RUNLOCK(inp);
934 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_WAIT) &&
935 (SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_ECHOED) &&
936 (SCTP_GET_STATE(asoc) != SCTP_STATE_OPEN)) {
938 * If we are not in or before ESTABLISHED, there is
939 * no protocol action required.
941 SCTP_TCB_UNLOCK(stcb);
942 SCTP_INP_RUNLOCK(inp);
945 if (stcb->asoc.alternate) {
946 netp = stcb->asoc.alternate;
948 netp = stcb->asoc.primary_destination;
950 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) &&
951 TAILQ_EMPTY(&asoc->send_queue) &&
952 TAILQ_EMPTY(&asoc->sent_queue) &&
953 (asoc->stream_queue_cnt == 0)) {
954 if (asoc->locked_on_sending) {
957 /* there is nothing queued to send, so I'm done... */
958 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
959 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
960 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
961 sctp_stop_timers_for_shutdown(stcb);
962 sctp_send_shutdown(stcb, netp);
963 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
964 stcb->sctp_ep, stcb, netp);
967 * We still got (or just got) data to send, so set
970 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
971 if (asoc->locked_on_sending) {
972 /* Locked to send out the data */
973 struct sctp_stream_queue_pending *sp;
975 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
977 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
978 asoc->locked_on_sending->stream_no);
980 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
981 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_PARTIAL_MSG_LEFT);
985 if (TAILQ_EMPTY(&asoc->send_queue) &&
986 TAILQ_EMPTY(&asoc->sent_queue) &&
987 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
991 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
992 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
993 sctp_abort_an_association(stcb->sctp_ep, stcb,
994 op_err, SCTP_SO_LOCKED);
995 SCTP_INP_RUNLOCK(inp);
999 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, netp);
1001 * XXX: Why do this in the case where we have still data
1004 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1005 SCTP_TCB_UNLOCK(stcb);
1006 SCTP_INP_RUNLOCK(inp);
1012 * copies a "user" presentable address and removes embedded scope, etc.
1013 * returns 0 on success, 1 on error
1016 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1019 struct sockaddr_in6 lsa6;
1021 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1024 memcpy(ss, sa, sa->sa_len);
1031 * NOTE: assumes addr lock is held
1034 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1035 struct sctp_tcb *stcb,
1037 struct sockaddr_storage *sas,
1040 struct sctp_ifn *sctp_ifn;
1041 struct sctp_ifa *sctp_ifa;
1046 int ipv4_local_scope, ipv4_addr_legal;
1050 int local_scope, site_scope, ipv6_addr_legal;
1053 struct sctp_vrf *vrf;
1060 /* Turn on all the appropriate scope */
1061 loopback_scope = stcb->asoc.scope.loopback_scope;
1063 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1064 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1067 local_scope = stcb->asoc.scope.local_scope;
1068 site_scope = stcb->asoc.scope.site_scope;
1069 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1072 /* Use generic values for endpoints. */
1075 ipv4_local_scope = 1;
1081 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1083 ipv6_addr_legal = 1;
1086 if (SCTP_IPV6_V6ONLY(inp)) {
1087 ipv4_addr_legal = 0;
1089 ipv4_addr_legal = 1;
1094 ipv6_addr_legal = 0;
1097 ipv4_addr_legal = 1;
1101 vrf = sctp_find_vrf(vrf_id);
1105 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1106 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1107 if ((loopback_scope == 0) &&
1108 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1109 /* Skip loopback if loopback_scope not set */
1112 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1115 * For the BOUND-ALL case, the list
1116 * associated with a TCB is Always
1117 * considered a reverse list.. i.e.
1118 * it lists addresses that are NOT
1119 * part of the association. If this
1120 * is one of those we must skip it.
1122 if (sctp_is_addr_restricted(stcb,
1127 switch (sctp_ifa->address.sa.sa_family) {
1130 if (ipv4_addr_legal) {
1131 struct sockaddr_in *sin;
1133 sin = &sctp_ifa->address.sin;
1134 if (sin->sin_addr.s_addr == 0) {
1142 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1143 &sin->sin_addr) != 0) {
1146 if ((ipv4_local_scope == 0) &&
1147 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1151 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1152 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1153 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1154 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1155 actual += sizeof(struct sockaddr_in6);
1158 memcpy(sas, sin, sizeof(*sin));
1159 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1160 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1161 actual += sizeof(*sin);
1165 if (actual >= limit) {
1175 if (ipv6_addr_legal) {
1176 struct sockaddr_in6 *sin6;
1178 sin6 = &sctp_ifa->address.sin6;
1179 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1187 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1188 &sin6->sin6_addr) != 0) {
1191 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1192 if (local_scope == 0)
1194 if (sin6->sin6_scope_id == 0) {
1195 if (sa6_recoverscope(sin6) != 0)
1213 if ((site_scope == 0) &&
1214 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1217 memcpy(sas, sin6, sizeof(*sin6));
1218 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1219 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1220 actual += sizeof(*sin6);
1221 if (actual >= limit) {
1236 struct sctp_laddr *laddr;
1238 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1240 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1244 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1246 switch (laddr->ifa->address.sa.sa_family) {
1249 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1254 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1261 sas = (struct sockaddr_storage *)((caddr_t)sas +
1262 laddr->ifa->address.sa.sa_len);
1263 actual += laddr->ifa->address.sa.sa_len;
1264 if (actual >= limit) {
1273 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1274 struct sctp_tcb *stcb,
1276 struct sockaddr_storage *sas)
1280 SCTP_IPI_ADDR_RLOCK();
1281 /* fill up addresses for the endpoint's default vrf */
1282 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1284 SCTP_IPI_ADDR_RUNLOCK();
1289 * NOTE: assumes addr lock is held
1292 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1295 struct sctp_vrf *vrf = NULL;
1298 * In both sub-set bound an bound_all cases we return the MAXIMUM
1299 * number of addresses that you COULD get. In reality the sub-set
1300 * bound may have an exclusion list for a given TCB OR in the
1301 * bound-all case a TCB may NOT include the loopback or other
1302 * addresses as well.
1304 vrf = sctp_find_vrf(vrf_id);
1308 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1309 struct sctp_ifn *sctp_ifn;
1310 struct sctp_ifa *sctp_ifa;
1312 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1313 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1314 /* Count them if they are the right type */
1315 switch (sctp_ifa->address.sa.sa_family) {
1319 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1320 cnt += sizeof(struct sockaddr_in6);
1322 cnt += sizeof(struct sockaddr_in);
1324 cnt += sizeof(struct sockaddr_in);
1330 cnt += sizeof(struct sockaddr_in6);
1339 struct sctp_laddr *laddr;
1341 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1342 switch (laddr->ifa->address.sa.sa_family) {
1346 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1347 cnt += sizeof(struct sockaddr_in6);
1349 cnt += sizeof(struct sockaddr_in);
1351 cnt += sizeof(struct sockaddr_in);
1357 cnt += sizeof(struct sockaddr_in6);
1369 sctp_count_max_addresses(struct sctp_inpcb *inp)
1373 SCTP_IPI_ADDR_RLOCK();
1374 /* count addresses for the endpoint's default VRF */
1375 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1376 SCTP_IPI_ADDR_RUNLOCK();
1381 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1382 size_t optsize, void *p, int delay)
1385 int creat_lock_on = 0;
1386 struct sctp_tcb *stcb = NULL;
1387 struct sockaddr *sa;
1388 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1390 int bad_addresses = 0;
1393 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1395 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1396 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1397 /* We are already connected AND the TCP model */
1398 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1399 return (EADDRINUSE);
1401 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1402 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1403 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1406 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1407 SCTP_INP_RLOCK(inp);
1408 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1409 SCTP_INP_RUNLOCK(inp);
1412 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1415 SCTP_INP_INCR_REF(inp);
1416 SCTP_ASOC_CREATE_LOCK(inp);
1418 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1419 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1420 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1424 totaddrp = (unsigned int *)optval;
1425 totaddr = *totaddrp;
1426 sa = (struct sockaddr *)(totaddrp + 1);
1427 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (unsigned int)(optsize - sizeof(int)), &bad_addresses);
1428 if ((stcb != NULL) || bad_addresses) {
1429 /* Already have or am bring up an association */
1430 SCTP_ASOC_CREATE_UNLOCK(inp);
1433 SCTP_TCB_UNLOCK(stcb);
1434 if (bad_addresses == 0) {
1435 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1441 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1446 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1448 struct in6pcb *inp6;
1450 inp6 = (struct in6pcb *)inp;
1451 if (SCTP_IPV6_V6ONLY(inp6)) {
1453 * if IPV6_V6ONLY flag, ignore connections destined
1454 * to a v4 addr or v4-mapped addr
1456 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1462 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1463 SCTP_PCB_FLAGS_UNBOUND) {
1464 /* Bind a ephemeral port */
1465 error = sctp_inpcb_bind(so, NULL, NULL, p);
1470 /* FIX ME: do we want to pass in a vrf on the connect call? */
1471 vrf_id = inp->def_vrf_id;
1474 /* We are GOOD to go */
1475 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1476 inp->sctp_ep.pre_open_stream_count,
1481 /* Gak! no memory */
1484 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1485 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1486 /* Set the connected flag so we can queue data */
1489 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1490 /* move to second address */
1491 switch (sa->sa_family) {
1494 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1499 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1507 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1508 /* Fill in the return id */
1510 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE,
1511 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
1514 a_id = (sctp_assoc_t *) optval;
1515 *a_id = sctp_get_associd(stcb);
1517 /* initialize authentication parameters for the assoc */
1518 sctp_initialize_auth_params(inp, stcb);
1521 /* doing delayed connection */
1522 stcb->asoc.delayed_connection = 1;
1523 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1525 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1526 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1528 SCTP_TCB_UNLOCK(stcb);
1529 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1530 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1531 /* Set the connected flag so we can queue data */
1535 if (creat_lock_on) {
1536 SCTP_ASOC_CREATE_UNLOCK(inp);
1538 SCTP_INP_DECR_REF(inp);
1542 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1543 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1544 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1545 SCTP_INP_RLOCK(inp); \
1546 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1548 SCTP_TCB_LOCK(stcb); \
1550 SCTP_INP_RUNLOCK(inp); \
1551 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1552 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1553 if (stcb == NULL) { \
1554 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1564 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1565 if (size < sizeof(type)) { \
1566 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1570 destp = (type *)srcp; \
1575 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1578 struct sctp_inpcb *inp = NULL;
1580 struct sctp_tcb *stcb = NULL;
1582 if (optval == NULL) {
1583 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1586 inp = (struct sctp_inpcb *)so->so_pcb;
1588 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1595 case SCTP_AUTOCLOSE:
1596 case SCTP_EXPLICIT_EOR:
1597 case SCTP_AUTO_ASCONF:
1598 case SCTP_DISABLE_FRAGMENTS:
1599 case SCTP_I_WANT_MAPPED_V4_ADDR:
1600 case SCTP_USE_EXT_RCVINFO:
1601 SCTP_INP_RLOCK(inp);
1603 case SCTP_DISABLE_FRAGMENTS:
1604 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1606 case SCTP_I_WANT_MAPPED_V4_ADDR:
1607 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1609 case SCTP_AUTO_ASCONF:
1610 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1611 /* only valid for bound all sockets */
1612 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1614 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1619 case SCTP_EXPLICIT_EOR:
1620 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1623 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1625 case SCTP_USE_EXT_RCVINFO:
1626 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1628 case SCTP_AUTOCLOSE:
1629 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1630 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1636 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1637 error = ENOPROTOOPT;
1638 } /* end switch (sopt->sopt_name) */
1639 if (*optsize < sizeof(val)) {
1640 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1644 SCTP_INP_RUNLOCK(inp);
1646 /* return the option value */
1647 *(int *)optval = val;
1648 *optsize = sizeof(val);
1651 case SCTP_GET_PACKET_LOG:
1653 #ifdef SCTP_PACKET_LOGGING
1657 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1658 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1661 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1666 case SCTP_REUSE_PORT:
1670 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1671 /* Can't do this for a 1-m socket */
1675 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1676 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1677 *optsize = sizeof(uint32_t);
1680 case SCTP_PARTIAL_DELIVERY_POINT:
1684 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1685 *value = inp->partial_delivery_point;
1686 *optsize = sizeof(uint32_t);
1689 case SCTP_FRAGMENT_INTERLEAVE:
1693 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1694 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1695 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1696 *value = SCTP_FRAG_LEVEL_2;
1698 *value = SCTP_FRAG_LEVEL_1;
1701 *value = SCTP_FRAG_LEVEL_0;
1703 *optsize = sizeof(uint32_t);
1706 case SCTP_INTERLEAVING_SUPPORTED:
1708 struct sctp_assoc_value *av;
1710 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1711 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1714 av->assoc_value = stcb->asoc.idata_supported;
1715 SCTP_TCB_UNLOCK(stcb);
1717 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1718 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1719 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1720 SCTP_INP_RLOCK(inp);
1721 if (inp->idata_supported) {
1722 av->assoc_value = 1;
1724 av->assoc_value = 0;
1726 SCTP_INP_RUNLOCK(inp);
1728 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1733 *optsize = sizeof(struct sctp_assoc_value);
1737 case SCTP_CMT_ON_OFF:
1739 struct sctp_assoc_value *av;
1741 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1742 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1744 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1745 SCTP_TCB_UNLOCK(stcb);
1747 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1748 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1749 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1750 SCTP_INP_RLOCK(inp);
1751 av->assoc_value = inp->sctp_cmt_on_off;
1752 SCTP_INP_RUNLOCK(inp);
1754 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1759 *optsize = sizeof(struct sctp_assoc_value);
1763 case SCTP_PLUGGABLE_CC:
1765 struct sctp_assoc_value *av;
1767 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1768 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1770 av->assoc_value = stcb->asoc.congestion_control_module;
1771 SCTP_TCB_UNLOCK(stcb);
1773 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1774 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1775 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1776 SCTP_INP_RLOCK(inp);
1777 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1778 SCTP_INP_RUNLOCK(inp);
1780 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1785 *optsize = sizeof(struct sctp_assoc_value);
1789 case SCTP_CC_OPTION:
1791 struct sctp_cc_option *cc_opt;
1793 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1794 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1798 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1801 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1802 *optsize = sizeof(struct sctp_cc_option);
1804 SCTP_TCB_UNLOCK(stcb);
1808 case SCTP_PLUGGABLE_SS:
1810 struct sctp_assoc_value *av;
1812 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1813 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1815 av->assoc_value = stcb->asoc.stream_scheduling_module;
1816 SCTP_TCB_UNLOCK(stcb);
1818 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1819 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1820 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1821 SCTP_INP_RLOCK(inp);
1822 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1823 SCTP_INP_RUNLOCK(inp);
1825 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1830 *optsize = sizeof(struct sctp_assoc_value);
1836 struct sctp_stream_value *av;
1838 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1839 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1841 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1842 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1843 &av->stream_value) < 0)) {
1844 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1847 *optsize = sizeof(struct sctp_stream_value);
1849 SCTP_TCB_UNLOCK(stcb);
1852 * Can't get stream value without
1855 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1860 case SCTP_GET_ADDR_LEN:
1862 struct sctp_assoc_value *av;
1864 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1867 if (av->assoc_value == AF_INET) {
1868 av->assoc_value = sizeof(struct sockaddr_in);
1873 if (av->assoc_value == AF_INET6) {
1874 av->assoc_value = sizeof(struct sockaddr_in6);
1879 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1881 *optsize = sizeof(struct sctp_assoc_value);
1885 case SCTP_GET_ASSOC_NUMBER:
1887 uint32_t *value, cnt;
1889 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1890 SCTP_INP_RLOCK(inp);
1891 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1892 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1893 /* Can't do this for a 1-1 socket */
1895 SCTP_INP_RUNLOCK(inp);
1899 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1902 SCTP_INP_RUNLOCK(inp);
1904 *optsize = sizeof(uint32_t);
1907 case SCTP_GET_ASSOC_ID_LIST:
1909 struct sctp_assoc_ids *ids;
1913 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1914 SCTP_INP_RLOCK(inp);
1915 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1916 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1917 /* Can't do this for a 1-1 socket */
1919 SCTP_INP_RUNLOCK(inp);
1923 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1924 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1926 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1929 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1934 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1938 SCTP_INP_RUNLOCK(inp);
1940 ids->gaids_number_of_ids = at;
1941 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1947 struct sctp_assoc_value *av;
1949 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1950 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1953 av->assoc_value = stcb->asoc.context;
1954 SCTP_TCB_UNLOCK(stcb);
1956 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1957 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1958 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1959 SCTP_INP_RLOCK(inp);
1960 av->assoc_value = inp->sctp_context;
1961 SCTP_INP_RUNLOCK(inp);
1963 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1968 *optsize = sizeof(struct sctp_assoc_value);
1974 uint32_t *default_vrfid;
1976 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1977 *default_vrfid = inp->def_vrf_id;
1978 *optsize = sizeof(uint32_t);
1981 case SCTP_GET_ASOC_VRF:
1983 struct sctp_assoc_value *id;
1985 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1986 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1989 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1991 id->assoc_value = stcb->asoc.vrf_id;
1992 *optsize = sizeof(struct sctp_assoc_value);
1996 case SCTP_GET_VRF_IDS:
1998 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
2002 case SCTP_GET_NONCE_VALUES:
2004 struct sctp_get_nonce_values *gnv;
2006 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
2007 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
2010 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
2011 gnv->gn_local_tag = stcb->asoc.my_vtag;
2012 SCTP_TCB_UNLOCK(stcb);
2013 *optsize = sizeof(struct sctp_get_nonce_values);
2015 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2020 case SCTP_DELAYED_SACK:
2022 struct sctp_sack_info *sack;
2024 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2025 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2027 sack->sack_delay = stcb->asoc.delayed_ack;
2028 sack->sack_freq = stcb->asoc.sack_freq;
2029 SCTP_TCB_UNLOCK(stcb);
2031 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2032 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2033 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2034 SCTP_INP_RLOCK(inp);
2035 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2036 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2037 SCTP_INP_RUNLOCK(inp);
2039 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2044 *optsize = sizeof(struct sctp_sack_info);
2048 case SCTP_GET_SNDBUF_USE:
2050 struct sctp_sockstat *ss;
2052 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2053 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2056 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2057 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2058 stcb->asoc.size_on_all_streams);
2059 SCTP_TCB_UNLOCK(stcb);
2060 *optsize = sizeof(struct sctp_sockstat);
2062 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2067 case SCTP_MAX_BURST:
2069 struct sctp_assoc_value *av;
2071 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2072 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2075 av->assoc_value = stcb->asoc.max_burst;
2076 SCTP_TCB_UNLOCK(stcb);
2078 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2079 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2080 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2081 SCTP_INP_RLOCK(inp);
2082 av->assoc_value = inp->sctp_ep.max_burst;
2083 SCTP_INP_RUNLOCK(inp);
2085 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2090 *optsize = sizeof(struct sctp_assoc_value);
2096 struct sctp_assoc_value *av;
2099 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2100 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2103 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2104 SCTP_TCB_UNLOCK(stcb);
2106 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2107 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2108 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2109 SCTP_INP_RLOCK(inp);
2110 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2111 ovh = SCTP_MED_OVERHEAD;
2113 ovh = SCTP_MED_V4_OVERHEAD;
2115 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2116 av->assoc_value = 0;
2118 av->assoc_value = inp->sctp_frag_point - ovh;
2119 SCTP_INP_RUNLOCK(inp);
2121 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2126 *optsize = sizeof(struct sctp_assoc_value);
2130 case SCTP_GET_STAT_LOG:
2131 error = sctp_fill_stat_log(optval, optsize);
2135 struct sctp_event_subscribe *events;
2137 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2138 memset(events, 0, sizeof(struct sctp_event_subscribe));
2139 SCTP_INP_RLOCK(inp);
2140 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2141 events->sctp_data_io_event = 1;
2143 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2144 events->sctp_association_event = 1;
2146 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2147 events->sctp_address_event = 1;
2149 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2150 events->sctp_send_failure_event = 1;
2152 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2153 events->sctp_peer_error_event = 1;
2155 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2156 events->sctp_shutdown_event = 1;
2158 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2159 events->sctp_partial_delivery_event = 1;
2161 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2162 events->sctp_adaptation_layer_event = 1;
2164 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2165 events->sctp_authentication_event = 1;
2167 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2168 events->sctp_sender_dry_event = 1;
2170 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2171 events->sctp_stream_reset_event = 1;
2172 SCTP_INP_RUNLOCK(inp);
2173 *optsize = sizeof(struct sctp_event_subscribe);
2176 case SCTP_ADAPTATION_LAYER:
2180 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2182 SCTP_INP_RLOCK(inp);
2183 *value = inp->sctp_ep.adaptation_layer_indicator;
2184 SCTP_INP_RUNLOCK(inp);
2185 *optsize = sizeof(uint32_t);
2188 case SCTP_SET_INITIAL_DBG_SEQ:
2192 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2193 SCTP_INP_RLOCK(inp);
2194 *value = inp->sctp_ep.initial_sequence_debug;
2195 SCTP_INP_RUNLOCK(inp);
2196 *optsize = sizeof(uint32_t);
2199 case SCTP_GET_LOCAL_ADDR_SIZE:
2203 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2204 SCTP_INP_RLOCK(inp);
2205 *value = sctp_count_max_addresses(inp);
2206 SCTP_INP_RUNLOCK(inp);
2207 *optsize = sizeof(uint32_t);
2210 case SCTP_GET_REMOTE_ADDR_SIZE:
2214 struct sctp_nets *net;
2216 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2217 /* FIXME MT: change to sctp_assoc_value? */
2218 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2222 /* Count the sizes */
2223 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2224 switch (net->ro._l_addr.sa.sa_family) {
2228 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2229 size += sizeof(struct sockaddr_in6);
2231 size += sizeof(struct sockaddr_in);
2234 size += sizeof(struct sockaddr_in);
2240 size += sizeof(struct sockaddr_in6);
2247 SCTP_TCB_UNLOCK(stcb);
2248 *value = (uint32_t) size;
2249 *optsize = sizeof(uint32_t);
2251 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2256 case SCTP_GET_PEER_ADDRESSES:
2258 * Get the address information, an array is passed in to
2259 * fill up we pack it.
2263 struct sockaddr_storage *sas;
2264 struct sctp_nets *net;
2265 struct sctp_getaddresses *saddr;
2267 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2268 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2271 left = (*optsize) - sizeof(struct sctp_getaddresses);
2272 *optsize = sizeof(struct sctp_getaddresses);
2273 sas = (struct sockaddr_storage *)&saddr->addr[0];
2275 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2276 switch (net->ro._l_addr.sa.sa_family) {
2280 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2281 cpsz = sizeof(struct sockaddr_in6);
2283 cpsz = sizeof(struct sockaddr_in);
2286 cpsz = sizeof(struct sockaddr_in);
2292 cpsz = sizeof(struct sockaddr_in6);
2303 /* not enough room. */
2306 #if defined(INET) && defined(INET6)
2307 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2308 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2309 /* Must map the address */
2310 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2311 (struct sockaddr_in6 *)sas);
2313 memcpy(sas, &net->ro._l_addr, cpsz);
2316 memcpy(sas, &net->ro._l_addr, cpsz);
2318 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2320 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2324 SCTP_TCB_UNLOCK(stcb);
2326 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2331 case SCTP_GET_LOCAL_ADDRESSES:
2333 size_t limit, actual;
2334 struct sockaddr_storage *sas;
2335 struct sctp_getaddresses *saddr;
2337 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2338 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2340 sas = (struct sockaddr_storage *)&saddr->addr[0];
2341 limit = *optsize - sizeof(sctp_assoc_t);
2342 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2344 SCTP_TCB_UNLOCK(stcb);
2346 *optsize = sizeof(struct sockaddr_storage) + actual;
2349 case SCTP_PEER_ADDR_PARAMS:
2351 struct sctp_paddrparams *paddrp;
2352 struct sctp_nets *net;
2353 struct sockaddr *addr;
2355 #if defined(INET) && defined(INET6)
2356 struct sockaddr_in sin_store;
2360 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2361 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2363 #if defined(INET) && defined(INET6)
2364 if (paddrp->spp_address.ss_family == AF_INET6) {
2365 struct sockaddr_in6 *sin6;
2367 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2368 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2369 in6_sin6_2_sin(&sin_store, sin6);
2370 addr = (struct sockaddr *)&sin_store;
2372 addr = (struct sockaddr *)&paddrp->spp_address;
2375 addr = (struct sockaddr *)&paddrp->spp_address;
2378 addr = (struct sockaddr *)&paddrp->spp_address;
2381 net = sctp_findnet(stcb, addr);
2384 * We increment here since
2385 * sctp_findassociation_ep_addr() wil do a
2386 * decrement if it finds the stcb as long as
2387 * the locked tcb (last argument) is NOT a
2391 SCTP_INP_INCR_REF(inp);
2392 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2394 SCTP_INP_DECR_REF(inp);
2397 if ((stcb != NULL) && (net == NULL)) {
2399 if (addr->sa_family == AF_INET) {
2400 struct sockaddr_in *sin;
2402 sin = (struct sockaddr_in *)addr;
2403 if (sin->sin_addr.s_addr != INADDR_ANY) {
2405 SCTP_TCB_UNLOCK(stcb);
2406 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2412 if (addr->sa_family == AF_INET6) {
2413 struct sockaddr_in6 *sin6;
2415 sin6 = (struct sockaddr_in6 *)addr;
2416 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2418 SCTP_TCB_UNLOCK(stcb);
2419 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2425 error = EAFNOSUPPORT;
2426 SCTP_TCB_UNLOCK(stcb);
2427 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2432 /* Applies to the specific association */
2433 paddrp->spp_flags = 0;
2435 paddrp->spp_hbinterval = net->heart_beat_delay;
2436 paddrp->spp_pathmaxrxt = net->failure_threshold;
2437 paddrp->spp_pathmtu = net->mtu;
2438 switch (net->ro._l_addr.sa.sa_family) {
2441 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2446 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2452 /* get flags for HB */
2453 if (net->dest_state & SCTP_ADDR_NOHB) {
2454 paddrp->spp_flags |= SPP_HB_DISABLE;
2456 paddrp->spp_flags |= SPP_HB_ENABLE;
2458 /* get flags for PMTU */
2459 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2460 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2462 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2464 if (net->dscp & 0x01) {
2465 paddrp->spp_dscp = net->dscp & 0xfc;
2466 paddrp->spp_flags |= SPP_DSCP;
2469 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2470 (net->flowlabel & 0x80000000)) {
2471 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2472 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2477 * No destination so return default
2480 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2481 paddrp->spp_pathmtu = 0;
2482 if (stcb->asoc.default_dscp & 0x01) {
2483 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2484 paddrp->spp_flags |= SPP_DSCP;
2487 if (stcb->asoc.default_flowlabel & 0x80000000) {
2488 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2489 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2492 /* default settings should be these */
2493 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2494 paddrp->spp_flags |= SPP_HB_DISABLE;
2496 paddrp->spp_flags |= SPP_HB_ENABLE;
2498 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2499 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2501 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2503 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2505 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2506 SCTP_TCB_UNLOCK(stcb);
2508 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2509 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2510 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2511 /* Use endpoint defaults */
2512 SCTP_INP_RLOCK(inp);
2513 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2514 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2515 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2516 /* get inp's default */
2517 if (inp->sctp_ep.default_dscp & 0x01) {
2518 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2519 paddrp->spp_flags |= SPP_DSCP;
2522 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2523 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2524 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2525 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2528 /* can't return this */
2529 paddrp->spp_pathmtu = 0;
2531 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2532 paddrp->spp_flags |= SPP_HB_ENABLE;
2534 paddrp->spp_flags |= SPP_HB_DISABLE;
2536 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2537 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2539 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2541 SCTP_INP_RUNLOCK(inp);
2543 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2548 *optsize = sizeof(struct sctp_paddrparams);
2552 case SCTP_GET_PEER_ADDR_INFO:
2554 struct sctp_paddrinfo *paddri;
2555 struct sctp_nets *net;
2556 struct sockaddr *addr;
2558 #if defined(INET) && defined(INET6)
2559 struct sockaddr_in sin_store;
2563 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2564 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2566 #if defined(INET) && defined(INET6)
2567 if (paddri->spinfo_address.ss_family == AF_INET6) {
2568 struct sockaddr_in6 *sin6;
2570 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2571 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2572 in6_sin6_2_sin(&sin_store, sin6);
2573 addr = (struct sockaddr *)&sin_store;
2575 addr = (struct sockaddr *)&paddri->spinfo_address;
2578 addr = (struct sockaddr *)&paddri->spinfo_address;
2581 addr = (struct sockaddr *)&paddri->spinfo_address;
2584 net = sctp_findnet(stcb, addr);
2587 * We increment here since
2588 * sctp_findassociation_ep_addr() wil do a
2589 * decrement if it finds the stcb as long as
2590 * the locked tcb (last argument) is NOT a
2594 SCTP_INP_INCR_REF(inp);
2595 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2597 SCTP_INP_DECR_REF(inp);
2601 if ((stcb != NULL) && (net != NULL)) {
2602 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2603 /* It's unconfirmed */
2604 paddri->spinfo_state = SCTP_UNCONFIRMED;
2605 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2607 paddri->spinfo_state = SCTP_ACTIVE;
2610 paddri->spinfo_state = SCTP_INACTIVE;
2612 paddri->spinfo_cwnd = net->cwnd;
2613 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2614 paddri->spinfo_rto = net->RTO;
2615 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2616 paddri->spinfo_mtu = net->mtu;
2617 switch (addr->sa_family) {
2620 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2625 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2631 SCTP_TCB_UNLOCK(stcb);
2632 *optsize = sizeof(struct sctp_paddrinfo);
2635 SCTP_TCB_UNLOCK(stcb);
2637 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2642 case SCTP_PCB_STATUS:
2644 struct sctp_pcbinfo *spcb;
2646 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2647 sctp_fill_pcbinfo(spcb);
2648 *optsize = sizeof(struct sctp_pcbinfo);
2653 struct sctp_nets *net;
2654 struct sctp_status *sstat;
2656 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2657 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2660 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2664 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2665 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2666 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2667 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2669 * We can't include chunks that have been passed to
2670 * the socket layer. Only things in queue.
2672 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2673 stcb->asoc.cnt_on_all_streams);
2676 sstat->sstat_instrms = stcb->asoc.streamincnt;
2677 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2678 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2679 memcpy(&sstat->sstat_primary.spinfo_address,
2680 &stcb->asoc.primary_destination->ro._l_addr,
2681 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2682 net = stcb->asoc.primary_destination;
2683 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2685 * Again the user can get info from sctp_constants.h
2686 * for what the state of the network is.
2688 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2689 /* It's unconfirmed */
2690 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2691 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2693 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2696 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2698 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2699 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2700 sstat->sstat_primary.spinfo_rto = net->RTO;
2701 sstat->sstat_primary.spinfo_mtu = net->mtu;
2702 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2705 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2710 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2716 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2717 SCTP_TCB_UNLOCK(stcb);
2718 *optsize = sizeof(struct sctp_status);
2723 struct sctp_rtoinfo *srto;
2725 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2726 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2729 srto->srto_initial = stcb->asoc.initial_rto;
2730 srto->srto_max = stcb->asoc.maxrto;
2731 srto->srto_min = stcb->asoc.minrto;
2732 SCTP_TCB_UNLOCK(stcb);
2734 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2735 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2736 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2737 SCTP_INP_RLOCK(inp);
2738 srto->srto_initial = inp->sctp_ep.initial_rto;
2739 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2740 srto->srto_min = inp->sctp_ep.sctp_minrto;
2741 SCTP_INP_RUNLOCK(inp);
2743 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2748 *optsize = sizeof(struct sctp_rtoinfo);
2754 struct sctp_timeouts *stimo;
2756 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2757 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2760 stimo->stimo_init = stcb->asoc.timoinit;
2761 stimo->stimo_data = stcb->asoc.timodata;
2762 stimo->stimo_sack = stcb->asoc.timosack;
2763 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2764 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2765 stimo->stimo_cookie = stcb->asoc.timocookie;
2766 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2767 SCTP_TCB_UNLOCK(stcb);
2768 *optsize = sizeof(struct sctp_timeouts);
2770 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2775 case SCTP_ASSOCINFO:
2777 struct sctp_assocparams *sasoc;
2779 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2780 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2783 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2784 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2785 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2786 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2787 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2788 SCTP_TCB_UNLOCK(stcb);
2790 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2791 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2792 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2793 SCTP_INP_RLOCK(inp);
2794 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2795 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2796 sasoc->sasoc_number_peer_destinations = 0;
2797 sasoc->sasoc_peer_rwnd = 0;
2798 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2799 SCTP_INP_RUNLOCK(inp);
2801 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2806 *optsize = sizeof(struct sctp_assocparams);
2810 case SCTP_DEFAULT_SEND_PARAM:
2812 struct sctp_sndrcvinfo *s_info;
2814 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2815 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2818 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2819 SCTP_TCB_UNLOCK(stcb);
2821 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2822 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2823 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2824 SCTP_INP_RLOCK(inp);
2825 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2826 SCTP_INP_RUNLOCK(inp);
2828 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2833 *optsize = sizeof(struct sctp_sndrcvinfo);
2839 struct sctp_initmsg *sinit;
2841 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2842 SCTP_INP_RLOCK(inp);
2843 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2844 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2845 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2846 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2847 SCTP_INP_RUNLOCK(inp);
2848 *optsize = sizeof(struct sctp_initmsg);
2851 case SCTP_PRIMARY_ADDR:
2852 /* we allow a "get" operation on this */
2854 struct sctp_setprim *ssp;
2856 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2857 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2860 union sctp_sockstore *addr;
2862 addr = &stcb->asoc.primary_destination->ro._l_addr;
2863 switch (addr->sa.sa_family) {
2867 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2868 in6_sin_2_v4mapsin6(&addr->sin,
2869 (struct sockaddr_in6 *)&ssp->ssp_addr);
2871 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2874 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2880 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2886 SCTP_TCB_UNLOCK(stcb);
2887 *optsize = sizeof(struct sctp_setprim);
2889 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2894 case SCTP_HMAC_IDENT:
2896 struct sctp_hmacalgo *shmac;
2897 sctp_hmaclist_t *hmaclist;
2901 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2903 SCTP_INP_RLOCK(inp);
2904 hmaclist = inp->sctp_ep.local_hmacs;
2905 if (hmaclist == NULL) {
2906 /* no HMACs to return */
2907 *optsize = sizeof(*shmac);
2908 SCTP_INP_RUNLOCK(inp);
2911 /* is there room for all of the hmac ids? */
2912 size = sizeof(*shmac) + (hmaclist->num_algo *
2913 sizeof(shmac->shmac_idents[0]));
2914 if ((size_t)(*optsize) < size) {
2915 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2917 SCTP_INP_RUNLOCK(inp);
2920 /* copy in the list */
2921 shmac->shmac_number_of_idents = hmaclist->num_algo;
2922 for (i = 0; i < hmaclist->num_algo; i++) {
2923 shmac->shmac_idents[i] = hmaclist->hmac[i];
2925 SCTP_INP_RUNLOCK(inp);
2929 case SCTP_AUTH_ACTIVE_KEY:
2931 struct sctp_authkeyid *scact;
2933 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2934 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2937 /* get the active key on the assoc */
2938 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2939 SCTP_TCB_UNLOCK(stcb);
2941 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2942 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2943 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2944 /* get the endpoint active key */
2945 SCTP_INP_RLOCK(inp);
2946 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2947 SCTP_INP_RUNLOCK(inp);
2949 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2954 *optsize = sizeof(struct sctp_authkeyid);
2958 case SCTP_LOCAL_AUTH_CHUNKS:
2960 struct sctp_authchunks *sac;
2961 sctp_auth_chklist_t *chklist = NULL;
2964 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2965 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2968 /* get off the assoc */
2969 chklist = stcb->asoc.local_auth_chunks;
2970 /* is there enough space? */
2971 size = sctp_auth_get_chklist_size(chklist);
2972 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2974 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2976 /* copy in the chunks */
2977 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2978 sac->gauth_number_of_chunks = (uint32_t) size;
2979 *optsize = sizeof(struct sctp_authchunks) + size;
2981 SCTP_TCB_UNLOCK(stcb);
2983 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2984 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2985 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2986 /* get off the endpoint */
2987 SCTP_INP_RLOCK(inp);
2988 chklist = inp->sctp_ep.local_auth_chunks;
2989 /* is there enough space? */
2990 size = sctp_auth_get_chklist_size(chklist);
2991 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2993 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2995 /* copy in the chunks */
2996 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2997 sac->gauth_number_of_chunks = (uint32_t) size;
2998 *optsize = sizeof(struct sctp_authchunks) + size;
3000 SCTP_INP_RUNLOCK(inp);
3002 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3008 case SCTP_PEER_AUTH_CHUNKS:
3010 struct sctp_authchunks *sac;
3011 sctp_auth_chklist_t *chklist = NULL;
3014 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
3015 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
3018 /* get off the assoc */
3019 chklist = stcb->asoc.peer_auth_chunks;
3020 /* is there enough space? */
3021 size = sctp_auth_get_chklist_size(chklist);
3022 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
3024 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3026 /* copy in the chunks */
3027 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
3028 sac->gauth_number_of_chunks = (uint32_t) size;
3029 *optsize = sizeof(struct sctp_authchunks) + size;
3031 SCTP_TCB_UNLOCK(stcb);
3033 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3040 struct sctp_event *event;
3041 uint32_t event_type;
3043 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3044 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3046 switch (event->se_type) {
3047 case SCTP_ASSOC_CHANGE:
3048 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3050 case SCTP_PEER_ADDR_CHANGE:
3051 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3053 case SCTP_REMOTE_ERROR:
3054 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3056 case SCTP_SEND_FAILED:
3057 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3059 case SCTP_SHUTDOWN_EVENT:
3060 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3062 case SCTP_ADAPTATION_INDICATION:
3063 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3065 case SCTP_PARTIAL_DELIVERY_EVENT:
3066 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3068 case SCTP_AUTHENTICATION_EVENT:
3069 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3071 case SCTP_STREAM_RESET_EVENT:
3072 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3074 case SCTP_SENDER_DRY_EVENT:
3075 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3077 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3079 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3082 case SCTP_ASSOC_RESET_EVENT:
3083 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3085 case SCTP_STREAM_CHANGE_EVENT:
3086 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3088 case SCTP_SEND_FAILED_EVENT:
3089 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3093 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3097 if (event_type > 0) {
3099 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3100 SCTP_TCB_UNLOCK(stcb);
3102 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3103 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3104 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3105 SCTP_INP_RLOCK(inp);
3106 event->se_on = sctp_is_feature_on(inp, event_type);
3107 SCTP_INP_RUNLOCK(inp);
3109 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3115 *optsize = sizeof(struct sctp_event);
3119 case SCTP_RECVRCVINFO:
3123 if (*optsize < sizeof(int)) {
3124 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3127 SCTP_INP_RLOCK(inp);
3128 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3129 SCTP_INP_RUNLOCK(inp);
3132 /* return the option value */
3133 *(int *)optval = onoff;
3134 *optsize = sizeof(int);
3138 case SCTP_RECVNXTINFO:
3142 if (*optsize < sizeof(int)) {
3143 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3146 SCTP_INP_RLOCK(inp);
3147 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3148 SCTP_INP_RUNLOCK(inp);
3151 /* return the option value */
3152 *(int *)optval = onoff;
3153 *optsize = sizeof(int);
3157 case SCTP_DEFAULT_SNDINFO:
3159 struct sctp_sndinfo *info;
3161 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3162 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3165 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3166 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3167 info->snd_flags &= 0xfff0;
3168 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3169 info->snd_context = stcb->asoc.def_send.sinfo_context;
3170 SCTP_TCB_UNLOCK(stcb);
3172 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3173 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3174 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3175 SCTP_INP_RLOCK(inp);
3176 info->snd_sid = inp->def_send.sinfo_stream;
3177 info->snd_flags = inp->def_send.sinfo_flags;
3178 info->snd_flags &= 0xfff0;
3179 info->snd_ppid = inp->def_send.sinfo_ppid;
3180 info->snd_context = inp->def_send.sinfo_context;
3181 SCTP_INP_RUNLOCK(inp);
3183 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3188 *optsize = sizeof(struct sctp_sndinfo);
3192 case SCTP_DEFAULT_PRINFO:
3194 struct sctp_default_prinfo *info;
3196 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3197 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3200 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3201 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3202 SCTP_TCB_UNLOCK(stcb);
3204 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3205 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3206 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3207 SCTP_INP_RLOCK(inp);
3208 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3209 info->pr_value = inp->def_send.sinfo_timetolive;
3210 SCTP_INP_RUNLOCK(inp);
3212 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3217 *optsize = sizeof(struct sctp_default_prinfo);
3221 case SCTP_PEER_ADDR_THLDS:
3223 struct sctp_paddrthlds *thlds;
3224 struct sctp_nets *net;
3225 struct sockaddr *addr;
3227 #if defined(INET) && defined(INET6)
3228 struct sockaddr_in sin_store;
3232 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3233 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3235 #if defined(INET) && defined(INET6)
3236 if (thlds->spt_address.ss_family == AF_INET6) {
3237 struct sockaddr_in6 *sin6;
3239 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3240 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3241 in6_sin6_2_sin(&sin_store, sin6);
3242 addr = (struct sockaddr *)&sin_store;
3244 addr = (struct sockaddr *)&thlds->spt_address;
3247 addr = (struct sockaddr *)&thlds->spt_address;
3250 addr = (struct sockaddr *)&thlds->spt_address;
3253 net = sctp_findnet(stcb, addr);
3256 * We increment here since
3257 * sctp_findassociation_ep_addr() wil do a
3258 * decrement if it finds the stcb as long as
3259 * the locked tcb (last argument) is NOT a
3263 SCTP_INP_INCR_REF(inp);
3264 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3266 SCTP_INP_DECR_REF(inp);
3269 if ((stcb != NULL) && (net == NULL)) {
3271 if (addr->sa_family == AF_INET) {
3272 struct sockaddr_in *sin;
3274 sin = (struct sockaddr_in *)addr;
3275 if (sin->sin_addr.s_addr != INADDR_ANY) {
3277 SCTP_TCB_UNLOCK(stcb);
3278 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3284 if (addr->sa_family == AF_INET6) {
3285 struct sockaddr_in6 *sin6;
3287 sin6 = (struct sockaddr_in6 *)addr;
3288 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3290 SCTP_TCB_UNLOCK(stcb);
3291 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3297 error = EAFNOSUPPORT;
3298 SCTP_TCB_UNLOCK(stcb);
3299 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3305 thlds->spt_pathmaxrxt = net->failure_threshold;
3306 thlds->spt_pathpfthld = net->pf_threshold;
3307 thlds->spt_pathcpthld = 0xffff;
3309 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3310 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3311 thlds->spt_pathcpthld = 0xffff;
3313 thlds->spt_assoc_id = sctp_get_associd(stcb);
3314 SCTP_TCB_UNLOCK(stcb);
3316 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3317 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3318 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3319 /* Use endpoint defaults */
3320 SCTP_INP_RLOCK(inp);
3321 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3322 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3323 thlds->spt_pathcpthld = 0xffff;
3324 SCTP_INP_RUNLOCK(inp);
3326 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3331 *optsize = sizeof(struct sctp_paddrthlds);
3335 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3337 struct sctp_udpencaps *encaps;
3338 struct sctp_nets *net;
3339 struct sockaddr *addr;
3341 #if defined(INET) && defined(INET6)
3342 struct sockaddr_in sin_store;
3346 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3347 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3349 #if defined(INET) && defined(INET6)
3350 if (encaps->sue_address.ss_family == AF_INET6) {
3351 struct sockaddr_in6 *sin6;
3353 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3354 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3355 in6_sin6_2_sin(&sin_store, sin6);
3356 addr = (struct sockaddr *)&sin_store;
3358 addr = (struct sockaddr *)&encaps->sue_address;
3361 addr = (struct sockaddr *)&encaps->sue_address;
3364 addr = (struct sockaddr *)&encaps->sue_address;
3367 net = sctp_findnet(stcb, addr);
3370 * We increment here since
3371 * sctp_findassociation_ep_addr() wil do a
3372 * decrement if it finds the stcb as long as
3373 * the locked tcb (last argument) is NOT a
3377 SCTP_INP_INCR_REF(inp);
3378 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3380 SCTP_INP_DECR_REF(inp);
3383 if ((stcb != NULL) && (net == NULL)) {
3385 if (addr->sa_family == AF_INET) {
3386 struct sockaddr_in *sin;
3388 sin = (struct sockaddr_in *)addr;
3389 if (sin->sin_addr.s_addr != INADDR_ANY) {
3391 SCTP_TCB_UNLOCK(stcb);
3392 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3398 if (addr->sa_family == AF_INET6) {
3399 struct sockaddr_in6 *sin6;
3401 sin6 = (struct sockaddr_in6 *)addr;
3402 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3404 SCTP_TCB_UNLOCK(stcb);
3405 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3411 error = EAFNOSUPPORT;
3412 SCTP_TCB_UNLOCK(stcb);
3413 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3419 encaps->sue_port = net->port;
3421 encaps->sue_port = stcb->asoc.port;
3423 SCTP_TCB_UNLOCK(stcb);
3425 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3426 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3427 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3428 SCTP_INP_RLOCK(inp);
3429 encaps->sue_port = inp->sctp_ep.port;
3430 SCTP_INP_RUNLOCK(inp);
3432 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3437 *optsize = sizeof(struct sctp_udpencaps);
3441 case SCTP_ECN_SUPPORTED:
3443 struct sctp_assoc_value *av;
3445 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3446 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3449 av->assoc_value = stcb->asoc.ecn_supported;
3450 SCTP_TCB_UNLOCK(stcb);
3452 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3453 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3454 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3455 SCTP_INP_RLOCK(inp);
3456 av->assoc_value = inp->ecn_supported;
3457 SCTP_INP_RUNLOCK(inp);
3459 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3464 *optsize = sizeof(struct sctp_assoc_value);
3468 case SCTP_PR_SUPPORTED:
3470 struct sctp_assoc_value *av;
3472 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3473 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3476 av->assoc_value = stcb->asoc.prsctp_supported;
3477 SCTP_TCB_UNLOCK(stcb);
3479 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3480 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3481 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3482 SCTP_INP_RLOCK(inp);
3483 av->assoc_value = inp->prsctp_supported;
3484 SCTP_INP_RUNLOCK(inp);
3486 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3491 *optsize = sizeof(struct sctp_assoc_value);
3495 case SCTP_AUTH_SUPPORTED:
3497 struct sctp_assoc_value *av;
3499 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3500 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3503 av->assoc_value = stcb->asoc.auth_supported;
3504 SCTP_TCB_UNLOCK(stcb);
3506 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3507 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3508 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3509 SCTP_INP_RLOCK(inp);
3510 av->assoc_value = inp->auth_supported;
3511 SCTP_INP_RUNLOCK(inp);
3513 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3518 *optsize = sizeof(struct sctp_assoc_value);
3522 case SCTP_ASCONF_SUPPORTED:
3524 struct sctp_assoc_value *av;
3526 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3527 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3530 av->assoc_value = stcb->asoc.asconf_supported;
3531 SCTP_TCB_UNLOCK(stcb);
3533 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3534 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3535 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3536 SCTP_INP_RLOCK(inp);
3537 av->assoc_value = inp->asconf_supported;
3538 SCTP_INP_RUNLOCK(inp);
3540 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3545 *optsize = sizeof(struct sctp_assoc_value);
3549 case SCTP_RECONFIG_SUPPORTED:
3551 struct sctp_assoc_value *av;
3553 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3554 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3557 av->assoc_value = stcb->asoc.reconfig_supported;
3558 SCTP_TCB_UNLOCK(stcb);
3560 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3561 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3562 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3563 SCTP_INP_RLOCK(inp);
3564 av->assoc_value = inp->reconfig_supported;
3565 SCTP_INP_RUNLOCK(inp);
3567 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3572 *optsize = sizeof(struct sctp_assoc_value);
3576 case SCTP_NRSACK_SUPPORTED:
3578 struct sctp_assoc_value *av;
3580 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3581 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3584 av->assoc_value = stcb->asoc.nrsack_supported;
3585 SCTP_TCB_UNLOCK(stcb);
3587 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3588 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3589 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3590 SCTP_INP_RLOCK(inp);
3591 av->assoc_value = inp->nrsack_supported;
3592 SCTP_INP_RUNLOCK(inp);
3594 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3599 *optsize = sizeof(struct sctp_assoc_value);
3603 case SCTP_PKTDROP_SUPPORTED:
3605 struct sctp_assoc_value *av;
3607 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3608 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3611 av->assoc_value = stcb->asoc.pktdrop_supported;
3612 SCTP_TCB_UNLOCK(stcb);
3614 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3615 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3616 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3617 SCTP_INP_RLOCK(inp);
3618 av->assoc_value = inp->pktdrop_supported;
3619 SCTP_INP_RUNLOCK(inp);
3621 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3626 *optsize = sizeof(struct sctp_assoc_value);
3630 case SCTP_ENABLE_STREAM_RESET:
3632 struct sctp_assoc_value *av;
3634 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3635 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3638 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3639 SCTP_TCB_UNLOCK(stcb);
3641 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3642 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3643 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3644 SCTP_INP_RLOCK(inp);
3645 av->assoc_value = (uint32_t) inp->local_strreset_support;
3646 SCTP_INP_RUNLOCK(inp);
3648 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3653 *optsize = sizeof(struct sctp_assoc_value);
3657 case SCTP_PR_STREAM_STATUS:
3659 struct sctp_prstatus *sprstat;
3663 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3664 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3666 sid = sprstat->sprstat_sid;
3667 policy = sprstat->sprstat_policy;
3668 #if defined(SCTP_DETAILED_STR_STATS)
3669 if ((stcb != NULL) &&
3670 (sid < stcb->asoc.streamoutcnt) &&
3671 (policy != SCTP_PR_SCTP_NONE) &&
3672 ((policy <= SCTP_PR_SCTP_MAX) ||
3673 (policy == SCTP_PR_SCTP_ALL))) {
3674 if (policy == SCTP_PR_SCTP_ALL) {
3675 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3676 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3678 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3679 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3682 if ((stcb != NULL) &&
3683 (sid < stcb->asoc.streamoutcnt) &&
3684 (policy == SCTP_PR_SCTP_ALL)) {
3685 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3686 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3688 SCTP_TCB_UNLOCK(stcb);
3689 *optsize = sizeof(struct sctp_prstatus);
3691 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3696 case SCTP_PR_ASSOC_STATUS:
3698 struct sctp_prstatus *sprstat;
3701 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3702 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3704 policy = sprstat->sprstat_policy;
3705 if ((stcb != NULL) &&
3706 (policy != SCTP_PR_SCTP_NONE) &&
3707 ((policy <= SCTP_PR_SCTP_MAX) ||
3708 (policy == SCTP_PR_SCTP_ALL))) {
3709 if (policy == SCTP_PR_SCTP_ALL) {
3710 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3711 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3713 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3714 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3716 SCTP_TCB_UNLOCK(stcb);
3717 *optsize = sizeof(struct sctp_prstatus);
3719 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3726 struct sctp_assoc_value *av;
3728 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3729 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3732 av->assoc_value = stcb->asoc.max_cwnd;
3733 SCTP_TCB_UNLOCK(stcb);
3735 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3736 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3737 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3738 SCTP_INP_RLOCK(inp);
3739 av->assoc_value = inp->max_cwnd;
3740 SCTP_INP_RUNLOCK(inp);
3742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3747 *optsize = sizeof(struct sctp_assoc_value);
3752 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3753 error = ENOPROTOOPT;
3755 } /* end switch (sopt->sopt_name) */
3763 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3768 struct sctp_tcb *stcb = NULL;
3769 struct sctp_inpcb *inp = NULL;
3772 if (optval == NULL) {
3773 SCTP_PRINTF("optval is NULL\n");
3774 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3777 inp = (struct sctp_inpcb *)so->so_pcb;
3779 SCTP_PRINTF("inp is NULL?\n");
3780 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3783 vrf_id = inp->def_vrf_id;
3788 case SCTP_AUTOCLOSE:
3789 case SCTP_AUTO_ASCONF:
3790 case SCTP_EXPLICIT_EOR:
3791 case SCTP_DISABLE_FRAGMENTS:
3792 case SCTP_USE_EXT_RCVINFO:
3793 case SCTP_I_WANT_MAPPED_V4_ADDR:
3794 /* copy in the option value */
3795 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3800 case SCTP_DISABLE_FRAGMENTS:
3801 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3803 case SCTP_AUTO_ASCONF:
3805 * NOTE: we don't really support this flag
3807 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3808 /* only valid for bound all sockets */
3809 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3811 /* forbidden by admin */
3812 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3815 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3817 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3821 case SCTP_EXPLICIT_EOR:
3822 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3824 case SCTP_USE_EXT_RCVINFO:
3825 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3827 case SCTP_I_WANT_MAPPED_V4_ADDR:
3828 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3829 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3831 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3836 set_opt = SCTP_PCB_FLAGS_NODELAY;
3838 case SCTP_AUTOCLOSE:
3839 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3840 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3841 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3844 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3846 * The value is in ticks. Note this does not effect
3847 * old associations, only new ones.
3849 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3852 SCTP_INP_WLOCK(inp);
3854 sctp_feature_on(inp, set_opt);
3856 sctp_feature_off(inp, set_opt);
3858 SCTP_INP_WUNLOCK(inp);
3860 case SCTP_REUSE_PORT:
3862 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3863 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3864 /* Can't set it after we are bound */
3868 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3869 /* Can't do this for a 1-m socket */
3874 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3876 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3879 case SCTP_PARTIAL_DELIVERY_POINT:
3883 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3884 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3885 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3889 inp->partial_delivery_point = *value;
3892 case SCTP_FRAGMENT_INTERLEAVE:
3893 /* not yet until we re-write sctp_recvmsg() */
3897 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3898 if (*level == SCTP_FRAG_LEVEL_2) {
3899 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3900 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3901 } else if (*level == SCTP_FRAG_LEVEL_1) {
3902 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3903 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3904 } else if (*level == SCTP_FRAG_LEVEL_0) {
3905 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3906 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3909 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3914 case SCTP_INTERLEAVING_SUPPORTED:
3916 struct sctp_assoc_value *av;
3918 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3919 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3922 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3924 SCTP_TCB_UNLOCK(stcb);
3926 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3927 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3928 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3929 SCTP_INP_WLOCK(inp);
3930 if (av->assoc_value == 0) {
3931 inp->idata_supported = 0;
3933 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3934 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3935 inp->idata_supported = 1;
3943 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3947 SCTP_INP_WUNLOCK(inp);
3949 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3955 case SCTP_CMT_ON_OFF:
3956 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3957 struct sctp_assoc_value *av;
3959 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3960 if (av->assoc_value > SCTP_CMT_MAX) {
3961 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3965 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3967 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3968 SCTP_TCB_UNLOCK(stcb);
3970 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3971 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3972 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3973 (av->assoc_id == SCTP_ALL_ASSOC)) {
3974 SCTP_INP_WLOCK(inp);
3975 inp->sctp_cmt_on_off = av->assoc_value;
3976 SCTP_INP_WUNLOCK(inp);
3978 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3979 (av->assoc_id == SCTP_ALL_ASSOC)) {
3980 SCTP_INP_RLOCK(inp);
3981 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3982 SCTP_TCB_LOCK(stcb);
3983 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3984 SCTP_TCB_UNLOCK(stcb);
3986 SCTP_INP_RUNLOCK(inp);
3990 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3991 error = ENOPROTOOPT;
3994 case SCTP_PLUGGABLE_CC:
3996 struct sctp_assoc_value *av;
3997 struct sctp_nets *net;
3999 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4000 if ((av->assoc_value != SCTP_CC_RFC2581) &&
4001 (av->assoc_value != SCTP_CC_HSTCP) &&
4002 (av->assoc_value != SCTP_CC_HTCP) &&
4003 (av->assoc_value != SCTP_CC_RTCC)) {
4004 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4008 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4010 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4011 stcb->asoc.congestion_control_module = av->assoc_value;
4012 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4013 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4014 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4017 SCTP_TCB_UNLOCK(stcb);
4019 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4020 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4021 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4022 (av->assoc_id == SCTP_ALL_ASSOC)) {
4023 SCTP_INP_WLOCK(inp);
4024 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
4025 SCTP_INP_WUNLOCK(inp);
4027 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4028 (av->assoc_id == SCTP_ALL_ASSOC)) {
4029 SCTP_INP_RLOCK(inp);
4030 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4031 SCTP_TCB_LOCK(stcb);
4032 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4033 stcb->asoc.congestion_control_module = av->assoc_value;
4034 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4035 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4036 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4039 SCTP_TCB_UNLOCK(stcb);
4041 SCTP_INP_RUNLOCK(inp);
4046 case SCTP_CC_OPTION:
4048 struct sctp_cc_option *cc_opt;
4050 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4051 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4053 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
4054 SCTP_INP_RLOCK(inp);
4055 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4056 SCTP_TCB_LOCK(stcb);
4057 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4058 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4060 SCTP_TCB_UNLOCK(stcb);
4062 SCTP_INP_RUNLOCK(inp);
4067 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4070 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4073 SCTP_TCB_UNLOCK(stcb);
4077 case SCTP_PLUGGABLE_SS:
4079 struct sctp_assoc_value *av;
4081 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4082 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4083 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4084 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4085 (av->assoc_value != SCTP_SS_PRIORITY) &&
4086 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4087 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4088 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4092 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4094 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4095 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4096 stcb->asoc.stream_scheduling_module = av->assoc_value;
4097 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4098 SCTP_TCB_UNLOCK(stcb);
4100 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4101 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4102 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4103 (av->assoc_id == SCTP_ALL_ASSOC)) {
4104 SCTP_INP_WLOCK(inp);
4105 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4106 SCTP_INP_WUNLOCK(inp);
4108 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4109 (av->assoc_id == SCTP_ALL_ASSOC)) {
4110 SCTP_INP_RLOCK(inp);
4111 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4112 SCTP_TCB_LOCK(stcb);
4113 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4114 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4115 stcb->asoc.stream_scheduling_module = av->assoc_value;
4116 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4117 SCTP_TCB_UNLOCK(stcb);
4119 SCTP_INP_RUNLOCK(inp);
4126 struct sctp_stream_value *av;
4128 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4129 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4131 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4132 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4133 av->stream_value) < 0)) {
4134 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4137 SCTP_TCB_UNLOCK(stcb);
4139 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4140 SCTP_INP_RLOCK(inp);
4141 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4142 SCTP_TCB_LOCK(stcb);
4143 if (av->stream_id < stcb->asoc.streamoutcnt) {
4144 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4146 &stcb->asoc.strmout[av->stream_id],
4149 SCTP_TCB_UNLOCK(stcb);
4151 SCTP_INP_RUNLOCK(inp);
4154 * Can't set stream value without
4157 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4163 case SCTP_CLR_STAT_LOG:
4164 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4169 struct sctp_assoc_value *av;
4171 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4172 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4175 stcb->asoc.context = av->assoc_value;
4176 SCTP_TCB_UNLOCK(stcb);
4178 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4179 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4180 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4181 (av->assoc_id == SCTP_ALL_ASSOC)) {
4182 SCTP_INP_WLOCK(inp);
4183 inp->sctp_context = av->assoc_value;
4184 SCTP_INP_WUNLOCK(inp);
4186 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4187 (av->assoc_id == SCTP_ALL_ASSOC)) {
4188 SCTP_INP_RLOCK(inp);
4189 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4190 SCTP_TCB_LOCK(stcb);
4191 stcb->asoc.context = av->assoc_value;
4192 SCTP_TCB_UNLOCK(stcb);
4194 SCTP_INP_RUNLOCK(inp);
4201 uint32_t *default_vrfid;
4203 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4204 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4205 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4209 inp->def_vrf_id = *default_vrfid;
4212 case SCTP_DEL_VRF_ID:
4214 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4218 case SCTP_ADD_VRF_ID:
4220 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4224 case SCTP_DELAYED_SACK:
4226 struct sctp_sack_info *sack;
4228 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4229 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4230 if (sack->sack_delay) {
4231 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4232 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4233 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4234 sack->sack_delay = TICKS_TO_MSEC(1);
4238 if (sack->sack_delay) {
4239 stcb->asoc.delayed_ack = sack->sack_delay;
4241 if (sack->sack_freq) {
4242 stcb->asoc.sack_freq = sack->sack_freq;
4244 SCTP_TCB_UNLOCK(stcb);
4246 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4247 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4248 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4249 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4250 SCTP_INP_WLOCK(inp);
4251 if (sack->sack_delay) {
4252 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4254 if (sack->sack_freq) {
4255 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4257 SCTP_INP_WUNLOCK(inp);
4259 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4260 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4261 SCTP_INP_RLOCK(inp);
4262 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4263 SCTP_TCB_LOCK(stcb);
4264 if (sack->sack_delay) {
4265 stcb->asoc.delayed_ack = sack->sack_delay;
4267 if (sack->sack_freq) {
4268 stcb->asoc.sack_freq = sack->sack_freq;
4270 SCTP_TCB_UNLOCK(stcb);
4272 SCTP_INP_RUNLOCK(inp);
4277 case SCTP_AUTH_CHUNK:
4279 struct sctp_authchunk *sauth;
4281 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4283 SCTP_INP_WLOCK(inp);
4284 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4285 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4288 SCTP_INP_WUNLOCK(inp);
4293 struct sctp_authkey *sca;
4294 struct sctp_keyhead *shared_keys;
4295 sctp_sharedkey_t *shared_key;
4296 sctp_key_t *key = NULL;
4299 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4300 if (sca->sca_keylength == 0) {
4301 size = optsize - sizeof(struct sctp_authkey);
4303 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4304 size = sca->sca_keylength;
4306 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4311 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4314 shared_keys = &stcb->asoc.shared_keys;
4315 /* clear the cached keys for this key id */
4316 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4318 * create the new shared key and
4322 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4324 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4326 SCTP_TCB_UNLOCK(stcb);
4330 shared_key = sctp_alloc_sharedkey();
4331 if (shared_key == NULL) {
4333 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4335 SCTP_TCB_UNLOCK(stcb);
4338 shared_key->key = key;
4339 shared_key->keyid = sca->sca_keynumber;
4340 error = sctp_insert_sharedkey(shared_keys, shared_key);
4341 SCTP_TCB_UNLOCK(stcb);
4343 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4344 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4345 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4346 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4347 SCTP_INP_WLOCK(inp);
4348 shared_keys = &inp->sctp_ep.shared_keys;
4350 * clear the cached keys on all
4351 * assocs for this key id
4353 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4355 * create the new shared key and
4359 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4361 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4363 SCTP_INP_WUNLOCK(inp);
4367 shared_key = sctp_alloc_sharedkey();
4368 if (shared_key == NULL) {
4370 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4372 SCTP_INP_WUNLOCK(inp);
4375 shared_key->key = key;
4376 shared_key->keyid = sca->sca_keynumber;
4377 error = sctp_insert_sharedkey(shared_keys, shared_key);
4378 SCTP_INP_WUNLOCK(inp);
4380 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4381 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4382 SCTP_INP_RLOCK(inp);
4383 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4384 SCTP_TCB_LOCK(stcb);
4385 shared_keys = &stcb->asoc.shared_keys;
4387 * clear the cached keys for
4390 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4392 * create the new shared key
4393 * and insert/replace it
4396 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4398 SCTP_TCB_UNLOCK(stcb);
4402 shared_key = sctp_alloc_sharedkey();
4403 if (shared_key == NULL) {
4405 SCTP_TCB_UNLOCK(stcb);
4408 shared_key->key = key;
4409 shared_key->keyid = sca->sca_keynumber;
4410 error = sctp_insert_sharedkey(shared_keys, shared_key);
4411 SCTP_TCB_UNLOCK(stcb);
4413 SCTP_INP_RUNLOCK(inp);
4418 case SCTP_HMAC_IDENT:
4420 struct sctp_hmacalgo *shmac;
4421 sctp_hmaclist_t *hmaclist;
4425 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4426 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4427 (shmac->shmac_number_of_idents > 0xffff)) {
4428 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4432 hmaclist = sctp_alloc_hmaclist((uint16_t) shmac->shmac_number_of_idents);
4433 if (hmaclist == NULL) {
4434 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4438 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4439 hmacid = shmac->shmac_idents[i];
4440 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4441 /* invalid HMACs were found */ ;
4442 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4444 sctp_free_hmaclist(hmaclist);
4445 goto sctp_set_hmac_done;
4448 for (i = 0; i < hmaclist->num_algo; i++) {
4449 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4450 /* already in list */
4454 if (i == hmaclist->num_algo) {
4455 /* not found in list */
4456 sctp_free_hmaclist(hmaclist);
4457 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4461 /* set it on the endpoint */
4462 SCTP_INP_WLOCK(inp);
4463 if (inp->sctp_ep.local_hmacs)
4464 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4465 inp->sctp_ep.local_hmacs = hmaclist;
4466 SCTP_INP_WUNLOCK(inp);
4470 case SCTP_AUTH_ACTIVE_KEY:
4472 struct sctp_authkeyid *scact;
4474 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4475 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4477 /* set the active key on the right place */
4479 /* set the active key on the assoc */
4480 if (sctp_auth_setactivekey(stcb,
4481 scact->scact_keynumber)) {
4482 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4483 SCTP_FROM_SCTP_USRREQ,
4487 SCTP_TCB_UNLOCK(stcb);
4489 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4490 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4491 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4492 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4493 SCTP_INP_WLOCK(inp);
4494 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4495 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4498 SCTP_INP_WUNLOCK(inp);
4500 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4501 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4502 SCTP_INP_RLOCK(inp);
4503 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4504 SCTP_TCB_LOCK(stcb);
4505 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4506 SCTP_TCB_UNLOCK(stcb);
4508 SCTP_INP_RUNLOCK(inp);
4513 case SCTP_AUTH_DELETE_KEY:
4515 struct sctp_authkeyid *scdel;
4517 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4518 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4520 /* delete the key from the right place */
4522 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4523 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4526 SCTP_TCB_UNLOCK(stcb);
4528 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4529 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4530 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4531 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4532 SCTP_INP_WLOCK(inp);
4533 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4534 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4537 SCTP_INP_WUNLOCK(inp);
4539 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4540 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4541 SCTP_INP_RLOCK(inp);
4542 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4543 SCTP_TCB_LOCK(stcb);
4544 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4545 SCTP_TCB_UNLOCK(stcb);
4547 SCTP_INP_RUNLOCK(inp);
4552 case SCTP_AUTH_DEACTIVATE_KEY:
4554 struct sctp_authkeyid *keyid;
4556 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4557 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4559 /* deactivate the key from the right place */
4561 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4562 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4565 SCTP_TCB_UNLOCK(stcb);
4567 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4568 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4569 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4570 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4571 SCTP_INP_WLOCK(inp);
4572 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4573 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4576 SCTP_INP_WUNLOCK(inp);
4578 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4579 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4580 SCTP_INP_RLOCK(inp);
4581 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4582 SCTP_TCB_LOCK(stcb);
4583 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4584 SCTP_TCB_UNLOCK(stcb);
4586 SCTP_INP_RUNLOCK(inp);
4591 case SCTP_ENABLE_STREAM_RESET:
4593 struct sctp_assoc_value *av;
4595 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4596 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4597 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4601 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4603 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4604 SCTP_TCB_UNLOCK(stcb);
4606 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4607 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4608 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4609 (av->assoc_id == SCTP_ALL_ASSOC)) {
4610 SCTP_INP_WLOCK(inp);
4611 inp->local_strreset_support = (uint8_t) av->assoc_value;
4612 SCTP_INP_WUNLOCK(inp);
4614 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4615 (av->assoc_id == SCTP_ALL_ASSOC)) {
4616 SCTP_INP_RLOCK(inp);
4617 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4618 SCTP_TCB_LOCK(stcb);
4619 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4620 SCTP_TCB_UNLOCK(stcb);
4622 SCTP_INP_RUNLOCK(inp);
4627 case SCTP_RESET_STREAMS:
4629 struct sctp_reset_streams *strrst;
4630 int i, send_out = 0;
4633 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4634 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4636 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4640 if (stcb->asoc.reconfig_supported == 0) {
4642 * Peer does not support the chunk type.
4644 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4646 SCTP_TCB_UNLOCK(stcb);
4649 if (sizeof(struct sctp_reset_streams) +
4650 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4652 SCTP_TCB_UNLOCK(stcb);
4655 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4657 if (stcb->asoc.stream_reset_outstanding) {
4658 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4660 SCTP_TCB_UNLOCK(stcb);
4664 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4667 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4668 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4670 SCTP_TCB_UNLOCK(stcb);
4673 if ((send_in == 0) && (send_out == 0)) {
4674 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4676 SCTP_TCB_UNLOCK(stcb);
4679 for (i = 0; i < strrst->srs_number_streams; i++) {
4681 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4682 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4687 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4688 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4694 SCTP_TCB_UNLOCK(stcb);
4701 if (strrst->srs_number_streams) {
4702 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4703 strm = strrst->srs_stream_list[i];
4704 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4705 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4711 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4712 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4713 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4720 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4721 strrst->srs_stream_list,
4722 send_in, 0, 0, 0, 0, 0);
4724 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4727 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4730 * For outgoing streams don't report any
4731 * problems in sending the request to the
4732 * application. XXX: Double check resetting
4737 SCTP_TCB_UNLOCK(stcb);
4740 case SCTP_ADD_STREAMS:
4742 struct sctp_add_streams *stradd;
4743 uint8_t addstream = 0;
4744 uint16_t add_o_strmcnt = 0;
4745 uint16_t add_i_strmcnt = 0;
4747 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4748 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4750 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4754 if (stcb->asoc.reconfig_supported == 0) {
4756 * Peer does not support the chunk type.
4758 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4760 SCTP_TCB_UNLOCK(stcb);
4763 if (stcb->asoc.stream_reset_outstanding) {
4764 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4766 SCTP_TCB_UNLOCK(stcb);
4769 if ((stradd->sas_outstrms == 0) &&
4770 (stradd->sas_instrms == 0)) {
4774 if (stradd->sas_outstrms) {
4776 /* We allocate here */
4777 add_o_strmcnt = stradd->sas_outstrms;
4778 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4779 /* You can't have more than 64k */
4784 if (stradd->sas_instrms) {
4789 * We allocate inside
4790 * sctp_send_str_reset_req()
4792 add_i_strmcnt = stradd->sas_instrms;
4793 cnt = add_i_strmcnt;
4794 cnt += stcb->asoc.streamincnt;
4795 if (cnt > 0x0000ffff) {
4796 /* You can't have more than 64k */
4800 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4801 /* More than you are allowed */
4806 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4807 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4809 SCTP_TCB_UNLOCK(stcb);
4812 case SCTP_RESET_ASSOC:
4817 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4818 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4820 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4824 if (stcb->asoc.reconfig_supported == 0) {
4826 * Peer does not support the chunk type.
4828 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4830 SCTP_TCB_UNLOCK(stcb);
4833 if (stcb->asoc.stream_reset_outstanding) {
4834 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4836 SCTP_TCB_UNLOCK(stcb);
4840 * Is there any data pending in the send or sent
4843 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4844 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4847 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4848 SCTP_TCB_UNLOCK(stcb);
4851 /* Do any streams have data queued? */
4852 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4853 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4857 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4858 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4859 SCTP_TCB_UNLOCK(stcb);
4862 case SCTP_CONNECT_X:
4863 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4864 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4868 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4870 case SCTP_CONNECT_X_DELAYED:
4871 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4872 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4876 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4878 case SCTP_CONNECT_X_COMPLETE:
4880 struct sockaddr *sa;
4882 /* FIXME MT: check correct? */
4883 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4886 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4887 SCTP_INP_RLOCK(inp);
4888 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4890 SCTP_TCB_LOCK(stcb);
4892 SCTP_INP_RUNLOCK(inp);
4895 * We increment here since
4896 * sctp_findassociation_ep_addr() wil do a
4897 * decrement if it finds the stcb as long as
4898 * the locked tcb (last argument) is NOT a
4901 SCTP_INP_INCR_REF(inp);
4902 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4904 SCTP_INP_DECR_REF(inp);
4909 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4913 if (stcb->asoc.delayed_connection == 1) {
4914 stcb->asoc.delayed_connection = 0;
4915 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4916 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4917 stcb->asoc.primary_destination,
4918 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4919 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4922 * already expired or did not use delayed
4925 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4928 SCTP_TCB_UNLOCK(stcb);
4931 case SCTP_MAX_BURST:
4933 struct sctp_assoc_value *av;
4935 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4936 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4939 stcb->asoc.max_burst = av->assoc_value;
4940 SCTP_TCB_UNLOCK(stcb);
4942 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4943 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4944 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4945 (av->assoc_id == SCTP_ALL_ASSOC)) {
4946 SCTP_INP_WLOCK(inp);
4947 inp->sctp_ep.max_burst = av->assoc_value;
4948 SCTP_INP_WUNLOCK(inp);
4950 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4951 (av->assoc_id == SCTP_ALL_ASSOC)) {
4952 SCTP_INP_RLOCK(inp);
4953 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4954 SCTP_TCB_LOCK(stcb);
4955 stcb->asoc.max_burst = av->assoc_value;
4956 SCTP_TCB_UNLOCK(stcb);
4958 SCTP_INP_RUNLOCK(inp);
4965 struct sctp_assoc_value *av;
4968 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4969 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4971 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4972 ovh = SCTP_MED_OVERHEAD;
4974 ovh = SCTP_MED_V4_OVERHEAD;
4977 if (av->assoc_value) {
4978 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4980 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4982 SCTP_TCB_UNLOCK(stcb);
4984 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4985 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4986 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4987 SCTP_INP_WLOCK(inp);
4989 * FIXME MT: I think this is not in
4990 * tune with the API ID
4992 if (av->assoc_value) {
4993 inp->sctp_frag_point = (av->assoc_value + ovh);
4995 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4997 SCTP_INP_WUNLOCK(inp);
4999 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5007 struct sctp_event_subscribe *events;
5009 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
5011 SCTP_INP_WLOCK(inp);
5012 if (events->sctp_data_io_event) {
5013 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5015 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5018 if (events->sctp_association_event) {
5019 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5021 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5024 if (events->sctp_address_event) {
5025 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5027 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5030 if (events->sctp_send_failure_event) {
5031 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5033 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5036 if (events->sctp_peer_error_event) {
5037 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5039 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5042 if (events->sctp_shutdown_event) {
5043 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5045 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5048 if (events->sctp_partial_delivery_event) {
5049 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5051 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5054 if (events->sctp_adaptation_layer_event) {
5055 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5057 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5060 if (events->sctp_authentication_event) {
5061 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5063 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5066 if (events->sctp_sender_dry_event) {
5067 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5069 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5072 if (events->sctp_stream_reset_event) {
5073 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5075 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5077 SCTP_INP_WUNLOCK(inp);
5079 SCTP_INP_RLOCK(inp);
5080 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5081 SCTP_TCB_LOCK(stcb);
5082 if (events->sctp_association_event) {
5083 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5085 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5087 if (events->sctp_address_event) {
5088 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5090 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5092 if (events->sctp_send_failure_event) {
5093 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5095 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5097 if (events->sctp_peer_error_event) {
5098 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5100 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5102 if (events->sctp_shutdown_event) {
5103 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5105 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5107 if (events->sctp_partial_delivery_event) {
5108 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5110 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5112 if (events->sctp_adaptation_layer_event) {
5113 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5115 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5117 if (events->sctp_authentication_event) {
5118 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5120 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5122 if (events->sctp_sender_dry_event) {
5123 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5125 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5127 if (events->sctp_stream_reset_event) {
5128 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5130 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5132 SCTP_TCB_UNLOCK(stcb);
5135 * Send up the sender dry event only for 1-to-1
5138 if (events->sctp_sender_dry_event) {
5139 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5140 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5141 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5143 SCTP_TCB_LOCK(stcb);
5144 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5145 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5146 (stcb->asoc.stream_queue_cnt == 0)) {
5147 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5149 SCTP_TCB_UNLOCK(stcb);
5153 SCTP_INP_RUNLOCK(inp);
5156 case SCTP_ADAPTATION_LAYER:
5158 struct sctp_setadaptation *adap_bits;
5160 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5161 SCTP_INP_WLOCK(inp);
5162 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5163 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5164 SCTP_INP_WUNLOCK(inp);
5168 case SCTP_SET_INITIAL_DBG_SEQ:
5172 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5173 SCTP_INP_WLOCK(inp);
5174 inp->sctp_ep.initial_sequence_debug = *vvv;
5175 SCTP_INP_WUNLOCK(inp);
5179 case SCTP_DEFAULT_SEND_PARAM:
5181 struct sctp_sndrcvinfo *s_info;
5183 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5184 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5187 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5188 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5190 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5193 SCTP_TCB_UNLOCK(stcb);
5195 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5196 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5197 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5198 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5199 SCTP_INP_WLOCK(inp);
5200 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5201 SCTP_INP_WUNLOCK(inp);
5203 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5204 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5205 SCTP_INP_RLOCK(inp);
5206 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5207 SCTP_TCB_LOCK(stcb);
5208 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5209 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5211 SCTP_TCB_UNLOCK(stcb);
5213 SCTP_INP_RUNLOCK(inp);
5218 case SCTP_PEER_ADDR_PARAMS:
5220 struct sctp_paddrparams *paddrp;
5221 struct sctp_nets *net;
5222 struct sockaddr *addr;
5224 #if defined(INET) && defined(INET6)
5225 struct sockaddr_in sin_store;
5229 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5230 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5232 #if defined(INET) && defined(INET6)
5233 if (paddrp->spp_address.ss_family == AF_INET6) {
5234 struct sockaddr_in6 *sin6;
5236 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5237 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5238 in6_sin6_2_sin(&sin_store, sin6);
5239 addr = (struct sockaddr *)&sin_store;
5241 addr = (struct sockaddr *)&paddrp->spp_address;
5244 addr = (struct sockaddr *)&paddrp->spp_address;
5247 addr = (struct sockaddr *)&paddrp->spp_address;
5250 net = sctp_findnet(stcb, addr);
5253 * We increment here since
5254 * sctp_findassociation_ep_addr() wil do a
5255 * decrement if it finds the stcb as long as
5256 * the locked tcb (last argument) is NOT a
5260 SCTP_INP_INCR_REF(inp);
5261 stcb = sctp_findassociation_ep_addr(&inp, addr,
5264 SCTP_INP_DECR_REF(inp);
5267 if ((stcb != NULL) && (net == NULL)) {
5269 if (addr->sa_family == AF_INET) {
5271 struct sockaddr_in *sin;
5273 sin = (struct sockaddr_in *)addr;
5274 if (sin->sin_addr.s_addr != INADDR_ANY) {
5275 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5276 SCTP_TCB_UNLOCK(stcb);
5283 if (addr->sa_family == AF_INET6) {
5284 struct sockaddr_in6 *sin6;
5286 sin6 = (struct sockaddr_in6 *)addr;
5287 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5288 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5289 SCTP_TCB_UNLOCK(stcb);
5296 error = EAFNOSUPPORT;
5297 SCTP_TCB_UNLOCK(stcb);
5298 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5303 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5305 SCTP_TCB_UNLOCK(stcb);
5306 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5309 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5311 SCTP_TCB_UNLOCK(stcb);
5312 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5316 /************************TCB SPECIFIC SET ******************/
5318 /************************NET SPECIFIC SET ******************/
5319 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5320 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5321 !(net->dest_state & SCTP_ADDR_NOHB)) {
5322 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5323 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5325 net->dest_state |= SCTP_ADDR_NOHB;
5327 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5328 if (paddrp->spp_hbinterval) {
5329 net->heart_beat_delay = paddrp->spp_hbinterval;
5330 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5331 net->heart_beat_delay = 0;
5333 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5334 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5335 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5336 net->dest_state &= ~SCTP_ADDR_NOHB;
5338 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5340 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5341 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5342 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5344 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5345 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5346 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5347 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5349 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5350 net->mtu = paddrp->spp_pathmtu;
5351 switch (net->ro._l_addr.sa.sa_family) {
5354 net->mtu += SCTP_MIN_V4_OVERHEAD;
5359 net->mtu += SCTP_MIN_OVERHEAD;
5365 if (net->mtu < stcb->asoc.smallest_mtu) {
5366 sctp_pathmtu_adjustment(stcb, net->mtu);
5369 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5370 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5371 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5373 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5375 if (paddrp->spp_pathmaxrxt) {
5376 if (net->dest_state & SCTP_ADDR_PF) {
5377 if (net->error_count > paddrp->spp_pathmaxrxt) {
5378 net->dest_state &= ~SCTP_ADDR_PF;
5381 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5382 (net->error_count > net->pf_threshold)) {
5383 net->dest_state |= SCTP_ADDR_PF;
5384 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5385 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5386 stcb->sctp_ep, stcb, net,
5387 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5388 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5391 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5392 if (net->error_count > paddrp->spp_pathmaxrxt) {
5393 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5394 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5397 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5398 net->dest_state |= SCTP_ADDR_REACHABLE;
5399 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5402 net->failure_threshold = paddrp->spp_pathmaxrxt;
5404 if (paddrp->spp_flags & SPP_DSCP) {
5405 net->dscp = paddrp->spp_dscp & 0xfc;
5409 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5410 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5411 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5412 net->flowlabel |= 0x80000000;
5417 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5418 if (paddrp->spp_pathmaxrxt != 0) {
5419 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5420 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5421 if (net->dest_state & SCTP_ADDR_PF) {
5422 if (net->error_count > paddrp->spp_pathmaxrxt) {
5423 net->dest_state &= ~SCTP_ADDR_PF;
5426 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5427 (net->error_count > net->pf_threshold)) {
5428 net->dest_state |= SCTP_ADDR_PF;
5429 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5430 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5431 stcb->sctp_ep, stcb, net,
5432 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5433 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5436 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5437 if (net->error_count > paddrp->spp_pathmaxrxt) {
5438 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5439 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5442 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5443 net->dest_state |= SCTP_ADDR_REACHABLE;
5444 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5447 net->failure_threshold = paddrp->spp_pathmaxrxt;
5450 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5451 if (paddrp->spp_hbinterval != 0) {
5452 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5453 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5454 stcb->asoc.heart_beat_delay = 0;
5456 /* Turn back on the timer */
5457 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5458 if (paddrp->spp_hbinterval != 0) {
5459 net->heart_beat_delay = paddrp->spp_hbinterval;
5460 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5461 net->heart_beat_delay = 0;
5463 if (net->dest_state & SCTP_ADDR_NOHB) {
5464 net->dest_state &= ~SCTP_ADDR_NOHB;
5466 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5467 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5468 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5470 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5472 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5473 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5474 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5475 net->dest_state |= SCTP_ADDR_NOHB;
5476 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5477 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5479 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5483 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5485 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5486 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5487 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5488 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5489 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5491 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5492 net->mtu = paddrp->spp_pathmtu;
5493 switch (net->ro._l_addr.sa.sa_family) {
5496 net->mtu += SCTP_MIN_V4_OVERHEAD;
5501 net->mtu += SCTP_MIN_OVERHEAD;
5507 if (net->mtu < stcb->asoc.smallest_mtu) {
5508 sctp_pathmtu_adjustment(stcb, net->mtu);
5511 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5513 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5514 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5515 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5516 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5518 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5520 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5522 if (paddrp->spp_flags & SPP_DSCP) {
5523 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5524 net->dscp = paddrp->spp_dscp & 0xfc;
5527 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5528 stcb->asoc.default_dscp |= 0x01;
5531 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5532 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5533 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5534 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5535 net->flowlabel |= 0x80000000;
5538 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5539 stcb->asoc.default_flowlabel |= 0x80000000;
5543 SCTP_TCB_UNLOCK(stcb);
5545 /************************NO TCB, SET TO default stuff ******************/
5546 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5547 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5548 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5549 SCTP_INP_WLOCK(inp);
5551 * For the TOS/FLOWLABEL stuff you
5552 * set it with the options on the
5555 if (paddrp->spp_pathmaxrxt != 0) {
5556 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5558 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5559 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5560 else if (paddrp->spp_hbinterval != 0) {
5561 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5562 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5563 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5565 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5566 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5567 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5568 } else if (paddrp->spp_hbinterval) {
5569 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5571 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5572 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5573 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5575 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5576 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5577 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5578 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5580 if (paddrp->spp_flags & SPP_DSCP) {
5581 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5582 inp->sctp_ep.default_dscp |= 0x01;
5585 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5586 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5587 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5588 inp->sctp_ep.default_flowlabel |= 0x80000000;
5592 SCTP_INP_WUNLOCK(inp);
5594 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5602 struct sctp_rtoinfo *srto;
5603 uint32_t new_init, new_min, new_max;
5605 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5606 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5609 if (srto->srto_initial)
5610 new_init = srto->srto_initial;
5612 new_init = stcb->asoc.initial_rto;
5614 new_max = srto->srto_max;
5616 new_max = stcb->asoc.maxrto;
5618 new_min = srto->srto_min;
5620 new_min = stcb->asoc.minrto;
5621 if ((new_min <= new_init) && (new_init <= new_max)) {
5622 stcb->asoc.initial_rto = new_init;
5623 stcb->asoc.maxrto = new_max;
5624 stcb->asoc.minrto = new_min;
5626 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5629 SCTP_TCB_UNLOCK(stcb);
5631 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5632 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5633 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5634 SCTP_INP_WLOCK(inp);
5635 if (srto->srto_initial)
5636 new_init = srto->srto_initial;
5638 new_init = inp->sctp_ep.initial_rto;
5640 new_max = srto->srto_max;
5642 new_max = inp->sctp_ep.sctp_maxrto;
5644 new_min = srto->srto_min;
5646 new_min = inp->sctp_ep.sctp_minrto;
5647 if ((new_min <= new_init) && (new_init <= new_max)) {
5648 inp->sctp_ep.initial_rto = new_init;
5649 inp->sctp_ep.sctp_maxrto = new_max;
5650 inp->sctp_ep.sctp_minrto = new_min;
5652 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5655 SCTP_INP_WUNLOCK(inp);
5657 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5663 case SCTP_ASSOCINFO:
5665 struct sctp_assocparams *sasoc;
5667 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5668 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5669 if (sasoc->sasoc_cookie_life) {
5670 /* boundary check the cookie life */
5671 if (sasoc->sasoc_cookie_life < 1000)
5672 sasoc->sasoc_cookie_life = 1000;
5673 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5674 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5678 if (sasoc->sasoc_asocmaxrxt)
5679 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5680 if (sasoc->sasoc_cookie_life) {
5681 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5683 SCTP_TCB_UNLOCK(stcb);
5685 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5686 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5687 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5688 SCTP_INP_WLOCK(inp);
5689 if (sasoc->sasoc_asocmaxrxt)
5690 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5691 if (sasoc->sasoc_cookie_life) {
5692 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5694 SCTP_INP_WUNLOCK(inp);
5696 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5704 struct sctp_initmsg *sinit;
5706 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5707 SCTP_INP_WLOCK(inp);
5708 if (sinit->sinit_num_ostreams)
5709 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5711 if (sinit->sinit_max_instreams)
5712 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5714 if (sinit->sinit_max_attempts)
5715 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5717 if (sinit->sinit_max_init_timeo)
5718 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5719 SCTP_INP_WUNLOCK(inp);
5722 case SCTP_PRIMARY_ADDR:
5724 struct sctp_setprim *spa;
5725 struct sctp_nets *net;
5726 struct sockaddr *addr;
5728 #if defined(INET) && defined(INET6)
5729 struct sockaddr_in sin_store;
5733 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5734 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5736 #if defined(INET) && defined(INET6)
5737 if (spa->ssp_addr.ss_family == AF_INET6) {
5738 struct sockaddr_in6 *sin6;
5740 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5741 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5742 in6_sin6_2_sin(&sin_store, sin6);
5743 addr = (struct sockaddr *)&sin_store;
5745 addr = (struct sockaddr *)&spa->ssp_addr;
5748 addr = (struct sockaddr *)&spa->ssp_addr;
5751 addr = (struct sockaddr *)&spa->ssp_addr;
5754 net = sctp_findnet(stcb, addr);
5757 * We increment here since
5758 * sctp_findassociation_ep_addr() wil do a
5759 * decrement if it finds the stcb as long as
5760 * the locked tcb (last argument) is NOT a
5764 SCTP_INP_INCR_REF(inp);
5765 stcb = sctp_findassociation_ep_addr(&inp, addr,
5768 SCTP_INP_DECR_REF(inp);
5772 if ((stcb != NULL) && (net != NULL)) {
5773 if (net != stcb->asoc.primary_destination) {
5774 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5775 /* Ok we need to set it */
5776 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5777 if ((stcb->asoc.alternate) &&
5778 (!(net->dest_state & SCTP_ADDR_PF)) &&
5779 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5780 sctp_free_remote_addr(stcb->asoc.alternate);
5781 stcb->asoc.alternate = NULL;
5784 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);
5793 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5797 SCTP_TCB_UNLOCK(stcb);
5801 case SCTP_SET_DYNAMIC_PRIMARY:
5803 union sctp_sockstore *ss;
5805 error = priv_check(curthread,
5806 PRIV_NETINET_RESERVEDPORT);
5810 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5811 /* SUPER USER CHECK? */
5812 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5815 case SCTP_SET_PEER_PRIMARY_ADDR:
5817 struct sctp_setpeerprim *sspp;
5818 struct sockaddr *addr;
5820 #if defined(INET) && defined(INET6)
5821 struct sockaddr_in sin_store;
5825 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5826 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5828 struct sctp_ifa *ifa;
5830 #if defined(INET) && defined(INET6)
5831 if (sspp->sspp_addr.ss_family == AF_INET6) {
5832 struct sockaddr_in6 *sin6;
5834 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5835 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5836 in6_sin6_2_sin(&sin_store, sin6);
5837 addr = (struct sockaddr *)&sin_store;
5839 addr = (struct sockaddr *)&sspp->sspp_addr;
5842 addr = (struct sockaddr *)&sspp->sspp_addr;
5845 addr = (struct sockaddr *)&sspp->sspp_addr;
5847 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5849 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5853 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5855 * Must validate the ifa found is in
5858 struct sctp_laddr *laddr;
5861 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5862 if (laddr->ifa == NULL) {
5863 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5867 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5868 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5871 if (laddr->ifa == ifa) {
5877 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5882 switch (addr->sa_family) {
5886 struct sockaddr_in *sin;
5888 sin = (struct sockaddr_in *)addr;
5889 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5890 &sin->sin_addr) != 0) {
5891 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5901 struct sockaddr_in6 *sin6;
5903 sin6 = (struct sockaddr_in6 *)addr;
5904 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5905 &sin6->sin6_addr) != 0) {
5906 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5914 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5919 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5920 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5923 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5925 SCTP_TCB_UNLOCK(stcb);
5927 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5932 case SCTP_BINDX_ADD_ADDR:
5934 struct sctp_getaddresses *addrs;
5937 td = (struct thread *)p;
5938 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5941 if (addrs->addr->sa_family == AF_INET) {
5942 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5943 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5947 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5948 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5954 if (addrs->addr->sa_family == AF_INET6) {
5955 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5956 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5960 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5961 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5962 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5968 error = EAFNOSUPPORT;
5971 sctp_bindx_add_address(so, inp, addrs->addr,
5972 addrs->sget_assoc_id, vrf_id,
5976 case SCTP_BINDX_REM_ADDR:
5978 struct sctp_getaddresses *addrs;
5981 td = (struct thread *)p;
5983 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5985 if (addrs->addr->sa_family == AF_INET) {
5986 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5987 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5991 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5992 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5998 if (addrs->addr->sa_family == AF_INET6) {
5999 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
6000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6005 (error = prison_local_ip6(td->td_ucred,
6006 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
6007 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6008 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6014 error = EAFNOSUPPORT;
6017 sctp_bindx_delete_address(inp, addrs->addr,
6018 addrs->sget_assoc_id, vrf_id,
6024 struct sctp_event *event;
6025 uint32_t event_type;
6027 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6028 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6029 switch (event->se_type) {
6030 case SCTP_ASSOC_CHANGE:
6031 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6033 case SCTP_PEER_ADDR_CHANGE:
6034 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6036 case SCTP_REMOTE_ERROR:
6037 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6039 case SCTP_SEND_FAILED:
6040 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6042 case SCTP_SHUTDOWN_EVENT:
6043 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6045 case SCTP_ADAPTATION_INDICATION:
6046 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6048 case SCTP_PARTIAL_DELIVERY_EVENT:
6049 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6051 case SCTP_AUTHENTICATION_EVENT:
6052 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6054 case SCTP_STREAM_RESET_EVENT:
6055 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6057 case SCTP_SENDER_DRY_EVENT:
6058 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6060 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6062 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6065 case SCTP_ASSOC_RESET_EVENT:
6066 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6068 case SCTP_STREAM_CHANGE_EVENT:
6069 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6071 case SCTP_SEND_FAILED_EVENT:
6072 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6076 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6080 if (event_type > 0) {
6083 sctp_stcb_feature_on(inp, stcb, event_type);
6084 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6085 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6086 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6087 (stcb->asoc.stream_queue_cnt == 0)) {
6088 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6092 sctp_stcb_feature_off(inp, stcb, event_type);
6094 SCTP_TCB_UNLOCK(stcb);
6097 * We don't want to send up a storm
6098 * of events, so return an error for
6101 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6102 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6103 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6104 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6105 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6106 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6110 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6111 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6112 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6113 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6114 SCTP_INP_WLOCK(inp);
6116 sctp_feature_on(inp, event_type);
6118 sctp_feature_off(inp, event_type);
6120 SCTP_INP_WUNLOCK(inp);
6122 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6123 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6124 SCTP_INP_RLOCK(inp);
6125 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6126 SCTP_TCB_LOCK(stcb);
6128 sctp_stcb_feature_on(inp, stcb, event_type);
6130 sctp_stcb_feature_off(inp, stcb, event_type);
6132 SCTP_TCB_UNLOCK(stcb);
6134 SCTP_INP_RUNLOCK(inp);
6140 case SCTP_RECVRCVINFO:
6144 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6145 SCTP_INP_WLOCK(inp);
6147 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6149 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6151 SCTP_INP_WUNLOCK(inp);
6154 case SCTP_RECVNXTINFO:
6158 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6159 SCTP_INP_WLOCK(inp);
6161 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6163 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6165 SCTP_INP_WUNLOCK(inp);
6168 case SCTP_DEFAULT_SNDINFO:
6170 struct sctp_sndinfo *info;
6173 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6174 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6177 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6178 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6179 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6180 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6181 stcb->asoc.def_send.sinfo_flags |= policy;
6182 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6183 stcb->asoc.def_send.sinfo_context = info->snd_context;
6185 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6188 SCTP_TCB_UNLOCK(stcb);
6190 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6191 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6192 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6193 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6194 SCTP_INP_WLOCK(inp);
6195 inp->def_send.sinfo_stream = info->snd_sid;
6196 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6197 inp->def_send.sinfo_flags = info->snd_flags;
6198 inp->def_send.sinfo_flags |= policy;
6199 inp->def_send.sinfo_ppid = info->snd_ppid;
6200 inp->def_send.sinfo_context = info->snd_context;
6201 SCTP_INP_WUNLOCK(inp);
6203 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6204 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6205 SCTP_INP_RLOCK(inp);
6206 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6207 SCTP_TCB_LOCK(stcb);
6208 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6209 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6210 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6211 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6212 stcb->asoc.def_send.sinfo_flags |= policy;
6213 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6214 stcb->asoc.def_send.sinfo_context = info->snd_context;
6216 SCTP_TCB_UNLOCK(stcb);
6218 SCTP_INP_RUNLOCK(inp);
6223 case SCTP_DEFAULT_PRINFO:
6225 struct sctp_default_prinfo *info;
6227 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6228 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6230 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6231 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6236 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6237 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6238 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6239 SCTP_TCB_UNLOCK(stcb);
6241 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6242 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6243 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6244 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6245 SCTP_INP_WLOCK(inp);
6246 inp->def_send.sinfo_flags &= 0xfff0;
6247 inp->def_send.sinfo_flags |= info->pr_policy;
6248 inp->def_send.sinfo_timetolive = info->pr_value;
6249 SCTP_INP_WUNLOCK(inp);
6251 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6252 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6253 SCTP_INP_RLOCK(inp);
6254 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6255 SCTP_TCB_LOCK(stcb);
6256 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6257 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6258 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6259 SCTP_TCB_UNLOCK(stcb);
6261 SCTP_INP_RUNLOCK(inp);
6266 case SCTP_PEER_ADDR_THLDS:
6267 /* Applies to the specific association */
6269 struct sctp_paddrthlds *thlds;
6270 struct sctp_nets *net;
6271 struct sockaddr *addr;
6273 #if defined(INET) && defined(INET6)
6274 struct sockaddr_in sin_store;
6278 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6279 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6281 #if defined(INET) && defined(INET6)
6282 if (thlds->spt_address.ss_family == AF_INET6) {
6283 struct sockaddr_in6 *sin6;
6285 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6286 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6287 in6_sin6_2_sin(&sin_store, sin6);
6288 addr = (struct sockaddr *)&sin_store;
6290 addr = (struct sockaddr *)&thlds->spt_address;
6293 addr = (struct sockaddr *)&thlds->spt_address;
6296 addr = (struct sockaddr *)&thlds->spt_address;
6299 net = sctp_findnet(stcb, addr);
6302 * We increment here since
6303 * sctp_findassociation_ep_addr() wil do a
6304 * decrement if it finds the stcb as long as
6305 * the locked tcb (last argument) is NOT a
6309 SCTP_INP_INCR_REF(inp);
6310 stcb = sctp_findassociation_ep_addr(&inp, addr,
6313 SCTP_INP_DECR_REF(inp);
6316 if ((stcb != NULL) && (net == NULL)) {
6318 if (addr->sa_family == AF_INET) {
6320 struct sockaddr_in *sin;
6322 sin = (struct sockaddr_in *)addr;
6323 if (sin->sin_addr.s_addr != INADDR_ANY) {
6324 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6325 SCTP_TCB_UNLOCK(stcb);
6332 if (addr->sa_family == AF_INET6) {
6333 struct sockaddr_in6 *sin6;
6335 sin6 = (struct sockaddr_in6 *)addr;
6336 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6337 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6338 SCTP_TCB_UNLOCK(stcb);
6345 error = EAFNOSUPPORT;
6346 SCTP_TCB_UNLOCK(stcb);
6347 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6351 if (thlds->spt_pathcpthld != 0xffff) {
6353 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6358 net->failure_threshold = thlds->spt_pathmaxrxt;
6359 net->pf_threshold = thlds->spt_pathpfthld;
6360 if (net->dest_state & SCTP_ADDR_PF) {
6361 if ((net->error_count > net->failure_threshold) ||
6362 (net->error_count <= net->pf_threshold)) {
6363 net->dest_state &= ~SCTP_ADDR_PF;
6366 if ((net->error_count > net->pf_threshold) &&
6367 (net->error_count <= net->failure_threshold)) {
6368 net->dest_state |= SCTP_ADDR_PF;
6369 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6370 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6371 stcb->sctp_ep, stcb, net,
6372 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6373 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6376 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6377 if (net->error_count > net->failure_threshold) {
6378 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6379 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6382 if (net->error_count <= net->failure_threshold) {
6383 net->dest_state |= SCTP_ADDR_REACHABLE;
6384 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6388 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6389 net->failure_threshold = thlds->spt_pathmaxrxt;
6390 net->pf_threshold = thlds->spt_pathpfthld;
6391 if (net->dest_state & SCTP_ADDR_PF) {
6392 if ((net->error_count > net->failure_threshold) ||
6393 (net->error_count <= net->pf_threshold)) {
6394 net->dest_state &= ~SCTP_ADDR_PF;
6397 if ((net->error_count > net->pf_threshold) &&
6398 (net->error_count <= net->failure_threshold)) {
6399 net->dest_state |= SCTP_ADDR_PF;
6400 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6401 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6402 stcb->sctp_ep, stcb, net,
6403 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6404 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6407 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6408 if (net->error_count > net->failure_threshold) {
6409 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6410 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6413 if (net->error_count <= net->failure_threshold) {
6414 net->dest_state |= SCTP_ADDR_REACHABLE;
6415 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6419 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6420 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6422 SCTP_TCB_UNLOCK(stcb);
6424 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6425 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6426 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6427 SCTP_INP_WLOCK(inp);
6428 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6429 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6430 SCTP_INP_WUNLOCK(inp);
6432 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6438 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6440 struct sctp_udpencaps *encaps;
6441 struct sctp_nets *net;
6442 struct sockaddr *addr;
6444 #if defined(INET) && defined(INET6)
6445 struct sockaddr_in sin_store;
6449 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6450 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6452 #if defined(INET) && defined(INET6)
6453 if (encaps->sue_address.ss_family == AF_INET6) {
6454 struct sockaddr_in6 *sin6;
6456 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6457 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6458 in6_sin6_2_sin(&sin_store, sin6);
6459 addr = (struct sockaddr *)&sin_store;
6461 addr = (struct sockaddr *)&encaps->sue_address;
6464 addr = (struct sockaddr *)&encaps->sue_address;
6467 addr = (struct sockaddr *)&encaps->sue_address;
6470 net = sctp_findnet(stcb, addr);
6473 * We increment here since
6474 * sctp_findassociation_ep_addr() wil do a
6475 * decrement if it finds the stcb as long as
6476 * the locked tcb (last argument) is NOT a
6480 SCTP_INP_INCR_REF(inp);
6481 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6483 SCTP_INP_DECR_REF(inp);
6486 if ((stcb != NULL) && (net == NULL)) {
6488 if (addr->sa_family == AF_INET) {
6490 struct sockaddr_in *sin;
6492 sin = (struct sockaddr_in *)addr;
6493 if (sin->sin_addr.s_addr != INADDR_ANY) {
6494 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6495 SCTP_TCB_UNLOCK(stcb);
6502 if (addr->sa_family == AF_INET6) {
6503 struct sockaddr_in6 *sin6;
6505 sin6 = (struct sockaddr_in6 *)addr;
6506 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6507 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6508 SCTP_TCB_UNLOCK(stcb);
6515 error = EAFNOSUPPORT;
6516 SCTP_TCB_UNLOCK(stcb);
6517 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6523 net->port = encaps->sue_port;
6525 stcb->asoc.port = encaps->sue_port;
6527 SCTP_TCB_UNLOCK(stcb);
6529 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6530 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6531 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6532 SCTP_INP_WLOCK(inp);
6533 inp->sctp_ep.port = encaps->sue_port;
6534 SCTP_INP_WUNLOCK(inp);
6536 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6542 case SCTP_ECN_SUPPORTED:
6544 struct sctp_assoc_value *av;
6546 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6547 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6550 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6552 SCTP_TCB_UNLOCK(stcb);
6554 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6555 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6556 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6557 SCTP_INP_WLOCK(inp);
6558 if (av->assoc_value == 0) {
6559 inp->ecn_supported = 0;
6561 inp->ecn_supported = 1;
6563 SCTP_INP_WUNLOCK(inp);
6565 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6571 case SCTP_PR_SUPPORTED:
6573 struct sctp_assoc_value *av;
6575 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6576 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6579 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6581 SCTP_TCB_UNLOCK(stcb);
6583 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6584 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6585 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6586 SCTP_INP_WLOCK(inp);
6587 if (av->assoc_value == 0) {
6588 inp->prsctp_supported = 0;
6590 inp->prsctp_supported = 1;
6592 SCTP_INP_WUNLOCK(inp);
6594 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6600 case SCTP_AUTH_SUPPORTED:
6602 struct sctp_assoc_value *av;
6604 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6605 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6608 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6610 SCTP_TCB_UNLOCK(stcb);
6612 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6613 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6614 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6615 if ((av->assoc_value == 0) &&
6616 (inp->asconf_supported == 1)) {
6618 * AUTH is required for
6621 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6624 SCTP_INP_WLOCK(inp);
6625 if (av->assoc_value == 0) {
6626 inp->auth_supported = 0;
6628 inp->auth_supported = 1;
6630 SCTP_INP_WUNLOCK(inp);
6633 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6639 case SCTP_ASCONF_SUPPORTED:
6641 struct sctp_assoc_value *av;
6643 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6644 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6647 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6649 SCTP_TCB_UNLOCK(stcb);
6651 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6652 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6653 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6654 if ((av->assoc_value != 0) &&
6655 (inp->auth_supported == 0)) {
6657 * AUTH is required for
6660 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6663 SCTP_INP_WLOCK(inp);
6664 if (av->assoc_value == 0) {
6665 inp->asconf_supported = 0;
6666 sctp_auth_delete_chunk(SCTP_ASCONF,
6667 inp->sctp_ep.local_auth_chunks);
6668 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6669 inp->sctp_ep.local_auth_chunks);
6671 inp->asconf_supported = 1;
6672 sctp_auth_add_chunk(SCTP_ASCONF,
6673 inp->sctp_ep.local_auth_chunks);
6674 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6675 inp->sctp_ep.local_auth_chunks);
6677 SCTP_INP_WUNLOCK(inp);
6680 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6686 case SCTP_RECONFIG_SUPPORTED:
6688 struct sctp_assoc_value *av;
6690 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6691 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6694 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6696 SCTP_TCB_UNLOCK(stcb);
6698 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6699 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6700 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6701 SCTP_INP_WLOCK(inp);
6702 if (av->assoc_value == 0) {
6703 inp->reconfig_supported = 0;
6705 inp->reconfig_supported = 1;
6707 SCTP_INP_WUNLOCK(inp);
6709 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6715 case SCTP_NRSACK_SUPPORTED:
6717 struct sctp_assoc_value *av;
6719 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6720 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6723 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6725 SCTP_TCB_UNLOCK(stcb);
6727 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6728 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6729 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6730 SCTP_INP_WLOCK(inp);
6731 if (av->assoc_value == 0) {
6732 inp->nrsack_supported = 0;
6734 inp->nrsack_supported = 1;
6736 SCTP_INP_WUNLOCK(inp);
6738 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6744 case SCTP_PKTDROP_SUPPORTED:
6746 struct sctp_assoc_value *av;
6748 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6749 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6752 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6754 SCTP_TCB_UNLOCK(stcb);
6756 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6757 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6758 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6759 SCTP_INP_WLOCK(inp);
6760 if (av->assoc_value == 0) {
6761 inp->pktdrop_supported = 0;
6763 inp->pktdrop_supported = 1;
6765 SCTP_INP_WUNLOCK(inp);
6767 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6775 struct sctp_assoc_value *av;
6776 struct sctp_nets *net;
6778 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6779 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6782 stcb->asoc.max_cwnd = av->assoc_value;
6783 if (stcb->asoc.max_cwnd > 0) {
6784 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6785 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6786 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6787 net->cwnd = stcb->asoc.max_cwnd;
6788 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6789 net->cwnd = net->mtu - sizeof(struct sctphdr);
6794 SCTP_TCB_UNLOCK(stcb);
6796 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6797 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6798 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6799 SCTP_INP_WLOCK(inp);
6800 inp->max_cwnd = av->assoc_value;
6801 SCTP_INP_WUNLOCK(inp);
6803 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6810 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6811 error = ENOPROTOOPT;
6813 } /* end switch (opt) */
6818 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6820 void *optval = NULL;
6824 struct sctp_inpcb *inp;
6826 if ((sopt->sopt_level == SOL_SOCKET) &&
6827 (sopt->sopt_name == SO_SETFIB)) {
6828 inp = (struct sctp_inpcb *)so->so_pcb;
6830 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6833 SCTP_INP_WLOCK(inp);
6834 inp->fibnum = so->so_fibnum;
6835 SCTP_INP_WUNLOCK(inp);
6838 if (sopt->sopt_level != IPPROTO_SCTP) {
6839 /* wrong proto level... send back up to IP */
6841 if (INP_CHECK_SOCKAF(so, AF_INET6))
6842 error = ip6_ctloutput(so, sopt);
6844 #if defined(INET) && defined(INET6)
6848 error = ip_ctloutput(so, sopt);
6852 optsize = sopt->sopt_valsize;
6854 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6855 if (optval == NULL) {
6856 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6859 error = sooptcopyin(sopt, optval, optsize, optsize);
6861 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6865 p = (void *)sopt->sopt_td;
6866 if (sopt->sopt_dir == SOPT_SET) {
6867 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6868 } else if (sopt->sopt_dir == SOPT_GET) {
6869 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6871 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6874 if ((error == 0) && (optval != NULL)) {
6875 error = sooptcopyout(sopt, optval, optsize);
6876 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6877 } else if (optval != NULL) {
6878 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6886 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6889 int create_lock_on = 0;
6891 struct sctp_inpcb *inp;
6892 struct sctp_tcb *stcb = NULL;
6894 inp = (struct sctp_inpcb *)so->so_pcb;
6896 /* I made the same as TCP since we are not setup? */
6897 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6898 return (ECONNRESET);
6901 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6904 switch (addr->sa_family) {
6908 struct sockaddr_in6 *sin6p;
6910 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6911 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6914 sin6p = (struct sockaddr_in6 *)addr;
6915 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6916 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6925 struct sockaddr_in *sinp;
6927 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6928 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6931 sinp = (struct sockaddr_in *)addr;
6932 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6933 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6940 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6941 return (EAFNOSUPPORT);
6943 SCTP_INP_INCR_REF(inp);
6944 SCTP_ASOC_CREATE_LOCK(inp);
6948 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6949 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6950 /* Should I really unlock ? */
6951 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6956 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6957 (addr->sa_family == AF_INET6)) {
6958 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6963 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6964 SCTP_PCB_FLAGS_UNBOUND) {
6965 /* Bind a ephemeral port */
6966 error = sctp_inpcb_bind(so, NULL, NULL, p);
6971 /* Now do we connect? */
6972 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6973 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6974 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6978 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6979 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6980 /* We are already connected AND the TCP model */
6981 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6985 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6986 SCTP_INP_RLOCK(inp);
6987 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6988 SCTP_INP_RUNLOCK(inp);
6991 * We increment here since sctp_findassociation_ep_addr()
6992 * will do a decrement if it finds the stcb as long as the
6993 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6995 SCTP_INP_INCR_REF(inp);
6996 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6998 SCTP_INP_DECR_REF(inp);
7000 SCTP_TCB_UNLOCK(stcb);
7004 /* Already have or am bring up an association */
7005 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7009 vrf_id = inp->def_vrf_id;
7010 /* We are GOOD to go */
7011 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
7012 inp->sctp_ep.pre_open_stream_count,
7013 inp->sctp_ep.port, p);
7015 /* Gak! no memory */
7018 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
7019 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
7020 /* Set the connected flag so we can queue data */
7023 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
7024 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7026 /* initialize authentication parameters for the assoc */
7027 sctp_initialize_auth_params(inp, stcb);
7029 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7030 SCTP_TCB_UNLOCK(stcb);
7032 if (create_lock_on) {
7033 SCTP_ASOC_CREATE_UNLOCK(inp);
7035 SCTP_INP_DECR_REF(inp);
7042 sctp_listen(struct socket *so, int backlog, struct thread *p)
7045 * Note this module depends on the protocol processing being called
7046 * AFTER any socket level flags and backlog are applied to the
7047 * socket. The traditional way that the socket flags are applied is
7048 * AFTER protocol processing. We have made a change to the
7049 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7050 * place if the socket API for SCTP is to work properly.
7054 struct sctp_inpcb *inp;
7056 inp = (struct sctp_inpcb *)so->so_pcb;
7058 /* I made the same as TCP since we are not setup? */
7059 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7060 return (ECONNRESET);
7062 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7063 /* See if we have a listener */
7064 struct sctp_inpcb *tinp;
7065 union sctp_sockstore store;
7067 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7069 struct sctp_laddr *laddr;
7071 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7072 memcpy(&store, &laddr->ifa->address, sizeof(store));
7073 switch (store.sa.sa_family) {
7076 store.sin.sin_port = inp->sctp_lport;
7081 store.sin6.sin6_port = inp->sctp_lport;
7087 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7088 if (tinp && (tinp != inp) &&
7089 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7090 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7091 (tinp->sctp_socket->so_qlimit)) {
7093 * we have a listener already and
7096 SCTP_INP_DECR_REF(tinp);
7097 return (EADDRINUSE);
7099 SCTP_INP_DECR_REF(tinp);
7103 /* Setup a local addr bound all */
7104 memset(&store, 0, sizeof(store));
7106 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7107 store.sa.sa_family = AF_INET6;
7108 store.sa.sa_len = sizeof(struct sockaddr_in6);
7112 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7113 store.sa.sa_family = AF_INET;
7114 store.sa.sa_len = sizeof(struct sockaddr_in);
7117 switch (store.sa.sa_family) {
7120 store.sin.sin_port = inp->sctp_lport;
7125 store.sin6.sin6_port = inp->sctp_lport;
7131 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7132 if (tinp && (tinp != inp) &&
7133 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7134 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7135 (tinp->sctp_socket->so_qlimit)) {
7137 * we have a listener already and its not
7140 SCTP_INP_DECR_REF(tinp);
7141 return (EADDRINUSE);
7143 SCTP_INP_DECR_REF(tinp);
7147 SCTP_INP_RLOCK(inp);
7148 #ifdef SCTP_LOCK_LOGGING
7149 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7150 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7154 error = solisten_proto_check(so);
7157 SCTP_INP_RUNLOCK(inp);
7160 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7161 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7163 * The unlucky case - We are in the tcp pool with this guy.
7164 * - Someone else is in the main inp slot. - We must move
7165 * this guy (the listener) to the main slot - We must then
7166 * move the guy that was listener to the TCP Pool.
7168 if (sctp_swap_inpcb_for_listen(inp)) {
7169 SCTP_INP_RUNLOCK(inp);
7170 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7171 return (EADDRINUSE);
7174 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7175 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7176 /* We are already connected AND the TCP model */
7177 SCTP_INP_RUNLOCK(inp);
7178 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7179 return (EADDRINUSE);
7181 SCTP_INP_RUNLOCK(inp);
7182 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7183 /* We must do a bind. */
7184 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7185 /* bind error, probably perm */
7190 /* It appears for 7.0 and on, we must always call this. */
7191 solisten_proto(so, backlog);
7192 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7193 /* remove the ACCEPTCONN flag for one-to-many sockets */
7194 so->so_options &= ~SO_ACCEPTCONN;
7197 /* turning off listen */
7198 so->so_options &= ~SO_ACCEPTCONN;
7204 static int sctp_defered_wakeup_cnt = 0;
7207 sctp_accept(struct socket *so, struct sockaddr **addr)
7209 struct sctp_tcb *stcb;
7210 struct sctp_inpcb *inp;
7211 union sctp_sockstore store;
7217 inp = (struct sctp_inpcb *)so->so_pcb;
7220 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7221 return (ECONNRESET);
7223 SCTP_INP_RLOCK(inp);
7224 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7225 SCTP_INP_RUNLOCK(inp);
7226 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7227 return (EOPNOTSUPP);
7229 if (so->so_state & SS_ISDISCONNECTED) {
7230 SCTP_INP_RUNLOCK(inp);
7231 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7232 return (ECONNABORTED);
7234 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7236 SCTP_INP_RUNLOCK(inp);
7237 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7238 return (ECONNRESET);
7240 SCTP_TCB_LOCK(stcb);
7241 SCTP_INP_RUNLOCK(inp);
7242 store = stcb->asoc.primary_destination->ro._l_addr;
7243 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
7244 SCTP_TCB_UNLOCK(stcb);
7245 switch (store.sa.sa_family) {
7249 struct sockaddr_in *sin;
7251 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7254 sin->sin_family = AF_INET;
7255 sin->sin_len = sizeof(*sin);
7256 sin->sin_port = store.sin.sin_port;
7257 sin->sin_addr = store.sin.sin_addr;
7258 *addr = (struct sockaddr *)sin;
7265 struct sockaddr_in6 *sin6;
7267 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7270 sin6->sin6_family = AF_INET6;
7271 sin6->sin6_len = sizeof(*sin6);
7272 sin6->sin6_port = store.sin6.sin6_port;
7273 sin6->sin6_addr = store.sin6.sin6_addr;
7274 if ((error = sa6_recoverscope(sin6)) != 0) {
7275 SCTP_FREE_SONAME(sin6);
7278 *addr = (struct sockaddr *)sin6;
7286 /* Wake any delayed sleep action */
7287 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7288 SCTP_INP_WLOCK(inp);
7289 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7290 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7291 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7292 SCTP_INP_WUNLOCK(inp);
7293 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7294 if (sowriteable(inp->sctp_socket)) {
7295 sowwakeup_locked(inp->sctp_socket);
7297 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7299 SCTP_INP_WLOCK(inp);
7301 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7302 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7303 SCTP_INP_WUNLOCK(inp);
7304 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7305 if (soreadable(inp->sctp_socket)) {
7306 sctp_defered_wakeup_cnt++;
7307 sorwakeup_locked(inp->sctp_socket);
7309 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7311 SCTP_INP_WLOCK(inp);
7313 SCTP_INP_WUNLOCK(inp);
7315 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7316 SCTP_TCB_LOCK(stcb);
7317 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7318 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7325 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7327 struct sockaddr_in *sin;
7329 struct sctp_inpcb *inp;
7330 struct sctp_ifa *sctp_ifa;
7333 * Do the malloc first in case it blocks.
7335 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7338 sin->sin_family = AF_INET;
7339 sin->sin_len = sizeof(*sin);
7340 inp = (struct sctp_inpcb *)so->so_pcb;
7342 SCTP_FREE_SONAME(sin);
7343 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7344 return (ECONNRESET);
7346 SCTP_INP_RLOCK(inp);
7347 sin->sin_port = inp->sctp_lport;
7348 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7349 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7350 struct sctp_tcb *stcb;
7351 struct sockaddr_in *sin_a;
7352 struct sctp_nets *net;
7355 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7361 SCTP_TCB_LOCK(stcb);
7362 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7363 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7365 /* this will make coverity happy */
7368 if (sin_a->sin_family == AF_INET) {
7373 if ((!fnd) || (sin_a == NULL)) {
7375 SCTP_TCB_UNLOCK(stcb);
7378 vrf_id = inp->def_vrf_id;
7379 sctp_ifa = sctp_source_address_selection(inp,
7381 (sctp_route_t *) & net->ro,
7384 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7385 sctp_free_ifa(sctp_ifa);
7387 SCTP_TCB_UNLOCK(stcb);
7389 /* For the bound all case you get back 0 */
7391 sin->sin_addr.s_addr = 0;
7395 /* Take the first IPv4 address in the list */
7396 struct sctp_laddr *laddr;
7399 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7400 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7401 struct sockaddr_in *sin_a;
7403 sin_a = &laddr->ifa->address.sin;
7404 sin->sin_addr = sin_a->sin_addr;
7410 SCTP_FREE_SONAME(sin);
7411 SCTP_INP_RUNLOCK(inp);
7412 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7416 SCTP_INP_RUNLOCK(inp);
7417 (*addr) = (struct sockaddr *)sin;
7422 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7424 struct sockaddr_in *sin;
7426 struct sockaddr_in *sin_a;
7427 struct sctp_inpcb *inp;
7428 struct sctp_tcb *stcb;
7429 struct sctp_nets *net;
7431 /* Do the malloc first in case it blocks. */
7432 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7435 sin->sin_family = AF_INET;
7436 sin->sin_len = sizeof(*sin);
7438 inp = (struct sctp_inpcb *)so->so_pcb;
7439 if ((inp == NULL) ||
7440 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7441 /* UDP type and listeners will drop out here */
7442 SCTP_FREE_SONAME(sin);
7443 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7446 SCTP_INP_RLOCK(inp);
7447 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7449 SCTP_TCB_LOCK(stcb);
7451 SCTP_INP_RUNLOCK(inp);
7453 SCTP_FREE_SONAME(sin);
7454 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7455 return (ECONNRESET);
7458 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7459 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7460 if (sin_a->sin_family == AF_INET) {
7462 sin->sin_port = stcb->rport;
7463 sin->sin_addr = sin_a->sin_addr;
7467 SCTP_TCB_UNLOCK(stcb);
7469 /* No IPv4 address */
7470 SCTP_FREE_SONAME(sin);
7471 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7474 (*addr) = (struct sockaddr *)sin;
7478 struct pr_usrreqs sctp_usrreqs = {
7479 .pru_abort = sctp_abort,
7480 .pru_accept = sctp_accept,
7481 .pru_attach = sctp_attach,
7482 .pru_bind = sctp_bind,
7483 .pru_connect = sctp_connect,
7484 .pru_control = in_control,
7485 .pru_close = sctp_close,
7486 .pru_detach = sctp_close,
7487 .pru_sopoll = sopoll_generic,
7488 .pru_flush = sctp_flush,
7489 .pru_disconnect = sctp_disconnect,
7490 .pru_listen = sctp_listen,
7491 .pru_peeraddr = sctp_peeraddr,
7492 .pru_send = sctp_sendm,
7493 .pru_shutdown = sctp_shutdown,
7494 .pru_sockaddr = sctp_ingetaddr,
7495 .pru_sosend = sctp_sosend,
7496 .pru_soreceive = sctp_soreceive