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);
101 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
103 struct sctp_tmit_chunk *chk;
106 /* Adjust that too */
107 stcb->asoc.smallest_mtu = nxtsz;
108 /* now off to subtract IP_DF flag if needed */
109 overhead = IP_HDR_SIZE;
110 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
111 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
113 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
114 if ((chk->send_size + overhead) > nxtsz) {
115 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
118 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
119 if ((chk->send_size + overhead) > nxtsz) {
121 * For this guy we also mark for immediate resend
122 * since we sent to big of chunk
124 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
125 if (chk->sent < SCTP_DATAGRAM_RESEND) {
126 sctp_flight_size_decrease(chk);
127 sctp_total_flight_decrease(stcb, chk);
128 chk->sent = SCTP_DATAGRAM_RESEND;
129 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
130 chk->rec.data.doing_fast_retransmit = 0;
131 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
132 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
133 chk->whoTo->flight_size,
135 (uint32_t) (uintptr_t) chk->whoTo,
136 chk->rec.data.TSN_seq);
138 /* Clear any time so NO RTT is being done */
147 sctp_notify(struct sctp_inpcb *inp,
148 struct sctp_tcb *stcb,
149 struct sctp_nets *net,
155 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
161 if (icmp_type != ICMP_UNREACH) {
162 /* We only care about unreachable */
163 SCTP_TCB_UNLOCK(stcb);
166 if ((icmp_code == ICMP_UNREACH_NET) ||
167 (icmp_code == ICMP_UNREACH_HOST) ||
168 (icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
169 (icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
170 (icmp_code == ICMP_UNREACH_ISOLATED) ||
171 (icmp_code == ICMP_UNREACH_NET_PROHIB) ||
172 (icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
173 (icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
176 * Hmm reachablity problems we must examine closely. If its
177 * not reachable, we may have lost a network. Or if there is
178 * NO protocol at the other end named SCTP. well we consider
181 if (net->dest_state & SCTP_ADDR_REACHABLE) {
182 /* OK, that destination is NOT reachable. */
183 net->dest_state &= ~SCTP_ADDR_REACHABLE;
184 net->dest_state &= ~SCTP_ADDR_PF;
185 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
187 (void *)net, SCTP_SO_NOT_LOCKED);
189 SCTP_TCB_UNLOCK(stcb);
190 } else if ((icmp_code == ICMP_UNREACH_PROTOCOL) ||
191 (icmp_code == ICMP_UNREACH_PORT)) {
193 * Here the peer is either playing tricks on us, including
194 * an address that belongs to someone who does not support
195 * SCTP OR was a userland implementation that shutdown and
196 * now is dead. In either case treat it like a OOTB abort
199 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
200 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
201 so = SCTP_INP_SO(inp);
202 atomic_add_int(&stcb->asoc.refcnt, 1);
203 SCTP_TCB_UNLOCK(stcb);
204 SCTP_SOCKET_LOCK(so, 1);
206 atomic_subtract_int(&stcb->asoc.refcnt, 1);
208 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
209 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
210 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
211 SCTP_SOCKET_UNLOCK(so, 1);
212 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
214 /* no need to unlock here, since the TCB is gone */
215 } else if (icmp_code == ICMP_UNREACH_NEEDFRAG) {
216 /* Find the next (smaller) MTU */
219 * Old type router that does not tell us what the
220 * next MTU is. Rats we will have to guess (in a
221 * educated fashion of course).
223 next_mtu = sctp_get_prev_mtu(ip_len);
225 /* Stop the PMTU timer. */
226 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
228 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
229 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
233 /* Update the path MTU. */
234 if (net->mtu > next_mtu) {
237 net->mtu -= sizeof(struct udphdr);
240 /* Update the association MTU */
241 if (stcb->asoc.smallest_mtu > next_mtu) {
242 sctp_pathmtu_adjustment(stcb, next_mtu);
244 /* Finally, start the PMTU timer if it was running before. */
246 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
248 SCTP_TCB_UNLOCK(stcb);
250 SCTP_TCB_UNLOCK(stcb);
255 sctp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
257 struct ip *outer_ip, *inner_ip;
260 struct sctp_inpcb *inp;
261 struct sctp_tcb *stcb;
262 struct sctp_nets *net;
263 struct sctp_init_chunk *ch;
264 struct sockaddr_in to, from;
266 if (sa->sa_family != AF_INET ||
267 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
270 if (PRC_IS_REDIRECT(cmd)) {
272 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
276 inner_ip = (struct ip *)vip;
277 icmp = (struct icmp *)((caddr_t)inner_ip -
278 (sizeof(struct icmp) - sizeof(struct ip)));
279 outer_ip = (struct ip *)((caddr_t)icmp - sizeof(struct ip));
280 sh = (struct sctphdr *)((caddr_t)inner_ip + (inner_ip->ip_hl << 2));
281 bzero(&to, sizeof(to));
282 bzero(&from, sizeof(from));
283 from.sin_family = to.sin_family = AF_INET;
284 from.sin_len = to.sin_len = sizeof(to);
285 from.sin_port = sh->src_port;
286 from.sin_addr = inner_ip->ip_src;
287 to.sin_port = sh->dest_port;
288 to.sin_addr = inner_ip->ip_dst;
290 * 'to' holds the dest of the packet that failed to be sent.
291 * 'from' holds our local endpoint address. Thus we reverse
292 * the to and the from in the lookup.
296 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&to,
297 (struct sockaddr *)&from,
300 if ((stcb != NULL) &&
303 (inp->sctp_socket != NULL)) {
304 /* Check the verification tag */
305 if (ntohl(sh->v_tag) != 0) {
307 * This must be the verification tag used
308 * for sending out packets. We don't
309 * consider packets reflecting the
312 if (ntohl(sh->v_tag) != stcb->asoc.peer_vtag) {
313 SCTP_TCB_UNLOCK(stcb);
317 if (ntohs(outer_ip->ip_len) >=
319 8 + (inner_ip->ip_hl << 2) + 20) {
321 * In this case we can check if we
322 * got an INIT chunk and if the
323 * initiate tag matches.
325 ch = (struct sctp_init_chunk *)(sh + 1);
326 if ((ch->ch.chunk_type != SCTP_INITIATION) ||
327 (ntohl(ch->init.initiate_tag) != stcb->asoc.my_vtag)) {
328 SCTP_TCB_UNLOCK(stcb);
332 SCTP_TCB_UNLOCK(stcb);
336 sctp_notify(inp, stcb, net,
339 ntohs(inner_ip->ip_len),
340 ntohs(icmp->icmp_nextmtu));
342 if ((stcb == NULL) && (inp != NULL)) {
343 /* reduce ref-count */
345 SCTP_INP_DECR_REF(inp);
346 SCTP_INP_WUNLOCK(inp);
349 SCTP_TCB_UNLOCK(stcb);
359 sctp_getcred(SYSCTL_HANDLER_ARGS)
362 struct sockaddr_in addrs[2];
363 struct sctp_inpcb *inp;
364 struct sctp_nets *net;
365 struct sctp_tcb *stcb;
369 /* FIX, for non-bsd is this right? */
370 vrf_id = SCTP_DEFAULT_VRFID;
372 error = priv_check(req->td, PRIV_NETINET_GETCRED);
377 error = SYSCTL_IN(req, addrs, sizeof(addrs));
381 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
383 &inp, &net, 1, vrf_id);
384 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
385 if ((inp != NULL) && (stcb == NULL)) {
386 /* reduce ref-count */
388 SCTP_INP_DECR_REF(inp);
391 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
395 SCTP_TCB_UNLOCK(stcb);
397 * We use the write lock here, only since in the error leg we need
398 * it. If we used RLOCK, then we would have to
399 * wlock/decr/unlock/rlock. Which in theory could create a hole.
400 * Better to use higher wlock.
404 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
406 SCTP_INP_WUNLOCK(inp);
409 cru2x(inp->sctp_socket->so_cred, &xuc);
410 SCTP_INP_WUNLOCK(inp);
411 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
416 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
417 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
422 sctp_abort(struct socket *so)
424 struct sctp_inpcb *inp;
427 inp = (struct sctp_inpcb *)so->so_pcb;
432 flags = inp->sctp_flags;
433 #ifdef SCTP_LOG_CLOSING
434 sctp_log_closing(inp, NULL, 17);
436 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
437 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
438 #ifdef SCTP_LOG_CLOSING
439 sctp_log_closing(inp, NULL, 16);
441 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
442 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
444 SCTP_SB_CLEAR(so->so_snd);
446 * same for the rcv ones, they are only here for the
449 SCTP_SB_CLEAR(so->so_rcv);
451 /* Now null out the reference, we are completely detached. */
455 flags = inp->sctp_flags;
456 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
457 goto sctp_must_try_again;
464 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
466 struct sctp_inpcb *inp;
467 struct inpcb *ip_inp;
469 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
471 inp = (struct sctp_inpcb *)so->so_pcb;
473 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
476 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
477 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
482 error = sctp_inpcb_alloc(so, vrf_id);
486 inp = (struct sctp_inpcb *)so->so_pcb;
488 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
489 ip_inp = &inp->ip_inp.inp;
490 ip_inp->inp_vflag |= INP_IPV4;
491 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
492 SCTP_INP_WUNLOCK(inp);
497 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
499 struct sctp_inpcb *inp;
501 inp = (struct sctp_inpcb *)so->so_pcb;
503 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
507 if ((addr->sa_family != AF_INET) ||
508 (addr->sa_len != sizeof(struct sockaddr_in))) {
509 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
513 return (sctp_inpcb_bind(so, addr, NULL, p));
518 sctp_close(struct socket *so)
520 struct sctp_inpcb *inp;
523 inp = (struct sctp_inpcb *)so->so_pcb;
528 * Inform all the lower layer assoc that we are done.
531 flags = inp->sctp_flags;
532 #ifdef SCTP_LOG_CLOSING
533 sctp_log_closing(inp, NULL, 17);
535 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
536 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
537 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
538 (so->so_rcv.sb_cc > 0)) {
539 #ifdef SCTP_LOG_CLOSING
540 sctp_log_closing(inp, NULL, 13);
542 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
543 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
545 #ifdef SCTP_LOG_CLOSING
546 sctp_log_closing(inp, NULL, 14);
548 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
549 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
552 * The socket is now detached, no matter what the state of
553 * the SCTP association.
556 SCTP_SB_CLEAR(so->so_snd);
558 * same for the rcv ones, they are only here for the
561 SCTP_SB_CLEAR(so->so_rcv);
563 /* Now null out the reference, we are completely detached. */
567 flags = inp->sctp_flags;
568 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
569 goto sctp_must_try_again;
577 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
578 struct mbuf *control, struct thread *p);
582 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
583 struct mbuf *control, struct thread *p)
585 struct sctp_inpcb *inp;
588 inp = (struct sctp_inpcb *)so->so_pcb;
591 sctp_m_freem(control);
594 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
598 /* Got to have an to address if we are NOT a connected socket */
599 if ((addr == NULL) &&
600 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
601 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
603 } else if (addr == NULL) {
604 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
605 error = EDESTADDRREQ;
608 sctp_m_freem(control);
614 if (addr->sa_family != AF_INET) {
615 /* must be a v4 address! */
616 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
619 sctp_m_freem(control);
622 error = EDESTADDRREQ;
627 /* now what about control */
630 SCTP_PRINTF("huh? control set?\n");
631 sctp_m_freem(inp->control);
634 inp->control = control;
638 SCTP_BUF_NEXT(inp->pkt_last) = m;
641 inp->pkt_last = inp->pkt = m;
644 /* FreeBSD uses a flag passed */
645 ((flags & PRUS_MORETOCOME) == 0)
648 * note with the current version this code will only be used
649 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
650 * re-defining sosend to use the sctp_sosend. One can
651 * optionally switch back to this code (by changing back the
652 * definitions) but this is not advisable. This code is used
653 * by FreeBSD when sending a file with sendfile() though.
657 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
667 sctp_disconnect(struct socket *so)
669 struct sctp_inpcb *inp;
671 inp = (struct sctp_inpcb *)so->so_pcb;
673 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
677 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
678 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
679 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
681 SCTP_INP_RUNLOCK(inp);
684 struct sctp_association *asoc;
685 struct sctp_tcb *stcb;
687 stcb = LIST_FIRST(&inp->sctp_asoc_list);
689 SCTP_INP_RUNLOCK(inp);
690 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
695 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
696 /* We are about to be freed, out of here */
697 SCTP_TCB_UNLOCK(stcb);
698 SCTP_INP_RUNLOCK(inp);
701 if (((so->so_options & SO_LINGER) &&
702 (so->so_linger == 0)) ||
703 (so->so_rcv.sb_cc > 0)) {
704 if (SCTP_GET_STATE(asoc) !=
705 SCTP_STATE_COOKIE_WAIT) {
706 /* Left with Data unread */
709 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_NOWAIT, 1, MT_DATA);
715 struct sctp_paramhdr *ph;
717 ph = mtod(err, struct sctp_paramhdr *);
718 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
719 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
720 ph->param_length = htons(SCTP_BUF_LEN(err));
722 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
723 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
725 SCTP_INP_RUNLOCK(inp);
726 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
727 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
728 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
730 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
731 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
732 /* No unlock tcb assoc is gone */
735 if (TAILQ_EMPTY(&asoc->send_queue) &&
736 TAILQ_EMPTY(&asoc->sent_queue) &&
737 (asoc->stream_queue_cnt == 0)) {
738 /* there is nothing queued to send, so done */
739 if (asoc->locked_on_sending) {
742 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
743 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
744 /* only send SHUTDOWN 1st time thru */
745 struct sctp_nets *netp;
747 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
748 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
749 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
751 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
752 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
753 sctp_stop_timers_for_shutdown(stcb);
754 if (stcb->asoc.alternate) {
755 netp = stcb->asoc.alternate;
757 netp = stcb->asoc.primary_destination;
759 sctp_send_shutdown(stcb, netp);
760 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
761 stcb->sctp_ep, stcb, netp);
762 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
763 stcb->sctp_ep, stcb, netp);
764 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
768 * we still got (or just got) data to send,
769 * so set SHUTDOWN_PENDING
772 * XXX sockets draft says that SCTP_EOF
773 * should be sent with no data. currently,
774 * we will allow user data to be sent first
775 * and move to SHUTDOWN-PENDING
777 struct sctp_nets *netp;
779 if (stcb->asoc.alternate) {
780 netp = stcb->asoc.alternate;
782 netp = stcb->asoc.primary_destination;
785 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
786 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
788 if (asoc->locked_on_sending) {
789 /* Locked to send out the data */
790 struct sctp_stream_queue_pending *sp;
792 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
794 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
795 asoc->locked_on_sending->stream_no);
797 if ((sp->length == 0) && (sp->msg_is_complete == 0))
798 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
801 if (TAILQ_EMPTY(&asoc->send_queue) &&
802 TAILQ_EMPTY(&asoc->sent_queue) &&
803 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
807 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
808 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
809 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
810 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
811 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
812 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
813 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
815 SCTP_INP_RUNLOCK(inp);
816 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
817 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
820 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
823 soisdisconnecting(so);
824 SCTP_TCB_UNLOCK(stcb);
825 SCTP_INP_RUNLOCK(inp);
830 /* UDP model does not support this */
831 SCTP_INP_RUNLOCK(inp);
832 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
838 sctp_flush(struct socket *so, int how)
841 * We will just clear out the values and let subsequent close clear
842 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
843 * they will not be able to read the data, the socket will block
844 * that from happening.
846 struct sctp_inpcb *inp;
848 inp = (struct sctp_inpcb *)so->so_pcb;
850 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
854 /* For the 1 to many model this does nothing */
855 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
856 SCTP_INP_RUNLOCK(inp);
859 SCTP_INP_RUNLOCK(inp);
860 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
862 * First make sure the sb will be happy, we don't use these
863 * except maybe the count
866 SCTP_INP_READ_LOCK(inp);
867 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
868 SCTP_INP_READ_UNLOCK(inp);
869 SCTP_INP_WUNLOCK(inp);
870 so->so_rcv.sb_cc = 0;
871 so->so_rcv.sb_mbcnt = 0;
872 so->so_rcv.sb_mb = NULL;
874 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
876 * First make sure the sb will be happy, we don't use these
877 * except maybe the count
879 so->so_snd.sb_cc = 0;
880 so->so_snd.sb_mbcnt = 0;
881 so->so_snd.sb_mb = NULL;
888 sctp_shutdown(struct socket *so)
890 struct sctp_inpcb *inp;
892 inp = (struct sctp_inpcb *)so->so_pcb;
894 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
898 /* For UDP model this is a invalid call */
899 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
900 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
901 /* Restore the flags that the soshutdown took away. */
902 SOCKBUF_LOCK(&so->so_rcv);
903 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
904 SOCKBUF_UNLOCK(&so->so_rcv);
905 /* This proc will wakeup for read and do nothing (I hope) */
906 SCTP_INP_RUNLOCK(inp);
907 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
911 * Ok, if we reach here its the TCP model and it is either a
912 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
915 struct sctp_tcb *stcb;
916 struct sctp_association *asoc;
917 struct sctp_nets *netp;
920 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
921 SCTP_INP_RUNLOCK(inp);
926 stcb = LIST_FIRST(&inp->sctp_asoc_list);
929 * Ok, we hit the case that the shutdown call was
930 * made after an abort or something. Nothing to do
933 SCTP_INP_RUNLOCK(inp);
938 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
939 SCTP_TCB_UNLOCK(stcb);
940 SCTP_INP_RUNLOCK(inp);
943 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_WAIT) &&
944 (SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_ECHOED) &&
945 (SCTP_GET_STATE(asoc) != SCTP_STATE_OPEN)) {
947 * If we are not in or before ESTABLISHED, there is
948 * no protocol action required.
950 SCTP_TCB_UNLOCK(stcb);
951 SCTP_INP_RUNLOCK(inp);
954 if (stcb->asoc.alternate) {
955 netp = stcb->asoc.alternate;
957 netp = stcb->asoc.primary_destination;
959 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) &&
960 TAILQ_EMPTY(&asoc->send_queue) &&
961 TAILQ_EMPTY(&asoc->sent_queue) &&
962 (asoc->stream_queue_cnt == 0)) {
963 if (asoc->locked_on_sending) {
966 /* there is nothing queued to send, so I'm done... */
967 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
968 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
969 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
970 sctp_stop_timers_for_shutdown(stcb);
971 sctp_send_shutdown(stcb, netp);
972 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
973 stcb->sctp_ep, stcb, netp);
976 * We still got (or just got) data to send, so set
979 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
980 if (asoc->locked_on_sending) {
981 /* Locked to send out the data */
982 struct sctp_stream_queue_pending *sp;
984 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
986 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
987 asoc->locked_on_sending->stream_no);
989 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
990 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_PARTIAL_MSG_LEFT);
994 if (TAILQ_EMPTY(&asoc->send_queue) &&
995 TAILQ_EMPTY(&asoc->sent_queue) &&
996 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1000 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
1001 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
1002 sctp_abort_an_association(stcb->sctp_ep, stcb,
1003 op_err, SCTP_SO_LOCKED);
1004 SCTP_INP_RUNLOCK(inp);
1008 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, netp);
1010 * XXX: Why do this in the case where we have still data
1013 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1014 SCTP_TCB_UNLOCK(stcb);
1015 SCTP_INP_RUNLOCK(inp);
1021 * copies a "user" presentable address and removes embedded scope, etc.
1022 * returns 0 on success, 1 on error
1025 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1028 struct sockaddr_in6 lsa6;
1030 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1033 memcpy(ss, sa, sa->sa_len);
1040 * NOTE: assumes addr lock is held
1043 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1044 struct sctp_tcb *stcb,
1046 struct sockaddr_storage *sas,
1049 struct sctp_ifn *sctp_ifn;
1050 struct sctp_ifa *sctp_ifa;
1055 int ipv4_local_scope, ipv4_addr_legal;
1059 int local_scope, site_scope, ipv6_addr_legal;
1062 struct sctp_vrf *vrf;
1069 /* Turn on all the appropriate scope */
1070 loopback_scope = stcb->asoc.scope.loopback_scope;
1072 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1073 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1076 local_scope = stcb->asoc.scope.local_scope;
1077 site_scope = stcb->asoc.scope.site_scope;
1078 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1081 /* Use generic values for endpoints. */
1084 ipv4_local_scope = 1;
1090 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1092 ipv6_addr_legal = 1;
1095 if (SCTP_IPV6_V6ONLY(inp)) {
1096 ipv4_addr_legal = 0;
1098 ipv4_addr_legal = 1;
1103 ipv6_addr_legal = 0;
1106 ipv4_addr_legal = 1;
1110 vrf = sctp_find_vrf(vrf_id);
1114 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1115 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1116 if ((loopback_scope == 0) &&
1117 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1118 /* Skip loopback if loopback_scope not set */
1121 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1124 * For the BOUND-ALL case, the list
1125 * associated with a TCB is Always
1126 * considered a reverse list.. i.e.
1127 * it lists addresses that are NOT
1128 * part of the association. If this
1129 * is one of those we must skip it.
1131 if (sctp_is_addr_restricted(stcb,
1136 switch (sctp_ifa->address.sa.sa_family) {
1139 if (ipv4_addr_legal) {
1140 struct sockaddr_in *sin;
1142 sin = &sctp_ifa->address.sin;
1143 if (sin->sin_addr.s_addr == 0) {
1151 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1152 &sin->sin_addr) != 0) {
1155 if ((ipv4_local_scope == 0) &&
1156 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1160 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1161 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1162 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1163 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1164 actual += sizeof(struct sockaddr_in6);
1167 memcpy(sas, sin, sizeof(*sin));
1168 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1169 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1170 actual += sizeof(*sin);
1174 if (actual >= limit) {
1184 if (ipv6_addr_legal) {
1185 struct sockaddr_in6 *sin6;
1187 sin6 = &sctp_ifa->address.sin6;
1188 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1196 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1197 &sin6->sin6_addr) != 0) {
1200 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1201 if (local_scope == 0)
1203 if (sin6->sin6_scope_id == 0) {
1204 if (sa6_recoverscope(sin6) != 0)
1222 if ((site_scope == 0) &&
1223 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1226 memcpy(sas, sin6, sizeof(*sin6));
1227 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1228 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1229 actual += sizeof(*sin6);
1230 if (actual >= limit) {
1245 struct sctp_laddr *laddr;
1247 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1249 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1253 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1255 switch (laddr->ifa->address.sa.sa_family) {
1258 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1263 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1270 sas = (struct sockaddr_storage *)((caddr_t)sas +
1271 laddr->ifa->address.sa.sa_len);
1272 actual += laddr->ifa->address.sa.sa_len;
1273 if (actual >= limit) {
1282 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1283 struct sctp_tcb *stcb,
1285 struct sockaddr_storage *sas)
1289 SCTP_IPI_ADDR_RLOCK();
1290 /* fill up addresses for the endpoint's default vrf */
1291 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1293 SCTP_IPI_ADDR_RUNLOCK();
1298 * NOTE: assumes addr lock is held
1301 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1304 struct sctp_vrf *vrf = NULL;
1307 * In both sub-set bound an bound_all cases we return the MAXIMUM
1308 * number of addresses that you COULD get. In reality the sub-set
1309 * bound may have an exclusion list for a given TCB OR in the
1310 * bound-all case a TCB may NOT include the loopback or other
1311 * addresses as well.
1313 vrf = sctp_find_vrf(vrf_id);
1317 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1318 struct sctp_ifn *sctp_ifn;
1319 struct sctp_ifa *sctp_ifa;
1321 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1322 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1323 /* Count them if they are the right type */
1324 switch (sctp_ifa->address.sa.sa_family) {
1328 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1329 cnt += sizeof(struct sockaddr_in6);
1331 cnt += sizeof(struct sockaddr_in);
1333 cnt += sizeof(struct sockaddr_in);
1339 cnt += sizeof(struct sockaddr_in6);
1348 struct sctp_laddr *laddr;
1350 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1351 switch (laddr->ifa->address.sa.sa_family) {
1355 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1356 cnt += sizeof(struct sockaddr_in6);
1358 cnt += sizeof(struct sockaddr_in);
1360 cnt += sizeof(struct sockaddr_in);
1366 cnt += sizeof(struct sockaddr_in6);
1378 sctp_count_max_addresses(struct sctp_inpcb *inp)
1382 SCTP_IPI_ADDR_RLOCK();
1383 /* count addresses for the endpoint's default VRF */
1384 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1385 SCTP_IPI_ADDR_RUNLOCK();
1390 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1391 size_t optsize, void *p, int delay)
1394 int creat_lock_on = 0;
1395 struct sctp_tcb *stcb = NULL;
1396 struct sockaddr *sa;
1397 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1399 int bad_addresses = 0;
1402 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1404 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1405 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1406 /* We are already connected AND the TCP model */
1407 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1408 return (EADDRINUSE);
1410 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1411 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1412 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1415 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1416 SCTP_INP_RLOCK(inp);
1417 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1418 SCTP_INP_RUNLOCK(inp);
1421 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1424 SCTP_INP_INCR_REF(inp);
1425 SCTP_ASOC_CREATE_LOCK(inp);
1427 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1428 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1429 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1433 totaddrp = (unsigned int *)optval;
1434 totaddr = *totaddrp;
1435 sa = (struct sockaddr *)(totaddrp + 1);
1436 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (unsigned int)(optsize - sizeof(int)), &bad_addresses);
1437 if ((stcb != NULL) || bad_addresses) {
1438 /* Already have or am bring up an association */
1439 SCTP_ASOC_CREATE_UNLOCK(inp);
1442 SCTP_TCB_UNLOCK(stcb);
1443 if (bad_addresses == 0) {
1444 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1450 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1455 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1457 struct in6pcb *inp6;
1459 inp6 = (struct in6pcb *)inp;
1460 if (SCTP_IPV6_V6ONLY(inp6)) {
1462 * if IPV6_V6ONLY flag, ignore connections destined
1463 * to a v4 addr or v4-mapped addr
1465 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1471 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1472 SCTP_PCB_FLAGS_UNBOUND) {
1473 /* Bind a ephemeral port */
1474 error = sctp_inpcb_bind(so, NULL, NULL, p);
1479 /* FIX ME: do we want to pass in a vrf on the connect call? */
1480 vrf_id = inp->def_vrf_id;
1483 /* We are GOOD to go */
1484 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1485 inp->sctp_ep.pre_open_stream_count,
1489 /* Gak! no memory */
1492 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1493 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1494 /* Set the connected flag so we can queue data */
1497 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1498 /* move to second address */
1499 switch (sa->sa_family) {
1502 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1507 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1515 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1516 /* Fill in the return id */
1518 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE,
1519 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
1522 a_id = (sctp_assoc_t *) optval;
1523 *a_id = sctp_get_associd(stcb);
1525 /* initialize authentication parameters for the assoc */
1526 sctp_initialize_auth_params(inp, stcb);
1529 /* doing delayed connection */
1530 stcb->asoc.delayed_connection = 1;
1531 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1533 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1534 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1536 SCTP_TCB_UNLOCK(stcb);
1537 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1538 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1539 /* Set the connected flag so we can queue data */
1543 if (creat_lock_on) {
1544 SCTP_ASOC_CREATE_UNLOCK(inp);
1546 SCTP_INP_DECR_REF(inp);
1550 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1551 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1552 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1553 SCTP_INP_RLOCK(inp); \
1554 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1556 SCTP_TCB_LOCK(stcb); \
1558 SCTP_INP_RUNLOCK(inp); \
1559 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1560 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1561 if (stcb == NULL) { \
1562 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1572 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1573 if (size < sizeof(type)) { \
1574 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1578 destp = (type *)srcp; \
1583 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1586 struct sctp_inpcb *inp = NULL;
1588 struct sctp_tcb *stcb = NULL;
1590 if (optval == NULL) {
1591 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1594 inp = (struct sctp_inpcb *)so->so_pcb;
1596 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1603 case SCTP_AUTOCLOSE:
1604 case SCTP_EXPLICIT_EOR:
1605 case SCTP_AUTO_ASCONF:
1606 case SCTP_DISABLE_FRAGMENTS:
1607 case SCTP_I_WANT_MAPPED_V4_ADDR:
1608 case SCTP_USE_EXT_RCVINFO:
1609 SCTP_INP_RLOCK(inp);
1611 case SCTP_DISABLE_FRAGMENTS:
1612 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1614 case SCTP_I_WANT_MAPPED_V4_ADDR:
1615 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1617 case SCTP_AUTO_ASCONF:
1618 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1619 /* only valid for bound all sockets */
1620 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1622 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1627 case SCTP_EXPLICIT_EOR:
1628 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1631 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1633 case SCTP_USE_EXT_RCVINFO:
1634 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1636 case SCTP_AUTOCLOSE:
1637 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1638 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1644 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1645 error = ENOPROTOOPT;
1646 } /* end switch (sopt->sopt_name) */
1647 if (*optsize < sizeof(val)) {
1648 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1652 SCTP_INP_RUNLOCK(inp);
1654 /* return the option value */
1655 *(int *)optval = val;
1656 *optsize = sizeof(val);
1659 case SCTP_GET_PACKET_LOG:
1661 #ifdef SCTP_PACKET_LOGGING
1665 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1666 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1669 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1674 case SCTP_REUSE_PORT:
1678 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1679 /* Can't do this for a 1-m socket */
1683 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1684 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1685 *optsize = sizeof(uint32_t);
1688 case SCTP_PARTIAL_DELIVERY_POINT:
1692 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1693 *value = inp->partial_delivery_point;
1694 *optsize = sizeof(uint32_t);
1697 case SCTP_FRAGMENT_INTERLEAVE:
1701 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1702 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1703 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1704 *value = SCTP_FRAG_LEVEL_2;
1706 *value = SCTP_FRAG_LEVEL_1;
1709 *value = SCTP_FRAG_LEVEL_0;
1711 *optsize = sizeof(uint32_t);
1714 case SCTP_INTERLEAVING_SUPPORTED:
1716 struct sctp_assoc_value *av;
1718 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1719 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1722 av->assoc_value = stcb->asoc.idata_supported;
1723 SCTP_TCB_UNLOCK(stcb);
1725 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1726 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1727 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1728 SCTP_INP_RLOCK(inp);
1729 if (inp->idata_supported) {
1730 av->assoc_value = 1;
1732 av->assoc_value = 0;
1734 SCTP_INP_RUNLOCK(inp);
1736 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1741 *optsize = sizeof(struct sctp_assoc_value);
1745 case SCTP_CMT_ON_OFF:
1747 struct sctp_assoc_value *av;
1749 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1750 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1752 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1753 SCTP_TCB_UNLOCK(stcb);
1755 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1756 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1757 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1758 SCTP_INP_RLOCK(inp);
1759 av->assoc_value = inp->sctp_cmt_on_off;
1760 SCTP_INP_RUNLOCK(inp);
1762 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1767 *optsize = sizeof(struct sctp_assoc_value);
1771 case SCTP_PLUGGABLE_CC:
1773 struct sctp_assoc_value *av;
1775 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1776 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1778 av->assoc_value = stcb->asoc.congestion_control_module;
1779 SCTP_TCB_UNLOCK(stcb);
1781 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1782 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1783 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1784 SCTP_INP_RLOCK(inp);
1785 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1786 SCTP_INP_RUNLOCK(inp);
1788 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1793 *optsize = sizeof(struct sctp_assoc_value);
1797 case SCTP_CC_OPTION:
1799 struct sctp_cc_option *cc_opt;
1801 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1802 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1806 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1809 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1810 *optsize = sizeof(struct sctp_cc_option);
1812 SCTP_TCB_UNLOCK(stcb);
1816 case SCTP_PLUGGABLE_SS:
1818 struct sctp_assoc_value *av;
1820 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1821 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1823 av->assoc_value = stcb->asoc.stream_scheduling_module;
1824 SCTP_TCB_UNLOCK(stcb);
1826 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1827 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1828 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1829 SCTP_INP_RLOCK(inp);
1830 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1831 SCTP_INP_RUNLOCK(inp);
1833 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1838 *optsize = sizeof(struct sctp_assoc_value);
1844 struct sctp_stream_value *av;
1846 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1847 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1849 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1850 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1851 &av->stream_value) < 0)) {
1852 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1855 *optsize = sizeof(struct sctp_stream_value);
1857 SCTP_TCB_UNLOCK(stcb);
1860 * Can't get stream value without
1863 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1868 case SCTP_GET_ADDR_LEN:
1870 struct sctp_assoc_value *av;
1872 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1875 if (av->assoc_value == AF_INET) {
1876 av->assoc_value = sizeof(struct sockaddr_in);
1881 if (av->assoc_value == AF_INET6) {
1882 av->assoc_value = sizeof(struct sockaddr_in6);
1887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1889 *optsize = sizeof(struct sctp_assoc_value);
1893 case SCTP_GET_ASSOC_NUMBER:
1895 uint32_t *value, cnt;
1897 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1898 SCTP_INP_RLOCK(inp);
1899 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1900 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1901 /* Can't do this for a 1-1 socket */
1903 SCTP_INP_RUNLOCK(inp);
1907 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1910 SCTP_INP_RUNLOCK(inp);
1912 *optsize = sizeof(uint32_t);
1915 case SCTP_GET_ASSOC_ID_LIST:
1917 struct sctp_assoc_ids *ids;
1921 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1922 SCTP_INP_RLOCK(inp);
1923 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1924 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1925 /* Can't do this for a 1-1 socket */
1927 SCTP_INP_RUNLOCK(inp);
1931 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1932 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1934 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1937 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1942 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1946 SCTP_INP_RUNLOCK(inp);
1948 ids->gaids_number_of_ids = at;
1949 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1955 struct sctp_assoc_value *av;
1957 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1958 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1961 av->assoc_value = stcb->asoc.context;
1962 SCTP_TCB_UNLOCK(stcb);
1964 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1965 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1966 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1967 SCTP_INP_RLOCK(inp);
1968 av->assoc_value = inp->sctp_context;
1969 SCTP_INP_RUNLOCK(inp);
1971 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1976 *optsize = sizeof(struct sctp_assoc_value);
1982 uint32_t *default_vrfid;
1984 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1985 *default_vrfid = inp->def_vrf_id;
1986 *optsize = sizeof(uint32_t);
1989 case SCTP_GET_ASOC_VRF:
1991 struct sctp_assoc_value *id;
1993 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1994 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1997 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1999 id->assoc_value = stcb->asoc.vrf_id;
2000 *optsize = sizeof(struct sctp_assoc_value);
2004 case SCTP_GET_VRF_IDS:
2006 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
2010 case SCTP_GET_NONCE_VALUES:
2012 struct sctp_get_nonce_values *gnv;
2014 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
2015 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
2018 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
2019 gnv->gn_local_tag = stcb->asoc.my_vtag;
2020 SCTP_TCB_UNLOCK(stcb);
2021 *optsize = sizeof(struct sctp_get_nonce_values);
2023 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2028 case SCTP_DELAYED_SACK:
2030 struct sctp_sack_info *sack;
2032 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2033 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2035 sack->sack_delay = stcb->asoc.delayed_ack;
2036 sack->sack_freq = stcb->asoc.sack_freq;
2037 SCTP_TCB_UNLOCK(stcb);
2039 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2040 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2041 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2042 SCTP_INP_RLOCK(inp);
2043 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2044 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2045 SCTP_INP_RUNLOCK(inp);
2047 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2052 *optsize = sizeof(struct sctp_sack_info);
2056 case SCTP_GET_SNDBUF_USE:
2058 struct sctp_sockstat *ss;
2060 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2061 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2064 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2065 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2066 stcb->asoc.size_on_all_streams);
2067 SCTP_TCB_UNLOCK(stcb);
2068 *optsize = sizeof(struct sctp_sockstat);
2070 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2075 case SCTP_MAX_BURST:
2077 struct sctp_assoc_value *av;
2079 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2080 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2083 av->assoc_value = stcb->asoc.max_burst;
2084 SCTP_TCB_UNLOCK(stcb);
2086 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2087 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2088 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2089 SCTP_INP_RLOCK(inp);
2090 av->assoc_value = inp->sctp_ep.max_burst;
2091 SCTP_INP_RUNLOCK(inp);
2093 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2098 *optsize = sizeof(struct sctp_assoc_value);
2104 struct sctp_assoc_value *av;
2107 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2108 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2111 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2112 SCTP_TCB_UNLOCK(stcb);
2114 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2115 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2116 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2117 SCTP_INP_RLOCK(inp);
2118 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2119 ovh = SCTP_MED_OVERHEAD;
2121 ovh = SCTP_MED_V4_OVERHEAD;
2123 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2124 av->assoc_value = 0;
2126 av->assoc_value = inp->sctp_frag_point - ovh;
2127 SCTP_INP_RUNLOCK(inp);
2129 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2134 *optsize = sizeof(struct sctp_assoc_value);
2138 case SCTP_GET_STAT_LOG:
2139 error = sctp_fill_stat_log(optval, optsize);
2143 struct sctp_event_subscribe *events;
2145 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2146 memset(events, 0, sizeof(struct sctp_event_subscribe));
2147 SCTP_INP_RLOCK(inp);
2148 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2149 events->sctp_data_io_event = 1;
2151 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2152 events->sctp_association_event = 1;
2154 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2155 events->sctp_address_event = 1;
2157 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2158 events->sctp_send_failure_event = 1;
2160 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2161 events->sctp_peer_error_event = 1;
2163 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2164 events->sctp_shutdown_event = 1;
2166 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2167 events->sctp_partial_delivery_event = 1;
2169 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2170 events->sctp_adaptation_layer_event = 1;
2172 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2173 events->sctp_authentication_event = 1;
2175 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2176 events->sctp_sender_dry_event = 1;
2178 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2179 events->sctp_stream_reset_event = 1;
2180 SCTP_INP_RUNLOCK(inp);
2181 *optsize = sizeof(struct sctp_event_subscribe);
2184 case SCTP_ADAPTATION_LAYER:
2188 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2190 SCTP_INP_RLOCK(inp);
2191 *value = inp->sctp_ep.adaptation_layer_indicator;
2192 SCTP_INP_RUNLOCK(inp);
2193 *optsize = sizeof(uint32_t);
2196 case SCTP_SET_INITIAL_DBG_SEQ:
2200 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2201 SCTP_INP_RLOCK(inp);
2202 *value = inp->sctp_ep.initial_sequence_debug;
2203 SCTP_INP_RUNLOCK(inp);
2204 *optsize = sizeof(uint32_t);
2207 case SCTP_GET_LOCAL_ADDR_SIZE:
2211 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2212 SCTP_INP_RLOCK(inp);
2213 *value = sctp_count_max_addresses(inp);
2214 SCTP_INP_RUNLOCK(inp);
2215 *optsize = sizeof(uint32_t);
2218 case SCTP_GET_REMOTE_ADDR_SIZE:
2222 struct sctp_nets *net;
2224 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2225 /* FIXME MT: change to sctp_assoc_value? */
2226 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2230 /* Count the sizes */
2231 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2232 switch (net->ro._l_addr.sa.sa_family) {
2236 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2237 size += sizeof(struct sockaddr_in6);
2239 size += sizeof(struct sockaddr_in);
2242 size += sizeof(struct sockaddr_in);
2248 size += sizeof(struct sockaddr_in6);
2255 SCTP_TCB_UNLOCK(stcb);
2256 *value = (uint32_t) size;
2257 *optsize = sizeof(uint32_t);
2259 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2264 case SCTP_GET_PEER_ADDRESSES:
2266 * Get the address information, an array is passed in to
2267 * fill up we pack it.
2271 struct sockaddr_storage *sas;
2272 struct sctp_nets *net;
2273 struct sctp_getaddresses *saddr;
2275 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2276 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2279 left = (*optsize) - sizeof(struct sctp_getaddresses);
2280 *optsize = sizeof(struct sctp_getaddresses);
2281 sas = (struct sockaddr_storage *)&saddr->addr[0];
2283 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2284 switch (net->ro._l_addr.sa.sa_family) {
2288 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2289 cpsz = sizeof(struct sockaddr_in6);
2291 cpsz = sizeof(struct sockaddr_in);
2294 cpsz = sizeof(struct sockaddr_in);
2300 cpsz = sizeof(struct sockaddr_in6);
2311 /* not enough room. */
2314 #if defined(INET) && defined(INET6)
2315 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2316 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2317 /* Must map the address */
2318 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2319 (struct sockaddr_in6 *)sas);
2321 memcpy(sas, &net->ro._l_addr, cpsz);
2324 memcpy(sas, &net->ro._l_addr, cpsz);
2326 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2328 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2332 SCTP_TCB_UNLOCK(stcb);
2334 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2339 case SCTP_GET_LOCAL_ADDRESSES:
2341 size_t limit, actual;
2342 struct sockaddr_storage *sas;
2343 struct sctp_getaddresses *saddr;
2345 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2346 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2348 sas = (struct sockaddr_storage *)&saddr->addr[0];
2349 limit = *optsize - sizeof(sctp_assoc_t);
2350 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2352 SCTP_TCB_UNLOCK(stcb);
2354 *optsize = sizeof(struct sockaddr_storage) + actual;
2357 case SCTP_PEER_ADDR_PARAMS:
2359 struct sctp_paddrparams *paddrp;
2360 struct sctp_nets *net;
2361 struct sockaddr *addr;
2363 #if defined(INET) && defined(INET6)
2364 struct sockaddr_in sin_store;
2368 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2369 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2371 #if defined(INET) && defined(INET6)
2372 if (paddrp->spp_address.ss_family == AF_INET6) {
2373 struct sockaddr_in6 *sin6;
2375 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2376 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2377 in6_sin6_2_sin(&sin_store, sin6);
2378 addr = (struct sockaddr *)&sin_store;
2380 addr = (struct sockaddr *)&paddrp->spp_address;
2383 addr = (struct sockaddr *)&paddrp->spp_address;
2386 addr = (struct sockaddr *)&paddrp->spp_address;
2389 net = sctp_findnet(stcb, addr);
2392 * We increment here since
2393 * sctp_findassociation_ep_addr() wil do a
2394 * decrement if it finds the stcb as long as
2395 * the locked tcb (last argument) is NOT a
2399 SCTP_INP_INCR_REF(inp);
2400 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2402 SCTP_INP_DECR_REF(inp);
2405 if ((stcb != NULL) && (net == NULL)) {
2407 if (addr->sa_family == AF_INET) {
2408 struct sockaddr_in *sin;
2410 sin = (struct sockaddr_in *)addr;
2411 if (sin->sin_addr.s_addr != INADDR_ANY) {
2413 SCTP_TCB_UNLOCK(stcb);
2414 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2420 if (addr->sa_family == AF_INET6) {
2421 struct sockaddr_in6 *sin6;
2423 sin6 = (struct sockaddr_in6 *)addr;
2424 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2426 SCTP_TCB_UNLOCK(stcb);
2427 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2433 error = EAFNOSUPPORT;
2434 SCTP_TCB_UNLOCK(stcb);
2435 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2440 /* Applies to the specific association */
2441 paddrp->spp_flags = 0;
2443 paddrp->spp_hbinterval = net->heart_beat_delay;
2444 paddrp->spp_pathmaxrxt = net->failure_threshold;
2445 paddrp->spp_pathmtu = net->mtu;
2446 switch (net->ro._l_addr.sa.sa_family) {
2449 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2454 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2460 /* get flags for HB */
2461 if (net->dest_state & SCTP_ADDR_NOHB) {
2462 paddrp->spp_flags |= SPP_HB_DISABLE;
2464 paddrp->spp_flags |= SPP_HB_ENABLE;
2466 /* get flags for PMTU */
2467 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2468 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2470 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2472 if (net->dscp & 0x01) {
2473 paddrp->spp_dscp = net->dscp & 0xfc;
2474 paddrp->spp_flags |= SPP_DSCP;
2477 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2478 (net->flowlabel & 0x80000000)) {
2479 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2480 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2485 * No destination so return default
2488 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2489 paddrp->spp_pathmtu = 0;
2490 if (stcb->asoc.default_dscp & 0x01) {
2491 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2492 paddrp->spp_flags |= SPP_DSCP;
2495 if (stcb->asoc.default_flowlabel & 0x80000000) {
2496 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2497 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2500 /* default settings should be these */
2501 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2502 paddrp->spp_flags |= SPP_HB_DISABLE;
2504 paddrp->spp_flags |= SPP_HB_ENABLE;
2506 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2507 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2509 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2511 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2513 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2514 SCTP_TCB_UNLOCK(stcb);
2516 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2517 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2518 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2519 /* Use endpoint defaults */
2520 SCTP_INP_RLOCK(inp);
2521 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2522 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2523 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2524 /* get inp's default */
2525 if (inp->sctp_ep.default_dscp & 0x01) {
2526 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2527 paddrp->spp_flags |= SPP_DSCP;
2530 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2531 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2532 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2533 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2536 /* can't return this */
2537 paddrp->spp_pathmtu = 0;
2539 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2540 paddrp->spp_flags |= SPP_HB_ENABLE;
2542 paddrp->spp_flags |= SPP_HB_DISABLE;
2544 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2545 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2547 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2549 SCTP_INP_RUNLOCK(inp);
2551 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2556 *optsize = sizeof(struct sctp_paddrparams);
2560 case SCTP_GET_PEER_ADDR_INFO:
2562 struct sctp_paddrinfo *paddri;
2563 struct sctp_nets *net;
2564 struct sockaddr *addr;
2566 #if defined(INET) && defined(INET6)
2567 struct sockaddr_in sin_store;
2571 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2572 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2574 #if defined(INET) && defined(INET6)
2575 if (paddri->spinfo_address.ss_family == AF_INET6) {
2576 struct sockaddr_in6 *sin6;
2578 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2579 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2580 in6_sin6_2_sin(&sin_store, sin6);
2581 addr = (struct sockaddr *)&sin_store;
2583 addr = (struct sockaddr *)&paddri->spinfo_address;
2586 addr = (struct sockaddr *)&paddri->spinfo_address;
2589 addr = (struct sockaddr *)&paddri->spinfo_address;
2592 net = sctp_findnet(stcb, addr);
2595 * We increment here since
2596 * sctp_findassociation_ep_addr() wil do a
2597 * decrement if it finds the stcb as long as
2598 * the locked tcb (last argument) is NOT a
2602 SCTP_INP_INCR_REF(inp);
2603 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2605 SCTP_INP_DECR_REF(inp);
2609 if ((stcb != NULL) && (net != NULL)) {
2610 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2611 /* It's unconfirmed */
2612 paddri->spinfo_state = SCTP_UNCONFIRMED;
2613 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2615 paddri->spinfo_state = SCTP_ACTIVE;
2618 paddri->spinfo_state = SCTP_INACTIVE;
2620 paddri->spinfo_cwnd = net->cwnd;
2621 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2622 paddri->spinfo_rto = net->RTO;
2623 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2624 paddri->spinfo_mtu = net->mtu;
2625 switch (addr->sa_family) {
2628 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2633 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2639 SCTP_TCB_UNLOCK(stcb);
2640 *optsize = sizeof(struct sctp_paddrinfo);
2643 SCTP_TCB_UNLOCK(stcb);
2645 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2650 case SCTP_PCB_STATUS:
2652 struct sctp_pcbinfo *spcb;
2654 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2655 sctp_fill_pcbinfo(spcb);
2656 *optsize = sizeof(struct sctp_pcbinfo);
2661 struct sctp_nets *net;
2662 struct sctp_status *sstat;
2664 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2665 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2668 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2672 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2673 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2674 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2675 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2677 * We can't include chunks that have been passed to
2678 * the socket layer. Only things in queue.
2680 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2681 stcb->asoc.cnt_on_all_streams);
2684 sstat->sstat_instrms = stcb->asoc.streamincnt;
2685 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2686 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2687 memcpy(&sstat->sstat_primary.spinfo_address,
2688 &stcb->asoc.primary_destination->ro._l_addr,
2689 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2690 net = stcb->asoc.primary_destination;
2691 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2693 * Again the user can get info from sctp_constants.h
2694 * for what the state of the network is.
2696 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2697 /* It's unconfirmed */
2698 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2699 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2701 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2704 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2706 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2707 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2708 sstat->sstat_primary.spinfo_rto = net->RTO;
2709 sstat->sstat_primary.spinfo_mtu = net->mtu;
2710 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2713 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2718 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2724 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2725 SCTP_TCB_UNLOCK(stcb);
2726 *optsize = sizeof(struct sctp_status);
2731 struct sctp_rtoinfo *srto;
2733 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2734 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2737 srto->srto_initial = stcb->asoc.initial_rto;
2738 srto->srto_max = stcb->asoc.maxrto;
2739 srto->srto_min = stcb->asoc.minrto;
2740 SCTP_TCB_UNLOCK(stcb);
2742 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2743 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2744 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2745 SCTP_INP_RLOCK(inp);
2746 srto->srto_initial = inp->sctp_ep.initial_rto;
2747 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2748 srto->srto_min = inp->sctp_ep.sctp_minrto;
2749 SCTP_INP_RUNLOCK(inp);
2751 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2756 *optsize = sizeof(struct sctp_rtoinfo);
2762 struct sctp_timeouts *stimo;
2764 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2765 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2768 stimo->stimo_init = stcb->asoc.timoinit;
2769 stimo->stimo_data = stcb->asoc.timodata;
2770 stimo->stimo_sack = stcb->asoc.timosack;
2771 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2772 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2773 stimo->stimo_cookie = stcb->asoc.timocookie;
2774 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2775 SCTP_TCB_UNLOCK(stcb);
2776 *optsize = sizeof(struct sctp_timeouts);
2778 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2783 case SCTP_ASSOCINFO:
2785 struct sctp_assocparams *sasoc;
2787 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2788 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2791 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2792 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2793 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2794 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2795 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2796 SCTP_TCB_UNLOCK(stcb);
2798 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2799 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2800 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2801 SCTP_INP_RLOCK(inp);
2802 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2803 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2804 sasoc->sasoc_number_peer_destinations = 0;
2805 sasoc->sasoc_peer_rwnd = 0;
2806 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2807 SCTP_INP_RUNLOCK(inp);
2809 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2814 *optsize = sizeof(struct sctp_assocparams);
2818 case SCTP_DEFAULT_SEND_PARAM:
2820 struct sctp_sndrcvinfo *s_info;
2822 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2823 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2826 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2827 SCTP_TCB_UNLOCK(stcb);
2829 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2830 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2831 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2832 SCTP_INP_RLOCK(inp);
2833 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2834 SCTP_INP_RUNLOCK(inp);
2836 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2841 *optsize = sizeof(struct sctp_sndrcvinfo);
2847 struct sctp_initmsg *sinit;
2849 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2850 SCTP_INP_RLOCK(inp);
2851 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2852 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2853 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2854 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2855 SCTP_INP_RUNLOCK(inp);
2856 *optsize = sizeof(struct sctp_initmsg);
2859 case SCTP_PRIMARY_ADDR:
2860 /* we allow a "get" operation on this */
2862 struct sctp_setprim *ssp;
2864 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2865 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2868 union sctp_sockstore *addr;
2870 addr = &stcb->asoc.primary_destination->ro._l_addr;
2871 switch (addr->sa.sa_family) {
2875 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2876 in6_sin_2_v4mapsin6(&addr->sin,
2877 (struct sockaddr_in6 *)&ssp->ssp_addr);
2879 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2882 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2888 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2894 SCTP_TCB_UNLOCK(stcb);
2895 *optsize = sizeof(struct sctp_setprim);
2897 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2902 case SCTP_HMAC_IDENT:
2904 struct sctp_hmacalgo *shmac;
2905 sctp_hmaclist_t *hmaclist;
2909 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2911 SCTP_INP_RLOCK(inp);
2912 hmaclist = inp->sctp_ep.local_hmacs;
2913 if (hmaclist == NULL) {
2914 /* no HMACs to return */
2915 *optsize = sizeof(*shmac);
2916 SCTP_INP_RUNLOCK(inp);
2919 /* is there room for all of the hmac ids? */
2920 size = sizeof(*shmac) + (hmaclist->num_algo *
2921 sizeof(shmac->shmac_idents[0]));
2922 if ((size_t)(*optsize) < size) {
2923 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2925 SCTP_INP_RUNLOCK(inp);
2928 /* copy in the list */
2929 shmac->shmac_number_of_idents = hmaclist->num_algo;
2930 for (i = 0; i < hmaclist->num_algo; i++) {
2931 shmac->shmac_idents[i] = hmaclist->hmac[i];
2933 SCTP_INP_RUNLOCK(inp);
2937 case SCTP_AUTH_ACTIVE_KEY:
2939 struct sctp_authkeyid *scact;
2941 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2942 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2945 /* get the active key on the assoc */
2946 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2947 SCTP_TCB_UNLOCK(stcb);
2949 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2950 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2951 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2952 /* get the endpoint active key */
2953 SCTP_INP_RLOCK(inp);
2954 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2955 SCTP_INP_RUNLOCK(inp);
2957 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2962 *optsize = sizeof(struct sctp_authkeyid);
2966 case SCTP_LOCAL_AUTH_CHUNKS:
2968 struct sctp_authchunks *sac;
2969 sctp_auth_chklist_t *chklist = NULL;
2972 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2973 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2976 /* get off the assoc */
2977 chklist = stcb->asoc.local_auth_chunks;
2978 /* is there enough space? */
2979 size = sctp_auth_get_chklist_size(chklist);
2980 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2982 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2984 /* copy in the chunks */
2985 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2986 sac->gauth_number_of_chunks = (uint32_t) size;
2987 *optsize = sizeof(struct sctp_authchunks) + size;
2989 SCTP_TCB_UNLOCK(stcb);
2991 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2992 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2993 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2994 /* get off the endpoint */
2995 SCTP_INP_RLOCK(inp);
2996 chklist = inp->sctp_ep.local_auth_chunks;
2997 /* is there enough space? */
2998 size = sctp_auth_get_chklist_size(chklist);
2999 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
3001 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3003 /* copy in the chunks */
3004 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
3005 sac->gauth_number_of_chunks = (uint32_t) size;
3006 *optsize = sizeof(struct sctp_authchunks) + size;
3008 SCTP_INP_RUNLOCK(inp);
3010 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3016 case SCTP_PEER_AUTH_CHUNKS:
3018 struct sctp_authchunks *sac;
3019 sctp_auth_chklist_t *chklist = NULL;
3022 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
3023 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
3026 /* get off the assoc */
3027 chklist = stcb->asoc.peer_auth_chunks;
3028 /* is there enough space? */
3029 size = sctp_auth_get_chklist_size(chklist);
3030 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
3032 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3034 /* copy in the chunks */
3035 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
3036 sac->gauth_number_of_chunks = (uint32_t) size;
3037 *optsize = sizeof(struct sctp_authchunks) + size;
3039 SCTP_TCB_UNLOCK(stcb);
3041 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3048 struct sctp_event *event;
3049 uint32_t event_type;
3051 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3052 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3054 switch (event->se_type) {
3055 case SCTP_ASSOC_CHANGE:
3056 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3058 case SCTP_PEER_ADDR_CHANGE:
3059 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3061 case SCTP_REMOTE_ERROR:
3062 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3064 case SCTP_SEND_FAILED:
3065 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3067 case SCTP_SHUTDOWN_EVENT:
3068 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3070 case SCTP_ADAPTATION_INDICATION:
3071 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3073 case SCTP_PARTIAL_DELIVERY_EVENT:
3074 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3076 case SCTP_AUTHENTICATION_EVENT:
3077 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3079 case SCTP_STREAM_RESET_EVENT:
3080 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3082 case SCTP_SENDER_DRY_EVENT:
3083 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3085 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3087 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3090 case SCTP_ASSOC_RESET_EVENT:
3091 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3093 case SCTP_STREAM_CHANGE_EVENT:
3094 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3096 case SCTP_SEND_FAILED_EVENT:
3097 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3101 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3105 if (event_type > 0) {
3107 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3108 SCTP_TCB_UNLOCK(stcb);
3110 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3111 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3112 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3113 SCTP_INP_RLOCK(inp);
3114 event->se_on = sctp_is_feature_on(inp, event_type);
3115 SCTP_INP_RUNLOCK(inp);
3117 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3123 *optsize = sizeof(struct sctp_event);
3127 case SCTP_RECVRCVINFO:
3131 if (*optsize < sizeof(int)) {
3132 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3135 SCTP_INP_RLOCK(inp);
3136 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3137 SCTP_INP_RUNLOCK(inp);
3140 /* return the option value */
3141 *(int *)optval = onoff;
3142 *optsize = sizeof(int);
3146 case SCTP_RECVNXTINFO:
3150 if (*optsize < sizeof(int)) {
3151 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3154 SCTP_INP_RLOCK(inp);
3155 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3156 SCTP_INP_RUNLOCK(inp);
3159 /* return the option value */
3160 *(int *)optval = onoff;
3161 *optsize = sizeof(int);
3165 case SCTP_DEFAULT_SNDINFO:
3167 struct sctp_sndinfo *info;
3169 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3170 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3173 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3174 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3175 info->snd_flags &= 0xfff0;
3176 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3177 info->snd_context = stcb->asoc.def_send.sinfo_context;
3178 SCTP_TCB_UNLOCK(stcb);
3180 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3181 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3182 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3183 SCTP_INP_RLOCK(inp);
3184 info->snd_sid = inp->def_send.sinfo_stream;
3185 info->snd_flags = inp->def_send.sinfo_flags;
3186 info->snd_flags &= 0xfff0;
3187 info->snd_ppid = inp->def_send.sinfo_ppid;
3188 info->snd_context = inp->def_send.sinfo_context;
3189 SCTP_INP_RUNLOCK(inp);
3191 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3196 *optsize = sizeof(struct sctp_sndinfo);
3200 case SCTP_DEFAULT_PRINFO:
3202 struct sctp_default_prinfo *info;
3204 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3205 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3208 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3209 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3210 SCTP_TCB_UNLOCK(stcb);
3212 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3213 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3214 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3215 SCTP_INP_RLOCK(inp);
3216 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3217 info->pr_value = inp->def_send.sinfo_timetolive;
3218 SCTP_INP_RUNLOCK(inp);
3220 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3225 *optsize = sizeof(struct sctp_default_prinfo);
3229 case SCTP_PEER_ADDR_THLDS:
3231 struct sctp_paddrthlds *thlds;
3232 struct sctp_nets *net;
3233 struct sockaddr *addr;
3235 #if defined(INET) && defined(INET6)
3236 struct sockaddr_in sin_store;
3240 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3241 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3243 #if defined(INET) && defined(INET6)
3244 if (thlds->spt_address.ss_family == AF_INET6) {
3245 struct sockaddr_in6 *sin6;
3247 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3248 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3249 in6_sin6_2_sin(&sin_store, sin6);
3250 addr = (struct sockaddr *)&sin_store;
3252 addr = (struct sockaddr *)&thlds->spt_address;
3255 addr = (struct sockaddr *)&thlds->spt_address;
3258 addr = (struct sockaddr *)&thlds->spt_address;
3261 net = sctp_findnet(stcb, addr);
3264 * We increment here since
3265 * sctp_findassociation_ep_addr() wil do a
3266 * decrement if it finds the stcb as long as
3267 * the locked tcb (last argument) is NOT a
3271 SCTP_INP_INCR_REF(inp);
3272 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3274 SCTP_INP_DECR_REF(inp);
3277 if ((stcb != NULL) && (net == NULL)) {
3279 if (addr->sa_family == AF_INET) {
3280 struct sockaddr_in *sin;
3282 sin = (struct sockaddr_in *)addr;
3283 if (sin->sin_addr.s_addr != INADDR_ANY) {
3285 SCTP_TCB_UNLOCK(stcb);
3286 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3292 if (addr->sa_family == AF_INET6) {
3293 struct sockaddr_in6 *sin6;
3295 sin6 = (struct sockaddr_in6 *)addr;
3296 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3298 SCTP_TCB_UNLOCK(stcb);
3299 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3305 error = EAFNOSUPPORT;
3306 SCTP_TCB_UNLOCK(stcb);
3307 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3313 thlds->spt_pathmaxrxt = net->failure_threshold;
3314 thlds->spt_pathpfthld = net->pf_threshold;
3316 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3317 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3319 thlds->spt_assoc_id = sctp_get_associd(stcb);
3320 SCTP_TCB_UNLOCK(stcb);
3322 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3323 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3324 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3325 /* Use endpoint defaults */
3326 SCTP_INP_RLOCK(inp);
3327 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3328 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3329 SCTP_INP_RUNLOCK(inp);
3331 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3336 *optsize = sizeof(struct sctp_paddrthlds);
3340 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3342 struct sctp_udpencaps *encaps;
3343 struct sctp_nets *net;
3344 struct sockaddr *addr;
3346 #if defined(INET) && defined(INET6)
3347 struct sockaddr_in sin_store;
3351 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3352 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3354 #if defined(INET) && defined(INET6)
3355 if (encaps->sue_address.ss_family == AF_INET6) {
3356 struct sockaddr_in6 *sin6;
3358 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3359 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3360 in6_sin6_2_sin(&sin_store, sin6);
3361 addr = (struct sockaddr *)&sin_store;
3363 addr = (struct sockaddr *)&encaps->sue_address;
3366 addr = (struct sockaddr *)&encaps->sue_address;
3369 addr = (struct sockaddr *)&encaps->sue_address;
3372 net = sctp_findnet(stcb, addr);
3375 * We increment here since
3376 * sctp_findassociation_ep_addr() wil do a
3377 * decrement if it finds the stcb as long as
3378 * the locked tcb (last argument) is NOT a
3382 SCTP_INP_INCR_REF(inp);
3383 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3385 SCTP_INP_DECR_REF(inp);
3388 if ((stcb != NULL) && (net == NULL)) {
3390 if (addr->sa_family == AF_INET) {
3391 struct sockaddr_in *sin;
3393 sin = (struct sockaddr_in *)addr;
3394 if (sin->sin_addr.s_addr != INADDR_ANY) {
3396 SCTP_TCB_UNLOCK(stcb);
3397 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3403 if (addr->sa_family == AF_INET6) {
3404 struct sockaddr_in6 *sin6;
3406 sin6 = (struct sockaddr_in6 *)addr;
3407 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3409 SCTP_TCB_UNLOCK(stcb);
3410 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3416 error = EAFNOSUPPORT;
3417 SCTP_TCB_UNLOCK(stcb);
3418 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3424 encaps->sue_port = net->port;
3426 encaps->sue_port = stcb->asoc.port;
3428 SCTP_TCB_UNLOCK(stcb);
3430 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3431 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3432 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3433 SCTP_INP_RLOCK(inp);
3434 encaps->sue_port = inp->sctp_ep.port;
3435 SCTP_INP_RUNLOCK(inp);
3437 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3442 *optsize = sizeof(struct sctp_udpencaps);
3446 case SCTP_ECN_SUPPORTED:
3448 struct sctp_assoc_value *av;
3450 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3451 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3454 av->assoc_value = stcb->asoc.ecn_supported;
3455 SCTP_TCB_UNLOCK(stcb);
3457 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3458 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3459 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3460 SCTP_INP_RLOCK(inp);
3461 av->assoc_value = inp->ecn_supported;
3462 SCTP_INP_RUNLOCK(inp);
3464 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3469 *optsize = sizeof(struct sctp_assoc_value);
3473 case SCTP_PR_SUPPORTED:
3475 struct sctp_assoc_value *av;
3477 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3478 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3481 av->assoc_value = stcb->asoc.prsctp_supported;
3482 SCTP_TCB_UNLOCK(stcb);
3484 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3485 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3486 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3487 SCTP_INP_RLOCK(inp);
3488 av->assoc_value = inp->prsctp_supported;
3489 SCTP_INP_RUNLOCK(inp);
3491 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3496 *optsize = sizeof(struct sctp_assoc_value);
3500 case SCTP_AUTH_SUPPORTED:
3502 struct sctp_assoc_value *av;
3504 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3505 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3508 av->assoc_value = stcb->asoc.auth_supported;
3509 SCTP_TCB_UNLOCK(stcb);
3511 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3512 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3513 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3514 SCTP_INP_RLOCK(inp);
3515 av->assoc_value = inp->auth_supported;
3516 SCTP_INP_RUNLOCK(inp);
3518 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3523 *optsize = sizeof(struct sctp_assoc_value);
3527 case SCTP_ASCONF_SUPPORTED:
3529 struct sctp_assoc_value *av;
3531 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3532 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3535 av->assoc_value = stcb->asoc.asconf_supported;
3536 SCTP_TCB_UNLOCK(stcb);
3538 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3539 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3540 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3541 SCTP_INP_RLOCK(inp);
3542 av->assoc_value = inp->asconf_supported;
3543 SCTP_INP_RUNLOCK(inp);
3545 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3550 *optsize = sizeof(struct sctp_assoc_value);
3554 case SCTP_RECONFIG_SUPPORTED:
3556 struct sctp_assoc_value *av;
3558 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3559 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3562 av->assoc_value = stcb->asoc.reconfig_supported;
3563 SCTP_TCB_UNLOCK(stcb);
3565 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3566 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3567 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3568 SCTP_INP_RLOCK(inp);
3569 av->assoc_value = inp->reconfig_supported;
3570 SCTP_INP_RUNLOCK(inp);
3572 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3577 *optsize = sizeof(struct sctp_assoc_value);
3581 case SCTP_NRSACK_SUPPORTED:
3583 struct sctp_assoc_value *av;
3585 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3586 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3589 av->assoc_value = stcb->asoc.nrsack_supported;
3590 SCTP_TCB_UNLOCK(stcb);
3592 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3593 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3594 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3595 SCTP_INP_RLOCK(inp);
3596 av->assoc_value = inp->nrsack_supported;
3597 SCTP_INP_RUNLOCK(inp);
3599 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3604 *optsize = sizeof(struct sctp_assoc_value);
3608 case SCTP_PKTDROP_SUPPORTED:
3610 struct sctp_assoc_value *av;
3612 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3613 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3616 av->assoc_value = stcb->asoc.pktdrop_supported;
3617 SCTP_TCB_UNLOCK(stcb);
3619 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3620 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3621 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3622 SCTP_INP_RLOCK(inp);
3623 av->assoc_value = inp->pktdrop_supported;
3624 SCTP_INP_RUNLOCK(inp);
3626 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3631 *optsize = sizeof(struct sctp_assoc_value);
3635 case SCTP_ENABLE_STREAM_RESET:
3637 struct sctp_assoc_value *av;
3639 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3640 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3643 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3644 SCTP_TCB_UNLOCK(stcb);
3646 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3647 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3648 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3649 SCTP_INP_RLOCK(inp);
3650 av->assoc_value = (uint32_t) inp->local_strreset_support;
3651 SCTP_INP_RUNLOCK(inp);
3653 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3658 *optsize = sizeof(struct sctp_assoc_value);
3662 case SCTP_PR_STREAM_STATUS:
3664 struct sctp_prstatus *sprstat;
3668 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3669 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3671 sid = sprstat->sprstat_sid;
3672 policy = sprstat->sprstat_policy;
3673 #if defined(SCTP_DETAILED_STR_STATS)
3674 if ((stcb != NULL) &&
3675 (sid < stcb->asoc.streamoutcnt) &&
3676 (policy != SCTP_PR_SCTP_NONE) &&
3677 ((policy <= SCTP_PR_SCTP_MAX) ||
3678 (policy == SCTP_PR_SCTP_ALL))) {
3679 if (policy == SCTP_PR_SCTP_ALL) {
3680 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3681 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3683 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3684 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3687 if ((stcb != NULL) &&
3688 (sid < stcb->asoc.streamoutcnt) &&
3689 (policy == SCTP_PR_SCTP_ALL)) {
3690 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3691 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3693 SCTP_TCB_UNLOCK(stcb);
3694 *optsize = sizeof(struct sctp_prstatus);
3696 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3701 case SCTP_PR_ASSOC_STATUS:
3703 struct sctp_prstatus *sprstat;
3706 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3707 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3709 policy = sprstat->sprstat_policy;
3710 if ((stcb != NULL) &&
3711 (policy != SCTP_PR_SCTP_NONE) &&
3712 ((policy <= SCTP_PR_SCTP_MAX) ||
3713 (policy == SCTP_PR_SCTP_ALL))) {
3714 if (policy == SCTP_PR_SCTP_ALL) {
3715 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3716 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3718 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3719 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3721 SCTP_TCB_UNLOCK(stcb);
3722 *optsize = sizeof(struct sctp_prstatus);
3724 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3731 struct sctp_assoc_value *av;
3733 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3734 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3737 av->assoc_value = stcb->asoc.max_cwnd;
3738 SCTP_TCB_UNLOCK(stcb);
3740 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3741 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3742 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3743 SCTP_INP_RLOCK(inp);
3744 av->assoc_value = inp->max_cwnd;
3745 SCTP_INP_RUNLOCK(inp);
3747 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3752 *optsize = sizeof(struct sctp_assoc_value);
3757 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3758 error = ENOPROTOOPT;
3760 } /* end switch (sopt->sopt_name) */
3768 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3773 struct sctp_tcb *stcb = NULL;
3774 struct sctp_inpcb *inp = NULL;
3777 if (optval == NULL) {
3778 SCTP_PRINTF("optval is NULL\n");
3779 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3782 inp = (struct sctp_inpcb *)so->so_pcb;
3784 SCTP_PRINTF("inp is NULL?\n");
3785 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3788 vrf_id = inp->def_vrf_id;
3793 case SCTP_AUTOCLOSE:
3794 case SCTP_AUTO_ASCONF:
3795 case SCTP_EXPLICIT_EOR:
3796 case SCTP_DISABLE_FRAGMENTS:
3797 case SCTP_USE_EXT_RCVINFO:
3798 case SCTP_I_WANT_MAPPED_V4_ADDR:
3799 /* copy in the option value */
3800 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3805 case SCTP_DISABLE_FRAGMENTS:
3806 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3808 case SCTP_AUTO_ASCONF:
3810 * NOTE: we don't really support this flag
3812 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3813 /* only valid for bound all sockets */
3814 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3816 /* forbidden by admin */
3817 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3820 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3822 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3826 case SCTP_EXPLICIT_EOR:
3827 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3829 case SCTP_USE_EXT_RCVINFO:
3830 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3832 case SCTP_I_WANT_MAPPED_V4_ADDR:
3833 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3834 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3836 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3841 set_opt = SCTP_PCB_FLAGS_NODELAY;
3843 case SCTP_AUTOCLOSE:
3844 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3845 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3846 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3849 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3851 * The value is in ticks. Note this does not effect
3852 * old associations, only new ones.
3854 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3857 SCTP_INP_WLOCK(inp);
3859 sctp_feature_on(inp, set_opt);
3861 sctp_feature_off(inp, set_opt);
3863 SCTP_INP_WUNLOCK(inp);
3865 case SCTP_REUSE_PORT:
3867 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3868 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3869 /* Can't set it after we are bound */
3873 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3874 /* Can't do this for a 1-m socket */
3879 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3881 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3884 case SCTP_PARTIAL_DELIVERY_POINT:
3888 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3889 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3890 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3894 inp->partial_delivery_point = *value;
3897 case SCTP_FRAGMENT_INTERLEAVE:
3898 /* not yet until we re-write sctp_recvmsg() */
3902 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3903 if (*level == SCTP_FRAG_LEVEL_2) {
3904 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3905 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3906 } else if (*level == SCTP_FRAG_LEVEL_1) {
3907 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3908 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3909 } else if (*level == SCTP_FRAG_LEVEL_0) {
3910 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3911 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3914 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3919 case SCTP_INTERLEAVING_SUPPORTED:
3921 struct sctp_assoc_value *av;
3923 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3924 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3927 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3929 SCTP_TCB_UNLOCK(stcb);
3931 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3932 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3933 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3934 SCTP_INP_WLOCK(inp);
3935 if (av->assoc_value == 0) {
3936 inp->idata_supported = 0;
3938 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3939 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3940 inp->idata_supported = 1;
3948 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3952 SCTP_INP_WUNLOCK(inp);
3954 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3960 case SCTP_CMT_ON_OFF:
3961 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3962 struct sctp_assoc_value *av;
3964 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3965 if (av->assoc_value > SCTP_CMT_MAX) {
3966 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3970 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3972 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3973 SCTP_TCB_UNLOCK(stcb);
3975 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3976 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3977 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3978 (av->assoc_id == SCTP_ALL_ASSOC)) {
3979 SCTP_INP_WLOCK(inp);
3980 inp->sctp_cmt_on_off = av->assoc_value;
3981 SCTP_INP_WUNLOCK(inp);
3983 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3984 (av->assoc_id == SCTP_ALL_ASSOC)) {
3985 SCTP_INP_RLOCK(inp);
3986 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3987 SCTP_TCB_LOCK(stcb);
3988 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3989 SCTP_TCB_UNLOCK(stcb);
3991 SCTP_INP_RUNLOCK(inp);
3995 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3996 error = ENOPROTOOPT;
3999 case SCTP_PLUGGABLE_CC:
4001 struct sctp_assoc_value *av;
4002 struct sctp_nets *net;
4004 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4005 if ((av->assoc_value != SCTP_CC_RFC2581) &&
4006 (av->assoc_value != SCTP_CC_HSTCP) &&
4007 (av->assoc_value != SCTP_CC_HTCP) &&
4008 (av->assoc_value != SCTP_CC_RTCC)) {
4009 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4013 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4015 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4016 stcb->asoc.congestion_control_module = av->assoc_value;
4017 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4018 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4019 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4022 SCTP_TCB_UNLOCK(stcb);
4024 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4025 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4026 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4027 (av->assoc_id == SCTP_ALL_ASSOC)) {
4028 SCTP_INP_WLOCK(inp);
4029 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
4030 SCTP_INP_WUNLOCK(inp);
4032 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4033 (av->assoc_id == SCTP_ALL_ASSOC)) {
4034 SCTP_INP_RLOCK(inp);
4035 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4036 SCTP_TCB_LOCK(stcb);
4037 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4038 stcb->asoc.congestion_control_module = av->assoc_value;
4039 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4040 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4041 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4044 SCTP_TCB_UNLOCK(stcb);
4046 SCTP_INP_RUNLOCK(inp);
4051 case SCTP_CC_OPTION:
4053 struct sctp_cc_option *cc_opt;
4055 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4056 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4058 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
4059 SCTP_INP_RLOCK(inp);
4060 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4061 SCTP_TCB_LOCK(stcb);
4062 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4063 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4065 SCTP_TCB_UNLOCK(stcb);
4067 SCTP_INP_RUNLOCK(inp);
4072 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4075 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4078 SCTP_TCB_UNLOCK(stcb);
4082 case SCTP_PLUGGABLE_SS:
4084 struct sctp_assoc_value *av;
4086 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4087 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4088 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4089 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4090 (av->assoc_value != SCTP_SS_PRIORITY) &&
4091 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4092 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4093 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4097 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4099 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4100 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4101 stcb->asoc.stream_scheduling_module = av->assoc_value;
4102 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4103 SCTP_TCB_UNLOCK(stcb);
4105 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4106 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4107 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4108 (av->assoc_id == SCTP_ALL_ASSOC)) {
4109 SCTP_INP_WLOCK(inp);
4110 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4111 SCTP_INP_WUNLOCK(inp);
4113 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4114 (av->assoc_id == SCTP_ALL_ASSOC)) {
4115 SCTP_INP_RLOCK(inp);
4116 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4117 SCTP_TCB_LOCK(stcb);
4118 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4119 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4120 stcb->asoc.stream_scheduling_module = av->assoc_value;
4121 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4122 SCTP_TCB_UNLOCK(stcb);
4124 SCTP_INP_RUNLOCK(inp);
4131 struct sctp_stream_value *av;
4133 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4134 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4136 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4137 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4138 av->stream_value) < 0)) {
4139 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4142 SCTP_TCB_UNLOCK(stcb);
4144 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4145 SCTP_INP_RLOCK(inp);
4146 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4147 SCTP_TCB_LOCK(stcb);
4148 if (av->stream_id < stcb->asoc.streamoutcnt) {
4149 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4151 &stcb->asoc.strmout[av->stream_id],
4154 SCTP_TCB_UNLOCK(stcb);
4156 SCTP_INP_RUNLOCK(inp);
4159 * Can't set stream value without
4162 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4168 case SCTP_CLR_STAT_LOG:
4169 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4174 struct sctp_assoc_value *av;
4176 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4177 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4180 stcb->asoc.context = av->assoc_value;
4181 SCTP_TCB_UNLOCK(stcb);
4183 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4184 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4185 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4186 (av->assoc_id == SCTP_ALL_ASSOC)) {
4187 SCTP_INP_WLOCK(inp);
4188 inp->sctp_context = av->assoc_value;
4189 SCTP_INP_WUNLOCK(inp);
4191 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4192 (av->assoc_id == SCTP_ALL_ASSOC)) {
4193 SCTP_INP_RLOCK(inp);
4194 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4195 SCTP_TCB_LOCK(stcb);
4196 stcb->asoc.context = av->assoc_value;
4197 SCTP_TCB_UNLOCK(stcb);
4199 SCTP_INP_RUNLOCK(inp);
4206 uint32_t *default_vrfid;
4208 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4209 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4210 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4214 inp->def_vrf_id = *default_vrfid;
4217 case SCTP_DEL_VRF_ID:
4219 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4223 case SCTP_ADD_VRF_ID:
4225 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4229 case SCTP_DELAYED_SACK:
4231 struct sctp_sack_info *sack;
4233 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4234 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4235 if (sack->sack_delay) {
4236 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4237 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4238 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4239 sack->sack_delay = TICKS_TO_MSEC(1);
4243 if (sack->sack_delay) {
4244 stcb->asoc.delayed_ack = sack->sack_delay;
4246 if (sack->sack_freq) {
4247 stcb->asoc.sack_freq = sack->sack_freq;
4249 SCTP_TCB_UNLOCK(stcb);
4251 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4252 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4253 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4254 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4255 SCTP_INP_WLOCK(inp);
4256 if (sack->sack_delay) {
4257 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4259 if (sack->sack_freq) {
4260 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4262 SCTP_INP_WUNLOCK(inp);
4264 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4265 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4266 SCTP_INP_RLOCK(inp);
4267 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4268 SCTP_TCB_LOCK(stcb);
4269 if (sack->sack_delay) {
4270 stcb->asoc.delayed_ack = sack->sack_delay;
4272 if (sack->sack_freq) {
4273 stcb->asoc.sack_freq = sack->sack_freq;
4275 SCTP_TCB_UNLOCK(stcb);
4277 SCTP_INP_RUNLOCK(inp);
4282 case SCTP_AUTH_CHUNK:
4284 struct sctp_authchunk *sauth;
4286 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4288 SCTP_INP_WLOCK(inp);
4289 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4290 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4293 SCTP_INP_WUNLOCK(inp);
4298 struct sctp_authkey *sca;
4299 struct sctp_keyhead *shared_keys;
4300 sctp_sharedkey_t *shared_key;
4301 sctp_key_t *key = NULL;
4304 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4305 if (sca->sca_keylength == 0) {
4306 size = optsize - sizeof(struct sctp_authkey);
4308 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4309 size = sca->sca_keylength;
4311 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4316 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4319 shared_keys = &stcb->asoc.shared_keys;
4320 /* clear the cached keys for this key id */
4321 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4323 * create the new shared key and
4327 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4329 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4331 SCTP_TCB_UNLOCK(stcb);
4335 shared_key = sctp_alloc_sharedkey();
4336 if (shared_key == NULL) {
4338 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4340 SCTP_TCB_UNLOCK(stcb);
4343 shared_key->key = key;
4344 shared_key->keyid = sca->sca_keynumber;
4345 error = sctp_insert_sharedkey(shared_keys, shared_key);
4346 SCTP_TCB_UNLOCK(stcb);
4348 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4349 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4350 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4351 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4352 SCTP_INP_WLOCK(inp);
4353 shared_keys = &inp->sctp_ep.shared_keys;
4355 * clear the cached keys on all
4356 * assocs for this key id
4358 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4360 * create the new shared key and
4364 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4366 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4368 SCTP_INP_WUNLOCK(inp);
4372 shared_key = sctp_alloc_sharedkey();
4373 if (shared_key == NULL) {
4375 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4377 SCTP_INP_WUNLOCK(inp);
4380 shared_key->key = key;
4381 shared_key->keyid = sca->sca_keynumber;
4382 error = sctp_insert_sharedkey(shared_keys, shared_key);
4383 SCTP_INP_WUNLOCK(inp);
4385 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4386 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4387 SCTP_INP_RLOCK(inp);
4388 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4389 SCTP_TCB_LOCK(stcb);
4390 shared_keys = &stcb->asoc.shared_keys;
4392 * clear the cached keys for
4395 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4397 * create the new shared key
4398 * and insert/replace it
4401 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4403 SCTP_TCB_UNLOCK(stcb);
4407 shared_key = sctp_alloc_sharedkey();
4408 if (shared_key == NULL) {
4410 SCTP_TCB_UNLOCK(stcb);
4413 shared_key->key = key;
4414 shared_key->keyid = sca->sca_keynumber;
4415 error = sctp_insert_sharedkey(shared_keys, shared_key);
4416 SCTP_TCB_UNLOCK(stcb);
4418 SCTP_INP_RUNLOCK(inp);
4423 case SCTP_HMAC_IDENT:
4425 struct sctp_hmacalgo *shmac;
4426 sctp_hmaclist_t *hmaclist;
4430 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4431 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4432 (shmac->shmac_number_of_idents > 0xffff)) {
4433 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4437 hmaclist = sctp_alloc_hmaclist((uint16_t) shmac->shmac_number_of_idents);
4438 if (hmaclist == NULL) {
4439 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4443 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4444 hmacid = shmac->shmac_idents[i];
4445 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4446 /* invalid HMACs were found */ ;
4447 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4449 sctp_free_hmaclist(hmaclist);
4450 goto sctp_set_hmac_done;
4453 for (i = 0; i < hmaclist->num_algo; i++) {
4454 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4455 /* already in list */
4459 if (i == hmaclist->num_algo) {
4460 /* not found in list */
4461 sctp_free_hmaclist(hmaclist);
4462 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4466 /* set it on the endpoint */
4467 SCTP_INP_WLOCK(inp);
4468 if (inp->sctp_ep.local_hmacs)
4469 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4470 inp->sctp_ep.local_hmacs = hmaclist;
4471 SCTP_INP_WUNLOCK(inp);
4475 case SCTP_AUTH_ACTIVE_KEY:
4477 struct sctp_authkeyid *scact;
4479 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4480 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4482 /* set the active key on the right place */
4484 /* set the active key on the assoc */
4485 if (sctp_auth_setactivekey(stcb,
4486 scact->scact_keynumber)) {
4487 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4488 SCTP_FROM_SCTP_USRREQ,
4492 SCTP_TCB_UNLOCK(stcb);
4494 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4495 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4496 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4497 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4498 SCTP_INP_WLOCK(inp);
4499 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4500 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4503 SCTP_INP_WUNLOCK(inp);
4505 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4506 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4507 SCTP_INP_RLOCK(inp);
4508 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4509 SCTP_TCB_LOCK(stcb);
4510 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4511 SCTP_TCB_UNLOCK(stcb);
4513 SCTP_INP_RUNLOCK(inp);
4518 case SCTP_AUTH_DELETE_KEY:
4520 struct sctp_authkeyid *scdel;
4522 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4523 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4525 /* delete the key from the right place */
4527 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4528 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4531 SCTP_TCB_UNLOCK(stcb);
4533 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4534 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4535 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4536 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4537 SCTP_INP_WLOCK(inp);
4538 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4539 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4542 SCTP_INP_WUNLOCK(inp);
4544 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4545 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4546 SCTP_INP_RLOCK(inp);
4547 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4548 SCTP_TCB_LOCK(stcb);
4549 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4550 SCTP_TCB_UNLOCK(stcb);
4552 SCTP_INP_RUNLOCK(inp);
4557 case SCTP_AUTH_DEACTIVATE_KEY:
4559 struct sctp_authkeyid *keyid;
4561 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4562 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4564 /* deactivate the key from the right place */
4566 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4567 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4570 SCTP_TCB_UNLOCK(stcb);
4572 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4573 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4574 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4575 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4576 SCTP_INP_WLOCK(inp);
4577 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4578 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4581 SCTP_INP_WUNLOCK(inp);
4583 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4584 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4585 SCTP_INP_RLOCK(inp);
4586 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4587 SCTP_TCB_LOCK(stcb);
4588 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4589 SCTP_TCB_UNLOCK(stcb);
4591 SCTP_INP_RUNLOCK(inp);
4596 case SCTP_ENABLE_STREAM_RESET:
4598 struct sctp_assoc_value *av;
4600 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4601 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4602 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4606 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4608 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4609 SCTP_TCB_UNLOCK(stcb);
4611 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4612 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4613 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4614 (av->assoc_id == SCTP_ALL_ASSOC)) {
4615 SCTP_INP_WLOCK(inp);
4616 inp->local_strreset_support = (uint8_t) av->assoc_value;
4617 SCTP_INP_WUNLOCK(inp);
4619 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4620 (av->assoc_id == SCTP_ALL_ASSOC)) {
4621 SCTP_INP_RLOCK(inp);
4622 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4623 SCTP_TCB_LOCK(stcb);
4624 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4625 SCTP_TCB_UNLOCK(stcb);
4627 SCTP_INP_RUNLOCK(inp);
4632 case SCTP_RESET_STREAMS:
4634 struct sctp_reset_streams *strrst;
4635 int i, send_out = 0;
4638 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4639 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4641 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4645 if (stcb->asoc.reconfig_supported == 0) {
4647 * Peer does not support the chunk type.
4649 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4651 SCTP_TCB_UNLOCK(stcb);
4654 if (sizeof(struct sctp_reset_streams) +
4655 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4657 SCTP_TCB_UNLOCK(stcb);
4660 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4662 if (stcb->asoc.stream_reset_outstanding) {
4663 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4665 SCTP_TCB_UNLOCK(stcb);
4669 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4672 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4673 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4675 SCTP_TCB_UNLOCK(stcb);
4678 if ((send_in == 0) && (send_out == 0)) {
4679 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4681 SCTP_TCB_UNLOCK(stcb);
4684 for (i = 0; i < strrst->srs_number_streams; i++) {
4686 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4687 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4692 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4693 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4699 SCTP_TCB_UNLOCK(stcb);
4706 if (strrst->srs_number_streams) {
4707 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4708 strm = strrst->srs_stream_list[i];
4709 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4710 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4716 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4717 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4718 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4725 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4726 strrst->srs_stream_list,
4727 send_in, 0, 0, 0, 0, 0);
4729 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4732 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4735 * For outgoing streams don't report any
4736 * problems in sending the request to the
4737 * application. XXX: Double check resetting
4742 SCTP_TCB_UNLOCK(stcb);
4745 case SCTP_ADD_STREAMS:
4747 struct sctp_add_streams *stradd;
4748 uint8_t addstream = 0;
4749 uint16_t add_o_strmcnt = 0;
4750 uint16_t add_i_strmcnt = 0;
4752 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4753 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4755 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4759 if (stcb->asoc.reconfig_supported == 0) {
4761 * Peer does not support the chunk type.
4763 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4765 SCTP_TCB_UNLOCK(stcb);
4768 if (stcb->asoc.stream_reset_outstanding) {
4769 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4771 SCTP_TCB_UNLOCK(stcb);
4774 if ((stradd->sas_outstrms == 0) &&
4775 (stradd->sas_instrms == 0)) {
4779 if (stradd->sas_outstrms) {
4781 /* We allocate here */
4782 add_o_strmcnt = stradd->sas_outstrms;
4783 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4784 /* You can't have more than 64k */
4789 if (stradd->sas_instrms) {
4794 * We allocate inside
4795 * sctp_send_str_reset_req()
4797 add_i_strmcnt = stradd->sas_instrms;
4798 cnt = add_i_strmcnt;
4799 cnt += stcb->asoc.streamincnt;
4800 if (cnt > 0x0000ffff) {
4801 /* You can't have more than 64k */
4805 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4806 /* More than you are allowed */
4811 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4812 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4814 SCTP_TCB_UNLOCK(stcb);
4817 case SCTP_RESET_ASSOC:
4822 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4823 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4825 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4829 if (stcb->asoc.reconfig_supported == 0) {
4831 * Peer does not support the chunk type.
4833 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4835 SCTP_TCB_UNLOCK(stcb);
4838 if (stcb->asoc.stream_reset_outstanding) {
4839 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4841 SCTP_TCB_UNLOCK(stcb);
4845 * Is there any data pending in the send or sent
4848 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4849 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4852 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4853 SCTP_TCB_UNLOCK(stcb);
4856 /* Do any streams have data queued? */
4857 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4858 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4862 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4863 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4864 SCTP_TCB_UNLOCK(stcb);
4867 case SCTP_CONNECT_X:
4868 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4869 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4873 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4875 case SCTP_CONNECT_X_DELAYED:
4876 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4877 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4881 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4883 case SCTP_CONNECT_X_COMPLETE:
4885 struct sockaddr *sa;
4887 /* FIXME MT: check correct? */
4888 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4891 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4892 SCTP_INP_RLOCK(inp);
4893 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4895 SCTP_TCB_LOCK(stcb);
4897 SCTP_INP_RUNLOCK(inp);
4900 * We increment here since
4901 * sctp_findassociation_ep_addr() wil do a
4902 * decrement if it finds the stcb as long as
4903 * the locked tcb (last argument) is NOT a
4906 SCTP_INP_INCR_REF(inp);
4907 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4909 SCTP_INP_DECR_REF(inp);
4914 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4918 if (stcb->asoc.delayed_connection == 1) {
4919 stcb->asoc.delayed_connection = 0;
4920 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4921 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4922 stcb->asoc.primary_destination,
4923 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4924 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4927 * already expired or did not use delayed
4930 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4933 SCTP_TCB_UNLOCK(stcb);
4936 case SCTP_MAX_BURST:
4938 struct sctp_assoc_value *av;
4940 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4941 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4944 stcb->asoc.max_burst = av->assoc_value;
4945 SCTP_TCB_UNLOCK(stcb);
4947 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4948 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4949 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4950 (av->assoc_id == SCTP_ALL_ASSOC)) {
4951 SCTP_INP_WLOCK(inp);
4952 inp->sctp_ep.max_burst = av->assoc_value;
4953 SCTP_INP_WUNLOCK(inp);
4955 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4956 (av->assoc_id == SCTP_ALL_ASSOC)) {
4957 SCTP_INP_RLOCK(inp);
4958 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4959 SCTP_TCB_LOCK(stcb);
4960 stcb->asoc.max_burst = av->assoc_value;
4961 SCTP_TCB_UNLOCK(stcb);
4963 SCTP_INP_RUNLOCK(inp);
4970 struct sctp_assoc_value *av;
4973 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4974 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4976 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4977 ovh = SCTP_MED_OVERHEAD;
4979 ovh = SCTP_MED_V4_OVERHEAD;
4982 if (av->assoc_value) {
4983 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4985 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4987 SCTP_TCB_UNLOCK(stcb);
4989 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4990 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4991 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4992 SCTP_INP_WLOCK(inp);
4994 * FIXME MT: I think this is not in
4995 * tune with the API ID
4997 if (av->assoc_value) {
4998 inp->sctp_frag_point = (av->assoc_value + ovh);
5000 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
5002 SCTP_INP_WUNLOCK(inp);
5004 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5012 struct sctp_event_subscribe *events;
5014 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
5016 SCTP_INP_WLOCK(inp);
5017 if (events->sctp_data_io_event) {
5018 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5020 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5023 if (events->sctp_association_event) {
5024 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5026 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5029 if (events->sctp_address_event) {
5030 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5032 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5035 if (events->sctp_send_failure_event) {
5036 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5038 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5041 if (events->sctp_peer_error_event) {
5042 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5044 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5047 if (events->sctp_shutdown_event) {
5048 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5050 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5053 if (events->sctp_partial_delivery_event) {
5054 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5056 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5059 if (events->sctp_adaptation_layer_event) {
5060 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5062 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5065 if (events->sctp_authentication_event) {
5066 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5068 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5071 if (events->sctp_sender_dry_event) {
5072 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5074 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5077 if (events->sctp_stream_reset_event) {
5078 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5080 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5082 SCTP_INP_WUNLOCK(inp);
5084 SCTP_INP_RLOCK(inp);
5085 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5086 SCTP_TCB_LOCK(stcb);
5087 if (events->sctp_association_event) {
5088 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5090 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5092 if (events->sctp_address_event) {
5093 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5095 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5097 if (events->sctp_send_failure_event) {
5098 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5100 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5102 if (events->sctp_peer_error_event) {
5103 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5105 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5107 if (events->sctp_shutdown_event) {
5108 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5110 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5112 if (events->sctp_partial_delivery_event) {
5113 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5115 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5117 if (events->sctp_adaptation_layer_event) {
5118 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5120 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5122 if (events->sctp_authentication_event) {
5123 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5125 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5127 if (events->sctp_sender_dry_event) {
5128 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5130 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5132 if (events->sctp_stream_reset_event) {
5133 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5135 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5137 SCTP_TCB_UNLOCK(stcb);
5140 * Send up the sender dry event only for 1-to-1
5143 if (events->sctp_sender_dry_event) {
5144 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5145 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5146 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5148 SCTP_TCB_LOCK(stcb);
5149 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5150 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5151 (stcb->asoc.stream_queue_cnt == 0)) {
5152 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5154 SCTP_TCB_UNLOCK(stcb);
5158 SCTP_INP_RUNLOCK(inp);
5161 case SCTP_ADAPTATION_LAYER:
5163 struct sctp_setadaptation *adap_bits;
5165 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5166 SCTP_INP_WLOCK(inp);
5167 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5168 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5169 SCTP_INP_WUNLOCK(inp);
5173 case SCTP_SET_INITIAL_DBG_SEQ:
5177 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5178 SCTP_INP_WLOCK(inp);
5179 inp->sctp_ep.initial_sequence_debug = *vvv;
5180 SCTP_INP_WUNLOCK(inp);
5184 case SCTP_DEFAULT_SEND_PARAM:
5186 struct sctp_sndrcvinfo *s_info;
5188 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5189 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5192 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5193 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5195 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5198 SCTP_TCB_UNLOCK(stcb);
5200 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5201 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5202 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5203 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5204 SCTP_INP_WLOCK(inp);
5205 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5206 SCTP_INP_WUNLOCK(inp);
5208 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5209 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5210 SCTP_INP_RLOCK(inp);
5211 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5212 SCTP_TCB_LOCK(stcb);
5213 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5214 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5216 SCTP_TCB_UNLOCK(stcb);
5218 SCTP_INP_RUNLOCK(inp);
5223 case SCTP_PEER_ADDR_PARAMS:
5225 struct sctp_paddrparams *paddrp;
5226 struct sctp_nets *net;
5227 struct sockaddr *addr;
5229 #if defined(INET) && defined(INET6)
5230 struct sockaddr_in sin_store;
5234 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5235 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5237 #if defined(INET) && defined(INET6)
5238 if (paddrp->spp_address.ss_family == AF_INET6) {
5239 struct sockaddr_in6 *sin6;
5241 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5242 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5243 in6_sin6_2_sin(&sin_store, sin6);
5244 addr = (struct sockaddr *)&sin_store;
5246 addr = (struct sockaddr *)&paddrp->spp_address;
5249 addr = (struct sockaddr *)&paddrp->spp_address;
5252 addr = (struct sockaddr *)&paddrp->spp_address;
5255 net = sctp_findnet(stcb, addr);
5258 * We increment here since
5259 * sctp_findassociation_ep_addr() wil do a
5260 * decrement if it finds the stcb as long as
5261 * the locked tcb (last argument) is NOT a
5265 SCTP_INP_INCR_REF(inp);
5266 stcb = sctp_findassociation_ep_addr(&inp, addr,
5269 SCTP_INP_DECR_REF(inp);
5272 if ((stcb != NULL) && (net == NULL)) {
5274 if (addr->sa_family == AF_INET) {
5276 struct sockaddr_in *sin;
5278 sin = (struct sockaddr_in *)addr;
5279 if (sin->sin_addr.s_addr != INADDR_ANY) {
5280 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5281 SCTP_TCB_UNLOCK(stcb);
5288 if (addr->sa_family == AF_INET6) {
5289 struct sockaddr_in6 *sin6;
5291 sin6 = (struct sockaddr_in6 *)addr;
5292 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5293 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5294 SCTP_TCB_UNLOCK(stcb);
5301 error = EAFNOSUPPORT;
5302 SCTP_TCB_UNLOCK(stcb);
5303 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5308 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5310 SCTP_TCB_UNLOCK(stcb);
5311 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5314 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5316 SCTP_TCB_UNLOCK(stcb);
5317 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5321 /************************TCB SPECIFIC SET ******************/
5323 /************************NET SPECIFIC SET ******************/
5324 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5325 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5326 !(net->dest_state & SCTP_ADDR_NOHB)) {
5327 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5328 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5330 net->dest_state |= SCTP_ADDR_NOHB;
5332 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5333 if (paddrp->spp_hbinterval) {
5334 net->heart_beat_delay = paddrp->spp_hbinterval;
5335 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5336 net->heart_beat_delay = 0;
5338 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5339 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5340 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5341 net->dest_state &= ~SCTP_ADDR_NOHB;
5343 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5345 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5346 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5347 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5349 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5350 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5351 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5352 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5354 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5355 net->mtu = paddrp->spp_pathmtu;
5356 switch (net->ro._l_addr.sa.sa_family) {
5359 net->mtu += SCTP_MIN_V4_OVERHEAD;
5364 net->mtu += SCTP_MIN_OVERHEAD;
5370 if (net->mtu < stcb->asoc.smallest_mtu) {
5371 sctp_pathmtu_adjustment(stcb, net->mtu);
5374 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5375 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5376 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5378 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5380 if (paddrp->spp_pathmaxrxt) {
5381 if (net->dest_state & SCTP_ADDR_PF) {
5382 if (net->error_count > paddrp->spp_pathmaxrxt) {
5383 net->dest_state &= ~SCTP_ADDR_PF;
5386 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5387 (net->error_count > net->pf_threshold)) {
5388 net->dest_state |= SCTP_ADDR_PF;
5389 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5390 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5391 stcb->sctp_ep, stcb, net,
5392 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5393 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5396 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5397 if (net->error_count > paddrp->spp_pathmaxrxt) {
5398 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5399 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5402 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5403 net->dest_state |= SCTP_ADDR_REACHABLE;
5404 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5407 net->failure_threshold = paddrp->spp_pathmaxrxt;
5409 if (paddrp->spp_flags & SPP_DSCP) {
5410 net->dscp = paddrp->spp_dscp & 0xfc;
5414 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5415 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5416 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5417 net->flowlabel |= 0x80000000;
5422 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5423 if (paddrp->spp_pathmaxrxt != 0) {
5424 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5425 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5426 if (net->dest_state & SCTP_ADDR_PF) {
5427 if (net->error_count > paddrp->spp_pathmaxrxt) {
5428 net->dest_state &= ~SCTP_ADDR_PF;
5431 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5432 (net->error_count > net->pf_threshold)) {
5433 net->dest_state |= SCTP_ADDR_PF;
5434 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5435 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5436 stcb->sctp_ep, stcb, net,
5437 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5438 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5441 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5442 if (net->error_count > paddrp->spp_pathmaxrxt) {
5443 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5444 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5447 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5448 net->dest_state |= SCTP_ADDR_REACHABLE;
5449 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5452 net->failure_threshold = paddrp->spp_pathmaxrxt;
5455 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5456 if (paddrp->spp_hbinterval != 0) {
5457 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5458 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5459 stcb->asoc.heart_beat_delay = 0;
5461 /* Turn back on the timer */
5462 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5463 if (paddrp->spp_hbinterval != 0) {
5464 net->heart_beat_delay = paddrp->spp_hbinterval;
5465 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5466 net->heart_beat_delay = 0;
5468 if (net->dest_state & SCTP_ADDR_NOHB) {
5469 net->dest_state &= ~SCTP_ADDR_NOHB;
5471 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5472 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5473 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5475 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5477 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5478 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5479 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5480 net->dest_state |= SCTP_ADDR_NOHB;
5481 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5482 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5484 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5488 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5490 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5491 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5492 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5493 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5494 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5496 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5497 net->mtu = paddrp->spp_pathmtu;
5498 switch (net->ro._l_addr.sa.sa_family) {
5501 net->mtu += SCTP_MIN_V4_OVERHEAD;
5506 net->mtu += SCTP_MIN_OVERHEAD;
5512 if (net->mtu < stcb->asoc.smallest_mtu) {
5513 sctp_pathmtu_adjustment(stcb, net->mtu);
5516 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5518 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5519 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5520 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5521 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5523 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5525 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5527 if (paddrp->spp_flags & SPP_DSCP) {
5528 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5529 net->dscp = paddrp->spp_dscp & 0xfc;
5532 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5533 stcb->asoc.default_dscp |= 0x01;
5536 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5537 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5538 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5539 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5540 net->flowlabel |= 0x80000000;
5543 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5544 stcb->asoc.default_flowlabel |= 0x80000000;
5548 SCTP_TCB_UNLOCK(stcb);
5550 /************************NO TCB, SET TO default stuff ******************/
5551 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5552 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5553 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5554 SCTP_INP_WLOCK(inp);
5556 * For the TOS/FLOWLABEL stuff you
5557 * set it with the options on the
5560 if (paddrp->spp_pathmaxrxt != 0) {
5561 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5563 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5564 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5565 else if (paddrp->spp_hbinterval != 0) {
5566 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5567 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5568 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5570 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5571 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5572 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5573 } else if (paddrp->spp_hbinterval) {
5574 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5576 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5577 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5578 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5580 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5581 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5582 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5583 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5585 if (paddrp->spp_flags & SPP_DSCP) {
5586 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5587 inp->sctp_ep.default_dscp |= 0x01;
5590 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5591 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5592 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5593 inp->sctp_ep.default_flowlabel |= 0x80000000;
5597 SCTP_INP_WUNLOCK(inp);
5599 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5607 struct sctp_rtoinfo *srto;
5608 uint32_t new_init, new_min, new_max;
5610 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5611 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5614 if (srto->srto_initial)
5615 new_init = srto->srto_initial;
5617 new_init = stcb->asoc.initial_rto;
5619 new_max = srto->srto_max;
5621 new_max = stcb->asoc.maxrto;
5623 new_min = srto->srto_min;
5625 new_min = stcb->asoc.minrto;
5626 if ((new_min <= new_init) && (new_init <= new_max)) {
5627 stcb->asoc.initial_rto = new_init;
5628 stcb->asoc.maxrto = new_max;
5629 stcb->asoc.minrto = new_min;
5631 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5634 SCTP_TCB_UNLOCK(stcb);
5636 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5637 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5638 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5639 SCTP_INP_WLOCK(inp);
5640 if (srto->srto_initial)
5641 new_init = srto->srto_initial;
5643 new_init = inp->sctp_ep.initial_rto;
5645 new_max = srto->srto_max;
5647 new_max = inp->sctp_ep.sctp_maxrto;
5649 new_min = srto->srto_min;
5651 new_min = inp->sctp_ep.sctp_minrto;
5652 if ((new_min <= new_init) && (new_init <= new_max)) {
5653 inp->sctp_ep.initial_rto = new_init;
5654 inp->sctp_ep.sctp_maxrto = new_max;
5655 inp->sctp_ep.sctp_minrto = new_min;
5657 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5660 SCTP_INP_WUNLOCK(inp);
5662 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5668 case SCTP_ASSOCINFO:
5670 struct sctp_assocparams *sasoc;
5672 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5673 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5674 if (sasoc->sasoc_cookie_life) {
5675 /* boundary check the cookie life */
5676 if (sasoc->sasoc_cookie_life < 1000)
5677 sasoc->sasoc_cookie_life = 1000;
5678 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5679 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5683 if (sasoc->sasoc_asocmaxrxt)
5684 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5685 if (sasoc->sasoc_cookie_life) {
5686 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5688 SCTP_TCB_UNLOCK(stcb);
5690 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5691 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5692 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5693 SCTP_INP_WLOCK(inp);
5694 if (sasoc->sasoc_asocmaxrxt)
5695 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5696 if (sasoc->sasoc_cookie_life) {
5697 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5699 SCTP_INP_WUNLOCK(inp);
5701 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5709 struct sctp_initmsg *sinit;
5711 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5712 SCTP_INP_WLOCK(inp);
5713 if (sinit->sinit_num_ostreams)
5714 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5716 if (sinit->sinit_max_instreams)
5717 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5719 if (sinit->sinit_max_attempts)
5720 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5722 if (sinit->sinit_max_init_timeo)
5723 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5724 SCTP_INP_WUNLOCK(inp);
5727 case SCTP_PRIMARY_ADDR:
5729 struct sctp_setprim *spa;
5730 struct sctp_nets *net;
5731 struct sockaddr *addr;
5733 #if defined(INET) && defined(INET6)
5734 struct sockaddr_in sin_store;
5738 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5739 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5741 #if defined(INET) && defined(INET6)
5742 if (spa->ssp_addr.ss_family == AF_INET6) {
5743 struct sockaddr_in6 *sin6;
5745 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5746 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5747 in6_sin6_2_sin(&sin_store, sin6);
5748 addr = (struct sockaddr *)&sin_store;
5750 addr = (struct sockaddr *)&spa->ssp_addr;
5753 addr = (struct sockaddr *)&spa->ssp_addr;
5756 addr = (struct sockaddr *)&spa->ssp_addr;
5759 net = sctp_findnet(stcb, addr);
5762 * We increment here since
5763 * sctp_findassociation_ep_addr() wil do a
5764 * decrement if it finds the stcb as long as
5765 * the locked tcb (last argument) is NOT a
5769 SCTP_INP_INCR_REF(inp);
5770 stcb = sctp_findassociation_ep_addr(&inp, addr,
5773 SCTP_INP_DECR_REF(inp);
5777 if ((stcb != NULL) && (net != NULL)) {
5778 if (net != stcb->asoc.primary_destination) {
5779 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5780 /* Ok we need to set it */
5781 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5782 if ((stcb->asoc.alternate) &&
5783 (!(net->dest_state & SCTP_ADDR_PF)) &&
5784 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5785 sctp_free_remote_addr(stcb->asoc.alternate);
5786 stcb->asoc.alternate = NULL;
5789 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5793 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5798 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5802 SCTP_TCB_UNLOCK(stcb);
5806 case SCTP_SET_DYNAMIC_PRIMARY:
5808 union sctp_sockstore *ss;
5810 error = priv_check(curthread,
5811 PRIV_NETINET_RESERVEDPORT);
5815 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5816 /* SUPER USER CHECK? */
5817 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5820 case SCTP_SET_PEER_PRIMARY_ADDR:
5822 struct sctp_setpeerprim *sspp;
5823 struct sockaddr *addr;
5825 #if defined(INET) && defined(INET6)
5826 struct sockaddr_in sin_store;
5830 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5831 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5833 struct sctp_ifa *ifa;
5835 #if defined(INET) && defined(INET6)
5836 if (sspp->sspp_addr.ss_family == AF_INET6) {
5837 struct sockaddr_in6 *sin6;
5839 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5840 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5841 in6_sin6_2_sin(&sin_store, sin6);
5842 addr = (struct sockaddr *)&sin_store;
5844 addr = (struct sockaddr *)&sspp->sspp_addr;
5847 addr = (struct sockaddr *)&sspp->sspp_addr;
5850 addr = (struct sockaddr *)&sspp->sspp_addr;
5852 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5858 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5860 * Must validate the ifa found is in
5863 struct sctp_laddr *laddr;
5866 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5867 if (laddr->ifa == NULL) {
5868 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5872 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5873 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5876 if (laddr->ifa == ifa) {
5882 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5887 switch (addr->sa_family) {
5891 struct sockaddr_in *sin;
5893 sin = (struct sockaddr_in *)addr;
5894 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5895 &sin->sin_addr) != 0) {
5896 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5906 struct sockaddr_in6 *sin6;
5908 sin6 = (struct sockaddr_in6 *)addr;
5909 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5910 &sin6->sin6_addr) != 0) {
5911 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5919 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5924 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5925 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5928 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5930 SCTP_TCB_UNLOCK(stcb);
5932 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5937 case SCTP_BINDX_ADD_ADDR:
5939 struct sctp_getaddresses *addrs;
5942 td = (struct thread *)p;
5943 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5946 if (addrs->addr->sa_family == AF_INET) {
5947 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5948 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5952 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5953 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5959 if (addrs->addr->sa_family == AF_INET6) {
5960 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5961 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5965 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5966 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5967 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5973 error = EAFNOSUPPORT;
5976 sctp_bindx_add_address(so, inp, addrs->addr,
5977 addrs->sget_assoc_id, vrf_id,
5981 case SCTP_BINDX_REM_ADDR:
5983 struct sctp_getaddresses *addrs;
5986 td = (struct thread *)p;
5988 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5990 if (addrs->addr->sa_family == AF_INET) {
5991 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5992 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5996 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5997 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6003 if (addrs->addr->sa_family == AF_INET6) {
6004 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
6005 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6010 (error = prison_local_ip6(td->td_ucred,
6011 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
6012 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6013 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6019 error = EAFNOSUPPORT;
6022 sctp_bindx_delete_address(inp, addrs->addr,
6023 addrs->sget_assoc_id, vrf_id,
6029 struct sctp_event *event;
6030 uint32_t event_type;
6032 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6033 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6034 switch (event->se_type) {
6035 case SCTP_ASSOC_CHANGE:
6036 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6038 case SCTP_PEER_ADDR_CHANGE:
6039 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6041 case SCTP_REMOTE_ERROR:
6042 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6044 case SCTP_SEND_FAILED:
6045 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6047 case SCTP_SHUTDOWN_EVENT:
6048 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6050 case SCTP_ADAPTATION_INDICATION:
6051 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6053 case SCTP_PARTIAL_DELIVERY_EVENT:
6054 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6056 case SCTP_AUTHENTICATION_EVENT:
6057 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6059 case SCTP_STREAM_RESET_EVENT:
6060 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6062 case SCTP_SENDER_DRY_EVENT:
6063 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6065 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6067 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6070 case SCTP_ASSOC_RESET_EVENT:
6071 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6073 case SCTP_STREAM_CHANGE_EVENT:
6074 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6076 case SCTP_SEND_FAILED_EVENT:
6077 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6081 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6085 if (event_type > 0) {
6088 sctp_stcb_feature_on(inp, stcb, event_type);
6089 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6090 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6091 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6092 (stcb->asoc.stream_queue_cnt == 0)) {
6093 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6097 sctp_stcb_feature_off(inp, stcb, event_type);
6099 SCTP_TCB_UNLOCK(stcb);
6102 * We don't want to send up a storm
6103 * of events, so return an error for
6106 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6107 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6108 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6109 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6110 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6111 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6115 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6116 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6117 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6118 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6119 SCTP_INP_WLOCK(inp);
6121 sctp_feature_on(inp, event_type);
6123 sctp_feature_off(inp, event_type);
6125 SCTP_INP_WUNLOCK(inp);
6127 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6128 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6129 SCTP_INP_RLOCK(inp);
6130 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6131 SCTP_TCB_LOCK(stcb);
6133 sctp_stcb_feature_on(inp, stcb, event_type);
6135 sctp_stcb_feature_off(inp, stcb, event_type);
6137 SCTP_TCB_UNLOCK(stcb);
6139 SCTP_INP_RUNLOCK(inp);
6145 case SCTP_RECVRCVINFO:
6149 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6150 SCTP_INP_WLOCK(inp);
6152 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6154 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6156 SCTP_INP_WUNLOCK(inp);
6159 case SCTP_RECVNXTINFO:
6163 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6164 SCTP_INP_WLOCK(inp);
6166 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6168 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6170 SCTP_INP_WUNLOCK(inp);
6173 case SCTP_DEFAULT_SNDINFO:
6175 struct sctp_sndinfo *info;
6178 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6179 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6182 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6183 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6184 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6185 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6186 stcb->asoc.def_send.sinfo_flags |= policy;
6187 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6188 stcb->asoc.def_send.sinfo_context = info->snd_context;
6190 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6193 SCTP_TCB_UNLOCK(stcb);
6195 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6196 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6197 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6198 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6199 SCTP_INP_WLOCK(inp);
6200 inp->def_send.sinfo_stream = info->snd_sid;
6201 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6202 inp->def_send.sinfo_flags = info->snd_flags;
6203 inp->def_send.sinfo_flags |= policy;
6204 inp->def_send.sinfo_ppid = info->snd_ppid;
6205 inp->def_send.sinfo_context = info->snd_context;
6206 SCTP_INP_WUNLOCK(inp);
6208 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6209 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6210 SCTP_INP_RLOCK(inp);
6211 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6212 SCTP_TCB_LOCK(stcb);
6213 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6214 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6215 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6216 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6217 stcb->asoc.def_send.sinfo_flags |= policy;
6218 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6219 stcb->asoc.def_send.sinfo_context = info->snd_context;
6221 SCTP_TCB_UNLOCK(stcb);
6223 SCTP_INP_RUNLOCK(inp);
6228 case SCTP_DEFAULT_PRINFO:
6230 struct sctp_default_prinfo *info;
6232 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6233 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6235 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6236 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6241 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6242 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6243 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6244 SCTP_TCB_UNLOCK(stcb);
6246 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6247 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6248 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6249 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6250 SCTP_INP_WLOCK(inp);
6251 inp->def_send.sinfo_flags &= 0xfff0;
6252 inp->def_send.sinfo_flags |= info->pr_policy;
6253 inp->def_send.sinfo_timetolive = info->pr_value;
6254 SCTP_INP_WUNLOCK(inp);
6256 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6257 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6258 SCTP_INP_RLOCK(inp);
6259 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6260 SCTP_TCB_LOCK(stcb);
6261 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6262 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6263 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6264 SCTP_TCB_UNLOCK(stcb);
6266 SCTP_INP_RUNLOCK(inp);
6271 case SCTP_PEER_ADDR_THLDS:
6272 /* Applies to the specific association */
6274 struct sctp_paddrthlds *thlds;
6275 struct sctp_nets *net;
6276 struct sockaddr *addr;
6278 #if defined(INET) && defined(INET6)
6279 struct sockaddr_in sin_store;
6283 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6284 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6286 #if defined(INET) && defined(INET6)
6287 if (thlds->spt_address.ss_family == AF_INET6) {
6288 struct sockaddr_in6 *sin6;
6290 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6291 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6292 in6_sin6_2_sin(&sin_store, sin6);
6293 addr = (struct sockaddr *)&sin_store;
6295 addr = (struct sockaddr *)&thlds->spt_address;
6298 addr = (struct sockaddr *)&thlds->spt_address;
6301 addr = (struct sockaddr *)&thlds->spt_address;
6304 net = sctp_findnet(stcb, addr);
6307 * We increment here since
6308 * sctp_findassociation_ep_addr() wil do a
6309 * decrement if it finds the stcb as long as
6310 * the locked tcb (last argument) is NOT a
6314 SCTP_INP_INCR_REF(inp);
6315 stcb = sctp_findassociation_ep_addr(&inp, addr,
6318 SCTP_INP_DECR_REF(inp);
6321 if ((stcb != NULL) && (net == NULL)) {
6323 if (addr->sa_family == AF_INET) {
6325 struct sockaddr_in *sin;
6327 sin = (struct sockaddr_in *)addr;
6328 if (sin->sin_addr.s_addr != INADDR_ANY) {
6329 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6330 SCTP_TCB_UNLOCK(stcb);
6337 if (addr->sa_family == AF_INET6) {
6338 struct sockaddr_in6 *sin6;
6340 sin6 = (struct sockaddr_in6 *)addr;
6341 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6342 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6343 SCTP_TCB_UNLOCK(stcb);
6350 error = EAFNOSUPPORT;
6351 SCTP_TCB_UNLOCK(stcb);
6352 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6358 net->failure_threshold = thlds->spt_pathmaxrxt;
6359 net->pf_threshold = thlds->spt_pathpfthld;
6360 if (net->dest_state & SCTP_ADDR_PF) {
6361 if ((net->error_count > net->failure_threshold) ||
6362 (net->error_count <= net->pf_threshold)) {
6363 net->dest_state &= ~SCTP_ADDR_PF;
6366 if ((net->error_count > net->pf_threshold) &&
6367 (net->error_count <= net->failure_threshold)) {
6368 net->dest_state |= SCTP_ADDR_PF;
6369 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6370 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6371 stcb->sctp_ep, stcb, net,
6372 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6373 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6376 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6377 if (net->error_count > net->failure_threshold) {
6378 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6379 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6382 if (net->error_count <= net->failure_threshold) {
6383 net->dest_state |= SCTP_ADDR_REACHABLE;
6384 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6388 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6389 net->failure_threshold = thlds->spt_pathmaxrxt;
6390 net->pf_threshold = thlds->spt_pathpfthld;
6391 if (net->dest_state & SCTP_ADDR_PF) {
6392 if ((net->error_count > net->failure_threshold) ||
6393 (net->error_count <= net->pf_threshold)) {
6394 net->dest_state &= ~SCTP_ADDR_PF;
6397 if ((net->error_count > net->pf_threshold) &&
6398 (net->error_count <= net->failure_threshold)) {
6399 net->dest_state |= SCTP_ADDR_PF;
6400 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6401 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6402 stcb->sctp_ep, stcb, net,
6403 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6404 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6407 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6408 if (net->error_count > net->failure_threshold) {
6409 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6410 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6413 if (net->error_count <= net->failure_threshold) {
6414 net->dest_state |= SCTP_ADDR_REACHABLE;
6415 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6419 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6420 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6422 SCTP_TCB_UNLOCK(stcb);
6424 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6425 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6426 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6427 SCTP_INP_WLOCK(inp);
6428 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6429 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6430 SCTP_INP_WUNLOCK(inp);
6432 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6438 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6440 struct sctp_udpencaps *encaps;
6441 struct sctp_nets *net;
6442 struct sockaddr *addr;
6444 #if defined(INET) && defined(INET6)
6445 struct sockaddr_in sin_store;
6449 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6450 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6452 #if defined(INET) && defined(INET6)
6453 if (encaps->sue_address.ss_family == AF_INET6) {
6454 struct sockaddr_in6 *sin6;
6456 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6457 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6458 in6_sin6_2_sin(&sin_store, sin6);
6459 addr = (struct sockaddr *)&sin_store;
6461 addr = (struct sockaddr *)&encaps->sue_address;
6464 addr = (struct sockaddr *)&encaps->sue_address;
6467 addr = (struct sockaddr *)&encaps->sue_address;
6470 net = sctp_findnet(stcb, addr);
6473 * We increment here since
6474 * sctp_findassociation_ep_addr() wil do a
6475 * decrement if it finds the stcb as long as
6476 * the locked tcb (last argument) is NOT a
6480 SCTP_INP_INCR_REF(inp);
6481 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6483 SCTP_INP_DECR_REF(inp);
6486 if ((stcb != NULL) && (net == NULL)) {
6488 if (addr->sa_family == AF_INET) {
6490 struct sockaddr_in *sin;
6492 sin = (struct sockaddr_in *)addr;
6493 if (sin->sin_addr.s_addr != INADDR_ANY) {
6494 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6495 SCTP_TCB_UNLOCK(stcb);
6502 if (addr->sa_family == AF_INET6) {
6503 struct sockaddr_in6 *sin6;
6505 sin6 = (struct sockaddr_in6 *)addr;
6506 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6507 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6508 SCTP_TCB_UNLOCK(stcb);
6515 error = EAFNOSUPPORT;
6516 SCTP_TCB_UNLOCK(stcb);
6517 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6523 net->port = encaps->sue_port;
6525 stcb->asoc.port = encaps->sue_port;
6527 SCTP_TCB_UNLOCK(stcb);
6529 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6530 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6531 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6532 SCTP_INP_WLOCK(inp);
6533 inp->sctp_ep.port = encaps->sue_port;
6534 SCTP_INP_WUNLOCK(inp);
6536 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6542 case SCTP_ECN_SUPPORTED:
6544 struct sctp_assoc_value *av;
6546 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6547 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6550 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6552 SCTP_TCB_UNLOCK(stcb);
6554 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6555 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6556 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6557 SCTP_INP_WLOCK(inp);
6558 if (av->assoc_value == 0) {
6559 inp->ecn_supported = 0;
6561 inp->ecn_supported = 1;
6563 SCTP_INP_WUNLOCK(inp);
6565 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6571 case SCTP_PR_SUPPORTED:
6573 struct sctp_assoc_value *av;
6575 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6576 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6579 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6581 SCTP_TCB_UNLOCK(stcb);
6583 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6584 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6585 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6586 SCTP_INP_WLOCK(inp);
6587 if (av->assoc_value == 0) {
6588 inp->prsctp_supported = 0;
6590 inp->prsctp_supported = 1;
6592 SCTP_INP_WUNLOCK(inp);
6594 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6600 case SCTP_AUTH_SUPPORTED:
6602 struct sctp_assoc_value *av;
6604 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6605 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6608 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6610 SCTP_TCB_UNLOCK(stcb);
6612 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6613 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6614 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6615 if ((av->assoc_value == 0) &&
6616 (inp->asconf_supported == 1)) {
6618 * AUTH is required for
6621 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6624 SCTP_INP_WLOCK(inp);
6625 if (av->assoc_value == 0) {
6626 inp->auth_supported = 0;
6628 inp->auth_supported = 1;
6630 SCTP_INP_WUNLOCK(inp);
6633 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6639 case SCTP_ASCONF_SUPPORTED:
6641 struct sctp_assoc_value *av;
6643 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6644 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6647 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6649 SCTP_TCB_UNLOCK(stcb);
6651 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6652 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6653 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6654 if ((av->assoc_value != 0) &&
6655 (inp->auth_supported == 0)) {
6657 * AUTH is required for
6660 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6663 SCTP_INP_WLOCK(inp);
6664 if (av->assoc_value == 0) {
6665 inp->asconf_supported = 0;
6666 sctp_auth_delete_chunk(SCTP_ASCONF,
6667 inp->sctp_ep.local_auth_chunks);
6668 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6669 inp->sctp_ep.local_auth_chunks);
6671 inp->asconf_supported = 1;
6672 sctp_auth_add_chunk(SCTP_ASCONF,
6673 inp->sctp_ep.local_auth_chunks);
6674 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6675 inp->sctp_ep.local_auth_chunks);
6677 SCTP_INP_WUNLOCK(inp);
6680 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6686 case SCTP_RECONFIG_SUPPORTED:
6688 struct sctp_assoc_value *av;
6690 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6691 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6694 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6696 SCTP_TCB_UNLOCK(stcb);
6698 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6699 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6700 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6701 SCTP_INP_WLOCK(inp);
6702 if (av->assoc_value == 0) {
6703 inp->reconfig_supported = 0;
6705 inp->reconfig_supported = 1;
6707 SCTP_INP_WUNLOCK(inp);
6709 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6715 case SCTP_NRSACK_SUPPORTED:
6717 struct sctp_assoc_value *av;
6719 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6720 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6723 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6725 SCTP_TCB_UNLOCK(stcb);
6727 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6728 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6729 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6730 SCTP_INP_WLOCK(inp);
6731 if (av->assoc_value == 0) {
6732 inp->nrsack_supported = 0;
6734 inp->nrsack_supported = 1;
6736 SCTP_INP_WUNLOCK(inp);
6738 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6744 case SCTP_PKTDROP_SUPPORTED:
6746 struct sctp_assoc_value *av;
6748 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6749 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6752 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6754 SCTP_TCB_UNLOCK(stcb);
6756 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6757 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6758 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6759 SCTP_INP_WLOCK(inp);
6760 if (av->assoc_value == 0) {
6761 inp->pktdrop_supported = 0;
6763 inp->pktdrop_supported = 1;
6765 SCTP_INP_WUNLOCK(inp);
6767 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6775 struct sctp_assoc_value *av;
6776 struct sctp_nets *net;
6778 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6779 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6782 stcb->asoc.max_cwnd = av->assoc_value;
6783 if (stcb->asoc.max_cwnd > 0) {
6784 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6785 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6786 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6787 net->cwnd = stcb->asoc.max_cwnd;
6788 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6789 net->cwnd = net->mtu - sizeof(struct sctphdr);
6794 SCTP_TCB_UNLOCK(stcb);
6796 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6797 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6798 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6799 SCTP_INP_WLOCK(inp);
6800 inp->max_cwnd = av->assoc_value;
6801 SCTP_INP_WUNLOCK(inp);
6803 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6810 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6811 error = ENOPROTOOPT;
6813 } /* end switch (opt) */
6818 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6820 void *optval = NULL;
6824 struct sctp_inpcb *inp;
6826 if ((sopt->sopt_level == SOL_SOCKET) &&
6827 (sopt->sopt_name == SO_SETFIB)) {
6828 inp = (struct sctp_inpcb *)so->so_pcb;
6830 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6833 SCTP_INP_WLOCK(inp);
6834 inp->fibnum = so->so_fibnum;
6835 SCTP_INP_WUNLOCK(inp);
6838 if (sopt->sopt_level != IPPROTO_SCTP) {
6839 /* wrong proto level... send back up to IP */
6841 if (INP_CHECK_SOCKAF(so, AF_INET6))
6842 error = ip6_ctloutput(so, sopt);
6844 #if defined(INET) && defined(INET6)
6848 error = ip_ctloutput(so, sopt);
6852 optsize = sopt->sopt_valsize;
6854 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6855 if (optval == NULL) {
6856 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6859 error = sooptcopyin(sopt, optval, optsize, optsize);
6861 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6865 p = (void *)sopt->sopt_td;
6866 if (sopt->sopt_dir == SOPT_SET) {
6867 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6868 } else if (sopt->sopt_dir == SOPT_GET) {
6869 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6871 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6874 if ((error == 0) && (optval != NULL)) {
6875 error = sooptcopyout(sopt, optval, optsize);
6876 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6877 } else if (optval != NULL) {
6878 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6886 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6889 int create_lock_on = 0;
6891 struct sctp_inpcb *inp;
6892 struct sctp_tcb *stcb = NULL;
6894 inp = (struct sctp_inpcb *)so->so_pcb;
6896 /* I made the same as TCP since we are not setup? */
6897 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6898 return (ECONNRESET);
6901 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6904 switch (addr->sa_family) {
6908 struct sockaddr_in6 *sin6p;
6910 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6911 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6914 sin6p = (struct sockaddr_in6 *)addr;
6915 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6916 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6925 struct sockaddr_in *sinp;
6927 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6928 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6931 sinp = (struct sockaddr_in *)addr;
6932 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6933 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6940 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6941 return (EAFNOSUPPORT);
6943 SCTP_INP_INCR_REF(inp);
6944 SCTP_ASOC_CREATE_LOCK(inp);
6948 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6949 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6950 /* Should I really unlock ? */
6951 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6956 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6957 (addr->sa_family == AF_INET6)) {
6958 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6963 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6964 SCTP_PCB_FLAGS_UNBOUND) {
6965 /* Bind a ephemeral port */
6966 error = sctp_inpcb_bind(so, NULL, NULL, p);
6971 /* Now do we connect? */
6972 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6973 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6974 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6978 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6979 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6980 /* We are already connected AND the TCP model */
6981 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6985 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6986 SCTP_INP_RLOCK(inp);
6987 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6988 SCTP_INP_RUNLOCK(inp);
6991 * We increment here since sctp_findassociation_ep_addr()
6992 * will do a decrement if it finds the stcb as long as the
6993 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6995 SCTP_INP_INCR_REF(inp);
6996 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6998 SCTP_INP_DECR_REF(inp);
7000 SCTP_TCB_UNLOCK(stcb);
7004 /* Already have or am bring up an association */
7005 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7009 vrf_id = inp->def_vrf_id;
7010 /* We are GOOD to go */
7011 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, inp->sctp_ep.pre_open_stream_count, p);
7013 /* Gak! no memory */
7016 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
7017 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
7018 /* Set the connected flag so we can queue data */
7021 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
7022 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7024 /* initialize authentication parameters for the assoc */
7025 sctp_initialize_auth_params(inp, stcb);
7027 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7028 SCTP_TCB_UNLOCK(stcb);
7030 if (create_lock_on) {
7031 SCTP_ASOC_CREATE_UNLOCK(inp);
7033 SCTP_INP_DECR_REF(inp);
7040 sctp_listen(struct socket *so, int backlog, struct thread *p)
7043 * Note this module depends on the protocol processing being called
7044 * AFTER any socket level flags and backlog are applied to the
7045 * socket. The traditional way that the socket flags are applied is
7046 * AFTER protocol processing. We have made a change to the
7047 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7048 * place if the socket API for SCTP is to work properly.
7052 struct sctp_inpcb *inp;
7054 inp = (struct sctp_inpcb *)so->so_pcb;
7056 /* I made the same as TCP since we are not setup? */
7057 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7058 return (ECONNRESET);
7060 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7061 /* See if we have a listener */
7062 struct sctp_inpcb *tinp;
7063 union sctp_sockstore store;
7065 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7067 struct sctp_laddr *laddr;
7069 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7070 memcpy(&store, &laddr->ifa->address, sizeof(store));
7071 switch (store.sa.sa_family) {
7074 store.sin.sin_port = inp->sctp_lport;
7079 store.sin6.sin6_port = inp->sctp_lport;
7085 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7086 if (tinp && (tinp != inp) &&
7087 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7088 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7089 (tinp->sctp_socket->so_qlimit)) {
7091 * we have a listener already and
7094 SCTP_INP_DECR_REF(tinp);
7095 return (EADDRINUSE);
7097 SCTP_INP_DECR_REF(tinp);
7101 /* Setup a local addr bound all */
7102 memset(&store, 0, sizeof(store));
7104 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7105 store.sa.sa_family = AF_INET6;
7106 store.sa.sa_len = sizeof(struct sockaddr_in6);
7110 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7111 store.sa.sa_family = AF_INET;
7112 store.sa.sa_len = sizeof(struct sockaddr_in);
7115 switch (store.sa.sa_family) {
7118 store.sin.sin_port = inp->sctp_lport;
7123 store.sin6.sin6_port = inp->sctp_lport;
7129 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7130 if (tinp && (tinp != inp) &&
7131 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7132 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7133 (tinp->sctp_socket->so_qlimit)) {
7135 * we have a listener already and its not
7138 SCTP_INP_DECR_REF(tinp);
7139 return (EADDRINUSE);
7141 SCTP_INP_DECR_REF(tinp);
7145 SCTP_INP_RLOCK(inp);
7146 #ifdef SCTP_LOCK_LOGGING
7147 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7148 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7152 error = solisten_proto_check(so);
7155 SCTP_INP_RUNLOCK(inp);
7158 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7159 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7161 * The unlucky case - We are in the tcp pool with this guy.
7162 * - Someone else is in the main inp slot. - We must move
7163 * this guy (the listener) to the main slot - We must then
7164 * move the guy that was listener to the TCP Pool.
7166 if (sctp_swap_inpcb_for_listen(inp)) {
7167 SCTP_INP_RUNLOCK(inp);
7168 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7169 return (EADDRINUSE);
7172 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7173 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7174 /* We are already connected AND the TCP model */
7175 SCTP_INP_RUNLOCK(inp);
7176 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7177 return (EADDRINUSE);
7179 SCTP_INP_RUNLOCK(inp);
7180 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7181 /* We must do a bind. */
7182 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7183 /* bind error, probably perm */
7188 /* It appears for 7.0 and on, we must always call this. */
7189 solisten_proto(so, backlog);
7190 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7191 /* remove the ACCEPTCONN flag for one-to-many sockets */
7192 so->so_options &= ~SO_ACCEPTCONN;
7195 /* turning off listen */
7196 so->so_options &= ~SO_ACCEPTCONN;
7202 static int sctp_defered_wakeup_cnt = 0;
7205 sctp_accept(struct socket *so, struct sockaddr **addr)
7207 struct sctp_tcb *stcb;
7208 struct sctp_inpcb *inp;
7209 union sctp_sockstore store;
7215 inp = (struct sctp_inpcb *)so->so_pcb;
7218 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7219 return (ECONNRESET);
7221 SCTP_INP_RLOCK(inp);
7222 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7223 SCTP_INP_RUNLOCK(inp);
7224 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7225 return (EOPNOTSUPP);
7227 if (so->so_state & SS_ISDISCONNECTED) {
7228 SCTP_INP_RUNLOCK(inp);
7229 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7230 return (ECONNABORTED);
7232 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7234 SCTP_INP_RUNLOCK(inp);
7235 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7236 return (ECONNRESET);
7238 SCTP_TCB_LOCK(stcb);
7239 SCTP_INP_RUNLOCK(inp);
7240 store = stcb->asoc.primary_destination->ro._l_addr;
7241 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
7242 SCTP_TCB_UNLOCK(stcb);
7243 switch (store.sa.sa_family) {
7247 struct sockaddr_in *sin;
7249 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7252 sin->sin_family = AF_INET;
7253 sin->sin_len = sizeof(*sin);
7254 sin->sin_port = store.sin.sin_port;
7255 sin->sin_addr = store.sin.sin_addr;
7256 *addr = (struct sockaddr *)sin;
7263 struct sockaddr_in6 *sin6;
7265 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7268 sin6->sin6_family = AF_INET6;
7269 sin6->sin6_len = sizeof(*sin6);
7270 sin6->sin6_port = store.sin6.sin6_port;
7271 sin6->sin6_addr = store.sin6.sin6_addr;
7272 if ((error = sa6_recoverscope(sin6)) != 0) {
7273 SCTP_FREE_SONAME(sin6);
7276 *addr = (struct sockaddr *)sin6;
7284 /* Wake any delayed sleep action */
7285 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7286 SCTP_INP_WLOCK(inp);
7287 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7288 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7289 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7290 SCTP_INP_WUNLOCK(inp);
7291 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7292 if (sowriteable(inp->sctp_socket)) {
7293 sowwakeup_locked(inp->sctp_socket);
7295 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7297 SCTP_INP_WLOCK(inp);
7299 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7300 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7301 SCTP_INP_WUNLOCK(inp);
7302 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7303 if (soreadable(inp->sctp_socket)) {
7304 sctp_defered_wakeup_cnt++;
7305 sorwakeup_locked(inp->sctp_socket);
7307 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7309 SCTP_INP_WLOCK(inp);
7311 SCTP_INP_WUNLOCK(inp);
7313 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7314 SCTP_TCB_LOCK(stcb);
7315 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7316 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7323 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7325 struct sockaddr_in *sin;
7327 struct sctp_inpcb *inp;
7328 struct sctp_ifa *sctp_ifa;
7331 * Do the malloc first in case it blocks.
7333 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7336 sin->sin_family = AF_INET;
7337 sin->sin_len = sizeof(*sin);
7338 inp = (struct sctp_inpcb *)so->so_pcb;
7340 SCTP_FREE_SONAME(sin);
7341 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7342 return (ECONNRESET);
7344 SCTP_INP_RLOCK(inp);
7345 sin->sin_port = inp->sctp_lport;
7346 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7347 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7348 struct sctp_tcb *stcb;
7349 struct sockaddr_in *sin_a;
7350 struct sctp_nets *net;
7353 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7359 SCTP_TCB_LOCK(stcb);
7360 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7361 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7363 /* this will make coverity happy */
7366 if (sin_a->sin_family == AF_INET) {
7371 if ((!fnd) || (sin_a == NULL)) {
7373 SCTP_TCB_UNLOCK(stcb);
7376 vrf_id = inp->def_vrf_id;
7377 sctp_ifa = sctp_source_address_selection(inp,
7379 (sctp_route_t *) & net->ro,
7382 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7383 sctp_free_ifa(sctp_ifa);
7385 SCTP_TCB_UNLOCK(stcb);
7387 /* For the bound all case you get back 0 */
7389 sin->sin_addr.s_addr = 0;
7393 /* Take the first IPv4 address in the list */
7394 struct sctp_laddr *laddr;
7397 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7398 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7399 struct sockaddr_in *sin_a;
7401 sin_a = &laddr->ifa->address.sin;
7402 sin->sin_addr = sin_a->sin_addr;
7408 SCTP_FREE_SONAME(sin);
7409 SCTP_INP_RUNLOCK(inp);
7410 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7414 SCTP_INP_RUNLOCK(inp);
7415 (*addr) = (struct sockaddr *)sin;
7420 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7422 struct sockaddr_in *sin;
7424 struct sockaddr_in *sin_a;
7425 struct sctp_inpcb *inp;
7426 struct sctp_tcb *stcb;
7427 struct sctp_nets *net;
7429 /* Do the malloc first in case it blocks. */
7430 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7433 sin->sin_family = AF_INET;
7434 sin->sin_len = sizeof(*sin);
7436 inp = (struct sctp_inpcb *)so->so_pcb;
7437 if ((inp == NULL) ||
7438 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7439 /* UDP type and listeners will drop out here */
7440 SCTP_FREE_SONAME(sin);
7441 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7444 SCTP_INP_RLOCK(inp);
7445 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7447 SCTP_TCB_LOCK(stcb);
7449 SCTP_INP_RUNLOCK(inp);
7451 SCTP_FREE_SONAME(sin);
7452 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7453 return (ECONNRESET);
7456 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7457 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7458 if (sin_a->sin_family == AF_INET) {
7460 sin->sin_port = stcb->rport;
7461 sin->sin_addr = sin_a->sin_addr;
7465 SCTP_TCB_UNLOCK(stcb);
7467 /* No IPv4 address */
7468 SCTP_FREE_SONAME(sin);
7469 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7472 (*addr) = (struct sockaddr *)sin;
7476 struct pr_usrreqs sctp_usrreqs = {
7477 .pru_abort = sctp_abort,
7478 .pru_accept = sctp_accept,
7479 .pru_attach = sctp_attach,
7480 .pru_bind = sctp_bind,
7481 .pru_connect = sctp_connect,
7482 .pru_control = in_control,
7483 .pru_close = sctp_close,
7484 .pru_detach = sctp_close,
7485 .pru_sopoll = sopoll_generic,
7486 .pru_flush = sctp_flush,
7487 .pru_disconnect = sctp_disconnect,
7488 .pru_listen = sctp_listen,
7489 .pru_peeraddr = sctp_peeraddr,
7490 .pru_send = sctp_sendm,
7491 .pru_shutdown = sctp_shutdown,
7492 .pru_sockaddr = sctp_ingetaddr,
7493 .pru_sosend = sctp_sosend,
7494 .pru_soreceive = sctp_soreceive