2 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * a) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
12 * b) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the distribution.
16 * c) Neither the name of Cisco Systems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <netinet/sctp_os.h>
38 #include <netinet/sctp_pcb.h>
39 #include <netinet/sctp_header.h>
40 #include <netinet/sctp_var.h>
42 #include <netinet6/sctp6_var.h>
44 #include <netinet/sctp_sysctl.h>
45 #include <netinet/sctp_output.h>
46 #include <netinet/sctp_uio.h>
47 #include <netinet/sctp_asconf.h>
48 #include <netinet/sctputil.h>
49 #include <netinet/sctp_indata.h>
50 #include <netinet/sctp_timer.h>
51 #include <netinet/sctp_auth.h>
52 #include <netinet/sctp_bsd_addr.h>
53 #include <netinet/udp.h>
57 extern const struct sctp_cc_functions sctp_cc_functions[];
58 extern const struct sctp_ss_functions sctp_ss_functions[];
65 /* Initialize and modify the sysctled variables */
67 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
68 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
70 * Allow a user to take no more than 1/2 the number of clusters or
71 * the SB_MAX whichever is smaller for the send window.
73 sb_max_adj = (u_long)((u_quad_t)(SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
74 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
75 (((uint32_t)nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
77 * Now for the recv window, should we take the same amount? or
78 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
79 * now I will just copy.
81 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
82 SCTP_BASE_VAR(first_time) = 0;
83 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
85 #if defined(SCTP_PACKET_LOGGING)
86 SCTP_BASE_VAR(packet_log_writers) = 0;
87 SCTP_BASE_VAR(packet_log_end) = 0;
88 bzero(&SCTP_BASE_VAR(packet_log_buffer), SCTP_PACKET_LOG_SIZE);
94 sctp_finish(void *unused __unused)
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;
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. */
223 if (net->mtu > next_mtu) {
226 net->mtu -= sizeof(struct udphdr);
229 /* Update the association MTU */
230 if (stcb->asoc.smallest_mtu > next_mtu) {
231 sctp_pathmtu_adjustment(stcb, next_mtu);
233 /* Finally, start the PMTU timer if it was running before. */
235 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
237 SCTP_TCB_UNLOCK(stcb);
239 SCTP_TCB_UNLOCK(stcb);
244 sctp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
250 struct sctp_inpcb *inp;
251 struct sctp_tcb *stcb;
252 struct sctp_nets *net;
253 struct sctp_init_chunk *ch;
254 struct sockaddr_in src, dst;
256 if (sa->sa_family != AF_INET ||
257 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
260 if (PRC_IS_REDIRECT(cmd)) {
262 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
266 inner_ip = (struct ip *)vip;
267 icmp = (struct icmp *)((caddr_t)inner_ip -
268 (sizeof(struct icmp) - sizeof(struct ip)));
269 outer_ip = (struct ip *)((caddr_t)icmp - sizeof(struct ip));
270 sh = (struct sctphdr *)((caddr_t)inner_ip + (inner_ip->ip_hl << 2));
271 memset(&src, 0, sizeof(struct sockaddr_in));
272 src.sin_family = AF_INET;
273 src.sin_len = sizeof(struct sockaddr_in);
274 src.sin_port = sh->src_port;
275 src.sin_addr = inner_ip->ip_src;
276 memset(&dst, 0, sizeof(struct sockaddr_in));
277 dst.sin_family = AF_INET;
278 dst.sin_len = sizeof(struct sockaddr_in);
279 dst.sin_port = sh->dest_port;
280 dst.sin_addr = inner_ip->ip_dst;
282 * 'dst' holds the dest of the packet that failed to be
283 * sent. 'src' holds our local endpoint address. Thus we
284 * reverse the dst and the src in the lookup.
288 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst,
289 (struct sockaddr *)&src,
292 if ((stcb != NULL) &&
295 /* Check the verification tag */
296 if (ntohl(sh->v_tag) != 0) {
298 * This must be the verification tag used
299 * for sending out packets. We don't
300 * consider packets reflecting the
303 if (ntohl(sh->v_tag) != stcb->asoc.peer_vtag) {
304 SCTP_TCB_UNLOCK(stcb);
308 if (ntohs(outer_ip->ip_len) >=
310 8 + (inner_ip->ip_hl << 2) + 20) {
312 * In this case we can check if we
313 * got an INIT chunk and if the
314 * initiate tag matches.
316 ch = (struct sctp_init_chunk *)(sh + 1);
317 if ((ch->ch.chunk_type != SCTP_INITIATION) ||
318 (ntohl(ch->init.initiate_tag) != stcb->asoc.my_vtag)) {
319 SCTP_TCB_UNLOCK(stcb);
323 SCTP_TCB_UNLOCK(stcb);
327 sctp_notify(inp, stcb, net,
330 ntohs(inner_ip->ip_len),
331 ntohs(icmp->icmp_nextmtu));
333 if ((stcb == NULL) && (inp != NULL)) {
334 /* reduce ref-count */
336 SCTP_INP_DECR_REF(inp);
337 SCTP_INP_WUNLOCK(inp);
340 SCTP_TCB_UNLOCK(stcb);
349 sctp_getcred(SYSCTL_HANDLER_ARGS)
352 struct sockaddr_in addrs[2];
353 struct sctp_inpcb *inp;
354 struct sctp_nets *net;
355 struct sctp_tcb *stcb;
359 /* FIX, for non-bsd is this right? */
360 vrf_id = SCTP_DEFAULT_VRFID;
362 error = priv_check(req->td, PRIV_NETINET_GETCRED);
367 error = SYSCTL_IN(req, addrs, sizeof(addrs));
371 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
373 &inp, &net, 1, vrf_id);
374 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
375 if ((inp != NULL) && (stcb == NULL)) {
376 /* reduce ref-count */
378 SCTP_INP_DECR_REF(inp);
381 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
385 SCTP_TCB_UNLOCK(stcb);
387 * We use the write lock here, only since in the error leg we need
388 * it. If we used RLOCK, then we would have to
389 * wlock/decr/unlock/rlock. Which in theory could create a hole.
390 * Better to use higher wlock.
394 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
396 SCTP_INP_WUNLOCK(inp);
399 cru2x(inp->sctp_socket->so_cred, &xuc);
400 SCTP_INP_WUNLOCK(inp);
401 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
406 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
407 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
412 sctp_abort(struct socket *so)
414 struct sctp_inpcb *inp;
417 inp = (struct sctp_inpcb *)so->so_pcb;
422 flags = inp->sctp_flags;
423 #ifdef SCTP_LOG_CLOSING
424 sctp_log_closing(inp, NULL, 17);
426 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
427 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
428 #ifdef SCTP_LOG_CLOSING
429 sctp_log_closing(inp, NULL, 16);
431 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
432 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
434 SCTP_SB_CLEAR(so->so_snd);
436 * same for the rcv ones, they are only here for the
439 SCTP_SB_CLEAR(so->so_rcv);
441 /* Now null out the reference, we are completely detached. */
445 flags = inp->sctp_flags;
446 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
447 goto sctp_must_try_again;
454 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
456 struct sctp_inpcb *inp;
457 struct inpcb *ip_inp;
459 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
461 inp = (struct sctp_inpcb *)so->so_pcb;
463 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
466 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
467 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
472 error = sctp_inpcb_alloc(so, vrf_id);
476 inp = (struct sctp_inpcb *)so->so_pcb;
478 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
479 ip_inp = &inp->ip_inp.inp;
480 ip_inp->inp_vflag |= INP_IPV4;
481 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
482 SCTP_INP_WUNLOCK(inp);
487 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
489 struct sctp_inpcb *inp;
491 inp = (struct sctp_inpcb *)so->so_pcb;
493 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
497 if ((addr->sa_family != AF_INET) ||
498 (addr->sa_len != sizeof(struct sockaddr_in))) {
499 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
503 return (sctp_inpcb_bind(so, addr, NULL, p));
508 sctp_close(struct socket *so)
510 struct sctp_inpcb *inp;
513 inp = (struct sctp_inpcb *)so->so_pcb;
518 * Inform all the lower layer assoc that we are done.
521 flags = inp->sctp_flags;
522 #ifdef SCTP_LOG_CLOSING
523 sctp_log_closing(inp, NULL, 17);
525 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
526 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
527 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
528 (so->so_rcv.sb_cc > 0)) {
529 #ifdef SCTP_LOG_CLOSING
530 sctp_log_closing(inp, NULL, 13);
532 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
533 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
535 #ifdef SCTP_LOG_CLOSING
536 sctp_log_closing(inp, NULL, 14);
538 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
539 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
542 * The socket is now detached, no matter what the state of
543 * the SCTP association.
546 SCTP_SB_CLEAR(so->so_snd);
548 * same for the rcv ones, they are only here for the
551 SCTP_SB_CLEAR(so->so_rcv);
553 /* Now null out the reference, we are completely detached. */
557 flags = inp->sctp_flags;
558 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
559 goto sctp_must_try_again;
567 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
568 struct mbuf *control, struct thread *p);
572 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
573 struct mbuf *control, struct thread *p)
575 struct sctp_inpcb *inp;
578 inp = (struct sctp_inpcb *)so->so_pcb;
581 sctp_m_freem(control);
584 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
588 /* Got to have an to address if we are NOT a connected socket */
589 if ((addr == NULL) &&
590 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
591 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
593 } else if (addr == NULL) {
594 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
595 error = EDESTADDRREQ;
598 sctp_m_freem(control);
604 if (addr->sa_family != AF_INET) {
605 /* must be a v4 address! */
606 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
609 sctp_m_freem(control);
612 error = EDESTADDRREQ;
617 /* now what about control */
620 SCTP_PRINTF("huh? control set?\n");
621 sctp_m_freem(inp->control);
624 inp->control = control;
628 SCTP_BUF_NEXT(inp->pkt_last) = m;
631 inp->pkt_last = inp->pkt = m;
634 /* FreeBSD uses a flag passed */
635 ((flags & PRUS_MORETOCOME) == 0)
638 * note with the current version this code will only be used
639 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
640 * re-defining sosend to use the sctp_sosend. One can
641 * optionally switch back to this code (by changing back the
642 * definitions) but this is not advisable. This code is used
643 * by FreeBSD when sending a file with sendfile() though.
647 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
657 sctp_disconnect(struct socket *so)
659 struct sctp_inpcb *inp;
661 inp = (struct sctp_inpcb *)so->so_pcb;
663 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
667 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
668 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
669 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
671 SCTP_INP_RUNLOCK(inp);
674 struct sctp_association *asoc;
675 struct sctp_tcb *stcb;
677 stcb = LIST_FIRST(&inp->sctp_asoc_list);
679 SCTP_INP_RUNLOCK(inp);
680 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
685 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
686 /* We are about to be freed, out of here */
687 SCTP_TCB_UNLOCK(stcb);
688 SCTP_INP_RUNLOCK(inp);
691 if (((so->so_options & SO_LINGER) &&
692 (so->so_linger == 0)) ||
693 (so->so_rcv.sb_cc > 0)) {
694 if (SCTP_GET_STATE(asoc) !=
695 SCTP_STATE_COOKIE_WAIT) {
696 /* Left with Data unread */
699 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_NOWAIT, 1, MT_DATA);
705 struct sctp_paramhdr *ph;
707 ph = mtod(err, struct sctp_paramhdr *);
708 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
709 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
710 ph->param_length = htons(SCTP_BUF_LEN(err));
712 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
713 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
715 SCTP_INP_RUNLOCK(inp);
716 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
717 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
718 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
720 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
721 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
722 /* No unlock tcb assoc is gone */
725 if (TAILQ_EMPTY(&asoc->send_queue) &&
726 TAILQ_EMPTY(&asoc->sent_queue) &&
727 (asoc->stream_queue_cnt == 0)) {
728 /* there is nothing queued to send, so done */
729 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
732 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
733 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
734 /* only send SHUTDOWN 1st time thru */
735 struct sctp_nets *netp;
737 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
738 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
739 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
741 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
742 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
743 sctp_stop_timers_for_shutdown(stcb);
744 if (stcb->asoc.alternate) {
745 netp = stcb->asoc.alternate;
747 netp = stcb->asoc.primary_destination;
749 sctp_send_shutdown(stcb, netp);
750 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
751 stcb->sctp_ep, stcb, netp);
752 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
753 stcb->sctp_ep, stcb, netp);
754 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
758 * we still got (or just got) data to send,
759 * so set SHUTDOWN_PENDING
762 * XXX sockets draft says that SCTP_EOF
763 * should be sent with no data. currently,
764 * we will allow user data to be sent first
765 * and move to SHUTDOWN-PENDING
767 struct sctp_nets *netp;
769 if (stcb->asoc.alternate) {
770 netp = stcb->asoc.alternate;
772 netp = stcb->asoc.primary_destination;
775 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
776 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
778 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
779 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
781 if (TAILQ_EMPTY(&asoc->send_queue) &&
782 TAILQ_EMPTY(&asoc->sent_queue) &&
783 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
787 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
788 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
789 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
790 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
791 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
792 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
793 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
795 SCTP_INP_RUNLOCK(inp);
796 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
797 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
800 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
803 soisdisconnecting(so);
804 SCTP_TCB_UNLOCK(stcb);
805 SCTP_INP_RUNLOCK(inp);
810 /* UDP model does not support this */
811 SCTP_INP_RUNLOCK(inp);
812 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
818 sctp_flush(struct socket *so, int how)
821 * We will just clear out the values and let subsequent close clear
822 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
823 * they will not be able to read the data, the socket will block
824 * that from happening.
826 struct sctp_inpcb *inp;
828 inp = (struct sctp_inpcb *)so->so_pcb;
830 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
834 /* For the 1 to many model this does nothing */
835 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
836 SCTP_INP_RUNLOCK(inp);
839 SCTP_INP_RUNLOCK(inp);
840 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
842 * First make sure the sb will be happy, we don't use these
843 * except maybe the count
846 SCTP_INP_READ_LOCK(inp);
847 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
848 SCTP_INP_READ_UNLOCK(inp);
849 SCTP_INP_WUNLOCK(inp);
850 so->so_rcv.sb_cc = 0;
851 so->so_rcv.sb_mbcnt = 0;
852 so->so_rcv.sb_mb = NULL;
854 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
856 * First make sure the sb will be happy, we don't use these
857 * except maybe the count
859 so->so_snd.sb_cc = 0;
860 so->so_snd.sb_mbcnt = 0;
861 so->so_snd.sb_mb = NULL;
868 sctp_shutdown(struct socket *so)
870 struct sctp_inpcb *inp;
872 inp = (struct sctp_inpcb *)so->so_pcb;
874 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
878 /* For UDP model this is a invalid call */
879 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
880 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
881 /* Restore the flags that the soshutdown took away. */
882 SOCKBUF_LOCK(&so->so_rcv);
883 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
884 SOCKBUF_UNLOCK(&so->so_rcv);
885 /* This proc will wakeup for read and do nothing (I hope) */
886 SCTP_INP_RUNLOCK(inp);
887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
891 * Ok, if we reach here its the TCP model and it is either a
892 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
895 struct sctp_tcb *stcb;
896 struct sctp_association *asoc;
897 struct sctp_nets *netp;
900 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
901 SCTP_INP_RUNLOCK(inp);
906 stcb = LIST_FIRST(&inp->sctp_asoc_list);
909 * Ok, we hit the case that the shutdown call was
910 * made after an abort or something. Nothing to do
913 SCTP_INP_RUNLOCK(inp);
918 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
919 SCTP_TCB_UNLOCK(stcb);
920 SCTP_INP_RUNLOCK(inp);
923 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_WAIT) &&
924 (SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_ECHOED) &&
925 (SCTP_GET_STATE(asoc) != SCTP_STATE_OPEN)) {
927 * If we are not in or before ESTABLISHED, there is
928 * no protocol action required.
930 SCTP_TCB_UNLOCK(stcb);
931 SCTP_INP_RUNLOCK(inp);
934 if (stcb->asoc.alternate) {
935 netp = stcb->asoc.alternate;
937 netp = stcb->asoc.primary_destination;
939 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) &&
940 TAILQ_EMPTY(&asoc->send_queue) &&
941 TAILQ_EMPTY(&asoc->sent_queue) &&
942 (asoc->stream_queue_cnt == 0)) {
943 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
946 /* there is nothing queued to send, so I'm done... */
947 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
948 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
949 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
950 sctp_stop_timers_for_shutdown(stcb);
951 sctp_send_shutdown(stcb, netp);
952 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
953 stcb->sctp_ep, stcb, netp);
956 * We still got (or just got) data to send, so set
959 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
960 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
961 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_PARTIAL_MSG_LEFT);
963 if (TAILQ_EMPTY(&asoc->send_queue) &&
964 TAILQ_EMPTY(&asoc->sent_queue) &&
965 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
969 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
970 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
971 sctp_abort_an_association(stcb->sctp_ep, stcb,
972 op_err, SCTP_SO_LOCKED);
973 SCTP_INP_RUNLOCK(inp);
977 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, netp);
979 * XXX: Why do this in the case where we have still data
982 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
983 SCTP_TCB_UNLOCK(stcb);
984 SCTP_INP_RUNLOCK(inp);
990 * copies a "user" presentable address and removes embedded scope, etc.
991 * returns 0 on success, 1 on error
994 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
997 struct sockaddr_in6 lsa6;
999 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1002 memcpy(ss, sa, sa->sa_len);
1009 * NOTE: assumes addr lock is held
1012 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1013 struct sctp_tcb *stcb,
1015 struct sockaddr_storage *sas,
1018 struct sctp_ifn *sctp_ifn;
1019 struct sctp_ifa *sctp_ifa;
1023 int ipv4_local_scope, ipv4_addr_legal;
1026 int local_scope, site_scope, ipv6_addr_legal;
1028 struct sctp_vrf *vrf;
1035 /* Turn on all the appropriate scope */
1036 loopback_scope = stcb->asoc.scope.loopback_scope;
1038 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1039 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1042 local_scope = stcb->asoc.scope.local_scope;
1043 site_scope = stcb->asoc.scope.site_scope;
1044 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1047 /* Use generic values for endpoints. */
1050 ipv4_local_scope = 1;
1056 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1058 ipv6_addr_legal = 1;
1061 if (SCTP_IPV6_V6ONLY(inp)) {
1062 ipv4_addr_legal = 0;
1064 ipv4_addr_legal = 1;
1069 ipv6_addr_legal = 0;
1072 ipv4_addr_legal = 1;
1076 vrf = sctp_find_vrf(vrf_id);
1080 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1081 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1082 if ((loopback_scope == 0) &&
1083 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1084 /* Skip loopback if loopback_scope not set */
1087 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1090 * For the BOUND-ALL case, the list
1091 * associated with a TCB is Always
1092 * considered a reverse list.. i.e.
1093 * it lists addresses that are NOT
1094 * part of the association. If this
1095 * is one of those we must skip it.
1097 if (sctp_is_addr_restricted(stcb,
1102 switch (sctp_ifa->address.sa.sa_family) {
1105 if (ipv4_addr_legal) {
1106 struct sockaddr_in *sin;
1108 sin = &sctp_ifa->address.sin;
1109 if (sin->sin_addr.s_addr == 0) {
1117 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1118 &sin->sin_addr) != 0) {
1121 if ((ipv4_local_scope == 0) &&
1122 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1126 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1127 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1128 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1129 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1130 actual += sizeof(struct sockaddr_in6);
1133 memcpy(sas, sin, sizeof(*sin));
1134 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1135 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1136 actual += sizeof(*sin);
1140 if (actual >= limit) {
1150 if (ipv6_addr_legal) {
1151 struct sockaddr_in6 *sin6;
1153 sin6 = &sctp_ifa->address.sin6;
1154 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1162 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1163 &sin6->sin6_addr) != 0) {
1166 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1167 if (local_scope == 0)
1169 if (sin6->sin6_scope_id == 0) {
1170 if (sa6_recoverscope(sin6) != 0)
1183 if ((site_scope == 0) &&
1184 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1187 memcpy(sas, sin6, sizeof(*sin6));
1188 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1189 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1190 actual += sizeof(*sin6);
1191 if (actual >= limit) {
1206 struct sctp_laddr *laddr;
1208 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1210 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1214 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1216 switch (laddr->ifa->address.sa.sa_family) {
1219 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1224 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1231 sas = (struct sockaddr_storage *)((caddr_t)sas +
1232 laddr->ifa->address.sa.sa_len);
1233 actual += laddr->ifa->address.sa.sa_len;
1234 if (actual >= limit) {
1243 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1244 struct sctp_tcb *stcb,
1246 struct sockaddr_storage *sas)
1250 SCTP_IPI_ADDR_RLOCK();
1251 /* fill up addresses for the endpoint's default vrf */
1252 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1254 SCTP_IPI_ADDR_RUNLOCK();
1259 * NOTE: assumes addr lock is held
1262 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1265 struct sctp_vrf *vrf = NULL;
1268 * In both sub-set bound an bound_all cases we return the MAXIMUM
1269 * number of addresses that you COULD get. In reality the sub-set
1270 * bound may have an exclusion list for a given TCB OR in the
1271 * bound-all case a TCB may NOT include the loopback or other
1272 * addresses as well.
1274 vrf = sctp_find_vrf(vrf_id);
1278 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1279 struct sctp_ifn *sctp_ifn;
1280 struct sctp_ifa *sctp_ifa;
1282 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1283 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1284 /* Count them if they are the right type */
1285 switch (sctp_ifa->address.sa.sa_family) {
1289 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1290 cnt += sizeof(struct sockaddr_in6);
1292 cnt += sizeof(struct sockaddr_in);
1294 cnt += sizeof(struct sockaddr_in);
1300 cnt += sizeof(struct sockaddr_in6);
1309 struct sctp_laddr *laddr;
1311 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1312 switch (laddr->ifa->address.sa.sa_family) {
1316 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1317 cnt += sizeof(struct sockaddr_in6);
1319 cnt += sizeof(struct sockaddr_in);
1321 cnt += sizeof(struct sockaddr_in);
1327 cnt += sizeof(struct sockaddr_in6);
1339 sctp_count_max_addresses(struct sctp_inpcb *inp)
1343 SCTP_IPI_ADDR_RLOCK();
1344 /* count addresses for the endpoint's default VRF */
1345 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1346 SCTP_IPI_ADDR_RUNLOCK();
1351 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1352 size_t optsize, void *p, int delay)
1355 int creat_lock_on = 0;
1356 struct sctp_tcb *stcb = NULL;
1357 struct sockaddr *sa;
1358 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1360 int bad_addresses = 0;
1363 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1365 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1366 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1367 /* We are already connected AND the TCP model */
1368 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1369 return (EADDRINUSE);
1371 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1372 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1373 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1376 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1377 SCTP_INP_RLOCK(inp);
1378 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1379 SCTP_INP_RUNLOCK(inp);
1382 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1385 SCTP_INP_INCR_REF(inp);
1386 SCTP_ASOC_CREATE_LOCK(inp);
1388 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1389 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1390 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1394 totaddrp = (unsigned int *)optval;
1395 totaddr = *totaddrp;
1396 sa = (struct sockaddr *)(totaddrp + 1);
1397 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (unsigned int)(optsize - sizeof(int)), &bad_addresses);
1398 if ((stcb != NULL) || bad_addresses) {
1399 /* Already have or am bring up an association */
1400 SCTP_ASOC_CREATE_UNLOCK(inp);
1403 SCTP_TCB_UNLOCK(stcb);
1404 if (bad_addresses == 0) {
1405 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1411 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1416 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1418 struct in6pcb *inp6;
1420 inp6 = (struct in6pcb *)inp;
1421 if (SCTP_IPV6_V6ONLY(inp6)) {
1423 * if IPV6_V6ONLY flag, ignore connections destined
1424 * to a v4 addr or v4-mapped addr
1426 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1432 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1433 SCTP_PCB_FLAGS_UNBOUND) {
1434 /* Bind a ephemeral port */
1435 error = sctp_inpcb_bind(so, NULL, NULL, p);
1440 /* FIX ME: do we want to pass in a vrf on the connect call? */
1441 vrf_id = inp->def_vrf_id;
1444 /* We are GOOD to go */
1445 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1446 inp->sctp_ep.pre_open_stream_count,
1451 /* Gak! no memory */
1454 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1455 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1456 /* Set the connected flag so we can queue data */
1459 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1460 /* move to second address */
1461 switch (sa->sa_family) {
1464 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1469 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1477 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1478 /* Fill in the return id */
1480 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE,
1481 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
1484 a_id = (sctp_assoc_t *)optval;
1485 *a_id = sctp_get_associd(stcb);
1487 /* initialize authentication parameters for the assoc */
1488 sctp_initialize_auth_params(inp, stcb);
1491 /* doing delayed connection */
1492 stcb->asoc.delayed_connection = 1;
1493 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1495 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1496 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1498 SCTP_TCB_UNLOCK(stcb);
1500 if (creat_lock_on) {
1501 SCTP_ASOC_CREATE_UNLOCK(inp);
1503 SCTP_INP_DECR_REF(inp);
1507 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1508 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1509 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1510 SCTP_INP_RLOCK(inp); \
1511 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1513 SCTP_TCB_LOCK(stcb); \
1515 SCTP_INP_RUNLOCK(inp); \
1516 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1517 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1518 if (stcb == NULL) { \
1519 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1529 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1530 if (size < sizeof(type)) { \
1531 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1535 destp = (type *)srcp; \
1540 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1543 struct sctp_inpcb *inp = NULL;
1545 struct sctp_tcb *stcb = NULL;
1547 if (optval == NULL) {
1548 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1551 inp = (struct sctp_inpcb *)so->so_pcb;
1553 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1560 case SCTP_AUTOCLOSE:
1561 case SCTP_EXPLICIT_EOR:
1562 case SCTP_AUTO_ASCONF:
1563 case SCTP_DISABLE_FRAGMENTS:
1564 case SCTP_I_WANT_MAPPED_V4_ADDR:
1565 case SCTP_USE_EXT_RCVINFO:
1566 SCTP_INP_RLOCK(inp);
1568 case SCTP_DISABLE_FRAGMENTS:
1569 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1571 case SCTP_I_WANT_MAPPED_V4_ADDR:
1572 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1574 case SCTP_AUTO_ASCONF:
1575 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1576 /* only valid for bound all sockets */
1577 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1579 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1584 case SCTP_EXPLICIT_EOR:
1585 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1588 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1590 case SCTP_USE_EXT_RCVINFO:
1591 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1593 case SCTP_AUTOCLOSE:
1594 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1595 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1601 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1602 error = ENOPROTOOPT;
1603 } /* end switch (sopt->sopt_name) */
1604 if (*optsize < sizeof(val)) {
1605 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1609 SCTP_INP_RUNLOCK(inp);
1611 /* return the option value */
1612 *(int *)optval = val;
1613 *optsize = sizeof(val);
1616 case SCTP_GET_PACKET_LOG:
1618 #ifdef SCTP_PACKET_LOGGING
1622 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1623 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1626 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1631 case SCTP_REUSE_PORT:
1635 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1636 /* Can't do this for a 1-m socket */
1640 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1641 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1642 *optsize = sizeof(uint32_t);
1645 case SCTP_PARTIAL_DELIVERY_POINT:
1649 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1650 *value = inp->partial_delivery_point;
1651 *optsize = sizeof(uint32_t);
1654 case SCTP_FRAGMENT_INTERLEAVE:
1658 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1659 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1660 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1661 *value = SCTP_FRAG_LEVEL_2;
1663 *value = SCTP_FRAG_LEVEL_1;
1666 *value = SCTP_FRAG_LEVEL_0;
1668 *optsize = sizeof(uint32_t);
1671 case SCTP_INTERLEAVING_SUPPORTED:
1673 struct sctp_assoc_value *av;
1675 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1676 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1679 av->assoc_value = stcb->asoc.idata_supported;
1680 SCTP_TCB_UNLOCK(stcb);
1682 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1683 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1684 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1685 SCTP_INP_RLOCK(inp);
1686 if (inp->idata_supported) {
1687 av->assoc_value = 1;
1689 av->assoc_value = 0;
1691 SCTP_INP_RUNLOCK(inp);
1693 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1698 *optsize = sizeof(struct sctp_assoc_value);
1702 case SCTP_CMT_ON_OFF:
1704 struct sctp_assoc_value *av;
1706 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1707 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1709 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1710 SCTP_TCB_UNLOCK(stcb);
1712 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1713 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1714 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1715 SCTP_INP_RLOCK(inp);
1716 av->assoc_value = inp->sctp_cmt_on_off;
1717 SCTP_INP_RUNLOCK(inp);
1719 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1724 *optsize = sizeof(struct sctp_assoc_value);
1728 case SCTP_PLUGGABLE_CC:
1730 struct sctp_assoc_value *av;
1732 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1733 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1735 av->assoc_value = stcb->asoc.congestion_control_module;
1736 SCTP_TCB_UNLOCK(stcb);
1738 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1739 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1740 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1741 SCTP_INP_RLOCK(inp);
1742 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1743 SCTP_INP_RUNLOCK(inp);
1745 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1750 *optsize = sizeof(struct sctp_assoc_value);
1754 case SCTP_CC_OPTION:
1756 struct sctp_cc_option *cc_opt;
1758 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1759 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1763 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1766 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1767 *optsize = sizeof(struct sctp_cc_option);
1769 SCTP_TCB_UNLOCK(stcb);
1773 case SCTP_PLUGGABLE_SS:
1775 struct sctp_assoc_value *av;
1777 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1778 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1780 av->assoc_value = stcb->asoc.stream_scheduling_module;
1781 SCTP_TCB_UNLOCK(stcb);
1783 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1784 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1785 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1786 SCTP_INP_RLOCK(inp);
1787 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1788 SCTP_INP_RUNLOCK(inp);
1790 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1795 *optsize = sizeof(struct sctp_assoc_value);
1801 struct sctp_stream_value *av;
1803 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1804 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1806 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1807 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1808 &av->stream_value) < 0)) {
1809 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1812 *optsize = sizeof(struct sctp_stream_value);
1814 SCTP_TCB_UNLOCK(stcb);
1817 * Can't get stream value without
1820 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1825 case SCTP_GET_ADDR_LEN:
1827 struct sctp_assoc_value *av;
1829 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1832 if (av->assoc_value == AF_INET) {
1833 av->assoc_value = sizeof(struct sockaddr_in);
1838 if (av->assoc_value == AF_INET6) {
1839 av->assoc_value = sizeof(struct sockaddr_in6);
1844 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1846 *optsize = sizeof(struct sctp_assoc_value);
1850 case SCTP_GET_ASSOC_NUMBER:
1852 uint32_t *value, cnt;
1854 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1855 SCTP_INP_RLOCK(inp);
1856 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1857 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1858 /* Can't do this for a 1-1 socket */
1860 SCTP_INP_RUNLOCK(inp);
1864 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1867 SCTP_INP_RUNLOCK(inp);
1869 *optsize = sizeof(uint32_t);
1872 case SCTP_GET_ASSOC_ID_LIST:
1874 struct sctp_assoc_ids *ids;
1878 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1879 SCTP_INP_RLOCK(inp);
1880 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1881 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1882 /* Can't do this for a 1-1 socket */
1884 SCTP_INP_RUNLOCK(inp);
1888 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1889 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1891 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1894 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1899 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1903 SCTP_INP_RUNLOCK(inp);
1905 ids->gaids_number_of_ids = at;
1906 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1912 struct sctp_assoc_value *av;
1914 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1915 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1918 av->assoc_value = stcb->asoc.context;
1919 SCTP_TCB_UNLOCK(stcb);
1921 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1922 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1923 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1924 SCTP_INP_RLOCK(inp);
1925 av->assoc_value = inp->sctp_context;
1926 SCTP_INP_RUNLOCK(inp);
1928 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1933 *optsize = sizeof(struct sctp_assoc_value);
1939 uint32_t *default_vrfid;
1941 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1942 *default_vrfid = inp->def_vrf_id;
1943 *optsize = sizeof(uint32_t);
1946 case SCTP_GET_ASOC_VRF:
1948 struct sctp_assoc_value *id;
1950 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1951 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1954 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1956 id->assoc_value = stcb->asoc.vrf_id;
1957 *optsize = sizeof(struct sctp_assoc_value);
1961 case SCTP_GET_VRF_IDS:
1963 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1967 case SCTP_GET_NONCE_VALUES:
1969 struct sctp_get_nonce_values *gnv;
1971 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1972 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1975 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1976 gnv->gn_local_tag = stcb->asoc.my_vtag;
1977 SCTP_TCB_UNLOCK(stcb);
1978 *optsize = sizeof(struct sctp_get_nonce_values);
1980 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1985 case SCTP_DELAYED_SACK:
1987 struct sctp_sack_info *sack;
1989 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1990 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1992 sack->sack_delay = stcb->asoc.delayed_ack;
1993 sack->sack_freq = stcb->asoc.sack_freq;
1994 SCTP_TCB_UNLOCK(stcb);
1996 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1997 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1998 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
1999 SCTP_INP_RLOCK(inp);
2000 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2001 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2002 SCTP_INP_RUNLOCK(inp);
2004 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2009 *optsize = sizeof(struct sctp_sack_info);
2013 case SCTP_GET_SNDBUF_USE:
2015 struct sctp_sockstat *ss;
2017 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2018 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2021 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2022 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2023 stcb->asoc.size_on_all_streams);
2024 SCTP_TCB_UNLOCK(stcb);
2025 *optsize = sizeof(struct sctp_sockstat);
2027 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2032 case SCTP_MAX_BURST:
2034 struct sctp_assoc_value *av;
2036 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2037 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2040 av->assoc_value = stcb->asoc.max_burst;
2041 SCTP_TCB_UNLOCK(stcb);
2043 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2044 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2045 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2046 SCTP_INP_RLOCK(inp);
2047 av->assoc_value = inp->sctp_ep.max_burst;
2048 SCTP_INP_RUNLOCK(inp);
2050 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2055 *optsize = sizeof(struct sctp_assoc_value);
2061 struct sctp_assoc_value *av;
2064 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2065 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2068 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2069 SCTP_TCB_UNLOCK(stcb);
2071 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2072 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2073 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2074 SCTP_INP_RLOCK(inp);
2075 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2076 ovh = SCTP_MED_OVERHEAD;
2078 ovh = SCTP_MED_V4_OVERHEAD;
2080 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2081 av->assoc_value = 0;
2083 av->assoc_value = inp->sctp_frag_point - ovh;
2084 SCTP_INP_RUNLOCK(inp);
2086 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2091 *optsize = sizeof(struct sctp_assoc_value);
2095 case SCTP_GET_STAT_LOG:
2096 error = sctp_fill_stat_log(optval, optsize);
2100 struct sctp_event_subscribe *events;
2102 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2103 memset(events, 0, sizeof(struct sctp_event_subscribe));
2104 SCTP_INP_RLOCK(inp);
2105 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2106 events->sctp_data_io_event = 1;
2108 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2109 events->sctp_association_event = 1;
2111 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2112 events->sctp_address_event = 1;
2114 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2115 events->sctp_send_failure_event = 1;
2117 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2118 events->sctp_peer_error_event = 1;
2120 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2121 events->sctp_shutdown_event = 1;
2123 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2124 events->sctp_partial_delivery_event = 1;
2126 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2127 events->sctp_adaptation_layer_event = 1;
2129 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2130 events->sctp_authentication_event = 1;
2132 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2133 events->sctp_sender_dry_event = 1;
2135 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2136 events->sctp_stream_reset_event = 1;
2137 SCTP_INP_RUNLOCK(inp);
2138 *optsize = sizeof(struct sctp_event_subscribe);
2141 case SCTP_ADAPTATION_LAYER:
2145 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2147 SCTP_INP_RLOCK(inp);
2148 *value = inp->sctp_ep.adaptation_layer_indicator;
2149 SCTP_INP_RUNLOCK(inp);
2150 *optsize = sizeof(uint32_t);
2153 case SCTP_SET_INITIAL_DBG_SEQ:
2157 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2158 SCTP_INP_RLOCK(inp);
2159 *value = inp->sctp_ep.initial_sequence_debug;
2160 SCTP_INP_RUNLOCK(inp);
2161 *optsize = sizeof(uint32_t);
2164 case SCTP_GET_LOCAL_ADDR_SIZE:
2168 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2169 SCTP_INP_RLOCK(inp);
2170 *value = sctp_count_max_addresses(inp);
2171 SCTP_INP_RUNLOCK(inp);
2172 *optsize = sizeof(uint32_t);
2175 case SCTP_GET_REMOTE_ADDR_SIZE:
2179 struct sctp_nets *net;
2181 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2182 /* FIXME MT: change to sctp_assoc_value? */
2183 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2187 /* Count the sizes */
2188 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2189 switch (net->ro._l_addr.sa.sa_family) {
2193 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2194 size += sizeof(struct sockaddr_in6);
2196 size += sizeof(struct sockaddr_in);
2199 size += sizeof(struct sockaddr_in);
2205 size += sizeof(struct sockaddr_in6);
2212 SCTP_TCB_UNLOCK(stcb);
2213 *value = (uint32_t)size;
2214 *optsize = sizeof(uint32_t);
2216 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2221 case SCTP_GET_PEER_ADDRESSES:
2223 * Get the address information, an array is passed in to
2224 * fill up we pack it.
2228 struct sockaddr_storage *sas;
2229 struct sctp_nets *net;
2230 struct sctp_getaddresses *saddr;
2232 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2233 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2236 left = (*optsize) - sizeof(struct sctp_getaddresses);
2237 *optsize = sizeof(struct sctp_getaddresses);
2238 sas = (struct sockaddr_storage *)&saddr->addr[0];
2240 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2241 switch (net->ro._l_addr.sa.sa_family) {
2245 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2246 cpsz = sizeof(struct sockaddr_in6);
2248 cpsz = sizeof(struct sockaddr_in);
2251 cpsz = sizeof(struct sockaddr_in);
2257 cpsz = sizeof(struct sockaddr_in6);
2268 /* not enough room. */
2271 #if defined(INET) && defined(INET6)
2272 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2273 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2274 /* Must map the address */
2275 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2276 (struct sockaddr_in6 *)sas);
2278 memcpy(sas, &net->ro._l_addr, cpsz);
2281 memcpy(sas, &net->ro._l_addr, cpsz);
2283 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2285 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2289 SCTP_TCB_UNLOCK(stcb);
2291 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2296 case SCTP_GET_LOCAL_ADDRESSES:
2298 size_t limit, actual;
2299 struct sockaddr_storage *sas;
2300 struct sctp_getaddresses *saddr;
2302 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2303 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2305 sas = (struct sockaddr_storage *)&saddr->addr[0];
2306 limit = *optsize - sizeof(sctp_assoc_t);
2307 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2309 SCTP_TCB_UNLOCK(stcb);
2311 *optsize = sizeof(struct sockaddr_storage) + actual;
2314 case SCTP_PEER_ADDR_PARAMS:
2316 struct sctp_paddrparams *paddrp;
2317 struct sctp_nets *net;
2318 struct sockaddr *addr;
2319 #if defined(INET) && defined(INET6)
2320 struct sockaddr_in sin_store;
2323 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2324 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2326 #if defined(INET) && defined(INET6)
2327 if (paddrp->spp_address.ss_family == AF_INET6) {
2328 struct sockaddr_in6 *sin6;
2330 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2331 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2332 in6_sin6_2_sin(&sin_store, sin6);
2333 addr = (struct sockaddr *)&sin_store;
2335 addr = (struct sockaddr *)&paddrp->spp_address;
2338 addr = (struct sockaddr *)&paddrp->spp_address;
2341 addr = (struct sockaddr *)&paddrp->spp_address;
2344 net = sctp_findnet(stcb, addr);
2347 * We increment here since
2348 * sctp_findassociation_ep_addr() wil do a
2349 * decrement if it finds the stcb as long as
2350 * the locked tcb (last argument) is NOT a
2354 SCTP_INP_INCR_REF(inp);
2355 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2357 SCTP_INP_DECR_REF(inp);
2360 if ((stcb != NULL) && (net == NULL)) {
2362 if (addr->sa_family == AF_INET) {
2363 struct sockaddr_in *sin;
2365 sin = (struct sockaddr_in *)addr;
2366 if (sin->sin_addr.s_addr != INADDR_ANY) {
2368 SCTP_TCB_UNLOCK(stcb);
2369 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2375 if (addr->sa_family == AF_INET6) {
2376 struct sockaddr_in6 *sin6;
2378 sin6 = (struct sockaddr_in6 *)addr;
2379 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2381 SCTP_TCB_UNLOCK(stcb);
2382 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2388 error = EAFNOSUPPORT;
2389 SCTP_TCB_UNLOCK(stcb);
2390 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2395 /* Applies to the specific association */
2396 paddrp->spp_flags = 0;
2398 paddrp->spp_hbinterval = net->heart_beat_delay;
2399 paddrp->spp_pathmaxrxt = net->failure_threshold;
2400 paddrp->spp_pathmtu = net->mtu;
2401 switch (net->ro._l_addr.sa.sa_family) {
2404 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2409 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2415 /* get flags for HB */
2416 if (net->dest_state & SCTP_ADDR_NOHB) {
2417 paddrp->spp_flags |= SPP_HB_DISABLE;
2419 paddrp->spp_flags |= SPP_HB_ENABLE;
2421 /* get flags for PMTU */
2422 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2423 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2425 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2427 if (net->dscp & 0x01) {
2428 paddrp->spp_dscp = net->dscp & 0xfc;
2429 paddrp->spp_flags |= SPP_DSCP;
2432 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2433 (net->flowlabel & 0x80000000)) {
2434 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2435 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2440 * No destination so return default
2443 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2444 paddrp->spp_pathmtu = 0;
2445 if (stcb->asoc.default_dscp & 0x01) {
2446 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2447 paddrp->spp_flags |= SPP_DSCP;
2450 if (stcb->asoc.default_flowlabel & 0x80000000) {
2451 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2452 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2455 /* default settings should be these */
2456 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2457 paddrp->spp_flags |= SPP_HB_DISABLE;
2459 paddrp->spp_flags |= SPP_HB_ENABLE;
2461 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2462 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2464 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2466 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2468 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2469 SCTP_TCB_UNLOCK(stcb);
2471 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2472 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2473 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2474 /* Use endpoint defaults */
2475 SCTP_INP_RLOCK(inp);
2476 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2477 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2478 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2479 /* get inp's default */
2480 if (inp->sctp_ep.default_dscp & 0x01) {
2481 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2482 paddrp->spp_flags |= SPP_DSCP;
2485 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2486 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2487 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2488 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2491 /* can't return this */
2492 paddrp->spp_pathmtu = 0;
2494 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2495 paddrp->spp_flags |= SPP_HB_ENABLE;
2497 paddrp->spp_flags |= SPP_HB_DISABLE;
2499 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2500 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2502 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2504 SCTP_INP_RUNLOCK(inp);
2506 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2511 *optsize = sizeof(struct sctp_paddrparams);
2515 case SCTP_GET_PEER_ADDR_INFO:
2517 struct sctp_paddrinfo *paddri;
2518 struct sctp_nets *net;
2519 struct sockaddr *addr;
2520 #if defined(INET) && defined(INET6)
2521 struct sockaddr_in sin_store;
2524 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2525 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2527 #if defined(INET) && defined(INET6)
2528 if (paddri->spinfo_address.ss_family == AF_INET6) {
2529 struct sockaddr_in6 *sin6;
2531 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2532 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2533 in6_sin6_2_sin(&sin_store, sin6);
2534 addr = (struct sockaddr *)&sin_store;
2536 addr = (struct sockaddr *)&paddri->spinfo_address;
2539 addr = (struct sockaddr *)&paddri->spinfo_address;
2542 addr = (struct sockaddr *)&paddri->spinfo_address;
2545 net = sctp_findnet(stcb, addr);
2548 * We increment here since
2549 * sctp_findassociation_ep_addr() wil do a
2550 * decrement if it finds the stcb as long as
2551 * the locked tcb (last argument) is NOT a
2555 SCTP_INP_INCR_REF(inp);
2556 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2558 SCTP_INP_DECR_REF(inp);
2562 if ((stcb != NULL) && (net != NULL)) {
2563 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2564 /* It's unconfirmed */
2565 paddri->spinfo_state = SCTP_UNCONFIRMED;
2566 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2568 paddri->spinfo_state = SCTP_ACTIVE;
2571 paddri->spinfo_state = SCTP_INACTIVE;
2573 paddri->spinfo_cwnd = net->cwnd;
2574 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2575 paddri->spinfo_rto = net->RTO;
2576 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2577 paddri->spinfo_mtu = net->mtu;
2578 switch (addr->sa_family) {
2581 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2586 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2592 SCTP_TCB_UNLOCK(stcb);
2593 *optsize = sizeof(struct sctp_paddrinfo);
2596 SCTP_TCB_UNLOCK(stcb);
2598 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2603 case SCTP_PCB_STATUS:
2605 struct sctp_pcbinfo *spcb;
2607 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2608 sctp_fill_pcbinfo(spcb);
2609 *optsize = sizeof(struct sctp_pcbinfo);
2614 struct sctp_nets *net;
2615 struct sctp_status *sstat;
2617 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2618 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2621 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2625 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2626 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2627 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2628 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2630 * We can't include chunks that have been passed to
2631 * the socket layer. Only things in queue.
2633 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2634 stcb->asoc.cnt_on_all_streams);
2637 sstat->sstat_instrms = stcb->asoc.streamincnt;
2638 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2639 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2640 memcpy(&sstat->sstat_primary.spinfo_address,
2641 &stcb->asoc.primary_destination->ro._l_addr,
2642 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2643 net = stcb->asoc.primary_destination;
2644 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2646 * Again the user can get info from sctp_constants.h
2647 * for what the state of the network is.
2649 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2650 /* It's unconfirmed */
2651 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2652 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2654 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2657 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2659 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2660 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2661 sstat->sstat_primary.spinfo_rto = net->RTO;
2662 sstat->sstat_primary.spinfo_mtu = net->mtu;
2663 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2666 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2671 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2677 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2678 SCTP_TCB_UNLOCK(stcb);
2679 *optsize = sizeof(struct sctp_status);
2684 struct sctp_rtoinfo *srto;
2686 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2687 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2690 srto->srto_initial = stcb->asoc.initial_rto;
2691 srto->srto_max = stcb->asoc.maxrto;
2692 srto->srto_min = stcb->asoc.minrto;
2693 SCTP_TCB_UNLOCK(stcb);
2695 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2696 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2697 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2698 SCTP_INP_RLOCK(inp);
2699 srto->srto_initial = inp->sctp_ep.initial_rto;
2700 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2701 srto->srto_min = inp->sctp_ep.sctp_minrto;
2702 SCTP_INP_RUNLOCK(inp);
2704 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2709 *optsize = sizeof(struct sctp_rtoinfo);
2715 struct sctp_timeouts *stimo;
2717 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2718 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2721 stimo->stimo_init = stcb->asoc.timoinit;
2722 stimo->stimo_data = stcb->asoc.timodata;
2723 stimo->stimo_sack = stcb->asoc.timosack;
2724 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2725 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2726 stimo->stimo_cookie = stcb->asoc.timocookie;
2727 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2728 SCTP_TCB_UNLOCK(stcb);
2729 *optsize = sizeof(struct sctp_timeouts);
2731 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2736 case SCTP_ASSOCINFO:
2738 struct sctp_assocparams *sasoc;
2740 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2741 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2744 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2745 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2746 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2747 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2748 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2749 SCTP_TCB_UNLOCK(stcb);
2751 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2752 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2753 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2754 SCTP_INP_RLOCK(inp);
2755 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2756 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2757 sasoc->sasoc_number_peer_destinations = 0;
2758 sasoc->sasoc_peer_rwnd = 0;
2759 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2760 SCTP_INP_RUNLOCK(inp);
2762 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2767 *optsize = sizeof(struct sctp_assocparams);
2771 case SCTP_DEFAULT_SEND_PARAM:
2773 struct sctp_sndrcvinfo *s_info;
2775 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2776 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2779 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2780 SCTP_TCB_UNLOCK(stcb);
2782 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2783 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2784 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2785 SCTP_INP_RLOCK(inp);
2786 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2787 SCTP_INP_RUNLOCK(inp);
2789 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2794 *optsize = sizeof(struct sctp_sndrcvinfo);
2800 struct sctp_initmsg *sinit;
2802 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2803 SCTP_INP_RLOCK(inp);
2804 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2805 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2806 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2807 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2808 SCTP_INP_RUNLOCK(inp);
2809 *optsize = sizeof(struct sctp_initmsg);
2812 case SCTP_PRIMARY_ADDR:
2813 /* we allow a "get" operation on this */
2815 struct sctp_setprim *ssp;
2817 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2818 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2821 union sctp_sockstore *addr;
2823 addr = &stcb->asoc.primary_destination->ro._l_addr;
2824 switch (addr->sa.sa_family) {
2828 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2829 in6_sin_2_v4mapsin6(&addr->sin,
2830 (struct sockaddr_in6 *)&ssp->ssp_addr);
2832 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2835 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2841 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2847 SCTP_TCB_UNLOCK(stcb);
2848 *optsize = sizeof(struct sctp_setprim);
2850 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2855 case SCTP_HMAC_IDENT:
2857 struct sctp_hmacalgo *shmac;
2858 sctp_hmaclist_t *hmaclist;
2862 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2864 SCTP_INP_RLOCK(inp);
2865 hmaclist = inp->sctp_ep.local_hmacs;
2866 if (hmaclist == NULL) {
2867 /* no HMACs to return */
2868 *optsize = sizeof(*shmac);
2869 SCTP_INP_RUNLOCK(inp);
2872 /* is there room for all of the hmac ids? */
2873 size = sizeof(*shmac) + (hmaclist->num_algo *
2874 sizeof(shmac->shmac_idents[0]));
2875 if ((size_t)(*optsize) < size) {
2876 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2878 SCTP_INP_RUNLOCK(inp);
2881 /* copy in the list */
2882 shmac->shmac_number_of_idents = hmaclist->num_algo;
2883 for (i = 0; i < hmaclist->num_algo; i++) {
2884 shmac->shmac_idents[i] = hmaclist->hmac[i];
2886 SCTP_INP_RUNLOCK(inp);
2890 case SCTP_AUTH_ACTIVE_KEY:
2892 struct sctp_authkeyid *scact;
2894 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2895 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2898 /* get the active key on the assoc */
2899 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2900 SCTP_TCB_UNLOCK(stcb);
2902 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2903 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2904 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2905 /* get the endpoint active key */
2906 SCTP_INP_RLOCK(inp);
2907 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2908 SCTP_INP_RUNLOCK(inp);
2910 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2915 *optsize = sizeof(struct sctp_authkeyid);
2919 case SCTP_LOCAL_AUTH_CHUNKS:
2921 struct sctp_authchunks *sac;
2922 sctp_auth_chklist_t *chklist = NULL;
2925 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2926 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2929 /* get off the assoc */
2930 chklist = stcb->asoc.local_auth_chunks;
2931 /* is there enough space? */
2932 size = sctp_auth_get_chklist_size(chklist);
2933 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2935 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2937 /* copy in the chunks */
2938 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2939 sac->gauth_number_of_chunks = (uint32_t)size;
2940 *optsize = sizeof(struct sctp_authchunks) + size;
2942 SCTP_TCB_UNLOCK(stcb);
2944 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2945 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2946 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2947 /* get off the endpoint */
2948 SCTP_INP_RLOCK(inp);
2949 chklist = inp->sctp_ep.local_auth_chunks;
2950 /* is there enough space? */
2951 size = sctp_auth_get_chklist_size(chklist);
2952 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2954 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2956 /* copy in the chunks */
2957 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2958 sac->gauth_number_of_chunks = (uint32_t)size;
2959 *optsize = sizeof(struct sctp_authchunks) + size;
2961 SCTP_INP_RUNLOCK(inp);
2963 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2969 case SCTP_PEER_AUTH_CHUNKS:
2971 struct sctp_authchunks *sac;
2972 sctp_auth_chklist_t *chklist = NULL;
2975 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2976 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2979 /* get off the assoc */
2980 chklist = stcb->asoc.peer_auth_chunks;
2981 /* is there enough space? */
2982 size = sctp_auth_get_chklist_size(chklist);
2983 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2985 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2987 /* copy in the chunks */
2988 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2989 sac->gauth_number_of_chunks = (uint32_t)size;
2990 *optsize = sizeof(struct sctp_authchunks) + size;
2992 SCTP_TCB_UNLOCK(stcb);
2994 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3001 struct sctp_event *event;
3002 uint32_t event_type;
3004 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3005 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3007 switch (event->se_type) {
3008 case SCTP_ASSOC_CHANGE:
3009 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3011 case SCTP_PEER_ADDR_CHANGE:
3012 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3014 case SCTP_REMOTE_ERROR:
3015 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3017 case SCTP_SEND_FAILED:
3018 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3020 case SCTP_SHUTDOWN_EVENT:
3021 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3023 case SCTP_ADAPTATION_INDICATION:
3024 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3026 case SCTP_PARTIAL_DELIVERY_EVENT:
3027 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3029 case SCTP_AUTHENTICATION_EVENT:
3030 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3032 case SCTP_STREAM_RESET_EVENT:
3033 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3035 case SCTP_SENDER_DRY_EVENT:
3036 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3038 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3040 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3043 case SCTP_ASSOC_RESET_EVENT:
3044 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3046 case SCTP_STREAM_CHANGE_EVENT:
3047 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3049 case SCTP_SEND_FAILED_EVENT:
3050 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3054 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3058 if (event_type > 0) {
3060 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3061 SCTP_TCB_UNLOCK(stcb);
3063 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3064 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3065 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3066 SCTP_INP_RLOCK(inp);
3067 event->se_on = sctp_is_feature_on(inp, event_type);
3068 SCTP_INP_RUNLOCK(inp);
3070 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3076 *optsize = sizeof(struct sctp_event);
3080 case SCTP_RECVRCVINFO:
3084 if (*optsize < sizeof(int)) {
3085 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3088 SCTP_INP_RLOCK(inp);
3089 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3090 SCTP_INP_RUNLOCK(inp);
3093 /* return the option value */
3094 *(int *)optval = onoff;
3095 *optsize = sizeof(int);
3099 case SCTP_RECVNXTINFO:
3103 if (*optsize < sizeof(int)) {
3104 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3107 SCTP_INP_RLOCK(inp);
3108 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3109 SCTP_INP_RUNLOCK(inp);
3112 /* return the option value */
3113 *(int *)optval = onoff;
3114 *optsize = sizeof(int);
3118 case SCTP_DEFAULT_SNDINFO:
3120 struct sctp_sndinfo *info;
3122 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3123 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3126 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3127 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3128 info->snd_flags &= 0xfff0;
3129 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3130 info->snd_context = stcb->asoc.def_send.sinfo_context;
3131 SCTP_TCB_UNLOCK(stcb);
3133 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3134 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3135 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3136 SCTP_INP_RLOCK(inp);
3137 info->snd_sid = inp->def_send.sinfo_stream;
3138 info->snd_flags = inp->def_send.sinfo_flags;
3139 info->snd_flags &= 0xfff0;
3140 info->snd_ppid = inp->def_send.sinfo_ppid;
3141 info->snd_context = inp->def_send.sinfo_context;
3142 SCTP_INP_RUNLOCK(inp);
3144 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3149 *optsize = sizeof(struct sctp_sndinfo);
3153 case SCTP_DEFAULT_PRINFO:
3155 struct sctp_default_prinfo *info;
3157 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3158 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3161 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3162 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3163 SCTP_TCB_UNLOCK(stcb);
3165 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3166 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3167 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3168 SCTP_INP_RLOCK(inp);
3169 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3170 info->pr_value = inp->def_send.sinfo_timetolive;
3171 SCTP_INP_RUNLOCK(inp);
3173 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3178 *optsize = sizeof(struct sctp_default_prinfo);
3182 case SCTP_PEER_ADDR_THLDS:
3184 struct sctp_paddrthlds *thlds;
3185 struct sctp_nets *net;
3186 struct sockaddr *addr;
3187 #if defined(INET) && defined(INET6)
3188 struct sockaddr_in sin_store;
3191 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3192 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3194 #if defined(INET) && defined(INET6)
3195 if (thlds->spt_address.ss_family == AF_INET6) {
3196 struct sockaddr_in6 *sin6;
3198 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3199 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3200 in6_sin6_2_sin(&sin_store, sin6);
3201 addr = (struct sockaddr *)&sin_store;
3203 addr = (struct sockaddr *)&thlds->spt_address;
3206 addr = (struct sockaddr *)&thlds->spt_address;
3209 addr = (struct sockaddr *)&thlds->spt_address;
3212 net = sctp_findnet(stcb, addr);
3215 * We increment here since
3216 * sctp_findassociation_ep_addr() wil do a
3217 * decrement if it finds the stcb as long as
3218 * the locked tcb (last argument) is NOT a
3222 SCTP_INP_INCR_REF(inp);
3223 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3225 SCTP_INP_DECR_REF(inp);
3228 if ((stcb != NULL) && (net == NULL)) {
3230 if (addr->sa_family == AF_INET) {
3231 struct sockaddr_in *sin;
3233 sin = (struct sockaddr_in *)addr;
3234 if (sin->sin_addr.s_addr != INADDR_ANY) {
3236 SCTP_TCB_UNLOCK(stcb);
3237 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3243 if (addr->sa_family == AF_INET6) {
3244 struct sockaddr_in6 *sin6;
3246 sin6 = (struct sockaddr_in6 *)addr;
3247 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3249 SCTP_TCB_UNLOCK(stcb);
3250 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3256 error = EAFNOSUPPORT;
3257 SCTP_TCB_UNLOCK(stcb);
3258 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3264 thlds->spt_pathmaxrxt = net->failure_threshold;
3265 thlds->spt_pathpfthld = net->pf_threshold;
3266 thlds->spt_pathcpthld = 0xffff;
3268 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3269 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3270 thlds->spt_pathcpthld = 0xffff;
3272 thlds->spt_assoc_id = sctp_get_associd(stcb);
3273 SCTP_TCB_UNLOCK(stcb);
3275 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3276 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3277 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3278 /* Use endpoint defaults */
3279 SCTP_INP_RLOCK(inp);
3280 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3281 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3282 thlds->spt_pathcpthld = 0xffff;
3283 SCTP_INP_RUNLOCK(inp);
3285 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3290 *optsize = sizeof(struct sctp_paddrthlds);
3294 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3296 struct sctp_udpencaps *encaps;
3297 struct sctp_nets *net;
3298 struct sockaddr *addr;
3299 #if defined(INET) && defined(INET6)
3300 struct sockaddr_in sin_store;
3303 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3304 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3306 #if defined(INET) && defined(INET6)
3307 if (encaps->sue_address.ss_family == AF_INET6) {
3308 struct sockaddr_in6 *sin6;
3310 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3311 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3312 in6_sin6_2_sin(&sin_store, sin6);
3313 addr = (struct sockaddr *)&sin_store;
3315 addr = (struct sockaddr *)&encaps->sue_address;
3318 addr = (struct sockaddr *)&encaps->sue_address;
3321 addr = (struct sockaddr *)&encaps->sue_address;
3324 net = sctp_findnet(stcb, addr);
3327 * We increment here since
3328 * sctp_findassociation_ep_addr() wil do a
3329 * decrement if it finds the stcb as long as
3330 * the locked tcb (last argument) is NOT a
3334 SCTP_INP_INCR_REF(inp);
3335 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3337 SCTP_INP_DECR_REF(inp);
3340 if ((stcb != NULL) && (net == NULL)) {
3342 if (addr->sa_family == AF_INET) {
3343 struct sockaddr_in *sin;
3345 sin = (struct sockaddr_in *)addr;
3346 if (sin->sin_addr.s_addr != INADDR_ANY) {
3348 SCTP_TCB_UNLOCK(stcb);
3349 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3355 if (addr->sa_family == AF_INET6) {
3356 struct sockaddr_in6 *sin6;
3358 sin6 = (struct sockaddr_in6 *)addr;
3359 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3361 SCTP_TCB_UNLOCK(stcb);
3362 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3368 error = EAFNOSUPPORT;
3369 SCTP_TCB_UNLOCK(stcb);
3370 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3376 encaps->sue_port = net->port;
3378 encaps->sue_port = stcb->asoc.port;
3380 SCTP_TCB_UNLOCK(stcb);
3382 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3383 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3384 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3385 SCTP_INP_RLOCK(inp);
3386 encaps->sue_port = inp->sctp_ep.port;
3387 SCTP_INP_RUNLOCK(inp);
3389 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3394 *optsize = sizeof(struct sctp_udpencaps);
3398 case SCTP_ECN_SUPPORTED:
3400 struct sctp_assoc_value *av;
3402 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3403 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3406 av->assoc_value = stcb->asoc.ecn_supported;
3407 SCTP_TCB_UNLOCK(stcb);
3409 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3410 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3411 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3412 SCTP_INP_RLOCK(inp);
3413 av->assoc_value = inp->ecn_supported;
3414 SCTP_INP_RUNLOCK(inp);
3416 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3421 *optsize = sizeof(struct sctp_assoc_value);
3425 case SCTP_PR_SUPPORTED:
3427 struct sctp_assoc_value *av;
3429 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3430 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3433 av->assoc_value = stcb->asoc.prsctp_supported;
3434 SCTP_TCB_UNLOCK(stcb);
3436 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3437 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3438 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3439 SCTP_INP_RLOCK(inp);
3440 av->assoc_value = inp->prsctp_supported;
3441 SCTP_INP_RUNLOCK(inp);
3443 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3448 *optsize = sizeof(struct sctp_assoc_value);
3452 case SCTP_AUTH_SUPPORTED:
3454 struct sctp_assoc_value *av;
3456 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3457 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3460 av->assoc_value = stcb->asoc.auth_supported;
3461 SCTP_TCB_UNLOCK(stcb);
3463 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3464 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3465 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3466 SCTP_INP_RLOCK(inp);
3467 av->assoc_value = inp->auth_supported;
3468 SCTP_INP_RUNLOCK(inp);
3470 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3475 *optsize = sizeof(struct sctp_assoc_value);
3479 case SCTP_ASCONF_SUPPORTED:
3481 struct sctp_assoc_value *av;
3483 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3484 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3487 av->assoc_value = stcb->asoc.asconf_supported;
3488 SCTP_TCB_UNLOCK(stcb);
3490 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3491 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3492 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3493 SCTP_INP_RLOCK(inp);
3494 av->assoc_value = inp->asconf_supported;
3495 SCTP_INP_RUNLOCK(inp);
3497 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3502 *optsize = sizeof(struct sctp_assoc_value);
3506 case SCTP_RECONFIG_SUPPORTED:
3508 struct sctp_assoc_value *av;
3510 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3511 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3514 av->assoc_value = stcb->asoc.reconfig_supported;
3515 SCTP_TCB_UNLOCK(stcb);
3517 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3518 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3519 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3520 SCTP_INP_RLOCK(inp);
3521 av->assoc_value = inp->reconfig_supported;
3522 SCTP_INP_RUNLOCK(inp);
3524 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3529 *optsize = sizeof(struct sctp_assoc_value);
3533 case SCTP_NRSACK_SUPPORTED:
3535 struct sctp_assoc_value *av;
3537 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3538 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3541 av->assoc_value = stcb->asoc.nrsack_supported;
3542 SCTP_TCB_UNLOCK(stcb);
3544 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3545 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3546 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3547 SCTP_INP_RLOCK(inp);
3548 av->assoc_value = inp->nrsack_supported;
3549 SCTP_INP_RUNLOCK(inp);
3551 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3556 *optsize = sizeof(struct sctp_assoc_value);
3560 case SCTP_PKTDROP_SUPPORTED:
3562 struct sctp_assoc_value *av;
3564 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3565 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3568 av->assoc_value = stcb->asoc.pktdrop_supported;
3569 SCTP_TCB_UNLOCK(stcb);
3571 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3572 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3573 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3574 SCTP_INP_RLOCK(inp);
3575 av->assoc_value = inp->pktdrop_supported;
3576 SCTP_INP_RUNLOCK(inp);
3578 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3583 *optsize = sizeof(struct sctp_assoc_value);
3587 case SCTP_ENABLE_STREAM_RESET:
3589 struct sctp_assoc_value *av;
3591 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3592 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3595 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3596 SCTP_TCB_UNLOCK(stcb);
3598 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3599 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3600 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3601 SCTP_INP_RLOCK(inp);
3602 av->assoc_value = (uint32_t)inp->local_strreset_support;
3603 SCTP_INP_RUNLOCK(inp);
3605 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3610 *optsize = sizeof(struct sctp_assoc_value);
3614 case SCTP_PR_STREAM_STATUS:
3616 struct sctp_prstatus *sprstat;
3620 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3621 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3623 sid = sprstat->sprstat_sid;
3624 policy = sprstat->sprstat_policy;
3625 #if defined(SCTP_DETAILED_STR_STATS)
3626 if ((stcb != NULL) &&
3627 (sid < stcb->asoc.streamoutcnt) &&
3628 (policy != SCTP_PR_SCTP_NONE) &&
3629 ((policy <= SCTP_PR_SCTP_MAX) ||
3630 (policy == SCTP_PR_SCTP_ALL))) {
3631 if (policy == SCTP_PR_SCTP_ALL) {
3632 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3633 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3635 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3636 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3639 if ((stcb != NULL) &&
3640 (sid < stcb->asoc.streamoutcnt) &&
3641 (policy == SCTP_PR_SCTP_ALL)) {
3642 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3643 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3645 SCTP_TCB_UNLOCK(stcb);
3646 *optsize = sizeof(struct sctp_prstatus);
3648 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3653 case SCTP_PR_ASSOC_STATUS:
3655 struct sctp_prstatus *sprstat;
3658 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3659 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3661 policy = sprstat->sprstat_policy;
3662 if ((stcb != NULL) &&
3663 (policy != SCTP_PR_SCTP_NONE) &&
3664 ((policy <= SCTP_PR_SCTP_MAX) ||
3665 (policy == SCTP_PR_SCTP_ALL))) {
3666 if (policy == SCTP_PR_SCTP_ALL) {
3667 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3668 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3670 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3671 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3673 SCTP_TCB_UNLOCK(stcb);
3674 *optsize = sizeof(struct sctp_prstatus);
3676 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3683 struct sctp_assoc_value *av;
3685 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3686 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3689 av->assoc_value = stcb->asoc.max_cwnd;
3690 SCTP_TCB_UNLOCK(stcb);
3692 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3693 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3694 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3695 SCTP_INP_RLOCK(inp);
3696 av->assoc_value = inp->max_cwnd;
3697 SCTP_INP_RUNLOCK(inp);
3699 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3704 *optsize = sizeof(struct sctp_assoc_value);
3709 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3710 error = ENOPROTOOPT;
3712 } /* end switch (sopt->sopt_name) */
3720 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3725 struct sctp_tcb *stcb = NULL;
3726 struct sctp_inpcb *inp = NULL;
3729 if (optval == NULL) {
3730 SCTP_PRINTF("optval is NULL\n");
3731 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3734 inp = (struct sctp_inpcb *)so->so_pcb;
3736 SCTP_PRINTF("inp is NULL?\n");
3737 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3740 vrf_id = inp->def_vrf_id;
3745 case SCTP_AUTOCLOSE:
3746 case SCTP_AUTO_ASCONF:
3747 case SCTP_EXPLICIT_EOR:
3748 case SCTP_DISABLE_FRAGMENTS:
3749 case SCTP_USE_EXT_RCVINFO:
3750 case SCTP_I_WANT_MAPPED_V4_ADDR:
3751 /* copy in the option value */
3752 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3757 case SCTP_DISABLE_FRAGMENTS:
3758 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3760 case SCTP_AUTO_ASCONF:
3762 * NOTE: we don't really support this flag
3764 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3765 /* only valid for bound all sockets */
3766 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3768 /* forbidden by admin */
3769 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3772 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3774 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3778 case SCTP_EXPLICIT_EOR:
3779 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3781 case SCTP_USE_EXT_RCVINFO:
3782 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3784 case SCTP_I_WANT_MAPPED_V4_ADDR:
3785 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3786 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3788 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3793 set_opt = SCTP_PCB_FLAGS_NODELAY;
3795 case SCTP_AUTOCLOSE:
3796 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3797 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3798 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3801 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3803 * The value is in ticks. Note this does not effect
3804 * old associations, only new ones.
3806 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3809 SCTP_INP_WLOCK(inp);
3811 sctp_feature_on(inp, set_opt);
3813 sctp_feature_off(inp, set_opt);
3815 SCTP_INP_WUNLOCK(inp);
3817 case SCTP_REUSE_PORT:
3819 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3820 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3821 /* Can't set it after we are bound */
3825 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3826 /* Can't do this for a 1-m socket */
3831 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3833 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3836 case SCTP_PARTIAL_DELIVERY_POINT:
3840 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3841 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3842 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3846 inp->partial_delivery_point = *value;
3849 case SCTP_FRAGMENT_INTERLEAVE:
3850 /* not yet until we re-write sctp_recvmsg() */
3854 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3855 if (*level == SCTP_FRAG_LEVEL_2) {
3856 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3857 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3858 } else if (*level == SCTP_FRAG_LEVEL_1) {
3859 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3860 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3861 } else if (*level == SCTP_FRAG_LEVEL_0) {
3862 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3863 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3866 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3871 case SCTP_INTERLEAVING_SUPPORTED:
3873 struct sctp_assoc_value *av;
3875 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3876 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3879 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3881 SCTP_TCB_UNLOCK(stcb);
3883 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3884 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3885 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3886 SCTP_INP_WLOCK(inp);
3887 if (av->assoc_value == 0) {
3888 inp->idata_supported = 0;
3890 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3891 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3892 inp->idata_supported = 1;
3900 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3904 SCTP_INP_WUNLOCK(inp);
3906 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3912 case SCTP_CMT_ON_OFF:
3913 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3914 struct sctp_assoc_value *av;
3916 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3917 if (av->assoc_value > SCTP_CMT_MAX) {
3918 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3922 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3924 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3925 SCTP_TCB_UNLOCK(stcb);
3927 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3928 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3929 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3930 (av->assoc_id == SCTP_ALL_ASSOC)) {
3931 SCTP_INP_WLOCK(inp);
3932 inp->sctp_cmt_on_off = av->assoc_value;
3933 SCTP_INP_WUNLOCK(inp);
3935 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3936 (av->assoc_id == SCTP_ALL_ASSOC)) {
3937 SCTP_INP_RLOCK(inp);
3938 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3939 SCTP_TCB_LOCK(stcb);
3940 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3941 SCTP_TCB_UNLOCK(stcb);
3943 SCTP_INP_RUNLOCK(inp);
3947 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3948 error = ENOPROTOOPT;
3951 case SCTP_PLUGGABLE_CC:
3953 struct sctp_assoc_value *av;
3954 struct sctp_nets *net;
3956 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3957 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3958 (av->assoc_value != SCTP_CC_HSTCP) &&
3959 (av->assoc_value != SCTP_CC_HTCP) &&
3960 (av->assoc_value != SCTP_CC_RTCC)) {
3961 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3965 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3967 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3968 stcb->asoc.congestion_control_module = av->assoc_value;
3969 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3970 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3971 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3974 SCTP_TCB_UNLOCK(stcb);
3976 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3977 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3978 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3979 (av->assoc_id == SCTP_ALL_ASSOC)) {
3980 SCTP_INP_WLOCK(inp);
3981 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3982 SCTP_INP_WUNLOCK(inp);
3984 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3985 (av->assoc_id == SCTP_ALL_ASSOC)) {
3986 SCTP_INP_RLOCK(inp);
3987 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3988 SCTP_TCB_LOCK(stcb);
3989 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3990 stcb->asoc.congestion_control_module = av->assoc_value;
3991 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3992 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3993 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3996 SCTP_TCB_UNLOCK(stcb);
3998 SCTP_INP_RUNLOCK(inp);
4003 case SCTP_CC_OPTION:
4005 struct sctp_cc_option *cc_opt;
4007 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4008 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4010 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
4011 SCTP_INP_RLOCK(inp);
4012 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4013 SCTP_TCB_LOCK(stcb);
4014 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4015 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4017 SCTP_TCB_UNLOCK(stcb);
4019 SCTP_INP_RUNLOCK(inp);
4024 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4027 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4030 SCTP_TCB_UNLOCK(stcb);
4034 case SCTP_PLUGGABLE_SS:
4036 struct sctp_assoc_value *av;
4038 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4039 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4040 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4041 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4042 (av->assoc_value != SCTP_SS_PRIORITY) &&
4043 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4044 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4045 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4049 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4051 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4052 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4053 stcb->asoc.stream_scheduling_module = av->assoc_value;
4054 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4055 SCTP_TCB_UNLOCK(stcb);
4057 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4058 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4059 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4060 (av->assoc_id == SCTP_ALL_ASSOC)) {
4061 SCTP_INP_WLOCK(inp);
4062 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4063 SCTP_INP_WUNLOCK(inp);
4065 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4066 (av->assoc_id == SCTP_ALL_ASSOC)) {
4067 SCTP_INP_RLOCK(inp);
4068 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4069 SCTP_TCB_LOCK(stcb);
4070 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4071 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4072 stcb->asoc.stream_scheduling_module = av->assoc_value;
4073 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4074 SCTP_TCB_UNLOCK(stcb);
4076 SCTP_INP_RUNLOCK(inp);
4083 struct sctp_stream_value *av;
4085 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4086 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4088 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4089 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4090 av->stream_value) < 0)) {
4091 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4094 SCTP_TCB_UNLOCK(stcb);
4096 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4097 SCTP_INP_RLOCK(inp);
4098 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4099 SCTP_TCB_LOCK(stcb);
4100 if (av->stream_id < stcb->asoc.streamoutcnt) {
4101 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4103 &stcb->asoc.strmout[av->stream_id],
4106 SCTP_TCB_UNLOCK(stcb);
4108 SCTP_INP_RUNLOCK(inp);
4111 * Can't set stream value without
4114 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4120 case SCTP_CLR_STAT_LOG:
4121 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4126 struct sctp_assoc_value *av;
4128 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4129 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4132 stcb->asoc.context = av->assoc_value;
4133 SCTP_TCB_UNLOCK(stcb);
4135 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4136 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4137 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4138 (av->assoc_id == SCTP_ALL_ASSOC)) {
4139 SCTP_INP_WLOCK(inp);
4140 inp->sctp_context = av->assoc_value;
4141 SCTP_INP_WUNLOCK(inp);
4143 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4144 (av->assoc_id == SCTP_ALL_ASSOC)) {
4145 SCTP_INP_RLOCK(inp);
4146 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4147 SCTP_TCB_LOCK(stcb);
4148 stcb->asoc.context = av->assoc_value;
4149 SCTP_TCB_UNLOCK(stcb);
4151 SCTP_INP_RUNLOCK(inp);
4158 uint32_t *default_vrfid;
4160 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4161 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4162 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4166 inp->def_vrf_id = *default_vrfid;
4169 case SCTP_DEL_VRF_ID:
4171 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4175 case SCTP_ADD_VRF_ID:
4177 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4181 case SCTP_DELAYED_SACK:
4183 struct sctp_sack_info *sack;
4185 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4186 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4187 if (sack->sack_delay) {
4188 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4189 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4190 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4191 sack->sack_delay = TICKS_TO_MSEC(1);
4195 if (sack->sack_delay) {
4196 stcb->asoc.delayed_ack = sack->sack_delay;
4198 if (sack->sack_freq) {
4199 stcb->asoc.sack_freq = sack->sack_freq;
4201 SCTP_TCB_UNLOCK(stcb);
4203 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4204 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4205 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4206 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4207 SCTP_INP_WLOCK(inp);
4208 if (sack->sack_delay) {
4209 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4211 if (sack->sack_freq) {
4212 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4214 SCTP_INP_WUNLOCK(inp);
4216 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4217 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4218 SCTP_INP_RLOCK(inp);
4219 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4220 SCTP_TCB_LOCK(stcb);
4221 if (sack->sack_delay) {
4222 stcb->asoc.delayed_ack = sack->sack_delay;
4224 if (sack->sack_freq) {
4225 stcb->asoc.sack_freq = sack->sack_freq;
4227 SCTP_TCB_UNLOCK(stcb);
4229 SCTP_INP_RUNLOCK(inp);
4234 case SCTP_AUTH_CHUNK:
4236 struct sctp_authchunk *sauth;
4238 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4240 SCTP_INP_WLOCK(inp);
4241 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4242 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4245 SCTP_INP_WUNLOCK(inp);
4250 struct sctp_authkey *sca;
4251 struct sctp_keyhead *shared_keys;
4252 sctp_sharedkey_t *shared_key;
4253 sctp_key_t *key = NULL;
4256 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4257 if (sca->sca_keylength == 0) {
4258 size = optsize - sizeof(struct sctp_authkey);
4260 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4261 size = sca->sca_keylength;
4263 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4268 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4271 shared_keys = &stcb->asoc.shared_keys;
4272 /* clear the cached keys for this key id */
4273 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4275 * create the new shared key and
4279 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4281 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4283 SCTP_TCB_UNLOCK(stcb);
4287 shared_key = sctp_alloc_sharedkey();
4288 if (shared_key == NULL) {
4290 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4292 SCTP_TCB_UNLOCK(stcb);
4295 shared_key->key = key;
4296 shared_key->keyid = sca->sca_keynumber;
4297 error = sctp_insert_sharedkey(shared_keys, shared_key);
4298 SCTP_TCB_UNLOCK(stcb);
4300 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4301 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4302 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4303 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4304 SCTP_INP_WLOCK(inp);
4305 shared_keys = &inp->sctp_ep.shared_keys;
4307 * clear the cached keys on all
4308 * assocs for this key id
4310 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4312 * create the new shared key and
4316 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4318 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4320 SCTP_INP_WUNLOCK(inp);
4324 shared_key = sctp_alloc_sharedkey();
4325 if (shared_key == NULL) {
4327 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4329 SCTP_INP_WUNLOCK(inp);
4332 shared_key->key = key;
4333 shared_key->keyid = sca->sca_keynumber;
4334 error = sctp_insert_sharedkey(shared_keys, shared_key);
4335 SCTP_INP_WUNLOCK(inp);
4337 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4338 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4339 SCTP_INP_RLOCK(inp);
4340 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4341 SCTP_TCB_LOCK(stcb);
4342 shared_keys = &stcb->asoc.shared_keys;
4344 * clear the cached keys for
4347 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4349 * create the new shared key
4350 * and insert/replace it
4353 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4355 SCTP_TCB_UNLOCK(stcb);
4359 shared_key = sctp_alloc_sharedkey();
4360 if (shared_key == NULL) {
4362 SCTP_TCB_UNLOCK(stcb);
4365 shared_key->key = key;
4366 shared_key->keyid = sca->sca_keynumber;
4367 error = sctp_insert_sharedkey(shared_keys, shared_key);
4368 SCTP_TCB_UNLOCK(stcb);
4370 SCTP_INP_RUNLOCK(inp);
4375 case SCTP_HMAC_IDENT:
4377 struct sctp_hmacalgo *shmac;
4378 sctp_hmaclist_t *hmaclist;
4382 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4383 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4384 (shmac->shmac_number_of_idents > 0xffff)) {
4385 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4389 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4390 if (hmaclist == NULL) {
4391 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4395 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4396 hmacid = shmac->shmac_idents[i];
4397 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4398 /* invalid HMACs were found */ ;
4399 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4401 sctp_free_hmaclist(hmaclist);
4402 goto sctp_set_hmac_done;
4405 for (i = 0; i < hmaclist->num_algo; i++) {
4406 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4407 /* already in list */
4411 if (i == hmaclist->num_algo) {
4412 /* not found in list */
4413 sctp_free_hmaclist(hmaclist);
4414 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4418 /* set it on the endpoint */
4419 SCTP_INP_WLOCK(inp);
4420 if (inp->sctp_ep.local_hmacs)
4421 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4422 inp->sctp_ep.local_hmacs = hmaclist;
4423 SCTP_INP_WUNLOCK(inp);
4427 case SCTP_AUTH_ACTIVE_KEY:
4429 struct sctp_authkeyid *scact;
4431 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4432 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4434 /* set the active key on the right place */
4436 /* set the active key on the assoc */
4437 if (sctp_auth_setactivekey(stcb,
4438 scact->scact_keynumber)) {
4439 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4440 SCTP_FROM_SCTP_USRREQ,
4444 SCTP_TCB_UNLOCK(stcb);
4446 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4447 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4448 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4449 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4450 SCTP_INP_WLOCK(inp);
4451 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4452 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4455 SCTP_INP_WUNLOCK(inp);
4457 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4458 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4459 SCTP_INP_RLOCK(inp);
4460 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4461 SCTP_TCB_LOCK(stcb);
4462 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4463 SCTP_TCB_UNLOCK(stcb);
4465 SCTP_INP_RUNLOCK(inp);
4470 case SCTP_AUTH_DELETE_KEY:
4472 struct sctp_authkeyid *scdel;
4474 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4475 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4477 /* delete the key from the right place */
4479 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4480 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4483 SCTP_TCB_UNLOCK(stcb);
4485 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4486 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4487 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4488 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4489 SCTP_INP_WLOCK(inp);
4490 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4491 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4494 SCTP_INP_WUNLOCK(inp);
4496 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4497 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4498 SCTP_INP_RLOCK(inp);
4499 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4500 SCTP_TCB_LOCK(stcb);
4501 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4502 SCTP_TCB_UNLOCK(stcb);
4504 SCTP_INP_RUNLOCK(inp);
4509 case SCTP_AUTH_DEACTIVATE_KEY:
4511 struct sctp_authkeyid *keyid;
4513 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4514 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4516 /* deactivate the key from the right place */
4518 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4519 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4522 SCTP_TCB_UNLOCK(stcb);
4524 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4525 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4526 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4527 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4528 SCTP_INP_WLOCK(inp);
4529 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4530 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4533 SCTP_INP_WUNLOCK(inp);
4535 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4536 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4537 SCTP_INP_RLOCK(inp);
4538 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4539 SCTP_TCB_LOCK(stcb);
4540 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4541 SCTP_TCB_UNLOCK(stcb);
4543 SCTP_INP_RUNLOCK(inp);
4548 case SCTP_ENABLE_STREAM_RESET:
4550 struct sctp_assoc_value *av;
4552 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4553 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4554 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4558 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4560 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4561 SCTP_TCB_UNLOCK(stcb);
4563 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4564 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4565 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4566 (av->assoc_id == SCTP_ALL_ASSOC)) {
4567 SCTP_INP_WLOCK(inp);
4568 inp->local_strreset_support = (uint8_t)av->assoc_value;
4569 SCTP_INP_WUNLOCK(inp);
4571 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4572 (av->assoc_id == SCTP_ALL_ASSOC)) {
4573 SCTP_INP_RLOCK(inp);
4574 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4575 SCTP_TCB_LOCK(stcb);
4576 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4577 SCTP_TCB_UNLOCK(stcb);
4579 SCTP_INP_RUNLOCK(inp);
4584 case SCTP_RESET_STREAMS:
4586 struct sctp_reset_streams *strrst;
4587 int i, send_out = 0;
4590 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4591 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4593 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4597 if (stcb->asoc.reconfig_supported == 0) {
4599 * Peer does not support the chunk type.
4601 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4603 SCTP_TCB_UNLOCK(stcb);
4606 if (sizeof(struct sctp_reset_streams) +
4607 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4609 SCTP_TCB_UNLOCK(stcb);
4612 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4614 if (stcb->asoc.stream_reset_outstanding) {
4615 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4617 SCTP_TCB_UNLOCK(stcb);
4621 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4624 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4625 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4627 SCTP_TCB_UNLOCK(stcb);
4630 if ((send_in == 0) && (send_out == 0)) {
4631 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4633 SCTP_TCB_UNLOCK(stcb);
4636 for (i = 0; i < strrst->srs_number_streams; i++) {
4638 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4639 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4644 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4645 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4651 SCTP_TCB_UNLOCK(stcb);
4658 if (strrst->srs_number_streams) {
4659 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4660 strm = strrst->srs_stream_list[i];
4661 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4662 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4668 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4669 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4670 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4677 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4678 strrst->srs_stream_list,
4679 send_in, 0, 0, 0, 0, 0);
4681 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4684 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4687 * For outgoing streams don't report any
4688 * problems in sending the request to the
4689 * application. XXX: Double check resetting
4694 SCTP_TCB_UNLOCK(stcb);
4697 case SCTP_ADD_STREAMS:
4699 struct sctp_add_streams *stradd;
4700 uint8_t addstream = 0;
4701 uint16_t add_o_strmcnt = 0;
4702 uint16_t add_i_strmcnt = 0;
4704 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4705 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4707 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4711 if (stcb->asoc.reconfig_supported == 0) {
4713 * Peer does not support the chunk type.
4715 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4717 SCTP_TCB_UNLOCK(stcb);
4720 if (stcb->asoc.stream_reset_outstanding) {
4721 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4723 SCTP_TCB_UNLOCK(stcb);
4726 if ((stradd->sas_outstrms == 0) &&
4727 (stradd->sas_instrms == 0)) {
4731 if (stradd->sas_outstrms) {
4733 /* We allocate here */
4734 add_o_strmcnt = stradd->sas_outstrms;
4735 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4736 /* You can't have more than 64k */
4741 if (stradd->sas_instrms) {
4746 * We allocate inside
4747 * sctp_send_str_reset_req()
4749 add_i_strmcnt = stradd->sas_instrms;
4750 cnt = add_i_strmcnt;
4751 cnt += stcb->asoc.streamincnt;
4752 if (cnt > 0x0000ffff) {
4753 /* You can't have more than 64k */
4757 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4758 /* More than you are allowed */
4763 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4764 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4766 SCTP_TCB_UNLOCK(stcb);
4769 case SCTP_RESET_ASSOC:
4774 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4775 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4777 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4781 if (stcb->asoc.reconfig_supported == 0) {
4783 * Peer does not support the chunk type.
4785 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4787 SCTP_TCB_UNLOCK(stcb);
4790 if (stcb->asoc.stream_reset_outstanding) {
4791 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4793 SCTP_TCB_UNLOCK(stcb);
4797 * Is there any data pending in the send or sent
4800 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4801 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4804 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4805 SCTP_TCB_UNLOCK(stcb);
4808 /* Do any streams have data queued? */
4809 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4810 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4814 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4815 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4816 SCTP_TCB_UNLOCK(stcb);
4819 case SCTP_CONNECT_X:
4820 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4821 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4825 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4827 case SCTP_CONNECT_X_DELAYED:
4828 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4829 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4833 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4835 case SCTP_CONNECT_X_COMPLETE:
4837 struct sockaddr *sa;
4839 /* FIXME MT: check correct? */
4840 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4843 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4844 SCTP_INP_RLOCK(inp);
4845 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4847 SCTP_TCB_LOCK(stcb);
4849 SCTP_INP_RUNLOCK(inp);
4852 * We increment here since
4853 * sctp_findassociation_ep_addr() wil do a
4854 * decrement if it finds the stcb as long as
4855 * the locked tcb (last argument) is NOT a
4858 SCTP_INP_INCR_REF(inp);
4859 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4861 SCTP_INP_DECR_REF(inp);
4866 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4870 if (stcb->asoc.delayed_connection == 1) {
4871 stcb->asoc.delayed_connection = 0;
4872 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4873 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4874 stcb->asoc.primary_destination,
4875 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4876 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4879 * already expired or did not use delayed
4882 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4885 SCTP_TCB_UNLOCK(stcb);
4888 case SCTP_MAX_BURST:
4890 struct sctp_assoc_value *av;
4892 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4893 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4896 stcb->asoc.max_burst = av->assoc_value;
4897 SCTP_TCB_UNLOCK(stcb);
4899 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4900 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4901 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4902 (av->assoc_id == SCTP_ALL_ASSOC)) {
4903 SCTP_INP_WLOCK(inp);
4904 inp->sctp_ep.max_burst = av->assoc_value;
4905 SCTP_INP_WUNLOCK(inp);
4907 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4908 (av->assoc_id == SCTP_ALL_ASSOC)) {
4909 SCTP_INP_RLOCK(inp);
4910 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4911 SCTP_TCB_LOCK(stcb);
4912 stcb->asoc.max_burst = av->assoc_value;
4913 SCTP_TCB_UNLOCK(stcb);
4915 SCTP_INP_RUNLOCK(inp);
4922 struct sctp_assoc_value *av;
4925 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4926 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4928 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4929 ovh = SCTP_MED_OVERHEAD;
4931 ovh = SCTP_MED_V4_OVERHEAD;
4934 if (av->assoc_value) {
4935 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4937 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4939 SCTP_TCB_UNLOCK(stcb);
4941 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4942 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4943 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4944 SCTP_INP_WLOCK(inp);
4946 * FIXME MT: I think this is not in
4947 * tune with the API ID
4949 if (av->assoc_value) {
4950 inp->sctp_frag_point = (av->assoc_value + ovh);
4952 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4954 SCTP_INP_WUNLOCK(inp);
4956 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4964 struct sctp_event_subscribe *events;
4966 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4968 SCTP_INP_WLOCK(inp);
4969 if (events->sctp_data_io_event) {
4970 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4972 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4975 if (events->sctp_association_event) {
4976 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4978 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4981 if (events->sctp_address_event) {
4982 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4984 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4987 if (events->sctp_send_failure_event) {
4988 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4990 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4993 if (events->sctp_peer_error_event) {
4994 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4996 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4999 if (events->sctp_shutdown_event) {
5000 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5002 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5005 if (events->sctp_partial_delivery_event) {
5006 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5008 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5011 if (events->sctp_adaptation_layer_event) {
5012 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5014 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5017 if (events->sctp_authentication_event) {
5018 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5020 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5023 if (events->sctp_sender_dry_event) {
5024 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5026 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5029 if (events->sctp_stream_reset_event) {
5030 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5032 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5034 SCTP_INP_WUNLOCK(inp);
5036 SCTP_INP_RLOCK(inp);
5037 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5038 SCTP_TCB_LOCK(stcb);
5039 if (events->sctp_association_event) {
5040 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5042 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5044 if (events->sctp_address_event) {
5045 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5047 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5049 if (events->sctp_send_failure_event) {
5050 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5052 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5054 if (events->sctp_peer_error_event) {
5055 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5057 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5059 if (events->sctp_shutdown_event) {
5060 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5062 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5064 if (events->sctp_partial_delivery_event) {
5065 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5067 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5069 if (events->sctp_adaptation_layer_event) {
5070 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5072 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5074 if (events->sctp_authentication_event) {
5075 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5077 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5079 if (events->sctp_sender_dry_event) {
5080 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5082 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5084 if (events->sctp_stream_reset_event) {
5085 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5087 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5089 SCTP_TCB_UNLOCK(stcb);
5092 * Send up the sender dry event only for 1-to-1
5095 if (events->sctp_sender_dry_event) {
5096 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5097 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5098 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5100 SCTP_TCB_LOCK(stcb);
5101 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5102 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5103 (stcb->asoc.stream_queue_cnt == 0)) {
5104 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5106 SCTP_TCB_UNLOCK(stcb);
5110 SCTP_INP_RUNLOCK(inp);
5113 case SCTP_ADAPTATION_LAYER:
5115 struct sctp_setadaptation *adap_bits;
5117 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5118 SCTP_INP_WLOCK(inp);
5119 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5120 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5121 SCTP_INP_WUNLOCK(inp);
5125 case SCTP_SET_INITIAL_DBG_SEQ:
5129 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5130 SCTP_INP_WLOCK(inp);
5131 inp->sctp_ep.initial_sequence_debug = *vvv;
5132 SCTP_INP_WUNLOCK(inp);
5136 case SCTP_DEFAULT_SEND_PARAM:
5138 struct sctp_sndrcvinfo *s_info;
5140 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5141 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5144 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5145 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5147 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5150 SCTP_TCB_UNLOCK(stcb);
5152 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5153 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5154 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5155 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5156 SCTP_INP_WLOCK(inp);
5157 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5158 SCTP_INP_WUNLOCK(inp);
5160 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5161 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5162 SCTP_INP_RLOCK(inp);
5163 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5164 SCTP_TCB_LOCK(stcb);
5165 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5166 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5168 SCTP_TCB_UNLOCK(stcb);
5170 SCTP_INP_RUNLOCK(inp);
5175 case SCTP_PEER_ADDR_PARAMS:
5177 struct sctp_paddrparams *paddrp;
5178 struct sctp_nets *net;
5179 struct sockaddr *addr;
5180 #if defined(INET) && defined(INET6)
5181 struct sockaddr_in sin_store;
5184 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5185 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5187 #if defined(INET) && defined(INET6)
5188 if (paddrp->spp_address.ss_family == AF_INET6) {
5189 struct sockaddr_in6 *sin6;
5191 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5192 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5193 in6_sin6_2_sin(&sin_store, sin6);
5194 addr = (struct sockaddr *)&sin_store;
5196 addr = (struct sockaddr *)&paddrp->spp_address;
5199 addr = (struct sockaddr *)&paddrp->spp_address;
5202 addr = (struct sockaddr *)&paddrp->spp_address;
5205 net = sctp_findnet(stcb, addr);
5208 * We increment here since
5209 * sctp_findassociation_ep_addr() wil do a
5210 * decrement if it finds the stcb as long as
5211 * the locked tcb (last argument) is NOT a
5215 SCTP_INP_INCR_REF(inp);
5216 stcb = sctp_findassociation_ep_addr(&inp, addr,
5219 SCTP_INP_DECR_REF(inp);
5222 if ((stcb != NULL) && (net == NULL)) {
5224 if (addr->sa_family == AF_INET) {
5226 struct sockaddr_in *sin;
5228 sin = (struct sockaddr_in *)addr;
5229 if (sin->sin_addr.s_addr != INADDR_ANY) {
5230 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5231 SCTP_TCB_UNLOCK(stcb);
5238 if (addr->sa_family == AF_INET6) {
5239 struct sockaddr_in6 *sin6;
5241 sin6 = (struct sockaddr_in6 *)addr;
5242 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5243 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5244 SCTP_TCB_UNLOCK(stcb);
5251 error = EAFNOSUPPORT;
5252 SCTP_TCB_UNLOCK(stcb);
5253 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5258 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5260 SCTP_TCB_UNLOCK(stcb);
5261 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5264 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5266 SCTP_TCB_UNLOCK(stcb);
5267 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5271 /************************TCB SPECIFIC SET ******************/
5273 /************************NET SPECIFIC SET ******************/
5274 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5275 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5276 !(net->dest_state & SCTP_ADDR_NOHB)) {
5277 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5278 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5280 net->dest_state |= SCTP_ADDR_NOHB;
5282 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5283 if (paddrp->spp_hbinterval) {
5284 net->heart_beat_delay = paddrp->spp_hbinterval;
5285 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5286 net->heart_beat_delay = 0;
5288 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5289 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5290 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5291 net->dest_state &= ~SCTP_ADDR_NOHB;
5293 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5295 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5296 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5297 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5299 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5300 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5301 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5302 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5304 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5305 net->mtu = paddrp->spp_pathmtu;
5306 switch (net->ro._l_addr.sa.sa_family) {
5309 net->mtu += SCTP_MIN_V4_OVERHEAD;
5314 net->mtu += SCTP_MIN_OVERHEAD;
5320 if (net->mtu < stcb->asoc.smallest_mtu) {
5321 sctp_pathmtu_adjustment(stcb, net->mtu);
5324 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5325 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5326 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5328 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5330 if (paddrp->spp_pathmaxrxt) {
5331 if (net->dest_state & SCTP_ADDR_PF) {
5332 if (net->error_count > paddrp->spp_pathmaxrxt) {
5333 net->dest_state &= ~SCTP_ADDR_PF;
5336 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5337 (net->error_count > net->pf_threshold)) {
5338 net->dest_state |= SCTP_ADDR_PF;
5339 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5340 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5341 stcb->sctp_ep, stcb, net,
5342 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5343 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5346 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5347 if (net->error_count > paddrp->spp_pathmaxrxt) {
5348 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5349 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5352 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5353 net->dest_state |= SCTP_ADDR_REACHABLE;
5354 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5357 net->failure_threshold = paddrp->spp_pathmaxrxt;
5359 if (paddrp->spp_flags & SPP_DSCP) {
5360 net->dscp = paddrp->spp_dscp & 0xfc;
5364 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5365 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5366 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5367 net->flowlabel |= 0x80000000;
5372 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5373 if (paddrp->spp_pathmaxrxt != 0) {
5374 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5375 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5376 if (net->dest_state & SCTP_ADDR_PF) {
5377 if (net->error_count > paddrp->spp_pathmaxrxt) {
5378 net->dest_state &= ~SCTP_ADDR_PF;
5381 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5382 (net->error_count > net->pf_threshold)) {
5383 net->dest_state |= SCTP_ADDR_PF;
5384 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5385 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5386 stcb->sctp_ep, stcb, net,
5387 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5388 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5391 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5392 if (net->error_count > paddrp->spp_pathmaxrxt) {
5393 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5394 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5397 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5398 net->dest_state |= SCTP_ADDR_REACHABLE;
5399 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5402 net->failure_threshold = paddrp->spp_pathmaxrxt;
5405 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5406 if (paddrp->spp_hbinterval != 0) {
5407 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5408 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5409 stcb->asoc.heart_beat_delay = 0;
5411 /* Turn back on the timer */
5412 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5413 if (paddrp->spp_hbinterval != 0) {
5414 net->heart_beat_delay = paddrp->spp_hbinterval;
5415 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5416 net->heart_beat_delay = 0;
5418 if (net->dest_state & SCTP_ADDR_NOHB) {
5419 net->dest_state &= ~SCTP_ADDR_NOHB;
5421 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5422 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5423 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5425 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5427 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5428 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5429 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5430 net->dest_state |= SCTP_ADDR_NOHB;
5431 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5432 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5434 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5438 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5440 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5441 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5442 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5443 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5444 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5446 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5447 net->mtu = paddrp->spp_pathmtu;
5448 switch (net->ro._l_addr.sa.sa_family) {
5451 net->mtu += SCTP_MIN_V4_OVERHEAD;
5456 net->mtu += SCTP_MIN_OVERHEAD;
5462 if (net->mtu < stcb->asoc.smallest_mtu) {
5463 sctp_pathmtu_adjustment(stcb, net->mtu);
5466 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5468 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5469 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5470 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5471 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5473 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5475 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5477 if (paddrp->spp_flags & SPP_DSCP) {
5478 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5479 net->dscp = paddrp->spp_dscp & 0xfc;
5482 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5483 stcb->asoc.default_dscp |= 0x01;
5486 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5487 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5488 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5489 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5490 net->flowlabel |= 0x80000000;
5493 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5494 stcb->asoc.default_flowlabel |= 0x80000000;
5498 SCTP_TCB_UNLOCK(stcb);
5500 /************************NO TCB, SET TO default stuff ******************/
5501 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5502 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5503 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5504 SCTP_INP_WLOCK(inp);
5506 * For the TOS/FLOWLABEL stuff you
5507 * set it with the options on the
5510 if (paddrp->spp_pathmaxrxt != 0) {
5511 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5513 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5514 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5515 else if (paddrp->spp_hbinterval != 0) {
5516 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5517 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5518 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5520 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5521 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5522 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5523 } else if (paddrp->spp_hbinterval) {
5524 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5526 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5527 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5528 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5530 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5531 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5532 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5533 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5535 if (paddrp->spp_flags & SPP_DSCP) {
5536 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5537 inp->sctp_ep.default_dscp |= 0x01;
5540 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5541 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5542 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5543 inp->sctp_ep.default_flowlabel |= 0x80000000;
5547 SCTP_INP_WUNLOCK(inp);
5549 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5557 struct sctp_rtoinfo *srto;
5558 uint32_t new_init, new_min, new_max;
5560 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5561 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5564 if (srto->srto_initial)
5565 new_init = srto->srto_initial;
5567 new_init = stcb->asoc.initial_rto;
5569 new_max = srto->srto_max;
5571 new_max = stcb->asoc.maxrto;
5573 new_min = srto->srto_min;
5575 new_min = stcb->asoc.minrto;
5576 if ((new_min <= new_init) && (new_init <= new_max)) {
5577 stcb->asoc.initial_rto = new_init;
5578 stcb->asoc.maxrto = new_max;
5579 stcb->asoc.minrto = new_min;
5581 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5584 SCTP_TCB_UNLOCK(stcb);
5586 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5587 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5588 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5589 SCTP_INP_WLOCK(inp);
5590 if (srto->srto_initial)
5591 new_init = srto->srto_initial;
5593 new_init = inp->sctp_ep.initial_rto;
5595 new_max = srto->srto_max;
5597 new_max = inp->sctp_ep.sctp_maxrto;
5599 new_min = srto->srto_min;
5601 new_min = inp->sctp_ep.sctp_minrto;
5602 if ((new_min <= new_init) && (new_init <= new_max)) {
5603 inp->sctp_ep.initial_rto = new_init;
5604 inp->sctp_ep.sctp_maxrto = new_max;
5605 inp->sctp_ep.sctp_minrto = new_min;
5607 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5610 SCTP_INP_WUNLOCK(inp);
5612 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5618 case SCTP_ASSOCINFO:
5620 struct sctp_assocparams *sasoc;
5622 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5623 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5624 if (sasoc->sasoc_cookie_life) {
5625 /* boundary check the cookie life */
5626 if (sasoc->sasoc_cookie_life < 1000)
5627 sasoc->sasoc_cookie_life = 1000;
5628 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5629 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5633 if (sasoc->sasoc_asocmaxrxt)
5634 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5635 if (sasoc->sasoc_cookie_life) {
5636 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5638 SCTP_TCB_UNLOCK(stcb);
5640 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5641 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5642 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5643 SCTP_INP_WLOCK(inp);
5644 if (sasoc->sasoc_asocmaxrxt)
5645 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5646 if (sasoc->sasoc_cookie_life) {
5647 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5649 SCTP_INP_WUNLOCK(inp);
5651 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5659 struct sctp_initmsg *sinit;
5661 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5662 SCTP_INP_WLOCK(inp);
5663 if (sinit->sinit_num_ostreams)
5664 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5666 if (sinit->sinit_max_instreams)
5667 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5669 if (sinit->sinit_max_attempts)
5670 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5672 if (sinit->sinit_max_init_timeo)
5673 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5674 SCTP_INP_WUNLOCK(inp);
5677 case SCTP_PRIMARY_ADDR:
5679 struct sctp_setprim *spa;
5680 struct sctp_nets *net;
5681 struct sockaddr *addr;
5682 #if defined(INET) && defined(INET6)
5683 struct sockaddr_in sin_store;
5686 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5687 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5689 #if defined(INET) && defined(INET6)
5690 if (spa->ssp_addr.ss_family == AF_INET6) {
5691 struct sockaddr_in6 *sin6;
5693 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5694 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5695 in6_sin6_2_sin(&sin_store, sin6);
5696 addr = (struct sockaddr *)&sin_store;
5698 addr = (struct sockaddr *)&spa->ssp_addr;
5701 addr = (struct sockaddr *)&spa->ssp_addr;
5704 addr = (struct sockaddr *)&spa->ssp_addr;
5707 net = sctp_findnet(stcb, addr);
5710 * We increment here since
5711 * sctp_findassociation_ep_addr() wil do a
5712 * decrement if it finds the stcb as long as
5713 * the locked tcb (last argument) is NOT a
5717 SCTP_INP_INCR_REF(inp);
5718 stcb = sctp_findassociation_ep_addr(&inp, addr,
5721 SCTP_INP_DECR_REF(inp);
5725 if ((stcb != NULL) && (net != NULL)) {
5726 if (net != stcb->asoc.primary_destination) {
5727 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5728 /* Ok we need to set it */
5729 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5730 if ((stcb->asoc.alternate) &&
5731 (!(net->dest_state & SCTP_ADDR_PF)) &&
5732 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5733 sctp_free_remote_addr(stcb->asoc.alternate);
5734 stcb->asoc.alternate = NULL;
5737 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5741 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);
5750 SCTP_TCB_UNLOCK(stcb);
5754 case SCTP_SET_DYNAMIC_PRIMARY:
5756 union sctp_sockstore *ss;
5758 error = priv_check(curthread,
5759 PRIV_NETINET_RESERVEDPORT);
5763 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5764 /* SUPER USER CHECK? */
5765 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5768 case SCTP_SET_PEER_PRIMARY_ADDR:
5770 struct sctp_setpeerprim *sspp;
5771 struct sockaddr *addr;
5772 #if defined(INET) && defined(INET6)
5773 struct sockaddr_in sin_store;
5776 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5777 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5779 struct sctp_ifa *ifa;
5781 #if defined(INET) && defined(INET6)
5782 if (sspp->sspp_addr.ss_family == AF_INET6) {
5783 struct sockaddr_in6 *sin6;
5785 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5786 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5787 in6_sin6_2_sin(&sin_store, sin6);
5788 addr = (struct sockaddr *)&sin_store;
5790 addr = (struct sockaddr *)&sspp->sspp_addr;
5793 addr = (struct sockaddr *)&sspp->sspp_addr;
5796 addr = (struct sockaddr *)&sspp->sspp_addr;
5798 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5804 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5806 * Must validate the ifa found is in
5809 struct sctp_laddr *laddr;
5812 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5813 if (laddr->ifa == NULL) {
5814 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5818 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5819 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5822 if (laddr->ifa == ifa) {
5828 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5833 switch (addr->sa_family) {
5837 struct sockaddr_in *sin;
5839 sin = (struct sockaddr_in *)addr;
5840 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5841 &sin->sin_addr) != 0) {
5842 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5852 struct sockaddr_in6 *sin6;
5854 sin6 = (struct sockaddr_in6 *)addr;
5855 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5856 &sin6->sin6_addr) != 0) {
5857 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5865 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5870 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5871 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5874 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5876 SCTP_TCB_UNLOCK(stcb);
5878 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5883 case SCTP_BINDX_ADD_ADDR:
5885 struct sctp_getaddresses *addrs;
5888 td = (struct thread *)p;
5889 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5892 if (addrs->addr->sa_family == AF_INET) {
5893 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5894 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5898 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5899 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5905 if (addrs->addr->sa_family == AF_INET6) {
5906 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5907 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5911 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5912 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5913 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5919 error = EAFNOSUPPORT;
5922 sctp_bindx_add_address(so, inp, addrs->addr,
5923 addrs->sget_assoc_id, vrf_id,
5927 case SCTP_BINDX_REM_ADDR:
5929 struct sctp_getaddresses *addrs;
5932 td = (struct thread *)p;
5934 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5936 if (addrs->addr->sa_family == AF_INET) {
5937 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5938 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5942 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5943 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5949 if (addrs->addr->sa_family == AF_INET6) {
5950 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5951 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5956 (error = prison_local_ip6(td->td_ucred,
5957 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5958 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5959 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5965 error = EAFNOSUPPORT;
5968 sctp_bindx_delete_address(inp, addrs->addr,
5969 addrs->sget_assoc_id, vrf_id,
5975 struct sctp_event *event;
5976 uint32_t event_type;
5978 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5979 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5980 switch (event->se_type) {
5981 case SCTP_ASSOC_CHANGE:
5982 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5984 case SCTP_PEER_ADDR_CHANGE:
5985 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5987 case SCTP_REMOTE_ERROR:
5988 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5990 case SCTP_SEND_FAILED:
5991 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5993 case SCTP_SHUTDOWN_EVENT:
5994 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5996 case SCTP_ADAPTATION_INDICATION:
5997 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5999 case SCTP_PARTIAL_DELIVERY_EVENT:
6000 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6002 case SCTP_AUTHENTICATION_EVENT:
6003 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6005 case SCTP_STREAM_RESET_EVENT:
6006 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6008 case SCTP_SENDER_DRY_EVENT:
6009 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6011 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6013 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6016 case SCTP_ASSOC_RESET_EVENT:
6017 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6019 case SCTP_STREAM_CHANGE_EVENT:
6020 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6022 case SCTP_SEND_FAILED_EVENT:
6023 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6027 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6031 if (event_type > 0) {
6034 sctp_stcb_feature_on(inp, stcb, event_type);
6035 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6036 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6037 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6038 (stcb->asoc.stream_queue_cnt == 0)) {
6039 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6043 sctp_stcb_feature_off(inp, stcb, event_type);
6045 SCTP_TCB_UNLOCK(stcb);
6048 * We don't want to send up a storm
6049 * of events, so return an error for
6052 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6053 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6054 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6055 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6056 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6057 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6061 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6062 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6063 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6064 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6065 SCTP_INP_WLOCK(inp);
6067 sctp_feature_on(inp, event_type);
6069 sctp_feature_off(inp, event_type);
6071 SCTP_INP_WUNLOCK(inp);
6073 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6074 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6075 SCTP_INP_RLOCK(inp);
6076 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6077 SCTP_TCB_LOCK(stcb);
6079 sctp_stcb_feature_on(inp, stcb, event_type);
6081 sctp_stcb_feature_off(inp, stcb, event_type);
6083 SCTP_TCB_UNLOCK(stcb);
6085 SCTP_INP_RUNLOCK(inp);
6091 case SCTP_RECVRCVINFO:
6095 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6096 SCTP_INP_WLOCK(inp);
6098 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6100 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6102 SCTP_INP_WUNLOCK(inp);
6105 case SCTP_RECVNXTINFO:
6109 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6110 SCTP_INP_WLOCK(inp);
6112 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6114 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6116 SCTP_INP_WUNLOCK(inp);
6119 case SCTP_DEFAULT_SNDINFO:
6121 struct sctp_sndinfo *info;
6124 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6125 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6128 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6129 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6130 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6131 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6132 stcb->asoc.def_send.sinfo_flags |= policy;
6133 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6134 stcb->asoc.def_send.sinfo_context = info->snd_context;
6136 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6139 SCTP_TCB_UNLOCK(stcb);
6141 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6142 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6143 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6144 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6145 SCTP_INP_WLOCK(inp);
6146 inp->def_send.sinfo_stream = info->snd_sid;
6147 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6148 inp->def_send.sinfo_flags = info->snd_flags;
6149 inp->def_send.sinfo_flags |= policy;
6150 inp->def_send.sinfo_ppid = info->snd_ppid;
6151 inp->def_send.sinfo_context = info->snd_context;
6152 SCTP_INP_WUNLOCK(inp);
6154 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6155 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6156 SCTP_INP_RLOCK(inp);
6157 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6158 SCTP_TCB_LOCK(stcb);
6159 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6160 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6161 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6162 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6163 stcb->asoc.def_send.sinfo_flags |= policy;
6164 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6165 stcb->asoc.def_send.sinfo_context = info->snd_context;
6167 SCTP_TCB_UNLOCK(stcb);
6169 SCTP_INP_RUNLOCK(inp);
6174 case SCTP_DEFAULT_PRINFO:
6176 struct sctp_default_prinfo *info;
6178 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6179 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6181 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6182 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6187 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6188 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6189 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6190 SCTP_TCB_UNLOCK(stcb);
6192 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6193 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6194 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6195 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6196 SCTP_INP_WLOCK(inp);
6197 inp->def_send.sinfo_flags &= 0xfff0;
6198 inp->def_send.sinfo_flags |= info->pr_policy;
6199 inp->def_send.sinfo_timetolive = info->pr_value;
6200 SCTP_INP_WUNLOCK(inp);
6202 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6203 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6204 SCTP_INP_RLOCK(inp);
6205 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6206 SCTP_TCB_LOCK(stcb);
6207 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6208 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6209 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6210 SCTP_TCB_UNLOCK(stcb);
6212 SCTP_INP_RUNLOCK(inp);
6217 case SCTP_PEER_ADDR_THLDS:
6218 /* Applies to the specific association */
6220 struct sctp_paddrthlds *thlds;
6221 struct sctp_nets *net;
6222 struct sockaddr *addr;
6223 #if defined(INET) && defined(INET6)
6224 struct sockaddr_in sin_store;
6227 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6228 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6230 #if defined(INET) && defined(INET6)
6231 if (thlds->spt_address.ss_family == AF_INET6) {
6232 struct sockaddr_in6 *sin6;
6234 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6235 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6236 in6_sin6_2_sin(&sin_store, sin6);
6237 addr = (struct sockaddr *)&sin_store;
6239 addr = (struct sockaddr *)&thlds->spt_address;
6242 addr = (struct sockaddr *)&thlds->spt_address;
6245 addr = (struct sockaddr *)&thlds->spt_address;
6248 net = sctp_findnet(stcb, addr);
6251 * We increment here since
6252 * sctp_findassociation_ep_addr() wil do a
6253 * decrement if it finds the stcb as long as
6254 * the locked tcb (last argument) is NOT a
6258 SCTP_INP_INCR_REF(inp);
6259 stcb = sctp_findassociation_ep_addr(&inp, addr,
6262 SCTP_INP_DECR_REF(inp);
6265 if ((stcb != NULL) && (net == NULL)) {
6267 if (addr->sa_family == AF_INET) {
6269 struct sockaddr_in *sin;
6271 sin = (struct sockaddr_in *)addr;
6272 if (sin->sin_addr.s_addr != INADDR_ANY) {
6273 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6274 SCTP_TCB_UNLOCK(stcb);
6281 if (addr->sa_family == AF_INET6) {
6282 struct sockaddr_in6 *sin6;
6284 sin6 = (struct sockaddr_in6 *)addr;
6285 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6286 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6287 SCTP_TCB_UNLOCK(stcb);
6294 error = EAFNOSUPPORT;
6295 SCTP_TCB_UNLOCK(stcb);
6296 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6300 if (thlds->spt_pathcpthld != 0xffff) {
6302 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6307 net->failure_threshold = thlds->spt_pathmaxrxt;
6308 net->pf_threshold = thlds->spt_pathpfthld;
6309 if (net->dest_state & SCTP_ADDR_PF) {
6310 if ((net->error_count > net->failure_threshold) ||
6311 (net->error_count <= net->pf_threshold)) {
6312 net->dest_state &= ~SCTP_ADDR_PF;
6315 if ((net->error_count > net->pf_threshold) &&
6316 (net->error_count <= net->failure_threshold)) {
6317 net->dest_state |= SCTP_ADDR_PF;
6318 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6319 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6320 stcb->sctp_ep, stcb, net,
6321 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6322 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6325 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6326 if (net->error_count > net->failure_threshold) {
6327 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6328 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6331 if (net->error_count <= net->failure_threshold) {
6332 net->dest_state |= SCTP_ADDR_REACHABLE;
6333 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6337 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6338 net->failure_threshold = thlds->spt_pathmaxrxt;
6339 net->pf_threshold = thlds->spt_pathpfthld;
6340 if (net->dest_state & SCTP_ADDR_PF) {
6341 if ((net->error_count > net->failure_threshold) ||
6342 (net->error_count <= net->pf_threshold)) {
6343 net->dest_state &= ~SCTP_ADDR_PF;
6346 if ((net->error_count > net->pf_threshold) &&
6347 (net->error_count <= net->failure_threshold)) {
6348 net->dest_state |= SCTP_ADDR_PF;
6349 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6350 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6351 stcb->sctp_ep, stcb, net,
6352 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6353 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6356 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6357 if (net->error_count > net->failure_threshold) {
6358 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6359 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6362 if (net->error_count <= net->failure_threshold) {
6363 net->dest_state |= SCTP_ADDR_REACHABLE;
6364 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6368 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6369 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6371 SCTP_TCB_UNLOCK(stcb);
6373 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6374 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6375 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6376 SCTP_INP_WLOCK(inp);
6377 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6378 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6379 SCTP_INP_WUNLOCK(inp);
6381 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6387 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6389 struct sctp_udpencaps *encaps;
6390 struct sctp_nets *net;
6391 struct sockaddr *addr;
6392 #if defined(INET) && defined(INET6)
6393 struct sockaddr_in sin_store;
6396 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6397 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6399 #if defined(INET) && defined(INET6)
6400 if (encaps->sue_address.ss_family == AF_INET6) {
6401 struct sockaddr_in6 *sin6;
6403 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6404 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6405 in6_sin6_2_sin(&sin_store, sin6);
6406 addr = (struct sockaddr *)&sin_store;
6408 addr = (struct sockaddr *)&encaps->sue_address;
6411 addr = (struct sockaddr *)&encaps->sue_address;
6414 addr = (struct sockaddr *)&encaps->sue_address;
6417 net = sctp_findnet(stcb, addr);
6420 * We increment here since
6421 * sctp_findassociation_ep_addr() wil do a
6422 * decrement if it finds the stcb as long as
6423 * the locked tcb (last argument) is NOT a
6427 SCTP_INP_INCR_REF(inp);
6428 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6430 SCTP_INP_DECR_REF(inp);
6433 if ((stcb != NULL) && (net == NULL)) {
6435 if (addr->sa_family == AF_INET) {
6437 struct sockaddr_in *sin;
6439 sin = (struct sockaddr_in *)addr;
6440 if (sin->sin_addr.s_addr != INADDR_ANY) {
6441 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6442 SCTP_TCB_UNLOCK(stcb);
6449 if (addr->sa_family == AF_INET6) {
6450 struct sockaddr_in6 *sin6;
6452 sin6 = (struct sockaddr_in6 *)addr;
6453 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6454 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6455 SCTP_TCB_UNLOCK(stcb);
6462 error = EAFNOSUPPORT;
6463 SCTP_TCB_UNLOCK(stcb);
6464 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6470 net->port = encaps->sue_port;
6472 stcb->asoc.port = encaps->sue_port;
6474 SCTP_TCB_UNLOCK(stcb);
6476 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6477 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6478 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6479 SCTP_INP_WLOCK(inp);
6480 inp->sctp_ep.port = encaps->sue_port;
6481 SCTP_INP_WUNLOCK(inp);
6483 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6489 case SCTP_ECN_SUPPORTED:
6491 struct sctp_assoc_value *av;
6493 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6494 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6497 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6499 SCTP_TCB_UNLOCK(stcb);
6501 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6502 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6503 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6504 SCTP_INP_WLOCK(inp);
6505 if (av->assoc_value == 0) {
6506 inp->ecn_supported = 0;
6508 inp->ecn_supported = 1;
6510 SCTP_INP_WUNLOCK(inp);
6512 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6518 case SCTP_PR_SUPPORTED:
6520 struct sctp_assoc_value *av;
6522 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6523 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6526 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6528 SCTP_TCB_UNLOCK(stcb);
6530 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6531 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6532 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6533 SCTP_INP_WLOCK(inp);
6534 if (av->assoc_value == 0) {
6535 inp->prsctp_supported = 0;
6537 inp->prsctp_supported = 1;
6539 SCTP_INP_WUNLOCK(inp);
6541 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6547 case SCTP_AUTH_SUPPORTED:
6549 struct sctp_assoc_value *av;
6551 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6552 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6555 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6557 SCTP_TCB_UNLOCK(stcb);
6559 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6560 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6561 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6562 if ((av->assoc_value == 0) &&
6563 (inp->asconf_supported == 1)) {
6565 * AUTH is required for
6568 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6571 SCTP_INP_WLOCK(inp);
6572 if (av->assoc_value == 0) {
6573 inp->auth_supported = 0;
6575 inp->auth_supported = 1;
6577 SCTP_INP_WUNLOCK(inp);
6580 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6586 case SCTP_ASCONF_SUPPORTED:
6588 struct sctp_assoc_value *av;
6590 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6591 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6594 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6596 SCTP_TCB_UNLOCK(stcb);
6598 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6599 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6600 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6601 if ((av->assoc_value != 0) &&
6602 (inp->auth_supported == 0)) {
6604 * AUTH is required for
6607 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6610 SCTP_INP_WLOCK(inp);
6611 if (av->assoc_value == 0) {
6612 inp->asconf_supported = 0;
6613 sctp_auth_delete_chunk(SCTP_ASCONF,
6614 inp->sctp_ep.local_auth_chunks);
6615 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6616 inp->sctp_ep.local_auth_chunks);
6618 inp->asconf_supported = 1;
6619 sctp_auth_add_chunk(SCTP_ASCONF,
6620 inp->sctp_ep.local_auth_chunks);
6621 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6622 inp->sctp_ep.local_auth_chunks);
6624 SCTP_INP_WUNLOCK(inp);
6627 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6633 case SCTP_RECONFIG_SUPPORTED:
6635 struct sctp_assoc_value *av;
6637 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6638 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6641 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6643 SCTP_TCB_UNLOCK(stcb);
6645 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6646 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6647 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6648 SCTP_INP_WLOCK(inp);
6649 if (av->assoc_value == 0) {
6650 inp->reconfig_supported = 0;
6652 inp->reconfig_supported = 1;
6654 SCTP_INP_WUNLOCK(inp);
6656 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6662 case SCTP_NRSACK_SUPPORTED:
6664 struct sctp_assoc_value *av;
6666 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6667 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6670 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6672 SCTP_TCB_UNLOCK(stcb);
6674 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6675 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6676 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6677 SCTP_INP_WLOCK(inp);
6678 if (av->assoc_value == 0) {
6679 inp->nrsack_supported = 0;
6681 inp->nrsack_supported = 1;
6683 SCTP_INP_WUNLOCK(inp);
6685 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6691 case SCTP_PKTDROP_SUPPORTED:
6693 struct sctp_assoc_value *av;
6695 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6696 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6699 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6701 SCTP_TCB_UNLOCK(stcb);
6703 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6704 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6705 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6706 SCTP_INP_WLOCK(inp);
6707 if (av->assoc_value == 0) {
6708 inp->pktdrop_supported = 0;
6710 inp->pktdrop_supported = 1;
6712 SCTP_INP_WUNLOCK(inp);
6714 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6722 struct sctp_assoc_value *av;
6723 struct sctp_nets *net;
6725 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6726 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6729 stcb->asoc.max_cwnd = av->assoc_value;
6730 if (stcb->asoc.max_cwnd > 0) {
6731 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6732 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6733 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6734 net->cwnd = stcb->asoc.max_cwnd;
6735 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6736 net->cwnd = net->mtu - sizeof(struct sctphdr);
6741 SCTP_TCB_UNLOCK(stcb);
6743 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6744 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6745 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6746 SCTP_INP_WLOCK(inp);
6747 inp->max_cwnd = av->assoc_value;
6748 SCTP_INP_WUNLOCK(inp);
6750 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6757 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6758 error = ENOPROTOOPT;
6760 } /* end switch (opt) */
6765 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6767 void *optval = NULL;
6771 struct sctp_inpcb *inp;
6773 if ((sopt->sopt_level == SOL_SOCKET) &&
6774 (sopt->sopt_name == SO_SETFIB)) {
6775 inp = (struct sctp_inpcb *)so->so_pcb;
6777 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6780 SCTP_INP_WLOCK(inp);
6781 inp->fibnum = so->so_fibnum;
6782 SCTP_INP_WUNLOCK(inp);
6785 if (sopt->sopt_level != IPPROTO_SCTP) {
6786 /* wrong proto level... send back up to IP */
6788 if (INP_CHECK_SOCKAF(so, AF_INET6))
6789 error = ip6_ctloutput(so, sopt);
6791 #if defined(INET) && defined(INET6)
6795 error = ip_ctloutput(so, sopt);
6799 optsize = sopt->sopt_valsize;
6801 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6802 if (optval == NULL) {
6803 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6806 error = sooptcopyin(sopt, optval, optsize, optsize);
6808 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6812 p = (void *)sopt->sopt_td;
6813 if (sopt->sopt_dir == SOPT_SET) {
6814 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6815 } else if (sopt->sopt_dir == SOPT_GET) {
6816 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6818 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6821 if ((error == 0) && (optval != NULL)) {
6822 error = sooptcopyout(sopt, optval, optsize);
6823 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6824 } else if (optval != NULL) {
6825 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6833 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6836 int create_lock_on = 0;
6838 struct sctp_inpcb *inp;
6839 struct sctp_tcb *stcb = NULL;
6841 inp = (struct sctp_inpcb *)so->so_pcb;
6843 /* I made the same as TCP since we are not setup? */
6844 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6845 return (ECONNRESET);
6848 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6851 switch (addr->sa_family) {
6855 struct sockaddr_in6 *sin6p;
6857 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6858 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6861 sin6p = (struct sockaddr_in6 *)addr;
6862 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6863 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6872 struct sockaddr_in *sinp;
6874 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6875 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6878 sinp = (struct sockaddr_in *)addr;
6879 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6880 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6888 return (EAFNOSUPPORT);
6890 SCTP_INP_INCR_REF(inp);
6891 SCTP_ASOC_CREATE_LOCK(inp);
6895 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6896 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6897 /* Should I really unlock ? */
6898 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6903 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6904 (addr->sa_family == AF_INET6)) {
6905 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6910 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6911 SCTP_PCB_FLAGS_UNBOUND) {
6912 /* Bind a ephemeral port */
6913 error = sctp_inpcb_bind(so, NULL, NULL, p);
6918 /* Now do we connect? */
6919 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6920 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6925 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6926 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6927 /* We are already connected AND the TCP model */
6928 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6932 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6933 SCTP_INP_RLOCK(inp);
6934 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6935 SCTP_INP_RUNLOCK(inp);
6938 * We increment here since sctp_findassociation_ep_addr()
6939 * will do a decrement if it finds the stcb as long as the
6940 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6942 SCTP_INP_INCR_REF(inp);
6943 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6945 SCTP_INP_DECR_REF(inp);
6947 SCTP_TCB_UNLOCK(stcb);
6951 /* Already have or am bring up an association */
6952 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
6956 vrf_id = inp->def_vrf_id;
6957 /* We are GOOD to go */
6958 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
6959 inp->sctp_ep.pre_open_stream_count,
6960 inp->sctp_ep.port, p);
6962 /* Gak! no memory */
6965 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
6966 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
6967 /* Set the connected flag so we can queue data */
6970 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
6971 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
6973 /* initialize authentication parameters for the assoc */
6974 sctp_initialize_auth_params(inp, stcb);
6976 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
6977 SCTP_TCB_UNLOCK(stcb);
6979 if (create_lock_on) {
6980 SCTP_ASOC_CREATE_UNLOCK(inp);
6982 SCTP_INP_DECR_REF(inp);
6988 sctp_listen(struct socket *so, int backlog, struct thread *p)
6991 * Note this module depends on the protocol processing being called
6992 * AFTER any socket level flags and backlog are applied to the
6993 * socket. The traditional way that the socket flags are applied is
6994 * AFTER protocol processing. We have made a change to the
6995 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
6996 * place if the socket API for SCTP is to work properly.
7000 struct sctp_inpcb *inp;
7002 inp = (struct sctp_inpcb *)so->so_pcb;
7004 /* I made the same as TCP since we are not setup? */
7005 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7006 return (ECONNRESET);
7008 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7009 /* See if we have a listener */
7010 struct sctp_inpcb *tinp;
7011 union sctp_sockstore store;
7013 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7015 struct sctp_laddr *laddr;
7017 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7018 memcpy(&store, &laddr->ifa->address, sizeof(store));
7019 switch (store.sa.sa_family) {
7022 store.sin.sin_port = inp->sctp_lport;
7027 store.sin6.sin6_port = inp->sctp_lport;
7033 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7034 if (tinp && (tinp != inp) &&
7035 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7036 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7037 (tinp->sctp_socket->so_qlimit)) {
7039 * we have a listener already and
7042 SCTP_INP_DECR_REF(tinp);
7043 return (EADDRINUSE);
7045 SCTP_INP_DECR_REF(tinp);
7049 /* Setup a local addr bound all */
7050 memset(&store, 0, sizeof(store));
7052 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7053 store.sa.sa_family = AF_INET6;
7054 store.sa.sa_len = sizeof(struct sockaddr_in6);
7058 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7059 store.sa.sa_family = AF_INET;
7060 store.sa.sa_len = sizeof(struct sockaddr_in);
7063 switch (store.sa.sa_family) {
7066 store.sin.sin_port = inp->sctp_lport;
7071 store.sin6.sin6_port = inp->sctp_lport;
7077 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7078 if (tinp && (tinp != inp) &&
7079 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7080 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7081 (tinp->sctp_socket->so_qlimit)) {
7083 * we have a listener already and its not
7086 SCTP_INP_DECR_REF(tinp);
7087 return (EADDRINUSE);
7089 SCTP_INP_DECR_REF(tinp);
7093 SCTP_INP_RLOCK(inp);
7094 #ifdef SCTP_LOCK_LOGGING
7095 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7096 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7100 error = solisten_proto_check(so);
7103 SCTP_INP_RUNLOCK(inp);
7106 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7107 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7109 * The unlucky case - We are in the tcp pool with this guy.
7110 * - Someone else is in the main inp slot. - We must move
7111 * this guy (the listener) to the main slot - We must then
7112 * move the guy that was listener to the TCP Pool.
7114 if (sctp_swap_inpcb_for_listen(inp)) {
7115 SCTP_INP_RUNLOCK(inp);
7116 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7117 return (EADDRINUSE);
7120 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7121 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7122 /* We are already connected AND the TCP model */
7123 SCTP_INP_RUNLOCK(inp);
7124 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7125 return (EADDRINUSE);
7127 SCTP_INP_RUNLOCK(inp);
7128 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7129 /* We must do a bind. */
7130 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7131 /* bind error, probably perm */
7136 /* It appears for 7.0 and on, we must always call this. */
7137 solisten_proto(so, backlog);
7138 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7139 /* remove the ACCEPTCONN flag for one-to-many sockets */
7140 so->so_options &= ~SO_ACCEPTCONN;
7143 /* turning off listen */
7144 so->so_options &= ~SO_ACCEPTCONN;
7150 static int sctp_defered_wakeup_cnt = 0;
7153 sctp_accept(struct socket *so, struct sockaddr **addr)
7155 struct sctp_tcb *stcb;
7156 struct sctp_inpcb *inp;
7157 union sctp_sockstore store;
7161 inp = (struct sctp_inpcb *)so->so_pcb;
7164 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7165 return (ECONNRESET);
7167 SCTP_INP_RLOCK(inp);
7168 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7169 SCTP_INP_RUNLOCK(inp);
7170 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7171 return (EOPNOTSUPP);
7173 if (so->so_state & SS_ISDISCONNECTED) {
7174 SCTP_INP_RUNLOCK(inp);
7175 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7176 return (ECONNABORTED);
7178 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7180 SCTP_INP_RUNLOCK(inp);
7181 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7182 return (ECONNRESET);
7184 SCTP_TCB_LOCK(stcb);
7185 SCTP_INP_RUNLOCK(inp);
7186 store = stcb->asoc.primary_destination->ro._l_addr;
7187 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
7188 SCTP_TCB_UNLOCK(stcb);
7189 switch (store.sa.sa_family) {
7193 struct sockaddr_in *sin;
7195 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7198 sin->sin_family = AF_INET;
7199 sin->sin_len = sizeof(*sin);
7200 sin->sin_port = store.sin.sin_port;
7201 sin->sin_addr = store.sin.sin_addr;
7202 *addr = (struct sockaddr *)sin;
7209 struct sockaddr_in6 *sin6;
7211 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7214 sin6->sin6_family = AF_INET6;
7215 sin6->sin6_len = sizeof(*sin6);
7216 sin6->sin6_port = store.sin6.sin6_port;
7217 sin6->sin6_addr = store.sin6.sin6_addr;
7218 if ((error = sa6_recoverscope(sin6)) != 0) {
7219 SCTP_FREE_SONAME(sin6);
7222 *addr = (struct sockaddr *)sin6;
7230 /* Wake any delayed sleep action */
7231 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7232 SCTP_INP_WLOCK(inp);
7233 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7234 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7235 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7236 SCTP_INP_WUNLOCK(inp);
7237 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7238 if (sowriteable(inp->sctp_socket)) {
7239 sowwakeup_locked(inp->sctp_socket);
7241 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7243 SCTP_INP_WLOCK(inp);
7245 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7246 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7247 SCTP_INP_WUNLOCK(inp);
7248 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7249 if (soreadable(inp->sctp_socket)) {
7250 sctp_defered_wakeup_cnt++;
7251 sorwakeup_locked(inp->sctp_socket);
7253 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7255 SCTP_INP_WLOCK(inp);
7257 SCTP_INP_WUNLOCK(inp);
7259 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7260 SCTP_TCB_LOCK(stcb);
7261 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7262 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7269 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7271 struct sockaddr_in *sin;
7273 struct sctp_inpcb *inp;
7274 struct sctp_ifa *sctp_ifa;
7277 * Do the malloc first in case it blocks.
7279 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7282 sin->sin_family = AF_INET;
7283 sin->sin_len = sizeof(*sin);
7284 inp = (struct sctp_inpcb *)so->so_pcb;
7286 SCTP_FREE_SONAME(sin);
7287 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7288 return (ECONNRESET);
7290 SCTP_INP_RLOCK(inp);
7291 sin->sin_port = inp->sctp_lport;
7292 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7293 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7294 struct sctp_tcb *stcb;
7295 struct sockaddr_in *sin_a;
7296 struct sctp_nets *net;
7299 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7305 SCTP_TCB_LOCK(stcb);
7306 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7307 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7309 /* this will make coverity happy */
7312 if (sin_a->sin_family == AF_INET) {
7317 if ((!fnd) || (sin_a == NULL)) {
7319 SCTP_TCB_UNLOCK(stcb);
7322 vrf_id = inp->def_vrf_id;
7323 sctp_ifa = sctp_source_address_selection(inp,
7325 (sctp_route_t *)&net->ro,
7328 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7329 sctp_free_ifa(sctp_ifa);
7331 SCTP_TCB_UNLOCK(stcb);
7333 /* For the bound all case you get back 0 */
7335 sin->sin_addr.s_addr = 0;
7339 /* Take the first IPv4 address in the list */
7340 struct sctp_laddr *laddr;
7343 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7344 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7345 struct sockaddr_in *sin_a;
7347 sin_a = &laddr->ifa->address.sin;
7348 sin->sin_addr = sin_a->sin_addr;
7354 SCTP_FREE_SONAME(sin);
7355 SCTP_INP_RUNLOCK(inp);
7356 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7360 SCTP_INP_RUNLOCK(inp);
7361 (*addr) = (struct sockaddr *)sin;
7366 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7368 struct sockaddr_in *sin;
7370 struct sockaddr_in *sin_a;
7371 struct sctp_inpcb *inp;
7372 struct sctp_tcb *stcb;
7373 struct sctp_nets *net;
7375 /* Do the malloc first in case it blocks. */
7376 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7379 sin->sin_family = AF_INET;
7380 sin->sin_len = sizeof(*sin);
7382 inp = (struct sctp_inpcb *)so->so_pcb;
7383 if ((inp == NULL) ||
7384 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7385 /* UDP type and listeners will drop out here */
7386 SCTP_FREE_SONAME(sin);
7387 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7390 SCTP_INP_RLOCK(inp);
7391 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7393 SCTP_TCB_LOCK(stcb);
7395 SCTP_INP_RUNLOCK(inp);
7397 SCTP_FREE_SONAME(sin);
7398 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7399 return (ECONNRESET);
7402 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7403 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7404 if (sin_a->sin_family == AF_INET) {
7406 sin->sin_port = stcb->rport;
7407 sin->sin_addr = sin_a->sin_addr;
7411 SCTP_TCB_UNLOCK(stcb);
7413 /* No IPv4 address */
7414 SCTP_FREE_SONAME(sin);
7415 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7418 (*addr) = (struct sockaddr *)sin;
7422 struct pr_usrreqs sctp_usrreqs = {
7423 .pru_abort = sctp_abort,
7424 .pru_accept = sctp_accept,
7425 .pru_attach = sctp_attach,
7426 .pru_bind = sctp_bind,
7427 .pru_connect = sctp_connect,
7428 .pru_control = in_control,
7429 .pru_close = sctp_close,
7430 .pru_detach = sctp_close,
7431 .pru_sopoll = sopoll_generic,
7432 .pru_flush = sctp_flush,
7433 .pru_disconnect = sctp_disconnect,
7434 .pru_listen = sctp_listen,
7435 .pru_peeraddr = sctp_peeraddr,
7436 .pru_send = sctp_sendm,
7437 .pru_shutdown = sctp_shutdown,
7438 .pru_sockaddr = sctp_ingetaddr,
7439 .pru_sosend = sctp_sosend,
7440 .pru_soreceive = sctp_soreceive