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 memset(&SCTP_BASE_VAR(packet_log_buffer), 0, SCTP_PACKET_LOG_SIZE);
94 sctp_finish(void *unused __unused)
99 VNET_SYSUNINIT(sctp, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, sctp_finish, NULL);
103 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
105 struct sctp_tmit_chunk *chk;
108 /* Adjust that too */
109 stcb->asoc.smallest_mtu = nxtsz;
110 /* now off to subtract IP_DF flag if needed */
111 overhead = IP_HDR_SIZE + sizeof(struct sctphdr);
112 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
113 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
115 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
116 if ((chk->send_size + overhead) > nxtsz) {
117 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
120 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
121 if ((chk->send_size + overhead) > nxtsz) {
123 * For this guy we also mark for immediate resend
124 * since we sent to big of chunk
126 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
127 if (chk->sent < SCTP_DATAGRAM_RESEND) {
128 sctp_flight_size_decrease(chk);
129 sctp_total_flight_decrease(stcb, chk);
130 chk->sent = SCTP_DATAGRAM_RESEND;
131 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
132 chk->rec.data.doing_fast_retransmit = 0;
133 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
134 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
135 chk->whoTo->flight_size,
137 (uint32_t)(uintptr_t)chk->whoTo,
140 /* Clear any time so NO RTT is being done */
149 sctp_notify(struct sctp_inpcb *inp,
150 struct sctp_tcb *stcb,
151 struct sctp_nets *net,
157 #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. */
224 next_mtu -= sizeof(struct udphdr);
226 if (net->mtu > next_mtu) {
229 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu + sizeof(struct udphdr));
231 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu);
234 /* Update the association MTU */
235 if (stcb->asoc.smallest_mtu > next_mtu) {
236 sctp_pathmtu_adjustment(stcb, next_mtu);
238 /* Finally, start the PMTU timer if it was running before. */
240 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
242 SCTP_TCB_UNLOCK(stcb);
244 SCTP_TCB_UNLOCK(stcb);
249 sctp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
255 struct sctp_inpcb *inp;
256 struct sctp_tcb *stcb;
257 struct sctp_nets *net;
258 struct sctp_init_chunk *ch;
259 struct sockaddr_in src, dst;
261 if (sa->sa_family != AF_INET ||
262 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
265 if (PRC_IS_REDIRECT(cmd)) {
267 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
271 inner_ip = (struct ip *)vip;
272 icmp = (struct icmp *)((caddr_t)inner_ip -
273 (sizeof(struct icmp) - sizeof(struct ip)));
274 outer_ip = (struct ip *)((caddr_t)icmp - sizeof(struct ip));
275 sh = (struct sctphdr *)((caddr_t)inner_ip + (inner_ip->ip_hl << 2));
276 memset(&src, 0, sizeof(struct sockaddr_in));
277 src.sin_family = AF_INET;
278 src.sin_len = sizeof(struct sockaddr_in);
279 src.sin_port = sh->src_port;
280 src.sin_addr = inner_ip->ip_src;
281 memset(&dst, 0, sizeof(struct sockaddr_in));
282 dst.sin_family = AF_INET;
283 dst.sin_len = sizeof(struct sockaddr_in);
284 dst.sin_port = sh->dest_port;
285 dst.sin_addr = inner_ip->ip_dst;
287 * 'dst' holds the dest of the packet that failed to be
288 * sent. 'src' holds our local endpoint address. Thus we
289 * reverse the dst and the src in the lookup.
293 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst,
294 (struct sockaddr *)&src,
297 if ((stcb != NULL) &&
300 /* Check the verification tag */
301 if (ntohl(sh->v_tag) != 0) {
303 * This must be the verification tag used
304 * for sending out packets. We don't
305 * consider packets reflecting the
308 if (ntohl(sh->v_tag) != stcb->asoc.peer_vtag) {
309 SCTP_TCB_UNLOCK(stcb);
313 if (ntohs(outer_ip->ip_len) >=
315 8 + (inner_ip->ip_hl << 2) + 20) {
317 * In this case we can check if we
318 * got an INIT chunk and if the
319 * initiate tag matches.
321 ch = (struct sctp_init_chunk *)(sh + 1);
322 if ((ch->ch.chunk_type != SCTP_INITIATION) ||
323 (ntohl(ch->init.initiate_tag) != stcb->asoc.my_vtag)) {
324 SCTP_TCB_UNLOCK(stcb);
328 SCTP_TCB_UNLOCK(stcb);
332 sctp_notify(inp, stcb, net,
335 ntohs(inner_ip->ip_len),
336 (uint32_t)ntohs(icmp->icmp_nextmtu));
338 if ((stcb == NULL) && (inp != NULL)) {
339 /* reduce ref-count */
341 SCTP_INP_DECR_REF(inp);
342 SCTP_INP_WUNLOCK(inp);
345 SCTP_TCB_UNLOCK(stcb);
354 sctp_getcred(SYSCTL_HANDLER_ARGS)
357 struct sockaddr_in addrs[2];
358 struct sctp_inpcb *inp;
359 struct sctp_nets *net;
360 struct sctp_tcb *stcb;
364 /* FIX, for non-bsd is this right? */
365 vrf_id = SCTP_DEFAULT_VRFID;
367 error = priv_check(req->td, PRIV_NETINET_GETCRED);
372 error = SYSCTL_IN(req, addrs, sizeof(addrs));
376 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
378 &inp, &net, 1, vrf_id);
379 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
380 if ((inp != NULL) && (stcb == NULL)) {
381 /* reduce ref-count */
383 SCTP_INP_DECR_REF(inp);
386 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
390 SCTP_TCB_UNLOCK(stcb);
392 * We use the write lock here, only since in the error leg we need
393 * it. If we used RLOCK, then we would have to
394 * wlock/decr/unlock/rlock. Which in theory could create a hole.
395 * Better to use higher wlock.
399 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
401 SCTP_INP_WUNLOCK(inp);
404 cru2x(inp->sctp_socket->so_cred, &xuc);
405 SCTP_INP_WUNLOCK(inp);
406 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
411 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
412 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
417 sctp_abort(struct socket *so)
419 struct sctp_inpcb *inp;
422 inp = (struct sctp_inpcb *)so->so_pcb;
427 flags = inp->sctp_flags;
428 #ifdef SCTP_LOG_CLOSING
429 sctp_log_closing(inp, NULL, 17);
431 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
432 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
433 #ifdef SCTP_LOG_CLOSING
434 sctp_log_closing(inp, NULL, 16);
436 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
437 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
439 SCTP_SB_CLEAR(so->so_snd);
441 * same for the rcv ones, they are only here for the
444 SCTP_SB_CLEAR(so->so_rcv);
446 /* Now null out the reference, we are completely detached. */
450 flags = inp->sctp_flags;
451 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
452 goto sctp_must_try_again;
459 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
461 struct sctp_inpcb *inp;
462 struct inpcb *ip_inp;
464 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
466 inp = (struct sctp_inpcb *)so->so_pcb;
468 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
471 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
472 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
477 error = sctp_inpcb_alloc(so, vrf_id);
481 inp = (struct sctp_inpcb *)so->so_pcb;
483 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
484 ip_inp = &inp->ip_inp.inp;
485 ip_inp->inp_vflag |= INP_IPV4;
486 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
487 SCTP_INP_WUNLOCK(inp);
492 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
494 struct sctp_inpcb *inp;
496 inp = (struct sctp_inpcb *)so->so_pcb;
498 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
502 if ((addr->sa_family != AF_INET) ||
503 (addr->sa_len != sizeof(struct sockaddr_in))) {
504 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
508 return (sctp_inpcb_bind(so, addr, NULL, p));
513 sctp_close(struct socket *so)
515 struct sctp_inpcb *inp;
518 inp = (struct sctp_inpcb *)so->so_pcb;
523 * Inform all the lower layer assoc that we are done.
526 flags = inp->sctp_flags;
527 #ifdef SCTP_LOG_CLOSING
528 sctp_log_closing(inp, NULL, 17);
530 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
531 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
532 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
533 (so->so_rcv.sb_cc > 0)) {
534 #ifdef SCTP_LOG_CLOSING
535 sctp_log_closing(inp, NULL, 13);
537 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
538 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
540 #ifdef SCTP_LOG_CLOSING
541 sctp_log_closing(inp, NULL, 14);
543 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
544 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
547 * The socket is now detached, no matter what the state of
548 * the SCTP association.
551 SCTP_SB_CLEAR(so->so_snd);
553 * same for the rcv ones, they are only here for the
556 SCTP_SB_CLEAR(so->so_rcv);
558 /* Now null out the reference, we are completely detached. */
562 flags = inp->sctp_flags;
563 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
564 goto sctp_must_try_again;
572 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
573 struct mbuf *control, struct thread *p);
577 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
578 struct mbuf *control, struct thread *p)
580 struct sctp_inpcb *inp;
583 inp = (struct sctp_inpcb *)so->so_pcb;
586 sctp_m_freem(control);
589 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
593 /* Got to have an to address if we are NOT a connected socket */
594 if ((addr == NULL) &&
595 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
596 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
598 } else if (addr == NULL) {
599 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
600 error = EDESTADDRREQ;
603 sctp_m_freem(control);
609 if (addr->sa_family != AF_INET) {
610 /* must be a v4 address! */
611 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
614 sctp_m_freem(control);
617 error = EDESTADDRREQ;
622 /* now what about control */
625 SCTP_PRINTF("huh? control set?\n");
626 sctp_m_freem(inp->control);
629 inp->control = control;
633 SCTP_BUF_NEXT(inp->pkt_last) = m;
636 inp->pkt_last = inp->pkt = m;
639 /* FreeBSD uses a flag passed */
640 ((flags & PRUS_MORETOCOME) == 0)
643 * note with the current version this code will only be used
644 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
645 * re-defining sosend to use the sctp_sosend. One can
646 * optionally switch back to this code (by changing back the
647 * definitions) but this is not advisable. This code is used
648 * by FreeBSD when sending a file with sendfile() though.
652 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
662 sctp_disconnect(struct socket *so)
664 struct sctp_inpcb *inp;
666 inp = (struct sctp_inpcb *)so->so_pcb;
668 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
672 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
673 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
674 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
676 SCTP_INP_RUNLOCK(inp);
679 struct sctp_association *asoc;
680 struct sctp_tcb *stcb;
682 stcb = LIST_FIRST(&inp->sctp_asoc_list);
684 SCTP_INP_RUNLOCK(inp);
685 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
690 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
691 /* We are about to be freed, out of here */
692 SCTP_TCB_UNLOCK(stcb);
693 SCTP_INP_RUNLOCK(inp);
696 if (((so->so_options & SO_LINGER) &&
697 (so->so_linger == 0)) ||
698 (so->so_rcv.sb_cc > 0)) {
699 if (SCTP_GET_STATE(asoc) !=
700 SCTP_STATE_COOKIE_WAIT) {
701 /* Left with Data unread */
704 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_NOWAIT, 1, MT_DATA);
710 struct sctp_paramhdr *ph;
712 ph = mtod(err, struct sctp_paramhdr *);
713 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
714 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
715 ph->param_length = htons(SCTP_BUF_LEN(err));
717 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
718 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
720 SCTP_INP_RUNLOCK(inp);
721 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
722 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
723 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
725 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
726 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
727 /* No unlock tcb assoc is gone */
730 if (TAILQ_EMPTY(&asoc->send_queue) &&
731 TAILQ_EMPTY(&asoc->sent_queue) &&
732 (asoc->stream_queue_cnt == 0)) {
733 /* there is nothing queued to send, so done */
734 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
737 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
738 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
739 /* only send SHUTDOWN 1st time thru */
740 struct sctp_nets *netp;
742 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
743 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
744 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
746 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
747 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
748 sctp_stop_timers_for_shutdown(stcb);
749 if (stcb->asoc.alternate) {
750 netp = stcb->asoc.alternate;
752 netp = stcb->asoc.primary_destination;
754 sctp_send_shutdown(stcb, netp);
755 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
756 stcb->sctp_ep, stcb, netp);
757 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
758 stcb->sctp_ep, stcb, netp);
759 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
763 * we still got (or just got) data to send,
764 * so set SHUTDOWN_PENDING
767 * XXX sockets draft says that SCTP_EOF
768 * should be sent with no data. currently,
769 * we will allow user data to be sent first
770 * and move to SHUTDOWN-PENDING
772 struct sctp_nets *netp;
774 if (stcb->asoc.alternate) {
775 netp = stcb->asoc.alternate;
777 netp = stcb->asoc.primary_destination;
780 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
781 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
783 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
784 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
786 if (TAILQ_EMPTY(&asoc->send_queue) &&
787 TAILQ_EMPTY(&asoc->sent_queue) &&
788 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
792 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
793 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
794 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
795 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
796 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
797 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
798 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
800 SCTP_INP_RUNLOCK(inp);
801 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
802 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
805 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
808 soisdisconnecting(so);
809 SCTP_TCB_UNLOCK(stcb);
810 SCTP_INP_RUNLOCK(inp);
815 /* UDP model does not support this */
816 SCTP_INP_RUNLOCK(inp);
817 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
823 sctp_flush(struct socket *so, int how)
826 * We will just clear out the values and let subsequent close clear
827 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
828 * they will not be able to read the data, the socket will block
829 * that from happening.
831 struct sctp_inpcb *inp;
833 inp = (struct sctp_inpcb *)so->so_pcb;
835 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
839 /* For the 1 to many model this does nothing */
840 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
841 SCTP_INP_RUNLOCK(inp);
844 SCTP_INP_RUNLOCK(inp);
845 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
847 * First make sure the sb will be happy, we don't use these
848 * except maybe the count
851 SCTP_INP_READ_LOCK(inp);
852 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
853 SCTP_INP_READ_UNLOCK(inp);
854 SCTP_INP_WUNLOCK(inp);
855 so->so_rcv.sb_cc = 0;
856 so->so_rcv.sb_mbcnt = 0;
857 so->so_rcv.sb_mb = NULL;
859 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
861 * First make sure the sb will be happy, we don't use these
862 * except maybe the count
864 so->so_snd.sb_cc = 0;
865 so->so_snd.sb_mbcnt = 0;
866 so->so_snd.sb_mb = NULL;
873 sctp_shutdown(struct socket *so)
875 struct sctp_inpcb *inp;
877 inp = (struct sctp_inpcb *)so->so_pcb;
879 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
883 /* For UDP model this is a invalid call */
884 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
885 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
886 /* Restore the flags that the soshutdown took away. */
887 SOCKBUF_LOCK(&so->so_rcv);
888 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
889 SOCKBUF_UNLOCK(&so->so_rcv);
890 /* This proc will wakeup for read and do nothing (I hope) */
891 SCTP_INP_RUNLOCK(inp);
892 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
896 * Ok, if we reach here its the TCP model and it is either a
897 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
900 struct sctp_tcb *stcb;
901 struct sctp_association *asoc;
902 struct sctp_nets *netp;
905 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
906 SCTP_INP_RUNLOCK(inp);
911 stcb = LIST_FIRST(&inp->sctp_asoc_list);
914 * Ok, we hit the case that the shutdown call was
915 * made after an abort or something. Nothing to do
918 SCTP_INP_RUNLOCK(inp);
923 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
924 SCTP_TCB_UNLOCK(stcb);
925 SCTP_INP_RUNLOCK(inp);
928 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_WAIT) &&
929 (SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_ECHOED) &&
930 (SCTP_GET_STATE(asoc) != SCTP_STATE_OPEN)) {
932 * If we are not in or before ESTABLISHED, there is
933 * no protocol action required.
935 SCTP_TCB_UNLOCK(stcb);
936 SCTP_INP_RUNLOCK(inp);
939 if (stcb->asoc.alternate) {
940 netp = stcb->asoc.alternate;
942 netp = stcb->asoc.primary_destination;
944 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) &&
945 TAILQ_EMPTY(&asoc->send_queue) &&
946 TAILQ_EMPTY(&asoc->sent_queue) &&
947 (asoc->stream_queue_cnt == 0)) {
948 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
951 /* there is nothing queued to send, so I'm done... */
952 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
953 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
954 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
955 sctp_stop_timers_for_shutdown(stcb);
956 sctp_send_shutdown(stcb, netp);
957 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
958 stcb->sctp_ep, stcb, netp);
961 * We still got (or just got) data to send, so set
964 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
965 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
966 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_PARTIAL_MSG_LEFT);
968 if (TAILQ_EMPTY(&asoc->send_queue) &&
969 TAILQ_EMPTY(&asoc->sent_queue) &&
970 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
974 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
975 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
976 sctp_abort_an_association(stcb->sctp_ep, stcb,
977 op_err, SCTP_SO_LOCKED);
978 SCTP_INP_RUNLOCK(inp);
982 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, netp);
984 * XXX: Why do this in the case where we have still data
987 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
988 SCTP_TCB_UNLOCK(stcb);
989 SCTP_INP_RUNLOCK(inp);
995 * copies a "user" presentable address and removes embedded scope, etc.
996 * returns 0 on success, 1 on error
999 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1002 struct sockaddr_in6 lsa6;
1004 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1007 memcpy(ss, sa, sa->sa_len);
1014 * NOTE: assumes addr lock is held
1017 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1018 struct sctp_tcb *stcb,
1020 struct sockaddr_storage *sas,
1023 struct sctp_ifn *sctp_ifn;
1024 struct sctp_ifa *sctp_ifa;
1028 int ipv4_local_scope, ipv4_addr_legal;
1031 int local_scope, site_scope, ipv6_addr_legal;
1033 struct sctp_vrf *vrf;
1040 /* Turn on all the appropriate scope */
1041 loopback_scope = stcb->asoc.scope.loopback_scope;
1043 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1044 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1047 local_scope = stcb->asoc.scope.local_scope;
1048 site_scope = stcb->asoc.scope.site_scope;
1049 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1052 /* Use generic values for endpoints. */
1055 ipv4_local_scope = 1;
1061 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1063 ipv6_addr_legal = 1;
1066 if (SCTP_IPV6_V6ONLY(inp)) {
1067 ipv4_addr_legal = 0;
1069 ipv4_addr_legal = 1;
1074 ipv6_addr_legal = 0;
1077 ipv4_addr_legal = 1;
1081 vrf = sctp_find_vrf(vrf_id);
1085 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1086 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1087 if ((loopback_scope == 0) &&
1088 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1089 /* Skip loopback if loopback_scope not set */
1092 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1095 * For the BOUND-ALL case, the list
1096 * associated with a TCB is Always
1097 * considered a reverse list.. i.e.
1098 * it lists addresses that are NOT
1099 * part of the association. If this
1100 * is one of those we must skip it.
1102 if (sctp_is_addr_restricted(stcb,
1107 switch (sctp_ifa->address.sa.sa_family) {
1110 if (ipv4_addr_legal) {
1111 struct sockaddr_in *sin;
1113 sin = &sctp_ifa->address.sin;
1114 if (sin->sin_addr.s_addr == 0) {
1122 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1123 &sin->sin_addr) != 0) {
1126 if ((ipv4_local_scope == 0) &&
1127 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1131 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1132 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1133 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1134 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1135 actual += sizeof(struct sockaddr_in6);
1138 memcpy(sas, sin, sizeof(*sin));
1139 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1140 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1141 actual += sizeof(*sin);
1145 if (actual >= limit) {
1155 if (ipv6_addr_legal) {
1156 struct sockaddr_in6 *sin6;
1158 sin6 = &sctp_ifa->address.sin6;
1159 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1167 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1168 &sin6->sin6_addr) != 0) {
1171 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1172 if (local_scope == 0)
1174 if (sin6->sin6_scope_id == 0) {
1175 if (sa6_recoverscope(sin6) != 0)
1188 if ((site_scope == 0) &&
1189 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1192 memcpy(sas, sin6, sizeof(*sin6));
1193 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1194 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1195 actual += sizeof(*sin6);
1196 if (actual >= limit) {
1211 struct sctp_laddr *laddr;
1213 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1215 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1219 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1221 switch (laddr->ifa->address.sa.sa_family) {
1224 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1229 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1236 sas = (struct sockaddr_storage *)((caddr_t)sas +
1237 laddr->ifa->address.sa.sa_len);
1238 actual += laddr->ifa->address.sa.sa_len;
1239 if (actual >= limit) {
1248 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1249 struct sctp_tcb *stcb,
1251 struct sockaddr_storage *sas)
1255 SCTP_IPI_ADDR_RLOCK();
1256 /* fill up addresses for the endpoint's default vrf */
1257 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1259 SCTP_IPI_ADDR_RUNLOCK();
1264 * NOTE: assumes addr lock is held
1267 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1270 struct sctp_vrf *vrf = NULL;
1273 * In both sub-set bound an bound_all cases we return the MAXIMUM
1274 * number of addresses that you COULD get. In reality the sub-set
1275 * bound may have an exclusion list for a given TCB OR in the
1276 * bound-all case a TCB may NOT include the loopback or other
1277 * addresses as well.
1279 vrf = sctp_find_vrf(vrf_id);
1283 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1284 struct sctp_ifn *sctp_ifn;
1285 struct sctp_ifa *sctp_ifa;
1287 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1288 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1289 /* Count them if they are the right type */
1290 switch (sctp_ifa->address.sa.sa_family) {
1294 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1295 cnt += sizeof(struct sockaddr_in6);
1297 cnt += sizeof(struct sockaddr_in);
1299 cnt += sizeof(struct sockaddr_in);
1305 cnt += sizeof(struct sockaddr_in6);
1314 struct sctp_laddr *laddr;
1316 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1317 switch (laddr->ifa->address.sa.sa_family) {
1321 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1322 cnt += sizeof(struct sockaddr_in6);
1324 cnt += sizeof(struct sockaddr_in);
1326 cnt += sizeof(struct sockaddr_in);
1332 cnt += sizeof(struct sockaddr_in6);
1344 sctp_count_max_addresses(struct sctp_inpcb *inp)
1348 SCTP_IPI_ADDR_RLOCK();
1349 /* count addresses for the endpoint's default VRF */
1350 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1351 SCTP_IPI_ADDR_RUNLOCK();
1356 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1357 size_t optsize, void *p, int delay)
1360 int creat_lock_on = 0;
1361 struct sctp_tcb *stcb = NULL;
1362 struct sockaddr *sa;
1363 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1365 int bad_addresses = 0;
1368 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1370 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1371 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1372 /* We are already connected AND the TCP model */
1373 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1374 return (EADDRINUSE);
1376 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1377 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1378 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1381 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1382 SCTP_INP_RLOCK(inp);
1383 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1384 SCTP_INP_RUNLOCK(inp);
1387 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1390 SCTP_INP_INCR_REF(inp);
1391 SCTP_ASOC_CREATE_LOCK(inp);
1393 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1394 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1395 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1399 totaddrp = (unsigned int *)optval;
1400 totaddr = *totaddrp;
1401 sa = (struct sockaddr *)(totaddrp + 1);
1402 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (unsigned int)(optsize - sizeof(int)), &bad_addresses);
1403 if ((stcb != NULL) || bad_addresses) {
1404 /* Already have or am bring up an association */
1405 SCTP_ASOC_CREATE_UNLOCK(inp);
1408 SCTP_TCB_UNLOCK(stcb);
1409 if (bad_addresses == 0) {
1410 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1416 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1421 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1423 struct in6pcb *inp6;
1425 inp6 = (struct in6pcb *)inp;
1426 if (SCTP_IPV6_V6ONLY(inp6)) {
1428 * if IPV6_V6ONLY flag, ignore connections destined
1429 * to a v4 addr or v4-mapped addr
1431 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1437 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1438 SCTP_PCB_FLAGS_UNBOUND) {
1439 /* Bind a ephemeral port */
1440 error = sctp_inpcb_bind(so, NULL, NULL, p);
1445 /* FIX ME: do we want to pass in a vrf on the connect call? */
1446 vrf_id = inp->def_vrf_id;
1449 /* We are GOOD to go */
1450 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1451 inp->sctp_ep.pre_open_stream_count,
1456 /* Gak! no memory */
1459 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1460 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1461 /* Set the connected flag so we can queue data */
1464 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1465 /* move to second address */
1466 switch (sa->sa_family) {
1469 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1474 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1482 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1483 /* Fill in the return id */
1485 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE,
1486 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
1489 a_id = (sctp_assoc_t *)optval;
1490 *a_id = sctp_get_associd(stcb);
1492 /* initialize authentication parameters for the assoc */
1493 sctp_initialize_auth_params(inp, stcb);
1496 /* doing delayed connection */
1497 stcb->asoc.delayed_connection = 1;
1498 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1500 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1501 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1503 SCTP_TCB_UNLOCK(stcb);
1505 if (creat_lock_on) {
1506 SCTP_ASOC_CREATE_UNLOCK(inp);
1508 SCTP_INP_DECR_REF(inp);
1512 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1513 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1514 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1515 SCTP_INP_RLOCK(inp); \
1516 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1518 SCTP_TCB_LOCK(stcb); \
1520 SCTP_INP_RUNLOCK(inp); \
1521 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1522 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1523 if (stcb == NULL) { \
1524 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1534 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1535 if (size < sizeof(type)) { \
1536 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1540 destp = (type *)srcp; \
1545 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1548 struct sctp_inpcb *inp = NULL;
1550 struct sctp_tcb *stcb = NULL;
1552 if (optval == NULL) {
1553 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1556 inp = (struct sctp_inpcb *)so->so_pcb;
1558 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1565 case SCTP_AUTOCLOSE:
1566 case SCTP_EXPLICIT_EOR:
1567 case SCTP_AUTO_ASCONF:
1568 case SCTP_DISABLE_FRAGMENTS:
1569 case SCTP_I_WANT_MAPPED_V4_ADDR:
1570 case SCTP_USE_EXT_RCVINFO:
1571 SCTP_INP_RLOCK(inp);
1573 case SCTP_DISABLE_FRAGMENTS:
1574 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1576 case SCTP_I_WANT_MAPPED_V4_ADDR:
1577 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1579 case SCTP_AUTO_ASCONF:
1580 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1581 /* only valid for bound all sockets */
1582 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1584 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1589 case SCTP_EXPLICIT_EOR:
1590 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1593 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1595 case SCTP_USE_EXT_RCVINFO:
1596 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1598 case SCTP_AUTOCLOSE:
1599 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1600 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1606 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1607 error = ENOPROTOOPT;
1608 } /* end switch (sopt->sopt_name) */
1609 if (*optsize < sizeof(val)) {
1610 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1614 SCTP_INP_RUNLOCK(inp);
1616 /* return the option value */
1617 *(int *)optval = val;
1618 *optsize = sizeof(val);
1621 case SCTP_GET_PACKET_LOG:
1623 #ifdef SCTP_PACKET_LOGGING
1627 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1628 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1631 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1636 case SCTP_REUSE_PORT:
1640 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1641 /* Can't do this for a 1-m socket */
1645 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1646 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1647 *optsize = sizeof(uint32_t);
1650 case SCTP_PARTIAL_DELIVERY_POINT:
1654 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1655 *value = inp->partial_delivery_point;
1656 *optsize = sizeof(uint32_t);
1659 case SCTP_FRAGMENT_INTERLEAVE:
1663 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1664 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1665 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1666 *value = SCTP_FRAG_LEVEL_2;
1668 *value = SCTP_FRAG_LEVEL_1;
1671 *value = SCTP_FRAG_LEVEL_0;
1673 *optsize = sizeof(uint32_t);
1676 case SCTP_INTERLEAVING_SUPPORTED:
1678 struct sctp_assoc_value *av;
1680 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1681 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1684 av->assoc_value = stcb->asoc.idata_supported;
1685 SCTP_TCB_UNLOCK(stcb);
1687 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1688 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1689 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1690 SCTP_INP_RLOCK(inp);
1691 if (inp->idata_supported) {
1692 av->assoc_value = 1;
1694 av->assoc_value = 0;
1696 SCTP_INP_RUNLOCK(inp);
1698 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1703 *optsize = sizeof(struct sctp_assoc_value);
1707 case SCTP_CMT_ON_OFF:
1709 struct sctp_assoc_value *av;
1711 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1712 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1714 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
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 av->assoc_value = inp->sctp_cmt_on_off;
1722 SCTP_INP_RUNLOCK(inp);
1724 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1729 *optsize = sizeof(struct sctp_assoc_value);
1733 case SCTP_PLUGGABLE_CC:
1735 struct sctp_assoc_value *av;
1737 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1738 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1740 av->assoc_value = stcb->asoc.congestion_control_module;
1741 SCTP_TCB_UNLOCK(stcb);
1743 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1744 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1745 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1746 SCTP_INP_RLOCK(inp);
1747 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1748 SCTP_INP_RUNLOCK(inp);
1750 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1755 *optsize = sizeof(struct sctp_assoc_value);
1759 case SCTP_CC_OPTION:
1761 struct sctp_cc_option *cc_opt;
1763 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1764 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1768 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1771 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1772 *optsize = sizeof(struct sctp_cc_option);
1774 SCTP_TCB_UNLOCK(stcb);
1778 case SCTP_PLUGGABLE_SS:
1780 struct sctp_assoc_value *av;
1782 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1783 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1785 av->assoc_value = stcb->asoc.stream_scheduling_module;
1786 SCTP_TCB_UNLOCK(stcb);
1788 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1789 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1790 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1791 SCTP_INP_RLOCK(inp);
1792 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1793 SCTP_INP_RUNLOCK(inp);
1795 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1800 *optsize = sizeof(struct sctp_assoc_value);
1806 struct sctp_stream_value *av;
1808 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1809 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1811 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1812 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1813 &av->stream_value) < 0)) {
1814 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1817 *optsize = sizeof(struct sctp_stream_value);
1819 SCTP_TCB_UNLOCK(stcb);
1822 * Can't get stream value without
1825 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1830 case SCTP_GET_ADDR_LEN:
1832 struct sctp_assoc_value *av;
1834 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1837 if (av->assoc_value == AF_INET) {
1838 av->assoc_value = sizeof(struct sockaddr_in);
1843 if (av->assoc_value == AF_INET6) {
1844 av->assoc_value = sizeof(struct sockaddr_in6);
1849 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1851 *optsize = sizeof(struct sctp_assoc_value);
1855 case SCTP_GET_ASSOC_NUMBER:
1857 uint32_t *value, cnt;
1859 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1860 SCTP_INP_RLOCK(inp);
1861 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1862 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1863 /* Can't do this for a 1-1 socket */
1865 SCTP_INP_RUNLOCK(inp);
1869 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1872 SCTP_INP_RUNLOCK(inp);
1874 *optsize = sizeof(uint32_t);
1877 case SCTP_GET_ASSOC_ID_LIST:
1879 struct sctp_assoc_ids *ids;
1883 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1884 SCTP_INP_RLOCK(inp);
1885 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1886 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1887 /* Can't do this for a 1-1 socket */
1889 SCTP_INP_RUNLOCK(inp);
1893 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1894 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1896 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1899 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1904 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1908 SCTP_INP_RUNLOCK(inp);
1910 ids->gaids_number_of_ids = at;
1911 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1917 struct sctp_assoc_value *av;
1919 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1920 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1923 av->assoc_value = stcb->asoc.context;
1924 SCTP_TCB_UNLOCK(stcb);
1926 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1927 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1928 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1929 SCTP_INP_RLOCK(inp);
1930 av->assoc_value = inp->sctp_context;
1931 SCTP_INP_RUNLOCK(inp);
1933 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1938 *optsize = sizeof(struct sctp_assoc_value);
1944 uint32_t *default_vrfid;
1946 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1947 *default_vrfid = inp->def_vrf_id;
1948 *optsize = sizeof(uint32_t);
1951 case SCTP_GET_ASOC_VRF:
1953 struct sctp_assoc_value *id;
1955 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1956 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1959 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1961 id->assoc_value = stcb->asoc.vrf_id;
1962 SCTP_TCB_UNLOCK(stcb);
1963 *optsize = sizeof(struct sctp_assoc_value);
1967 case SCTP_GET_VRF_IDS:
1969 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1973 case SCTP_GET_NONCE_VALUES:
1975 struct sctp_get_nonce_values *gnv;
1977 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1978 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1981 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1982 gnv->gn_local_tag = stcb->asoc.my_vtag;
1983 SCTP_TCB_UNLOCK(stcb);
1984 *optsize = sizeof(struct sctp_get_nonce_values);
1986 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1991 case SCTP_DELAYED_SACK:
1993 struct sctp_sack_info *sack;
1995 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1996 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1998 sack->sack_delay = stcb->asoc.delayed_ack;
1999 sack->sack_freq = stcb->asoc.sack_freq;
2000 SCTP_TCB_UNLOCK(stcb);
2002 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2003 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2004 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2005 SCTP_INP_RLOCK(inp);
2006 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2007 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2008 SCTP_INP_RUNLOCK(inp);
2010 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2015 *optsize = sizeof(struct sctp_sack_info);
2019 case SCTP_GET_SNDBUF_USE:
2021 struct sctp_sockstat *ss;
2023 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2024 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2027 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2028 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2029 stcb->asoc.size_on_all_streams);
2030 SCTP_TCB_UNLOCK(stcb);
2031 *optsize = sizeof(struct sctp_sockstat);
2033 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2038 case SCTP_MAX_BURST:
2040 struct sctp_assoc_value *av;
2042 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2043 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2046 av->assoc_value = stcb->asoc.max_burst;
2047 SCTP_TCB_UNLOCK(stcb);
2049 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2050 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2051 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2052 SCTP_INP_RLOCK(inp);
2053 av->assoc_value = inp->sctp_ep.max_burst;
2054 SCTP_INP_RUNLOCK(inp);
2056 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2061 *optsize = sizeof(struct sctp_assoc_value);
2067 struct sctp_assoc_value *av;
2070 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2071 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2074 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2075 SCTP_TCB_UNLOCK(stcb);
2077 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2078 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2079 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2080 SCTP_INP_RLOCK(inp);
2081 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2082 ovh = SCTP_MED_OVERHEAD;
2084 ovh = SCTP_MED_V4_OVERHEAD;
2086 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2087 av->assoc_value = 0;
2089 av->assoc_value = inp->sctp_frag_point - ovh;
2090 SCTP_INP_RUNLOCK(inp);
2092 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2097 *optsize = sizeof(struct sctp_assoc_value);
2101 case SCTP_GET_STAT_LOG:
2102 error = sctp_fill_stat_log(optval, optsize);
2106 struct sctp_event_subscribe *events;
2108 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2109 memset(events, 0, sizeof(struct sctp_event_subscribe));
2110 SCTP_INP_RLOCK(inp);
2111 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2112 events->sctp_data_io_event = 1;
2114 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2115 events->sctp_association_event = 1;
2117 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2118 events->sctp_address_event = 1;
2120 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2121 events->sctp_send_failure_event = 1;
2123 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2124 events->sctp_peer_error_event = 1;
2126 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2127 events->sctp_shutdown_event = 1;
2129 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2130 events->sctp_partial_delivery_event = 1;
2132 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2133 events->sctp_adaptation_layer_event = 1;
2135 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2136 events->sctp_authentication_event = 1;
2138 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2139 events->sctp_sender_dry_event = 1;
2141 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2142 events->sctp_stream_reset_event = 1;
2143 SCTP_INP_RUNLOCK(inp);
2144 *optsize = sizeof(struct sctp_event_subscribe);
2147 case SCTP_ADAPTATION_LAYER:
2151 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2153 SCTP_INP_RLOCK(inp);
2154 *value = inp->sctp_ep.adaptation_layer_indicator;
2155 SCTP_INP_RUNLOCK(inp);
2156 *optsize = sizeof(uint32_t);
2159 case SCTP_SET_INITIAL_DBG_SEQ:
2163 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2164 SCTP_INP_RLOCK(inp);
2165 *value = inp->sctp_ep.initial_sequence_debug;
2166 SCTP_INP_RUNLOCK(inp);
2167 *optsize = sizeof(uint32_t);
2170 case SCTP_GET_LOCAL_ADDR_SIZE:
2174 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2175 SCTP_INP_RLOCK(inp);
2176 *value = sctp_count_max_addresses(inp);
2177 SCTP_INP_RUNLOCK(inp);
2178 *optsize = sizeof(uint32_t);
2181 case SCTP_GET_REMOTE_ADDR_SIZE:
2185 struct sctp_nets *net;
2187 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2188 /* FIXME MT: change to sctp_assoc_value? */
2189 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2193 /* Count the sizes */
2194 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2195 switch (net->ro._l_addr.sa.sa_family) {
2199 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2200 size += sizeof(struct sockaddr_in6);
2202 size += sizeof(struct sockaddr_in);
2205 size += sizeof(struct sockaddr_in);
2211 size += sizeof(struct sockaddr_in6);
2218 SCTP_TCB_UNLOCK(stcb);
2219 *value = (uint32_t)size;
2220 *optsize = sizeof(uint32_t);
2222 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2227 case SCTP_GET_PEER_ADDRESSES:
2229 * Get the address information, an array is passed in to
2230 * fill up we pack it.
2234 struct sockaddr_storage *sas;
2235 struct sctp_nets *net;
2236 struct sctp_getaddresses *saddr;
2238 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2239 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2242 left = (*optsize) - sizeof(struct sctp_getaddresses);
2243 *optsize = sizeof(struct sctp_getaddresses);
2244 sas = (struct sockaddr_storage *)&saddr->addr[0];
2246 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2247 switch (net->ro._l_addr.sa.sa_family) {
2251 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2252 cpsz = sizeof(struct sockaddr_in6);
2254 cpsz = sizeof(struct sockaddr_in);
2257 cpsz = sizeof(struct sockaddr_in);
2263 cpsz = sizeof(struct sockaddr_in6);
2274 /* not enough room. */
2277 #if defined(INET) && defined(INET6)
2278 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2279 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2280 /* Must map the address */
2281 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2282 (struct sockaddr_in6 *)sas);
2284 memcpy(sas, &net->ro._l_addr, cpsz);
2287 memcpy(sas, &net->ro._l_addr, cpsz);
2289 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2291 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2295 SCTP_TCB_UNLOCK(stcb);
2297 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2302 case SCTP_GET_LOCAL_ADDRESSES:
2304 size_t limit, actual;
2305 struct sockaddr_storage *sas;
2306 struct sctp_getaddresses *saddr;
2308 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2309 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2311 sas = (struct sockaddr_storage *)&saddr->addr[0];
2312 limit = *optsize - sizeof(sctp_assoc_t);
2313 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2315 SCTP_TCB_UNLOCK(stcb);
2317 *optsize = sizeof(struct sockaddr_storage) + actual;
2320 case SCTP_PEER_ADDR_PARAMS:
2322 struct sctp_paddrparams *paddrp;
2323 struct sctp_nets *net;
2324 struct sockaddr *addr;
2325 #if defined(INET) && defined(INET6)
2326 struct sockaddr_in sin_store;
2329 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2330 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2332 #if defined(INET) && defined(INET6)
2333 if (paddrp->spp_address.ss_family == AF_INET6) {
2334 struct sockaddr_in6 *sin6;
2336 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2337 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2338 in6_sin6_2_sin(&sin_store, sin6);
2339 addr = (struct sockaddr *)&sin_store;
2341 addr = (struct sockaddr *)&paddrp->spp_address;
2344 addr = (struct sockaddr *)&paddrp->spp_address;
2347 addr = (struct sockaddr *)&paddrp->spp_address;
2350 net = sctp_findnet(stcb, addr);
2353 * We increment here since
2354 * sctp_findassociation_ep_addr() wil do a
2355 * decrement if it finds the stcb as long as
2356 * the locked tcb (last argument) is NOT a
2360 SCTP_INP_INCR_REF(inp);
2361 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2363 SCTP_INP_DECR_REF(inp);
2366 if ((stcb != NULL) && (net == NULL)) {
2368 if (addr->sa_family == AF_INET) {
2369 struct sockaddr_in *sin;
2371 sin = (struct sockaddr_in *)addr;
2372 if (sin->sin_addr.s_addr != INADDR_ANY) {
2374 SCTP_TCB_UNLOCK(stcb);
2375 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2381 if (addr->sa_family == AF_INET6) {
2382 struct sockaddr_in6 *sin6;
2384 sin6 = (struct sockaddr_in6 *)addr;
2385 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2387 SCTP_TCB_UNLOCK(stcb);
2388 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2394 error = EAFNOSUPPORT;
2395 SCTP_TCB_UNLOCK(stcb);
2396 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2401 /* Applies to the specific association */
2402 paddrp->spp_flags = 0;
2404 paddrp->spp_hbinterval = net->heart_beat_delay;
2405 paddrp->spp_pathmaxrxt = net->failure_threshold;
2406 paddrp->spp_pathmtu = net->mtu;
2407 switch (net->ro._l_addr.sa.sa_family) {
2410 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2415 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2421 /* get flags for HB */
2422 if (net->dest_state & SCTP_ADDR_NOHB) {
2423 paddrp->spp_flags |= SPP_HB_DISABLE;
2425 paddrp->spp_flags |= SPP_HB_ENABLE;
2427 /* get flags for PMTU */
2428 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2429 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2431 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2433 if (net->dscp & 0x01) {
2434 paddrp->spp_dscp = net->dscp & 0xfc;
2435 paddrp->spp_flags |= SPP_DSCP;
2438 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2439 (net->flowlabel & 0x80000000)) {
2440 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2441 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2446 * No destination so return default
2449 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2450 paddrp->spp_pathmtu = 0;
2451 if (stcb->asoc.default_dscp & 0x01) {
2452 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2453 paddrp->spp_flags |= SPP_DSCP;
2456 if (stcb->asoc.default_flowlabel & 0x80000000) {
2457 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2458 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2461 /* default settings should be these */
2462 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2463 paddrp->spp_flags |= SPP_HB_DISABLE;
2465 paddrp->spp_flags |= SPP_HB_ENABLE;
2467 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2468 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2470 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2472 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2474 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2475 SCTP_TCB_UNLOCK(stcb);
2477 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2478 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2479 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2480 /* Use endpoint defaults */
2481 SCTP_INP_RLOCK(inp);
2482 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2483 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2484 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2485 /* get inp's default */
2486 if (inp->sctp_ep.default_dscp & 0x01) {
2487 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2488 paddrp->spp_flags |= SPP_DSCP;
2491 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2492 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2493 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2494 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2497 /* can't return this */
2498 paddrp->spp_pathmtu = 0;
2500 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2501 paddrp->spp_flags |= SPP_HB_ENABLE;
2503 paddrp->spp_flags |= SPP_HB_DISABLE;
2505 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2506 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2508 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2510 SCTP_INP_RUNLOCK(inp);
2512 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2517 *optsize = sizeof(struct sctp_paddrparams);
2521 case SCTP_GET_PEER_ADDR_INFO:
2523 struct sctp_paddrinfo *paddri;
2524 struct sctp_nets *net;
2525 struct sockaddr *addr;
2526 #if defined(INET) && defined(INET6)
2527 struct sockaddr_in sin_store;
2530 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2531 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2533 #if defined(INET) && defined(INET6)
2534 if (paddri->spinfo_address.ss_family == AF_INET6) {
2535 struct sockaddr_in6 *sin6;
2537 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2538 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2539 in6_sin6_2_sin(&sin_store, sin6);
2540 addr = (struct sockaddr *)&sin_store;
2542 addr = (struct sockaddr *)&paddri->spinfo_address;
2545 addr = (struct sockaddr *)&paddri->spinfo_address;
2548 addr = (struct sockaddr *)&paddri->spinfo_address;
2551 net = sctp_findnet(stcb, addr);
2554 * We increment here since
2555 * sctp_findassociation_ep_addr() wil do a
2556 * decrement if it finds the stcb as long as
2557 * the locked tcb (last argument) is NOT a
2561 SCTP_INP_INCR_REF(inp);
2562 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2564 SCTP_INP_DECR_REF(inp);
2568 if ((stcb != NULL) && (net != NULL)) {
2569 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2570 /* It's unconfirmed */
2571 paddri->spinfo_state = SCTP_UNCONFIRMED;
2572 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2574 paddri->spinfo_state = SCTP_ACTIVE;
2577 paddri->spinfo_state = SCTP_INACTIVE;
2579 paddri->spinfo_cwnd = net->cwnd;
2580 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2581 paddri->spinfo_rto = net->RTO;
2582 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2583 paddri->spinfo_mtu = net->mtu;
2584 switch (addr->sa_family) {
2587 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2592 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2598 SCTP_TCB_UNLOCK(stcb);
2599 *optsize = sizeof(struct sctp_paddrinfo);
2602 SCTP_TCB_UNLOCK(stcb);
2604 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2609 case SCTP_PCB_STATUS:
2611 struct sctp_pcbinfo *spcb;
2613 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2614 sctp_fill_pcbinfo(spcb);
2615 *optsize = sizeof(struct sctp_pcbinfo);
2620 struct sctp_nets *net;
2621 struct sctp_status *sstat;
2623 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2624 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2627 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2631 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2632 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2633 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2634 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2636 * We can't include chunks that have been passed to
2637 * the socket layer. Only things in queue.
2639 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2640 stcb->asoc.cnt_on_all_streams);
2643 sstat->sstat_instrms = stcb->asoc.streamincnt;
2644 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2645 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2646 memcpy(&sstat->sstat_primary.spinfo_address,
2647 &stcb->asoc.primary_destination->ro._l_addr,
2648 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2649 net = stcb->asoc.primary_destination;
2650 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2652 * Again the user can get info from sctp_constants.h
2653 * for what the state of the network is.
2655 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2656 /* It's unconfirmed */
2657 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2658 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2660 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2663 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2665 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2666 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2667 sstat->sstat_primary.spinfo_rto = net->RTO;
2668 sstat->sstat_primary.spinfo_mtu = net->mtu;
2669 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2672 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2677 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2683 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2684 SCTP_TCB_UNLOCK(stcb);
2685 *optsize = sizeof(struct sctp_status);
2690 struct sctp_rtoinfo *srto;
2692 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2693 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2696 srto->srto_initial = stcb->asoc.initial_rto;
2697 srto->srto_max = stcb->asoc.maxrto;
2698 srto->srto_min = stcb->asoc.minrto;
2699 SCTP_TCB_UNLOCK(stcb);
2701 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2702 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2703 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2704 SCTP_INP_RLOCK(inp);
2705 srto->srto_initial = inp->sctp_ep.initial_rto;
2706 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2707 srto->srto_min = inp->sctp_ep.sctp_minrto;
2708 SCTP_INP_RUNLOCK(inp);
2710 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2715 *optsize = sizeof(struct sctp_rtoinfo);
2721 struct sctp_timeouts *stimo;
2723 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2724 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2727 stimo->stimo_init = stcb->asoc.timoinit;
2728 stimo->stimo_data = stcb->asoc.timodata;
2729 stimo->stimo_sack = stcb->asoc.timosack;
2730 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2731 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2732 stimo->stimo_cookie = stcb->asoc.timocookie;
2733 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2734 SCTP_TCB_UNLOCK(stcb);
2735 *optsize = sizeof(struct sctp_timeouts);
2737 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2742 case SCTP_ASSOCINFO:
2744 struct sctp_assocparams *sasoc;
2746 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2747 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2750 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2751 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2752 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2753 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2754 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2755 SCTP_TCB_UNLOCK(stcb);
2757 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2758 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2759 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2760 SCTP_INP_RLOCK(inp);
2761 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2762 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2763 sasoc->sasoc_number_peer_destinations = 0;
2764 sasoc->sasoc_peer_rwnd = 0;
2765 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2766 SCTP_INP_RUNLOCK(inp);
2768 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2773 *optsize = sizeof(struct sctp_assocparams);
2777 case SCTP_DEFAULT_SEND_PARAM:
2779 struct sctp_sndrcvinfo *s_info;
2781 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2782 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2785 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2786 SCTP_TCB_UNLOCK(stcb);
2788 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2789 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2790 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2791 SCTP_INP_RLOCK(inp);
2792 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2793 SCTP_INP_RUNLOCK(inp);
2795 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2800 *optsize = sizeof(struct sctp_sndrcvinfo);
2806 struct sctp_initmsg *sinit;
2808 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2809 SCTP_INP_RLOCK(inp);
2810 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2811 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2812 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2813 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2814 SCTP_INP_RUNLOCK(inp);
2815 *optsize = sizeof(struct sctp_initmsg);
2818 case SCTP_PRIMARY_ADDR:
2819 /* we allow a "get" operation on this */
2821 struct sctp_setprim *ssp;
2823 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2824 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2827 union sctp_sockstore *addr;
2829 addr = &stcb->asoc.primary_destination->ro._l_addr;
2830 switch (addr->sa.sa_family) {
2834 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2835 in6_sin_2_v4mapsin6(&addr->sin,
2836 (struct sockaddr_in6 *)&ssp->ssp_addr);
2838 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2841 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2847 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2853 SCTP_TCB_UNLOCK(stcb);
2854 *optsize = sizeof(struct sctp_setprim);
2856 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2861 case SCTP_HMAC_IDENT:
2863 struct sctp_hmacalgo *shmac;
2864 sctp_hmaclist_t *hmaclist;
2868 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2870 SCTP_INP_RLOCK(inp);
2871 hmaclist = inp->sctp_ep.local_hmacs;
2872 if (hmaclist == NULL) {
2873 /* no HMACs to return */
2874 *optsize = sizeof(*shmac);
2875 SCTP_INP_RUNLOCK(inp);
2878 /* is there room for all of the hmac ids? */
2879 size = sizeof(*shmac) + (hmaclist->num_algo *
2880 sizeof(shmac->shmac_idents[0]));
2881 if ((size_t)(*optsize) < size) {
2882 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2884 SCTP_INP_RUNLOCK(inp);
2887 /* copy in the list */
2888 shmac->shmac_number_of_idents = hmaclist->num_algo;
2889 for (i = 0; i < hmaclist->num_algo; i++) {
2890 shmac->shmac_idents[i] = hmaclist->hmac[i];
2892 SCTP_INP_RUNLOCK(inp);
2896 case SCTP_AUTH_ACTIVE_KEY:
2898 struct sctp_authkeyid *scact;
2900 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2901 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2904 /* get the active key on the assoc */
2905 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2906 SCTP_TCB_UNLOCK(stcb);
2908 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2909 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2910 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2911 /* get the endpoint active key */
2912 SCTP_INP_RLOCK(inp);
2913 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2914 SCTP_INP_RUNLOCK(inp);
2916 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2921 *optsize = sizeof(struct sctp_authkeyid);
2925 case SCTP_LOCAL_AUTH_CHUNKS:
2927 struct sctp_authchunks *sac;
2928 sctp_auth_chklist_t *chklist = NULL;
2931 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2932 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2935 /* get off the assoc */
2936 chklist = stcb->asoc.local_auth_chunks;
2937 /* is there enough space? */
2938 size = sctp_auth_get_chklist_size(chklist);
2939 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2941 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2943 /* copy in the chunks */
2944 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2945 sac->gauth_number_of_chunks = (uint32_t)size;
2946 *optsize = sizeof(struct sctp_authchunks) + size;
2948 SCTP_TCB_UNLOCK(stcb);
2950 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2951 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2952 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2953 /* get off the endpoint */
2954 SCTP_INP_RLOCK(inp);
2955 chklist = inp->sctp_ep.local_auth_chunks;
2956 /* is there enough space? */
2957 size = sctp_auth_get_chklist_size(chklist);
2958 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2960 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2962 /* copy in the chunks */
2963 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2964 sac->gauth_number_of_chunks = (uint32_t)size;
2965 *optsize = sizeof(struct sctp_authchunks) + size;
2967 SCTP_INP_RUNLOCK(inp);
2969 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2975 case SCTP_PEER_AUTH_CHUNKS:
2977 struct sctp_authchunks *sac;
2978 sctp_auth_chklist_t *chklist = NULL;
2981 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2982 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2985 /* get off the assoc */
2986 chklist = stcb->asoc.peer_auth_chunks;
2987 /* is there enough space? */
2988 size = sctp_auth_get_chklist_size(chklist);
2989 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2991 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2993 /* copy in the chunks */
2994 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2995 sac->gauth_number_of_chunks = (uint32_t)size;
2996 *optsize = sizeof(struct sctp_authchunks) + size;
2998 SCTP_TCB_UNLOCK(stcb);
3000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3007 struct sctp_event *event;
3008 uint32_t event_type;
3010 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3011 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3013 switch (event->se_type) {
3014 case SCTP_ASSOC_CHANGE:
3015 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3017 case SCTP_PEER_ADDR_CHANGE:
3018 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3020 case SCTP_REMOTE_ERROR:
3021 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3023 case SCTP_SEND_FAILED:
3024 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3026 case SCTP_SHUTDOWN_EVENT:
3027 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3029 case SCTP_ADAPTATION_INDICATION:
3030 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3032 case SCTP_PARTIAL_DELIVERY_EVENT:
3033 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3035 case SCTP_AUTHENTICATION_EVENT:
3036 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3038 case SCTP_STREAM_RESET_EVENT:
3039 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3041 case SCTP_SENDER_DRY_EVENT:
3042 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3044 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3046 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3049 case SCTP_ASSOC_RESET_EVENT:
3050 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3052 case SCTP_STREAM_CHANGE_EVENT:
3053 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3055 case SCTP_SEND_FAILED_EVENT:
3056 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3060 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3064 if (event_type > 0) {
3066 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3068 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3069 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3070 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3071 SCTP_INP_RLOCK(inp);
3072 event->se_on = sctp_is_feature_on(inp, event_type);
3073 SCTP_INP_RUNLOCK(inp);
3075 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3081 SCTP_TCB_UNLOCK(stcb);
3084 *optsize = sizeof(struct sctp_event);
3088 case SCTP_RECVRCVINFO:
3092 if (*optsize < sizeof(int)) {
3093 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3096 SCTP_INP_RLOCK(inp);
3097 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3098 SCTP_INP_RUNLOCK(inp);
3101 /* return the option value */
3102 *(int *)optval = onoff;
3103 *optsize = sizeof(int);
3107 case SCTP_RECVNXTINFO:
3111 if (*optsize < sizeof(int)) {
3112 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3115 SCTP_INP_RLOCK(inp);
3116 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3117 SCTP_INP_RUNLOCK(inp);
3120 /* return the option value */
3121 *(int *)optval = onoff;
3122 *optsize = sizeof(int);
3126 case SCTP_DEFAULT_SNDINFO:
3128 struct sctp_sndinfo *info;
3130 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3131 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3134 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3135 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3136 info->snd_flags &= 0xfff0;
3137 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3138 info->snd_context = stcb->asoc.def_send.sinfo_context;
3139 SCTP_TCB_UNLOCK(stcb);
3141 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3142 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3143 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3144 SCTP_INP_RLOCK(inp);
3145 info->snd_sid = inp->def_send.sinfo_stream;
3146 info->snd_flags = inp->def_send.sinfo_flags;
3147 info->snd_flags &= 0xfff0;
3148 info->snd_ppid = inp->def_send.sinfo_ppid;
3149 info->snd_context = inp->def_send.sinfo_context;
3150 SCTP_INP_RUNLOCK(inp);
3152 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3157 *optsize = sizeof(struct sctp_sndinfo);
3161 case SCTP_DEFAULT_PRINFO:
3163 struct sctp_default_prinfo *info;
3165 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3166 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3169 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3170 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3171 SCTP_TCB_UNLOCK(stcb);
3173 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3174 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3175 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3176 SCTP_INP_RLOCK(inp);
3177 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3178 info->pr_value = inp->def_send.sinfo_timetolive;
3179 SCTP_INP_RUNLOCK(inp);
3181 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3186 *optsize = sizeof(struct sctp_default_prinfo);
3190 case SCTP_PEER_ADDR_THLDS:
3192 struct sctp_paddrthlds *thlds;
3193 struct sctp_nets *net;
3194 struct sockaddr *addr;
3195 #if defined(INET) && defined(INET6)
3196 struct sockaddr_in sin_store;
3199 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3200 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3202 #if defined(INET) && defined(INET6)
3203 if (thlds->spt_address.ss_family == AF_INET6) {
3204 struct sockaddr_in6 *sin6;
3206 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3207 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3208 in6_sin6_2_sin(&sin_store, sin6);
3209 addr = (struct sockaddr *)&sin_store;
3211 addr = (struct sockaddr *)&thlds->spt_address;
3214 addr = (struct sockaddr *)&thlds->spt_address;
3217 addr = (struct sockaddr *)&thlds->spt_address;
3220 net = sctp_findnet(stcb, addr);
3223 * We increment here since
3224 * sctp_findassociation_ep_addr() wil do a
3225 * decrement if it finds the stcb as long as
3226 * the locked tcb (last argument) is NOT a
3230 SCTP_INP_INCR_REF(inp);
3231 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3233 SCTP_INP_DECR_REF(inp);
3236 if ((stcb != NULL) && (net == NULL)) {
3238 if (addr->sa_family == AF_INET) {
3239 struct sockaddr_in *sin;
3241 sin = (struct sockaddr_in *)addr;
3242 if (sin->sin_addr.s_addr != INADDR_ANY) {
3244 SCTP_TCB_UNLOCK(stcb);
3245 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3251 if (addr->sa_family == AF_INET6) {
3252 struct sockaddr_in6 *sin6;
3254 sin6 = (struct sockaddr_in6 *)addr;
3255 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3257 SCTP_TCB_UNLOCK(stcb);
3258 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3264 error = EAFNOSUPPORT;
3265 SCTP_TCB_UNLOCK(stcb);
3266 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3272 thlds->spt_pathmaxrxt = net->failure_threshold;
3273 thlds->spt_pathpfthld = net->pf_threshold;
3274 thlds->spt_pathcpthld = 0xffff;
3276 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3277 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3278 thlds->spt_pathcpthld = 0xffff;
3280 thlds->spt_assoc_id = sctp_get_associd(stcb);
3281 SCTP_TCB_UNLOCK(stcb);
3283 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3284 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3285 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3286 /* Use endpoint defaults */
3287 SCTP_INP_RLOCK(inp);
3288 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3289 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3290 thlds->spt_pathcpthld = 0xffff;
3291 SCTP_INP_RUNLOCK(inp);
3293 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3298 *optsize = sizeof(struct sctp_paddrthlds);
3302 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3304 struct sctp_udpencaps *encaps;
3305 struct sctp_nets *net;
3306 struct sockaddr *addr;
3307 #if defined(INET) && defined(INET6)
3308 struct sockaddr_in sin_store;
3311 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3312 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3314 #if defined(INET) && defined(INET6)
3315 if (encaps->sue_address.ss_family == AF_INET6) {
3316 struct sockaddr_in6 *sin6;
3318 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3319 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3320 in6_sin6_2_sin(&sin_store, sin6);
3321 addr = (struct sockaddr *)&sin_store;
3323 addr = (struct sockaddr *)&encaps->sue_address;
3326 addr = (struct sockaddr *)&encaps->sue_address;
3329 addr = (struct sockaddr *)&encaps->sue_address;
3332 net = sctp_findnet(stcb, addr);
3335 * We increment here since
3336 * sctp_findassociation_ep_addr() wil do a
3337 * decrement if it finds the stcb as long as
3338 * the locked tcb (last argument) is NOT a
3342 SCTP_INP_INCR_REF(inp);
3343 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3345 SCTP_INP_DECR_REF(inp);
3348 if ((stcb != NULL) && (net == NULL)) {
3350 if (addr->sa_family == AF_INET) {
3351 struct sockaddr_in *sin;
3353 sin = (struct sockaddr_in *)addr;
3354 if (sin->sin_addr.s_addr != INADDR_ANY) {
3356 SCTP_TCB_UNLOCK(stcb);
3357 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3363 if (addr->sa_family == AF_INET6) {
3364 struct sockaddr_in6 *sin6;
3366 sin6 = (struct sockaddr_in6 *)addr;
3367 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3369 SCTP_TCB_UNLOCK(stcb);
3370 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3376 error = EAFNOSUPPORT;
3377 SCTP_TCB_UNLOCK(stcb);
3378 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3384 encaps->sue_port = net->port;
3386 encaps->sue_port = stcb->asoc.port;
3388 SCTP_TCB_UNLOCK(stcb);
3390 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3391 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3392 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3393 SCTP_INP_RLOCK(inp);
3394 encaps->sue_port = inp->sctp_ep.port;
3395 SCTP_INP_RUNLOCK(inp);
3397 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3402 *optsize = sizeof(struct sctp_udpencaps);
3406 case SCTP_ECN_SUPPORTED:
3408 struct sctp_assoc_value *av;
3410 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3411 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3414 av->assoc_value = stcb->asoc.ecn_supported;
3415 SCTP_TCB_UNLOCK(stcb);
3417 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3418 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3419 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3420 SCTP_INP_RLOCK(inp);
3421 av->assoc_value = inp->ecn_supported;
3422 SCTP_INP_RUNLOCK(inp);
3424 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3429 *optsize = sizeof(struct sctp_assoc_value);
3433 case SCTP_PR_SUPPORTED:
3435 struct sctp_assoc_value *av;
3437 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3438 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3441 av->assoc_value = stcb->asoc.prsctp_supported;
3442 SCTP_TCB_UNLOCK(stcb);
3444 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3445 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3446 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3447 SCTP_INP_RLOCK(inp);
3448 av->assoc_value = inp->prsctp_supported;
3449 SCTP_INP_RUNLOCK(inp);
3451 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3456 *optsize = sizeof(struct sctp_assoc_value);
3460 case SCTP_AUTH_SUPPORTED:
3462 struct sctp_assoc_value *av;
3464 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3465 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3468 av->assoc_value = stcb->asoc.auth_supported;
3469 SCTP_TCB_UNLOCK(stcb);
3471 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3472 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3473 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3474 SCTP_INP_RLOCK(inp);
3475 av->assoc_value = inp->auth_supported;
3476 SCTP_INP_RUNLOCK(inp);
3478 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3483 *optsize = sizeof(struct sctp_assoc_value);
3487 case SCTP_ASCONF_SUPPORTED:
3489 struct sctp_assoc_value *av;
3491 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3492 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3495 av->assoc_value = stcb->asoc.asconf_supported;
3496 SCTP_TCB_UNLOCK(stcb);
3498 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3499 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3500 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3501 SCTP_INP_RLOCK(inp);
3502 av->assoc_value = inp->asconf_supported;
3503 SCTP_INP_RUNLOCK(inp);
3505 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3510 *optsize = sizeof(struct sctp_assoc_value);
3514 case SCTP_RECONFIG_SUPPORTED:
3516 struct sctp_assoc_value *av;
3518 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3519 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3522 av->assoc_value = stcb->asoc.reconfig_supported;
3523 SCTP_TCB_UNLOCK(stcb);
3525 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3526 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3527 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3528 SCTP_INP_RLOCK(inp);
3529 av->assoc_value = inp->reconfig_supported;
3530 SCTP_INP_RUNLOCK(inp);
3532 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3537 *optsize = sizeof(struct sctp_assoc_value);
3541 case SCTP_NRSACK_SUPPORTED:
3543 struct sctp_assoc_value *av;
3545 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3546 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3549 av->assoc_value = stcb->asoc.nrsack_supported;
3550 SCTP_TCB_UNLOCK(stcb);
3552 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3553 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3554 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3555 SCTP_INP_RLOCK(inp);
3556 av->assoc_value = inp->nrsack_supported;
3557 SCTP_INP_RUNLOCK(inp);
3559 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3564 *optsize = sizeof(struct sctp_assoc_value);
3568 case SCTP_PKTDROP_SUPPORTED:
3570 struct sctp_assoc_value *av;
3572 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3573 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3576 av->assoc_value = stcb->asoc.pktdrop_supported;
3577 SCTP_TCB_UNLOCK(stcb);
3579 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3580 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3581 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3582 SCTP_INP_RLOCK(inp);
3583 av->assoc_value = inp->pktdrop_supported;
3584 SCTP_INP_RUNLOCK(inp);
3586 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3591 *optsize = sizeof(struct sctp_assoc_value);
3595 case SCTP_ENABLE_STREAM_RESET:
3597 struct sctp_assoc_value *av;
3599 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3600 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3603 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3604 SCTP_TCB_UNLOCK(stcb);
3606 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3607 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3608 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3609 SCTP_INP_RLOCK(inp);
3610 av->assoc_value = (uint32_t)inp->local_strreset_support;
3611 SCTP_INP_RUNLOCK(inp);
3613 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3618 *optsize = sizeof(struct sctp_assoc_value);
3622 case SCTP_PR_STREAM_STATUS:
3624 struct sctp_prstatus *sprstat;
3628 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3629 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3631 sid = sprstat->sprstat_sid;
3632 policy = sprstat->sprstat_policy;
3633 #if defined(SCTP_DETAILED_STR_STATS)
3634 if ((stcb != NULL) &&
3635 (sid < stcb->asoc.streamoutcnt) &&
3636 (policy != SCTP_PR_SCTP_NONE) &&
3637 ((policy <= SCTP_PR_SCTP_MAX) ||
3638 (policy == SCTP_PR_SCTP_ALL))) {
3639 if (policy == SCTP_PR_SCTP_ALL) {
3640 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3641 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3643 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3644 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3647 if ((stcb != NULL) &&
3648 (sid < stcb->asoc.streamoutcnt) &&
3649 (policy == SCTP_PR_SCTP_ALL)) {
3650 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3651 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3654 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3658 SCTP_TCB_UNLOCK(stcb);
3661 *optsize = sizeof(struct sctp_prstatus);
3665 case SCTP_PR_ASSOC_STATUS:
3667 struct sctp_prstatus *sprstat;
3670 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3671 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3673 policy = sprstat->sprstat_policy;
3674 if ((stcb != NULL) &&
3675 (policy != SCTP_PR_SCTP_NONE) &&
3676 ((policy <= SCTP_PR_SCTP_MAX) ||
3677 (policy == SCTP_PR_SCTP_ALL))) {
3678 if (policy == SCTP_PR_SCTP_ALL) {
3679 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3680 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3682 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3683 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3686 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3690 SCTP_TCB_UNLOCK(stcb);
3693 *optsize = sizeof(struct sctp_prstatus);
3699 struct sctp_assoc_value *av;
3701 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3702 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3705 av->assoc_value = stcb->asoc.max_cwnd;
3706 SCTP_TCB_UNLOCK(stcb);
3708 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3709 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3710 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3711 SCTP_INP_RLOCK(inp);
3712 av->assoc_value = inp->max_cwnd;
3713 SCTP_INP_RUNLOCK(inp);
3715 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3720 *optsize = sizeof(struct sctp_assoc_value);
3725 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3726 error = ENOPROTOOPT;
3728 } /* end switch (sopt->sopt_name) */
3736 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3741 struct sctp_tcb *stcb = NULL;
3742 struct sctp_inpcb *inp = NULL;
3745 if (optval == NULL) {
3746 SCTP_PRINTF("optval is NULL\n");
3747 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3750 inp = (struct sctp_inpcb *)so->so_pcb;
3752 SCTP_PRINTF("inp is NULL?\n");
3753 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3756 vrf_id = inp->def_vrf_id;
3761 case SCTP_AUTOCLOSE:
3762 case SCTP_AUTO_ASCONF:
3763 case SCTP_EXPLICIT_EOR:
3764 case SCTP_DISABLE_FRAGMENTS:
3765 case SCTP_USE_EXT_RCVINFO:
3766 case SCTP_I_WANT_MAPPED_V4_ADDR:
3767 /* copy in the option value */
3768 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3773 case SCTP_DISABLE_FRAGMENTS:
3774 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3776 case SCTP_AUTO_ASCONF:
3778 * NOTE: we don't really support this flag
3780 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3781 /* only valid for bound all sockets */
3782 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3784 /* forbidden by admin */
3785 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3788 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3790 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3794 case SCTP_EXPLICIT_EOR:
3795 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3797 case SCTP_USE_EXT_RCVINFO:
3798 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3800 case SCTP_I_WANT_MAPPED_V4_ADDR:
3801 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3802 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3804 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3809 set_opt = SCTP_PCB_FLAGS_NODELAY;
3811 case SCTP_AUTOCLOSE:
3812 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3813 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3814 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3817 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3819 * The value is in ticks. Note this does not effect
3820 * old associations, only new ones.
3822 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3825 SCTP_INP_WLOCK(inp);
3827 sctp_feature_on(inp, set_opt);
3829 sctp_feature_off(inp, set_opt);
3831 SCTP_INP_WUNLOCK(inp);
3833 case SCTP_REUSE_PORT:
3835 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3836 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3837 /* Can't set it after we are bound */
3841 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3842 /* Can't do this for a 1-m socket */
3847 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3849 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3852 case SCTP_PARTIAL_DELIVERY_POINT:
3856 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3857 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3858 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3862 inp->partial_delivery_point = *value;
3865 case SCTP_FRAGMENT_INTERLEAVE:
3866 /* not yet until we re-write sctp_recvmsg() */
3870 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3871 if (*level == SCTP_FRAG_LEVEL_2) {
3872 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3873 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3874 } else if (*level == SCTP_FRAG_LEVEL_1) {
3875 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3876 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3877 } else if (*level == SCTP_FRAG_LEVEL_0) {
3878 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3879 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3882 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3887 case SCTP_INTERLEAVING_SUPPORTED:
3889 struct sctp_assoc_value *av;
3891 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3892 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3895 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3897 SCTP_TCB_UNLOCK(stcb);
3899 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3900 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3901 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3902 SCTP_INP_WLOCK(inp);
3903 if (av->assoc_value == 0) {
3904 inp->idata_supported = 0;
3906 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3907 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3908 inp->idata_supported = 1;
3916 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3920 SCTP_INP_WUNLOCK(inp);
3922 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3928 case SCTP_CMT_ON_OFF:
3929 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3930 struct sctp_assoc_value *av;
3932 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3933 if (av->assoc_value > SCTP_CMT_MAX) {
3934 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3938 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3940 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3941 SCTP_TCB_UNLOCK(stcb);
3943 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3944 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3945 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3946 (av->assoc_id == SCTP_ALL_ASSOC)) {
3947 SCTP_INP_WLOCK(inp);
3948 inp->sctp_cmt_on_off = av->assoc_value;
3949 SCTP_INP_WUNLOCK(inp);
3951 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3952 (av->assoc_id == SCTP_ALL_ASSOC)) {
3953 SCTP_INP_RLOCK(inp);
3954 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3955 SCTP_TCB_LOCK(stcb);
3956 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3957 SCTP_TCB_UNLOCK(stcb);
3959 SCTP_INP_RUNLOCK(inp);
3963 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3964 error = ENOPROTOOPT;
3967 case SCTP_PLUGGABLE_CC:
3969 struct sctp_assoc_value *av;
3970 struct sctp_nets *net;
3972 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3973 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3974 (av->assoc_value != SCTP_CC_HSTCP) &&
3975 (av->assoc_value != SCTP_CC_HTCP) &&
3976 (av->assoc_value != SCTP_CC_RTCC)) {
3977 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3981 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3983 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3984 stcb->asoc.congestion_control_module = av->assoc_value;
3985 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3986 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3987 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3990 SCTP_TCB_UNLOCK(stcb);
3992 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3993 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3994 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3995 (av->assoc_id == SCTP_ALL_ASSOC)) {
3996 SCTP_INP_WLOCK(inp);
3997 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3998 SCTP_INP_WUNLOCK(inp);
4000 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4001 (av->assoc_id == SCTP_ALL_ASSOC)) {
4002 SCTP_INP_RLOCK(inp);
4003 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4004 SCTP_TCB_LOCK(stcb);
4005 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4006 stcb->asoc.congestion_control_module = av->assoc_value;
4007 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4008 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4009 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4012 SCTP_TCB_UNLOCK(stcb);
4014 SCTP_INP_RUNLOCK(inp);
4019 case SCTP_CC_OPTION:
4021 struct sctp_cc_option *cc_opt;
4023 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4024 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4026 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
4027 SCTP_INP_RLOCK(inp);
4028 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4029 SCTP_TCB_LOCK(stcb);
4030 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4031 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4033 SCTP_TCB_UNLOCK(stcb);
4035 SCTP_INP_RUNLOCK(inp);
4040 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4043 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4046 SCTP_TCB_UNLOCK(stcb);
4050 case SCTP_PLUGGABLE_SS:
4052 struct sctp_assoc_value *av;
4054 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4055 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4056 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4057 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4058 (av->assoc_value != SCTP_SS_PRIORITY) &&
4059 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4060 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4061 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4065 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4067 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4068 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4069 stcb->asoc.stream_scheduling_module = av->assoc_value;
4070 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4071 SCTP_TCB_UNLOCK(stcb);
4073 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4074 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4075 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4076 (av->assoc_id == SCTP_ALL_ASSOC)) {
4077 SCTP_INP_WLOCK(inp);
4078 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4079 SCTP_INP_WUNLOCK(inp);
4081 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4082 (av->assoc_id == SCTP_ALL_ASSOC)) {
4083 SCTP_INP_RLOCK(inp);
4084 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4085 SCTP_TCB_LOCK(stcb);
4086 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4087 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4088 stcb->asoc.stream_scheduling_module = av->assoc_value;
4089 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4090 SCTP_TCB_UNLOCK(stcb);
4092 SCTP_INP_RUNLOCK(inp);
4099 struct sctp_stream_value *av;
4101 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4102 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4104 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4105 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4106 av->stream_value) < 0)) {
4107 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4110 SCTP_TCB_UNLOCK(stcb);
4112 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4113 SCTP_INP_RLOCK(inp);
4114 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4115 SCTP_TCB_LOCK(stcb);
4116 if (av->stream_id < stcb->asoc.streamoutcnt) {
4117 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4119 &stcb->asoc.strmout[av->stream_id],
4122 SCTP_TCB_UNLOCK(stcb);
4124 SCTP_INP_RUNLOCK(inp);
4127 * Can't set stream value without
4130 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4136 case SCTP_CLR_STAT_LOG:
4137 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4142 struct sctp_assoc_value *av;
4144 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4145 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4148 stcb->asoc.context = av->assoc_value;
4149 SCTP_TCB_UNLOCK(stcb);
4151 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4152 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4153 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4154 (av->assoc_id == SCTP_ALL_ASSOC)) {
4155 SCTP_INP_WLOCK(inp);
4156 inp->sctp_context = av->assoc_value;
4157 SCTP_INP_WUNLOCK(inp);
4159 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4160 (av->assoc_id == SCTP_ALL_ASSOC)) {
4161 SCTP_INP_RLOCK(inp);
4162 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4163 SCTP_TCB_LOCK(stcb);
4164 stcb->asoc.context = av->assoc_value;
4165 SCTP_TCB_UNLOCK(stcb);
4167 SCTP_INP_RUNLOCK(inp);
4174 uint32_t *default_vrfid;
4176 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4177 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4178 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4182 inp->def_vrf_id = *default_vrfid;
4185 case SCTP_DEL_VRF_ID:
4187 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4191 case SCTP_ADD_VRF_ID:
4193 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4197 case SCTP_DELAYED_SACK:
4199 struct sctp_sack_info *sack;
4201 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4202 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4203 if (sack->sack_delay) {
4204 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4205 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4206 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4207 sack->sack_delay = TICKS_TO_MSEC(1);
4211 if (sack->sack_delay) {
4212 stcb->asoc.delayed_ack = sack->sack_delay;
4214 if (sack->sack_freq) {
4215 stcb->asoc.sack_freq = sack->sack_freq;
4217 SCTP_TCB_UNLOCK(stcb);
4219 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4220 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4221 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4222 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4223 SCTP_INP_WLOCK(inp);
4224 if (sack->sack_delay) {
4225 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4227 if (sack->sack_freq) {
4228 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4230 SCTP_INP_WUNLOCK(inp);
4232 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4233 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4234 SCTP_INP_RLOCK(inp);
4235 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4236 SCTP_TCB_LOCK(stcb);
4237 if (sack->sack_delay) {
4238 stcb->asoc.delayed_ack = sack->sack_delay;
4240 if (sack->sack_freq) {
4241 stcb->asoc.sack_freq = sack->sack_freq;
4243 SCTP_TCB_UNLOCK(stcb);
4245 SCTP_INP_RUNLOCK(inp);
4250 case SCTP_AUTH_CHUNK:
4252 struct sctp_authchunk *sauth;
4254 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4256 SCTP_INP_WLOCK(inp);
4257 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4258 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4261 SCTP_INP_WUNLOCK(inp);
4266 struct sctp_authkey *sca;
4267 struct sctp_keyhead *shared_keys;
4268 sctp_sharedkey_t *shared_key;
4269 sctp_key_t *key = NULL;
4272 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4273 if (sca->sca_keylength == 0) {
4274 size = optsize - sizeof(struct sctp_authkey);
4276 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4277 size = sca->sca_keylength;
4279 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4284 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4287 shared_keys = &stcb->asoc.shared_keys;
4288 /* clear the cached keys for this key id */
4289 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4291 * create the new shared key and
4295 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4297 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4299 SCTP_TCB_UNLOCK(stcb);
4303 shared_key = sctp_alloc_sharedkey();
4304 if (shared_key == NULL) {
4306 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4308 SCTP_TCB_UNLOCK(stcb);
4311 shared_key->key = key;
4312 shared_key->keyid = sca->sca_keynumber;
4313 error = sctp_insert_sharedkey(shared_keys, shared_key);
4314 SCTP_TCB_UNLOCK(stcb);
4316 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4317 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4318 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4319 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4320 SCTP_INP_WLOCK(inp);
4321 shared_keys = &inp->sctp_ep.shared_keys;
4323 * clear the cached keys on all
4324 * assocs for this key id
4326 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4328 * create the new shared key and
4332 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4334 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4336 SCTP_INP_WUNLOCK(inp);
4340 shared_key = sctp_alloc_sharedkey();
4341 if (shared_key == NULL) {
4343 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4345 SCTP_INP_WUNLOCK(inp);
4348 shared_key->key = key;
4349 shared_key->keyid = sca->sca_keynumber;
4350 error = sctp_insert_sharedkey(shared_keys, shared_key);
4351 SCTP_INP_WUNLOCK(inp);
4353 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4354 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4355 SCTP_INP_RLOCK(inp);
4356 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4357 SCTP_TCB_LOCK(stcb);
4358 shared_keys = &stcb->asoc.shared_keys;
4360 * clear the cached keys for
4363 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4365 * create the new shared key
4366 * and insert/replace it
4369 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4371 SCTP_TCB_UNLOCK(stcb);
4375 shared_key = sctp_alloc_sharedkey();
4376 if (shared_key == NULL) {
4378 SCTP_TCB_UNLOCK(stcb);
4381 shared_key->key = key;
4382 shared_key->keyid = sca->sca_keynumber;
4383 error = sctp_insert_sharedkey(shared_keys, shared_key);
4384 SCTP_TCB_UNLOCK(stcb);
4386 SCTP_INP_RUNLOCK(inp);
4391 case SCTP_HMAC_IDENT:
4393 struct sctp_hmacalgo *shmac;
4394 sctp_hmaclist_t *hmaclist;
4398 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4399 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4400 (shmac->shmac_number_of_idents > 0xffff)) {
4401 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4405 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4406 if (hmaclist == NULL) {
4407 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4411 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4412 hmacid = shmac->shmac_idents[i];
4413 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4414 /* invalid HMACs were found */ ;
4415 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4417 sctp_free_hmaclist(hmaclist);
4418 goto sctp_set_hmac_done;
4421 for (i = 0; i < hmaclist->num_algo; i++) {
4422 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4423 /* already in list */
4427 if (i == hmaclist->num_algo) {
4428 /* not found in list */
4429 sctp_free_hmaclist(hmaclist);
4430 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4434 /* set it on the endpoint */
4435 SCTP_INP_WLOCK(inp);
4436 if (inp->sctp_ep.local_hmacs)
4437 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4438 inp->sctp_ep.local_hmacs = hmaclist;
4439 SCTP_INP_WUNLOCK(inp);
4443 case SCTP_AUTH_ACTIVE_KEY:
4445 struct sctp_authkeyid *scact;
4447 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4448 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4450 /* set the active key on the right place */
4452 /* set the active key on the assoc */
4453 if (sctp_auth_setactivekey(stcb,
4454 scact->scact_keynumber)) {
4455 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4456 SCTP_FROM_SCTP_USRREQ,
4460 SCTP_TCB_UNLOCK(stcb);
4462 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4463 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4464 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4465 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4466 SCTP_INP_WLOCK(inp);
4467 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4468 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4471 SCTP_INP_WUNLOCK(inp);
4473 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4474 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4475 SCTP_INP_RLOCK(inp);
4476 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4477 SCTP_TCB_LOCK(stcb);
4478 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4479 SCTP_TCB_UNLOCK(stcb);
4481 SCTP_INP_RUNLOCK(inp);
4486 case SCTP_AUTH_DELETE_KEY:
4488 struct sctp_authkeyid *scdel;
4490 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4491 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4493 /* delete the key from the right place */
4495 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4496 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4499 SCTP_TCB_UNLOCK(stcb);
4501 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4502 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4503 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4504 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4505 SCTP_INP_WLOCK(inp);
4506 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4507 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4510 SCTP_INP_WUNLOCK(inp);
4512 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4513 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4514 SCTP_INP_RLOCK(inp);
4515 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4516 SCTP_TCB_LOCK(stcb);
4517 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4518 SCTP_TCB_UNLOCK(stcb);
4520 SCTP_INP_RUNLOCK(inp);
4525 case SCTP_AUTH_DEACTIVATE_KEY:
4527 struct sctp_authkeyid *keyid;
4529 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4530 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4532 /* deactivate the key from the right place */
4534 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4535 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4538 SCTP_TCB_UNLOCK(stcb);
4540 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4541 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4542 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4543 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4544 SCTP_INP_WLOCK(inp);
4545 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4546 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4549 SCTP_INP_WUNLOCK(inp);
4551 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4552 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4553 SCTP_INP_RLOCK(inp);
4554 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4555 SCTP_TCB_LOCK(stcb);
4556 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4557 SCTP_TCB_UNLOCK(stcb);
4559 SCTP_INP_RUNLOCK(inp);
4564 case SCTP_ENABLE_STREAM_RESET:
4566 struct sctp_assoc_value *av;
4568 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4569 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4570 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4574 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4576 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4577 SCTP_TCB_UNLOCK(stcb);
4579 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4580 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4581 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4582 (av->assoc_id == SCTP_ALL_ASSOC)) {
4583 SCTP_INP_WLOCK(inp);
4584 inp->local_strreset_support = (uint8_t)av->assoc_value;
4585 SCTP_INP_WUNLOCK(inp);
4587 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4588 (av->assoc_id == SCTP_ALL_ASSOC)) {
4589 SCTP_INP_RLOCK(inp);
4590 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4591 SCTP_TCB_LOCK(stcb);
4592 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4593 SCTP_TCB_UNLOCK(stcb);
4595 SCTP_INP_RUNLOCK(inp);
4600 case SCTP_RESET_STREAMS:
4602 struct sctp_reset_streams *strrst;
4603 int i, send_out = 0;
4606 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4607 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4609 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4613 if (stcb->asoc.reconfig_supported == 0) {
4615 * Peer does not support the chunk type.
4617 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4619 SCTP_TCB_UNLOCK(stcb);
4622 if (sizeof(struct sctp_reset_streams) +
4623 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4625 SCTP_TCB_UNLOCK(stcb);
4628 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4630 if (stcb->asoc.stream_reset_outstanding) {
4631 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4633 SCTP_TCB_UNLOCK(stcb);
4637 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4640 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4641 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4643 SCTP_TCB_UNLOCK(stcb);
4646 if ((send_in == 0) && (send_out == 0)) {
4647 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4649 SCTP_TCB_UNLOCK(stcb);
4652 for (i = 0; i < strrst->srs_number_streams; i++) {
4654 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4655 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4660 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4661 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4667 SCTP_TCB_UNLOCK(stcb);
4674 if (strrst->srs_number_streams) {
4675 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4676 strm = strrst->srs_stream_list[i];
4677 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4678 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4684 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4685 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4686 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4693 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4694 strrst->srs_stream_list,
4695 send_in, 0, 0, 0, 0, 0);
4697 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4700 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4703 * For outgoing streams don't report any
4704 * problems in sending the request to the
4705 * application. XXX: Double check resetting
4710 SCTP_TCB_UNLOCK(stcb);
4713 case SCTP_ADD_STREAMS:
4715 struct sctp_add_streams *stradd;
4716 uint8_t addstream = 0;
4717 uint16_t add_o_strmcnt = 0;
4718 uint16_t add_i_strmcnt = 0;
4720 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4721 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4723 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4727 if (stcb->asoc.reconfig_supported == 0) {
4729 * Peer does not support the chunk type.
4731 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4733 SCTP_TCB_UNLOCK(stcb);
4736 if (stcb->asoc.stream_reset_outstanding) {
4737 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4739 SCTP_TCB_UNLOCK(stcb);
4742 if ((stradd->sas_outstrms == 0) &&
4743 (stradd->sas_instrms == 0)) {
4747 if (stradd->sas_outstrms) {
4749 /* We allocate here */
4750 add_o_strmcnt = stradd->sas_outstrms;
4751 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4752 /* You can't have more than 64k */
4757 if (stradd->sas_instrms) {
4762 * We allocate inside
4763 * sctp_send_str_reset_req()
4765 add_i_strmcnt = stradd->sas_instrms;
4766 cnt = add_i_strmcnt;
4767 cnt += stcb->asoc.streamincnt;
4768 if (cnt > 0x0000ffff) {
4769 /* You can't have more than 64k */
4773 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4774 /* More than you are allowed */
4779 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4780 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4782 SCTP_TCB_UNLOCK(stcb);
4785 case SCTP_RESET_ASSOC:
4790 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4791 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4793 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4797 if (stcb->asoc.reconfig_supported == 0) {
4799 * Peer does not support the chunk type.
4801 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4803 SCTP_TCB_UNLOCK(stcb);
4806 if (stcb->asoc.stream_reset_outstanding) {
4807 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4809 SCTP_TCB_UNLOCK(stcb);
4813 * Is there any data pending in the send or sent
4816 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4817 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4820 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4821 SCTP_TCB_UNLOCK(stcb);
4824 /* Do any streams have data queued? */
4825 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4826 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4830 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4831 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4832 SCTP_TCB_UNLOCK(stcb);
4835 case SCTP_CONNECT_X:
4836 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4837 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4841 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4843 case SCTP_CONNECT_X_DELAYED:
4844 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4845 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4849 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4851 case SCTP_CONNECT_X_COMPLETE:
4853 struct sockaddr *sa;
4855 /* FIXME MT: check correct? */
4856 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4859 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4860 SCTP_INP_RLOCK(inp);
4861 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4863 SCTP_TCB_LOCK(stcb);
4865 SCTP_INP_RUNLOCK(inp);
4868 * We increment here since
4869 * sctp_findassociation_ep_addr() wil do a
4870 * decrement if it finds the stcb as long as
4871 * the locked tcb (last argument) is NOT a
4874 SCTP_INP_INCR_REF(inp);
4875 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4877 SCTP_INP_DECR_REF(inp);
4882 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4886 if (stcb->asoc.delayed_connection == 1) {
4887 stcb->asoc.delayed_connection = 0;
4888 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4889 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4890 stcb->asoc.primary_destination,
4891 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4892 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4895 * already expired or did not use delayed
4898 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4901 SCTP_TCB_UNLOCK(stcb);
4904 case SCTP_MAX_BURST:
4906 struct sctp_assoc_value *av;
4908 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4909 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4912 stcb->asoc.max_burst = av->assoc_value;
4913 SCTP_TCB_UNLOCK(stcb);
4915 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4916 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4917 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4918 (av->assoc_id == SCTP_ALL_ASSOC)) {
4919 SCTP_INP_WLOCK(inp);
4920 inp->sctp_ep.max_burst = av->assoc_value;
4921 SCTP_INP_WUNLOCK(inp);
4923 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4924 (av->assoc_id == SCTP_ALL_ASSOC)) {
4925 SCTP_INP_RLOCK(inp);
4926 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4927 SCTP_TCB_LOCK(stcb);
4928 stcb->asoc.max_burst = av->assoc_value;
4929 SCTP_TCB_UNLOCK(stcb);
4931 SCTP_INP_RUNLOCK(inp);
4938 struct sctp_assoc_value *av;
4941 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4942 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4944 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4945 ovh = SCTP_MED_OVERHEAD;
4947 ovh = SCTP_MED_V4_OVERHEAD;
4950 if (av->assoc_value) {
4951 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4953 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4955 SCTP_TCB_UNLOCK(stcb);
4957 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4958 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4959 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4960 SCTP_INP_WLOCK(inp);
4962 * FIXME MT: I think this is not in
4963 * tune with the API ID
4965 if (av->assoc_value) {
4966 inp->sctp_frag_point = (av->assoc_value + ovh);
4968 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4970 SCTP_INP_WUNLOCK(inp);
4972 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4980 struct sctp_event_subscribe *events;
4982 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4984 SCTP_INP_WLOCK(inp);
4985 if (events->sctp_data_io_event) {
4986 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4988 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4991 if (events->sctp_association_event) {
4992 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4994 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4997 if (events->sctp_address_event) {
4998 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5000 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5003 if (events->sctp_send_failure_event) {
5004 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5006 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5009 if (events->sctp_peer_error_event) {
5010 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5012 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5015 if (events->sctp_shutdown_event) {
5016 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5018 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5021 if (events->sctp_partial_delivery_event) {
5022 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5024 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5027 if (events->sctp_adaptation_layer_event) {
5028 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5030 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5033 if (events->sctp_authentication_event) {
5034 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5036 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5039 if (events->sctp_sender_dry_event) {
5040 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5042 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5045 if (events->sctp_stream_reset_event) {
5046 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5048 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5050 SCTP_INP_WUNLOCK(inp);
5052 SCTP_INP_RLOCK(inp);
5053 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5054 SCTP_TCB_LOCK(stcb);
5055 if (events->sctp_association_event) {
5056 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5058 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5060 if (events->sctp_address_event) {
5061 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5063 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5065 if (events->sctp_send_failure_event) {
5066 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5068 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5070 if (events->sctp_peer_error_event) {
5071 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5073 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5075 if (events->sctp_shutdown_event) {
5076 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5078 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5080 if (events->sctp_partial_delivery_event) {
5081 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5083 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5085 if (events->sctp_adaptation_layer_event) {
5086 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5088 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5090 if (events->sctp_authentication_event) {
5091 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5093 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5095 if (events->sctp_sender_dry_event) {
5096 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5098 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5100 if (events->sctp_stream_reset_event) {
5101 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5103 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5105 SCTP_TCB_UNLOCK(stcb);
5108 * Send up the sender dry event only for 1-to-1
5111 if (events->sctp_sender_dry_event) {
5112 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5113 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5114 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5116 SCTP_TCB_LOCK(stcb);
5117 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5118 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5119 (stcb->asoc.stream_queue_cnt == 0)) {
5120 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5122 SCTP_TCB_UNLOCK(stcb);
5126 SCTP_INP_RUNLOCK(inp);
5129 case SCTP_ADAPTATION_LAYER:
5131 struct sctp_setadaptation *adap_bits;
5133 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5134 SCTP_INP_WLOCK(inp);
5135 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5136 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5137 SCTP_INP_WUNLOCK(inp);
5141 case SCTP_SET_INITIAL_DBG_SEQ:
5145 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5146 SCTP_INP_WLOCK(inp);
5147 inp->sctp_ep.initial_sequence_debug = *vvv;
5148 SCTP_INP_WUNLOCK(inp);
5152 case SCTP_DEFAULT_SEND_PARAM:
5154 struct sctp_sndrcvinfo *s_info;
5156 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5157 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5160 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5161 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5163 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5166 SCTP_TCB_UNLOCK(stcb);
5168 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5169 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5170 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5171 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5172 SCTP_INP_WLOCK(inp);
5173 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5174 SCTP_INP_WUNLOCK(inp);
5176 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5177 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5178 SCTP_INP_RLOCK(inp);
5179 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5180 SCTP_TCB_LOCK(stcb);
5181 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5182 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5184 SCTP_TCB_UNLOCK(stcb);
5186 SCTP_INP_RUNLOCK(inp);
5191 case SCTP_PEER_ADDR_PARAMS:
5193 struct sctp_paddrparams *paddrp;
5194 struct sctp_nets *net;
5195 struct sockaddr *addr;
5196 #if defined(INET) && defined(INET6)
5197 struct sockaddr_in sin_store;
5200 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5201 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5203 #if defined(INET) && defined(INET6)
5204 if (paddrp->spp_address.ss_family == AF_INET6) {
5205 struct sockaddr_in6 *sin6;
5207 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5208 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5209 in6_sin6_2_sin(&sin_store, sin6);
5210 addr = (struct sockaddr *)&sin_store;
5212 addr = (struct sockaddr *)&paddrp->spp_address;
5215 addr = (struct sockaddr *)&paddrp->spp_address;
5218 addr = (struct sockaddr *)&paddrp->spp_address;
5221 net = sctp_findnet(stcb, addr);
5224 * We increment here since
5225 * sctp_findassociation_ep_addr() wil do a
5226 * decrement if it finds the stcb as long as
5227 * the locked tcb (last argument) is NOT a
5231 SCTP_INP_INCR_REF(inp);
5232 stcb = sctp_findassociation_ep_addr(&inp, addr,
5235 SCTP_INP_DECR_REF(inp);
5238 if ((stcb != NULL) && (net == NULL)) {
5240 if (addr->sa_family == AF_INET) {
5242 struct sockaddr_in *sin;
5244 sin = (struct sockaddr_in *)addr;
5245 if (sin->sin_addr.s_addr != INADDR_ANY) {
5246 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5247 SCTP_TCB_UNLOCK(stcb);
5254 if (addr->sa_family == AF_INET6) {
5255 struct sockaddr_in6 *sin6;
5257 sin6 = (struct sockaddr_in6 *)addr;
5258 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5259 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5260 SCTP_TCB_UNLOCK(stcb);
5267 error = EAFNOSUPPORT;
5268 SCTP_TCB_UNLOCK(stcb);
5269 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5274 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5276 SCTP_TCB_UNLOCK(stcb);
5277 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5280 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5282 SCTP_TCB_UNLOCK(stcb);
5283 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5287 /************************TCB SPECIFIC SET ******************/
5289 /************************NET SPECIFIC SET ******************/
5290 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5291 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5292 !(net->dest_state & SCTP_ADDR_NOHB)) {
5293 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5294 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5296 net->dest_state |= SCTP_ADDR_NOHB;
5298 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5299 if (paddrp->spp_hbinterval) {
5300 net->heart_beat_delay = paddrp->spp_hbinterval;
5301 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5302 net->heart_beat_delay = 0;
5304 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5305 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5306 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5307 net->dest_state &= ~SCTP_ADDR_NOHB;
5309 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5311 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5312 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5313 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5315 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5316 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5317 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5318 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5320 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5321 net->mtu = paddrp->spp_pathmtu;
5322 switch (net->ro._l_addr.sa.sa_family) {
5325 net->mtu += SCTP_MIN_V4_OVERHEAD;
5330 net->mtu += SCTP_MIN_OVERHEAD;
5336 if (net->mtu < stcb->asoc.smallest_mtu) {
5337 sctp_pathmtu_adjustment(stcb, net->mtu);
5340 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5341 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5342 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5344 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5346 if (paddrp->spp_pathmaxrxt) {
5347 if (net->dest_state & SCTP_ADDR_PF) {
5348 if (net->error_count > paddrp->spp_pathmaxrxt) {
5349 net->dest_state &= ~SCTP_ADDR_PF;
5352 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5353 (net->error_count > net->pf_threshold)) {
5354 net->dest_state |= SCTP_ADDR_PF;
5355 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5356 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5357 stcb->sctp_ep, stcb, net,
5358 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5359 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5362 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5363 if (net->error_count > paddrp->spp_pathmaxrxt) {
5364 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5365 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5368 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5369 net->dest_state |= SCTP_ADDR_REACHABLE;
5370 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5373 net->failure_threshold = paddrp->spp_pathmaxrxt;
5375 if (paddrp->spp_flags & SPP_DSCP) {
5376 net->dscp = paddrp->spp_dscp & 0xfc;
5380 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5381 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5382 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5383 net->flowlabel |= 0x80000000;
5388 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5389 if (paddrp->spp_pathmaxrxt != 0) {
5390 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5391 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5392 if (net->dest_state & SCTP_ADDR_PF) {
5393 if (net->error_count > paddrp->spp_pathmaxrxt) {
5394 net->dest_state &= ~SCTP_ADDR_PF;
5397 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5398 (net->error_count > net->pf_threshold)) {
5399 net->dest_state |= SCTP_ADDR_PF;
5400 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5401 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5402 stcb->sctp_ep, stcb, net,
5403 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5404 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5407 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5408 if (net->error_count > paddrp->spp_pathmaxrxt) {
5409 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5410 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5413 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5414 net->dest_state |= SCTP_ADDR_REACHABLE;
5415 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5418 net->failure_threshold = paddrp->spp_pathmaxrxt;
5421 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5422 if (paddrp->spp_hbinterval != 0) {
5423 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5424 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5425 stcb->asoc.heart_beat_delay = 0;
5427 /* Turn back on the timer */
5428 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5429 if (paddrp->spp_hbinterval != 0) {
5430 net->heart_beat_delay = paddrp->spp_hbinterval;
5431 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5432 net->heart_beat_delay = 0;
5434 if (net->dest_state & SCTP_ADDR_NOHB) {
5435 net->dest_state &= ~SCTP_ADDR_NOHB;
5437 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5438 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5439 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5441 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5443 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5444 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5445 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5446 net->dest_state |= SCTP_ADDR_NOHB;
5447 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5448 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5450 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5454 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5456 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5457 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5458 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5459 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5460 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5462 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5463 net->mtu = paddrp->spp_pathmtu;
5464 switch (net->ro._l_addr.sa.sa_family) {
5467 net->mtu += SCTP_MIN_V4_OVERHEAD;
5472 net->mtu += SCTP_MIN_OVERHEAD;
5478 if (net->mtu < stcb->asoc.smallest_mtu) {
5479 sctp_pathmtu_adjustment(stcb, net->mtu);
5482 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5484 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5485 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5486 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5487 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5489 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5491 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5493 if (paddrp->spp_flags & SPP_DSCP) {
5494 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5495 net->dscp = paddrp->spp_dscp & 0xfc;
5498 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5499 stcb->asoc.default_dscp |= 0x01;
5502 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5503 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5504 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5505 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5506 net->flowlabel |= 0x80000000;
5509 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5510 stcb->asoc.default_flowlabel |= 0x80000000;
5514 SCTP_TCB_UNLOCK(stcb);
5516 /************************NO TCB, SET TO default stuff ******************/
5517 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5518 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5519 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5520 SCTP_INP_WLOCK(inp);
5522 * For the TOS/FLOWLABEL stuff you
5523 * set it with the options on the
5526 if (paddrp->spp_pathmaxrxt != 0) {
5527 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5529 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5530 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5531 else if (paddrp->spp_hbinterval != 0) {
5532 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5533 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5534 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5536 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5537 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5538 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5539 } else if (paddrp->spp_hbinterval) {
5540 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5542 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5543 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5544 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5546 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5547 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5548 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5549 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5551 if (paddrp->spp_flags & SPP_DSCP) {
5552 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5553 inp->sctp_ep.default_dscp |= 0x01;
5556 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5557 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5558 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5559 inp->sctp_ep.default_flowlabel |= 0x80000000;
5563 SCTP_INP_WUNLOCK(inp);
5565 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5573 struct sctp_rtoinfo *srto;
5574 uint32_t new_init, new_min, new_max;
5576 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5577 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5580 if (srto->srto_initial)
5581 new_init = srto->srto_initial;
5583 new_init = stcb->asoc.initial_rto;
5585 new_max = srto->srto_max;
5587 new_max = stcb->asoc.maxrto;
5589 new_min = srto->srto_min;
5591 new_min = stcb->asoc.minrto;
5592 if ((new_min <= new_init) && (new_init <= new_max)) {
5593 stcb->asoc.initial_rto = new_init;
5594 stcb->asoc.maxrto = new_max;
5595 stcb->asoc.minrto = new_min;
5597 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5600 SCTP_TCB_UNLOCK(stcb);
5602 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5603 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5604 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5605 SCTP_INP_WLOCK(inp);
5606 if (srto->srto_initial)
5607 new_init = srto->srto_initial;
5609 new_init = inp->sctp_ep.initial_rto;
5611 new_max = srto->srto_max;
5613 new_max = inp->sctp_ep.sctp_maxrto;
5615 new_min = srto->srto_min;
5617 new_min = inp->sctp_ep.sctp_minrto;
5618 if ((new_min <= new_init) && (new_init <= new_max)) {
5619 inp->sctp_ep.initial_rto = new_init;
5620 inp->sctp_ep.sctp_maxrto = new_max;
5621 inp->sctp_ep.sctp_minrto = new_min;
5623 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5626 SCTP_INP_WUNLOCK(inp);
5628 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5634 case SCTP_ASSOCINFO:
5636 struct sctp_assocparams *sasoc;
5638 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5639 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5640 if (sasoc->sasoc_cookie_life) {
5641 /* boundary check the cookie life */
5642 if (sasoc->sasoc_cookie_life < 1000)
5643 sasoc->sasoc_cookie_life = 1000;
5644 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5645 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5649 if (sasoc->sasoc_asocmaxrxt)
5650 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5651 if (sasoc->sasoc_cookie_life) {
5652 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5654 SCTP_TCB_UNLOCK(stcb);
5656 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5657 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5658 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5659 SCTP_INP_WLOCK(inp);
5660 if (sasoc->sasoc_asocmaxrxt)
5661 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5662 if (sasoc->sasoc_cookie_life) {
5663 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5665 SCTP_INP_WUNLOCK(inp);
5667 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5675 struct sctp_initmsg *sinit;
5677 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5678 SCTP_INP_WLOCK(inp);
5679 if (sinit->sinit_num_ostreams)
5680 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5682 if (sinit->sinit_max_instreams)
5683 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5685 if (sinit->sinit_max_attempts)
5686 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5688 if (sinit->sinit_max_init_timeo)
5689 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5690 SCTP_INP_WUNLOCK(inp);
5693 case SCTP_PRIMARY_ADDR:
5695 struct sctp_setprim *spa;
5696 struct sctp_nets *net;
5697 struct sockaddr *addr;
5698 #if defined(INET) && defined(INET6)
5699 struct sockaddr_in sin_store;
5702 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5703 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5705 #if defined(INET) && defined(INET6)
5706 if (spa->ssp_addr.ss_family == AF_INET6) {
5707 struct sockaddr_in6 *sin6;
5709 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5710 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5711 in6_sin6_2_sin(&sin_store, sin6);
5712 addr = (struct sockaddr *)&sin_store;
5714 addr = (struct sockaddr *)&spa->ssp_addr;
5717 addr = (struct sockaddr *)&spa->ssp_addr;
5720 addr = (struct sockaddr *)&spa->ssp_addr;
5723 net = sctp_findnet(stcb, addr);
5726 * We increment here since
5727 * sctp_findassociation_ep_addr() wil do a
5728 * decrement if it finds the stcb as long as
5729 * the locked tcb (last argument) is NOT a
5733 SCTP_INP_INCR_REF(inp);
5734 stcb = sctp_findassociation_ep_addr(&inp, addr,
5737 SCTP_INP_DECR_REF(inp);
5741 if ((stcb != NULL) && (net != NULL)) {
5742 if (net != stcb->asoc.primary_destination) {
5743 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5744 /* Ok we need to set it */
5745 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5746 if ((stcb->asoc.alternate) &&
5747 (!(net->dest_state & SCTP_ADDR_PF)) &&
5748 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5749 sctp_free_remote_addr(stcb->asoc.alternate);
5750 stcb->asoc.alternate = NULL;
5753 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5757 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5762 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5766 SCTP_TCB_UNLOCK(stcb);
5770 case SCTP_SET_DYNAMIC_PRIMARY:
5772 union sctp_sockstore *ss;
5774 error = priv_check(curthread,
5775 PRIV_NETINET_RESERVEDPORT);
5779 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5780 /* SUPER USER CHECK? */
5781 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5784 case SCTP_SET_PEER_PRIMARY_ADDR:
5786 struct sctp_setpeerprim *sspp;
5787 struct sockaddr *addr;
5788 #if defined(INET) && defined(INET6)
5789 struct sockaddr_in sin_store;
5792 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5793 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5795 struct sctp_ifa *ifa;
5797 #if defined(INET) && defined(INET6)
5798 if (sspp->sspp_addr.ss_family == AF_INET6) {
5799 struct sockaddr_in6 *sin6;
5801 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5802 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5803 in6_sin6_2_sin(&sin_store, sin6);
5804 addr = (struct sockaddr *)&sin_store;
5806 addr = (struct sockaddr *)&sspp->sspp_addr;
5809 addr = (struct sockaddr *)&sspp->sspp_addr;
5812 addr = (struct sockaddr *)&sspp->sspp_addr;
5814 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5816 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5820 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5822 * Must validate the ifa found is in
5825 struct sctp_laddr *laddr;
5828 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5829 if (laddr->ifa == NULL) {
5830 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5834 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5835 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5838 if (laddr->ifa == ifa) {
5844 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5849 switch (addr->sa_family) {
5853 struct sockaddr_in *sin;
5855 sin = (struct sockaddr_in *)addr;
5856 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5857 &sin->sin_addr) != 0) {
5858 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5868 struct sockaddr_in6 *sin6;
5870 sin6 = (struct sockaddr_in6 *)addr;
5871 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5872 &sin6->sin6_addr) != 0) {
5873 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5886 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5890 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5892 SCTP_TCB_UNLOCK(stcb);
5894 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5899 case SCTP_BINDX_ADD_ADDR:
5901 struct sctp_getaddresses *addrs;
5904 td = (struct thread *)p;
5905 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5908 if (addrs->addr->sa_family == AF_INET) {
5909 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5910 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5914 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5915 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5921 if (addrs->addr->sa_family == AF_INET6) {
5922 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5923 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5927 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5928 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5929 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5935 error = EAFNOSUPPORT;
5938 sctp_bindx_add_address(so, inp, addrs->addr,
5939 addrs->sget_assoc_id, vrf_id,
5943 case SCTP_BINDX_REM_ADDR:
5945 struct sctp_getaddresses *addrs;
5948 td = (struct thread *)p;
5950 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5952 if (addrs->addr->sa_family == AF_INET) {
5953 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5954 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5958 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5959 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5965 if (addrs->addr->sa_family == AF_INET6) {
5966 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5967 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5972 (error = prison_local_ip6(td->td_ucred,
5973 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5974 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5975 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5981 error = EAFNOSUPPORT;
5984 sctp_bindx_delete_address(inp, addrs->addr,
5985 addrs->sget_assoc_id, vrf_id,
5991 struct sctp_event *event;
5992 uint32_t event_type;
5994 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5995 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5996 switch (event->se_type) {
5997 case SCTP_ASSOC_CHANGE:
5998 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6000 case SCTP_PEER_ADDR_CHANGE:
6001 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6003 case SCTP_REMOTE_ERROR:
6004 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6006 case SCTP_SEND_FAILED:
6007 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6009 case SCTP_SHUTDOWN_EVENT:
6010 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6012 case SCTP_ADAPTATION_INDICATION:
6013 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6015 case SCTP_PARTIAL_DELIVERY_EVENT:
6016 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6018 case SCTP_AUTHENTICATION_EVENT:
6019 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6021 case SCTP_STREAM_RESET_EVENT:
6022 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6024 case SCTP_SENDER_DRY_EVENT:
6025 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6027 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6029 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6032 case SCTP_ASSOC_RESET_EVENT:
6033 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6035 case SCTP_STREAM_CHANGE_EVENT:
6036 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6038 case SCTP_SEND_FAILED_EVENT:
6039 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6043 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6047 if (event_type > 0) {
6050 sctp_stcb_feature_on(inp, stcb, event_type);
6051 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6052 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6053 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6054 (stcb->asoc.stream_queue_cnt == 0)) {
6055 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6059 sctp_stcb_feature_off(inp, stcb, event_type);
6061 SCTP_TCB_UNLOCK(stcb);
6064 * We don't want to send up a storm
6065 * of events, so return an error for
6068 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6069 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6070 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6071 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6072 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6073 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6077 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6078 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6079 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6080 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6081 SCTP_INP_WLOCK(inp);
6083 sctp_feature_on(inp, event_type);
6085 sctp_feature_off(inp, event_type);
6087 SCTP_INP_WUNLOCK(inp);
6089 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6090 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6091 SCTP_INP_RLOCK(inp);
6092 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6093 SCTP_TCB_LOCK(stcb);
6095 sctp_stcb_feature_on(inp, stcb, event_type);
6097 sctp_stcb_feature_off(inp, stcb, event_type);
6099 SCTP_TCB_UNLOCK(stcb);
6101 SCTP_INP_RUNLOCK(inp);
6107 case SCTP_RECVRCVINFO:
6111 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6112 SCTP_INP_WLOCK(inp);
6114 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6116 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6118 SCTP_INP_WUNLOCK(inp);
6121 case SCTP_RECVNXTINFO:
6125 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6126 SCTP_INP_WLOCK(inp);
6128 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6130 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6132 SCTP_INP_WUNLOCK(inp);
6135 case SCTP_DEFAULT_SNDINFO:
6137 struct sctp_sndinfo *info;
6140 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6141 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6144 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6145 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6146 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6147 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6148 stcb->asoc.def_send.sinfo_flags |= policy;
6149 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6150 stcb->asoc.def_send.sinfo_context = info->snd_context;
6152 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6155 SCTP_TCB_UNLOCK(stcb);
6157 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6158 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6159 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6160 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6161 SCTP_INP_WLOCK(inp);
6162 inp->def_send.sinfo_stream = info->snd_sid;
6163 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6164 inp->def_send.sinfo_flags = info->snd_flags;
6165 inp->def_send.sinfo_flags |= policy;
6166 inp->def_send.sinfo_ppid = info->snd_ppid;
6167 inp->def_send.sinfo_context = info->snd_context;
6168 SCTP_INP_WUNLOCK(inp);
6170 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6171 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6172 SCTP_INP_RLOCK(inp);
6173 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6174 SCTP_TCB_LOCK(stcb);
6175 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6176 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6177 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6178 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6179 stcb->asoc.def_send.sinfo_flags |= policy;
6180 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6181 stcb->asoc.def_send.sinfo_context = info->snd_context;
6183 SCTP_TCB_UNLOCK(stcb);
6185 SCTP_INP_RUNLOCK(inp);
6190 case SCTP_DEFAULT_PRINFO:
6192 struct sctp_default_prinfo *info;
6194 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6195 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6197 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6198 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6203 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6204 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6205 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6206 SCTP_TCB_UNLOCK(stcb);
6208 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6209 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6210 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6211 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6212 SCTP_INP_WLOCK(inp);
6213 inp->def_send.sinfo_flags &= 0xfff0;
6214 inp->def_send.sinfo_flags |= info->pr_policy;
6215 inp->def_send.sinfo_timetolive = info->pr_value;
6216 SCTP_INP_WUNLOCK(inp);
6218 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6219 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6220 SCTP_INP_RLOCK(inp);
6221 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6222 SCTP_TCB_LOCK(stcb);
6223 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6224 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6225 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6226 SCTP_TCB_UNLOCK(stcb);
6228 SCTP_INP_RUNLOCK(inp);
6233 case SCTP_PEER_ADDR_THLDS:
6234 /* Applies to the specific association */
6236 struct sctp_paddrthlds *thlds;
6237 struct sctp_nets *net;
6238 struct sockaddr *addr;
6239 #if defined(INET) && defined(INET6)
6240 struct sockaddr_in sin_store;
6243 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6244 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6246 #if defined(INET) && defined(INET6)
6247 if (thlds->spt_address.ss_family == AF_INET6) {
6248 struct sockaddr_in6 *sin6;
6250 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6251 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6252 in6_sin6_2_sin(&sin_store, sin6);
6253 addr = (struct sockaddr *)&sin_store;
6255 addr = (struct sockaddr *)&thlds->spt_address;
6258 addr = (struct sockaddr *)&thlds->spt_address;
6261 addr = (struct sockaddr *)&thlds->spt_address;
6264 net = sctp_findnet(stcb, addr);
6267 * We increment here since
6268 * sctp_findassociation_ep_addr() wil do a
6269 * decrement if it finds the stcb as long as
6270 * the locked tcb (last argument) is NOT a
6274 SCTP_INP_INCR_REF(inp);
6275 stcb = sctp_findassociation_ep_addr(&inp, addr,
6278 SCTP_INP_DECR_REF(inp);
6281 if ((stcb != NULL) && (net == NULL)) {
6283 if (addr->sa_family == AF_INET) {
6285 struct sockaddr_in *sin;
6287 sin = (struct sockaddr_in *)addr;
6288 if (sin->sin_addr.s_addr != INADDR_ANY) {
6289 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6290 SCTP_TCB_UNLOCK(stcb);
6297 if (addr->sa_family == AF_INET6) {
6298 struct sockaddr_in6 *sin6;
6300 sin6 = (struct sockaddr_in6 *)addr;
6301 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6302 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6303 SCTP_TCB_UNLOCK(stcb);
6310 error = EAFNOSUPPORT;
6311 SCTP_TCB_UNLOCK(stcb);
6312 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6316 if (thlds->spt_pathcpthld != 0xffff) {
6318 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6323 net->failure_threshold = thlds->spt_pathmaxrxt;
6324 net->pf_threshold = thlds->spt_pathpfthld;
6325 if (net->dest_state & SCTP_ADDR_PF) {
6326 if ((net->error_count > net->failure_threshold) ||
6327 (net->error_count <= net->pf_threshold)) {
6328 net->dest_state &= ~SCTP_ADDR_PF;
6331 if ((net->error_count > net->pf_threshold) &&
6332 (net->error_count <= net->failure_threshold)) {
6333 net->dest_state |= SCTP_ADDR_PF;
6334 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6335 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6336 stcb->sctp_ep, stcb, net,
6337 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6338 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6341 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6342 if (net->error_count > net->failure_threshold) {
6343 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6344 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6347 if (net->error_count <= net->failure_threshold) {
6348 net->dest_state |= SCTP_ADDR_REACHABLE;
6349 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6353 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6354 net->failure_threshold = thlds->spt_pathmaxrxt;
6355 net->pf_threshold = thlds->spt_pathpfthld;
6356 if (net->dest_state & SCTP_ADDR_PF) {
6357 if ((net->error_count > net->failure_threshold) ||
6358 (net->error_count <= net->pf_threshold)) {
6359 net->dest_state &= ~SCTP_ADDR_PF;
6362 if ((net->error_count > net->pf_threshold) &&
6363 (net->error_count <= net->failure_threshold)) {
6364 net->dest_state |= SCTP_ADDR_PF;
6365 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6366 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6367 stcb->sctp_ep, stcb, net,
6368 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6369 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6372 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6373 if (net->error_count > net->failure_threshold) {
6374 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6375 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6378 if (net->error_count <= net->failure_threshold) {
6379 net->dest_state |= SCTP_ADDR_REACHABLE;
6380 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6384 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6385 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6387 SCTP_TCB_UNLOCK(stcb);
6389 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6390 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6391 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6392 SCTP_INP_WLOCK(inp);
6393 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6394 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6395 SCTP_INP_WUNLOCK(inp);
6397 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6403 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6405 struct sctp_udpencaps *encaps;
6406 struct sctp_nets *net;
6407 struct sockaddr *addr;
6408 #if defined(INET) && defined(INET6)
6409 struct sockaddr_in sin_store;
6412 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6413 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6415 #if defined(INET) && defined(INET6)
6416 if (encaps->sue_address.ss_family == AF_INET6) {
6417 struct sockaddr_in6 *sin6;
6419 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6420 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6421 in6_sin6_2_sin(&sin_store, sin6);
6422 addr = (struct sockaddr *)&sin_store;
6424 addr = (struct sockaddr *)&encaps->sue_address;
6427 addr = (struct sockaddr *)&encaps->sue_address;
6430 addr = (struct sockaddr *)&encaps->sue_address;
6433 net = sctp_findnet(stcb, addr);
6436 * We increment here since
6437 * sctp_findassociation_ep_addr() wil do a
6438 * decrement if it finds the stcb as long as
6439 * the locked tcb (last argument) is NOT a
6443 SCTP_INP_INCR_REF(inp);
6444 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6446 SCTP_INP_DECR_REF(inp);
6449 if ((stcb != NULL) && (net == NULL)) {
6451 if (addr->sa_family == AF_INET) {
6453 struct sockaddr_in *sin;
6455 sin = (struct sockaddr_in *)addr;
6456 if (sin->sin_addr.s_addr != INADDR_ANY) {
6457 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6458 SCTP_TCB_UNLOCK(stcb);
6465 if (addr->sa_family == AF_INET6) {
6466 struct sockaddr_in6 *sin6;
6468 sin6 = (struct sockaddr_in6 *)addr;
6469 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6470 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6471 SCTP_TCB_UNLOCK(stcb);
6478 error = EAFNOSUPPORT;
6479 SCTP_TCB_UNLOCK(stcb);
6480 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6486 net->port = encaps->sue_port;
6488 stcb->asoc.port = encaps->sue_port;
6490 SCTP_TCB_UNLOCK(stcb);
6492 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6493 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6494 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6495 SCTP_INP_WLOCK(inp);
6496 inp->sctp_ep.port = encaps->sue_port;
6497 SCTP_INP_WUNLOCK(inp);
6499 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6505 case SCTP_ECN_SUPPORTED:
6507 struct sctp_assoc_value *av;
6509 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6510 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6513 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6515 SCTP_TCB_UNLOCK(stcb);
6517 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6518 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6519 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6520 SCTP_INP_WLOCK(inp);
6521 if (av->assoc_value == 0) {
6522 inp->ecn_supported = 0;
6524 inp->ecn_supported = 1;
6526 SCTP_INP_WUNLOCK(inp);
6528 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6534 case SCTP_PR_SUPPORTED:
6536 struct sctp_assoc_value *av;
6538 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6539 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6542 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6544 SCTP_TCB_UNLOCK(stcb);
6546 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6547 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6548 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6549 SCTP_INP_WLOCK(inp);
6550 if (av->assoc_value == 0) {
6551 inp->prsctp_supported = 0;
6553 inp->prsctp_supported = 1;
6555 SCTP_INP_WUNLOCK(inp);
6557 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6563 case SCTP_AUTH_SUPPORTED:
6565 struct sctp_assoc_value *av;
6567 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6568 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6571 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6573 SCTP_TCB_UNLOCK(stcb);
6575 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6576 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6577 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6578 if ((av->assoc_value == 0) &&
6579 (inp->asconf_supported == 1)) {
6581 * AUTH is required for
6584 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6587 SCTP_INP_WLOCK(inp);
6588 if (av->assoc_value == 0) {
6589 inp->auth_supported = 0;
6591 inp->auth_supported = 1;
6593 SCTP_INP_WUNLOCK(inp);
6596 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6602 case SCTP_ASCONF_SUPPORTED:
6604 struct sctp_assoc_value *av;
6606 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6607 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6610 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6612 SCTP_TCB_UNLOCK(stcb);
6614 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6615 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6616 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6617 if ((av->assoc_value != 0) &&
6618 (inp->auth_supported == 0)) {
6620 * AUTH is required for
6623 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6626 SCTP_INP_WLOCK(inp);
6627 if (av->assoc_value == 0) {
6628 inp->asconf_supported = 0;
6629 sctp_auth_delete_chunk(SCTP_ASCONF,
6630 inp->sctp_ep.local_auth_chunks);
6631 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6632 inp->sctp_ep.local_auth_chunks);
6634 inp->asconf_supported = 1;
6635 sctp_auth_add_chunk(SCTP_ASCONF,
6636 inp->sctp_ep.local_auth_chunks);
6637 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6638 inp->sctp_ep.local_auth_chunks);
6640 SCTP_INP_WUNLOCK(inp);
6643 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6649 case SCTP_RECONFIG_SUPPORTED:
6651 struct sctp_assoc_value *av;
6653 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6654 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6657 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6659 SCTP_TCB_UNLOCK(stcb);
6661 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6662 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6663 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6664 SCTP_INP_WLOCK(inp);
6665 if (av->assoc_value == 0) {
6666 inp->reconfig_supported = 0;
6668 inp->reconfig_supported = 1;
6670 SCTP_INP_WUNLOCK(inp);
6672 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6678 case SCTP_NRSACK_SUPPORTED:
6680 struct sctp_assoc_value *av;
6682 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6683 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6686 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6688 SCTP_TCB_UNLOCK(stcb);
6690 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6691 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6692 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6693 SCTP_INP_WLOCK(inp);
6694 if (av->assoc_value == 0) {
6695 inp->nrsack_supported = 0;
6697 inp->nrsack_supported = 1;
6699 SCTP_INP_WUNLOCK(inp);
6701 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6707 case SCTP_PKTDROP_SUPPORTED:
6709 struct sctp_assoc_value *av;
6711 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6712 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6715 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6717 SCTP_TCB_UNLOCK(stcb);
6719 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6720 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6721 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6722 SCTP_INP_WLOCK(inp);
6723 if (av->assoc_value == 0) {
6724 inp->pktdrop_supported = 0;
6726 inp->pktdrop_supported = 1;
6728 SCTP_INP_WUNLOCK(inp);
6730 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6738 struct sctp_assoc_value *av;
6739 struct sctp_nets *net;
6741 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6742 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6745 stcb->asoc.max_cwnd = av->assoc_value;
6746 if (stcb->asoc.max_cwnd > 0) {
6747 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6748 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6749 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6750 net->cwnd = stcb->asoc.max_cwnd;
6751 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6752 net->cwnd = net->mtu - sizeof(struct sctphdr);
6757 SCTP_TCB_UNLOCK(stcb);
6759 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6760 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6761 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6762 SCTP_INP_WLOCK(inp);
6763 inp->max_cwnd = av->assoc_value;
6764 SCTP_INP_WUNLOCK(inp);
6766 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6773 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6774 error = ENOPROTOOPT;
6776 } /* end switch (opt) */
6781 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6783 void *optval = NULL;
6787 struct sctp_inpcb *inp;
6789 if ((sopt->sopt_level == SOL_SOCKET) &&
6790 (sopt->sopt_name == SO_SETFIB)) {
6791 inp = (struct sctp_inpcb *)so->so_pcb;
6793 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6796 SCTP_INP_WLOCK(inp);
6797 inp->fibnum = so->so_fibnum;
6798 SCTP_INP_WUNLOCK(inp);
6801 if (sopt->sopt_level != IPPROTO_SCTP) {
6802 /* wrong proto level... send back up to IP */
6804 if (INP_CHECK_SOCKAF(so, AF_INET6))
6805 error = ip6_ctloutput(so, sopt);
6807 #if defined(INET) && defined(INET6)
6811 error = ip_ctloutput(so, sopt);
6815 optsize = sopt->sopt_valsize;
6817 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6818 if (optval == NULL) {
6819 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6822 error = sooptcopyin(sopt, optval, optsize, optsize);
6824 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6828 p = (void *)sopt->sopt_td;
6829 if (sopt->sopt_dir == SOPT_SET) {
6830 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6831 } else if (sopt->sopt_dir == SOPT_GET) {
6832 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6834 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6837 if ((error == 0) && (optval != NULL)) {
6838 error = sooptcopyout(sopt, optval, optsize);
6839 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6840 } else if (optval != NULL) {
6841 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6849 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6852 int create_lock_on = 0;
6854 struct sctp_inpcb *inp;
6855 struct sctp_tcb *stcb = NULL;
6857 inp = (struct sctp_inpcb *)so->so_pcb;
6859 /* I made the same as TCP since we are not setup? */
6860 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6861 return (ECONNRESET);
6864 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6867 switch (addr->sa_family) {
6871 struct sockaddr_in6 *sin6p;
6873 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6874 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6877 sin6p = (struct sockaddr_in6 *)addr;
6878 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6879 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6888 struct sockaddr_in *sinp;
6890 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6891 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6894 sinp = (struct sockaddr_in *)addr;
6895 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6896 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6903 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6904 return (EAFNOSUPPORT);
6906 SCTP_INP_INCR_REF(inp);
6907 SCTP_ASOC_CREATE_LOCK(inp);
6911 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6912 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6913 /* Should I really unlock ? */
6914 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6919 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6920 (addr->sa_family == AF_INET6)) {
6921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6926 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6927 SCTP_PCB_FLAGS_UNBOUND) {
6928 /* Bind a ephemeral port */
6929 error = sctp_inpcb_bind(so, NULL, NULL, p);
6934 /* Now do we connect? */
6935 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6936 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6937 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6941 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6942 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6943 /* We are already connected AND the TCP model */
6944 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6948 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6949 SCTP_INP_RLOCK(inp);
6950 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6951 SCTP_INP_RUNLOCK(inp);
6954 * We increment here since sctp_findassociation_ep_addr()
6955 * will do a decrement if it finds the stcb as long as the
6956 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6958 SCTP_INP_INCR_REF(inp);
6959 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6961 SCTP_INP_DECR_REF(inp);
6963 SCTP_TCB_UNLOCK(stcb);
6967 /* Already have or am bring up an association */
6968 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
6972 vrf_id = inp->def_vrf_id;
6973 /* We are GOOD to go */
6974 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
6975 inp->sctp_ep.pre_open_stream_count,
6976 inp->sctp_ep.port, p);
6978 /* Gak! no memory */
6981 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
6982 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
6983 /* Set the connected flag so we can queue data */
6986 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
6987 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
6989 /* initialize authentication parameters for the assoc */
6990 sctp_initialize_auth_params(inp, stcb);
6992 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
6993 SCTP_TCB_UNLOCK(stcb);
6995 if (create_lock_on) {
6996 SCTP_ASOC_CREATE_UNLOCK(inp);
6998 SCTP_INP_DECR_REF(inp);
7004 sctp_listen(struct socket *so, int backlog, struct thread *p)
7007 * Note this module depends on the protocol processing being called
7008 * AFTER any socket level flags and backlog are applied to the
7009 * socket. The traditional way that the socket flags are applied is
7010 * AFTER protocol processing. We have made a change to the
7011 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7012 * place if the socket API for SCTP is to work properly.
7016 struct sctp_inpcb *inp;
7018 inp = (struct sctp_inpcb *)so->so_pcb;
7020 /* I made the same as TCP since we are not setup? */
7021 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7022 return (ECONNRESET);
7024 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7025 /* See if we have a listener */
7026 struct sctp_inpcb *tinp;
7027 union sctp_sockstore store;
7029 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7031 struct sctp_laddr *laddr;
7033 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7034 memcpy(&store, &laddr->ifa->address, sizeof(store));
7035 switch (store.sa.sa_family) {
7038 store.sin.sin_port = inp->sctp_lport;
7043 store.sin6.sin6_port = inp->sctp_lport;
7049 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7050 if (tinp && (tinp != inp) &&
7051 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7052 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7053 (SCTP_IS_LISTENING(tinp))) {
7055 * we have a listener already and
7058 SCTP_INP_DECR_REF(tinp);
7059 return (EADDRINUSE);
7061 SCTP_INP_DECR_REF(tinp);
7065 /* Setup a local addr bound all */
7066 memset(&store, 0, sizeof(store));
7068 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7069 store.sa.sa_family = AF_INET6;
7070 store.sa.sa_len = sizeof(struct sockaddr_in6);
7074 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7075 store.sa.sa_family = AF_INET;
7076 store.sa.sa_len = sizeof(struct sockaddr_in);
7079 switch (store.sa.sa_family) {
7082 store.sin.sin_port = inp->sctp_lport;
7087 store.sin6.sin6_port = inp->sctp_lport;
7093 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7094 if (tinp && (tinp != inp) &&
7095 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7096 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7097 (SCTP_IS_LISTENING(tinp))) {
7099 * we have a listener already and its not
7102 SCTP_INP_DECR_REF(tinp);
7103 return (EADDRINUSE);
7105 SCTP_INP_DECR_REF(tinp);
7109 SCTP_INP_RLOCK(inp);
7110 #ifdef SCTP_LOCK_LOGGING
7111 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7112 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7116 error = solisten_proto_check(so);
7119 SCTP_INP_RUNLOCK(inp);
7122 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7123 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7125 * The unlucky case - We are in the tcp pool with this guy.
7126 * - Someone else is in the main inp slot. - We must move
7127 * this guy (the listener) to the main slot - We must then
7128 * move the guy that was listener to the TCP Pool.
7130 if (sctp_swap_inpcb_for_listen(inp)) {
7131 SCTP_INP_RUNLOCK(inp);
7132 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7133 return (EADDRINUSE);
7136 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7137 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7138 /* We are already connected AND the TCP model */
7139 SCTP_INP_RUNLOCK(inp);
7140 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7141 return (EADDRINUSE);
7143 SCTP_INP_RUNLOCK(inp);
7144 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7145 /* We must do a bind. */
7146 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7147 /* bind error, probably perm */
7151 SCTP_INP_WLOCK(inp);
7152 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7154 solisten_proto(so, backlog);
7158 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7160 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7162 SCTP_INP_WUNLOCK(inp);
7166 static int sctp_defered_wakeup_cnt = 0;
7169 sctp_accept(struct socket *so, struct sockaddr **addr)
7171 struct sctp_tcb *stcb;
7172 struct sctp_inpcb *inp;
7173 union sctp_sockstore store;
7177 inp = (struct sctp_inpcb *)so->so_pcb;
7180 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7181 return (ECONNRESET);
7183 SCTP_INP_RLOCK(inp);
7184 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7185 SCTP_INP_RUNLOCK(inp);
7186 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7187 return (EOPNOTSUPP);
7189 if (so->so_state & SS_ISDISCONNECTED) {
7190 SCTP_INP_RUNLOCK(inp);
7191 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7192 return (ECONNABORTED);
7194 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7196 SCTP_INP_RUNLOCK(inp);
7197 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7198 return (ECONNRESET);
7200 SCTP_TCB_LOCK(stcb);
7201 SCTP_INP_RUNLOCK(inp);
7202 store = stcb->asoc.primary_destination->ro._l_addr;
7203 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
7204 SCTP_TCB_UNLOCK(stcb);
7205 switch (store.sa.sa_family) {
7209 struct sockaddr_in *sin;
7211 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7214 sin->sin_family = AF_INET;
7215 sin->sin_len = sizeof(*sin);
7216 sin->sin_port = store.sin.sin_port;
7217 sin->sin_addr = store.sin.sin_addr;
7218 *addr = (struct sockaddr *)sin;
7225 struct sockaddr_in6 *sin6;
7227 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7230 sin6->sin6_family = AF_INET6;
7231 sin6->sin6_len = sizeof(*sin6);
7232 sin6->sin6_port = store.sin6.sin6_port;
7233 sin6->sin6_addr = store.sin6.sin6_addr;
7234 if ((error = sa6_recoverscope(sin6)) != 0) {
7235 SCTP_FREE_SONAME(sin6);
7238 *addr = (struct sockaddr *)sin6;
7246 /* Wake any delayed sleep action */
7247 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7248 SCTP_INP_WLOCK(inp);
7249 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7250 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7251 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7252 SCTP_INP_WUNLOCK(inp);
7253 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7254 if (sowriteable(inp->sctp_socket)) {
7255 sowwakeup_locked(inp->sctp_socket);
7257 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7259 SCTP_INP_WLOCK(inp);
7261 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7262 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7263 SCTP_INP_WUNLOCK(inp);
7264 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7265 if (soreadable(inp->sctp_socket)) {
7266 sctp_defered_wakeup_cnt++;
7267 sorwakeup_locked(inp->sctp_socket);
7269 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7271 SCTP_INP_WLOCK(inp);
7273 SCTP_INP_WUNLOCK(inp);
7275 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7276 SCTP_TCB_LOCK(stcb);
7277 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7278 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7285 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7287 struct sockaddr_in *sin;
7289 struct sctp_inpcb *inp;
7290 struct sctp_ifa *sctp_ifa;
7293 * Do the malloc first in case it blocks.
7295 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7298 sin->sin_family = AF_INET;
7299 sin->sin_len = sizeof(*sin);
7300 inp = (struct sctp_inpcb *)so->so_pcb;
7302 SCTP_FREE_SONAME(sin);
7303 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7304 return (ECONNRESET);
7306 SCTP_INP_RLOCK(inp);
7307 sin->sin_port = inp->sctp_lport;
7308 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7309 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7310 struct sctp_tcb *stcb;
7311 struct sockaddr_in *sin_a;
7312 struct sctp_nets *net;
7315 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7321 SCTP_TCB_LOCK(stcb);
7322 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7323 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7325 /* this will make coverity happy */
7328 if (sin_a->sin_family == AF_INET) {
7333 if ((!fnd) || (sin_a == NULL)) {
7335 SCTP_TCB_UNLOCK(stcb);
7338 vrf_id = inp->def_vrf_id;
7339 sctp_ifa = sctp_source_address_selection(inp,
7341 (sctp_route_t *)&net->ro,
7344 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7345 sctp_free_ifa(sctp_ifa);
7347 SCTP_TCB_UNLOCK(stcb);
7349 /* For the bound all case you get back 0 */
7351 sin->sin_addr.s_addr = 0;
7355 /* Take the first IPv4 address in the list */
7356 struct sctp_laddr *laddr;
7359 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7360 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7361 struct sockaddr_in *sin_a;
7363 sin_a = &laddr->ifa->address.sin;
7364 sin->sin_addr = sin_a->sin_addr;
7370 SCTP_FREE_SONAME(sin);
7371 SCTP_INP_RUNLOCK(inp);
7372 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7376 SCTP_INP_RUNLOCK(inp);
7377 (*addr) = (struct sockaddr *)sin;
7382 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7384 struct sockaddr_in *sin;
7386 struct sockaddr_in *sin_a;
7387 struct sctp_inpcb *inp;
7388 struct sctp_tcb *stcb;
7389 struct sctp_nets *net;
7391 /* Do the malloc first in case it blocks. */
7392 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7395 sin->sin_family = AF_INET;
7396 sin->sin_len = sizeof(*sin);
7398 inp = (struct sctp_inpcb *)so->so_pcb;
7399 if ((inp == NULL) ||
7400 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7401 /* UDP type and listeners will drop out here */
7402 SCTP_FREE_SONAME(sin);
7403 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7406 SCTP_INP_RLOCK(inp);
7407 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7409 SCTP_TCB_LOCK(stcb);
7411 SCTP_INP_RUNLOCK(inp);
7413 SCTP_FREE_SONAME(sin);
7414 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7415 return (ECONNRESET);
7418 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7419 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7420 if (sin_a->sin_family == AF_INET) {
7422 sin->sin_port = stcb->rport;
7423 sin->sin_addr = sin_a->sin_addr;
7427 SCTP_TCB_UNLOCK(stcb);
7429 /* No IPv4 address */
7430 SCTP_FREE_SONAME(sin);
7431 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7434 (*addr) = (struct sockaddr *)sin;
7438 struct pr_usrreqs sctp_usrreqs = {
7439 .pru_abort = sctp_abort,
7440 .pru_accept = sctp_accept,
7441 .pru_attach = sctp_attach,
7442 .pru_bind = sctp_bind,
7443 .pru_connect = sctp_connect,
7444 .pru_control = in_control,
7445 .pru_close = sctp_close,
7446 .pru_detach = sctp_close,
7447 .pru_sopoll = sopoll_generic,
7448 .pru_flush = sctp_flush,
7449 .pru_disconnect = sctp_disconnect,
7450 .pru_listen = sctp_listen,
7451 .pru_peeraddr = sctp_peeraddr,
7452 .pru_send = sctp_sendm,
7453 .pru_shutdown = sctp_shutdown,
7454 .pru_sockaddr = sctp_ingetaddr,
7455 .pru_sosend = sctp_sosend,
7456 .pru_soreceive = sctp_soreceive