2 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * a) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
12 * b) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the distribution.
16 * c) Neither the name of Cisco Systems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <netinet/sctp_os.h>
38 #include <netinet/sctp_pcb.h>
39 #include <netinet/sctp_header.h>
40 #include <netinet/sctp_var.h>
42 #include <netinet6/sctp6_var.h>
44 #include <netinet/sctp_sysctl.h>
45 #include <netinet/sctp_output.h>
46 #include <netinet/sctp_uio.h>
47 #include <netinet/sctp_asconf.h>
48 #include <netinet/sctputil.h>
49 #include <netinet/sctp_indata.h>
50 #include <netinet/sctp_timer.h>
51 #include <netinet/sctp_auth.h>
52 #include <netinet/sctp_bsd_addr.h>
53 #include <netinet/udp.h>
57 extern const struct sctp_cc_functions sctp_cc_functions[];
58 extern const struct sctp_ss_functions sctp_ss_functions[];
65 /* Initialize and modify the sysctled variables */
67 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
68 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
70 * Allow a user to take no more than 1/2 the number of clusters or
71 * the SB_MAX whichever is smaller for the send window.
73 sb_max_adj = (u_long)((u_quad_t) (SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
74 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
75 (((uint32_t) nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
77 * Now for the recv window, should we take the same amount? or
78 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
79 * now I will just copy.
81 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
82 SCTP_BASE_VAR(first_time) = 0;
83 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
85 #if defined(SCTP_PACKET_LOGGING)
86 SCTP_BASE_VAR(packet_log_writers) = 0;
87 SCTP_BASE_VAR(packet_log_end) = 0;
88 bzero(&SCTP_BASE_VAR(packet_log_buffer), SCTP_PACKET_LOG_SIZE);
94 sctp_finish(void *unused __unused)
98 VNET_SYSUNINIT(sctp, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, sctp_finish, NULL);
102 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
104 struct sctp_tmit_chunk *chk;
107 /* Adjust that too */
108 stcb->asoc.smallest_mtu = nxtsz;
109 /* now off to subtract IP_DF flag if needed */
110 overhead = IP_HDR_SIZE;
111 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
112 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
114 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
115 if ((chk->send_size + overhead) > nxtsz) {
116 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
119 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
120 if ((chk->send_size + overhead) > nxtsz) {
122 * For this guy we also mark for immediate resend
123 * since we sent to big of chunk
125 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
126 if (chk->sent < SCTP_DATAGRAM_RESEND) {
127 sctp_flight_size_decrease(chk);
128 sctp_total_flight_decrease(stcb, chk);
129 chk->sent = SCTP_DATAGRAM_RESEND;
130 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
131 chk->rec.data.doing_fast_retransmit = 0;
132 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
133 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
134 chk->whoTo->flight_size,
136 (uint32_t) (uintptr_t) chk->whoTo,
137 chk->rec.data.TSN_seq);
139 /* Clear any time so NO RTT is being done */
148 sctp_notify(struct sctp_inpcb *inp,
149 struct sctp_tcb *stcb,
150 struct sctp_nets *net,
156 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
162 if (icmp_type != ICMP_UNREACH) {
163 /* We only care about unreachable */
164 SCTP_TCB_UNLOCK(stcb);
167 if ((icmp_code == ICMP_UNREACH_NET) ||
168 (icmp_code == ICMP_UNREACH_HOST) ||
169 (icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
170 (icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
171 (icmp_code == ICMP_UNREACH_ISOLATED) ||
172 (icmp_code == ICMP_UNREACH_NET_PROHIB) ||
173 (icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
174 (icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
175 /* Mark the net unreachable. */
176 if (net->dest_state & SCTP_ADDR_REACHABLE) {
177 /* OK, that destination is NOT reachable. */
178 net->dest_state &= ~SCTP_ADDR_REACHABLE;
179 net->dest_state &= ~SCTP_ADDR_PF;
180 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
182 (void *)net, SCTP_SO_NOT_LOCKED);
184 SCTP_TCB_UNLOCK(stcb);
185 } else if ((icmp_code == ICMP_UNREACH_PROTOCOL) ||
186 (icmp_code == ICMP_UNREACH_PORT)) {
187 /* Treat it like an ABORT. */
188 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
189 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
190 so = SCTP_INP_SO(inp);
191 atomic_add_int(&stcb->asoc.refcnt, 1);
192 SCTP_TCB_UNLOCK(stcb);
193 SCTP_SOCKET_LOCK(so, 1);
195 atomic_subtract_int(&stcb->asoc.refcnt, 1);
197 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
198 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
199 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
200 SCTP_SOCKET_UNLOCK(so, 1);
201 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
203 /* no need to unlock here, since the TCB is gone */
204 } else if (icmp_code == ICMP_UNREACH_NEEDFRAG) {
205 /* Find the next (smaller) MTU */
208 * Old type router that does not tell us what the
209 * next MTU is. Rats we will have to guess (in a
210 * educated fashion of course).
212 next_mtu = sctp_get_prev_mtu(ip_len);
214 /* Stop the PMTU timer. */
215 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
217 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
218 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
222 /* Update the path MTU. */
223 if (net->mtu > next_mtu) {
226 net->mtu -= sizeof(struct udphdr);
229 /* Update the association MTU */
230 if (stcb->asoc.smallest_mtu > next_mtu) {
231 sctp_pathmtu_adjustment(stcb, next_mtu);
233 /* Finally, start the PMTU timer if it was running before. */
235 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
237 SCTP_TCB_UNLOCK(stcb);
239 SCTP_TCB_UNLOCK(stcb);
244 sctp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
250 struct sctp_inpcb *inp;
251 struct sctp_tcb *stcb;
252 struct sctp_nets *net;
253 struct sctp_init_chunk *ch;
254 struct sockaddr_in src, dst;
256 if (sa->sa_family != AF_INET ||
257 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
260 if (PRC_IS_REDIRECT(cmd)) {
262 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
266 inner_ip = (struct ip *)vip;
267 icmp = (struct icmp *)((caddr_t)inner_ip -
268 (sizeof(struct icmp) - sizeof(struct ip)));
269 outer_ip = (struct ip *)((caddr_t)icmp - sizeof(struct ip));
270 sh = (struct sctphdr *)((caddr_t)inner_ip + (inner_ip->ip_hl << 2));
271 memset(&src, 0, sizeof(struct sockaddr_in));
272 src.sin_family = AF_INET;
273 src.sin_len = sizeof(struct sockaddr_in);
274 src.sin_port = sh->src_port;
275 src.sin_addr = inner_ip->ip_src;
276 memset(&dst, 0, sizeof(struct sockaddr_in));
277 dst.sin_family = AF_INET;
278 dst.sin_len = sizeof(struct sockaddr_in);
279 dst.sin_port = sh->dest_port;
280 dst.sin_addr = inner_ip->ip_dst;
282 * 'dst' holds the dest of the packet that failed to be
283 * sent. 'src' holds our local endpoint address. Thus we
284 * reverse the dst and the src in the lookup.
288 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst,
289 (struct sockaddr *)&src,
292 if ((stcb != NULL) &&
295 (inp->sctp_socket != NULL)) {
296 /* Check the verification tag */
297 if (ntohl(sh->v_tag) != 0) {
299 * This must be the verification tag used
300 * for sending out packets. We don't
301 * consider packets reflecting the
304 if (ntohl(sh->v_tag) != stcb->asoc.peer_vtag) {
305 SCTP_TCB_UNLOCK(stcb);
309 if (ntohs(outer_ip->ip_len) >=
311 8 + (inner_ip->ip_hl << 2) + 20) {
313 * In this case we can check if we
314 * got an INIT chunk and if the
315 * initiate tag matches.
317 ch = (struct sctp_init_chunk *)(sh + 1);
318 if ((ch->ch.chunk_type != SCTP_INITIATION) ||
319 (ntohl(ch->init.initiate_tag) != stcb->asoc.my_vtag)) {
320 SCTP_TCB_UNLOCK(stcb);
324 SCTP_TCB_UNLOCK(stcb);
328 sctp_notify(inp, stcb, net,
331 ntohs(inner_ip->ip_len),
332 ntohs(icmp->icmp_nextmtu));
334 if ((stcb == NULL) && (inp != NULL)) {
335 /* reduce ref-count */
337 SCTP_INP_DECR_REF(inp);
338 SCTP_INP_WUNLOCK(inp);
341 SCTP_TCB_UNLOCK(stcb);
351 sctp_getcred(SYSCTL_HANDLER_ARGS)
354 struct sockaddr_in addrs[2];
355 struct sctp_inpcb *inp;
356 struct sctp_nets *net;
357 struct sctp_tcb *stcb;
361 /* FIX, for non-bsd is this right? */
362 vrf_id = SCTP_DEFAULT_VRFID;
364 error = priv_check(req->td, PRIV_NETINET_GETCRED);
369 error = SYSCTL_IN(req, addrs, sizeof(addrs));
373 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
375 &inp, &net, 1, vrf_id);
376 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
377 if ((inp != NULL) && (stcb == NULL)) {
378 /* reduce ref-count */
380 SCTP_INP_DECR_REF(inp);
383 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
387 SCTP_TCB_UNLOCK(stcb);
389 * We use the write lock here, only since in the error leg we need
390 * it. If we used RLOCK, then we would have to
391 * wlock/decr/unlock/rlock. Which in theory could create a hole.
392 * Better to use higher wlock.
396 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
398 SCTP_INP_WUNLOCK(inp);
401 cru2x(inp->sctp_socket->so_cred, &xuc);
402 SCTP_INP_WUNLOCK(inp);
403 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
408 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
409 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
414 sctp_abort(struct socket *so)
416 struct sctp_inpcb *inp;
419 inp = (struct sctp_inpcb *)so->so_pcb;
424 flags = inp->sctp_flags;
425 #ifdef SCTP_LOG_CLOSING
426 sctp_log_closing(inp, NULL, 17);
428 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
429 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
430 #ifdef SCTP_LOG_CLOSING
431 sctp_log_closing(inp, NULL, 16);
433 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
434 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
436 SCTP_SB_CLEAR(so->so_snd);
438 * same for the rcv ones, they are only here for the
441 SCTP_SB_CLEAR(so->so_rcv);
443 /* Now null out the reference, we are completely detached. */
447 flags = inp->sctp_flags;
448 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
449 goto sctp_must_try_again;
456 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
458 struct sctp_inpcb *inp;
459 struct inpcb *ip_inp;
461 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
463 inp = (struct sctp_inpcb *)so->so_pcb;
465 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
468 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
469 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
474 error = sctp_inpcb_alloc(so, vrf_id);
478 inp = (struct sctp_inpcb *)so->so_pcb;
480 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
481 ip_inp = &inp->ip_inp.inp;
482 ip_inp->inp_vflag |= INP_IPV4;
483 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
484 SCTP_INP_WUNLOCK(inp);
489 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
491 struct sctp_inpcb *inp;
493 inp = (struct sctp_inpcb *)so->so_pcb;
495 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
499 if ((addr->sa_family != AF_INET) ||
500 (addr->sa_len != sizeof(struct sockaddr_in))) {
501 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
505 return (sctp_inpcb_bind(so, addr, NULL, p));
510 sctp_close(struct socket *so)
512 struct sctp_inpcb *inp;
515 inp = (struct sctp_inpcb *)so->so_pcb;
520 * Inform all the lower layer assoc that we are done.
523 flags = inp->sctp_flags;
524 #ifdef SCTP_LOG_CLOSING
525 sctp_log_closing(inp, NULL, 17);
527 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
528 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
529 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
530 (so->so_rcv.sb_cc > 0)) {
531 #ifdef SCTP_LOG_CLOSING
532 sctp_log_closing(inp, NULL, 13);
534 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
535 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
537 #ifdef SCTP_LOG_CLOSING
538 sctp_log_closing(inp, NULL, 14);
540 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
541 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
544 * The socket is now detached, no matter what the state of
545 * the SCTP association.
548 SCTP_SB_CLEAR(so->so_snd);
550 * same for the rcv ones, they are only here for the
553 SCTP_SB_CLEAR(so->so_rcv);
555 /* Now null out the reference, we are completely detached. */
559 flags = inp->sctp_flags;
560 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
561 goto sctp_must_try_again;
569 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
570 struct mbuf *control, struct thread *p);
574 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
575 struct mbuf *control, struct thread *p)
577 struct sctp_inpcb *inp;
580 inp = (struct sctp_inpcb *)so->so_pcb;
583 sctp_m_freem(control);
586 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
590 /* Got to have an to address if we are NOT a connected socket */
591 if ((addr == NULL) &&
592 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
593 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
595 } else if (addr == NULL) {
596 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
597 error = EDESTADDRREQ;
600 sctp_m_freem(control);
606 if (addr->sa_family != AF_INET) {
607 /* must be a v4 address! */
608 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
611 sctp_m_freem(control);
614 error = EDESTADDRREQ;
619 /* now what about control */
622 SCTP_PRINTF("huh? control set?\n");
623 sctp_m_freem(inp->control);
626 inp->control = control;
630 SCTP_BUF_NEXT(inp->pkt_last) = m;
633 inp->pkt_last = inp->pkt = m;
636 /* FreeBSD uses a flag passed */
637 ((flags & PRUS_MORETOCOME) == 0)
640 * note with the current version this code will only be used
641 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
642 * re-defining sosend to use the sctp_sosend. One can
643 * optionally switch back to this code (by changing back the
644 * definitions) but this is not advisable. This code is used
645 * by FreeBSD when sending a file with sendfile() though.
649 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
659 sctp_disconnect(struct socket *so)
661 struct sctp_inpcb *inp;
663 inp = (struct sctp_inpcb *)so->so_pcb;
665 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
669 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
670 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
671 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
673 SCTP_INP_RUNLOCK(inp);
676 struct sctp_association *asoc;
677 struct sctp_tcb *stcb;
679 stcb = LIST_FIRST(&inp->sctp_asoc_list);
681 SCTP_INP_RUNLOCK(inp);
682 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
687 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
688 /* We are about to be freed, out of here */
689 SCTP_TCB_UNLOCK(stcb);
690 SCTP_INP_RUNLOCK(inp);
693 if (((so->so_options & SO_LINGER) &&
694 (so->so_linger == 0)) ||
695 (so->so_rcv.sb_cc > 0)) {
696 if (SCTP_GET_STATE(asoc) !=
697 SCTP_STATE_COOKIE_WAIT) {
698 /* Left with Data unread */
701 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_NOWAIT, 1, MT_DATA);
707 struct sctp_paramhdr *ph;
709 ph = mtod(err, struct sctp_paramhdr *);
710 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
711 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
712 ph->param_length = htons(SCTP_BUF_LEN(err));
714 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
715 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
717 SCTP_INP_RUNLOCK(inp);
718 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
719 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
720 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
722 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
723 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
724 /* No unlock tcb assoc is gone */
727 if (TAILQ_EMPTY(&asoc->send_queue) &&
728 TAILQ_EMPTY(&asoc->sent_queue) &&
729 (asoc->stream_queue_cnt == 0)) {
730 /* there is nothing queued to send, so done */
731 if (asoc->locked_on_sending) {
734 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
735 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
736 /* only send SHUTDOWN 1st time thru */
737 struct sctp_nets *netp;
739 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
740 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
741 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
743 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
744 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
745 sctp_stop_timers_for_shutdown(stcb);
746 if (stcb->asoc.alternate) {
747 netp = stcb->asoc.alternate;
749 netp = stcb->asoc.primary_destination;
751 sctp_send_shutdown(stcb, netp);
752 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
753 stcb->sctp_ep, stcb, netp);
754 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
755 stcb->sctp_ep, stcb, netp);
756 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
760 * we still got (or just got) data to send,
761 * so set SHUTDOWN_PENDING
764 * XXX sockets draft says that SCTP_EOF
765 * should be sent with no data. currently,
766 * we will allow user data to be sent first
767 * and move to SHUTDOWN-PENDING
769 struct sctp_nets *netp;
771 if (stcb->asoc.alternate) {
772 netp = stcb->asoc.alternate;
774 netp = stcb->asoc.primary_destination;
777 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
778 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
780 if (asoc->locked_on_sending) {
781 /* Locked to send out the data */
782 struct sctp_stream_queue_pending *sp;
784 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
786 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
787 asoc->locked_on_sending->stream_no);
789 if ((sp->length == 0) && (sp->msg_is_complete == 0))
790 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
793 if (TAILQ_EMPTY(&asoc->send_queue) &&
794 TAILQ_EMPTY(&asoc->sent_queue) &&
795 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
799 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
800 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
801 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
802 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
803 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
804 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
805 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
807 SCTP_INP_RUNLOCK(inp);
808 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
809 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
812 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
815 soisdisconnecting(so);
816 SCTP_TCB_UNLOCK(stcb);
817 SCTP_INP_RUNLOCK(inp);
822 /* UDP model does not support this */
823 SCTP_INP_RUNLOCK(inp);
824 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
830 sctp_flush(struct socket *so, int how)
833 * We will just clear out the values and let subsequent close clear
834 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
835 * they will not be able to read the data, the socket will block
836 * that from happening.
838 struct sctp_inpcb *inp;
840 inp = (struct sctp_inpcb *)so->so_pcb;
842 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
846 /* For the 1 to many model this does nothing */
847 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
848 SCTP_INP_RUNLOCK(inp);
851 SCTP_INP_RUNLOCK(inp);
852 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
854 * First make sure the sb will be happy, we don't use these
855 * except maybe the count
858 SCTP_INP_READ_LOCK(inp);
859 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
860 SCTP_INP_READ_UNLOCK(inp);
861 SCTP_INP_WUNLOCK(inp);
862 so->so_rcv.sb_cc = 0;
863 so->so_rcv.sb_mbcnt = 0;
864 so->so_rcv.sb_mb = NULL;
866 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
868 * First make sure the sb will be happy, we don't use these
869 * except maybe the count
871 so->so_snd.sb_cc = 0;
872 so->so_snd.sb_mbcnt = 0;
873 so->so_snd.sb_mb = NULL;
880 sctp_shutdown(struct socket *so)
882 struct sctp_inpcb *inp;
884 inp = (struct sctp_inpcb *)so->so_pcb;
886 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
890 /* For UDP model this is a invalid call */
891 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
892 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
893 /* Restore the flags that the soshutdown took away. */
894 SOCKBUF_LOCK(&so->so_rcv);
895 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
896 SOCKBUF_UNLOCK(&so->so_rcv);
897 /* This proc will wakeup for read and do nothing (I hope) */
898 SCTP_INP_RUNLOCK(inp);
899 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
903 * Ok, if we reach here its the TCP model and it is either a
904 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
907 struct sctp_tcb *stcb;
908 struct sctp_association *asoc;
909 struct sctp_nets *netp;
912 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
913 SCTP_INP_RUNLOCK(inp);
918 stcb = LIST_FIRST(&inp->sctp_asoc_list);
921 * Ok, we hit the case that the shutdown call was
922 * made after an abort or something. Nothing to do
925 SCTP_INP_RUNLOCK(inp);
930 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
931 SCTP_TCB_UNLOCK(stcb);
932 SCTP_INP_RUNLOCK(inp);
935 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_WAIT) &&
936 (SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_ECHOED) &&
937 (SCTP_GET_STATE(asoc) != SCTP_STATE_OPEN)) {
939 * If we are not in or before ESTABLISHED, there is
940 * no protocol action required.
942 SCTP_TCB_UNLOCK(stcb);
943 SCTP_INP_RUNLOCK(inp);
946 if (stcb->asoc.alternate) {
947 netp = stcb->asoc.alternate;
949 netp = stcb->asoc.primary_destination;
951 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) &&
952 TAILQ_EMPTY(&asoc->send_queue) &&
953 TAILQ_EMPTY(&asoc->sent_queue) &&
954 (asoc->stream_queue_cnt == 0)) {
955 if (asoc->locked_on_sending) {
958 /* there is nothing queued to send, so I'm done... */
959 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
960 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
961 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
962 sctp_stop_timers_for_shutdown(stcb);
963 sctp_send_shutdown(stcb, netp);
964 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
965 stcb->sctp_ep, stcb, netp);
968 * We still got (or just got) data to send, so set
971 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
972 if (asoc->locked_on_sending) {
973 /* Locked to send out the data */
974 struct sctp_stream_queue_pending *sp;
976 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
978 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
979 asoc->locked_on_sending->stream_no);
981 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
982 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_PARTIAL_MSG_LEFT);
986 if (TAILQ_EMPTY(&asoc->send_queue) &&
987 TAILQ_EMPTY(&asoc->sent_queue) &&
988 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
992 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
993 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
994 sctp_abort_an_association(stcb->sctp_ep, stcb,
995 op_err, SCTP_SO_LOCKED);
996 SCTP_INP_RUNLOCK(inp);
1000 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, netp);
1002 * XXX: Why do this in the case where we have still data
1005 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1006 SCTP_TCB_UNLOCK(stcb);
1007 SCTP_INP_RUNLOCK(inp);
1013 * copies a "user" presentable address and removes embedded scope, etc.
1014 * returns 0 on success, 1 on error
1017 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1020 struct sockaddr_in6 lsa6;
1022 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1025 memcpy(ss, sa, sa->sa_len);
1032 * NOTE: assumes addr lock is held
1035 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1036 struct sctp_tcb *stcb,
1038 struct sockaddr_storage *sas,
1041 struct sctp_ifn *sctp_ifn;
1042 struct sctp_ifa *sctp_ifa;
1047 int ipv4_local_scope, ipv4_addr_legal;
1051 int local_scope, site_scope, ipv6_addr_legal;
1054 struct sctp_vrf *vrf;
1061 /* Turn on all the appropriate scope */
1062 loopback_scope = stcb->asoc.scope.loopback_scope;
1064 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1065 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1068 local_scope = stcb->asoc.scope.local_scope;
1069 site_scope = stcb->asoc.scope.site_scope;
1070 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1073 /* Use generic values for endpoints. */
1076 ipv4_local_scope = 1;
1082 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1084 ipv6_addr_legal = 1;
1087 if (SCTP_IPV6_V6ONLY(inp)) {
1088 ipv4_addr_legal = 0;
1090 ipv4_addr_legal = 1;
1095 ipv6_addr_legal = 0;
1098 ipv4_addr_legal = 1;
1102 vrf = sctp_find_vrf(vrf_id);
1106 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1107 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1108 if ((loopback_scope == 0) &&
1109 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1110 /* Skip loopback if loopback_scope not set */
1113 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1116 * For the BOUND-ALL case, the list
1117 * associated with a TCB is Always
1118 * considered a reverse list.. i.e.
1119 * it lists addresses that are NOT
1120 * part of the association. If this
1121 * is one of those we must skip it.
1123 if (sctp_is_addr_restricted(stcb,
1128 switch (sctp_ifa->address.sa.sa_family) {
1131 if (ipv4_addr_legal) {
1132 struct sockaddr_in *sin;
1134 sin = &sctp_ifa->address.sin;
1135 if (sin->sin_addr.s_addr == 0) {
1143 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1144 &sin->sin_addr) != 0) {
1147 if ((ipv4_local_scope == 0) &&
1148 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1152 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1153 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1154 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1155 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1156 actual += sizeof(struct sockaddr_in6);
1159 memcpy(sas, sin, sizeof(*sin));
1160 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1161 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1162 actual += sizeof(*sin);
1166 if (actual >= limit) {
1176 if (ipv6_addr_legal) {
1177 struct sockaddr_in6 *sin6;
1179 sin6 = &sctp_ifa->address.sin6;
1180 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1188 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1189 &sin6->sin6_addr) != 0) {
1192 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1193 if (local_scope == 0)
1195 if (sin6->sin6_scope_id == 0) {
1196 if (sa6_recoverscope(sin6) != 0)
1214 if ((site_scope == 0) &&
1215 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1218 memcpy(sas, sin6, sizeof(*sin6));
1219 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1220 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1221 actual += sizeof(*sin6);
1222 if (actual >= limit) {
1237 struct sctp_laddr *laddr;
1239 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1241 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1245 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1247 switch (laddr->ifa->address.sa.sa_family) {
1250 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1255 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1262 sas = (struct sockaddr_storage *)((caddr_t)sas +
1263 laddr->ifa->address.sa.sa_len);
1264 actual += laddr->ifa->address.sa.sa_len;
1265 if (actual >= limit) {
1274 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1275 struct sctp_tcb *stcb,
1277 struct sockaddr_storage *sas)
1281 SCTP_IPI_ADDR_RLOCK();
1282 /* fill up addresses for the endpoint's default vrf */
1283 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1285 SCTP_IPI_ADDR_RUNLOCK();
1290 * NOTE: assumes addr lock is held
1293 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1296 struct sctp_vrf *vrf = NULL;
1299 * In both sub-set bound an bound_all cases we return the MAXIMUM
1300 * number of addresses that you COULD get. In reality the sub-set
1301 * bound may have an exclusion list for a given TCB OR in the
1302 * bound-all case a TCB may NOT include the loopback or other
1303 * addresses as well.
1305 vrf = sctp_find_vrf(vrf_id);
1309 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1310 struct sctp_ifn *sctp_ifn;
1311 struct sctp_ifa *sctp_ifa;
1313 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1314 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1315 /* Count them if they are the right type */
1316 switch (sctp_ifa->address.sa.sa_family) {
1320 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1321 cnt += sizeof(struct sockaddr_in6);
1323 cnt += sizeof(struct sockaddr_in);
1325 cnt += sizeof(struct sockaddr_in);
1331 cnt += sizeof(struct sockaddr_in6);
1340 struct sctp_laddr *laddr;
1342 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1343 switch (laddr->ifa->address.sa.sa_family) {
1347 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1348 cnt += sizeof(struct sockaddr_in6);
1350 cnt += sizeof(struct sockaddr_in);
1352 cnt += sizeof(struct sockaddr_in);
1358 cnt += sizeof(struct sockaddr_in6);
1370 sctp_count_max_addresses(struct sctp_inpcb *inp)
1374 SCTP_IPI_ADDR_RLOCK();
1375 /* count addresses for the endpoint's default VRF */
1376 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1377 SCTP_IPI_ADDR_RUNLOCK();
1382 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1383 size_t optsize, void *p, int delay)
1386 int creat_lock_on = 0;
1387 struct sctp_tcb *stcb = NULL;
1388 struct sockaddr *sa;
1389 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1391 int bad_addresses = 0;
1394 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1396 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1397 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1398 /* We are already connected AND the TCP model */
1399 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1400 return (EADDRINUSE);
1402 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1403 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1404 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1407 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1408 SCTP_INP_RLOCK(inp);
1409 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1410 SCTP_INP_RUNLOCK(inp);
1413 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1416 SCTP_INP_INCR_REF(inp);
1417 SCTP_ASOC_CREATE_LOCK(inp);
1419 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1420 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1421 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1425 totaddrp = (unsigned int *)optval;
1426 totaddr = *totaddrp;
1427 sa = (struct sockaddr *)(totaddrp + 1);
1428 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (unsigned int)(optsize - sizeof(int)), &bad_addresses);
1429 if ((stcb != NULL) || bad_addresses) {
1430 /* Already have or am bring up an association */
1431 SCTP_ASOC_CREATE_UNLOCK(inp);
1434 SCTP_TCB_UNLOCK(stcb);
1435 if (bad_addresses == 0) {
1436 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1442 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1447 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1449 struct in6pcb *inp6;
1451 inp6 = (struct in6pcb *)inp;
1452 if (SCTP_IPV6_V6ONLY(inp6)) {
1454 * if IPV6_V6ONLY flag, ignore connections destined
1455 * to a v4 addr or v4-mapped addr
1457 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1463 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1464 SCTP_PCB_FLAGS_UNBOUND) {
1465 /* Bind a ephemeral port */
1466 error = sctp_inpcb_bind(so, NULL, NULL, p);
1471 /* FIX ME: do we want to pass in a vrf on the connect call? */
1472 vrf_id = inp->def_vrf_id;
1475 /* We are GOOD to go */
1476 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1477 inp->sctp_ep.pre_open_stream_count,
1482 /* Gak! no memory */
1485 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1486 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1487 /* Set the connected flag so we can queue data */
1490 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1491 /* move to second address */
1492 switch (sa->sa_family) {
1495 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1500 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1508 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1509 /* Fill in the return id */
1511 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE,
1512 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
1515 a_id = (sctp_assoc_t *) optval;
1516 *a_id = sctp_get_associd(stcb);
1518 /* initialize authentication parameters for the assoc */
1519 sctp_initialize_auth_params(inp, stcb);
1522 /* doing delayed connection */
1523 stcb->asoc.delayed_connection = 1;
1524 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1526 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1527 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1529 SCTP_TCB_UNLOCK(stcb);
1530 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1531 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1532 /* Set the connected flag so we can queue data */
1536 if (creat_lock_on) {
1537 SCTP_ASOC_CREATE_UNLOCK(inp);
1539 SCTP_INP_DECR_REF(inp);
1543 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1544 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1545 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1546 SCTP_INP_RLOCK(inp); \
1547 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1549 SCTP_TCB_LOCK(stcb); \
1551 SCTP_INP_RUNLOCK(inp); \
1552 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1553 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1554 if (stcb == NULL) { \
1555 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1565 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1566 if (size < sizeof(type)) { \
1567 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1571 destp = (type *)srcp; \
1576 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1579 struct sctp_inpcb *inp = NULL;
1581 struct sctp_tcb *stcb = NULL;
1583 if (optval == NULL) {
1584 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1587 inp = (struct sctp_inpcb *)so->so_pcb;
1589 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1596 case SCTP_AUTOCLOSE:
1597 case SCTP_EXPLICIT_EOR:
1598 case SCTP_AUTO_ASCONF:
1599 case SCTP_DISABLE_FRAGMENTS:
1600 case SCTP_I_WANT_MAPPED_V4_ADDR:
1601 case SCTP_USE_EXT_RCVINFO:
1602 SCTP_INP_RLOCK(inp);
1604 case SCTP_DISABLE_FRAGMENTS:
1605 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1607 case SCTP_I_WANT_MAPPED_V4_ADDR:
1608 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1610 case SCTP_AUTO_ASCONF:
1611 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1612 /* only valid for bound all sockets */
1613 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1615 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1620 case SCTP_EXPLICIT_EOR:
1621 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1624 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1626 case SCTP_USE_EXT_RCVINFO:
1627 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1629 case SCTP_AUTOCLOSE:
1630 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1631 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1637 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1638 error = ENOPROTOOPT;
1639 } /* end switch (sopt->sopt_name) */
1640 if (*optsize < sizeof(val)) {
1641 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1645 SCTP_INP_RUNLOCK(inp);
1647 /* return the option value */
1648 *(int *)optval = val;
1649 *optsize = sizeof(val);
1652 case SCTP_GET_PACKET_LOG:
1654 #ifdef SCTP_PACKET_LOGGING
1658 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1659 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1662 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1667 case SCTP_REUSE_PORT:
1671 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1672 /* Can't do this for a 1-m socket */
1676 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1677 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1678 *optsize = sizeof(uint32_t);
1681 case SCTP_PARTIAL_DELIVERY_POINT:
1685 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1686 *value = inp->partial_delivery_point;
1687 *optsize = sizeof(uint32_t);
1690 case SCTP_FRAGMENT_INTERLEAVE:
1694 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1695 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1696 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1697 *value = SCTP_FRAG_LEVEL_2;
1699 *value = SCTP_FRAG_LEVEL_1;
1702 *value = SCTP_FRAG_LEVEL_0;
1704 *optsize = sizeof(uint32_t);
1707 case SCTP_INTERLEAVING_SUPPORTED:
1709 struct sctp_assoc_value *av;
1711 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1712 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1715 av->assoc_value = stcb->asoc.idata_supported;
1716 SCTP_TCB_UNLOCK(stcb);
1718 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1719 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1720 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1721 SCTP_INP_RLOCK(inp);
1722 if (inp->idata_supported) {
1723 av->assoc_value = 1;
1725 av->assoc_value = 0;
1727 SCTP_INP_RUNLOCK(inp);
1729 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1734 *optsize = sizeof(struct sctp_assoc_value);
1738 case SCTP_CMT_ON_OFF:
1740 struct sctp_assoc_value *av;
1742 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1743 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1745 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1746 SCTP_TCB_UNLOCK(stcb);
1748 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1749 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1750 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1751 SCTP_INP_RLOCK(inp);
1752 av->assoc_value = inp->sctp_cmt_on_off;
1753 SCTP_INP_RUNLOCK(inp);
1755 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1760 *optsize = sizeof(struct sctp_assoc_value);
1764 case SCTP_PLUGGABLE_CC:
1766 struct sctp_assoc_value *av;
1768 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1769 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1771 av->assoc_value = stcb->asoc.congestion_control_module;
1772 SCTP_TCB_UNLOCK(stcb);
1774 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1775 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1776 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1777 SCTP_INP_RLOCK(inp);
1778 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1779 SCTP_INP_RUNLOCK(inp);
1781 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1786 *optsize = sizeof(struct sctp_assoc_value);
1790 case SCTP_CC_OPTION:
1792 struct sctp_cc_option *cc_opt;
1794 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1795 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1799 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1802 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1803 *optsize = sizeof(struct sctp_cc_option);
1805 SCTP_TCB_UNLOCK(stcb);
1809 case SCTP_PLUGGABLE_SS:
1811 struct sctp_assoc_value *av;
1813 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1814 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1816 av->assoc_value = stcb->asoc.stream_scheduling_module;
1817 SCTP_TCB_UNLOCK(stcb);
1819 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1820 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1821 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1822 SCTP_INP_RLOCK(inp);
1823 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1824 SCTP_INP_RUNLOCK(inp);
1826 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1831 *optsize = sizeof(struct sctp_assoc_value);
1837 struct sctp_stream_value *av;
1839 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1840 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1842 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1843 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1844 &av->stream_value) < 0)) {
1845 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1848 *optsize = sizeof(struct sctp_stream_value);
1850 SCTP_TCB_UNLOCK(stcb);
1853 * Can't get stream value without
1856 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1861 case SCTP_GET_ADDR_LEN:
1863 struct sctp_assoc_value *av;
1865 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1868 if (av->assoc_value == AF_INET) {
1869 av->assoc_value = sizeof(struct sockaddr_in);
1874 if (av->assoc_value == AF_INET6) {
1875 av->assoc_value = sizeof(struct sockaddr_in6);
1880 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1882 *optsize = sizeof(struct sctp_assoc_value);
1886 case SCTP_GET_ASSOC_NUMBER:
1888 uint32_t *value, cnt;
1890 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1891 SCTP_INP_RLOCK(inp);
1892 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1893 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1894 /* Can't do this for a 1-1 socket */
1896 SCTP_INP_RUNLOCK(inp);
1900 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1903 SCTP_INP_RUNLOCK(inp);
1905 *optsize = sizeof(uint32_t);
1908 case SCTP_GET_ASSOC_ID_LIST:
1910 struct sctp_assoc_ids *ids;
1914 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1915 SCTP_INP_RLOCK(inp);
1916 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1917 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1918 /* Can't do this for a 1-1 socket */
1920 SCTP_INP_RUNLOCK(inp);
1924 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1925 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1927 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1930 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1935 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1939 SCTP_INP_RUNLOCK(inp);
1941 ids->gaids_number_of_ids = at;
1942 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1948 struct sctp_assoc_value *av;
1950 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1951 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1954 av->assoc_value = stcb->asoc.context;
1955 SCTP_TCB_UNLOCK(stcb);
1957 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1958 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1959 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1960 SCTP_INP_RLOCK(inp);
1961 av->assoc_value = inp->sctp_context;
1962 SCTP_INP_RUNLOCK(inp);
1964 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1969 *optsize = sizeof(struct sctp_assoc_value);
1975 uint32_t *default_vrfid;
1977 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1978 *default_vrfid = inp->def_vrf_id;
1979 *optsize = sizeof(uint32_t);
1982 case SCTP_GET_ASOC_VRF:
1984 struct sctp_assoc_value *id;
1986 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1987 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1990 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1992 id->assoc_value = stcb->asoc.vrf_id;
1993 *optsize = sizeof(struct sctp_assoc_value);
1997 case SCTP_GET_VRF_IDS:
1999 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
2003 case SCTP_GET_NONCE_VALUES:
2005 struct sctp_get_nonce_values *gnv;
2007 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
2008 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
2011 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
2012 gnv->gn_local_tag = stcb->asoc.my_vtag;
2013 SCTP_TCB_UNLOCK(stcb);
2014 *optsize = sizeof(struct sctp_get_nonce_values);
2016 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2021 case SCTP_DELAYED_SACK:
2023 struct sctp_sack_info *sack;
2025 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2026 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2028 sack->sack_delay = stcb->asoc.delayed_ack;
2029 sack->sack_freq = stcb->asoc.sack_freq;
2030 SCTP_TCB_UNLOCK(stcb);
2032 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2033 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2034 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2035 SCTP_INP_RLOCK(inp);
2036 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2037 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2038 SCTP_INP_RUNLOCK(inp);
2040 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2045 *optsize = sizeof(struct sctp_sack_info);
2049 case SCTP_GET_SNDBUF_USE:
2051 struct sctp_sockstat *ss;
2053 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2054 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2057 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2058 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2059 stcb->asoc.size_on_all_streams);
2060 SCTP_TCB_UNLOCK(stcb);
2061 *optsize = sizeof(struct sctp_sockstat);
2063 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2068 case SCTP_MAX_BURST:
2070 struct sctp_assoc_value *av;
2072 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2073 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2076 av->assoc_value = stcb->asoc.max_burst;
2077 SCTP_TCB_UNLOCK(stcb);
2079 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2080 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2081 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2082 SCTP_INP_RLOCK(inp);
2083 av->assoc_value = inp->sctp_ep.max_burst;
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);
2097 struct sctp_assoc_value *av;
2100 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2101 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2104 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2105 SCTP_TCB_UNLOCK(stcb);
2107 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2108 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2109 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2110 SCTP_INP_RLOCK(inp);
2111 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2112 ovh = SCTP_MED_OVERHEAD;
2114 ovh = SCTP_MED_V4_OVERHEAD;
2116 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2117 av->assoc_value = 0;
2119 av->assoc_value = inp->sctp_frag_point - ovh;
2120 SCTP_INP_RUNLOCK(inp);
2122 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2127 *optsize = sizeof(struct sctp_assoc_value);
2131 case SCTP_GET_STAT_LOG:
2132 error = sctp_fill_stat_log(optval, optsize);
2136 struct sctp_event_subscribe *events;
2138 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2139 memset(events, 0, sizeof(struct sctp_event_subscribe));
2140 SCTP_INP_RLOCK(inp);
2141 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2142 events->sctp_data_io_event = 1;
2144 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2145 events->sctp_association_event = 1;
2147 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2148 events->sctp_address_event = 1;
2150 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2151 events->sctp_send_failure_event = 1;
2153 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2154 events->sctp_peer_error_event = 1;
2156 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2157 events->sctp_shutdown_event = 1;
2159 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2160 events->sctp_partial_delivery_event = 1;
2162 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2163 events->sctp_adaptation_layer_event = 1;
2165 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2166 events->sctp_authentication_event = 1;
2168 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2169 events->sctp_sender_dry_event = 1;
2171 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2172 events->sctp_stream_reset_event = 1;
2173 SCTP_INP_RUNLOCK(inp);
2174 *optsize = sizeof(struct sctp_event_subscribe);
2177 case SCTP_ADAPTATION_LAYER:
2181 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2183 SCTP_INP_RLOCK(inp);
2184 *value = inp->sctp_ep.adaptation_layer_indicator;
2185 SCTP_INP_RUNLOCK(inp);
2186 *optsize = sizeof(uint32_t);
2189 case SCTP_SET_INITIAL_DBG_SEQ:
2193 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2194 SCTP_INP_RLOCK(inp);
2195 *value = inp->sctp_ep.initial_sequence_debug;
2196 SCTP_INP_RUNLOCK(inp);
2197 *optsize = sizeof(uint32_t);
2200 case SCTP_GET_LOCAL_ADDR_SIZE:
2204 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2205 SCTP_INP_RLOCK(inp);
2206 *value = sctp_count_max_addresses(inp);
2207 SCTP_INP_RUNLOCK(inp);
2208 *optsize = sizeof(uint32_t);
2211 case SCTP_GET_REMOTE_ADDR_SIZE:
2215 struct sctp_nets *net;
2217 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2218 /* FIXME MT: change to sctp_assoc_value? */
2219 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2223 /* Count the sizes */
2224 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2225 switch (net->ro._l_addr.sa.sa_family) {
2229 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2230 size += sizeof(struct sockaddr_in6);
2232 size += sizeof(struct sockaddr_in);
2235 size += sizeof(struct sockaddr_in);
2241 size += sizeof(struct sockaddr_in6);
2248 SCTP_TCB_UNLOCK(stcb);
2249 *value = (uint32_t) size;
2250 *optsize = sizeof(uint32_t);
2252 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2257 case SCTP_GET_PEER_ADDRESSES:
2259 * Get the address information, an array is passed in to
2260 * fill up we pack it.
2264 struct sockaddr_storage *sas;
2265 struct sctp_nets *net;
2266 struct sctp_getaddresses *saddr;
2268 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2269 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2272 left = (*optsize) - sizeof(struct sctp_getaddresses);
2273 *optsize = sizeof(struct sctp_getaddresses);
2274 sas = (struct sockaddr_storage *)&saddr->addr[0];
2276 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2277 switch (net->ro._l_addr.sa.sa_family) {
2281 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2282 cpsz = sizeof(struct sockaddr_in6);
2284 cpsz = sizeof(struct sockaddr_in);
2287 cpsz = sizeof(struct sockaddr_in);
2293 cpsz = sizeof(struct sockaddr_in6);
2304 /* not enough room. */
2307 #if defined(INET) && defined(INET6)
2308 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2309 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2310 /* Must map the address */
2311 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2312 (struct sockaddr_in6 *)sas);
2314 memcpy(sas, &net->ro._l_addr, cpsz);
2317 memcpy(sas, &net->ro._l_addr, cpsz);
2319 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2321 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2325 SCTP_TCB_UNLOCK(stcb);
2327 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2332 case SCTP_GET_LOCAL_ADDRESSES:
2334 size_t limit, actual;
2335 struct sockaddr_storage *sas;
2336 struct sctp_getaddresses *saddr;
2338 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2339 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2341 sas = (struct sockaddr_storage *)&saddr->addr[0];
2342 limit = *optsize - sizeof(sctp_assoc_t);
2343 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2345 SCTP_TCB_UNLOCK(stcb);
2347 *optsize = sizeof(struct sockaddr_storage) + actual;
2350 case SCTP_PEER_ADDR_PARAMS:
2352 struct sctp_paddrparams *paddrp;
2353 struct sctp_nets *net;
2354 struct sockaddr *addr;
2356 #if defined(INET) && defined(INET6)
2357 struct sockaddr_in sin_store;
2361 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2362 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2364 #if defined(INET) && defined(INET6)
2365 if (paddrp->spp_address.ss_family == AF_INET6) {
2366 struct sockaddr_in6 *sin6;
2368 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2369 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2370 in6_sin6_2_sin(&sin_store, sin6);
2371 addr = (struct sockaddr *)&sin_store;
2373 addr = (struct sockaddr *)&paddrp->spp_address;
2376 addr = (struct sockaddr *)&paddrp->spp_address;
2379 addr = (struct sockaddr *)&paddrp->spp_address;
2382 net = sctp_findnet(stcb, addr);
2385 * We increment here since
2386 * sctp_findassociation_ep_addr() wil do a
2387 * decrement if it finds the stcb as long as
2388 * the locked tcb (last argument) is NOT a
2392 SCTP_INP_INCR_REF(inp);
2393 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2395 SCTP_INP_DECR_REF(inp);
2398 if ((stcb != NULL) && (net == NULL)) {
2400 if (addr->sa_family == AF_INET) {
2401 struct sockaddr_in *sin;
2403 sin = (struct sockaddr_in *)addr;
2404 if (sin->sin_addr.s_addr != INADDR_ANY) {
2406 SCTP_TCB_UNLOCK(stcb);
2407 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2413 if (addr->sa_family == AF_INET6) {
2414 struct sockaddr_in6 *sin6;
2416 sin6 = (struct sockaddr_in6 *)addr;
2417 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2419 SCTP_TCB_UNLOCK(stcb);
2420 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2426 error = EAFNOSUPPORT;
2427 SCTP_TCB_UNLOCK(stcb);
2428 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2433 /* Applies to the specific association */
2434 paddrp->spp_flags = 0;
2436 paddrp->spp_hbinterval = net->heart_beat_delay;
2437 paddrp->spp_pathmaxrxt = net->failure_threshold;
2438 paddrp->spp_pathmtu = net->mtu;
2439 switch (net->ro._l_addr.sa.sa_family) {
2442 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2447 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2453 /* get flags for HB */
2454 if (net->dest_state & SCTP_ADDR_NOHB) {
2455 paddrp->spp_flags |= SPP_HB_DISABLE;
2457 paddrp->spp_flags |= SPP_HB_ENABLE;
2459 /* get flags for PMTU */
2460 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2461 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2463 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2465 if (net->dscp & 0x01) {
2466 paddrp->spp_dscp = net->dscp & 0xfc;
2467 paddrp->spp_flags |= SPP_DSCP;
2470 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2471 (net->flowlabel & 0x80000000)) {
2472 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2473 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2478 * No destination so return default
2481 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2482 paddrp->spp_pathmtu = 0;
2483 if (stcb->asoc.default_dscp & 0x01) {
2484 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2485 paddrp->spp_flags |= SPP_DSCP;
2488 if (stcb->asoc.default_flowlabel & 0x80000000) {
2489 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2490 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2493 /* default settings should be these */
2494 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2495 paddrp->spp_flags |= SPP_HB_DISABLE;
2497 paddrp->spp_flags |= SPP_HB_ENABLE;
2499 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2500 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2502 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2504 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2506 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2507 SCTP_TCB_UNLOCK(stcb);
2509 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2510 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2511 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2512 /* Use endpoint defaults */
2513 SCTP_INP_RLOCK(inp);
2514 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2515 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2516 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2517 /* get inp's default */
2518 if (inp->sctp_ep.default_dscp & 0x01) {
2519 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2520 paddrp->spp_flags |= SPP_DSCP;
2523 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2524 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2525 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2526 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2529 /* can't return this */
2530 paddrp->spp_pathmtu = 0;
2532 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2533 paddrp->spp_flags |= SPP_HB_ENABLE;
2535 paddrp->spp_flags |= SPP_HB_DISABLE;
2537 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2538 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2540 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2542 SCTP_INP_RUNLOCK(inp);
2544 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2549 *optsize = sizeof(struct sctp_paddrparams);
2553 case SCTP_GET_PEER_ADDR_INFO:
2555 struct sctp_paddrinfo *paddri;
2556 struct sctp_nets *net;
2557 struct sockaddr *addr;
2559 #if defined(INET) && defined(INET6)
2560 struct sockaddr_in sin_store;
2564 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2565 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2567 #if defined(INET) && defined(INET6)
2568 if (paddri->spinfo_address.ss_family == AF_INET6) {
2569 struct sockaddr_in6 *sin6;
2571 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2572 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2573 in6_sin6_2_sin(&sin_store, sin6);
2574 addr = (struct sockaddr *)&sin_store;
2576 addr = (struct sockaddr *)&paddri->spinfo_address;
2579 addr = (struct sockaddr *)&paddri->spinfo_address;
2582 addr = (struct sockaddr *)&paddri->spinfo_address;
2585 net = sctp_findnet(stcb, addr);
2588 * We increment here since
2589 * sctp_findassociation_ep_addr() wil do a
2590 * decrement if it finds the stcb as long as
2591 * the locked tcb (last argument) is NOT a
2595 SCTP_INP_INCR_REF(inp);
2596 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2598 SCTP_INP_DECR_REF(inp);
2602 if ((stcb != NULL) && (net != NULL)) {
2603 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2604 /* It's unconfirmed */
2605 paddri->spinfo_state = SCTP_UNCONFIRMED;
2606 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2608 paddri->spinfo_state = SCTP_ACTIVE;
2611 paddri->spinfo_state = SCTP_INACTIVE;
2613 paddri->spinfo_cwnd = net->cwnd;
2614 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2615 paddri->spinfo_rto = net->RTO;
2616 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2617 paddri->spinfo_mtu = net->mtu;
2618 switch (addr->sa_family) {
2621 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2626 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2632 SCTP_TCB_UNLOCK(stcb);
2633 *optsize = sizeof(struct sctp_paddrinfo);
2636 SCTP_TCB_UNLOCK(stcb);
2638 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2643 case SCTP_PCB_STATUS:
2645 struct sctp_pcbinfo *spcb;
2647 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2648 sctp_fill_pcbinfo(spcb);
2649 *optsize = sizeof(struct sctp_pcbinfo);
2654 struct sctp_nets *net;
2655 struct sctp_status *sstat;
2657 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2658 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2661 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2665 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2666 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2667 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2668 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2670 * We can't include chunks that have been passed to
2671 * the socket layer. Only things in queue.
2673 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2674 stcb->asoc.cnt_on_all_streams);
2677 sstat->sstat_instrms = stcb->asoc.streamincnt;
2678 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2679 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2680 memcpy(&sstat->sstat_primary.spinfo_address,
2681 &stcb->asoc.primary_destination->ro._l_addr,
2682 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2683 net = stcb->asoc.primary_destination;
2684 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2686 * Again the user can get info from sctp_constants.h
2687 * for what the state of the network is.
2689 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2690 /* It's unconfirmed */
2691 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2692 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2694 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2697 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2699 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2700 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2701 sstat->sstat_primary.spinfo_rto = net->RTO;
2702 sstat->sstat_primary.spinfo_mtu = net->mtu;
2703 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2706 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2711 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2717 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2718 SCTP_TCB_UNLOCK(stcb);
2719 *optsize = sizeof(struct sctp_status);
2724 struct sctp_rtoinfo *srto;
2726 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2727 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2730 srto->srto_initial = stcb->asoc.initial_rto;
2731 srto->srto_max = stcb->asoc.maxrto;
2732 srto->srto_min = stcb->asoc.minrto;
2733 SCTP_TCB_UNLOCK(stcb);
2735 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2736 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2737 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2738 SCTP_INP_RLOCK(inp);
2739 srto->srto_initial = inp->sctp_ep.initial_rto;
2740 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2741 srto->srto_min = inp->sctp_ep.sctp_minrto;
2742 SCTP_INP_RUNLOCK(inp);
2744 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2749 *optsize = sizeof(struct sctp_rtoinfo);
2755 struct sctp_timeouts *stimo;
2757 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2758 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2761 stimo->stimo_init = stcb->asoc.timoinit;
2762 stimo->stimo_data = stcb->asoc.timodata;
2763 stimo->stimo_sack = stcb->asoc.timosack;
2764 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2765 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2766 stimo->stimo_cookie = stcb->asoc.timocookie;
2767 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2768 SCTP_TCB_UNLOCK(stcb);
2769 *optsize = sizeof(struct sctp_timeouts);
2771 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2776 case SCTP_ASSOCINFO:
2778 struct sctp_assocparams *sasoc;
2780 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2781 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2784 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2785 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2786 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2787 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2788 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2789 SCTP_TCB_UNLOCK(stcb);
2791 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2792 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2793 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2794 SCTP_INP_RLOCK(inp);
2795 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2796 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2797 sasoc->sasoc_number_peer_destinations = 0;
2798 sasoc->sasoc_peer_rwnd = 0;
2799 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2800 SCTP_INP_RUNLOCK(inp);
2802 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2807 *optsize = sizeof(struct sctp_assocparams);
2811 case SCTP_DEFAULT_SEND_PARAM:
2813 struct sctp_sndrcvinfo *s_info;
2815 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2816 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2819 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2820 SCTP_TCB_UNLOCK(stcb);
2822 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2823 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2824 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2825 SCTP_INP_RLOCK(inp);
2826 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2827 SCTP_INP_RUNLOCK(inp);
2829 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2834 *optsize = sizeof(struct sctp_sndrcvinfo);
2840 struct sctp_initmsg *sinit;
2842 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2843 SCTP_INP_RLOCK(inp);
2844 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2845 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2846 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2847 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2848 SCTP_INP_RUNLOCK(inp);
2849 *optsize = sizeof(struct sctp_initmsg);
2852 case SCTP_PRIMARY_ADDR:
2853 /* we allow a "get" operation on this */
2855 struct sctp_setprim *ssp;
2857 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2858 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2861 union sctp_sockstore *addr;
2863 addr = &stcb->asoc.primary_destination->ro._l_addr;
2864 switch (addr->sa.sa_family) {
2868 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2869 in6_sin_2_v4mapsin6(&addr->sin,
2870 (struct sockaddr_in6 *)&ssp->ssp_addr);
2872 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2875 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2881 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2887 SCTP_TCB_UNLOCK(stcb);
2888 *optsize = sizeof(struct sctp_setprim);
2890 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2895 case SCTP_HMAC_IDENT:
2897 struct sctp_hmacalgo *shmac;
2898 sctp_hmaclist_t *hmaclist;
2902 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2904 SCTP_INP_RLOCK(inp);
2905 hmaclist = inp->sctp_ep.local_hmacs;
2906 if (hmaclist == NULL) {
2907 /* no HMACs to return */
2908 *optsize = sizeof(*shmac);
2909 SCTP_INP_RUNLOCK(inp);
2912 /* is there room for all of the hmac ids? */
2913 size = sizeof(*shmac) + (hmaclist->num_algo *
2914 sizeof(shmac->shmac_idents[0]));
2915 if ((size_t)(*optsize) < size) {
2916 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2918 SCTP_INP_RUNLOCK(inp);
2921 /* copy in the list */
2922 shmac->shmac_number_of_idents = hmaclist->num_algo;
2923 for (i = 0; i < hmaclist->num_algo; i++) {
2924 shmac->shmac_idents[i] = hmaclist->hmac[i];
2926 SCTP_INP_RUNLOCK(inp);
2930 case SCTP_AUTH_ACTIVE_KEY:
2932 struct sctp_authkeyid *scact;
2934 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2935 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2938 /* get the active key on the assoc */
2939 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2940 SCTP_TCB_UNLOCK(stcb);
2942 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2943 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2944 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2945 /* get the endpoint active key */
2946 SCTP_INP_RLOCK(inp);
2947 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2948 SCTP_INP_RUNLOCK(inp);
2950 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2955 *optsize = sizeof(struct sctp_authkeyid);
2959 case SCTP_LOCAL_AUTH_CHUNKS:
2961 struct sctp_authchunks *sac;
2962 sctp_auth_chklist_t *chklist = NULL;
2965 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2966 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2969 /* get off the assoc */
2970 chklist = stcb->asoc.local_auth_chunks;
2971 /* is there enough space? */
2972 size = sctp_auth_get_chklist_size(chklist);
2973 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2975 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2977 /* copy in the chunks */
2978 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2979 sac->gauth_number_of_chunks = (uint32_t) size;
2980 *optsize = sizeof(struct sctp_authchunks) + size;
2982 SCTP_TCB_UNLOCK(stcb);
2984 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2985 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2986 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2987 /* get off the endpoint */
2988 SCTP_INP_RLOCK(inp);
2989 chklist = inp->sctp_ep.local_auth_chunks;
2990 /* is there enough space? */
2991 size = sctp_auth_get_chklist_size(chklist);
2992 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2994 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2996 /* copy in the chunks */
2997 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2998 sac->gauth_number_of_chunks = (uint32_t) size;
2999 *optsize = sizeof(struct sctp_authchunks) + size;
3001 SCTP_INP_RUNLOCK(inp);
3003 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3009 case SCTP_PEER_AUTH_CHUNKS:
3011 struct sctp_authchunks *sac;
3012 sctp_auth_chklist_t *chklist = NULL;
3015 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
3016 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
3019 /* get off the assoc */
3020 chklist = stcb->asoc.peer_auth_chunks;
3021 /* is there enough space? */
3022 size = sctp_auth_get_chklist_size(chklist);
3023 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
3025 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3027 /* copy in the chunks */
3028 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
3029 sac->gauth_number_of_chunks = (uint32_t) size;
3030 *optsize = sizeof(struct sctp_authchunks) + size;
3032 SCTP_TCB_UNLOCK(stcb);
3034 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3041 struct sctp_event *event;
3042 uint32_t event_type;
3044 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3045 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3047 switch (event->se_type) {
3048 case SCTP_ASSOC_CHANGE:
3049 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3051 case SCTP_PEER_ADDR_CHANGE:
3052 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3054 case SCTP_REMOTE_ERROR:
3055 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3057 case SCTP_SEND_FAILED:
3058 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3060 case SCTP_SHUTDOWN_EVENT:
3061 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3063 case SCTP_ADAPTATION_INDICATION:
3064 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3066 case SCTP_PARTIAL_DELIVERY_EVENT:
3067 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3069 case SCTP_AUTHENTICATION_EVENT:
3070 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3072 case SCTP_STREAM_RESET_EVENT:
3073 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3075 case SCTP_SENDER_DRY_EVENT:
3076 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3078 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3080 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3083 case SCTP_ASSOC_RESET_EVENT:
3084 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3086 case SCTP_STREAM_CHANGE_EVENT:
3087 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3089 case SCTP_SEND_FAILED_EVENT:
3090 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3094 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3098 if (event_type > 0) {
3100 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3101 SCTP_TCB_UNLOCK(stcb);
3103 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3104 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3105 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3106 SCTP_INP_RLOCK(inp);
3107 event->se_on = sctp_is_feature_on(inp, event_type);
3108 SCTP_INP_RUNLOCK(inp);
3110 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3116 *optsize = sizeof(struct sctp_event);
3120 case SCTP_RECVRCVINFO:
3124 if (*optsize < sizeof(int)) {
3125 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3128 SCTP_INP_RLOCK(inp);
3129 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3130 SCTP_INP_RUNLOCK(inp);
3133 /* return the option value */
3134 *(int *)optval = onoff;
3135 *optsize = sizeof(int);
3139 case SCTP_RECVNXTINFO:
3143 if (*optsize < sizeof(int)) {
3144 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3147 SCTP_INP_RLOCK(inp);
3148 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3149 SCTP_INP_RUNLOCK(inp);
3152 /* return the option value */
3153 *(int *)optval = onoff;
3154 *optsize = sizeof(int);
3158 case SCTP_DEFAULT_SNDINFO:
3160 struct sctp_sndinfo *info;
3162 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3163 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3166 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3167 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3168 info->snd_flags &= 0xfff0;
3169 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3170 info->snd_context = stcb->asoc.def_send.sinfo_context;
3171 SCTP_TCB_UNLOCK(stcb);
3173 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3174 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3175 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3176 SCTP_INP_RLOCK(inp);
3177 info->snd_sid = inp->def_send.sinfo_stream;
3178 info->snd_flags = inp->def_send.sinfo_flags;
3179 info->snd_flags &= 0xfff0;
3180 info->snd_ppid = inp->def_send.sinfo_ppid;
3181 info->snd_context = inp->def_send.sinfo_context;
3182 SCTP_INP_RUNLOCK(inp);
3184 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3189 *optsize = sizeof(struct sctp_sndinfo);
3193 case SCTP_DEFAULT_PRINFO:
3195 struct sctp_default_prinfo *info;
3197 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3198 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3201 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3202 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3203 SCTP_TCB_UNLOCK(stcb);
3205 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3206 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3207 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3208 SCTP_INP_RLOCK(inp);
3209 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3210 info->pr_value = inp->def_send.sinfo_timetolive;
3211 SCTP_INP_RUNLOCK(inp);
3213 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3218 *optsize = sizeof(struct sctp_default_prinfo);
3222 case SCTP_PEER_ADDR_THLDS:
3224 struct sctp_paddrthlds *thlds;
3225 struct sctp_nets *net;
3226 struct sockaddr *addr;
3228 #if defined(INET) && defined(INET6)
3229 struct sockaddr_in sin_store;
3233 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3234 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3236 #if defined(INET) && defined(INET6)
3237 if (thlds->spt_address.ss_family == AF_INET6) {
3238 struct sockaddr_in6 *sin6;
3240 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3241 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3242 in6_sin6_2_sin(&sin_store, sin6);
3243 addr = (struct sockaddr *)&sin_store;
3245 addr = (struct sockaddr *)&thlds->spt_address;
3248 addr = (struct sockaddr *)&thlds->spt_address;
3251 addr = (struct sockaddr *)&thlds->spt_address;
3254 net = sctp_findnet(stcb, addr);
3257 * We increment here since
3258 * sctp_findassociation_ep_addr() wil do a
3259 * decrement if it finds the stcb as long as
3260 * the locked tcb (last argument) is NOT a
3264 SCTP_INP_INCR_REF(inp);
3265 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3267 SCTP_INP_DECR_REF(inp);
3270 if ((stcb != NULL) && (net == NULL)) {
3272 if (addr->sa_family == AF_INET) {
3273 struct sockaddr_in *sin;
3275 sin = (struct sockaddr_in *)addr;
3276 if (sin->sin_addr.s_addr != INADDR_ANY) {
3278 SCTP_TCB_UNLOCK(stcb);
3279 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3285 if (addr->sa_family == AF_INET6) {
3286 struct sockaddr_in6 *sin6;
3288 sin6 = (struct sockaddr_in6 *)addr;
3289 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3291 SCTP_TCB_UNLOCK(stcb);
3292 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3298 error = EAFNOSUPPORT;
3299 SCTP_TCB_UNLOCK(stcb);
3300 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3306 thlds->spt_pathmaxrxt = net->failure_threshold;
3307 thlds->spt_pathpfthld = net->pf_threshold;
3308 thlds->spt_pathcpthld = 0xffff;
3310 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3311 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3312 thlds->spt_pathcpthld = 0xffff;
3314 thlds->spt_assoc_id = sctp_get_associd(stcb);
3315 SCTP_TCB_UNLOCK(stcb);
3317 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3318 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3319 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3320 /* Use endpoint defaults */
3321 SCTP_INP_RLOCK(inp);
3322 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3323 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3324 thlds->spt_pathcpthld = 0xffff;
3325 SCTP_INP_RUNLOCK(inp);
3327 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3332 *optsize = sizeof(struct sctp_paddrthlds);
3336 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3338 struct sctp_udpencaps *encaps;
3339 struct sctp_nets *net;
3340 struct sockaddr *addr;
3342 #if defined(INET) && defined(INET6)
3343 struct sockaddr_in sin_store;
3347 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3348 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3350 #if defined(INET) && defined(INET6)
3351 if (encaps->sue_address.ss_family == AF_INET6) {
3352 struct sockaddr_in6 *sin6;
3354 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3355 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3356 in6_sin6_2_sin(&sin_store, sin6);
3357 addr = (struct sockaddr *)&sin_store;
3359 addr = (struct sockaddr *)&encaps->sue_address;
3362 addr = (struct sockaddr *)&encaps->sue_address;
3365 addr = (struct sockaddr *)&encaps->sue_address;
3368 net = sctp_findnet(stcb, addr);
3371 * We increment here since
3372 * sctp_findassociation_ep_addr() wil do a
3373 * decrement if it finds the stcb as long as
3374 * the locked tcb (last argument) is NOT a
3378 SCTP_INP_INCR_REF(inp);
3379 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3381 SCTP_INP_DECR_REF(inp);
3384 if ((stcb != NULL) && (net == NULL)) {
3386 if (addr->sa_family == AF_INET) {
3387 struct sockaddr_in *sin;
3389 sin = (struct sockaddr_in *)addr;
3390 if (sin->sin_addr.s_addr != INADDR_ANY) {
3392 SCTP_TCB_UNLOCK(stcb);
3393 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3399 if (addr->sa_family == AF_INET6) {
3400 struct sockaddr_in6 *sin6;
3402 sin6 = (struct sockaddr_in6 *)addr;
3403 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3405 SCTP_TCB_UNLOCK(stcb);
3406 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3412 error = EAFNOSUPPORT;
3413 SCTP_TCB_UNLOCK(stcb);
3414 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3420 encaps->sue_port = net->port;
3422 encaps->sue_port = stcb->asoc.port;
3424 SCTP_TCB_UNLOCK(stcb);
3426 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3427 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3428 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3429 SCTP_INP_RLOCK(inp);
3430 encaps->sue_port = inp->sctp_ep.port;
3431 SCTP_INP_RUNLOCK(inp);
3433 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3438 *optsize = sizeof(struct sctp_udpencaps);
3442 case SCTP_ECN_SUPPORTED:
3444 struct sctp_assoc_value *av;
3446 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3447 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3450 av->assoc_value = stcb->asoc.ecn_supported;
3451 SCTP_TCB_UNLOCK(stcb);
3453 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3454 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3455 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3456 SCTP_INP_RLOCK(inp);
3457 av->assoc_value = inp->ecn_supported;
3458 SCTP_INP_RUNLOCK(inp);
3460 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3465 *optsize = sizeof(struct sctp_assoc_value);
3469 case SCTP_PR_SUPPORTED:
3471 struct sctp_assoc_value *av;
3473 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3474 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3477 av->assoc_value = stcb->asoc.prsctp_supported;
3478 SCTP_TCB_UNLOCK(stcb);
3480 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3481 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3482 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3483 SCTP_INP_RLOCK(inp);
3484 av->assoc_value = inp->prsctp_supported;
3485 SCTP_INP_RUNLOCK(inp);
3487 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3492 *optsize = sizeof(struct sctp_assoc_value);
3496 case SCTP_AUTH_SUPPORTED:
3498 struct sctp_assoc_value *av;
3500 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3501 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3504 av->assoc_value = stcb->asoc.auth_supported;
3505 SCTP_TCB_UNLOCK(stcb);
3507 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3508 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3509 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3510 SCTP_INP_RLOCK(inp);
3511 av->assoc_value = inp->auth_supported;
3512 SCTP_INP_RUNLOCK(inp);
3514 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3519 *optsize = sizeof(struct sctp_assoc_value);
3523 case SCTP_ASCONF_SUPPORTED:
3525 struct sctp_assoc_value *av;
3527 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3528 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3531 av->assoc_value = stcb->asoc.asconf_supported;
3532 SCTP_TCB_UNLOCK(stcb);
3534 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3535 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3536 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3537 SCTP_INP_RLOCK(inp);
3538 av->assoc_value = inp->asconf_supported;
3539 SCTP_INP_RUNLOCK(inp);
3541 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3546 *optsize = sizeof(struct sctp_assoc_value);
3550 case SCTP_RECONFIG_SUPPORTED:
3552 struct sctp_assoc_value *av;
3554 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3555 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3558 av->assoc_value = stcb->asoc.reconfig_supported;
3559 SCTP_TCB_UNLOCK(stcb);
3561 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3562 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3563 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3564 SCTP_INP_RLOCK(inp);
3565 av->assoc_value = inp->reconfig_supported;
3566 SCTP_INP_RUNLOCK(inp);
3568 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3573 *optsize = sizeof(struct sctp_assoc_value);
3577 case SCTP_NRSACK_SUPPORTED:
3579 struct sctp_assoc_value *av;
3581 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3582 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3585 av->assoc_value = stcb->asoc.nrsack_supported;
3586 SCTP_TCB_UNLOCK(stcb);
3588 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3589 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3590 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3591 SCTP_INP_RLOCK(inp);
3592 av->assoc_value = inp->nrsack_supported;
3593 SCTP_INP_RUNLOCK(inp);
3595 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3600 *optsize = sizeof(struct sctp_assoc_value);
3604 case SCTP_PKTDROP_SUPPORTED:
3606 struct sctp_assoc_value *av;
3608 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3609 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3612 av->assoc_value = stcb->asoc.pktdrop_supported;
3613 SCTP_TCB_UNLOCK(stcb);
3615 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3616 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3617 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3618 SCTP_INP_RLOCK(inp);
3619 av->assoc_value = inp->pktdrop_supported;
3620 SCTP_INP_RUNLOCK(inp);
3622 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3627 *optsize = sizeof(struct sctp_assoc_value);
3631 case SCTP_ENABLE_STREAM_RESET:
3633 struct sctp_assoc_value *av;
3635 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3636 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3639 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3640 SCTP_TCB_UNLOCK(stcb);
3642 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3643 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3644 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3645 SCTP_INP_RLOCK(inp);
3646 av->assoc_value = (uint32_t) inp->local_strreset_support;
3647 SCTP_INP_RUNLOCK(inp);
3649 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3654 *optsize = sizeof(struct sctp_assoc_value);
3658 case SCTP_PR_STREAM_STATUS:
3660 struct sctp_prstatus *sprstat;
3664 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3665 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3667 sid = sprstat->sprstat_sid;
3668 policy = sprstat->sprstat_policy;
3669 #if defined(SCTP_DETAILED_STR_STATS)
3670 if ((stcb != NULL) &&
3671 (sid < stcb->asoc.streamoutcnt) &&
3672 (policy != SCTP_PR_SCTP_NONE) &&
3673 ((policy <= SCTP_PR_SCTP_MAX) ||
3674 (policy == SCTP_PR_SCTP_ALL))) {
3675 if (policy == SCTP_PR_SCTP_ALL) {
3676 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3677 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3679 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3680 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3683 if ((stcb != NULL) &&
3684 (sid < stcb->asoc.streamoutcnt) &&
3685 (policy == SCTP_PR_SCTP_ALL)) {
3686 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3687 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3689 SCTP_TCB_UNLOCK(stcb);
3690 *optsize = sizeof(struct sctp_prstatus);
3692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3697 case SCTP_PR_ASSOC_STATUS:
3699 struct sctp_prstatus *sprstat;
3702 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3703 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3705 policy = sprstat->sprstat_policy;
3706 if ((stcb != NULL) &&
3707 (policy != SCTP_PR_SCTP_NONE) &&
3708 ((policy <= SCTP_PR_SCTP_MAX) ||
3709 (policy == SCTP_PR_SCTP_ALL))) {
3710 if (policy == SCTP_PR_SCTP_ALL) {
3711 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3712 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3714 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3715 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3717 SCTP_TCB_UNLOCK(stcb);
3718 *optsize = sizeof(struct sctp_prstatus);
3720 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3727 struct sctp_assoc_value *av;
3729 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3730 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3733 av->assoc_value = stcb->asoc.max_cwnd;
3734 SCTP_TCB_UNLOCK(stcb);
3736 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3737 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3738 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3739 SCTP_INP_RLOCK(inp);
3740 av->assoc_value = inp->max_cwnd;
3741 SCTP_INP_RUNLOCK(inp);
3743 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3748 *optsize = sizeof(struct sctp_assoc_value);
3753 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3754 error = ENOPROTOOPT;
3756 } /* end switch (sopt->sopt_name) */
3764 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3769 struct sctp_tcb *stcb = NULL;
3770 struct sctp_inpcb *inp = NULL;
3773 if (optval == NULL) {
3774 SCTP_PRINTF("optval is NULL\n");
3775 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3778 inp = (struct sctp_inpcb *)so->so_pcb;
3780 SCTP_PRINTF("inp is NULL?\n");
3781 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3784 vrf_id = inp->def_vrf_id;
3789 case SCTP_AUTOCLOSE:
3790 case SCTP_AUTO_ASCONF:
3791 case SCTP_EXPLICIT_EOR:
3792 case SCTP_DISABLE_FRAGMENTS:
3793 case SCTP_USE_EXT_RCVINFO:
3794 case SCTP_I_WANT_MAPPED_V4_ADDR:
3795 /* copy in the option value */
3796 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3801 case SCTP_DISABLE_FRAGMENTS:
3802 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3804 case SCTP_AUTO_ASCONF:
3806 * NOTE: we don't really support this flag
3808 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3809 /* only valid for bound all sockets */
3810 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3812 /* forbidden by admin */
3813 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3816 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3818 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3822 case SCTP_EXPLICIT_EOR:
3823 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3825 case SCTP_USE_EXT_RCVINFO:
3826 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3828 case SCTP_I_WANT_MAPPED_V4_ADDR:
3829 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3830 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3832 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3837 set_opt = SCTP_PCB_FLAGS_NODELAY;
3839 case SCTP_AUTOCLOSE:
3840 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3841 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3842 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3845 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3847 * The value is in ticks. Note this does not effect
3848 * old associations, only new ones.
3850 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3853 SCTP_INP_WLOCK(inp);
3855 sctp_feature_on(inp, set_opt);
3857 sctp_feature_off(inp, set_opt);
3859 SCTP_INP_WUNLOCK(inp);
3861 case SCTP_REUSE_PORT:
3863 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3864 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3865 /* Can't set it after we are bound */
3869 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3870 /* Can't do this for a 1-m socket */
3875 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3877 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3880 case SCTP_PARTIAL_DELIVERY_POINT:
3884 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3885 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3886 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3890 inp->partial_delivery_point = *value;
3893 case SCTP_FRAGMENT_INTERLEAVE:
3894 /* not yet until we re-write sctp_recvmsg() */
3898 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3899 if (*level == SCTP_FRAG_LEVEL_2) {
3900 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3901 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3902 } else if (*level == SCTP_FRAG_LEVEL_1) {
3903 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3904 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3905 } else if (*level == SCTP_FRAG_LEVEL_0) {
3906 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3907 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3910 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3915 case SCTP_INTERLEAVING_SUPPORTED:
3917 struct sctp_assoc_value *av;
3919 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3920 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3923 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
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 SCTP_INP_WLOCK(inp);
3931 if (av->assoc_value == 0) {
3932 inp->idata_supported = 0;
3934 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3935 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3936 inp->idata_supported = 1;
3944 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3948 SCTP_INP_WUNLOCK(inp);
3950 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3956 case SCTP_CMT_ON_OFF:
3957 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3958 struct sctp_assoc_value *av;
3960 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3961 if (av->assoc_value > SCTP_CMT_MAX) {
3962 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3966 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3968 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3969 SCTP_TCB_UNLOCK(stcb);
3971 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3972 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3973 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3974 (av->assoc_id == SCTP_ALL_ASSOC)) {
3975 SCTP_INP_WLOCK(inp);
3976 inp->sctp_cmt_on_off = av->assoc_value;
3977 SCTP_INP_WUNLOCK(inp);
3979 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3980 (av->assoc_id == SCTP_ALL_ASSOC)) {
3981 SCTP_INP_RLOCK(inp);
3982 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3983 SCTP_TCB_LOCK(stcb);
3984 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3985 SCTP_TCB_UNLOCK(stcb);
3987 SCTP_INP_RUNLOCK(inp);
3991 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3992 error = ENOPROTOOPT;
3995 case SCTP_PLUGGABLE_CC:
3997 struct sctp_assoc_value *av;
3998 struct sctp_nets *net;
4000 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4001 if ((av->assoc_value != SCTP_CC_RFC2581) &&
4002 (av->assoc_value != SCTP_CC_HSTCP) &&
4003 (av->assoc_value != SCTP_CC_HTCP) &&
4004 (av->assoc_value != SCTP_CC_RTCC)) {
4005 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4009 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4011 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4012 stcb->asoc.congestion_control_module = av->assoc_value;
4013 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4014 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4015 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4018 SCTP_TCB_UNLOCK(stcb);
4020 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4021 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4022 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4023 (av->assoc_id == SCTP_ALL_ASSOC)) {
4024 SCTP_INP_WLOCK(inp);
4025 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
4026 SCTP_INP_WUNLOCK(inp);
4028 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4029 (av->assoc_id == SCTP_ALL_ASSOC)) {
4030 SCTP_INP_RLOCK(inp);
4031 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4032 SCTP_TCB_LOCK(stcb);
4033 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4034 stcb->asoc.congestion_control_module = av->assoc_value;
4035 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4036 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4037 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4040 SCTP_TCB_UNLOCK(stcb);
4042 SCTP_INP_RUNLOCK(inp);
4047 case SCTP_CC_OPTION:
4049 struct sctp_cc_option *cc_opt;
4051 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4052 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4054 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
4055 SCTP_INP_RLOCK(inp);
4056 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4057 SCTP_TCB_LOCK(stcb);
4058 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4059 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4061 SCTP_TCB_UNLOCK(stcb);
4063 SCTP_INP_RUNLOCK(inp);
4068 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4071 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4074 SCTP_TCB_UNLOCK(stcb);
4078 case SCTP_PLUGGABLE_SS:
4080 struct sctp_assoc_value *av;
4082 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4083 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4084 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4085 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4086 (av->assoc_value != SCTP_SS_PRIORITY) &&
4087 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4088 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4089 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4093 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4095 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4096 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4097 stcb->asoc.stream_scheduling_module = av->assoc_value;
4098 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4099 SCTP_TCB_UNLOCK(stcb);
4101 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4102 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4103 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4104 (av->assoc_id == SCTP_ALL_ASSOC)) {
4105 SCTP_INP_WLOCK(inp);
4106 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4107 SCTP_INP_WUNLOCK(inp);
4109 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4110 (av->assoc_id == SCTP_ALL_ASSOC)) {
4111 SCTP_INP_RLOCK(inp);
4112 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4113 SCTP_TCB_LOCK(stcb);
4114 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4115 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4116 stcb->asoc.stream_scheduling_module = av->assoc_value;
4117 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4118 SCTP_TCB_UNLOCK(stcb);
4120 SCTP_INP_RUNLOCK(inp);
4127 struct sctp_stream_value *av;
4129 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4130 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4132 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4133 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4134 av->stream_value) < 0)) {
4135 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4138 SCTP_TCB_UNLOCK(stcb);
4140 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4141 SCTP_INP_RLOCK(inp);
4142 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4143 SCTP_TCB_LOCK(stcb);
4144 if (av->stream_id < stcb->asoc.streamoutcnt) {
4145 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4147 &stcb->asoc.strmout[av->stream_id],
4150 SCTP_TCB_UNLOCK(stcb);
4152 SCTP_INP_RUNLOCK(inp);
4155 * Can't set stream value without
4158 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4164 case SCTP_CLR_STAT_LOG:
4165 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4170 struct sctp_assoc_value *av;
4172 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4173 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4176 stcb->asoc.context = av->assoc_value;
4177 SCTP_TCB_UNLOCK(stcb);
4179 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4180 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4181 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4182 (av->assoc_id == SCTP_ALL_ASSOC)) {
4183 SCTP_INP_WLOCK(inp);
4184 inp->sctp_context = av->assoc_value;
4185 SCTP_INP_WUNLOCK(inp);
4187 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4188 (av->assoc_id == SCTP_ALL_ASSOC)) {
4189 SCTP_INP_RLOCK(inp);
4190 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4191 SCTP_TCB_LOCK(stcb);
4192 stcb->asoc.context = av->assoc_value;
4193 SCTP_TCB_UNLOCK(stcb);
4195 SCTP_INP_RUNLOCK(inp);
4202 uint32_t *default_vrfid;
4204 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4205 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4206 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4210 inp->def_vrf_id = *default_vrfid;
4213 case SCTP_DEL_VRF_ID:
4215 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4219 case SCTP_ADD_VRF_ID:
4221 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4225 case SCTP_DELAYED_SACK:
4227 struct sctp_sack_info *sack;
4229 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4230 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4231 if (sack->sack_delay) {
4232 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4233 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4234 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4235 sack->sack_delay = TICKS_TO_MSEC(1);
4239 if (sack->sack_delay) {
4240 stcb->asoc.delayed_ack = sack->sack_delay;
4242 if (sack->sack_freq) {
4243 stcb->asoc.sack_freq = sack->sack_freq;
4245 SCTP_TCB_UNLOCK(stcb);
4247 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4248 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4249 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4250 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4251 SCTP_INP_WLOCK(inp);
4252 if (sack->sack_delay) {
4253 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4255 if (sack->sack_freq) {
4256 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4258 SCTP_INP_WUNLOCK(inp);
4260 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4261 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4262 SCTP_INP_RLOCK(inp);
4263 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4264 SCTP_TCB_LOCK(stcb);
4265 if (sack->sack_delay) {
4266 stcb->asoc.delayed_ack = sack->sack_delay;
4268 if (sack->sack_freq) {
4269 stcb->asoc.sack_freq = sack->sack_freq;
4271 SCTP_TCB_UNLOCK(stcb);
4273 SCTP_INP_RUNLOCK(inp);
4278 case SCTP_AUTH_CHUNK:
4280 struct sctp_authchunk *sauth;
4282 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4284 SCTP_INP_WLOCK(inp);
4285 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4286 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4289 SCTP_INP_WUNLOCK(inp);
4294 struct sctp_authkey *sca;
4295 struct sctp_keyhead *shared_keys;
4296 sctp_sharedkey_t *shared_key;
4297 sctp_key_t *key = NULL;
4300 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4301 if (sca->sca_keylength == 0) {
4302 size = optsize - sizeof(struct sctp_authkey);
4304 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4305 size = sca->sca_keylength;
4307 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4312 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4315 shared_keys = &stcb->asoc.shared_keys;
4316 /* clear the cached keys for this key id */
4317 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4319 * create the new shared key and
4323 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4325 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4327 SCTP_TCB_UNLOCK(stcb);
4331 shared_key = sctp_alloc_sharedkey();
4332 if (shared_key == NULL) {
4334 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4336 SCTP_TCB_UNLOCK(stcb);
4339 shared_key->key = key;
4340 shared_key->keyid = sca->sca_keynumber;
4341 error = sctp_insert_sharedkey(shared_keys, shared_key);
4342 SCTP_TCB_UNLOCK(stcb);
4344 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4345 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4346 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4347 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4348 SCTP_INP_WLOCK(inp);
4349 shared_keys = &inp->sctp_ep.shared_keys;
4351 * clear the cached keys on all
4352 * assocs for this key id
4354 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4356 * create the new shared key and
4360 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4362 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4364 SCTP_INP_WUNLOCK(inp);
4368 shared_key = sctp_alloc_sharedkey();
4369 if (shared_key == NULL) {
4371 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4373 SCTP_INP_WUNLOCK(inp);
4376 shared_key->key = key;
4377 shared_key->keyid = sca->sca_keynumber;
4378 error = sctp_insert_sharedkey(shared_keys, shared_key);
4379 SCTP_INP_WUNLOCK(inp);
4381 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4382 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4383 SCTP_INP_RLOCK(inp);
4384 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4385 SCTP_TCB_LOCK(stcb);
4386 shared_keys = &stcb->asoc.shared_keys;
4388 * clear the cached keys for
4391 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4393 * create the new shared key
4394 * and insert/replace it
4397 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4399 SCTP_TCB_UNLOCK(stcb);
4403 shared_key = sctp_alloc_sharedkey();
4404 if (shared_key == NULL) {
4406 SCTP_TCB_UNLOCK(stcb);
4409 shared_key->key = key;
4410 shared_key->keyid = sca->sca_keynumber;
4411 error = sctp_insert_sharedkey(shared_keys, shared_key);
4412 SCTP_TCB_UNLOCK(stcb);
4414 SCTP_INP_RUNLOCK(inp);
4419 case SCTP_HMAC_IDENT:
4421 struct sctp_hmacalgo *shmac;
4422 sctp_hmaclist_t *hmaclist;
4426 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4427 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4428 (shmac->shmac_number_of_idents > 0xffff)) {
4429 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4433 hmaclist = sctp_alloc_hmaclist((uint16_t) shmac->shmac_number_of_idents);
4434 if (hmaclist == NULL) {
4435 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4439 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4440 hmacid = shmac->shmac_idents[i];
4441 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4442 /* invalid HMACs were found */ ;
4443 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4445 sctp_free_hmaclist(hmaclist);
4446 goto sctp_set_hmac_done;
4449 for (i = 0; i < hmaclist->num_algo; i++) {
4450 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4451 /* already in list */
4455 if (i == hmaclist->num_algo) {
4456 /* not found in list */
4457 sctp_free_hmaclist(hmaclist);
4458 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4462 /* set it on the endpoint */
4463 SCTP_INP_WLOCK(inp);
4464 if (inp->sctp_ep.local_hmacs)
4465 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4466 inp->sctp_ep.local_hmacs = hmaclist;
4467 SCTP_INP_WUNLOCK(inp);
4471 case SCTP_AUTH_ACTIVE_KEY:
4473 struct sctp_authkeyid *scact;
4475 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4476 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4478 /* set the active key on the right place */
4480 /* set the active key on the assoc */
4481 if (sctp_auth_setactivekey(stcb,
4482 scact->scact_keynumber)) {
4483 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4484 SCTP_FROM_SCTP_USRREQ,
4488 SCTP_TCB_UNLOCK(stcb);
4490 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4491 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4492 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4493 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4494 SCTP_INP_WLOCK(inp);
4495 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4496 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4499 SCTP_INP_WUNLOCK(inp);
4501 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4502 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4503 SCTP_INP_RLOCK(inp);
4504 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4505 SCTP_TCB_LOCK(stcb);
4506 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4507 SCTP_TCB_UNLOCK(stcb);
4509 SCTP_INP_RUNLOCK(inp);
4514 case SCTP_AUTH_DELETE_KEY:
4516 struct sctp_authkeyid *scdel;
4518 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4519 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4521 /* delete the key from the right place */
4523 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4524 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4527 SCTP_TCB_UNLOCK(stcb);
4529 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4530 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4531 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4532 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4533 SCTP_INP_WLOCK(inp);
4534 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4535 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4538 SCTP_INP_WUNLOCK(inp);
4540 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4541 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4542 SCTP_INP_RLOCK(inp);
4543 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4544 SCTP_TCB_LOCK(stcb);
4545 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4546 SCTP_TCB_UNLOCK(stcb);
4548 SCTP_INP_RUNLOCK(inp);
4553 case SCTP_AUTH_DEACTIVATE_KEY:
4555 struct sctp_authkeyid *keyid;
4557 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4558 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4560 /* deactivate the key from the right place */
4562 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4563 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4566 SCTP_TCB_UNLOCK(stcb);
4568 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4569 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4570 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4571 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4572 SCTP_INP_WLOCK(inp);
4573 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4574 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4577 SCTP_INP_WUNLOCK(inp);
4579 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4580 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4581 SCTP_INP_RLOCK(inp);
4582 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4583 SCTP_TCB_LOCK(stcb);
4584 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4585 SCTP_TCB_UNLOCK(stcb);
4587 SCTP_INP_RUNLOCK(inp);
4592 case SCTP_ENABLE_STREAM_RESET:
4594 struct sctp_assoc_value *av;
4596 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4597 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4598 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4602 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4604 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4605 SCTP_TCB_UNLOCK(stcb);
4607 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4608 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4609 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4610 (av->assoc_id == SCTP_ALL_ASSOC)) {
4611 SCTP_INP_WLOCK(inp);
4612 inp->local_strreset_support = (uint8_t) av->assoc_value;
4613 SCTP_INP_WUNLOCK(inp);
4615 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4616 (av->assoc_id == SCTP_ALL_ASSOC)) {
4617 SCTP_INP_RLOCK(inp);
4618 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4619 SCTP_TCB_LOCK(stcb);
4620 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4621 SCTP_TCB_UNLOCK(stcb);
4623 SCTP_INP_RUNLOCK(inp);
4628 case SCTP_RESET_STREAMS:
4630 struct sctp_reset_streams *strrst;
4631 int i, send_out = 0;
4634 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4635 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4637 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4641 if (stcb->asoc.reconfig_supported == 0) {
4643 * Peer does not support the chunk type.
4645 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4647 SCTP_TCB_UNLOCK(stcb);
4650 if (sizeof(struct sctp_reset_streams) +
4651 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4653 SCTP_TCB_UNLOCK(stcb);
4656 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4658 if (stcb->asoc.stream_reset_outstanding) {
4659 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4661 SCTP_TCB_UNLOCK(stcb);
4665 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4668 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4669 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4671 SCTP_TCB_UNLOCK(stcb);
4674 if ((send_in == 0) && (send_out == 0)) {
4675 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4677 SCTP_TCB_UNLOCK(stcb);
4680 for (i = 0; i < strrst->srs_number_streams; i++) {
4682 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4683 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4688 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4689 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4695 SCTP_TCB_UNLOCK(stcb);
4702 if (strrst->srs_number_streams) {
4703 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4704 strm = strrst->srs_stream_list[i];
4705 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4706 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4712 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4713 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4714 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4721 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4722 strrst->srs_stream_list,
4723 send_in, 0, 0, 0, 0, 0);
4725 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4728 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4731 * For outgoing streams don't report any
4732 * problems in sending the request to the
4733 * application. XXX: Double check resetting
4738 SCTP_TCB_UNLOCK(stcb);
4741 case SCTP_ADD_STREAMS:
4743 struct sctp_add_streams *stradd;
4744 uint8_t addstream = 0;
4745 uint16_t add_o_strmcnt = 0;
4746 uint16_t add_i_strmcnt = 0;
4748 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4749 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4751 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4755 if (stcb->asoc.reconfig_supported == 0) {
4757 * Peer does not support the chunk type.
4759 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4761 SCTP_TCB_UNLOCK(stcb);
4764 if (stcb->asoc.stream_reset_outstanding) {
4765 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4767 SCTP_TCB_UNLOCK(stcb);
4770 if ((stradd->sas_outstrms == 0) &&
4771 (stradd->sas_instrms == 0)) {
4775 if (stradd->sas_outstrms) {
4777 /* We allocate here */
4778 add_o_strmcnt = stradd->sas_outstrms;
4779 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4780 /* You can't have more than 64k */
4785 if (stradd->sas_instrms) {
4790 * We allocate inside
4791 * sctp_send_str_reset_req()
4793 add_i_strmcnt = stradd->sas_instrms;
4794 cnt = add_i_strmcnt;
4795 cnt += stcb->asoc.streamincnt;
4796 if (cnt > 0x0000ffff) {
4797 /* You can't have more than 64k */
4801 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4802 /* More than you are allowed */
4807 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4808 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4810 SCTP_TCB_UNLOCK(stcb);
4813 case SCTP_RESET_ASSOC:
4818 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4819 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4821 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4825 if (stcb->asoc.reconfig_supported == 0) {
4827 * Peer does not support the chunk type.
4829 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4831 SCTP_TCB_UNLOCK(stcb);
4834 if (stcb->asoc.stream_reset_outstanding) {
4835 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4837 SCTP_TCB_UNLOCK(stcb);
4841 * Is there any data pending in the send or sent
4844 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4845 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4848 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4849 SCTP_TCB_UNLOCK(stcb);
4852 /* Do any streams have data queued? */
4853 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4854 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4858 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4859 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4860 SCTP_TCB_UNLOCK(stcb);
4863 case SCTP_CONNECT_X:
4864 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4865 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4869 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4871 case SCTP_CONNECT_X_DELAYED:
4872 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4873 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4877 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4879 case SCTP_CONNECT_X_COMPLETE:
4881 struct sockaddr *sa;
4883 /* FIXME MT: check correct? */
4884 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4887 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4888 SCTP_INP_RLOCK(inp);
4889 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4891 SCTP_TCB_LOCK(stcb);
4893 SCTP_INP_RUNLOCK(inp);
4896 * We increment here since
4897 * sctp_findassociation_ep_addr() wil do a
4898 * decrement if it finds the stcb as long as
4899 * the locked tcb (last argument) is NOT a
4902 SCTP_INP_INCR_REF(inp);
4903 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4905 SCTP_INP_DECR_REF(inp);
4910 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4914 if (stcb->asoc.delayed_connection == 1) {
4915 stcb->asoc.delayed_connection = 0;
4916 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4917 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4918 stcb->asoc.primary_destination,
4919 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4920 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4923 * already expired or did not use delayed
4926 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4929 SCTP_TCB_UNLOCK(stcb);
4932 case SCTP_MAX_BURST:
4934 struct sctp_assoc_value *av;
4936 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4937 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4940 stcb->asoc.max_burst = av->assoc_value;
4941 SCTP_TCB_UNLOCK(stcb);
4943 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4944 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4945 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4946 (av->assoc_id == SCTP_ALL_ASSOC)) {
4947 SCTP_INP_WLOCK(inp);
4948 inp->sctp_ep.max_burst = av->assoc_value;
4949 SCTP_INP_WUNLOCK(inp);
4951 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4952 (av->assoc_id == SCTP_ALL_ASSOC)) {
4953 SCTP_INP_RLOCK(inp);
4954 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4955 SCTP_TCB_LOCK(stcb);
4956 stcb->asoc.max_burst = av->assoc_value;
4957 SCTP_TCB_UNLOCK(stcb);
4959 SCTP_INP_RUNLOCK(inp);
4966 struct sctp_assoc_value *av;
4969 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4970 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4972 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4973 ovh = SCTP_MED_OVERHEAD;
4975 ovh = SCTP_MED_V4_OVERHEAD;
4978 if (av->assoc_value) {
4979 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4981 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4983 SCTP_TCB_UNLOCK(stcb);
4985 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4986 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4987 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4988 SCTP_INP_WLOCK(inp);
4990 * FIXME MT: I think this is not in
4991 * tune with the API ID
4993 if (av->assoc_value) {
4994 inp->sctp_frag_point = (av->assoc_value + ovh);
4996 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4998 SCTP_INP_WUNLOCK(inp);
5000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5008 struct sctp_event_subscribe *events;
5010 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
5012 SCTP_INP_WLOCK(inp);
5013 if (events->sctp_data_io_event) {
5014 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5016 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5019 if (events->sctp_association_event) {
5020 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5022 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5025 if (events->sctp_address_event) {
5026 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5028 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5031 if (events->sctp_send_failure_event) {
5032 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5034 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5037 if (events->sctp_peer_error_event) {
5038 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5040 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5043 if (events->sctp_shutdown_event) {
5044 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5046 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5049 if (events->sctp_partial_delivery_event) {
5050 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5052 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5055 if (events->sctp_adaptation_layer_event) {
5056 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5058 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5061 if (events->sctp_authentication_event) {
5062 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5064 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5067 if (events->sctp_sender_dry_event) {
5068 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5070 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5073 if (events->sctp_stream_reset_event) {
5074 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5076 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5078 SCTP_INP_WUNLOCK(inp);
5080 SCTP_INP_RLOCK(inp);
5081 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5082 SCTP_TCB_LOCK(stcb);
5083 if (events->sctp_association_event) {
5084 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5086 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5088 if (events->sctp_address_event) {
5089 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5091 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5093 if (events->sctp_send_failure_event) {
5094 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5096 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5098 if (events->sctp_peer_error_event) {
5099 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5101 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5103 if (events->sctp_shutdown_event) {
5104 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5106 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5108 if (events->sctp_partial_delivery_event) {
5109 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5111 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5113 if (events->sctp_adaptation_layer_event) {
5114 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5116 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5118 if (events->sctp_authentication_event) {
5119 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5121 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5123 if (events->sctp_sender_dry_event) {
5124 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5126 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5128 if (events->sctp_stream_reset_event) {
5129 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5131 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5133 SCTP_TCB_UNLOCK(stcb);
5136 * Send up the sender dry event only for 1-to-1
5139 if (events->sctp_sender_dry_event) {
5140 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5141 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5142 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5144 SCTP_TCB_LOCK(stcb);
5145 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5146 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5147 (stcb->asoc.stream_queue_cnt == 0)) {
5148 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5150 SCTP_TCB_UNLOCK(stcb);
5154 SCTP_INP_RUNLOCK(inp);
5157 case SCTP_ADAPTATION_LAYER:
5159 struct sctp_setadaptation *adap_bits;
5161 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5162 SCTP_INP_WLOCK(inp);
5163 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5164 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5165 SCTP_INP_WUNLOCK(inp);
5169 case SCTP_SET_INITIAL_DBG_SEQ:
5173 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5174 SCTP_INP_WLOCK(inp);
5175 inp->sctp_ep.initial_sequence_debug = *vvv;
5176 SCTP_INP_WUNLOCK(inp);
5180 case SCTP_DEFAULT_SEND_PARAM:
5182 struct sctp_sndrcvinfo *s_info;
5184 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5185 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5188 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5189 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5191 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5194 SCTP_TCB_UNLOCK(stcb);
5196 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5197 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5198 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5199 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5200 SCTP_INP_WLOCK(inp);
5201 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5202 SCTP_INP_WUNLOCK(inp);
5204 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5205 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5206 SCTP_INP_RLOCK(inp);
5207 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5208 SCTP_TCB_LOCK(stcb);
5209 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5210 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5212 SCTP_TCB_UNLOCK(stcb);
5214 SCTP_INP_RUNLOCK(inp);
5219 case SCTP_PEER_ADDR_PARAMS:
5221 struct sctp_paddrparams *paddrp;
5222 struct sctp_nets *net;
5223 struct sockaddr *addr;
5225 #if defined(INET) && defined(INET6)
5226 struct sockaddr_in sin_store;
5230 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5231 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5233 #if defined(INET) && defined(INET6)
5234 if (paddrp->spp_address.ss_family == AF_INET6) {
5235 struct sockaddr_in6 *sin6;
5237 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5238 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5239 in6_sin6_2_sin(&sin_store, sin6);
5240 addr = (struct sockaddr *)&sin_store;
5242 addr = (struct sockaddr *)&paddrp->spp_address;
5245 addr = (struct sockaddr *)&paddrp->spp_address;
5248 addr = (struct sockaddr *)&paddrp->spp_address;
5251 net = sctp_findnet(stcb, addr);
5254 * We increment here since
5255 * sctp_findassociation_ep_addr() wil do a
5256 * decrement if it finds the stcb as long as
5257 * the locked tcb (last argument) is NOT a
5261 SCTP_INP_INCR_REF(inp);
5262 stcb = sctp_findassociation_ep_addr(&inp, addr,
5265 SCTP_INP_DECR_REF(inp);
5268 if ((stcb != NULL) && (net == NULL)) {
5270 if (addr->sa_family == AF_INET) {
5272 struct sockaddr_in *sin;
5274 sin = (struct sockaddr_in *)addr;
5275 if (sin->sin_addr.s_addr != INADDR_ANY) {
5276 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5277 SCTP_TCB_UNLOCK(stcb);
5284 if (addr->sa_family == AF_INET6) {
5285 struct sockaddr_in6 *sin6;
5287 sin6 = (struct sockaddr_in6 *)addr;
5288 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5289 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5290 SCTP_TCB_UNLOCK(stcb);
5297 error = EAFNOSUPPORT;
5298 SCTP_TCB_UNLOCK(stcb);
5299 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5304 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5306 SCTP_TCB_UNLOCK(stcb);
5307 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5310 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5312 SCTP_TCB_UNLOCK(stcb);
5313 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5317 /************************TCB SPECIFIC SET ******************/
5319 /************************NET SPECIFIC SET ******************/
5320 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5321 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5322 !(net->dest_state & SCTP_ADDR_NOHB)) {
5323 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5324 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5326 net->dest_state |= SCTP_ADDR_NOHB;
5328 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5329 if (paddrp->spp_hbinterval) {
5330 net->heart_beat_delay = paddrp->spp_hbinterval;
5331 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5332 net->heart_beat_delay = 0;
5334 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5335 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5336 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5337 net->dest_state &= ~SCTP_ADDR_NOHB;
5339 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5341 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5342 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5343 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5345 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5346 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5347 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5348 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5350 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5351 net->mtu = paddrp->spp_pathmtu;
5352 switch (net->ro._l_addr.sa.sa_family) {
5355 net->mtu += SCTP_MIN_V4_OVERHEAD;
5360 net->mtu += SCTP_MIN_OVERHEAD;
5366 if (net->mtu < stcb->asoc.smallest_mtu) {
5367 sctp_pathmtu_adjustment(stcb, net->mtu);
5370 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5371 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5372 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5374 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5376 if (paddrp->spp_pathmaxrxt) {
5377 if (net->dest_state & SCTP_ADDR_PF) {
5378 if (net->error_count > paddrp->spp_pathmaxrxt) {
5379 net->dest_state &= ~SCTP_ADDR_PF;
5382 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5383 (net->error_count > net->pf_threshold)) {
5384 net->dest_state |= SCTP_ADDR_PF;
5385 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5386 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5387 stcb->sctp_ep, stcb, net,
5388 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5389 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5392 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5393 if (net->error_count > paddrp->spp_pathmaxrxt) {
5394 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5395 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5398 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5399 net->dest_state |= SCTP_ADDR_REACHABLE;
5400 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5403 net->failure_threshold = paddrp->spp_pathmaxrxt;
5405 if (paddrp->spp_flags & SPP_DSCP) {
5406 net->dscp = paddrp->spp_dscp & 0xfc;
5410 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5411 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5412 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5413 net->flowlabel |= 0x80000000;
5418 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5419 if (paddrp->spp_pathmaxrxt != 0) {
5420 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5421 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5422 if (net->dest_state & SCTP_ADDR_PF) {
5423 if (net->error_count > paddrp->spp_pathmaxrxt) {
5424 net->dest_state &= ~SCTP_ADDR_PF;
5427 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5428 (net->error_count > net->pf_threshold)) {
5429 net->dest_state |= SCTP_ADDR_PF;
5430 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5431 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5432 stcb->sctp_ep, stcb, net,
5433 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5434 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5437 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5438 if (net->error_count > paddrp->spp_pathmaxrxt) {
5439 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5440 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5443 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5444 net->dest_state |= SCTP_ADDR_REACHABLE;
5445 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5448 net->failure_threshold = paddrp->spp_pathmaxrxt;
5451 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5452 if (paddrp->spp_hbinterval != 0) {
5453 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5454 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5455 stcb->asoc.heart_beat_delay = 0;
5457 /* Turn back on the timer */
5458 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5459 if (paddrp->spp_hbinterval != 0) {
5460 net->heart_beat_delay = paddrp->spp_hbinterval;
5461 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5462 net->heart_beat_delay = 0;
5464 if (net->dest_state & SCTP_ADDR_NOHB) {
5465 net->dest_state &= ~SCTP_ADDR_NOHB;
5467 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5468 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5469 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5471 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5473 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5474 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5475 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5476 net->dest_state |= SCTP_ADDR_NOHB;
5477 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5478 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5480 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5484 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5486 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5487 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5488 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5489 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5490 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5492 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5493 net->mtu = paddrp->spp_pathmtu;
5494 switch (net->ro._l_addr.sa.sa_family) {
5497 net->mtu += SCTP_MIN_V4_OVERHEAD;
5502 net->mtu += SCTP_MIN_OVERHEAD;
5508 if (net->mtu < stcb->asoc.smallest_mtu) {
5509 sctp_pathmtu_adjustment(stcb, net->mtu);
5512 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5514 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5515 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5516 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5517 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5519 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5521 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5523 if (paddrp->spp_flags & SPP_DSCP) {
5524 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5525 net->dscp = paddrp->spp_dscp & 0xfc;
5528 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5529 stcb->asoc.default_dscp |= 0x01;
5532 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5533 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5534 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5535 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5536 net->flowlabel |= 0x80000000;
5539 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5540 stcb->asoc.default_flowlabel |= 0x80000000;
5544 SCTP_TCB_UNLOCK(stcb);
5546 /************************NO TCB, SET TO default stuff ******************/
5547 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5548 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5549 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5550 SCTP_INP_WLOCK(inp);
5552 * For the TOS/FLOWLABEL stuff you
5553 * set it with the options on the
5556 if (paddrp->spp_pathmaxrxt != 0) {
5557 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5559 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5560 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5561 else if (paddrp->spp_hbinterval != 0) {
5562 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5563 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5564 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5566 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5567 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5568 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5569 } else if (paddrp->spp_hbinterval) {
5570 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5572 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5573 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5574 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5576 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5577 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5578 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5579 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5581 if (paddrp->spp_flags & SPP_DSCP) {
5582 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5583 inp->sctp_ep.default_dscp |= 0x01;
5586 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5587 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5588 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5589 inp->sctp_ep.default_flowlabel |= 0x80000000;
5593 SCTP_INP_WUNLOCK(inp);
5595 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5603 struct sctp_rtoinfo *srto;
5604 uint32_t new_init, new_min, new_max;
5606 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5607 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5610 if (srto->srto_initial)
5611 new_init = srto->srto_initial;
5613 new_init = stcb->asoc.initial_rto;
5615 new_max = srto->srto_max;
5617 new_max = stcb->asoc.maxrto;
5619 new_min = srto->srto_min;
5621 new_min = stcb->asoc.minrto;
5622 if ((new_min <= new_init) && (new_init <= new_max)) {
5623 stcb->asoc.initial_rto = new_init;
5624 stcb->asoc.maxrto = new_max;
5625 stcb->asoc.minrto = new_min;
5627 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5630 SCTP_TCB_UNLOCK(stcb);
5632 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5633 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5634 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5635 SCTP_INP_WLOCK(inp);
5636 if (srto->srto_initial)
5637 new_init = srto->srto_initial;
5639 new_init = inp->sctp_ep.initial_rto;
5641 new_max = srto->srto_max;
5643 new_max = inp->sctp_ep.sctp_maxrto;
5645 new_min = srto->srto_min;
5647 new_min = inp->sctp_ep.sctp_minrto;
5648 if ((new_min <= new_init) && (new_init <= new_max)) {
5649 inp->sctp_ep.initial_rto = new_init;
5650 inp->sctp_ep.sctp_maxrto = new_max;
5651 inp->sctp_ep.sctp_minrto = new_min;
5653 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5656 SCTP_INP_WUNLOCK(inp);
5658 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5664 case SCTP_ASSOCINFO:
5666 struct sctp_assocparams *sasoc;
5668 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5669 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5670 if (sasoc->sasoc_cookie_life) {
5671 /* boundary check the cookie life */
5672 if (sasoc->sasoc_cookie_life < 1000)
5673 sasoc->sasoc_cookie_life = 1000;
5674 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5675 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5679 if (sasoc->sasoc_asocmaxrxt)
5680 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5681 if (sasoc->sasoc_cookie_life) {
5682 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5684 SCTP_TCB_UNLOCK(stcb);
5686 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5687 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5688 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5689 SCTP_INP_WLOCK(inp);
5690 if (sasoc->sasoc_asocmaxrxt)
5691 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5692 if (sasoc->sasoc_cookie_life) {
5693 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5695 SCTP_INP_WUNLOCK(inp);
5697 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5705 struct sctp_initmsg *sinit;
5707 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5708 SCTP_INP_WLOCK(inp);
5709 if (sinit->sinit_num_ostreams)
5710 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5712 if (sinit->sinit_max_instreams)
5713 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5715 if (sinit->sinit_max_attempts)
5716 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5718 if (sinit->sinit_max_init_timeo)
5719 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5720 SCTP_INP_WUNLOCK(inp);
5723 case SCTP_PRIMARY_ADDR:
5725 struct sctp_setprim *spa;
5726 struct sctp_nets *net;
5727 struct sockaddr *addr;
5729 #if defined(INET) && defined(INET6)
5730 struct sockaddr_in sin_store;
5734 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5735 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5737 #if defined(INET) && defined(INET6)
5738 if (spa->ssp_addr.ss_family == AF_INET6) {
5739 struct sockaddr_in6 *sin6;
5741 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5742 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5743 in6_sin6_2_sin(&sin_store, sin6);
5744 addr = (struct sockaddr *)&sin_store;
5746 addr = (struct sockaddr *)&spa->ssp_addr;
5749 addr = (struct sockaddr *)&spa->ssp_addr;
5752 addr = (struct sockaddr *)&spa->ssp_addr;
5755 net = sctp_findnet(stcb, addr);
5758 * We increment here since
5759 * sctp_findassociation_ep_addr() wil do a
5760 * decrement if it finds the stcb as long as
5761 * the locked tcb (last argument) is NOT a
5765 SCTP_INP_INCR_REF(inp);
5766 stcb = sctp_findassociation_ep_addr(&inp, addr,
5769 SCTP_INP_DECR_REF(inp);
5773 if ((stcb != NULL) && (net != NULL)) {
5774 if (net != stcb->asoc.primary_destination) {
5775 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5776 /* Ok we need to set it */
5777 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5778 if ((stcb->asoc.alternate) &&
5779 (!(net->dest_state & SCTP_ADDR_PF)) &&
5780 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5781 sctp_free_remote_addr(stcb->asoc.alternate);
5782 stcb->asoc.alternate = NULL;
5785 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5789 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5794 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5798 SCTP_TCB_UNLOCK(stcb);
5802 case SCTP_SET_DYNAMIC_PRIMARY:
5804 union sctp_sockstore *ss;
5806 error = priv_check(curthread,
5807 PRIV_NETINET_RESERVEDPORT);
5811 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5812 /* SUPER USER CHECK? */
5813 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5816 case SCTP_SET_PEER_PRIMARY_ADDR:
5818 struct sctp_setpeerprim *sspp;
5819 struct sockaddr *addr;
5821 #if defined(INET) && defined(INET6)
5822 struct sockaddr_in sin_store;
5826 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5827 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5829 struct sctp_ifa *ifa;
5831 #if defined(INET) && defined(INET6)
5832 if (sspp->sspp_addr.ss_family == AF_INET6) {
5833 struct sockaddr_in6 *sin6;
5835 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5836 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5837 in6_sin6_2_sin(&sin_store, sin6);
5838 addr = (struct sockaddr *)&sin_store;
5840 addr = (struct sockaddr *)&sspp->sspp_addr;
5843 addr = (struct sockaddr *)&sspp->sspp_addr;
5846 addr = (struct sockaddr *)&sspp->sspp_addr;
5848 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5850 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5854 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5856 * Must validate the ifa found is in
5859 struct sctp_laddr *laddr;
5862 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5863 if (laddr->ifa == NULL) {
5864 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5868 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5869 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5872 if (laddr->ifa == ifa) {
5878 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5883 switch (addr->sa_family) {
5887 struct sockaddr_in *sin;
5889 sin = (struct sockaddr_in *)addr;
5890 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5891 &sin->sin_addr) != 0) {
5892 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5902 struct sockaddr_in6 *sin6;
5904 sin6 = (struct sockaddr_in6 *)addr;
5905 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5906 &sin6->sin6_addr) != 0) {
5907 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5915 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5920 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5924 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5926 SCTP_TCB_UNLOCK(stcb);
5928 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5933 case SCTP_BINDX_ADD_ADDR:
5935 struct sctp_getaddresses *addrs;
5938 td = (struct thread *)p;
5939 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5942 if (addrs->addr->sa_family == AF_INET) {
5943 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5944 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5948 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5949 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5955 if (addrs->addr->sa_family == AF_INET6) {
5956 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5957 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5961 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5962 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5963 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5969 error = EAFNOSUPPORT;
5972 sctp_bindx_add_address(so, inp, addrs->addr,
5973 addrs->sget_assoc_id, vrf_id,
5977 case SCTP_BINDX_REM_ADDR:
5979 struct sctp_getaddresses *addrs;
5982 td = (struct thread *)p;
5984 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5986 if (addrs->addr->sa_family == AF_INET) {
5987 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5988 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5992 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5993 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5999 if (addrs->addr->sa_family == AF_INET6) {
6000 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
6001 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6006 (error = prison_local_ip6(td->td_ucred,
6007 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
6008 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6009 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6015 error = EAFNOSUPPORT;
6018 sctp_bindx_delete_address(inp, addrs->addr,
6019 addrs->sget_assoc_id, vrf_id,
6025 struct sctp_event *event;
6026 uint32_t event_type;
6028 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6029 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6030 switch (event->se_type) {
6031 case SCTP_ASSOC_CHANGE:
6032 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6034 case SCTP_PEER_ADDR_CHANGE:
6035 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6037 case SCTP_REMOTE_ERROR:
6038 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6040 case SCTP_SEND_FAILED:
6041 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6043 case SCTP_SHUTDOWN_EVENT:
6044 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6046 case SCTP_ADAPTATION_INDICATION:
6047 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6049 case SCTP_PARTIAL_DELIVERY_EVENT:
6050 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6052 case SCTP_AUTHENTICATION_EVENT:
6053 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6055 case SCTP_STREAM_RESET_EVENT:
6056 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6058 case SCTP_SENDER_DRY_EVENT:
6059 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6061 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6063 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6066 case SCTP_ASSOC_RESET_EVENT:
6067 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6069 case SCTP_STREAM_CHANGE_EVENT:
6070 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6072 case SCTP_SEND_FAILED_EVENT:
6073 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6077 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6081 if (event_type > 0) {
6084 sctp_stcb_feature_on(inp, stcb, event_type);
6085 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6086 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6087 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6088 (stcb->asoc.stream_queue_cnt == 0)) {
6089 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6093 sctp_stcb_feature_off(inp, stcb, event_type);
6095 SCTP_TCB_UNLOCK(stcb);
6098 * We don't want to send up a storm
6099 * of events, so return an error for
6102 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6103 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6104 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6105 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6106 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6107 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6111 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6112 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6113 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6114 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6115 SCTP_INP_WLOCK(inp);
6117 sctp_feature_on(inp, event_type);
6119 sctp_feature_off(inp, event_type);
6121 SCTP_INP_WUNLOCK(inp);
6123 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6124 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6125 SCTP_INP_RLOCK(inp);
6126 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6127 SCTP_TCB_LOCK(stcb);
6129 sctp_stcb_feature_on(inp, stcb, event_type);
6131 sctp_stcb_feature_off(inp, stcb, event_type);
6133 SCTP_TCB_UNLOCK(stcb);
6135 SCTP_INP_RUNLOCK(inp);
6141 case SCTP_RECVRCVINFO:
6145 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6146 SCTP_INP_WLOCK(inp);
6148 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6150 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6152 SCTP_INP_WUNLOCK(inp);
6155 case SCTP_RECVNXTINFO:
6159 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6160 SCTP_INP_WLOCK(inp);
6162 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6164 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6166 SCTP_INP_WUNLOCK(inp);
6169 case SCTP_DEFAULT_SNDINFO:
6171 struct sctp_sndinfo *info;
6174 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6175 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6178 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6179 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6180 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6181 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6182 stcb->asoc.def_send.sinfo_flags |= policy;
6183 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6184 stcb->asoc.def_send.sinfo_context = info->snd_context;
6186 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6189 SCTP_TCB_UNLOCK(stcb);
6191 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6192 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6193 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6194 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6195 SCTP_INP_WLOCK(inp);
6196 inp->def_send.sinfo_stream = info->snd_sid;
6197 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6198 inp->def_send.sinfo_flags = info->snd_flags;
6199 inp->def_send.sinfo_flags |= policy;
6200 inp->def_send.sinfo_ppid = info->snd_ppid;
6201 inp->def_send.sinfo_context = info->snd_context;
6202 SCTP_INP_WUNLOCK(inp);
6204 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6205 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6206 SCTP_INP_RLOCK(inp);
6207 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6208 SCTP_TCB_LOCK(stcb);
6209 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6210 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6211 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6212 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6213 stcb->asoc.def_send.sinfo_flags |= policy;
6214 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6215 stcb->asoc.def_send.sinfo_context = info->snd_context;
6217 SCTP_TCB_UNLOCK(stcb);
6219 SCTP_INP_RUNLOCK(inp);
6224 case SCTP_DEFAULT_PRINFO:
6226 struct sctp_default_prinfo *info;
6228 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6229 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6231 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6232 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6237 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6238 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6239 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6240 SCTP_TCB_UNLOCK(stcb);
6242 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6243 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6244 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6245 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6246 SCTP_INP_WLOCK(inp);
6247 inp->def_send.sinfo_flags &= 0xfff0;
6248 inp->def_send.sinfo_flags |= info->pr_policy;
6249 inp->def_send.sinfo_timetolive = info->pr_value;
6250 SCTP_INP_WUNLOCK(inp);
6252 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6253 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6254 SCTP_INP_RLOCK(inp);
6255 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6256 SCTP_TCB_LOCK(stcb);
6257 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6258 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6259 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6260 SCTP_TCB_UNLOCK(stcb);
6262 SCTP_INP_RUNLOCK(inp);
6267 case SCTP_PEER_ADDR_THLDS:
6268 /* Applies to the specific association */
6270 struct sctp_paddrthlds *thlds;
6271 struct sctp_nets *net;
6272 struct sockaddr *addr;
6274 #if defined(INET) && defined(INET6)
6275 struct sockaddr_in sin_store;
6279 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6280 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6282 #if defined(INET) && defined(INET6)
6283 if (thlds->spt_address.ss_family == AF_INET6) {
6284 struct sockaddr_in6 *sin6;
6286 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6287 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6288 in6_sin6_2_sin(&sin_store, sin6);
6289 addr = (struct sockaddr *)&sin_store;
6291 addr = (struct sockaddr *)&thlds->spt_address;
6294 addr = (struct sockaddr *)&thlds->spt_address;
6297 addr = (struct sockaddr *)&thlds->spt_address;
6300 net = sctp_findnet(stcb, addr);
6303 * We increment here since
6304 * sctp_findassociation_ep_addr() wil do a
6305 * decrement if it finds the stcb as long as
6306 * the locked tcb (last argument) is NOT a
6310 SCTP_INP_INCR_REF(inp);
6311 stcb = sctp_findassociation_ep_addr(&inp, addr,
6314 SCTP_INP_DECR_REF(inp);
6317 if ((stcb != NULL) && (net == NULL)) {
6319 if (addr->sa_family == AF_INET) {
6321 struct sockaddr_in *sin;
6323 sin = (struct sockaddr_in *)addr;
6324 if (sin->sin_addr.s_addr != INADDR_ANY) {
6325 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6326 SCTP_TCB_UNLOCK(stcb);
6333 if (addr->sa_family == AF_INET6) {
6334 struct sockaddr_in6 *sin6;
6336 sin6 = (struct sockaddr_in6 *)addr;
6337 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6338 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6339 SCTP_TCB_UNLOCK(stcb);
6346 error = EAFNOSUPPORT;
6347 SCTP_TCB_UNLOCK(stcb);
6348 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6352 if (thlds->spt_pathcpthld != 0xffff) {
6354 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6359 net->failure_threshold = thlds->spt_pathmaxrxt;
6360 net->pf_threshold = thlds->spt_pathpfthld;
6361 if (net->dest_state & SCTP_ADDR_PF) {
6362 if ((net->error_count > net->failure_threshold) ||
6363 (net->error_count <= net->pf_threshold)) {
6364 net->dest_state &= ~SCTP_ADDR_PF;
6367 if ((net->error_count > net->pf_threshold) &&
6368 (net->error_count <= net->failure_threshold)) {
6369 net->dest_state |= SCTP_ADDR_PF;
6370 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6371 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6372 stcb->sctp_ep, stcb, net,
6373 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6374 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6377 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6378 if (net->error_count > net->failure_threshold) {
6379 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6380 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6383 if (net->error_count <= net->failure_threshold) {
6384 net->dest_state |= SCTP_ADDR_REACHABLE;
6385 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6389 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6390 net->failure_threshold = thlds->spt_pathmaxrxt;
6391 net->pf_threshold = thlds->spt_pathpfthld;
6392 if (net->dest_state & SCTP_ADDR_PF) {
6393 if ((net->error_count > net->failure_threshold) ||
6394 (net->error_count <= net->pf_threshold)) {
6395 net->dest_state &= ~SCTP_ADDR_PF;
6398 if ((net->error_count > net->pf_threshold) &&
6399 (net->error_count <= net->failure_threshold)) {
6400 net->dest_state |= SCTP_ADDR_PF;
6401 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6402 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6403 stcb->sctp_ep, stcb, net,
6404 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6405 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6408 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6409 if (net->error_count > net->failure_threshold) {
6410 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6411 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6414 if (net->error_count <= net->failure_threshold) {
6415 net->dest_state |= SCTP_ADDR_REACHABLE;
6416 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6420 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6421 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6423 SCTP_TCB_UNLOCK(stcb);
6425 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6426 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6427 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6428 SCTP_INP_WLOCK(inp);
6429 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6430 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6431 SCTP_INP_WUNLOCK(inp);
6433 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6439 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6441 struct sctp_udpencaps *encaps;
6442 struct sctp_nets *net;
6443 struct sockaddr *addr;
6445 #if defined(INET) && defined(INET6)
6446 struct sockaddr_in sin_store;
6450 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6451 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6453 #if defined(INET) && defined(INET6)
6454 if (encaps->sue_address.ss_family == AF_INET6) {
6455 struct sockaddr_in6 *sin6;
6457 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6458 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6459 in6_sin6_2_sin(&sin_store, sin6);
6460 addr = (struct sockaddr *)&sin_store;
6462 addr = (struct sockaddr *)&encaps->sue_address;
6465 addr = (struct sockaddr *)&encaps->sue_address;
6468 addr = (struct sockaddr *)&encaps->sue_address;
6471 net = sctp_findnet(stcb, addr);
6474 * We increment here since
6475 * sctp_findassociation_ep_addr() wil do a
6476 * decrement if it finds the stcb as long as
6477 * the locked tcb (last argument) is NOT a
6481 SCTP_INP_INCR_REF(inp);
6482 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6484 SCTP_INP_DECR_REF(inp);
6487 if ((stcb != NULL) && (net == NULL)) {
6489 if (addr->sa_family == AF_INET) {
6491 struct sockaddr_in *sin;
6493 sin = (struct sockaddr_in *)addr;
6494 if (sin->sin_addr.s_addr != INADDR_ANY) {
6495 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6496 SCTP_TCB_UNLOCK(stcb);
6503 if (addr->sa_family == AF_INET6) {
6504 struct sockaddr_in6 *sin6;
6506 sin6 = (struct sockaddr_in6 *)addr;
6507 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6508 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6509 SCTP_TCB_UNLOCK(stcb);
6516 error = EAFNOSUPPORT;
6517 SCTP_TCB_UNLOCK(stcb);
6518 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6524 net->port = encaps->sue_port;
6526 stcb->asoc.port = encaps->sue_port;
6528 SCTP_TCB_UNLOCK(stcb);
6530 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6531 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6532 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6533 SCTP_INP_WLOCK(inp);
6534 inp->sctp_ep.port = encaps->sue_port;
6535 SCTP_INP_WUNLOCK(inp);
6537 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6543 case SCTP_ECN_SUPPORTED:
6545 struct sctp_assoc_value *av;
6547 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6548 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6551 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6553 SCTP_TCB_UNLOCK(stcb);
6555 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6556 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6557 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6558 SCTP_INP_WLOCK(inp);
6559 if (av->assoc_value == 0) {
6560 inp->ecn_supported = 0;
6562 inp->ecn_supported = 1;
6564 SCTP_INP_WUNLOCK(inp);
6566 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6572 case SCTP_PR_SUPPORTED:
6574 struct sctp_assoc_value *av;
6576 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6577 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6580 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6582 SCTP_TCB_UNLOCK(stcb);
6584 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6585 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6586 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6587 SCTP_INP_WLOCK(inp);
6588 if (av->assoc_value == 0) {
6589 inp->prsctp_supported = 0;
6591 inp->prsctp_supported = 1;
6593 SCTP_INP_WUNLOCK(inp);
6595 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6601 case SCTP_AUTH_SUPPORTED:
6603 struct sctp_assoc_value *av;
6605 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6606 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6609 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6611 SCTP_TCB_UNLOCK(stcb);
6613 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6614 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6615 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6616 if ((av->assoc_value == 0) &&
6617 (inp->asconf_supported == 1)) {
6619 * AUTH is required for
6622 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6625 SCTP_INP_WLOCK(inp);
6626 if (av->assoc_value == 0) {
6627 inp->auth_supported = 0;
6629 inp->auth_supported = 1;
6631 SCTP_INP_WUNLOCK(inp);
6634 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6640 case SCTP_ASCONF_SUPPORTED:
6642 struct sctp_assoc_value *av;
6644 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6645 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6648 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6650 SCTP_TCB_UNLOCK(stcb);
6652 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6653 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6654 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6655 if ((av->assoc_value != 0) &&
6656 (inp->auth_supported == 0)) {
6658 * AUTH is required for
6661 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6664 SCTP_INP_WLOCK(inp);
6665 if (av->assoc_value == 0) {
6666 inp->asconf_supported = 0;
6667 sctp_auth_delete_chunk(SCTP_ASCONF,
6668 inp->sctp_ep.local_auth_chunks);
6669 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6670 inp->sctp_ep.local_auth_chunks);
6672 inp->asconf_supported = 1;
6673 sctp_auth_add_chunk(SCTP_ASCONF,
6674 inp->sctp_ep.local_auth_chunks);
6675 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6676 inp->sctp_ep.local_auth_chunks);
6678 SCTP_INP_WUNLOCK(inp);
6681 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6687 case SCTP_RECONFIG_SUPPORTED:
6689 struct sctp_assoc_value *av;
6691 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6692 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6695 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6697 SCTP_TCB_UNLOCK(stcb);
6699 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6700 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6701 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6702 SCTP_INP_WLOCK(inp);
6703 if (av->assoc_value == 0) {
6704 inp->reconfig_supported = 0;
6706 inp->reconfig_supported = 1;
6708 SCTP_INP_WUNLOCK(inp);
6710 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6716 case SCTP_NRSACK_SUPPORTED:
6718 struct sctp_assoc_value *av;
6720 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6721 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6724 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6726 SCTP_TCB_UNLOCK(stcb);
6728 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6729 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6730 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6731 SCTP_INP_WLOCK(inp);
6732 if (av->assoc_value == 0) {
6733 inp->nrsack_supported = 0;
6735 inp->nrsack_supported = 1;
6737 SCTP_INP_WUNLOCK(inp);
6739 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6745 case SCTP_PKTDROP_SUPPORTED:
6747 struct sctp_assoc_value *av;
6749 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6750 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6753 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6755 SCTP_TCB_UNLOCK(stcb);
6757 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6758 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6759 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6760 SCTP_INP_WLOCK(inp);
6761 if (av->assoc_value == 0) {
6762 inp->pktdrop_supported = 0;
6764 inp->pktdrop_supported = 1;
6766 SCTP_INP_WUNLOCK(inp);
6768 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6776 struct sctp_assoc_value *av;
6777 struct sctp_nets *net;
6779 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6780 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6783 stcb->asoc.max_cwnd = av->assoc_value;
6784 if (stcb->asoc.max_cwnd > 0) {
6785 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6786 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6787 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6788 net->cwnd = stcb->asoc.max_cwnd;
6789 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6790 net->cwnd = net->mtu - sizeof(struct sctphdr);
6795 SCTP_TCB_UNLOCK(stcb);
6797 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6798 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6799 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6800 SCTP_INP_WLOCK(inp);
6801 inp->max_cwnd = av->assoc_value;
6802 SCTP_INP_WUNLOCK(inp);
6804 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6811 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6812 error = ENOPROTOOPT;
6814 } /* end switch (opt) */
6819 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6821 void *optval = NULL;
6825 struct sctp_inpcb *inp;
6827 if ((sopt->sopt_level == SOL_SOCKET) &&
6828 (sopt->sopt_name == SO_SETFIB)) {
6829 inp = (struct sctp_inpcb *)so->so_pcb;
6831 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6834 SCTP_INP_WLOCK(inp);
6835 inp->fibnum = so->so_fibnum;
6836 SCTP_INP_WUNLOCK(inp);
6839 if (sopt->sopt_level != IPPROTO_SCTP) {
6840 /* wrong proto level... send back up to IP */
6842 if (INP_CHECK_SOCKAF(so, AF_INET6))
6843 error = ip6_ctloutput(so, sopt);
6845 #if defined(INET) && defined(INET6)
6849 error = ip_ctloutput(so, sopt);
6853 optsize = sopt->sopt_valsize;
6855 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6856 if (optval == NULL) {
6857 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6860 error = sooptcopyin(sopt, optval, optsize, optsize);
6862 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6866 p = (void *)sopt->sopt_td;
6867 if (sopt->sopt_dir == SOPT_SET) {
6868 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6869 } else if (sopt->sopt_dir == SOPT_GET) {
6870 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6872 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6875 if ((error == 0) && (optval != NULL)) {
6876 error = sooptcopyout(sopt, optval, optsize);
6877 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6878 } else if (optval != NULL) {
6879 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6887 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6890 int create_lock_on = 0;
6892 struct sctp_inpcb *inp;
6893 struct sctp_tcb *stcb = NULL;
6895 inp = (struct sctp_inpcb *)so->so_pcb;
6897 /* I made the same as TCP since we are not setup? */
6898 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6899 return (ECONNRESET);
6902 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6905 switch (addr->sa_family) {
6909 struct sockaddr_in6 *sin6p;
6911 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6912 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6915 sin6p = (struct sockaddr_in6 *)addr;
6916 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6917 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6926 struct sockaddr_in *sinp;
6928 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6929 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6932 sinp = (struct sockaddr_in *)addr;
6933 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6934 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6941 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6942 return (EAFNOSUPPORT);
6944 SCTP_INP_INCR_REF(inp);
6945 SCTP_ASOC_CREATE_LOCK(inp);
6949 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6950 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6951 /* Should I really unlock ? */
6952 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6957 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6958 (addr->sa_family == AF_INET6)) {
6959 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6964 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6965 SCTP_PCB_FLAGS_UNBOUND) {
6966 /* Bind a ephemeral port */
6967 error = sctp_inpcb_bind(so, NULL, NULL, p);
6972 /* Now do we connect? */
6973 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6974 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6975 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6979 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6980 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6981 /* We are already connected AND the TCP model */
6982 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6986 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6987 SCTP_INP_RLOCK(inp);
6988 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6989 SCTP_INP_RUNLOCK(inp);
6992 * We increment here since sctp_findassociation_ep_addr()
6993 * will do a decrement if it finds the stcb as long as the
6994 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6996 SCTP_INP_INCR_REF(inp);
6997 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6999 SCTP_INP_DECR_REF(inp);
7001 SCTP_TCB_UNLOCK(stcb);
7005 /* Already have or am bring up an association */
7006 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7010 vrf_id = inp->def_vrf_id;
7011 /* We are GOOD to go */
7012 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
7013 inp->sctp_ep.pre_open_stream_count,
7014 inp->sctp_ep.port, p);
7016 /* Gak! no memory */
7019 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
7020 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
7021 /* Set the connected flag so we can queue data */
7024 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
7025 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7027 /* initialize authentication parameters for the assoc */
7028 sctp_initialize_auth_params(inp, stcb);
7030 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7031 SCTP_TCB_UNLOCK(stcb);
7033 if (create_lock_on) {
7034 SCTP_ASOC_CREATE_UNLOCK(inp);
7036 SCTP_INP_DECR_REF(inp);
7043 sctp_listen(struct socket *so, int backlog, struct thread *p)
7046 * Note this module depends on the protocol processing being called
7047 * AFTER any socket level flags and backlog are applied to the
7048 * socket. The traditional way that the socket flags are applied is
7049 * AFTER protocol processing. We have made a change to the
7050 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7051 * place if the socket API for SCTP is to work properly.
7055 struct sctp_inpcb *inp;
7057 inp = (struct sctp_inpcb *)so->so_pcb;
7059 /* I made the same as TCP since we are not setup? */
7060 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7061 return (ECONNRESET);
7063 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7064 /* See if we have a listener */
7065 struct sctp_inpcb *tinp;
7066 union sctp_sockstore store;
7068 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7070 struct sctp_laddr *laddr;
7072 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7073 memcpy(&store, &laddr->ifa->address, sizeof(store));
7074 switch (store.sa.sa_family) {
7077 store.sin.sin_port = inp->sctp_lport;
7082 store.sin6.sin6_port = inp->sctp_lport;
7088 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7089 if (tinp && (tinp != inp) &&
7090 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7091 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7092 (tinp->sctp_socket->so_qlimit)) {
7094 * we have a listener already and
7097 SCTP_INP_DECR_REF(tinp);
7098 return (EADDRINUSE);
7100 SCTP_INP_DECR_REF(tinp);
7104 /* Setup a local addr bound all */
7105 memset(&store, 0, sizeof(store));
7107 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7108 store.sa.sa_family = AF_INET6;
7109 store.sa.sa_len = sizeof(struct sockaddr_in6);
7113 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7114 store.sa.sa_family = AF_INET;
7115 store.sa.sa_len = sizeof(struct sockaddr_in);
7118 switch (store.sa.sa_family) {
7121 store.sin.sin_port = inp->sctp_lport;
7126 store.sin6.sin6_port = inp->sctp_lport;
7132 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7133 if (tinp && (tinp != inp) &&
7134 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7135 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7136 (tinp->sctp_socket->so_qlimit)) {
7138 * we have a listener already and its not
7141 SCTP_INP_DECR_REF(tinp);
7142 return (EADDRINUSE);
7144 SCTP_INP_DECR_REF(tinp);
7148 SCTP_INP_RLOCK(inp);
7149 #ifdef SCTP_LOCK_LOGGING
7150 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7151 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7155 error = solisten_proto_check(so);
7158 SCTP_INP_RUNLOCK(inp);
7161 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7162 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7164 * The unlucky case - We are in the tcp pool with this guy.
7165 * - Someone else is in the main inp slot. - We must move
7166 * this guy (the listener) to the main slot - We must then
7167 * move the guy that was listener to the TCP Pool.
7169 if (sctp_swap_inpcb_for_listen(inp)) {
7170 SCTP_INP_RUNLOCK(inp);
7171 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7172 return (EADDRINUSE);
7175 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7176 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7177 /* We are already connected AND the TCP model */
7178 SCTP_INP_RUNLOCK(inp);
7179 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7180 return (EADDRINUSE);
7182 SCTP_INP_RUNLOCK(inp);
7183 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7184 /* We must do a bind. */
7185 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7186 /* bind error, probably perm */
7191 /* It appears for 7.0 and on, we must always call this. */
7192 solisten_proto(so, backlog);
7193 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7194 /* remove the ACCEPTCONN flag for one-to-many sockets */
7195 so->so_options &= ~SO_ACCEPTCONN;
7198 /* turning off listen */
7199 so->so_options &= ~SO_ACCEPTCONN;
7205 static int sctp_defered_wakeup_cnt = 0;
7208 sctp_accept(struct socket *so, struct sockaddr **addr)
7210 struct sctp_tcb *stcb;
7211 struct sctp_inpcb *inp;
7212 union sctp_sockstore store;
7218 inp = (struct sctp_inpcb *)so->so_pcb;
7221 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7222 return (ECONNRESET);
7224 SCTP_INP_RLOCK(inp);
7225 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7226 SCTP_INP_RUNLOCK(inp);
7227 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7228 return (EOPNOTSUPP);
7230 if (so->so_state & SS_ISDISCONNECTED) {
7231 SCTP_INP_RUNLOCK(inp);
7232 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7233 return (ECONNABORTED);
7235 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7237 SCTP_INP_RUNLOCK(inp);
7238 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7239 return (ECONNRESET);
7241 SCTP_TCB_LOCK(stcb);
7242 SCTP_INP_RUNLOCK(inp);
7243 store = stcb->asoc.primary_destination->ro._l_addr;
7244 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
7245 SCTP_TCB_UNLOCK(stcb);
7246 switch (store.sa.sa_family) {
7250 struct sockaddr_in *sin;
7252 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7255 sin->sin_family = AF_INET;
7256 sin->sin_len = sizeof(*sin);
7257 sin->sin_port = store.sin.sin_port;
7258 sin->sin_addr = store.sin.sin_addr;
7259 *addr = (struct sockaddr *)sin;
7266 struct sockaddr_in6 *sin6;
7268 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7271 sin6->sin6_family = AF_INET6;
7272 sin6->sin6_len = sizeof(*sin6);
7273 sin6->sin6_port = store.sin6.sin6_port;
7274 sin6->sin6_addr = store.sin6.sin6_addr;
7275 if ((error = sa6_recoverscope(sin6)) != 0) {
7276 SCTP_FREE_SONAME(sin6);
7279 *addr = (struct sockaddr *)sin6;
7287 /* Wake any delayed sleep action */
7288 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7289 SCTP_INP_WLOCK(inp);
7290 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7291 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7292 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7293 SCTP_INP_WUNLOCK(inp);
7294 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7295 if (sowriteable(inp->sctp_socket)) {
7296 sowwakeup_locked(inp->sctp_socket);
7298 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7300 SCTP_INP_WLOCK(inp);
7302 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7303 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7304 SCTP_INP_WUNLOCK(inp);
7305 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7306 if (soreadable(inp->sctp_socket)) {
7307 sctp_defered_wakeup_cnt++;
7308 sorwakeup_locked(inp->sctp_socket);
7310 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7312 SCTP_INP_WLOCK(inp);
7314 SCTP_INP_WUNLOCK(inp);
7316 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7317 SCTP_TCB_LOCK(stcb);
7318 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7319 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7326 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7328 struct sockaddr_in *sin;
7330 struct sctp_inpcb *inp;
7331 struct sctp_ifa *sctp_ifa;
7334 * Do the malloc first in case it blocks.
7336 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7339 sin->sin_family = AF_INET;
7340 sin->sin_len = sizeof(*sin);
7341 inp = (struct sctp_inpcb *)so->so_pcb;
7343 SCTP_FREE_SONAME(sin);
7344 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7345 return (ECONNRESET);
7347 SCTP_INP_RLOCK(inp);
7348 sin->sin_port = inp->sctp_lport;
7349 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7350 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7351 struct sctp_tcb *stcb;
7352 struct sockaddr_in *sin_a;
7353 struct sctp_nets *net;
7356 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7362 SCTP_TCB_LOCK(stcb);
7363 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7364 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7366 /* this will make coverity happy */
7369 if (sin_a->sin_family == AF_INET) {
7374 if ((!fnd) || (sin_a == NULL)) {
7376 SCTP_TCB_UNLOCK(stcb);
7379 vrf_id = inp->def_vrf_id;
7380 sctp_ifa = sctp_source_address_selection(inp,
7382 (sctp_route_t *) & net->ro,
7385 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7386 sctp_free_ifa(sctp_ifa);
7388 SCTP_TCB_UNLOCK(stcb);
7390 /* For the bound all case you get back 0 */
7392 sin->sin_addr.s_addr = 0;
7396 /* Take the first IPv4 address in the list */
7397 struct sctp_laddr *laddr;
7400 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7401 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7402 struct sockaddr_in *sin_a;
7404 sin_a = &laddr->ifa->address.sin;
7405 sin->sin_addr = sin_a->sin_addr;
7411 SCTP_FREE_SONAME(sin);
7412 SCTP_INP_RUNLOCK(inp);
7413 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7417 SCTP_INP_RUNLOCK(inp);
7418 (*addr) = (struct sockaddr *)sin;
7423 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7425 struct sockaddr_in *sin;
7427 struct sockaddr_in *sin_a;
7428 struct sctp_inpcb *inp;
7429 struct sctp_tcb *stcb;
7430 struct sctp_nets *net;
7432 /* Do the malloc first in case it blocks. */
7433 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7436 sin->sin_family = AF_INET;
7437 sin->sin_len = sizeof(*sin);
7439 inp = (struct sctp_inpcb *)so->so_pcb;
7440 if ((inp == NULL) ||
7441 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7442 /* UDP type and listeners will drop out here */
7443 SCTP_FREE_SONAME(sin);
7444 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7447 SCTP_INP_RLOCK(inp);
7448 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7450 SCTP_TCB_LOCK(stcb);
7452 SCTP_INP_RUNLOCK(inp);
7454 SCTP_FREE_SONAME(sin);
7455 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7456 return (ECONNRESET);
7459 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7460 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7461 if (sin_a->sin_family == AF_INET) {
7463 sin->sin_port = stcb->rport;
7464 sin->sin_addr = sin_a->sin_addr;
7468 SCTP_TCB_UNLOCK(stcb);
7470 /* No IPv4 address */
7471 SCTP_FREE_SONAME(sin);
7472 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7475 (*addr) = (struct sockaddr *)sin;
7479 struct pr_usrreqs sctp_usrreqs = {
7480 .pru_abort = sctp_abort,
7481 .pru_accept = sctp_accept,
7482 .pru_attach = sctp_attach,
7483 .pru_bind = sctp_bind,
7484 .pru_connect = sctp_connect,
7485 .pru_control = in_control,
7486 .pru_close = sctp_close,
7487 .pru_detach = sctp_close,
7488 .pru_sopoll = sopoll_generic,
7489 .pru_flush = sctp_flush,
7490 .pru_disconnect = sctp_disconnect,
7491 .pru_listen = sctp_listen,
7492 .pru_peeraddr = sctp_peeraddr,
7493 .pru_send = sctp_sendm,
7494 .pru_shutdown = sctp_shutdown,
7495 .pru_sockaddr = sctp_ingetaddr,
7496 .pru_sosend = sctp_sosend,
7497 .pru_soreceive = sctp_soreceive