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 *optsize = sizeof(struct sctp_assoc_value);
1966 case SCTP_GET_VRF_IDS:
1968 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1972 case SCTP_GET_NONCE_VALUES:
1974 struct sctp_get_nonce_values *gnv;
1976 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1977 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1980 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1981 gnv->gn_local_tag = stcb->asoc.my_vtag;
1982 SCTP_TCB_UNLOCK(stcb);
1983 *optsize = sizeof(struct sctp_get_nonce_values);
1985 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1990 case SCTP_DELAYED_SACK:
1992 struct sctp_sack_info *sack;
1994 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1995 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1997 sack->sack_delay = stcb->asoc.delayed_ack;
1998 sack->sack_freq = stcb->asoc.sack_freq;
1999 SCTP_TCB_UNLOCK(stcb);
2001 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2002 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2003 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2004 SCTP_INP_RLOCK(inp);
2005 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2006 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2007 SCTP_INP_RUNLOCK(inp);
2009 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2014 *optsize = sizeof(struct sctp_sack_info);
2018 case SCTP_GET_SNDBUF_USE:
2020 struct sctp_sockstat *ss;
2022 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2023 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2026 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2027 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2028 stcb->asoc.size_on_all_streams);
2029 SCTP_TCB_UNLOCK(stcb);
2030 *optsize = sizeof(struct sctp_sockstat);
2032 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2037 case SCTP_MAX_BURST:
2039 struct sctp_assoc_value *av;
2041 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2042 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2045 av->assoc_value = stcb->asoc.max_burst;
2046 SCTP_TCB_UNLOCK(stcb);
2048 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2049 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2050 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2051 SCTP_INP_RLOCK(inp);
2052 av->assoc_value = inp->sctp_ep.max_burst;
2053 SCTP_INP_RUNLOCK(inp);
2055 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2060 *optsize = sizeof(struct sctp_assoc_value);
2066 struct sctp_assoc_value *av;
2069 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2070 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2073 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2074 SCTP_TCB_UNLOCK(stcb);
2076 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2077 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2078 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2079 SCTP_INP_RLOCK(inp);
2080 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2081 ovh = SCTP_MED_OVERHEAD;
2083 ovh = SCTP_MED_V4_OVERHEAD;
2085 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2086 av->assoc_value = 0;
2088 av->assoc_value = inp->sctp_frag_point - ovh;
2089 SCTP_INP_RUNLOCK(inp);
2091 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2096 *optsize = sizeof(struct sctp_assoc_value);
2100 case SCTP_GET_STAT_LOG:
2101 error = sctp_fill_stat_log(optval, optsize);
2105 struct sctp_event_subscribe *events;
2107 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2108 memset(events, 0, sizeof(struct sctp_event_subscribe));
2109 SCTP_INP_RLOCK(inp);
2110 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2111 events->sctp_data_io_event = 1;
2113 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2114 events->sctp_association_event = 1;
2116 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2117 events->sctp_address_event = 1;
2119 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2120 events->sctp_send_failure_event = 1;
2122 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2123 events->sctp_peer_error_event = 1;
2125 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2126 events->sctp_shutdown_event = 1;
2128 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2129 events->sctp_partial_delivery_event = 1;
2131 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2132 events->sctp_adaptation_layer_event = 1;
2134 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2135 events->sctp_authentication_event = 1;
2137 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2138 events->sctp_sender_dry_event = 1;
2140 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2141 events->sctp_stream_reset_event = 1;
2142 SCTP_INP_RUNLOCK(inp);
2143 *optsize = sizeof(struct sctp_event_subscribe);
2146 case SCTP_ADAPTATION_LAYER:
2150 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2152 SCTP_INP_RLOCK(inp);
2153 *value = inp->sctp_ep.adaptation_layer_indicator;
2154 SCTP_INP_RUNLOCK(inp);
2155 *optsize = sizeof(uint32_t);
2158 case SCTP_SET_INITIAL_DBG_SEQ:
2162 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2163 SCTP_INP_RLOCK(inp);
2164 *value = inp->sctp_ep.initial_sequence_debug;
2165 SCTP_INP_RUNLOCK(inp);
2166 *optsize = sizeof(uint32_t);
2169 case SCTP_GET_LOCAL_ADDR_SIZE:
2173 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2174 SCTP_INP_RLOCK(inp);
2175 *value = sctp_count_max_addresses(inp);
2176 SCTP_INP_RUNLOCK(inp);
2177 *optsize = sizeof(uint32_t);
2180 case SCTP_GET_REMOTE_ADDR_SIZE:
2184 struct sctp_nets *net;
2186 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2187 /* FIXME MT: change to sctp_assoc_value? */
2188 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2192 /* Count the sizes */
2193 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2194 switch (net->ro._l_addr.sa.sa_family) {
2198 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2199 size += sizeof(struct sockaddr_in6);
2201 size += sizeof(struct sockaddr_in);
2204 size += sizeof(struct sockaddr_in);
2210 size += sizeof(struct sockaddr_in6);
2217 SCTP_TCB_UNLOCK(stcb);
2218 *value = (uint32_t)size;
2219 *optsize = sizeof(uint32_t);
2221 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2226 case SCTP_GET_PEER_ADDRESSES:
2228 * Get the address information, an array is passed in to
2229 * fill up we pack it.
2233 struct sockaddr_storage *sas;
2234 struct sctp_nets *net;
2235 struct sctp_getaddresses *saddr;
2237 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2238 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2241 left = (*optsize) - sizeof(struct sctp_getaddresses);
2242 *optsize = sizeof(struct sctp_getaddresses);
2243 sas = (struct sockaddr_storage *)&saddr->addr[0];
2245 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2246 switch (net->ro._l_addr.sa.sa_family) {
2250 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2251 cpsz = sizeof(struct sockaddr_in6);
2253 cpsz = sizeof(struct sockaddr_in);
2256 cpsz = sizeof(struct sockaddr_in);
2262 cpsz = sizeof(struct sockaddr_in6);
2273 /* not enough room. */
2276 #if defined(INET) && defined(INET6)
2277 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2278 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2279 /* Must map the address */
2280 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2281 (struct sockaddr_in6 *)sas);
2283 memcpy(sas, &net->ro._l_addr, cpsz);
2286 memcpy(sas, &net->ro._l_addr, cpsz);
2288 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2290 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2294 SCTP_TCB_UNLOCK(stcb);
2296 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2301 case SCTP_GET_LOCAL_ADDRESSES:
2303 size_t limit, actual;
2304 struct sockaddr_storage *sas;
2305 struct sctp_getaddresses *saddr;
2307 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2308 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2310 sas = (struct sockaddr_storage *)&saddr->addr[0];
2311 limit = *optsize - sizeof(sctp_assoc_t);
2312 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2314 SCTP_TCB_UNLOCK(stcb);
2316 *optsize = sizeof(struct sockaddr_storage) + actual;
2319 case SCTP_PEER_ADDR_PARAMS:
2321 struct sctp_paddrparams *paddrp;
2322 struct sctp_nets *net;
2323 struct sockaddr *addr;
2324 #if defined(INET) && defined(INET6)
2325 struct sockaddr_in sin_store;
2328 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2329 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2331 #if defined(INET) && defined(INET6)
2332 if (paddrp->spp_address.ss_family == AF_INET6) {
2333 struct sockaddr_in6 *sin6;
2335 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2336 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2337 in6_sin6_2_sin(&sin_store, sin6);
2338 addr = (struct sockaddr *)&sin_store;
2340 addr = (struct sockaddr *)&paddrp->spp_address;
2343 addr = (struct sockaddr *)&paddrp->spp_address;
2346 addr = (struct sockaddr *)&paddrp->spp_address;
2349 net = sctp_findnet(stcb, addr);
2352 * We increment here since
2353 * sctp_findassociation_ep_addr() wil do a
2354 * decrement if it finds the stcb as long as
2355 * the locked tcb (last argument) is NOT a
2359 SCTP_INP_INCR_REF(inp);
2360 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2362 SCTP_INP_DECR_REF(inp);
2365 if ((stcb != NULL) && (net == NULL)) {
2367 if (addr->sa_family == AF_INET) {
2368 struct sockaddr_in *sin;
2370 sin = (struct sockaddr_in *)addr;
2371 if (sin->sin_addr.s_addr != INADDR_ANY) {
2373 SCTP_TCB_UNLOCK(stcb);
2374 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2380 if (addr->sa_family == AF_INET6) {
2381 struct sockaddr_in6 *sin6;
2383 sin6 = (struct sockaddr_in6 *)addr;
2384 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2386 SCTP_TCB_UNLOCK(stcb);
2387 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2393 error = EAFNOSUPPORT;
2394 SCTP_TCB_UNLOCK(stcb);
2395 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2400 /* Applies to the specific association */
2401 paddrp->spp_flags = 0;
2403 paddrp->spp_hbinterval = net->heart_beat_delay;
2404 paddrp->spp_pathmaxrxt = net->failure_threshold;
2405 paddrp->spp_pathmtu = net->mtu;
2406 switch (net->ro._l_addr.sa.sa_family) {
2409 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2414 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2420 /* get flags for HB */
2421 if (net->dest_state & SCTP_ADDR_NOHB) {
2422 paddrp->spp_flags |= SPP_HB_DISABLE;
2424 paddrp->spp_flags |= SPP_HB_ENABLE;
2426 /* get flags for PMTU */
2427 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2428 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2430 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2432 if (net->dscp & 0x01) {
2433 paddrp->spp_dscp = net->dscp & 0xfc;
2434 paddrp->spp_flags |= SPP_DSCP;
2437 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2438 (net->flowlabel & 0x80000000)) {
2439 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2440 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2445 * No destination so return default
2448 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2449 paddrp->spp_pathmtu = 0;
2450 if (stcb->asoc.default_dscp & 0x01) {
2451 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2452 paddrp->spp_flags |= SPP_DSCP;
2455 if (stcb->asoc.default_flowlabel & 0x80000000) {
2456 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2457 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2460 /* default settings should be these */
2461 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2462 paddrp->spp_flags |= SPP_HB_DISABLE;
2464 paddrp->spp_flags |= SPP_HB_ENABLE;
2466 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2467 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2469 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2471 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2473 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2474 SCTP_TCB_UNLOCK(stcb);
2476 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2477 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2478 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2479 /* Use endpoint defaults */
2480 SCTP_INP_RLOCK(inp);
2481 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2482 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2483 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2484 /* get inp's default */
2485 if (inp->sctp_ep.default_dscp & 0x01) {
2486 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2487 paddrp->spp_flags |= SPP_DSCP;
2490 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2491 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2492 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2493 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2496 /* can't return this */
2497 paddrp->spp_pathmtu = 0;
2499 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2500 paddrp->spp_flags |= SPP_HB_ENABLE;
2502 paddrp->spp_flags |= SPP_HB_DISABLE;
2504 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2505 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2507 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2509 SCTP_INP_RUNLOCK(inp);
2511 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2516 *optsize = sizeof(struct sctp_paddrparams);
2520 case SCTP_GET_PEER_ADDR_INFO:
2522 struct sctp_paddrinfo *paddri;
2523 struct sctp_nets *net;
2524 struct sockaddr *addr;
2525 #if defined(INET) && defined(INET6)
2526 struct sockaddr_in sin_store;
2529 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2530 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2532 #if defined(INET) && defined(INET6)
2533 if (paddri->spinfo_address.ss_family == AF_INET6) {
2534 struct sockaddr_in6 *sin6;
2536 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2537 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2538 in6_sin6_2_sin(&sin_store, sin6);
2539 addr = (struct sockaddr *)&sin_store;
2541 addr = (struct sockaddr *)&paddri->spinfo_address;
2544 addr = (struct sockaddr *)&paddri->spinfo_address;
2547 addr = (struct sockaddr *)&paddri->spinfo_address;
2550 net = sctp_findnet(stcb, addr);
2553 * We increment here since
2554 * sctp_findassociation_ep_addr() wil do a
2555 * decrement if it finds the stcb as long as
2556 * the locked tcb (last argument) is NOT a
2560 SCTP_INP_INCR_REF(inp);
2561 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2563 SCTP_INP_DECR_REF(inp);
2567 if ((stcb != NULL) && (net != NULL)) {
2568 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2569 /* It's unconfirmed */
2570 paddri->spinfo_state = SCTP_UNCONFIRMED;
2571 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2573 paddri->spinfo_state = SCTP_ACTIVE;
2576 paddri->spinfo_state = SCTP_INACTIVE;
2578 paddri->spinfo_cwnd = net->cwnd;
2579 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2580 paddri->spinfo_rto = net->RTO;
2581 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2582 paddri->spinfo_mtu = net->mtu;
2583 switch (addr->sa_family) {
2586 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2591 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2597 SCTP_TCB_UNLOCK(stcb);
2598 *optsize = sizeof(struct sctp_paddrinfo);
2601 SCTP_TCB_UNLOCK(stcb);
2603 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2608 case SCTP_PCB_STATUS:
2610 struct sctp_pcbinfo *spcb;
2612 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2613 sctp_fill_pcbinfo(spcb);
2614 *optsize = sizeof(struct sctp_pcbinfo);
2619 struct sctp_nets *net;
2620 struct sctp_status *sstat;
2622 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2623 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2626 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2630 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2631 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2632 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2633 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2635 * We can't include chunks that have been passed to
2636 * the socket layer. Only things in queue.
2638 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2639 stcb->asoc.cnt_on_all_streams);
2642 sstat->sstat_instrms = stcb->asoc.streamincnt;
2643 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2644 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2645 memcpy(&sstat->sstat_primary.spinfo_address,
2646 &stcb->asoc.primary_destination->ro._l_addr,
2647 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2648 net = stcb->asoc.primary_destination;
2649 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2651 * Again the user can get info from sctp_constants.h
2652 * for what the state of the network is.
2654 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2655 /* It's unconfirmed */
2656 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2657 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2659 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2662 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2664 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2665 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2666 sstat->sstat_primary.spinfo_rto = net->RTO;
2667 sstat->sstat_primary.spinfo_mtu = net->mtu;
2668 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2671 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2676 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2682 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2683 SCTP_TCB_UNLOCK(stcb);
2684 *optsize = sizeof(struct sctp_status);
2689 struct sctp_rtoinfo *srto;
2691 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2692 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2695 srto->srto_initial = stcb->asoc.initial_rto;
2696 srto->srto_max = stcb->asoc.maxrto;
2697 srto->srto_min = stcb->asoc.minrto;
2698 SCTP_TCB_UNLOCK(stcb);
2700 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2701 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2702 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2703 SCTP_INP_RLOCK(inp);
2704 srto->srto_initial = inp->sctp_ep.initial_rto;
2705 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2706 srto->srto_min = inp->sctp_ep.sctp_minrto;
2707 SCTP_INP_RUNLOCK(inp);
2709 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2714 *optsize = sizeof(struct sctp_rtoinfo);
2720 struct sctp_timeouts *stimo;
2722 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2723 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2726 stimo->stimo_init = stcb->asoc.timoinit;
2727 stimo->stimo_data = stcb->asoc.timodata;
2728 stimo->stimo_sack = stcb->asoc.timosack;
2729 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2730 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2731 stimo->stimo_cookie = stcb->asoc.timocookie;
2732 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2733 SCTP_TCB_UNLOCK(stcb);
2734 *optsize = sizeof(struct sctp_timeouts);
2736 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2741 case SCTP_ASSOCINFO:
2743 struct sctp_assocparams *sasoc;
2745 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2746 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2749 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2750 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2751 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2752 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2753 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2754 SCTP_TCB_UNLOCK(stcb);
2756 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2757 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2758 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2759 SCTP_INP_RLOCK(inp);
2760 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2761 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2762 sasoc->sasoc_number_peer_destinations = 0;
2763 sasoc->sasoc_peer_rwnd = 0;
2764 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2765 SCTP_INP_RUNLOCK(inp);
2767 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2772 *optsize = sizeof(struct sctp_assocparams);
2776 case SCTP_DEFAULT_SEND_PARAM:
2778 struct sctp_sndrcvinfo *s_info;
2780 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2781 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2784 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2785 SCTP_TCB_UNLOCK(stcb);
2787 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2788 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2789 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2790 SCTP_INP_RLOCK(inp);
2791 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2792 SCTP_INP_RUNLOCK(inp);
2794 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2799 *optsize = sizeof(struct sctp_sndrcvinfo);
2805 struct sctp_initmsg *sinit;
2807 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2808 SCTP_INP_RLOCK(inp);
2809 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2810 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2811 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2812 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2813 SCTP_INP_RUNLOCK(inp);
2814 *optsize = sizeof(struct sctp_initmsg);
2817 case SCTP_PRIMARY_ADDR:
2818 /* we allow a "get" operation on this */
2820 struct sctp_setprim *ssp;
2822 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2823 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2826 union sctp_sockstore *addr;
2828 addr = &stcb->asoc.primary_destination->ro._l_addr;
2829 switch (addr->sa.sa_family) {
2833 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2834 in6_sin_2_v4mapsin6(&addr->sin,
2835 (struct sockaddr_in6 *)&ssp->ssp_addr);
2837 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2840 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2846 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2852 SCTP_TCB_UNLOCK(stcb);
2853 *optsize = sizeof(struct sctp_setprim);
2855 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2860 case SCTP_HMAC_IDENT:
2862 struct sctp_hmacalgo *shmac;
2863 sctp_hmaclist_t *hmaclist;
2867 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2869 SCTP_INP_RLOCK(inp);
2870 hmaclist = inp->sctp_ep.local_hmacs;
2871 if (hmaclist == NULL) {
2872 /* no HMACs to return */
2873 *optsize = sizeof(*shmac);
2874 SCTP_INP_RUNLOCK(inp);
2877 /* is there room for all of the hmac ids? */
2878 size = sizeof(*shmac) + (hmaclist->num_algo *
2879 sizeof(shmac->shmac_idents[0]));
2880 if ((size_t)(*optsize) < size) {
2881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2883 SCTP_INP_RUNLOCK(inp);
2886 /* copy in the list */
2887 shmac->shmac_number_of_idents = hmaclist->num_algo;
2888 for (i = 0; i < hmaclist->num_algo; i++) {
2889 shmac->shmac_idents[i] = hmaclist->hmac[i];
2891 SCTP_INP_RUNLOCK(inp);
2895 case SCTP_AUTH_ACTIVE_KEY:
2897 struct sctp_authkeyid *scact;
2899 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2900 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2903 /* get the active key on the assoc */
2904 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2905 SCTP_TCB_UNLOCK(stcb);
2907 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2908 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2909 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2910 /* get the endpoint active key */
2911 SCTP_INP_RLOCK(inp);
2912 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2913 SCTP_INP_RUNLOCK(inp);
2915 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2920 *optsize = sizeof(struct sctp_authkeyid);
2924 case SCTP_LOCAL_AUTH_CHUNKS:
2926 struct sctp_authchunks *sac;
2927 sctp_auth_chklist_t *chklist = NULL;
2930 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2931 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2934 /* get off the assoc */
2935 chklist = stcb->asoc.local_auth_chunks;
2936 /* is there enough space? */
2937 size = sctp_auth_get_chklist_size(chklist);
2938 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2940 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2942 /* copy in the chunks */
2943 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2944 sac->gauth_number_of_chunks = (uint32_t)size;
2945 *optsize = sizeof(struct sctp_authchunks) + size;
2947 SCTP_TCB_UNLOCK(stcb);
2949 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2950 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2951 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2952 /* get off the endpoint */
2953 SCTP_INP_RLOCK(inp);
2954 chklist = inp->sctp_ep.local_auth_chunks;
2955 /* is there enough space? */
2956 size = sctp_auth_get_chklist_size(chklist);
2957 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2959 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2961 /* copy in the chunks */
2962 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2963 sac->gauth_number_of_chunks = (uint32_t)size;
2964 *optsize = sizeof(struct sctp_authchunks) + size;
2966 SCTP_INP_RUNLOCK(inp);
2968 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2974 case SCTP_PEER_AUTH_CHUNKS:
2976 struct sctp_authchunks *sac;
2977 sctp_auth_chklist_t *chklist = NULL;
2980 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2981 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2984 /* get off the assoc */
2985 chklist = stcb->asoc.peer_auth_chunks;
2986 /* is there enough space? */
2987 size = sctp_auth_get_chklist_size(chklist);
2988 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2990 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2992 /* copy in the chunks */
2993 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2994 sac->gauth_number_of_chunks = (uint32_t)size;
2995 *optsize = sizeof(struct sctp_authchunks) + size;
2997 SCTP_TCB_UNLOCK(stcb);
2999 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3006 struct sctp_event *event;
3007 uint32_t event_type;
3009 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3010 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3012 switch (event->se_type) {
3013 case SCTP_ASSOC_CHANGE:
3014 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3016 case SCTP_PEER_ADDR_CHANGE:
3017 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3019 case SCTP_REMOTE_ERROR:
3020 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3022 case SCTP_SEND_FAILED:
3023 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3025 case SCTP_SHUTDOWN_EVENT:
3026 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3028 case SCTP_ADAPTATION_INDICATION:
3029 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3031 case SCTP_PARTIAL_DELIVERY_EVENT:
3032 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3034 case SCTP_AUTHENTICATION_EVENT:
3035 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3037 case SCTP_STREAM_RESET_EVENT:
3038 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3040 case SCTP_SENDER_DRY_EVENT:
3041 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3043 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3045 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3048 case SCTP_ASSOC_RESET_EVENT:
3049 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3051 case SCTP_STREAM_CHANGE_EVENT:
3052 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3054 case SCTP_SEND_FAILED_EVENT:
3055 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3059 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3063 if (event_type > 0) {
3065 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3066 SCTP_TCB_UNLOCK(stcb);
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 *optsize = sizeof(struct sctp_event);
3085 case SCTP_RECVRCVINFO:
3089 if (*optsize < sizeof(int)) {
3090 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3093 SCTP_INP_RLOCK(inp);
3094 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3095 SCTP_INP_RUNLOCK(inp);
3098 /* return the option value */
3099 *(int *)optval = onoff;
3100 *optsize = sizeof(int);
3104 case SCTP_RECVNXTINFO:
3108 if (*optsize < sizeof(int)) {
3109 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3112 SCTP_INP_RLOCK(inp);
3113 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3114 SCTP_INP_RUNLOCK(inp);
3117 /* return the option value */
3118 *(int *)optval = onoff;
3119 *optsize = sizeof(int);
3123 case SCTP_DEFAULT_SNDINFO:
3125 struct sctp_sndinfo *info;
3127 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3128 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3131 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3132 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3133 info->snd_flags &= 0xfff0;
3134 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3135 info->snd_context = stcb->asoc.def_send.sinfo_context;
3136 SCTP_TCB_UNLOCK(stcb);
3138 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3139 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3140 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3141 SCTP_INP_RLOCK(inp);
3142 info->snd_sid = inp->def_send.sinfo_stream;
3143 info->snd_flags = inp->def_send.sinfo_flags;
3144 info->snd_flags &= 0xfff0;
3145 info->snd_ppid = inp->def_send.sinfo_ppid;
3146 info->snd_context = inp->def_send.sinfo_context;
3147 SCTP_INP_RUNLOCK(inp);
3149 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3154 *optsize = sizeof(struct sctp_sndinfo);
3158 case SCTP_DEFAULT_PRINFO:
3160 struct sctp_default_prinfo *info;
3162 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3163 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3166 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3167 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3168 SCTP_TCB_UNLOCK(stcb);
3170 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3171 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3172 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3173 SCTP_INP_RLOCK(inp);
3174 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3175 info->pr_value = inp->def_send.sinfo_timetolive;
3176 SCTP_INP_RUNLOCK(inp);
3178 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3183 *optsize = sizeof(struct sctp_default_prinfo);
3187 case SCTP_PEER_ADDR_THLDS:
3189 struct sctp_paddrthlds *thlds;
3190 struct sctp_nets *net;
3191 struct sockaddr *addr;
3192 #if defined(INET) && defined(INET6)
3193 struct sockaddr_in sin_store;
3196 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3197 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3199 #if defined(INET) && defined(INET6)
3200 if (thlds->spt_address.ss_family == AF_INET6) {
3201 struct sockaddr_in6 *sin6;
3203 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3204 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3205 in6_sin6_2_sin(&sin_store, sin6);
3206 addr = (struct sockaddr *)&sin_store;
3208 addr = (struct sockaddr *)&thlds->spt_address;
3211 addr = (struct sockaddr *)&thlds->spt_address;
3214 addr = (struct sockaddr *)&thlds->spt_address;
3217 net = sctp_findnet(stcb, addr);
3220 * We increment here since
3221 * sctp_findassociation_ep_addr() wil do a
3222 * decrement if it finds the stcb as long as
3223 * the locked tcb (last argument) is NOT a
3227 SCTP_INP_INCR_REF(inp);
3228 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3230 SCTP_INP_DECR_REF(inp);
3233 if ((stcb != NULL) && (net == NULL)) {
3235 if (addr->sa_family == AF_INET) {
3236 struct sockaddr_in *sin;
3238 sin = (struct sockaddr_in *)addr;
3239 if (sin->sin_addr.s_addr != INADDR_ANY) {
3241 SCTP_TCB_UNLOCK(stcb);
3242 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3248 if (addr->sa_family == AF_INET6) {
3249 struct sockaddr_in6 *sin6;
3251 sin6 = (struct sockaddr_in6 *)addr;
3252 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3254 SCTP_TCB_UNLOCK(stcb);
3255 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3261 error = EAFNOSUPPORT;
3262 SCTP_TCB_UNLOCK(stcb);
3263 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3269 thlds->spt_pathmaxrxt = net->failure_threshold;
3270 thlds->spt_pathpfthld = net->pf_threshold;
3271 thlds->spt_pathcpthld = 0xffff;
3273 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3274 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3275 thlds->spt_pathcpthld = 0xffff;
3277 thlds->spt_assoc_id = sctp_get_associd(stcb);
3278 SCTP_TCB_UNLOCK(stcb);
3280 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3281 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3282 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3283 /* Use endpoint defaults */
3284 SCTP_INP_RLOCK(inp);
3285 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3286 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3287 thlds->spt_pathcpthld = 0xffff;
3288 SCTP_INP_RUNLOCK(inp);
3290 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3295 *optsize = sizeof(struct sctp_paddrthlds);
3299 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3301 struct sctp_udpencaps *encaps;
3302 struct sctp_nets *net;
3303 struct sockaddr *addr;
3304 #if defined(INET) && defined(INET6)
3305 struct sockaddr_in sin_store;
3308 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3309 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3311 #if defined(INET) && defined(INET6)
3312 if (encaps->sue_address.ss_family == AF_INET6) {
3313 struct sockaddr_in6 *sin6;
3315 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3316 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3317 in6_sin6_2_sin(&sin_store, sin6);
3318 addr = (struct sockaddr *)&sin_store;
3320 addr = (struct sockaddr *)&encaps->sue_address;
3323 addr = (struct sockaddr *)&encaps->sue_address;
3326 addr = (struct sockaddr *)&encaps->sue_address;
3329 net = sctp_findnet(stcb, addr);
3332 * We increment here since
3333 * sctp_findassociation_ep_addr() wil do a
3334 * decrement if it finds the stcb as long as
3335 * the locked tcb (last argument) is NOT a
3339 SCTP_INP_INCR_REF(inp);
3340 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3342 SCTP_INP_DECR_REF(inp);
3345 if ((stcb != NULL) && (net == NULL)) {
3347 if (addr->sa_family == AF_INET) {
3348 struct sockaddr_in *sin;
3350 sin = (struct sockaddr_in *)addr;
3351 if (sin->sin_addr.s_addr != INADDR_ANY) {
3353 SCTP_TCB_UNLOCK(stcb);
3354 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3360 if (addr->sa_family == AF_INET6) {
3361 struct sockaddr_in6 *sin6;
3363 sin6 = (struct sockaddr_in6 *)addr;
3364 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3366 SCTP_TCB_UNLOCK(stcb);
3367 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3373 error = EAFNOSUPPORT;
3374 SCTP_TCB_UNLOCK(stcb);
3375 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3381 encaps->sue_port = net->port;
3383 encaps->sue_port = stcb->asoc.port;
3385 SCTP_TCB_UNLOCK(stcb);
3387 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3388 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3389 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3390 SCTP_INP_RLOCK(inp);
3391 encaps->sue_port = inp->sctp_ep.port;
3392 SCTP_INP_RUNLOCK(inp);
3394 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3399 *optsize = sizeof(struct sctp_udpencaps);
3403 case SCTP_ECN_SUPPORTED:
3405 struct sctp_assoc_value *av;
3407 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3408 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3411 av->assoc_value = stcb->asoc.ecn_supported;
3412 SCTP_TCB_UNLOCK(stcb);
3414 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3415 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3416 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3417 SCTP_INP_RLOCK(inp);
3418 av->assoc_value = inp->ecn_supported;
3419 SCTP_INP_RUNLOCK(inp);
3421 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3426 *optsize = sizeof(struct sctp_assoc_value);
3430 case SCTP_PR_SUPPORTED:
3432 struct sctp_assoc_value *av;
3434 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3435 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3438 av->assoc_value = stcb->asoc.prsctp_supported;
3439 SCTP_TCB_UNLOCK(stcb);
3441 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3442 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3443 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3444 SCTP_INP_RLOCK(inp);
3445 av->assoc_value = inp->prsctp_supported;
3446 SCTP_INP_RUNLOCK(inp);
3448 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3453 *optsize = sizeof(struct sctp_assoc_value);
3457 case SCTP_AUTH_SUPPORTED:
3459 struct sctp_assoc_value *av;
3461 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3462 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3465 av->assoc_value = stcb->asoc.auth_supported;
3466 SCTP_TCB_UNLOCK(stcb);
3468 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3469 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3470 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3471 SCTP_INP_RLOCK(inp);
3472 av->assoc_value = inp->auth_supported;
3473 SCTP_INP_RUNLOCK(inp);
3475 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3480 *optsize = sizeof(struct sctp_assoc_value);
3484 case SCTP_ASCONF_SUPPORTED:
3486 struct sctp_assoc_value *av;
3488 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3489 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3492 av->assoc_value = stcb->asoc.asconf_supported;
3493 SCTP_TCB_UNLOCK(stcb);
3495 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3496 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3497 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3498 SCTP_INP_RLOCK(inp);
3499 av->assoc_value = inp->asconf_supported;
3500 SCTP_INP_RUNLOCK(inp);
3502 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3507 *optsize = sizeof(struct sctp_assoc_value);
3511 case SCTP_RECONFIG_SUPPORTED:
3513 struct sctp_assoc_value *av;
3515 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3516 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3519 av->assoc_value = stcb->asoc.reconfig_supported;
3520 SCTP_TCB_UNLOCK(stcb);
3522 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3523 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3524 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3525 SCTP_INP_RLOCK(inp);
3526 av->assoc_value = inp->reconfig_supported;
3527 SCTP_INP_RUNLOCK(inp);
3529 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3534 *optsize = sizeof(struct sctp_assoc_value);
3538 case SCTP_NRSACK_SUPPORTED:
3540 struct sctp_assoc_value *av;
3542 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3543 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3546 av->assoc_value = stcb->asoc.nrsack_supported;
3547 SCTP_TCB_UNLOCK(stcb);
3549 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3550 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3551 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3552 SCTP_INP_RLOCK(inp);
3553 av->assoc_value = inp->nrsack_supported;
3554 SCTP_INP_RUNLOCK(inp);
3556 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3561 *optsize = sizeof(struct sctp_assoc_value);
3565 case SCTP_PKTDROP_SUPPORTED:
3567 struct sctp_assoc_value *av;
3569 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3570 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3573 av->assoc_value = stcb->asoc.pktdrop_supported;
3574 SCTP_TCB_UNLOCK(stcb);
3576 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3577 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3578 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3579 SCTP_INP_RLOCK(inp);
3580 av->assoc_value = inp->pktdrop_supported;
3581 SCTP_INP_RUNLOCK(inp);
3583 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3588 *optsize = sizeof(struct sctp_assoc_value);
3592 case SCTP_ENABLE_STREAM_RESET:
3594 struct sctp_assoc_value *av;
3596 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3597 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3600 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3601 SCTP_TCB_UNLOCK(stcb);
3603 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3604 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3605 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3606 SCTP_INP_RLOCK(inp);
3607 av->assoc_value = (uint32_t)inp->local_strreset_support;
3608 SCTP_INP_RUNLOCK(inp);
3610 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3615 *optsize = sizeof(struct sctp_assoc_value);
3619 case SCTP_PR_STREAM_STATUS:
3621 struct sctp_prstatus *sprstat;
3625 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3626 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3628 sid = sprstat->sprstat_sid;
3629 policy = sprstat->sprstat_policy;
3630 #if defined(SCTP_DETAILED_STR_STATS)
3631 if ((stcb != NULL) &&
3632 (sid < stcb->asoc.streamoutcnt) &&
3633 (policy != SCTP_PR_SCTP_NONE) &&
3634 ((policy <= SCTP_PR_SCTP_MAX) ||
3635 (policy == SCTP_PR_SCTP_ALL))) {
3636 if (policy == SCTP_PR_SCTP_ALL) {
3637 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3638 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3640 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3641 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3644 if ((stcb != NULL) &&
3645 (sid < stcb->asoc.streamoutcnt) &&
3646 (policy == SCTP_PR_SCTP_ALL)) {
3647 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3648 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3650 SCTP_TCB_UNLOCK(stcb);
3651 *optsize = sizeof(struct sctp_prstatus);
3653 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3658 case SCTP_PR_ASSOC_STATUS:
3660 struct sctp_prstatus *sprstat;
3663 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3664 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3666 policy = sprstat->sprstat_policy;
3667 if ((stcb != NULL) &&
3668 (policy != SCTP_PR_SCTP_NONE) &&
3669 ((policy <= SCTP_PR_SCTP_MAX) ||
3670 (policy == SCTP_PR_SCTP_ALL))) {
3671 if (policy == SCTP_PR_SCTP_ALL) {
3672 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3673 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3675 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3676 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3678 SCTP_TCB_UNLOCK(stcb);
3679 *optsize = sizeof(struct sctp_prstatus);
3681 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3688 struct sctp_assoc_value *av;
3690 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3691 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3694 av->assoc_value = stcb->asoc.max_cwnd;
3695 SCTP_TCB_UNLOCK(stcb);
3697 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3698 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3699 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3700 SCTP_INP_RLOCK(inp);
3701 av->assoc_value = inp->max_cwnd;
3702 SCTP_INP_RUNLOCK(inp);
3704 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3709 *optsize = sizeof(struct sctp_assoc_value);
3714 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3715 error = ENOPROTOOPT;
3717 } /* end switch (sopt->sopt_name) */
3725 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3730 struct sctp_tcb *stcb = NULL;
3731 struct sctp_inpcb *inp = NULL;
3734 if (optval == NULL) {
3735 SCTP_PRINTF("optval is NULL\n");
3736 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3739 inp = (struct sctp_inpcb *)so->so_pcb;
3741 SCTP_PRINTF("inp is NULL?\n");
3742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3745 vrf_id = inp->def_vrf_id;
3750 case SCTP_AUTOCLOSE:
3751 case SCTP_AUTO_ASCONF:
3752 case SCTP_EXPLICIT_EOR:
3753 case SCTP_DISABLE_FRAGMENTS:
3754 case SCTP_USE_EXT_RCVINFO:
3755 case SCTP_I_WANT_MAPPED_V4_ADDR:
3756 /* copy in the option value */
3757 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3762 case SCTP_DISABLE_FRAGMENTS:
3763 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3765 case SCTP_AUTO_ASCONF:
3767 * NOTE: we don't really support this flag
3769 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3770 /* only valid for bound all sockets */
3771 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3773 /* forbidden by admin */
3774 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3777 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3779 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3783 case SCTP_EXPLICIT_EOR:
3784 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3786 case SCTP_USE_EXT_RCVINFO:
3787 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3789 case SCTP_I_WANT_MAPPED_V4_ADDR:
3790 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3791 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3793 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3798 set_opt = SCTP_PCB_FLAGS_NODELAY;
3800 case SCTP_AUTOCLOSE:
3801 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3802 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3803 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3806 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3808 * The value is in ticks. Note this does not effect
3809 * old associations, only new ones.
3811 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3814 SCTP_INP_WLOCK(inp);
3816 sctp_feature_on(inp, set_opt);
3818 sctp_feature_off(inp, set_opt);
3820 SCTP_INP_WUNLOCK(inp);
3822 case SCTP_REUSE_PORT:
3824 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3825 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3826 /* Can't set it after we are bound */
3830 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3831 /* Can't do this for a 1-m socket */
3836 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3838 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3841 case SCTP_PARTIAL_DELIVERY_POINT:
3845 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3846 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3847 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3851 inp->partial_delivery_point = *value;
3854 case SCTP_FRAGMENT_INTERLEAVE:
3855 /* not yet until we re-write sctp_recvmsg() */
3859 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3860 if (*level == SCTP_FRAG_LEVEL_2) {
3861 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3862 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3863 } else if (*level == SCTP_FRAG_LEVEL_1) {
3864 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3865 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3866 } else if (*level == SCTP_FRAG_LEVEL_0) {
3867 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3868 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3871 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3876 case SCTP_INTERLEAVING_SUPPORTED:
3878 struct sctp_assoc_value *av;
3880 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3881 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3884 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3886 SCTP_TCB_UNLOCK(stcb);
3888 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3889 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3890 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3891 SCTP_INP_WLOCK(inp);
3892 if (av->assoc_value == 0) {
3893 inp->idata_supported = 0;
3895 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3896 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3897 inp->idata_supported = 1;
3905 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3909 SCTP_INP_WUNLOCK(inp);
3911 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3917 case SCTP_CMT_ON_OFF:
3918 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3919 struct sctp_assoc_value *av;
3921 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3922 if (av->assoc_value > SCTP_CMT_MAX) {
3923 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3927 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3929 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3930 SCTP_TCB_UNLOCK(stcb);
3932 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3933 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3934 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3935 (av->assoc_id == SCTP_ALL_ASSOC)) {
3936 SCTP_INP_WLOCK(inp);
3937 inp->sctp_cmt_on_off = av->assoc_value;
3938 SCTP_INP_WUNLOCK(inp);
3940 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3941 (av->assoc_id == SCTP_ALL_ASSOC)) {
3942 SCTP_INP_RLOCK(inp);
3943 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3944 SCTP_TCB_LOCK(stcb);
3945 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3946 SCTP_TCB_UNLOCK(stcb);
3948 SCTP_INP_RUNLOCK(inp);
3952 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3953 error = ENOPROTOOPT;
3956 case SCTP_PLUGGABLE_CC:
3958 struct sctp_assoc_value *av;
3959 struct sctp_nets *net;
3961 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3962 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3963 (av->assoc_value != SCTP_CC_HSTCP) &&
3964 (av->assoc_value != SCTP_CC_HTCP) &&
3965 (av->assoc_value != SCTP_CC_RTCC)) {
3966 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3970 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3972 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3973 stcb->asoc.congestion_control_module = av->assoc_value;
3974 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3975 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3976 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3979 SCTP_TCB_UNLOCK(stcb);
3981 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3982 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3983 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3984 (av->assoc_id == SCTP_ALL_ASSOC)) {
3985 SCTP_INP_WLOCK(inp);
3986 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3987 SCTP_INP_WUNLOCK(inp);
3989 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3990 (av->assoc_id == SCTP_ALL_ASSOC)) {
3991 SCTP_INP_RLOCK(inp);
3992 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3993 SCTP_TCB_LOCK(stcb);
3994 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3995 stcb->asoc.congestion_control_module = av->assoc_value;
3996 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3997 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3998 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4001 SCTP_TCB_UNLOCK(stcb);
4003 SCTP_INP_RUNLOCK(inp);
4008 case SCTP_CC_OPTION:
4010 struct sctp_cc_option *cc_opt;
4012 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4013 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4015 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
4016 SCTP_INP_RLOCK(inp);
4017 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4018 SCTP_TCB_LOCK(stcb);
4019 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4020 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4022 SCTP_TCB_UNLOCK(stcb);
4024 SCTP_INP_RUNLOCK(inp);
4029 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4032 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4035 SCTP_TCB_UNLOCK(stcb);
4039 case SCTP_PLUGGABLE_SS:
4041 struct sctp_assoc_value *av;
4043 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4044 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4045 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4046 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4047 (av->assoc_value != SCTP_SS_PRIORITY) &&
4048 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4049 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4050 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4054 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4056 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4057 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4058 stcb->asoc.stream_scheduling_module = av->assoc_value;
4059 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4060 SCTP_TCB_UNLOCK(stcb);
4062 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4063 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4064 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4065 (av->assoc_id == SCTP_ALL_ASSOC)) {
4066 SCTP_INP_WLOCK(inp);
4067 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4068 SCTP_INP_WUNLOCK(inp);
4070 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4071 (av->assoc_id == SCTP_ALL_ASSOC)) {
4072 SCTP_INP_RLOCK(inp);
4073 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4074 SCTP_TCB_LOCK(stcb);
4075 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4076 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4077 stcb->asoc.stream_scheduling_module = av->assoc_value;
4078 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4079 SCTP_TCB_UNLOCK(stcb);
4081 SCTP_INP_RUNLOCK(inp);
4088 struct sctp_stream_value *av;
4090 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4091 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4093 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4094 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4095 av->stream_value) < 0)) {
4096 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4099 SCTP_TCB_UNLOCK(stcb);
4101 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4102 SCTP_INP_RLOCK(inp);
4103 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4104 SCTP_TCB_LOCK(stcb);
4105 if (av->stream_id < stcb->asoc.streamoutcnt) {
4106 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4108 &stcb->asoc.strmout[av->stream_id],
4111 SCTP_TCB_UNLOCK(stcb);
4113 SCTP_INP_RUNLOCK(inp);
4116 * Can't set stream value without
4119 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4125 case SCTP_CLR_STAT_LOG:
4126 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4131 struct sctp_assoc_value *av;
4133 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4134 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4137 stcb->asoc.context = av->assoc_value;
4138 SCTP_TCB_UNLOCK(stcb);
4140 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4141 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4142 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4143 (av->assoc_id == SCTP_ALL_ASSOC)) {
4144 SCTP_INP_WLOCK(inp);
4145 inp->sctp_context = av->assoc_value;
4146 SCTP_INP_WUNLOCK(inp);
4148 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4149 (av->assoc_id == SCTP_ALL_ASSOC)) {
4150 SCTP_INP_RLOCK(inp);
4151 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4152 SCTP_TCB_LOCK(stcb);
4153 stcb->asoc.context = av->assoc_value;
4154 SCTP_TCB_UNLOCK(stcb);
4156 SCTP_INP_RUNLOCK(inp);
4163 uint32_t *default_vrfid;
4165 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4166 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4167 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4171 inp->def_vrf_id = *default_vrfid;
4174 case SCTP_DEL_VRF_ID:
4176 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4180 case SCTP_ADD_VRF_ID:
4182 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4186 case SCTP_DELAYED_SACK:
4188 struct sctp_sack_info *sack;
4190 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4191 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4192 if (sack->sack_delay) {
4193 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4194 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4195 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4196 sack->sack_delay = TICKS_TO_MSEC(1);
4200 if (sack->sack_delay) {
4201 stcb->asoc.delayed_ack = sack->sack_delay;
4203 if (sack->sack_freq) {
4204 stcb->asoc.sack_freq = sack->sack_freq;
4206 SCTP_TCB_UNLOCK(stcb);
4208 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4209 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4210 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4211 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4212 SCTP_INP_WLOCK(inp);
4213 if (sack->sack_delay) {
4214 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4216 if (sack->sack_freq) {
4217 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4219 SCTP_INP_WUNLOCK(inp);
4221 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4222 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4223 SCTP_INP_RLOCK(inp);
4224 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4225 SCTP_TCB_LOCK(stcb);
4226 if (sack->sack_delay) {
4227 stcb->asoc.delayed_ack = sack->sack_delay;
4229 if (sack->sack_freq) {
4230 stcb->asoc.sack_freq = sack->sack_freq;
4232 SCTP_TCB_UNLOCK(stcb);
4234 SCTP_INP_RUNLOCK(inp);
4239 case SCTP_AUTH_CHUNK:
4241 struct sctp_authchunk *sauth;
4243 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4245 SCTP_INP_WLOCK(inp);
4246 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4247 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4250 SCTP_INP_WUNLOCK(inp);
4255 struct sctp_authkey *sca;
4256 struct sctp_keyhead *shared_keys;
4257 sctp_sharedkey_t *shared_key;
4258 sctp_key_t *key = NULL;
4261 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4262 if (sca->sca_keylength == 0) {
4263 size = optsize - sizeof(struct sctp_authkey);
4265 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4266 size = sca->sca_keylength;
4268 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4273 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4276 shared_keys = &stcb->asoc.shared_keys;
4277 /* clear the cached keys for this key id */
4278 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4280 * create the new shared key and
4284 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4286 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4288 SCTP_TCB_UNLOCK(stcb);
4292 shared_key = sctp_alloc_sharedkey();
4293 if (shared_key == NULL) {
4295 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4297 SCTP_TCB_UNLOCK(stcb);
4300 shared_key->key = key;
4301 shared_key->keyid = sca->sca_keynumber;
4302 error = sctp_insert_sharedkey(shared_keys, shared_key);
4303 SCTP_TCB_UNLOCK(stcb);
4305 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4306 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4307 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4308 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4309 SCTP_INP_WLOCK(inp);
4310 shared_keys = &inp->sctp_ep.shared_keys;
4312 * clear the cached keys on all
4313 * assocs for this key id
4315 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4317 * create the new shared key and
4321 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4323 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4325 SCTP_INP_WUNLOCK(inp);
4329 shared_key = sctp_alloc_sharedkey();
4330 if (shared_key == NULL) {
4332 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4334 SCTP_INP_WUNLOCK(inp);
4337 shared_key->key = key;
4338 shared_key->keyid = sca->sca_keynumber;
4339 error = sctp_insert_sharedkey(shared_keys, shared_key);
4340 SCTP_INP_WUNLOCK(inp);
4342 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4343 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4344 SCTP_INP_RLOCK(inp);
4345 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4346 SCTP_TCB_LOCK(stcb);
4347 shared_keys = &stcb->asoc.shared_keys;
4349 * clear the cached keys for
4352 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4354 * create the new shared key
4355 * and insert/replace it
4358 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4360 SCTP_TCB_UNLOCK(stcb);
4364 shared_key = sctp_alloc_sharedkey();
4365 if (shared_key == NULL) {
4367 SCTP_TCB_UNLOCK(stcb);
4370 shared_key->key = key;
4371 shared_key->keyid = sca->sca_keynumber;
4372 error = sctp_insert_sharedkey(shared_keys, shared_key);
4373 SCTP_TCB_UNLOCK(stcb);
4375 SCTP_INP_RUNLOCK(inp);
4380 case SCTP_HMAC_IDENT:
4382 struct sctp_hmacalgo *shmac;
4383 sctp_hmaclist_t *hmaclist;
4387 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4388 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4389 (shmac->shmac_number_of_idents > 0xffff)) {
4390 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4394 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4395 if (hmaclist == NULL) {
4396 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4400 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4401 hmacid = shmac->shmac_idents[i];
4402 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4403 /* invalid HMACs were found */ ;
4404 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4406 sctp_free_hmaclist(hmaclist);
4407 goto sctp_set_hmac_done;
4410 for (i = 0; i < hmaclist->num_algo; i++) {
4411 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4412 /* already in list */
4416 if (i == hmaclist->num_algo) {
4417 /* not found in list */
4418 sctp_free_hmaclist(hmaclist);
4419 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4423 /* set it on the endpoint */
4424 SCTP_INP_WLOCK(inp);
4425 if (inp->sctp_ep.local_hmacs)
4426 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4427 inp->sctp_ep.local_hmacs = hmaclist;
4428 SCTP_INP_WUNLOCK(inp);
4432 case SCTP_AUTH_ACTIVE_KEY:
4434 struct sctp_authkeyid *scact;
4436 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4437 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4439 /* set the active key on the right place */
4441 /* set the active key on the assoc */
4442 if (sctp_auth_setactivekey(stcb,
4443 scact->scact_keynumber)) {
4444 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4445 SCTP_FROM_SCTP_USRREQ,
4449 SCTP_TCB_UNLOCK(stcb);
4451 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4452 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4453 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4454 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4455 SCTP_INP_WLOCK(inp);
4456 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4457 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4460 SCTP_INP_WUNLOCK(inp);
4462 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4463 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4464 SCTP_INP_RLOCK(inp);
4465 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4466 SCTP_TCB_LOCK(stcb);
4467 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4468 SCTP_TCB_UNLOCK(stcb);
4470 SCTP_INP_RUNLOCK(inp);
4475 case SCTP_AUTH_DELETE_KEY:
4477 struct sctp_authkeyid *scdel;
4479 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4480 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4482 /* delete the key from the right place */
4484 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4485 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4488 SCTP_TCB_UNLOCK(stcb);
4490 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4491 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4492 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4493 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4494 SCTP_INP_WLOCK(inp);
4495 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4496 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4499 SCTP_INP_WUNLOCK(inp);
4501 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4502 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4503 SCTP_INP_RLOCK(inp);
4504 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4505 SCTP_TCB_LOCK(stcb);
4506 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4507 SCTP_TCB_UNLOCK(stcb);
4509 SCTP_INP_RUNLOCK(inp);
4514 case SCTP_AUTH_DEACTIVATE_KEY:
4516 struct sctp_authkeyid *keyid;
4518 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4519 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4521 /* deactivate the key from the right place */
4523 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4524 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4527 SCTP_TCB_UNLOCK(stcb);
4529 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4530 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4531 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4532 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4533 SCTP_INP_WLOCK(inp);
4534 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4535 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4538 SCTP_INP_WUNLOCK(inp);
4540 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4541 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4542 SCTP_INP_RLOCK(inp);
4543 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4544 SCTP_TCB_LOCK(stcb);
4545 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4546 SCTP_TCB_UNLOCK(stcb);
4548 SCTP_INP_RUNLOCK(inp);
4553 case SCTP_ENABLE_STREAM_RESET:
4555 struct sctp_assoc_value *av;
4557 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4558 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4559 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4563 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4565 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4566 SCTP_TCB_UNLOCK(stcb);
4568 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4569 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4570 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4571 (av->assoc_id == SCTP_ALL_ASSOC)) {
4572 SCTP_INP_WLOCK(inp);
4573 inp->local_strreset_support = (uint8_t)av->assoc_value;
4574 SCTP_INP_WUNLOCK(inp);
4576 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4577 (av->assoc_id == SCTP_ALL_ASSOC)) {
4578 SCTP_INP_RLOCK(inp);
4579 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4580 SCTP_TCB_LOCK(stcb);
4581 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4582 SCTP_TCB_UNLOCK(stcb);
4584 SCTP_INP_RUNLOCK(inp);
4589 case SCTP_RESET_STREAMS:
4591 struct sctp_reset_streams *strrst;
4592 int i, send_out = 0;
4595 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4596 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4598 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4602 if (stcb->asoc.reconfig_supported == 0) {
4604 * Peer does not support the chunk type.
4606 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4608 SCTP_TCB_UNLOCK(stcb);
4611 if (sizeof(struct sctp_reset_streams) +
4612 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4614 SCTP_TCB_UNLOCK(stcb);
4617 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4619 if (stcb->asoc.stream_reset_outstanding) {
4620 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4622 SCTP_TCB_UNLOCK(stcb);
4626 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4629 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4630 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4632 SCTP_TCB_UNLOCK(stcb);
4635 if ((send_in == 0) && (send_out == 0)) {
4636 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4638 SCTP_TCB_UNLOCK(stcb);
4641 for (i = 0; i < strrst->srs_number_streams; i++) {
4643 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4644 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4649 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4650 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4656 SCTP_TCB_UNLOCK(stcb);
4663 if (strrst->srs_number_streams) {
4664 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4665 strm = strrst->srs_stream_list[i];
4666 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4667 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4673 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4674 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4675 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4682 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4683 strrst->srs_stream_list,
4684 send_in, 0, 0, 0, 0, 0);
4686 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4689 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4692 * For outgoing streams don't report any
4693 * problems in sending the request to the
4694 * application. XXX: Double check resetting
4699 SCTP_TCB_UNLOCK(stcb);
4702 case SCTP_ADD_STREAMS:
4704 struct sctp_add_streams *stradd;
4705 uint8_t addstream = 0;
4706 uint16_t add_o_strmcnt = 0;
4707 uint16_t add_i_strmcnt = 0;
4709 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4710 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4712 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4716 if (stcb->asoc.reconfig_supported == 0) {
4718 * Peer does not support the chunk type.
4720 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4722 SCTP_TCB_UNLOCK(stcb);
4725 if (stcb->asoc.stream_reset_outstanding) {
4726 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4728 SCTP_TCB_UNLOCK(stcb);
4731 if ((stradd->sas_outstrms == 0) &&
4732 (stradd->sas_instrms == 0)) {
4736 if (stradd->sas_outstrms) {
4738 /* We allocate here */
4739 add_o_strmcnt = stradd->sas_outstrms;
4740 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4741 /* You can't have more than 64k */
4746 if (stradd->sas_instrms) {
4751 * We allocate inside
4752 * sctp_send_str_reset_req()
4754 add_i_strmcnt = stradd->sas_instrms;
4755 cnt = add_i_strmcnt;
4756 cnt += stcb->asoc.streamincnt;
4757 if (cnt > 0x0000ffff) {
4758 /* You can't have more than 64k */
4762 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4763 /* More than you are allowed */
4768 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4769 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4771 SCTP_TCB_UNLOCK(stcb);
4774 case SCTP_RESET_ASSOC:
4779 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4780 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4782 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4786 if (stcb->asoc.reconfig_supported == 0) {
4788 * Peer does not support the chunk type.
4790 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4792 SCTP_TCB_UNLOCK(stcb);
4795 if (stcb->asoc.stream_reset_outstanding) {
4796 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4798 SCTP_TCB_UNLOCK(stcb);
4802 * Is there any data pending in the send or sent
4805 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4806 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4809 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4810 SCTP_TCB_UNLOCK(stcb);
4813 /* Do any streams have data queued? */
4814 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4815 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4819 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4820 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4821 SCTP_TCB_UNLOCK(stcb);
4824 case SCTP_CONNECT_X:
4825 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4826 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4830 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4832 case SCTP_CONNECT_X_DELAYED:
4833 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4834 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4838 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4840 case SCTP_CONNECT_X_COMPLETE:
4842 struct sockaddr *sa;
4844 /* FIXME MT: check correct? */
4845 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4848 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4849 SCTP_INP_RLOCK(inp);
4850 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4852 SCTP_TCB_LOCK(stcb);
4854 SCTP_INP_RUNLOCK(inp);
4857 * We increment here since
4858 * sctp_findassociation_ep_addr() wil do a
4859 * decrement if it finds the stcb as long as
4860 * the locked tcb (last argument) is NOT a
4863 SCTP_INP_INCR_REF(inp);
4864 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4866 SCTP_INP_DECR_REF(inp);
4871 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4875 if (stcb->asoc.delayed_connection == 1) {
4876 stcb->asoc.delayed_connection = 0;
4877 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4878 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4879 stcb->asoc.primary_destination,
4880 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4881 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4884 * already expired or did not use delayed
4887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4890 SCTP_TCB_UNLOCK(stcb);
4893 case SCTP_MAX_BURST:
4895 struct sctp_assoc_value *av;
4897 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4898 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4901 stcb->asoc.max_burst = av->assoc_value;
4902 SCTP_TCB_UNLOCK(stcb);
4904 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4905 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4906 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4907 (av->assoc_id == SCTP_ALL_ASSOC)) {
4908 SCTP_INP_WLOCK(inp);
4909 inp->sctp_ep.max_burst = av->assoc_value;
4910 SCTP_INP_WUNLOCK(inp);
4912 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4913 (av->assoc_id == SCTP_ALL_ASSOC)) {
4914 SCTP_INP_RLOCK(inp);
4915 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4916 SCTP_TCB_LOCK(stcb);
4917 stcb->asoc.max_burst = av->assoc_value;
4918 SCTP_TCB_UNLOCK(stcb);
4920 SCTP_INP_RUNLOCK(inp);
4927 struct sctp_assoc_value *av;
4930 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4931 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4933 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4934 ovh = SCTP_MED_OVERHEAD;
4936 ovh = SCTP_MED_V4_OVERHEAD;
4939 if (av->assoc_value) {
4940 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4942 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4944 SCTP_TCB_UNLOCK(stcb);
4946 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4947 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4948 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4949 SCTP_INP_WLOCK(inp);
4951 * FIXME MT: I think this is not in
4952 * tune with the API ID
4954 if (av->assoc_value) {
4955 inp->sctp_frag_point = (av->assoc_value + ovh);
4957 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4959 SCTP_INP_WUNLOCK(inp);
4961 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4969 struct sctp_event_subscribe *events;
4971 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4973 SCTP_INP_WLOCK(inp);
4974 if (events->sctp_data_io_event) {
4975 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4977 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4980 if (events->sctp_association_event) {
4981 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4983 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4986 if (events->sctp_address_event) {
4987 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4989 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4992 if (events->sctp_send_failure_event) {
4993 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4995 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4998 if (events->sctp_peer_error_event) {
4999 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5001 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5004 if (events->sctp_shutdown_event) {
5005 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5007 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5010 if (events->sctp_partial_delivery_event) {
5011 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5013 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5016 if (events->sctp_adaptation_layer_event) {
5017 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5019 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5022 if (events->sctp_authentication_event) {
5023 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5025 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5028 if (events->sctp_sender_dry_event) {
5029 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5031 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5034 if (events->sctp_stream_reset_event) {
5035 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5037 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5039 SCTP_INP_WUNLOCK(inp);
5041 SCTP_INP_RLOCK(inp);
5042 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5043 SCTP_TCB_LOCK(stcb);
5044 if (events->sctp_association_event) {
5045 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5047 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5049 if (events->sctp_address_event) {
5050 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5052 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5054 if (events->sctp_send_failure_event) {
5055 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5057 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5059 if (events->sctp_peer_error_event) {
5060 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5062 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5064 if (events->sctp_shutdown_event) {
5065 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5067 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5069 if (events->sctp_partial_delivery_event) {
5070 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5072 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5074 if (events->sctp_adaptation_layer_event) {
5075 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5077 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5079 if (events->sctp_authentication_event) {
5080 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5082 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5084 if (events->sctp_sender_dry_event) {
5085 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5087 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5089 if (events->sctp_stream_reset_event) {
5090 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5092 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5094 SCTP_TCB_UNLOCK(stcb);
5097 * Send up the sender dry event only for 1-to-1
5100 if (events->sctp_sender_dry_event) {
5101 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5102 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5103 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5105 SCTP_TCB_LOCK(stcb);
5106 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5107 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5108 (stcb->asoc.stream_queue_cnt == 0)) {
5109 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5111 SCTP_TCB_UNLOCK(stcb);
5115 SCTP_INP_RUNLOCK(inp);
5118 case SCTP_ADAPTATION_LAYER:
5120 struct sctp_setadaptation *adap_bits;
5122 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5123 SCTP_INP_WLOCK(inp);
5124 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5125 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5126 SCTP_INP_WUNLOCK(inp);
5130 case SCTP_SET_INITIAL_DBG_SEQ:
5134 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5135 SCTP_INP_WLOCK(inp);
5136 inp->sctp_ep.initial_sequence_debug = *vvv;
5137 SCTP_INP_WUNLOCK(inp);
5141 case SCTP_DEFAULT_SEND_PARAM:
5143 struct sctp_sndrcvinfo *s_info;
5145 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5146 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5149 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5150 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5152 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5155 SCTP_TCB_UNLOCK(stcb);
5157 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5158 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5159 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5160 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5161 SCTP_INP_WLOCK(inp);
5162 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5163 SCTP_INP_WUNLOCK(inp);
5165 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5166 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5167 SCTP_INP_RLOCK(inp);
5168 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5169 SCTP_TCB_LOCK(stcb);
5170 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5171 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5173 SCTP_TCB_UNLOCK(stcb);
5175 SCTP_INP_RUNLOCK(inp);
5180 case SCTP_PEER_ADDR_PARAMS:
5182 struct sctp_paddrparams *paddrp;
5183 struct sctp_nets *net;
5184 struct sockaddr *addr;
5185 #if defined(INET) && defined(INET6)
5186 struct sockaddr_in sin_store;
5189 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5190 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5192 #if defined(INET) && defined(INET6)
5193 if (paddrp->spp_address.ss_family == AF_INET6) {
5194 struct sockaddr_in6 *sin6;
5196 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5197 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5198 in6_sin6_2_sin(&sin_store, sin6);
5199 addr = (struct sockaddr *)&sin_store;
5201 addr = (struct sockaddr *)&paddrp->spp_address;
5204 addr = (struct sockaddr *)&paddrp->spp_address;
5207 addr = (struct sockaddr *)&paddrp->spp_address;
5210 net = sctp_findnet(stcb, addr);
5213 * We increment here since
5214 * sctp_findassociation_ep_addr() wil do a
5215 * decrement if it finds the stcb as long as
5216 * the locked tcb (last argument) is NOT a
5220 SCTP_INP_INCR_REF(inp);
5221 stcb = sctp_findassociation_ep_addr(&inp, addr,
5224 SCTP_INP_DECR_REF(inp);
5227 if ((stcb != NULL) && (net == NULL)) {
5229 if (addr->sa_family == AF_INET) {
5231 struct sockaddr_in *sin;
5233 sin = (struct sockaddr_in *)addr;
5234 if (sin->sin_addr.s_addr != INADDR_ANY) {
5235 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5236 SCTP_TCB_UNLOCK(stcb);
5243 if (addr->sa_family == AF_INET6) {
5244 struct sockaddr_in6 *sin6;
5246 sin6 = (struct sockaddr_in6 *)addr;
5247 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5248 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5249 SCTP_TCB_UNLOCK(stcb);
5256 error = EAFNOSUPPORT;
5257 SCTP_TCB_UNLOCK(stcb);
5258 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5263 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5265 SCTP_TCB_UNLOCK(stcb);
5266 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5269 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5271 SCTP_TCB_UNLOCK(stcb);
5272 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5276 /************************TCB SPECIFIC SET ******************/
5278 /************************NET SPECIFIC SET ******************/
5279 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5280 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5281 !(net->dest_state & SCTP_ADDR_NOHB)) {
5282 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5283 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5285 net->dest_state |= SCTP_ADDR_NOHB;
5287 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5288 if (paddrp->spp_hbinterval) {
5289 net->heart_beat_delay = paddrp->spp_hbinterval;
5290 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5291 net->heart_beat_delay = 0;
5293 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5294 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5295 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5296 net->dest_state &= ~SCTP_ADDR_NOHB;
5298 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5300 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5301 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5302 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5304 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5305 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5306 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5307 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5309 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5310 net->mtu = paddrp->spp_pathmtu;
5311 switch (net->ro._l_addr.sa.sa_family) {
5314 net->mtu += SCTP_MIN_V4_OVERHEAD;
5319 net->mtu += SCTP_MIN_OVERHEAD;
5325 if (net->mtu < stcb->asoc.smallest_mtu) {
5326 sctp_pathmtu_adjustment(stcb, net->mtu);
5329 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5330 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5331 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5333 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5335 if (paddrp->spp_pathmaxrxt) {
5336 if (net->dest_state & SCTP_ADDR_PF) {
5337 if (net->error_count > paddrp->spp_pathmaxrxt) {
5338 net->dest_state &= ~SCTP_ADDR_PF;
5341 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5342 (net->error_count > net->pf_threshold)) {
5343 net->dest_state |= SCTP_ADDR_PF;
5344 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5345 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5346 stcb->sctp_ep, stcb, net,
5347 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5348 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5351 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5352 if (net->error_count > paddrp->spp_pathmaxrxt) {
5353 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5354 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5357 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5358 net->dest_state |= SCTP_ADDR_REACHABLE;
5359 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5362 net->failure_threshold = paddrp->spp_pathmaxrxt;
5364 if (paddrp->spp_flags & SPP_DSCP) {
5365 net->dscp = paddrp->spp_dscp & 0xfc;
5369 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5370 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5371 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5372 net->flowlabel |= 0x80000000;
5377 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5378 if (paddrp->spp_pathmaxrxt != 0) {
5379 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5380 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5381 if (net->dest_state & SCTP_ADDR_PF) {
5382 if (net->error_count > paddrp->spp_pathmaxrxt) {
5383 net->dest_state &= ~SCTP_ADDR_PF;
5386 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5387 (net->error_count > net->pf_threshold)) {
5388 net->dest_state |= SCTP_ADDR_PF;
5389 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5390 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5391 stcb->sctp_ep, stcb, net,
5392 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5393 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5396 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5397 if (net->error_count > paddrp->spp_pathmaxrxt) {
5398 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5399 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5402 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5403 net->dest_state |= SCTP_ADDR_REACHABLE;
5404 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5407 net->failure_threshold = paddrp->spp_pathmaxrxt;
5410 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5411 if (paddrp->spp_hbinterval != 0) {
5412 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5413 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5414 stcb->asoc.heart_beat_delay = 0;
5416 /* Turn back on the timer */
5417 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5418 if (paddrp->spp_hbinterval != 0) {
5419 net->heart_beat_delay = paddrp->spp_hbinterval;
5420 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5421 net->heart_beat_delay = 0;
5423 if (net->dest_state & SCTP_ADDR_NOHB) {
5424 net->dest_state &= ~SCTP_ADDR_NOHB;
5426 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5427 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5428 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5430 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5432 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5433 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5434 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5435 net->dest_state |= SCTP_ADDR_NOHB;
5436 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5437 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5439 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5443 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5445 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5446 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5447 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5448 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5449 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5451 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5452 net->mtu = paddrp->spp_pathmtu;
5453 switch (net->ro._l_addr.sa.sa_family) {
5456 net->mtu += SCTP_MIN_V4_OVERHEAD;
5461 net->mtu += SCTP_MIN_OVERHEAD;
5467 if (net->mtu < stcb->asoc.smallest_mtu) {
5468 sctp_pathmtu_adjustment(stcb, net->mtu);
5471 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5473 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5474 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5475 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5476 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5478 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5480 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5482 if (paddrp->spp_flags & SPP_DSCP) {
5483 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5484 net->dscp = paddrp->spp_dscp & 0xfc;
5487 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5488 stcb->asoc.default_dscp |= 0x01;
5491 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5492 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5493 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5494 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5495 net->flowlabel |= 0x80000000;
5498 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5499 stcb->asoc.default_flowlabel |= 0x80000000;
5503 SCTP_TCB_UNLOCK(stcb);
5505 /************************NO TCB, SET TO default stuff ******************/
5506 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5507 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5508 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5509 SCTP_INP_WLOCK(inp);
5511 * For the TOS/FLOWLABEL stuff you
5512 * set it with the options on the
5515 if (paddrp->spp_pathmaxrxt != 0) {
5516 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5518 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5519 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5520 else if (paddrp->spp_hbinterval != 0) {
5521 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5522 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5523 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5525 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5526 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5527 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5528 } else if (paddrp->spp_hbinterval) {
5529 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5531 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5532 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5533 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5535 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5536 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5537 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5538 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5540 if (paddrp->spp_flags & SPP_DSCP) {
5541 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5542 inp->sctp_ep.default_dscp |= 0x01;
5545 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5546 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5547 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5548 inp->sctp_ep.default_flowlabel |= 0x80000000;
5552 SCTP_INP_WUNLOCK(inp);
5554 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5562 struct sctp_rtoinfo *srto;
5563 uint32_t new_init, new_min, new_max;
5565 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5566 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5569 if (srto->srto_initial)
5570 new_init = srto->srto_initial;
5572 new_init = stcb->asoc.initial_rto;
5574 new_max = srto->srto_max;
5576 new_max = stcb->asoc.maxrto;
5578 new_min = srto->srto_min;
5580 new_min = stcb->asoc.minrto;
5581 if ((new_min <= new_init) && (new_init <= new_max)) {
5582 stcb->asoc.initial_rto = new_init;
5583 stcb->asoc.maxrto = new_max;
5584 stcb->asoc.minrto = new_min;
5586 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5589 SCTP_TCB_UNLOCK(stcb);
5591 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5592 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5593 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5594 SCTP_INP_WLOCK(inp);
5595 if (srto->srto_initial)
5596 new_init = srto->srto_initial;
5598 new_init = inp->sctp_ep.initial_rto;
5600 new_max = srto->srto_max;
5602 new_max = inp->sctp_ep.sctp_maxrto;
5604 new_min = srto->srto_min;
5606 new_min = inp->sctp_ep.sctp_minrto;
5607 if ((new_min <= new_init) && (new_init <= new_max)) {
5608 inp->sctp_ep.initial_rto = new_init;
5609 inp->sctp_ep.sctp_maxrto = new_max;
5610 inp->sctp_ep.sctp_minrto = new_min;
5612 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5615 SCTP_INP_WUNLOCK(inp);
5617 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5623 case SCTP_ASSOCINFO:
5625 struct sctp_assocparams *sasoc;
5627 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5628 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5629 if (sasoc->sasoc_cookie_life) {
5630 /* boundary check the cookie life */
5631 if (sasoc->sasoc_cookie_life < 1000)
5632 sasoc->sasoc_cookie_life = 1000;
5633 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5634 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5638 if (sasoc->sasoc_asocmaxrxt)
5639 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5640 if (sasoc->sasoc_cookie_life) {
5641 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5643 SCTP_TCB_UNLOCK(stcb);
5645 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5646 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5647 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5648 SCTP_INP_WLOCK(inp);
5649 if (sasoc->sasoc_asocmaxrxt)
5650 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5651 if (sasoc->sasoc_cookie_life) {
5652 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5654 SCTP_INP_WUNLOCK(inp);
5656 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5664 struct sctp_initmsg *sinit;
5666 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5667 SCTP_INP_WLOCK(inp);
5668 if (sinit->sinit_num_ostreams)
5669 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5671 if (sinit->sinit_max_instreams)
5672 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5674 if (sinit->sinit_max_attempts)
5675 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5677 if (sinit->sinit_max_init_timeo)
5678 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5679 SCTP_INP_WUNLOCK(inp);
5682 case SCTP_PRIMARY_ADDR:
5684 struct sctp_setprim *spa;
5685 struct sctp_nets *net;
5686 struct sockaddr *addr;
5687 #if defined(INET) && defined(INET6)
5688 struct sockaddr_in sin_store;
5691 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5692 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5694 #if defined(INET) && defined(INET6)
5695 if (spa->ssp_addr.ss_family == AF_INET6) {
5696 struct sockaddr_in6 *sin6;
5698 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5699 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5700 in6_sin6_2_sin(&sin_store, sin6);
5701 addr = (struct sockaddr *)&sin_store;
5703 addr = (struct sockaddr *)&spa->ssp_addr;
5706 addr = (struct sockaddr *)&spa->ssp_addr;
5709 addr = (struct sockaddr *)&spa->ssp_addr;
5712 net = sctp_findnet(stcb, addr);
5715 * We increment here since
5716 * sctp_findassociation_ep_addr() wil do a
5717 * decrement if it finds the stcb as long as
5718 * the locked tcb (last argument) is NOT a
5722 SCTP_INP_INCR_REF(inp);
5723 stcb = sctp_findassociation_ep_addr(&inp, addr,
5726 SCTP_INP_DECR_REF(inp);
5730 if ((stcb != NULL) && (net != NULL)) {
5731 if (net != stcb->asoc.primary_destination) {
5732 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5733 /* Ok we need to set it */
5734 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5735 if ((stcb->asoc.alternate) &&
5736 (!(net->dest_state & SCTP_ADDR_PF)) &&
5737 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5738 sctp_free_remote_addr(stcb->asoc.alternate);
5739 stcb->asoc.alternate = NULL;
5742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5746 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5751 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5755 SCTP_TCB_UNLOCK(stcb);
5759 case SCTP_SET_DYNAMIC_PRIMARY:
5761 union sctp_sockstore *ss;
5763 error = priv_check(curthread,
5764 PRIV_NETINET_RESERVEDPORT);
5768 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5769 /* SUPER USER CHECK? */
5770 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5773 case SCTP_SET_PEER_PRIMARY_ADDR:
5775 struct sctp_setpeerprim *sspp;
5776 struct sockaddr *addr;
5777 #if defined(INET) && defined(INET6)
5778 struct sockaddr_in sin_store;
5781 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5782 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5784 struct sctp_ifa *ifa;
5786 #if defined(INET) && defined(INET6)
5787 if (sspp->sspp_addr.ss_family == AF_INET6) {
5788 struct sockaddr_in6 *sin6;
5790 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5791 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5792 in6_sin6_2_sin(&sin_store, sin6);
5793 addr = (struct sockaddr *)&sin_store;
5795 addr = (struct sockaddr *)&sspp->sspp_addr;
5798 addr = (struct sockaddr *)&sspp->sspp_addr;
5801 addr = (struct sockaddr *)&sspp->sspp_addr;
5803 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5805 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5809 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5811 * Must validate the ifa found is in
5814 struct sctp_laddr *laddr;
5817 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5818 if (laddr->ifa == NULL) {
5819 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5823 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5824 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5827 if (laddr->ifa == ifa) {
5833 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5838 switch (addr->sa_family) {
5842 struct sockaddr_in *sin;
5844 sin = (struct sockaddr_in *)addr;
5845 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5846 &sin->sin_addr) != 0) {
5847 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5857 struct sockaddr_in6 *sin6;
5859 sin6 = (struct sockaddr_in6 *)addr;
5860 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5861 &sin6->sin6_addr) != 0) {
5862 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5870 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5875 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5876 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5879 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5881 SCTP_TCB_UNLOCK(stcb);
5883 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5888 case SCTP_BINDX_ADD_ADDR:
5890 struct sctp_getaddresses *addrs;
5893 td = (struct thread *)p;
5894 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5897 if (addrs->addr->sa_family == AF_INET) {
5898 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5899 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5903 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5904 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5910 if (addrs->addr->sa_family == AF_INET6) {
5911 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5912 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5916 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5917 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5918 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5924 error = EAFNOSUPPORT;
5927 sctp_bindx_add_address(so, inp, addrs->addr,
5928 addrs->sget_assoc_id, vrf_id,
5932 case SCTP_BINDX_REM_ADDR:
5934 struct sctp_getaddresses *addrs;
5937 td = (struct thread *)p;
5939 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5941 if (addrs->addr->sa_family == AF_INET) {
5942 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5943 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5947 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5948 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5954 if (addrs->addr->sa_family == AF_INET6) {
5955 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5956 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5961 (error = prison_local_ip6(td->td_ucred,
5962 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5963 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5964 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5970 error = EAFNOSUPPORT;
5973 sctp_bindx_delete_address(inp, addrs->addr,
5974 addrs->sget_assoc_id, vrf_id,
5980 struct sctp_event *event;
5981 uint32_t event_type;
5983 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5984 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5985 switch (event->se_type) {
5986 case SCTP_ASSOC_CHANGE:
5987 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5989 case SCTP_PEER_ADDR_CHANGE:
5990 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5992 case SCTP_REMOTE_ERROR:
5993 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5995 case SCTP_SEND_FAILED:
5996 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5998 case SCTP_SHUTDOWN_EVENT:
5999 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6001 case SCTP_ADAPTATION_INDICATION:
6002 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6004 case SCTP_PARTIAL_DELIVERY_EVENT:
6005 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6007 case SCTP_AUTHENTICATION_EVENT:
6008 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6010 case SCTP_STREAM_RESET_EVENT:
6011 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6013 case SCTP_SENDER_DRY_EVENT:
6014 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6016 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6018 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6021 case SCTP_ASSOC_RESET_EVENT:
6022 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6024 case SCTP_STREAM_CHANGE_EVENT:
6025 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6027 case SCTP_SEND_FAILED_EVENT:
6028 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6032 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6036 if (event_type > 0) {
6039 sctp_stcb_feature_on(inp, stcb, event_type);
6040 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6041 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6042 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6043 (stcb->asoc.stream_queue_cnt == 0)) {
6044 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6048 sctp_stcb_feature_off(inp, stcb, event_type);
6050 SCTP_TCB_UNLOCK(stcb);
6053 * We don't want to send up a storm
6054 * of events, so return an error for
6057 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6058 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6059 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6060 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6061 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6062 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6066 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6067 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6068 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6069 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6070 SCTP_INP_WLOCK(inp);
6072 sctp_feature_on(inp, event_type);
6074 sctp_feature_off(inp, event_type);
6076 SCTP_INP_WUNLOCK(inp);
6078 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6079 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6080 SCTP_INP_RLOCK(inp);
6081 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6082 SCTP_TCB_LOCK(stcb);
6084 sctp_stcb_feature_on(inp, stcb, event_type);
6086 sctp_stcb_feature_off(inp, stcb, event_type);
6088 SCTP_TCB_UNLOCK(stcb);
6090 SCTP_INP_RUNLOCK(inp);
6096 case SCTP_RECVRCVINFO:
6100 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6101 SCTP_INP_WLOCK(inp);
6103 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6105 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6107 SCTP_INP_WUNLOCK(inp);
6110 case SCTP_RECVNXTINFO:
6114 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6115 SCTP_INP_WLOCK(inp);
6117 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6119 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6121 SCTP_INP_WUNLOCK(inp);
6124 case SCTP_DEFAULT_SNDINFO:
6126 struct sctp_sndinfo *info;
6129 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6130 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6133 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6134 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6135 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6136 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6137 stcb->asoc.def_send.sinfo_flags |= policy;
6138 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6139 stcb->asoc.def_send.sinfo_context = info->snd_context;
6141 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6144 SCTP_TCB_UNLOCK(stcb);
6146 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6147 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6148 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6149 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6150 SCTP_INP_WLOCK(inp);
6151 inp->def_send.sinfo_stream = info->snd_sid;
6152 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6153 inp->def_send.sinfo_flags = info->snd_flags;
6154 inp->def_send.sinfo_flags |= policy;
6155 inp->def_send.sinfo_ppid = info->snd_ppid;
6156 inp->def_send.sinfo_context = info->snd_context;
6157 SCTP_INP_WUNLOCK(inp);
6159 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6160 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6161 SCTP_INP_RLOCK(inp);
6162 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6163 SCTP_TCB_LOCK(stcb);
6164 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6165 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6166 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6167 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6168 stcb->asoc.def_send.sinfo_flags |= policy;
6169 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6170 stcb->asoc.def_send.sinfo_context = info->snd_context;
6172 SCTP_TCB_UNLOCK(stcb);
6174 SCTP_INP_RUNLOCK(inp);
6179 case SCTP_DEFAULT_PRINFO:
6181 struct sctp_default_prinfo *info;
6183 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6184 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6186 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6187 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6192 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6193 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6194 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6195 SCTP_TCB_UNLOCK(stcb);
6197 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6198 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6199 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6200 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6201 SCTP_INP_WLOCK(inp);
6202 inp->def_send.sinfo_flags &= 0xfff0;
6203 inp->def_send.sinfo_flags |= info->pr_policy;
6204 inp->def_send.sinfo_timetolive = info->pr_value;
6205 SCTP_INP_WUNLOCK(inp);
6207 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6208 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6209 SCTP_INP_RLOCK(inp);
6210 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6211 SCTP_TCB_LOCK(stcb);
6212 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6213 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6214 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6215 SCTP_TCB_UNLOCK(stcb);
6217 SCTP_INP_RUNLOCK(inp);
6222 case SCTP_PEER_ADDR_THLDS:
6223 /* Applies to the specific association */
6225 struct sctp_paddrthlds *thlds;
6226 struct sctp_nets *net;
6227 struct sockaddr *addr;
6228 #if defined(INET) && defined(INET6)
6229 struct sockaddr_in sin_store;
6232 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6233 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6235 #if defined(INET) && defined(INET6)
6236 if (thlds->spt_address.ss_family == AF_INET6) {
6237 struct sockaddr_in6 *sin6;
6239 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6240 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6241 in6_sin6_2_sin(&sin_store, sin6);
6242 addr = (struct sockaddr *)&sin_store;
6244 addr = (struct sockaddr *)&thlds->spt_address;
6247 addr = (struct sockaddr *)&thlds->spt_address;
6250 addr = (struct sockaddr *)&thlds->spt_address;
6253 net = sctp_findnet(stcb, addr);
6256 * We increment here since
6257 * sctp_findassociation_ep_addr() wil do a
6258 * decrement if it finds the stcb as long as
6259 * the locked tcb (last argument) is NOT a
6263 SCTP_INP_INCR_REF(inp);
6264 stcb = sctp_findassociation_ep_addr(&inp, addr,
6267 SCTP_INP_DECR_REF(inp);
6270 if ((stcb != NULL) && (net == NULL)) {
6272 if (addr->sa_family == AF_INET) {
6274 struct sockaddr_in *sin;
6276 sin = (struct sockaddr_in *)addr;
6277 if (sin->sin_addr.s_addr != INADDR_ANY) {
6278 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6279 SCTP_TCB_UNLOCK(stcb);
6286 if (addr->sa_family == AF_INET6) {
6287 struct sockaddr_in6 *sin6;
6289 sin6 = (struct sockaddr_in6 *)addr;
6290 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6291 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6292 SCTP_TCB_UNLOCK(stcb);
6299 error = EAFNOSUPPORT;
6300 SCTP_TCB_UNLOCK(stcb);
6301 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6305 if (thlds->spt_pathcpthld != 0xffff) {
6307 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6312 net->failure_threshold = thlds->spt_pathmaxrxt;
6313 net->pf_threshold = thlds->spt_pathpfthld;
6314 if (net->dest_state & SCTP_ADDR_PF) {
6315 if ((net->error_count > net->failure_threshold) ||
6316 (net->error_count <= net->pf_threshold)) {
6317 net->dest_state &= ~SCTP_ADDR_PF;
6320 if ((net->error_count > net->pf_threshold) &&
6321 (net->error_count <= net->failure_threshold)) {
6322 net->dest_state |= SCTP_ADDR_PF;
6323 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6324 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6325 stcb->sctp_ep, stcb, net,
6326 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6327 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6330 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6331 if (net->error_count > net->failure_threshold) {
6332 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6333 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6336 if (net->error_count <= net->failure_threshold) {
6337 net->dest_state |= SCTP_ADDR_REACHABLE;
6338 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6342 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6343 net->failure_threshold = thlds->spt_pathmaxrxt;
6344 net->pf_threshold = thlds->spt_pathpfthld;
6345 if (net->dest_state & SCTP_ADDR_PF) {
6346 if ((net->error_count > net->failure_threshold) ||
6347 (net->error_count <= net->pf_threshold)) {
6348 net->dest_state &= ~SCTP_ADDR_PF;
6351 if ((net->error_count > net->pf_threshold) &&
6352 (net->error_count <= net->failure_threshold)) {
6353 net->dest_state |= SCTP_ADDR_PF;
6354 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6355 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6356 stcb->sctp_ep, stcb, net,
6357 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6358 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6361 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6362 if (net->error_count > net->failure_threshold) {
6363 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6364 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6367 if (net->error_count <= net->failure_threshold) {
6368 net->dest_state |= SCTP_ADDR_REACHABLE;
6369 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6373 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6374 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6376 SCTP_TCB_UNLOCK(stcb);
6378 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6379 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6380 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6381 SCTP_INP_WLOCK(inp);
6382 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6383 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6384 SCTP_INP_WUNLOCK(inp);
6386 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6392 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6394 struct sctp_udpencaps *encaps;
6395 struct sctp_nets *net;
6396 struct sockaddr *addr;
6397 #if defined(INET) && defined(INET6)
6398 struct sockaddr_in sin_store;
6401 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6402 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6404 #if defined(INET) && defined(INET6)
6405 if (encaps->sue_address.ss_family == AF_INET6) {
6406 struct sockaddr_in6 *sin6;
6408 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6409 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6410 in6_sin6_2_sin(&sin_store, sin6);
6411 addr = (struct sockaddr *)&sin_store;
6413 addr = (struct sockaddr *)&encaps->sue_address;
6416 addr = (struct sockaddr *)&encaps->sue_address;
6419 addr = (struct sockaddr *)&encaps->sue_address;
6422 net = sctp_findnet(stcb, addr);
6425 * We increment here since
6426 * sctp_findassociation_ep_addr() wil do a
6427 * decrement if it finds the stcb as long as
6428 * the locked tcb (last argument) is NOT a
6432 SCTP_INP_INCR_REF(inp);
6433 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6435 SCTP_INP_DECR_REF(inp);
6438 if ((stcb != NULL) && (net == NULL)) {
6440 if (addr->sa_family == AF_INET) {
6442 struct sockaddr_in *sin;
6444 sin = (struct sockaddr_in *)addr;
6445 if (sin->sin_addr.s_addr != INADDR_ANY) {
6446 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6447 SCTP_TCB_UNLOCK(stcb);
6454 if (addr->sa_family == AF_INET6) {
6455 struct sockaddr_in6 *sin6;
6457 sin6 = (struct sockaddr_in6 *)addr;
6458 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6459 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6460 SCTP_TCB_UNLOCK(stcb);
6467 error = EAFNOSUPPORT;
6468 SCTP_TCB_UNLOCK(stcb);
6469 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6475 net->port = encaps->sue_port;
6477 stcb->asoc.port = encaps->sue_port;
6479 SCTP_TCB_UNLOCK(stcb);
6481 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6482 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6483 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6484 SCTP_INP_WLOCK(inp);
6485 inp->sctp_ep.port = encaps->sue_port;
6486 SCTP_INP_WUNLOCK(inp);
6488 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6494 case SCTP_ECN_SUPPORTED:
6496 struct sctp_assoc_value *av;
6498 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6499 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6502 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6504 SCTP_TCB_UNLOCK(stcb);
6506 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6507 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6508 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6509 SCTP_INP_WLOCK(inp);
6510 if (av->assoc_value == 0) {
6511 inp->ecn_supported = 0;
6513 inp->ecn_supported = 1;
6515 SCTP_INP_WUNLOCK(inp);
6517 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6523 case SCTP_PR_SUPPORTED:
6525 struct sctp_assoc_value *av;
6527 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6528 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6531 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6533 SCTP_TCB_UNLOCK(stcb);
6535 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6536 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6537 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6538 SCTP_INP_WLOCK(inp);
6539 if (av->assoc_value == 0) {
6540 inp->prsctp_supported = 0;
6542 inp->prsctp_supported = 1;
6544 SCTP_INP_WUNLOCK(inp);
6546 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6552 case SCTP_AUTH_SUPPORTED:
6554 struct sctp_assoc_value *av;
6556 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6557 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6560 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6562 SCTP_TCB_UNLOCK(stcb);
6564 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6565 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6566 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6567 if ((av->assoc_value == 0) &&
6568 (inp->asconf_supported == 1)) {
6570 * AUTH is required for
6573 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6576 SCTP_INP_WLOCK(inp);
6577 if (av->assoc_value == 0) {
6578 inp->auth_supported = 0;
6580 inp->auth_supported = 1;
6582 SCTP_INP_WUNLOCK(inp);
6585 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6591 case SCTP_ASCONF_SUPPORTED:
6593 struct sctp_assoc_value *av;
6595 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6596 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6599 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6601 SCTP_TCB_UNLOCK(stcb);
6603 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6604 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6605 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6606 if ((av->assoc_value != 0) &&
6607 (inp->auth_supported == 0)) {
6609 * AUTH is required for
6612 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6615 SCTP_INP_WLOCK(inp);
6616 if (av->assoc_value == 0) {
6617 inp->asconf_supported = 0;
6618 sctp_auth_delete_chunk(SCTP_ASCONF,
6619 inp->sctp_ep.local_auth_chunks);
6620 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6621 inp->sctp_ep.local_auth_chunks);
6623 inp->asconf_supported = 1;
6624 sctp_auth_add_chunk(SCTP_ASCONF,
6625 inp->sctp_ep.local_auth_chunks);
6626 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6627 inp->sctp_ep.local_auth_chunks);
6629 SCTP_INP_WUNLOCK(inp);
6632 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6638 case SCTP_RECONFIG_SUPPORTED:
6640 struct sctp_assoc_value *av;
6642 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6643 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6646 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6648 SCTP_TCB_UNLOCK(stcb);
6650 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6651 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6652 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6653 SCTP_INP_WLOCK(inp);
6654 if (av->assoc_value == 0) {
6655 inp->reconfig_supported = 0;
6657 inp->reconfig_supported = 1;
6659 SCTP_INP_WUNLOCK(inp);
6661 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6667 case SCTP_NRSACK_SUPPORTED:
6669 struct sctp_assoc_value *av;
6671 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6672 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6675 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6677 SCTP_TCB_UNLOCK(stcb);
6679 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6680 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6681 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6682 SCTP_INP_WLOCK(inp);
6683 if (av->assoc_value == 0) {
6684 inp->nrsack_supported = 0;
6686 inp->nrsack_supported = 1;
6688 SCTP_INP_WUNLOCK(inp);
6690 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6696 case SCTP_PKTDROP_SUPPORTED:
6698 struct sctp_assoc_value *av;
6700 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6701 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6704 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6706 SCTP_TCB_UNLOCK(stcb);
6708 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6709 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6710 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6711 SCTP_INP_WLOCK(inp);
6712 if (av->assoc_value == 0) {
6713 inp->pktdrop_supported = 0;
6715 inp->pktdrop_supported = 1;
6717 SCTP_INP_WUNLOCK(inp);
6719 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6727 struct sctp_assoc_value *av;
6728 struct sctp_nets *net;
6730 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6731 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6734 stcb->asoc.max_cwnd = av->assoc_value;
6735 if (stcb->asoc.max_cwnd > 0) {
6736 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6737 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6738 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6739 net->cwnd = stcb->asoc.max_cwnd;
6740 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6741 net->cwnd = net->mtu - sizeof(struct sctphdr);
6746 SCTP_TCB_UNLOCK(stcb);
6748 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6749 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6750 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6751 SCTP_INP_WLOCK(inp);
6752 inp->max_cwnd = av->assoc_value;
6753 SCTP_INP_WUNLOCK(inp);
6755 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6762 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6763 error = ENOPROTOOPT;
6765 } /* end switch (opt) */
6770 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6772 void *optval = NULL;
6776 struct sctp_inpcb *inp;
6778 if ((sopt->sopt_level == SOL_SOCKET) &&
6779 (sopt->sopt_name == SO_SETFIB)) {
6780 inp = (struct sctp_inpcb *)so->so_pcb;
6782 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6785 SCTP_INP_WLOCK(inp);
6786 inp->fibnum = so->so_fibnum;
6787 SCTP_INP_WUNLOCK(inp);
6790 if (sopt->sopt_level != IPPROTO_SCTP) {
6791 /* wrong proto level... send back up to IP */
6793 if (INP_CHECK_SOCKAF(so, AF_INET6))
6794 error = ip6_ctloutput(so, sopt);
6796 #if defined(INET) && defined(INET6)
6800 error = ip_ctloutput(so, sopt);
6804 optsize = sopt->sopt_valsize;
6806 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6807 if (optval == NULL) {
6808 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6811 error = sooptcopyin(sopt, optval, optsize, optsize);
6813 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6817 p = (void *)sopt->sopt_td;
6818 if (sopt->sopt_dir == SOPT_SET) {
6819 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6820 } else if (sopt->sopt_dir == SOPT_GET) {
6821 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6823 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6826 if ((error == 0) && (optval != NULL)) {
6827 error = sooptcopyout(sopt, optval, optsize);
6828 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6829 } else if (optval != NULL) {
6830 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6838 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6841 int create_lock_on = 0;
6843 struct sctp_inpcb *inp;
6844 struct sctp_tcb *stcb = NULL;
6846 inp = (struct sctp_inpcb *)so->so_pcb;
6848 /* I made the same as TCP since we are not setup? */
6849 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6850 return (ECONNRESET);
6853 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6856 switch (addr->sa_family) {
6860 struct sockaddr_in6 *sin6p;
6862 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6863 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6866 sin6p = (struct sockaddr_in6 *)addr;
6867 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6868 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6877 struct sockaddr_in *sinp;
6879 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6880 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6883 sinp = (struct sockaddr_in *)addr;
6884 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6885 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6892 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6893 return (EAFNOSUPPORT);
6895 SCTP_INP_INCR_REF(inp);
6896 SCTP_ASOC_CREATE_LOCK(inp);
6900 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6901 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6902 /* Should I really unlock ? */
6903 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6908 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6909 (addr->sa_family == AF_INET6)) {
6910 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6915 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6916 SCTP_PCB_FLAGS_UNBOUND) {
6917 /* Bind a ephemeral port */
6918 error = sctp_inpcb_bind(so, NULL, NULL, p);
6923 /* Now do we connect? */
6924 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6925 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6926 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6930 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6931 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6932 /* We are already connected AND the TCP model */
6933 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6937 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6938 SCTP_INP_RLOCK(inp);
6939 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6940 SCTP_INP_RUNLOCK(inp);
6943 * We increment here since sctp_findassociation_ep_addr()
6944 * will do a decrement if it finds the stcb as long as the
6945 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6947 SCTP_INP_INCR_REF(inp);
6948 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6950 SCTP_INP_DECR_REF(inp);
6952 SCTP_TCB_UNLOCK(stcb);
6956 /* Already have or am bring up an association */
6957 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
6961 vrf_id = inp->def_vrf_id;
6962 /* We are GOOD to go */
6963 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
6964 inp->sctp_ep.pre_open_stream_count,
6965 inp->sctp_ep.port, p);
6967 /* Gak! no memory */
6970 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
6971 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
6972 /* Set the connected flag so we can queue data */
6975 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
6976 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
6978 /* initialize authentication parameters for the assoc */
6979 sctp_initialize_auth_params(inp, stcb);
6981 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
6982 SCTP_TCB_UNLOCK(stcb);
6984 if (create_lock_on) {
6985 SCTP_ASOC_CREATE_UNLOCK(inp);
6987 SCTP_INP_DECR_REF(inp);
6993 sctp_listen(struct socket *so, int backlog, struct thread *p)
6996 * Note this module depends on the protocol processing being called
6997 * AFTER any socket level flags and backlog are applied to the
6998 * socket. The traditional way that the socket flags are applied is
6999 * AFTER protocol processing. We have made a change to the
7000 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7001 * place if the socket API for SCTP is to work properly.
7005 struct sctp_inpcb *inp;
7007 inp = (struct sctp_inpcb *)so->so_pcb;
7009 /* I made the same as TCP since we are not setup? */
7010 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7011 return (ECONNRESET);
7013 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7014 /* See if we have a listener */
7015 struct sctp_inpcb *tinp;
7016 union sctp_sockstore store;
7018 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7020 struct sctp_laddr *laddr;
7022 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7023 memcpy(&store, &laddr->ifa->address, sizeof(store));
7024 switch (store.sa.sa_family) {
7027 store.sin.sin_port = inp->sctp_lport;
7032 store.sin6.sin6_port = inp->sctp_lport;
7038 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7039 if (tinp && (tinp != inp) &&
7040 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7041 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7042 (SCTP_IS_LISTENING(tinp))) {
7044 * we have a listener already and
7047 SCTP_INP_DECR_REF(tinp);
7048 return (EADDRINUSE);
7050 SCTP_INP_DECR_REF(tinp);
7054 /* Setup a local addr bound all */
7055 memset(&store, 0, sizeof(store));
7057 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7058 store.sa.sa_family = AF_INET6;
7059 store.sa.sa_len = sizeof(struct sockaddr_in6);
7063 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7064 store.sa.sa_family = AF_INET;
7065 store.sa.sa_len = sizeof(struct sockaddr_in);
7068 switch (store.sa.sa_family) {
7071 store.sin.sin_port = inp->sctp_lport;
7076 store.sin6.sin6_port = inp->sctp_lport;
7082 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7083 if (tinp && (tinp != inp) &&
7084 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7085 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7086 (SCTP_IS_LISTENING(tinp))) {
7088 * we have a listener already and its not
7091 SCTP_INP_DECR_REF(tinp);
7092 return (EADDRINUSE);
7094 SCTP_INP_DECR_REF(tinp);
7098 SCTP_INP_RLOCK(inp);
7099 #ifdef SCTP_LOCK_LOGGING
7100 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7101 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7105 error = solisten_proto_check(so);
7108 SCTP_INP_RUNLOCK(inp);
7111 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7112 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7114 * The unlucky case - We are in the tcp pool with this guy.
7115 * - Someone else is in the main inp slot. - We must move
7116 * this guy (the listener) to the main slot - We must then
7117 * move the guy that was listener to the TCP Pool.
7119 if (sctp_swap_inpcb_for_listen(inp)) {
7120 SCTP_INP_RUNLOCK(inp);
7121 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7122 return (EADDRINUSE);
7125 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7126 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7127 /* We are already connected AND the TCP model */
7128 SCTP_INP_RUNLOCK(inp);
7129 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7130 return (EADDRINUSE);
7132 SCTP_INP_RUNLOCK(inp);
7133 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7134 /* We must do a bind. */
7135 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7136 /* bind error, probably perm */
7140 SCTP_INP_WLOCK(inp);
7141 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7143 solisten_proto(so, backlog);
7147 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7149 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7151 SCTP_INP_WUNLOCK(inp);
7155 static int sctp_defered_wakeup_cnt = 0;
7158 sctp_accept(struct socket *so, struct sockaddr **addr)
7160 struct sctp_tcb *stcb;
7161 struct sctp_inpcb *inp;
7162 union sctp_sockstore store;
7166 inp = (struct sctp_inpcb *)so->so_pcb;
7169 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7170 return (ECONNRESET);
7172 SCTP_INP_RLOCK(inp);
7173 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7174 SCTP_INP_RUNLOCK(inp);
7175 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7176 return (EOPNOTSUPP);
7178 if (so->so_state & SS_ISDISCONNECTED) {
7179 SCTP_INP_RUNLOCK(inp);
7180 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7181 return (ECONNABORTED);
7183 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7185 SCTP_INP_RUNLOCK(inp);
7186 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7187 return (ECONNRESET);
7189 SCTP_TCB_LOCK(stcb);
7190 SCTP_INP_RUNLOCK(inp);
7191 store = stcb->asoc.primary_destination->ro._l_addr;
7192 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
7193 SCTP_TCB_UNLOCK(stcb);
7194 switch (store.sa.sa_family) {
7198 struct sockaddr_in *sin;
7200 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7203 sin->sin_family = AF_INET;
7204 sin->sin_len = sizeof(*sin);
7205 sin->sin_port = store.sin.sin_port;
7206 sin->sin_addr = store.sin.sin_addr;
7207 *addr = (struct sockaddr *)sin;
7214 struct sockaddr_in6 *sin6;
7216 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7219 sin6->sin6_family = AF_INET6;
7220 sin6->sin6_len = sizeof(*sin6);
7221 sin6->sin6_port = store.sin6.sin6_port;
7222 sin6->sin6_addr = store.sin6.sin6_addr;
7223 if ((error = sa6_recoverscope(sin6)) != 0) {
7224 SCTP_FREE_SONAME(sin6);
7227 *addr = (struct sockaddr *)sin6;
7235 /* Wake any delayed sleep action */
7236 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7237 SCTP_INP_WLOCK(inp);
7238 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7239 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7240 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7241 SCTP_INP_WUNLOCK(inp);
7242 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7243 if (sowriteable(inp->sctp_socket)) {
7244 sowwakeup_locked(inp->sctp_socket);
7246 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7248 SCTP_INP_WLOCK(inp);
7250 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7251 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7252 SCTP_INP_WUNLOCK(inp);
7253 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7254 if (soreadable(inp->sctp_socket)) {
7255 sctp_defered_wakeup_cnt++;
7256 sorwakeup_locked(inp->sctp_socket);
7258 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7260 SCTP_INP_WLOCK(inp);
7262 SCTP_INP_WUNLOCK(inp);
7264 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7265 SCTP_TCB_LOCK(stcb);
7266 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7267 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7274 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7276 struct sockaddr_in *sin;
7278 struct sctp_inpcb *inp;
7279 struct sctp_ifa *sctp_ifa;
7282 * Do the malloc first in case it blocks.
7284 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7287 sin->sin_family = AF_INET;
7288 sin->sin_len = sizeof(*sin);
7289 inp = (struct sctp_inpcb *)so->so_pcb;
7291 SCTP_FREE_SONAME(sin);
7292 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7293 return (ECONNRESET);
7295 SCTP_INP_RLOCK(inp);
7296 sin->sin_port = inp->sctp_lport;
7297 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7298 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7299 struct sctp_tcb *stcb;
7300 struct sockaddr_in *sin_a;
7301 struct sctp_nets *net;
7304 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7310 SCTP_TCB_LOCK(stcb);
7311 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7312 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7314 /* this will make coverity happy */
7317 if (sin_a->sin_family == AF_INET) {
7322 if ((!fnd) || (sin_a == NULL)) {
7324 SCTP_TCB_UNLOCK(stcb);
7327 vrf_id = inp->def_vrf_id;
7328 sctp_ifa = sctp_source_address_selection(inp,
7330 (sctp_route_t *)&net->ro,
7333 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7334 sctp_free_ifa(sctp_ifa);
7336 SCTP_TCB_UNLOCK(stcb);
7338 /* For the bound all case you get back 0 */
7340 sin->sin_addr.s_addr = 0;
7344 /* Take the first IPv4 address in the list */
7345 struct sctp_laddr *laddr;
7348 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7349 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7350 struct sockaddr_in *sin_a;
7352 sin_a = &laddr->ifa->address.sin;
7353 sin->sin_addr = sin_a->sin_addr;
7359 SCTP_FREE_SONAME(sin);
7360 SCTP_INP_RUNLOCK(inp);
7361 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7365 SCTP_INP_RUNLOCK(inp);
7366 (*addr) = (struct sockaddr *)sin;
7371 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7373 struct sockaddr_in *sin;
7375 struct sockaddr_in *sin_a;
7376 struct sctp_inpcb *inp;
7377 struct sctp_tcb *stcb;
7378 struct sctp_nets *net;
7380 /* Do the malloc first in case it blocks. */
7381 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7384 sin->sin_family = AF_INET;
7385 sin->sin_len = sizeof(*sin);
7387 inp = (struct sctp_inpcb *)so->so_pcb;
7388 if ((inp == NULL) ||
7389 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7390 /* UDP type and listeners will drop out here */
7391 SCTP_FREE_SONAME(sin);
7392 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7395 SCTP_INP_RLOCK(inp);
7396 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7398 SCTP_TCB_LOCK(stcb);
7400 SCTP_INP_RUNLOCK(inp);
7402 SCTP_FREE_SONAME(sin);
7403 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7404 return (ECONNRESET);
7407 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7408 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7409 if (sin_a->sin_family == AF_INET) {
7411 sin->sin_port = stcb->rport;
7412 sin->sin_addr = sin_a->sin_addr;
7416 SCTP_TCB_UNLOCK(stcb);
7418 /* No IPv4 address */
7419 SCTP_FREE_SONAME(sin);
7420 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7423 (*addr) = (struct sockaddr *)sin;
7427 struct pr_usrreqs sctp_usrreqs = {
7428 .pru_abort = sctp_abort,
7429 .pru_accept = sctp_accept,
7430 .pru_attach = sctp_attach,
7431 .pru_bind = sctp_bind,
7432 .pru_connect = sctp_connect,
7433 .pru_control = in_control,
7434 .pru_close = sctp_close,
7435 .pru_detach = sctp_close,
7436 .pru_sopoll = sopoll_generic,
7437 .pru_flush = sctp_flush,
7438 .pru_disconnect = sctp_disconnect,
7439 .pru_listen = sctp_listen,
7440 .pru_peeraddr = sctp_peeraddr,
7441 .pru_send = sctp_sendm,
7442 .pru_shutdown = sctp_shutdown,
7443 .pru_sockaddr = sctp_ingetaddr,
7444 .pru_sosend = sctp_sosend,
7445 .pru_soreceive = sctp_soreceive