2 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * a) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
12 * b) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the distribution.
16 * c) Neither the name of Cisco Systems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <netinet/sctp_os.h>
38 #include <netinet/sctp_pcb.h>
39 #include <netinet/sctp_header.h>
40 #include <netinet/sctp_var.h>
42 #include <netinet6/sctp6_var.h>
44 #include <netinet/sctp_sysctl.h>
45 #include <netinet/sctp_output.h>
46 #include <netinet/sctp_uio.h>
47 #include <netinet/sctp_asconf.h>
48 #include <netinet/sctputil.h>
49 #include <netinet/sctp_indata.h>
50 #include <netinet/sctp_timer.h>
51 #include <netinet/sctp_auth.h>
52 #include <netinet/sctp_bsd_addr.h>
53 #include <netinet/udp.h>
57 extern const struct sctp_cc_functions sctp_cc_functions[];
58 extern const struct sctp_ss_functions sctp_ss_functions[];
65 /* Initialize and modify the sysctled variables */
67 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
68 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
70 * Allow a user to take no more than 1/2 the number of clusters or
71 * the SB_MAX whichever is smaller for the send window.
73 sb_max_adj = (u_long)((u_quad_t) (SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
74 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
75 (((uint32_t) nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
77 * Now for the recv window, should we take the same amount? or
78 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
79 * now I will just copy.
81 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
82 SCTP_BASE_VAR(first_time) = 0;
83 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
85 #if defined(SCTP_PACKET_LOGGING)
86 SCTP_BASE_VAR(packet_log_writers) = 0;
87 SCTP_BASE_VAR(packet_log_end) = 0;
88 bzero(&SCTP_BASE_VAR(packet_log_buffer), SCTP_PACKET_LOG_SIZE);
94 sctp_finish(void *unused __unused)
99 VNET_SYSUNINIT(sctp, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, sctp_finish, NULL);
103 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
105 struct sctp_tmit_chunk *chk;
108 /* Adjust that too */
109 stcb->asoc.smallest_mtu = nxtsz;
110 /* now off to subtract IP_DF flag if needed */
111 overhead = IP_HDR_SIZE;
112 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
113 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
115 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
116 if ((chk->send_size + overhead) > nxtsz) {
117 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
120 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
121 if ((chk->send_size + overhead) > nxtsz) {
123 * For this guy we also mark for immediate resend
124 * since we sent to big of chunk
126 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
127 if (chk->sent < SCTP_DATAGRAM_RESEND) {
128 sctp_flight_size_decrease(chk);
129 sctp_total_flight_decrease(stcb, chk);
130 chk->sent = SCTP_DATAGRAM_RESEND;
131 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
132 chk->rec.data.doing_fast_retransmit = 0;
133 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
134 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
135 chk->whoTo->flight_size,
137 (uint32_t) (uintptr_t) chk->whoTo,
138 chk->rec.data.TSN_seq);
140 /* Clear any time so NO RTT is being done */
149 sctp_notify(struct sctp_inpcb *inp,
150 struct sctp_tcb *stcb,
151 struct sctp_nets *net,
157 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
162 if (icmp_type != ICMP_UNREACH) {
163 /* We only care about unreachable */
164 SCTP_TCB_UNLOCK(stcb);
167 if ((icmp_code == ICMP_UNREACH_NET) ||
168 (icmp_code == ICMP_UNREACH_HOST) ||
169 (icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
170 (icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
171 (icmp_code == ICMP_UNREACH_ISOLATED) ||
172 (icmp_code == ICMP_UNREACH_NET_PROHIB) ||
173 (icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
174 (icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
175 /* Mark the net unreachable. */
176 if (net->dest_state & SCTP_ADDR_REACHABLE) {
177 /* OK, that destination is NOT reachable. */
178 net->dest_state &= ~SCTP_ADDR_REACHABLE;
179 net->dest_state &= ~SCTP_ADDR_PF;
180 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
182 (void *)net, SCTP_SO_NOT_LOCKED);
184 SCTP_TCB_UNLOCK(stcb);
185 } else if ((icmp_code == ICMP_UNREACH_PROTOCOL) ||
186 (icmp_code == ICMP_UNREACH_PORT)) {
187 /* Treat it like an ABORT. */
188 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
189 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
190 so = SCTP_INP_SO(inp);
191 atomic_add_int(&stcb->asoc.refcnt, 1);
192 SCTP_TCB_UNLOCK(stcb);
193 SCTP_SOCKET_LOCK(so, 1);
195 atomic_subtract_int(&stcb->asoc.refcnt, 1);
197 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
198 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
199 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
200 SCTP_SOCKET_UNLOCK(so, 1);
201 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
203 /* no need to unlock here, since the TCB is gone */
204 } else if (icmp_code == ICMP_UNREACH_NEEDFRAG) {
205 /* Find the next (smaller) MTU */
208 * Old type router that does not tell us what the
209 * next MTU is. Rats we will have to guess (in a
210 * educated fashion of course).
212 next_mtu = sctp_get_prev_mtu(ip_len);
214 /* Stop the PMTU timer. */
215 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
217 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
218 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
222 /* Update the path MTU. */
223 if (net->mtu > next_mtu) {
226 net->mtu -= sizeof(struct udphdr);
229 /* Update the association MTU */
230 if (stcb->asoc.smallest_mtu > next_mtu) {
231 sctp_pathmtu_adjustment(stcb, next_mtu);
233 /* Finally, start the PMTU timer if it was running before. */
235 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
237 SCTP_TCB_UNLOCK(stcb);
239 SCTP_TCB_UNLOCK(stcb);
244 sctp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
250 struct sctp_inpcb *inp;
251 struct sctp_tcb *stcb;
252 struct sctp_nets *net;
253 struct sctp_init_chunk *ch;
254 struct sockaddr_in src, dst;
256 if (sa->sa_family != AF_INET ||
257 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
260 if (PRC_IS_REDIRECT(cmd)) {
262 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
266 inner_ip = (struct ip *)vip;
267 icmp = (struct icmp *)((caddr_t)inner_ip -
268 (sizeof(struct icmp) - sizeof(struct ip)));
269 outer_ip = (struct ip *)((caddr_t)icmp - sizeof(struct ip));
270 sh = (struct sctphdr *)((caddr_t)inner_ip + (inner_ip->ip_hl << 2));
271 memset(&src, 0, sizeof(struct sockaddr_in));
272 src.sin_family = AF_INET;
273 src.sin_len = sizeof(struct sockaddr_in);
274 src.sin_port = sh->src_port;
275 src.sin_addr = inner_ip->ip_src;
276 memset(&dst, 0, sizeof(struct sockaddr_in));
277 dst.sin_family = AF_INET;
278 dst.sin_len = sizeof(struct sockaddr_in);
279 dst.sin_port = sh->dest_port;
280 dst.sin_addr = inner_ip->ip_dst;
282 * 'dst' holds the dest of the packet that failed to be
283 * sent. 'src' holds our local endpoint address. Thus we
284 * reverse the dst and the src in the lookup.
288 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst,
289 (struct sockaddr *)&src,
292 if ((stcb != NULL) &&
295 /* Check the verification tag */
296 if (ntohl(sh->v_tag) != 0) {
298 * This must be the verification tag used
299 * for sending out packets. We don't
300 * consider packets reflecting the
303 if (ntohl(sh->v_tag) != stcb->asoc.peer_vtag) {
304 SCTP_TCB_UNLOCK(stcb);
308 if (ntohs(outer_ip->ip_len) >=
310 8 + (inner_ip->ip_hl << 2) + 20) {
312 * In this case we can check if we
313 * got an INIT chunk and if the
314 * initiate tag matches.
316 ch = (struct sctp_init_chunk *)(sh + 1);
317 if ((ch->ch.chunk_type != SCTP_INITIATION) ||
318 (ntohl(ch->init.initiate_tag) != stcb->asoc.my_vtag)) {
319 SCTP_TCB_UNLOCK(stcb);
323 SCTP_TCB_UNLOCK(stcb);
327 sctp_notify(inp, stcb, net,
330 ntohs(inner_ip->ip_len),
331 ntohs(icmp->icmp_nextmtu));
333 if ((stcb == NULL) && (inp != NULL)) {
334 /* reduce ref-count */
336 SCTP_INP_DECR_REF(inp);
337 SCTP_INP_WUNLOCK(inp);
340 SCTP_TCB_UNLOCK(stcb);
349 sctp_getcred(SYSCTL_HANDLER_ARGS)
352 struct sockaddr_in addrs[2];
353 struct sctp_inpcb *inp;
354 struct sctp_nets *net;
355 struct sctp_tcb *stcb;
359 /* FIX, for non-bsd is this right? */
360 vrf_id = SCTP_DEFAULT_VRFID;
362 error = priv_check(req->td, PRIV_NETINET_GETCRED);
367 error = SYSCTL_IN(req, addrs, sizeof(addrs));
371 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
373 &inp, &net, 1, vrf_id);
374 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
375 if ((inp != NULL) && (stcb == NULL)) {
376 /* reduce ref-count */
378 SCTP_INP_DECR_REF(inp);
381 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
385 SCTP_TCB_UNLOCK(stcb);
387 * We use the write lock here, only since in the error leg we need
388 * it. If we used RLOCK, then we would have to
389 * wlock/decr/unlock/rlock. Which in theory could create a hole.
390 * Better to use higher wlock.
394 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
396 SCTP_INP_WUNLOCK(inp);
399 cru2x(inp->sctp_socket->so_cred, &xuc);
400 SCTP_INP_WUNLOCK(inp);
401 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
406 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
407 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
412 sctp_abort(struct socket *so)
414 struct sctp_inpcb *inp;
417 inp = (struct sctp_inpcb *)so->so_pcb;
422 flags = inp->sctp_flags;
423 #ifdef SCTP_LOG_CLOSING
424 sctp_log_closing(inp, NULL, 17);
426 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
427 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
428 #ifdef SCTP_LOG_CLOSING
429 sctp_log_closing(inp, NULL, 16);
431 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
432 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
434 SCTP_SB_CLEAR(so->so_snd);
436 * same for the rcv ones, they are only here for the
439 SCTP_SB_CLEAR(so->so_rcv);
441 /* Now null out the reference, we are completely detached. */
445 flags = inp->sctp_flags;
446 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
447 goto sctp_must_try_again;
454 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
456 struct sctp_inpcb *inp;
457 struct inpcb *ip_inp;
459 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
461 inp = (struct sctp_inpcb *)so->so_pcb;
463 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
466 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
467 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
472 error = sctp_inpcb_alloc(so, vrf_id);
476 inp = (struct sctp_inpcb *)so->so_pcb;
478 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
479 ip_inp = &inp->ip_inp.inp;
480 ip_inp->inp_vflag |= INP_IPV4;
481 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
482 SCTP_INP_WUNLOCK(inp);
487 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
489 struct sctp_inpcb *inp;
491 inp = (struct sctp_inpcb *)so->so_pcb;
493 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
497 if ((addr->sa_family != AF_INET) ||
498 (addr->sa_len != sizeof(struct sockaddr_in))) {
499 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
503 return (sctp_inpcb_bind(so, addr, NULL, p));
508 sctp_close(struct socket *so)
510 struct sctp_inpcb *inp;
513 inp = (struct sctp_inpcb *)so->so_pcb;
518 * Inform all the lower layer assoc that we are done.
521 flags = inp->sctp_flags;
522 #ifdef SCTP_LOG_CLOSING
523 sctp_log_closing(inp, NULL, 17);
525 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
526 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
527 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
528 (so->so_rcv.sb_cc > 0)) {
529 #ifdef SCTP_LOG_CLOSING
530 sctp_log_closing(inp, NULL, 13);
532 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
533 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
535 #ifdef SCTP_LOG_CLOSING
536 sctp_log_closing(inp, NULL, 14);
538 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
539 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
542 * The socket is now detached, no matter what the state of
543 * the SCTP association.
546 SCTP_SB_CLEAR(so->so_snd);
548 * same for the rcv ones, they are only here for the
551 SCTP_SB_CLEAR(so->so_rcv);
553 /* Now null out the reference, we are completely detached. */
557 flags = inp->sctp_flags;
558 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
559 goto sctp_must_try_again;
567 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
568 struct mbuf *control, struct thread *p);
572 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
573 struct mbuf *control, struct thread *p)
575 struct sctp_inpcb *inp;
578 inp = (struct sctp_inpcb *)so->so_pcb;
581 sctp_m_freem(control);
584 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
588 /* Got to have an to address if we are NOT a connected socket */
589 if ((addr == NULL) &&
590 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
591 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
593 } else if (addr == NULL) {
594 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
595 error = EDESTADDRREQ;
598 sctp_m_freem(control);
604 if (addr->sa_family != AF_INET) {
605 /* must be a v4 address! */
606 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
609 sctp_m_freem(control);
612 error = EDESTADDRREQ;
617 /* now what about control */
620 SCTP_PRINTF("huh? control set?\n");
621 sctp_m_freem(inp->control);
624 inp->control = control;
628 SCTP_BUF_NEXT(inp->pkt_last) = m;
631 inp->pkt_last = inp->pkt = m;
634 /* FreeBSD uses a flag passed */
635 ((flags & PRUS_MORETOCOME) == 0)
638 * note with the current version this code will only be used
639 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
640 * re-defining sosend to use the sctp_sosend. One can
641 * optionally switch back to this code (by changing back the
642 * definitions) but this is not advisable. This code is used
643 * by FreeBSD when sending a file with sendfile() though.
647 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
657 sctp_disconnect(struct socket *so)
659 struct sctp_inpcb *inp;
661 inp = (struct sctp_inpcb *)so->so_pcb;
663 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
667 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
668 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
669 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
671 SCTP_INP_RUNLOCK(inp);
674 struct sctp_association *asoc;
675 struct sctp_tcb *stcb;
677 stcb = LIST_FIRST(&inp->sctp_asoc_list);
679 SCTP_INP_RUNLOCK(inp);
680 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
685 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
686 /* We are about to be freed, out of here */
687 SCTP_TCB_UNLOCK(stcb);
688 SCTP_INP_RUNLOCK(inp);
691 if (((so->so_options & SO_LINGER) &&
692 (so->so_linger == 0)) ||
693 (so->so_rcv.sb_cc > 0)) {
694 if (SCTP_GET_STATE(asoc) !=
695 SCTP_STATE_COOKIE_WAIT) {
696 /* Left with Data unread */
699 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_NOWAIT, 1, MT_DATA);
705 struct sctp_paramhdr *ph;
707 ph = mtod(err, struct sctp_paramhdr *);
708 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
709 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
710 ph->param_length = htons(SCTP_BUF_LEN(err));
712 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
713 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
715 SCTP_INP_RUNLOCK(inp);
716 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
717 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
718 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
720 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
721 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
722 /* No unlock tcb assoc is gone */
725 if (TAILQ_EMPTY(&asoc->send_queue) &&
726 TAILQ_EMPTY(&asoc->sent_queue) &&
727 (asoc->stream_queue_cnt == 0)) {
728 /* there is nothing queued to send, so done */
729 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
732 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
733 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
734 /* only send SHUTDOWN 1st time thru */
735 struct sctp_nets *netp;
737 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
738 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
739 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
741 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
742 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
743 sctp_stop_timers_for_shutdown(stcb);
744 if (stcb->asoc.alternate) {
745 netp = stcb->asoc.alternate;
747 netp = stcb->asoc.primary_destination;
749 sctp_send_shutdown(stcb, netp);
750 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
751 stcb->sctp_ep, stcb, netp);
752 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
753 stcb->sctp_ep, stcb, netp);
754 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
758 * we still got (or just got) data to send,
759 * so set SHUTDOWN_PENDING
762 * XXX sockets draft says that SCTP_EOF
763 * should be sent with no data. currently,
764 * we will allow user data to be sent first
765 * and move to SHUTDOWN-PENDING
767 struct sctp_nets *netp;
769 if (stcb->asoc.alternate) {
770 netp = stcb->asoc.alternate;
772 netp = stcb->asoc.primary_destination;
775 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
776 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
778 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
779 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
781 if (TAILQ_EMPTY(&asoc->send_queue) &&
782 TAILQ_EMPTY(&asoc->sent_queue) &&
783 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
787 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
788 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
789 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
790 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
791 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
792 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
793 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
795 SCTP_INP_RUNLOCK(inp);
796 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
797 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
800 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
803 soisdisconnecting(so);
804 SCTP_TCB_UNLOCK(stcb);
805 SCTP_INP_RUNLOCK(inp);
810 /* UDP model does not support this */
811 SCTP_INP_RUNLOCK(inp);
812 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
818 sctp_flush(struct socket *so, int how)
821 * We will just clear out the values and let subsequent close clear
822 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
823 * they will not be able to read the data, the socket will block
824 * that from happening.
826 struct sctp_inpcb *inp;
828 inp = (struct sctp_inpcb *)so->so_pcb;
830 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
834 /* For the 1 to many model this does nothing */
835 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
836 SCTP_INP_RUNLOCK(inp);
839 SCTP_INP_RUNLOCK(inp);
840 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
842 * First make sure the sb will be happy, we don't use these
843 * except maybe the count
846 SCTP_INP_READ_LOCK(inp);
847 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
848 SCTP_INP_READ_UNLOCK(inp);
849 SCTP_INP_WUNLOCK(inp);
850 so->so_rcv.sb_cc = 0;
851 so->so_rcv.sb_mbcnt = 0;
852 so->so_rcv.sb_mb = NULL;
854 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
856 * First make sure the sb will be happy, we don't use these
857 * except maybe the count
859 so->so_snd.sb_cc = 0;
860 so->so_snd.sb_mbcnt = 0;
861 so->so_snd.sb_mb = NULL;
868 sctp_shutdown(struct socket *so)
870 struct sctp_inpcb *inp;
872 inp = (struct sctp_inpcb *)so->so_pcb;
874 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
878 /* For UDP model this is a invalid call */
879 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
880 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
881 /* Restore the flags that the soshutdown took away. */
882 SOCKBUF_LOCK(&so->so_rcv);
883 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
884 SOCKBUF_UNLOCK(&so->so_rcv);
885 /* This proc will wakeup for read and do nothing (I hope) */
886 SCTP_INP_RUNLOCK(inp);
887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
891 * Ok, if we reach here its the TCP model and it is either a
892 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
895 struct sctp_tcb *stcb;
896 struct sctp_association *asoc;
897 struct sctp_nets *netp;
900 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
901 SCTP_INP_RUNLOCK(inp);
906 stcb = LIST_FIRST(&inp->sctp_asoc_list);
909 * Ok, we hit the case that the shutdown call was
910 * made after an abort or something. Nothing to do
913 SCTP_INP_RUNLOCK(inp);
918 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
919 SCTP_TCB_UNLOCK(stcb);
920 SCTP_INP_RUNLOCK(inp);
923 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_WAIT) &&
924 (SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_ECHOED) &&
925 (SCTP_GET_STATE(asoc) != SCTP_STATE_OPEN)) {
927 * If we are not in or before ESTABLISHED, there is
928 * no protocol action required.
930 SCTP_TCB_UNLOCK(stcb);
931 SCTP_INP_RUNLOCK(inp);
934 if (stcb->asoc.alternate) {
935 netp = stcb->asoc.alternate;
937 netp = stcb->asoc.primary_destination;
939 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) &&
940 TAILQ_EMPTY(&asoc->send_queue) &&
941 TAILQ_EMPTY(&asoc->sent_queue) &&
942 (asoc->stream_queue_cnt == 0)) {
943 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
946 /* there is nothing queued to send, so I'm done... */
947 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
948 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
949 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
950 sctp_stop_timers_for_shutdown(stcb);
951 sctp_send_shutdown(stcb, netp);
952 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
953 stcb->sctp_ep, stcb, netp);
956 * We still got (or just got) data to send, so set
959 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
960 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
961 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_PARTIAL_MSG_LEFT);
963 if (TAILQ_EMPTY(&asoc->send_queue) &&
964 TAILQ_EMPTY(&asoc->sent_queue) &&
965 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
969 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
970 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
971 sctp_abort_an_association(stcb->sctp_ep, stcb,
972 op_err, SCTP_SO_LOCKED);
973 SCTP_INP_RUNLOCK(inp);
977 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, netp);
978 /* XXX: Why do this in the case where we have still data
980 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
981 SCTP_TCB_UNLOCK(stcb);
982 SCTP_INP_RUNLOCK(inp);
988 * copies a "user" presentable address and removes embedded scope, etc.
989 * returns 0 on success, 1 on error
992 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
995 struct sockaddr_in6 lsa6;
997 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1000 memcpy(ss, sa, sa->sa_len);
1007 * NOTE: assumes addr lock is held
1010 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1011 struct sctp_tcb *stcb,
1013 struct sockaddr_storage *sas,
1016 struct sctp_ifn *sctp_ifn;
1017 struct sctp_ifa *sctp_ifa;
1021 int ipv4_local_scope, ipv4_addr_legal;
1024 int local_scope, site_scope, ipv6_addr_legal;
1026 struct sctp_vrf *vrf;
1033 /* Turn on all the appropriate scope */
1034 loopback_scope = stcb->asoc.scope.loopback_scope;
1036 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1037 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1040 local_scope = stcb->asoc.scope.local_scope;
1041 site_scope = stcb->asoc.scope.site_scope;
1042 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1045 /* Use generic values for endpoints. */
1048 ipv4_local_scope = 1;
1054 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1056 ipv6_addr_legal = 1;
1059 if (SCTP_IPV6_V6ONLY(inp)) {
1060 ipv4_addr_legal = 0;
1062 ipv4_addr_legal = 1;
1067 ipv6_addr_legal = 0;
1070 ipv4_addr_legal = 1;
1074 vrf = sctp_find_vrf(vrf_id);
1078 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1079 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1080 if ((loopback_scope == 0) &&
1081 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1082 /* Skip loopback if loopback_scope not set */
1085 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1088 * For the BOUND-ALL case, the list
1089 * associated with a TCB is Always
1090 * considered a reverse list.. i.e.
1091 * it lists addresses that are NOT
1092 * part of the association. If this
1093 * is one of those we must skip it.
1095 if (sctp_is_addr_restricted(stcb,
1100 switch (sctp_ifa->address.sa.sa_family) {
1103 if (ipv4_addr_legal) {
1104 struct sockaddr_in *sin;
1106 sin = &sctp_ifa->address.sin;
1107 if (sin->sin_addr.s_addr == 0) {
1115 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1116 &sin->sin_addr) != 0) {
1119 if ((ipv4_local_scope == 0) &&
1120 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1124 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1125 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1126 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1127 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1128 actual += sizeof(struct sockaddr_in6);
1131 memcpy(sas, sin, sizeof(*sin));
1132 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1133 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1134 actual += sizeof(*sin);
1138 if (actual >= limit) {
1148 if (ipv6_addr_legal) {
1149 struct sockaddr_in6 *sin6;
1151 sin6 = &sctp_ifa->address.sin6;
1152 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1160 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1161 &sin6->sin6_addr) != 0) {
1164 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1165 if (local_scope == 0)
1167 if (sin6->sin6_scope_id == 0) {
1168 if (sa6_recoverscope(sin6) != 0)
1181 if ((site_scope == 0) &&
1182 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1185 memcpy(sas, sin6, sizeof(*sin6));
1186 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1187 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1188 actual += sizeof(*sin6);
1189 if (actual >= limit) {
1204 struct sctp_laddr *laddr;
1206 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1208 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1212 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1214 switch (laddr->ifa->address.sa.sa_family) {
1217 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1222 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1229 sas = (struct sockaddr_storage *)((caddr_t)sas +
1230 laddr->ifa->address.sa.sa_len);
1231 actual += laddr->ifa->address.sa.sa_len;
1232 if (actual >= limit) {
1241 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1242 struct sctp_tcb *stcb,
1244 struct sockaddr_storage *sas)
1248 SCTP_IPI_ADDR_RLOCK();
1249 /* fill up addresses for the endpoint's default vrf */
1250 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1252 SCTP_IPI_ADDR_RUNLOCK();
1257 * NOTE: assumes addr lock is held
1260 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1263 struct sctp_vrf *vrf = NULL;
1266 * In both sub-set bound an bound_all cases we return the MAXIMUM
1267 * number of addresses that you COULD get. In reality the sub-set
1268 * bound may have an exclusion list for a given TCB OR in the
1269 * bound-all case a TCB may NOT include the loopback or other
1270 * addresses as well.
1272 vrf = sctp_find_vrf(vrf_id);
1276 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1277 struct sctp_ifn *sctp_ifn;
1278 struct sctp_ifa *sctp_ifa;
1280 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1281 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1282 /* Count them if they are the right type */
1283 switch (sctp_ifa->address.sa.sa_family) {
1287 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1288 cnt += sizeof(struct sockaddr_in6);
1290 cnt += sizeof(struct sockaddr_in);
1292 cnt += sizeof(struct sockaddr_in);
1298 cnt += sizeof(struct sockaddr_in6);
1307 struct sctp_laddr *laddr;
1309 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1310 switch (laddr->ifa->address.sa.sa_family) {
1314 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1315 cnt += sizeof(struct sockaddr_in6);
1317 cnt += sizeof(struct sockaddr_in);
1319 cnt += sizeof(struct sockaddr_in);
1325 cnt += sizeof(struct sockaddr_in6);
1337 sctp_count_max_addresses(struct sctp_inpcb *inp)
1341 SCTP_IPI_ADDR_RLOCK();
1342 /* count addresses for the endpoint's default VRF */
1343 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1344 SCTP_IPI_ADDR_RUNLOCK();
1349 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1350 size_t optsize, void *p, int delay)
1353 int creat_lock_on = 0;
1354 struct sctp_tcb *stcb = NULL;
1355 struct sockaddr *sa;
1356 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1358 int bad_addresses = 0;
1361 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1363 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1364 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1365 /* We are already connected AND the TCP model */
1366 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1367 return (EADDRINUSE);
1369 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1370 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1371 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1374 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1375 SCTP_INP_RLOCK(inp);
1376 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1377 SCTP_INP_RUNLOCK(inp);
1380 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1383 SCTP_INP_INCR_REF(inp);
1384 SCTP_ASOC_CREATE_LOCK(inp);
1386 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1387 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1388 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1392 totaddrp = (unsigned int *)optval;
1393 totaddr = *totaddrp;
1394 sa = (struct sockaddr *)(totaddrp + 1);
1395 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (unsigned int)(optsize - sizeof(int)), &bad_addresses);
1396 if ((stcb != NULL) || bad_addresses) {
1397 /* Already have or am bring up an association */
1398 SCTP_ASOC_CREATE_UNLOCK(inp);
1401 SCTP_TCB_UNLOCK(stcb);
1402 if (bad_addresses == 0) {
1403 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1409 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1414 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1416 struct in6pcb *inp6;
1418 inp6 = (struct in6pcb *)inp;
1419 if (SCTP_IPV6_V6ONLY(inp6)) {
1421 * if IPV6_V6ONLY flag, ignore connections destined
1422 * to a v4 addr or v4-mapped addr
1424 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1430 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1431 SCTP_PCB_FLAGS_UNBOUND) {
1432 /* Bind a ephemeral port */
1433 error = sctp_inpcb_bind(so, NULL, NULL, p);
1438 /* FIX ME: do we want to pass in a vrf on the connect call? */
1439 vrf_id = inp->def_vrf_id;
1442 /* We are GOOD to go */
1443 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1444 inp->sctp_ep.pre_open_stream_count,
1449 /* Gak! no memory */
1452 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1453 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1454 /* Set the connected flag so we can queue data */
1457 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1458 /* move to second address */
1459 switch (sa->sa_family) {
1462 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1467 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1475 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1476 /* Fill in the return id */
1478 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE,
1479 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
1482 a_id = (sctp_assoc_t *) optval;
1483 *a_id = sctp_get_associd(stcb);
1485 /* initialize authentication parameters for the assoc */
1486 sctp_initialize_auth_params(inp, stcb);
1489 /* doing delayed connection */
1490 stcb->asoc.delayed_connection = 1;
1491 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1493 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1494 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1496 SCTP_TCB_UNLOCK(stcb);
1498 if (creat_lock_on) {
1499 SCTP_ASOC_CREATE_UNLOCK(inp);
1501 SCTP_INP_DECR_REF(inp);
1505 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1506 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1507 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1508 SCTP_INP_RLOCK(inp); \
1509 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1511 SCTP_TCB_LOCK(stcb); \
1513 SCTP_INP_RUNLOCK(inp); \
1514 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1515 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1516 if (stcb == NULL) { \
1517 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1527 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1528 if (size < sizeof(type)) { \
1529 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1533 destp = (type *)srcp; \
1538 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1541 struct sctp_inpcb *inp = NULL;
1543 struct sctp_tcb *stcb = NULL;
1545 if (optval == NULL) {
1546 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1549 inp = (struct sctp_inpcb *)so->so_pcb;
1551 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1558 case SCTP_AUTOCLOSE:
1559 case SCTP_EXPLICIT_EOR:
1560 case SCTP_AUTO_ASCONF:
1561 case SCTP_DISABLE_FRAGMENTS:
1562 case SCTP_I_WANT_MAPPED_V4_ADDR:
1563 case SCTP_USE_EXT_RCVINFO:
1564 SCTP_INP_RLOCK(inp);
1566 case SCTP_DISABLE_FRAGMENTS:
1567 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1569 case SCTP_I_WANT_MAPPED_V4_ADDR:
1570 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1572 case SCTP_AUTO_ASCONF:
1573 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1574 /* only valid for bound all sockets */
1575 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1577 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1582 case SCTP_EXPLICIT_EOR:
1583 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1586 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1588 case SCTP_USE_EXT_RCVINFO:
1589 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1591 case SCTP_AUTOCLOSE:
1592 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1593 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1599 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1600 error = ENOPROTOOPT;
1601 } /* end switch (sopt->sopt_name) */
1602 if (*optsize < sizeof(val)) {
1603 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1607 SCTP_INP_RUNLOCK(inp);
1609 /* return the option value */
1610 *(int *)optval = val;
1611 *optsize = sizeof(val);
1614 case SCTP_GET_PACKET_LOG:
1616 #ifdef SCTP_PACKET_LOGGING
1620 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1621 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1624 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1629 case SCTP_REUSE_PORT:
1633 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1634 /* Can't do this for a 1-m socket */
1638 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1639 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1640 *optsize = sizeof(uint32_t);
1643 case SCTP_PARTIAL_DELIVERY_POINT:
1647 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1648 *value = inp->partial_delivery_point;
1649 *optsize = sizeof(uint32_t);
1652 case SCTP_FRAGMENT_INTERLEAVE:
1656 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1657 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1658 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1659 *value = SCTP_FRAG_LEVEL_2;
1661 *value = SCTP_FRAG_LEVEL_1;
1664 *value = SCTP_FRAG_LEVEL_0;
1666 *optsize = sizeof(uint32_t);
1669 case SCTP_INTERLEAVING_SUPPORTED:
1671 struct sctp_assoc_value *av;
1673 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1674 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1677 av->assoc_value = stcb->asoc.idata_supported;
1678 SCTP_TCB_UNLOCK(stcb);
1680 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1681 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1682 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1683 SCTP_INP_RLOCK(inp);
1684 if (inp->idata_supported) {
1685 av->assoc_value = 1;
1687 av->assoc_value = 0;
1689 SCTP_INP_RUNLOCK(inp);
1691 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1696 *optsize = sizeof(struct sctp_assoc_value);
1700 case SCTP_CMT_ON_OFF:
1702 struct sctp_assoc_value *av;
1704 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1705 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1707 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1708 SCTP_TCB_UNLOCK(stcb);
1710 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1711 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1712 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1713 SCTP_INP_RLOCK(inp);
1714 av->assoc_value = inp->sctp_cmt_on_off;
1715 SCTP_INP_RUNLOCK(inp);
1717 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1722 *optsize = sizeof(struct sctp_assoc_value);
1726 case SCTP_PLUGGABLE_CC:
1728 struct sctp_assoc_value *av;
1730 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1731 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1733 av->assoc_value = stcb->asoc.congestion_control_module;
1734 SCTP_TCB_UNLOCK(stcb);
1736 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1737 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1738 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1739 SCTP_INP_RLOCK(inp);
1740 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1741 SCTP_INP_RUNLOCK(inp);
1743 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1748 *optsize = sizeof(struct sctp_assoc_value);
1752 case SCTP_CC_OPTION:
1754 struct sctp_cc_option *cc_opt;
1756 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1757 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1761 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1764 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1765 *optsize = sizeof(struct sctp_cc_option);
1767 SCTP_TCB_UNLOCK(stcb);
1771 case SCTP_PLUGGABLE_SS:
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.stream_scheduling_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_ss_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);
1799 struct sctp_stream_value *av;
1801 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1802 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1804 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1805 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1806 &av->stream_value) < 0)) {
1807 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1810 *optsize = sizeof(struct sctp_stream_value);
1812 SCTP_TCB_UNLOCK(stcb);
1814 /* Can't get stream value without
1816 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1821 case SCTP_GET_ADDR_LEN:
1823 struct sctp_assoc_value *av;
1825 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1828 if (av->assoc_value == AF_INET) {
1829 av->assoc_value = sizeof(struct sockaddr_in);
1834 if (av->assoc_value == AF_INET6) {
1835 av->assoc_value = sizeof(struct sockaddr_in6);
1840 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1842 *optsize = sizeof(struct sctp_assoc_value);
1846 case SCTP_GET_ASSOC_NUMBER:
1848 uint32_t *value, cnt;
1850 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1851 SCTP_INP_RLOCK(inp);
1852 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1853 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1854 /* Can't do this for a 1-1 socket */
1856 SCTP_INP_RUNLOCK(inp);
1860 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1863 SCTP_INP_RUNLOCK(inp);
1865 *optsize = sizeof(uint32_t);
1868 case SCTP_GET_ASSOC_ID_LIST:
1870 struct sctp_assoc_ids *ids;
1874 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1875 SCTP_INP_RLOCK(inp);
1876 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1877 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1878 /* Can't do this for a 1-1 socket */
1880 SCTP_INP_RUNLOCK(inp);
1884 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1885 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1887 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1890 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1895 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1899 SCTP_INP_RUNLOCK(inp);
1901 ids->gaids_number_of_ids = at;
1902 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1908 struct sctp_assoc_value *av;
1910 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1911 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1914 av->assoc_value = stcb->asoc.context;
1915 SCTP_TCB_UNLOCK(stcb);
1917 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1918 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1919 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1920 SCTP_INP_RLOCK(inp);
1921 av->assoc_value = inp->sctp_context;
1922 SCTP_INP_RUNLOCK(inp);
1924 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1929 *optsize = sizeof(struct sctp_assoc_value);
1935 uint32_t *default_vrfid;
1937 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1938 *default_vrfid = inp->def_vrf_id;
1939 *optsize = sizeof(uint32_t);
1942 case SCTP_GET_ASOC_VRF:
1944 struct sctp_assoc_value *id;
1946 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1947 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1950 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1952 id->assoc_value = stcb->asoc.vrf_id;
1953 *optsize = sizeof(struct sctp_assoc_value);
1957 case SCTP_GET_VRF_IDS:
1959 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1963 case SCTP_GET_NONCE_VALUES:
1965 struct sctp_get_nonce_values *gnv;
1967 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1968 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1971 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1972 gnv->gn_local_tag = stcb->asoc.my_vtag;
1973 SCTP_TCB_UNLOCK(stcb);
1974 *optsize = sizeof(struct sctp_get_nonce_values);
1976 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1981 case SCTP_DELAYED_SACK:
1983 struct sctp_sack_info *sack;
1985 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1986 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1988 sack->sack_delay = stcb->asoc.delayed_ack;
1989 sack->sack_freq = stcb->asoc.sack_freq;
1990 SCTP_TCB_UNLOCK(stcb);
1992 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1993 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1994 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
1995 SCTP_INP_RLOCK(inp);
1996 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
1997 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
1998 SCTP_INP_RUNLOCK(inp);
2000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2005 *optsize = sizeof(struct sctp_sack_info);
2009 case SCTP_GET_SNDBUF_USE:
2011 struct sctp_sockstat *ss;
2013 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2014 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2017 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2018 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2019 stcb->asoc.size_on_all_streams);
2020 SCTP_TCB_UNLOCK(stcb);
2021 *optsize = sizeof(struct sctp_sockstat);
2023 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2028 case SCTP_MAX_BURST:
2030 struct sctp_assoc_value *av;
2032 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2033 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2036 av->assoc_value = stcb->asoc.max_burst;
2037 SCTP_TCB_UNLOCK(stcb);
2039 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2040 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2041 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2042 SCTP_INP_RLOCK(inp);
2043 av->assoc_value = inp->sctp_ep.max_burst;
2044 SCTP_INP_RUNLOCK(inp);
2046 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2051 *optsize = sizeof(struct sctp_assoc_value);
2057 struct sctp_assoc_value *av;
2060 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2061 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2064 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2065 SCTP_TCB_UNLOCK(stcb);
2067 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2068 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2069 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2070 SCTP_INP_RLOCK(inp);
2071 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2072 ovh = SCTP_MED_OVERHEAD;
2074 ovh = SCTP_MED_V4_OVERHEAD;
2076 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2077 av->assoc_value = 0;
2079 av->assoc_value = inp->sctp_frag_point - ovh;
2080 SCTP_INP_RUNLOCK(inp);
2082 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2087 *optsize = sizeof(struct sctp_assoc_value);
2091 case SCTP_GET_STAT_LOG:
2092 error = sctp_fill_stat_log(optval, optsize);
2096 struct sctp_event_subscribe *events;
2098 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2099 memset(events, 0, sizeof(struct sctp_event_subscribe));
2100 SCTP_INP_RLOCK(inp);
2101 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2102 events->sctp_data_io_event = 1;
2104 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2105 events->sctp_association_event = 1;
2107 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2108 events->sctp_address_event = 1;
2110 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2111 events->sctp_send_failure_event = 1;
2113 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2114 events->sctp_peer_error_event = 1;
2116 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2117 events->sctp_shutdown_event = 1;
2119 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2120 events->sctp_partial_delivery_event = 1;
2122 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2123 events->sctp_adaptation_layer_event = 1;
2125 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2126 events->sctp_authentication_event = 1;
2128 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2129 events->sctp_sender_dry_event = 1;
2131 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2132 events->sctp_stream_reset_event = 1;
2133 SCTP_INP_RUNLOCK(inp);
2134 *optsize = sizeof(struct sctp_event_subscribe);
2137 case SCTP_ADAPTATION_LAYER:
2141 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2143 SCTP_INP_RLOCK(inp);
2144 *value = inp->sctp_ep.adaptation_layer_indicator;
2145 SCTP_INP_RUNLOCK(inp);
2146 *optsize = sizeof(uint32_t);
2149 case SCTP_SET_INITIAL_DBG_SEQ:
2153 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2154 SCTP_INP_RLOCK(inp);
2155 *value = inp->sctp_ep.initial_sequence_debug;
2156 SCTP_INP_RUNLOCK(inp);
2157 *optsize = sizeof(uint32_t);
2160 case SCTP_GET_LOCAL_ADDR_SIZE:
2164 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2165 SCTP_INP_RLOCK(inp);
2166 *value = sctp_count_max_addresses(inp);
2167 SCTP_INP_RUNLOCK(inp);
2168 *optsize = sizeof(uint32_t);
2171 case SCTP_GET_REMOTE_ADDR_SIZE:
2175 struct sctp_nets *net;
2177 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2178 /* FIXME MT: change to sctp_assoc_value? */
2179 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2183 /* Count the sizes */
2184 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2185 switch (net->ro._l_addr.sa.sa_family) {
2189 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2190 size += sizeof(struct sockaddr_in6);
2192 size += sizeof(struct sockaddr_in);
2195 size += sizeof(struct sockaddr_in);
2201 size += sizeof(struct sockaddr_in6);
2208 SCTP_TCB_UNLOCK(stcb);
2209 *value = (uint32_t) size;
2210 *optsize = sizeof(uint32_t);
2212 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2217 case SCTP_GET_PEER_ADDRESSES:
2219 * Get the address information, an array is passed in to
2220 * fill up we pack it.
2224 struct sockaddr_storage *sas;
2225 struct sctp_nets *net;
2226 struct sctp_getaddresses *saddr;
2228 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2229 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2232 left = (*optsize) - sizeof(struct sctp_getaddresses);
2233 *optsize = sizeof(struct sctp_getaddresses);
2234 sas = (struct sockaddr_storage *)&saddr->addr[0];
2236 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2237 switch (net->ro._l_addr.sa.sa_family) {
2241 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2242 cpsz = sizeof(struct sockaddr_in6);
2244 cpsz = sizeof(struct sockaddr_in);
2247 cpsz = sizeof(struct sockaddr_in);
2253 cpsz = sizeof(struct sockaddr_in6);
2264 /* not enough room. */
2267 #if defined(INET) && defined(INET6)
2268 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2269 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2270 /* Must map the address */
2271 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2272 (struct sockaddr_in6 *)sas);
2274 memcpy(sas, &net->ro._l_addr, cpsz);
2277 memcpy(sas, &net->ro._l_addr, cpsz);
2279 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2281 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2285 SCTP_TCB_UNLOCK(stcb);
2287 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2292 case SCTP_GET_LOCAL_ADDRESSES:
2294 size_t limit, actual;
2295 struct sockaddr_storage *sas;
2296 struct sctp_getaddresses *saddr;
2298 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2299 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2301 sas = (struct sockaddr_storage *)&saddr->addr[0];
2302 limit = *optsize - sizeof(sctp_assoc_t);
2303 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2305 SCTP_TCB_UNLOCK(stcb);
2307 *optsize = sizeof(struct sockaddr_storage) + actual;
2310 case SCTP_PEER_ADDR_PARAMS:
2312 struct sctp_paddrparams *paddrp;
2313 struct sctp_nets *net;
2314 struct sockaddr *addr;
2315 #if defined(INET) && defined(INET6)
2316 struct sockaddr_in sin_store;
2319 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2320 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2322 #if defined(INET) && defined(INET6)
2323 if (paddrp->spp_address.ss_family == AF_INET6) {
2324 struct sockaddr_in6 *sin6;
2326 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2327 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2328 in6_sin6_2_sin(&sin_store, sin6);
2329 addr = (struct sockaddr *)&sin_store;
2331 addr = (struct sockaddr *)&paddrp->spp_address;
2334 addr = (struct sockaddr *)&paddrp->spp_address;
2337 addr = (struct sockaddr *)&paddrp->spp_address;
2340 net = sctp_findnet(stcb, addr);
2343 * We increment here since
2344 * sctp_findassociation_ep_addr() wil do a
2345 * decrement if it finds the stcb as long as
2346 * the locked tcb (last argument) is NOT a
2350 SCTP_INP_INCR_REF(inp);
2351 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2353 SCTP_INP_DECR_REF(inp);
2356 if ((stcb != NULL) && (net == NULL)) {
2358 if (addr->sa_family == AF_INET) {
2359 struct sockaddr_in *sin;
2361 sin = (struct sockaddr_in *)addr;
2362 if (sin->sin_addr.s_addr != INADDR_ANY) {
2364 SCTP_TCB_UNLOCK(stcb);
2365 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2371 if (addr->sa_family == AF_INET6) {
2372 struct sockaddr_in6 *sin6;
2374 sin6 = (struct sockaddr_in6 *)addr;
2375 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2377 SCTP_TCB_UNLOCK(stcb);
2378 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2384 error = EAFNOSUPPORT;
2385 SCTP_TCB_UNLOCK(stcb);
2386 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2391 /* Applies to the specific association */
2392 paddrp->spp_flags = 0;
2394 paddrp->spp_hbinterval = net->heart_beat_delay;
2395 paddrp->spp_pathmaxrxt = net->failure_threshold;
2396 paddrp->spp_pathmtu = net->mtu;
2397 switch (net->ro._l_addr.sa.sa_family) {
2400 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2405 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2411 /* get flags for HB */
2412 if (net->dest_state & SCTP_ADDR_NOHB) {
2413 paddrp->spp_flags |= SPP_HB_DISABLE;
2415 paddrp->spp_flags |= SPP_HB_ENABLE;
2417 /* get flags for PMTU */
2418 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2419 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2421 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2423 if (net->dscp & 0x01) {
2424 paddrp->spp_dscp = net->dscp & 0xfc;
2425 paddrp->spp_flags |= SPP_DSCP;
2428 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2429 (net->flowlabel & 0x80000000)) {
2430 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2431 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2436 * No destination so return default
2439 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2440 paddrp->spp_pathmtu = 0;
2441 if (stcb->asoc.default_dscp & 0x01) {
2442 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2443 paddrp->spp_flags |= SPP_DSCP;
2446 if (stcb->asoc.default_flowlabel & 0x80000000) {
2447 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2448 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2451 /* default settings should be these */
2452 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2453 paddrp->spp_flags |= SPP_HB_DISABLE;
2455 paddrp->spp_flags |= SPP_HB_ENABLE;
2457 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2458 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2460 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2462 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2464 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2465 SCTP_TCB_UNLOCK(stcb);
2467 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2468 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2469 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2470 /* Use endpoint defaults */
2471 SCTP_INP_RLOCK(inp);
2472 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2473 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2474 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2475 /* get inp's default */
2476 if (inp->sctp_ep.default_dscp & 0x01) {
2477 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2478 paddrp->spp_flags |= SPP_DSCP;
2481 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2482 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2483 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2484 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2487 /* can't return this */
2488 paddrp->spp_pathmtu = 0;
2490 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2491 paddrp->spp_flags |= SPP_HB_ENABLE;
2493 paddrp->spp_flags |= SPP_HB_DISABLE;
2495 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2496 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2498 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2500 SCTP_INP_RUNLOCK(inp);
2502 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2507 *optsize = sizeof(struct sctp_paddrparams);
2511 case SCTP_GET_PEER_ADDR_INFO:
2513 struct sctp_paddrinfo *paddri;
2514 struct sctp_nets *net;
2515 struct sockaddr *addr;
2516 #if defined(INET) && defined(INET6)
2517 struct sockaddr_in sin_store;
2520 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2521 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2523 #if defined(INET) && defined(INET6)
2524 if (paddri->spinfo_address.ss_family == AF_INET6) {
2525 struct sockaddr_in6 *sin6;
2527 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2528 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2529 in6_sin6_2_sin(&sin_store, sin6);
2530 addr = (struct sockaddr *)&sin_store;
2532 addr = (struct sockaddr *)&paddri->spinfo_address;
2535 addr = (struct sockaddr *)&paddri->spinfo_address;
2538 addr = (struct sockaddr *)&paddri->spinfo_address;
2541 net = sctp_findnet(stcb, addr);
2544 * We increment here since
2545 * sctp_findassociation_ep_addr() wil do a
2546 * decrement if it finds the stcb as long as
2547 * the locked tcb (last argument) is NOT a
2551 SCTP_INP_INCR_REF(inp);
2552 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2554 SCTP_INP_DECR_REF(inp);
2558 if ((stcb != NULL) && (net != NULL)) {
2559 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2560 /* It's unconfirmed */
2561 paddri->spinfo_state = SCTP_UNCONFIRMED;
2562 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2564 paddri->spinfo_state = SCTP_ACTIVE;
2567 paddri->spinfo_state = SCTP_INACTIVE;
2569 paddri->spinfo_cwnd = net->cwnd;
2570 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2571 paddri->spinfo_rto = net->RTO;
2572 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2573 paddri->spinfo_mtu = net->mtu;
2574 switch (addr->sa_family) {
2577 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2582 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2588 SCTP_TCB_UNLOCK(stcb);
2589 *optsize = sizeof(struct sctp_paddrinfo);
2592 SCTP_TCB_UNLOCK(stcb);
2594 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2599 case SCTP_PCB_STATUS:
2601 struct sctp_pcbinfo *spcb;
2603 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2604 sctp_fill_pcbinfo(spcb);
2605 *optsize = sizeof(struct sctp_pcbinfo);
2610 struct sctp_nets *net;
2611 struct sctp_status *sstat;
2613 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2614 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2617 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2621 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2622 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2623 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2624 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2626 * We can't include chunks that have been passed to
2627 * the socket layer. Only things in queue.
2629 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2630 stcb->asoc.cnt_on_all_streams);
2633 sstat->sstat_instrms = stcb->asoc.streamincnt;
2634 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2635 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2636 memcpy(&sstat->sstat_primary.spinfo_address,
2637 &stcb->asoc.primary_destination->ro._l_addr,
2638 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2639 net = stcb->asoc.primary_destination;
2640 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2642 * Again the user can get info from sctp_constants.h
2643 * for what the state of the network is.
2645 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2646 /* It's unconfirmed */
2647 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2648 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2650 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2653 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2655 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2656 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2657 sstat->sstat_primary.spinfo_rto = net->RTO;
2658 sstat->sstat_primary.spinfo_mtu = net->mtu;
2659 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2662 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2667 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2673 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2674 SCTP_TCB_UNLOCK(stcb);
2675 *optsize = sizeof(struct sctp_status);
2680 struct sctp_rtoinfo *srto;
2682 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2683 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2686 srto->srto_initial = stcb->asoc.initial_rto;
2687 srto->srto_max = stcb->asoc.maxrto;
2688 srto->srto_min = stcb->asoc.minrto;
2689 SCTP_TCB_UNLOCK(stcb);
2691 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2692 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2693 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2694 SCTP_INP_RLOCK(inp);
2695 srto->srto_initial = inp->sctp_ep.initial_rto;
2696 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2697 srto->srto_min = inp->sctp_ep.sctp_minrto;
2698 SCTP_INP_RUNLOCK(inp);
2700 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2705 *optsize = sizeof(struct sctp_rtoinfo);
2711 struct sctp_timeouts *stimo;
2713 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2714 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2717 stimo->stimo_init = stcb->asoc.timoinit;
2718 stimo->stimo_data = stcb->asoc.timodata;
2719 stimo->stimo_sack = stcb->asoc.timosack;
2720 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2721 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2722 stimo->stimo_cookie = stcb->asoc.timocookie;
2723 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2724 SCTP_TCB_UNLOCK(stcb);
2725 *optsize = sizeof(struct sctp_timeouts);
2727 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2732 case SCTP_ASSOCINFO:
2734 struct sctp_assocparams *sasoc;
2736 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2737 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2740 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2741 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2742 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2743 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2744 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2745 SCTP_TCB_UNLOCK(stcb);
2747 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2748 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2749 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2750 SCTP_INP_RLOCK(inp);
2751 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2752 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2753 sasoc->sasoc_number_peer_destinations = 0;
2754 sasoc->sasoc_peer_rwnd = 0;
2755 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2756 SCTP_INP_RUNLOCK(inp);
2758 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2763 *optsize = sizeof(struct sctp_assocparams);
2767 case SCTP_DEFAULT_SEND_PARAM:
2769 struct sctp_sndrcvinfo *s_info;
2771 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2772 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2775 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2776 SCTP_TCB_UNLOCK(stcb);
2778 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2779 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2780 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2781 SCTP_INP_RLOCK(inp);
2782 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2783 SCTP_INP_RUNLOCK(inp);
2785 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2790 *optsize = sizeof(struct sctp_sndrcvinfo);
2796 struct sctp_initmsg *sinit;
2798 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2799 SCTP_INP_RLOCK(inp);
2800 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2801 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2802 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2803 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2804 SCTP_INP_RUNLOCK(inp);
2805 *optsize = sizeof(struct sctp_initmsg);
2808 case SCTP_PRIMARY_ADDR:
2809 /* we allow a "get" operation on this */
2811 struct sctp_setprim *ssp;
2813 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2814 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2817 union sctp_sockstore *addr;
2819 addr = &stcb->asoc.primary_destination->ro._l_addr;
2820 switch (addr->sa.sa_family) {
2824 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2825 in6_sin_2_v4mapsin6(&addr->sin,
2826 (struct sockaddr_in6 *)&ssp->ssp_addr);
2828 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2831 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2837 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2843 SCTP_TCB_UNLOCK(stcb);
2844 *optsize = sizeof(struct sctp_setprim);
2846 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2851 case SCTP_HMAC_IDENT:
2853 struct sctp_hmacalgo *shmac;
2854 sctp_hmaclist_t *hmaclist;
2858 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2860 SCTP_INP_RLOCK(inp);
2861 hmaclist = inp->sctp_ep.local_hmacs;
2862 if (hmaclist == NULL) {
2863 /* no HMACs to return */
2864 *optsize = sizeof(*shmac);
2865 SCTP_INP_RUNLOCK(inp);
2868 /* is there room for all of the hmac ids? */
2869 size = sizeof(*shmac) + (hmaclist->num_algo *
2870 sizeof(shmac->shmac_idents[0]));
2871 if ((size_t)(*optsize) < size) {
2872 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2874 SCTP_INP_RUNLOCK(inp);
2877 /* copy in the list */
2878 shmac->shmac_number_of_idents = hmaclist->num_algo;
2879 for (i = 0; i < hmaclist->num_algo; i++) {
2880 shmac->shmac_idents[i] = hmaclist->hmac[i];
2882 SCTP_INP_RUNLOCK(inp);
2886 case SCTP_AUTH_ACTIVE_KEY:
2888 struct sctp_authkeyid *scact;
2890 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2891 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2894 /* get the active key on the assoc */
2895 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2896 SCTP_TCB_UNLOCK(stcb);
2898 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2899 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2900 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2901 /* get the endpoint active key */
2902 SCTP_INP_RLOCK(inp);
2903 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2904 SCTP_INP_RUNLOCK(inp);
2906 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2911 *optsize = sizeof(struct sctp_authkeyid);
2915 case SCTP_LOCAL_AUTH_CHUNKS:
2917 struct sctp_authchunks *sac;
2918 sctp_auth_chklist_t *chklist = NULL;
2921 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2922 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2925 /* get off the assoc */
2926 chklist = stcb->asoc.local_auth_chunks;
2927 /* is there enough space? */
2928 size = sctp_auth_get_chklist_size(chklist);
2929 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2931 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2933 /* copy in the chunks */
2934 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2935 sac->gauth_number_of_chunks = (uint32_t) size;
2936 *optsize = sizeof(struct sctp_authchunks) + size;
2938 SCTP_TCB_UNLOCK(stcb);
2940 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2941 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2942 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2943 /* get off the endpoint */
2944 SCTP_INP_RLOCK(inp);
2945 chklist = inp->sctp_ep.local_auth_chunks;
2946 /* is there enough space? */
2947 size = sctp_auth_get_chklist_size(chklist);
2948 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2950 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2952 /* copy in the chunks */
2953 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2954 sac->gauth_number_of_chunks = (uint32_t) size;
2955 *optsize = sizeof(struct sctp_authchunks) + size;
2957 SCTP_INP_RUNLOCK(inp);
2959 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2965 case SCTP_PEER_AUTH_CHUNKS:
2967 struct sctp_authchunks *sac;
2968 sctp_auth_chklist_t *chklist = NULL;
2971 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2972 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2975 /* get off the assoc */
2976 chklist = stcb->asoc.peer_auth_chunks;
2977 /* is there enough space? */
2978 size = sctp_auth_get_chklist_size(chklist);
2979 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2981 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2983 /* copy in the chunks */
2984 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2985 sac->gauth_number_of_chunks = (uint32_t) size;
2986 *optsize = sizeof(struct sctp_authchunks) + size;
2988 SCTP_TCB_UNLOCK(stcb);
2990 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2997 struct sctp_event *event;
2998 uint32_t event_type;
3000 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3001 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3003 switch (event->se_type) {
3004 case SCTP_ASSOC_CHANGE:
3005 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3007 case SCTP_PEER_ADDR_CHANGE:
3008 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3010 case SCTP_REMOTE_ERROR:
3011 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3013 case SCTP_SEND_FAILED:
3014 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3016 case SCTP_SHUTDOWN_EVENT:
3017 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3019 case SCTP_ADAPTATION_INDICATION:
3020 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3022 case SCTP_PARTIAL_DELIVERY_EVENT:
3023 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3025 case SCTP_AUTHENTICATION_EVENT:
3026 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3028 case SCTP_STREAM_RESET_EVENT:
3029 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3031 case SCTP_SENDER_DRY_EVENT:
3032 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3034 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3036 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3039 case SCTP_ASSOC_RESET_EVENT:
3040 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3042 case SCTP_STREAM_CHANGE_EVENT:
3043 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3045 case SCTP_SEND_FAILED_EVENT:
3046 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3050 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3054 if (event_type > 0) {
3056 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3057 SCTP_TCB_UNLOCK(stcb);
3059 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3060 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3061 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3062 SCTP_INP_RLOCK(inp);
3063 event->se_on = sctp_is_feature_on(inp, event_type);
3064 SCTP_INP_RUNLOCK(inp);
3066 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3072 *optsize = sizeof(struct sctp_event);
3076 case SCTP_RECVRCVINFO:
3080 if (*optsize < sizeof(int)) {
3081 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3084 SCTP_INP_RLOCK(inp);
3085 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3086 SCTP_INP_RUNLOCK(inp);
3089 /* return the option value */
3090 *(int *)optval = onoff;
3091 *optsize = sizeof(int);
3095 case SCTP_RECVNXTINFO:
3099 if (*optsize < sizeof(int)) {
3100 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3103 SCTP_INP_RLOCK(inp);
3104 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3105 SCTP_INP_RUNLOCK(inp);
3108 /* return the option value */
3109 *(int *)optval = onoff;
3110 *optsize = sizeof(int);
3114 case SCTP_DEFAULT_SNDINFO:
3116 struct sctp_sndinfo *info;
3118 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3119 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3122 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3123 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3124 info->snd_flags &= 0xfff0;
3125 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3126 info->snd_context = stcb->asoc.def_send.sinfo_context;
3127 SCTP_TCB_UNLOCK(stcb);
3129 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3130 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3131 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3132 SCTP_INP_RLOCK(inp);
3133 info->snd_sid = inp->def_send.sinfo_stream;
3134 info->snd_flags = inp->def_send.sinfo_flags;
3135 info->snd_flags &= 0xfff0;
3136 info->snd_ppid = inp->def_send.sinfo_ppid;
3137 info->snd_context = inp->def_send.sinfo_context;
3138 SCTP_INP_RUNLOCK(inp);
3140 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3145 *optsize = sizeof(struct sctp_sndinfo);
3149 case SCTP_DEFAULT_PRINFO:
3151 struct sctp_default_prinfo *info;
3153 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3154 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3157 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3158 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3159 SCTP_TCB_UNLOCK(stcb);
3161 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3162 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3163 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3164 SCTP_INP_RLOCK(inp);
3165 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3166 info->pr_value = inp->def_send.sinfo_timetolive;
3167 SCTP_INP_RUNLOCK(inp);
3169 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3174 *optsize = sizeof(struct sctp_default_prinfo);
3178 case SCTP_PEER_ADDR_THLDS:
3180 struct sctp_paddrthlds *thlds;
3181 struct sctp_nets *net;
3182 struct sockaddr *addr;
3183 #if defined(INET) && defined(INET6)
3184 struct sockaddr_in sin_store;
3187 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3188 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3190 #if defined(INET) && defined(INET6)
3191 if (thlds->spt_address.ss_family == AF_INET6) {
3192 struct sockaddr_in6 *sin6;
3194 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3195 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3196 in6_sin6_2_sin(&sin_store, sin6);
3197 addr = (struct sockaddr *)&sin_store;
3199 addr = (struct sockaddr *)&thlds->spt_address;
3202 addr = (struct sockaddr *)&thlds->spt_address;
3205 addr = (struct sockaddr *)&thlds->spt_address;
3208 net = sctp_findnet(stcb, addr);
3211 * We increment here since
3212 * sctp_findassociation_ep_addr() wil do a
3213 * decrement if it finds the stcb as long as
3214 * the locked tcb (last argument) is NOT a
3218 SCTP_INP_INCR_REF(inp);
3219 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3221 SCTP_INP_DECR_REF(inp);
3224 if ((stcb != NULL) && (net == NULL)) {
3226 if (addr->sa_family == AF_INET) {
3227 struct sockaddr_in *sin;
3229 sin = (struct sockaddr_in *)addr;
3230 if (sin->sin_addr.s_addr != INADDR_ANY) {
3232 SCTP_TCB_UNLOCK(stcb);
3233 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3239 if (addr->sa_family == AF_INET6) {
3240 struct sockaddr_in6 *sin6;
3242 sin6 = (struct sockaddr_in6 *)addr;
3243 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3245 SCTP_TCB_UNLOCK(stcb);
3246 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3252 error = EAFNOSUPPORT;
3253 SCTP_TCB_UNLOCK(stcb);
3254 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3260 thlds->spt_pathmaxrxt = net->failure_threshold;
3261 thlds->spt_pathpfthld = net->pf_threshold;
3262 thlds->spt_pathcpthld = 0xffff;
3264 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3265 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3266 thlds->spt_pathcpthld = 0xffff;
3268 thlds->spt_assoc_id = sctp_get_associd(stcb);
3269 SCTP_TCB_UNLOCK(stcb);
3271 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3272 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3273 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3274 /* Use endpoint defaults */
3275 SCTP_INP_RLOCK(inp);
3276 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3277 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3278 thlds->spt_pathcpthld = 0xffff;
3279 SCTP_INP_RUNLOCK(inp);
3281 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3286 *optsize = sizeof(struct sctp_paddrthlds);
3290 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3292 struct sctp_udpencaps *encaps;
3293 struct sctp_nets *net;
3294 struct sockaddr *addr;
3295 #if defined(INET) && defined(INET6)
3296 struct sockaddr_in sin_store;
3299 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3300 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3302 #if defined(INET) && defined(INET6)
3303 if (encaps->sue_address.ss_family == AF_INET6) {
3304 struct sockaddr_in6 *sin6;
3306 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3307 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3308 in6_sin6_2_sin(&sin_store, sin6);
3309 addr = (struct sockaddr *)&sin_store;
3311 addr = (struct sockaddr *)&encaps->sue_address;
3314 addr = (struct sockaddr *)&encaps->sue_address;
3317 addr = (struct sockaddr *)&encaps->sue_address;
3320 net = sctp_findnet(stcb, addr);
3323 * We increment here since
3324 * sctp_findassociation_ep_addr() wil do a
3325 * decrement if it finds the stcb as long as
3326 * the locked tcb (last argument) is NOT a
3330 SCTP_INP_INCR_REF(inp);
3331 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3333 SCTP_INP_DECR_REF(inp);
3336 if ((stcb != NULL) && (net == NULL)) {
3338 if (addr->sa_family == AF_INET) {
3339 struct sockaddr_in *sin;
3341 sin = (struct sockaddr_in *)addr;
3342 if (sin->sin_addr.s_addr != INADDR_ANY) {
3344 SCTP_TCB_UNLOCK(stcb);
3345 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3351 if (addr->sa_family == AF_INET6) {
3352 struct sockaddr_in6 *sin6;
3354 sin6 = (struct sockaddr_in6 *)addr;
3355 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3357 SCTP_TCB_UNLOCK(stcb);
3358 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3364 error = EAFNOSUPPORT;
3365 SCTP_TCB_UNLOCK(stcb);
3366 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3372 encaps->sue_port = net->port;
3374 encaps->sue_port = stcb->asoc.port;
3376 SCTP_TCB_UNLOCK(stcb);
3378 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3379 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3380 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3381 SCTP_INP_RLOCK(inp);
3382 encaps->sue_port = inp->sctp_ep.port;
3383 SCTP_INP_RUNLOCK(inp);
3385 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3390 *optsize = sizeof(struct sctp_udpencaps);
3394 case SCTP_ECN_SUPPORTED:
3396 struct sctp_assoc_value *av;
3398 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3399 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3402 av->assoc_value = stcb->asoc.ecn_supported;
3403 SCTP_TCB_UNLOCK(stcb);
3405 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3406 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3407 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3408 SCTP_INP_RLOCK(inp);
3409 av->assoc_value = inp->ecn_supported;
3410 SCTP_INP_RUNLOCK(inp);
3412 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3417 *optsize = sizeof(struct sctp_assoc_value);
3421 case SCTP_PR_SUPPORTED:
3423 struct sctp_assoc_value *av;
3425 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3426 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3429 av->assoc_value = stcb->asoc.prsctp_supported;
3430 SCTP_TCB_UNLOCK(stcb);
3432 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3433 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3434 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3435 SCTP_INP_RLOCK(inp);
3436 av->assoc_value = inp->prsctp_supported;
3437 SCTP_INP_RUNLOCK(inp);
3439 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3444 *optsize = sizeof(struct sctp_assoc_value);
3448 case SCTP_AUTH_SUPPORTED:
3450 struct sctp_assoc_value *av;
3452 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3453 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3456 av->assoc_value = stcb->asoc.auth_supported;
3457 SCTP_TCB_UNLOCK(stcb);
3459 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3460 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3461 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3462 SCTP_INP_RLOCK(inp);
3463 av->assoc_value = inp->auth_supported;
3464 SCTP_INP_RUNLOCK(inp);
3466 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3471 *optsize = sizeof(struct sctp_assoc_value);
3475 case SCTP_ASCONF_SUPPORTED:
3477 struct sctp_assoc_value *av;
3479 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3480 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3483 av->assoc_value = stcb->asoc.asconf_supported;
3484 SCTP_TCB_UNLOCK(stcb);
3486 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3487 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3488 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3489 SCTP_INP_RLOCK(inp);
3490 av->assoc_value = inp->asconf_supported;
3491 SCTP_INP_RUNLOCK(inp);
3493 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3498 *optsize = sizeof(struct sctp_assoc_value);
3502 case SCTP_RECONFIG_SUPPORTED:
3504 struct sctp_assoc_value *av;
3506 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3507 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3510 av->assoc_value = stcb->asoc.reconfig_supported;
3511 SCTP_TCB_UNLOCK(stcb);
3513 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3514 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3515 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3516 SCTP_INP_RLOCK(inp);
3517 av->assoc_value = inp->reconfig_supported;
3518 SCTP_INP_RUNLOCK(inp);
3520 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3525 *optsize = sizeof(struct sctp_assoc_value);
3529 case SCTP_NRSACK_SUPPORTED:
3531 struct sctp_assoc_value *av;
3533 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3534 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3537 av->assoc_value = stcb->asoc.nrsack_supported;
3538 SCTP_TCB_UNLOCK(stcb);
3540 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3541 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3542 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3543 SCTP_INP_RLOCK(inp);
3544 av->assoc_value = inp->nrsack_supported;
3545 SCTP_INP_RUNLOCK(inp);
3547 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3552 *optsize = sizeof(struct sctp_assoc_value);
3556 case SCTP_PKTDROP_SUPPORTED:
3558 struct sctp_assoc_value *av;
3560 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3561 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3564 av->assoc_value = stcb->asoc.pktdrop_supported;
3565 SCTP_TCB_UNLOCK(stcb);
3567 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3568 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3569 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3570 SCTP_INP_RLOCK(inp);
3571 av->assoc_value = inp->pktdrop_supported;
3572 SCTP_INP_RUNLOCK(inp);
3574 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3579 *optsize = sizeof(struct sctp_assoc_value);
3583 case SCTP_ENABLE_STREAM_RESET:
3585 struct sctp_assoc_value *av;
3587 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3588 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3591 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3592 SCTP_TCB_UNLOCK(stcb);
3594 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3595 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3596 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3597 SCTP_INP_RLOCK(inp);
3598 av->assoc_value = (uint32_t) inp->local_strreset_support;
3599 SCTP_INP_RUNLOCK(inp);
3601 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3606 *optsize = sizeof(struct sctp_assoc_value);
3610 case SCTP_PR_STREAM_STATUS:
3612 struct sctp_prstatus *sprstat;
3616 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3617 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3619 sid = sprstat->sprstat_sid;
3620 policy = sprstat->sprstat_policy;
3621 #if defined(SCTP_DETAILED_STR_STATS)
3622 if ((stcb != NULL) &&
3623 (sid < stcb->asoc.streamoutcnt) &&
3624 (policy != SCTP_PR_SCTP_NONE) &&
3625 ((policy <= SCTP_PR_SCTP_MAX) ||
3626 (policy == SCTP_PR_SCTP_ALL))) {
3627 if (policy == SCTP_PR_SCTP_ALL) {
3628 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3629 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3631 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3632 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3635 if ((stcb != NULL) &&
3636 (sid < stcb->asoc.streamoutcnt) &&
3637 (policy == SCTP_PR_SCTP_ALL)) {
3638 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3639 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3641 SCTP_TCB_UNLOCK(stcb);
3642 *optsize = sizeof(struct sctp_prstatus);
3644 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3649 case SCTP_PR_ASSOC_STATUS:
3651 struct sctp_prstatus *sprstat;
3654 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3655 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3657 policy = sprstat->sprstat_policy;
3658 if ((stcb != NULL) &&
3659 (policy != SCTP_PR_SCTP_NONE) &&
3660 ((policy <= SCTP_PR_SCTP_MAX) ||
3661 (policy == SCTP_PR_SCTP_ALL))) {
3662 if (policy == SCTP_PR_SCTP_ALL) {
3663 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3664 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3666 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3667 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3669 SCTP_TCB_UNLOCK(stcb);
3670 *optsize = sizeof(struct sctp_prstatus);
3672 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3679 struct sctp_assoc_value *av;
3681 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3682 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3685 av->assoc_value = stcb->asoc.max_cwnd;
3686 SCTP_TCB_UNLOCK(stcb);
3688 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3689 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3690 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3691 SCTP_INP_RLOCK(inp);
3692 av->assoc_value = inp->max_cwnd;
3693 SCTP_INP_RUNLOCK(inp);
3695 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3700 *optsize = sizeof(struct sctp_assoc_value);
3705 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3706 error = ENOPROTOOPT;
3708 } /* end switch (sopt->sopt_name) */
3716 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3721 struct sctp_tcb *stcb = NULL;
3722 struct sctp_inpcb *inp = NULL;
3725 if (optval == NULL) {
3726 SCTP_PRINTF("optval is NULL\n");
3727 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3730 inp = (struct sctp_inpcb *)so->so_pcb;
3732 SCTP_PRINTF("inp is NULL?\n");
3733 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3736 vrf_id = inp->def_vrf_id;
3741 case SCTP_AUTOCLOSE:
3742 case SCTP_AUTO_ASCONF:
3743 case SCTP_EXPLICIT_EOR:
3744 case SCTP_DISABLE_FRAGMENTS:
3745 case SCTP_USE_EXT_RCVINFO:
3746 case SCTP_I_WANT_MAPPED_V4_ADDR:
3747 /* copy in the option value */
3748 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3753 case SCTP_DISABLE_FRAGMENTS:
3754 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3756 case SCTP_AUTO_ASCONF:
3758 * NOTE: we don't really support this flag
3760 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3761 /* only valid for bound all sockets */
3762 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3764 /* forbidden by admin */
3765 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3768 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3770 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3774 case SCTP_EXPLICIT_EOR:
3775 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3777 case SCTP_USE_EXT_RCVINFO:
3778 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3780 case SCTP_I_WANT_MAPPED_V4_ADDR:
3781 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3782 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3784 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3789 set_opt = SCTP_PCB_FLAGS_NODELAY;
3791 case SCTP_AUTOCLOSE:
3792 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3793 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3794 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3797 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3799 * The value is in ticks. Note this does not effect
3800 * old associations, only new ones.
3802 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3805 SCTP_INP_WLOCK(inp);
3807 sctp_feature_on(inp, set_opt);
3809 sctp_feature_off(inp, set_opt);
3811 SCTP_INP_WUNLOCK(inp);
3813 case SCTP_REUSE_PORT:
3815 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3816 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3817 /* Can't set it after we are bound */
3821 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3822 /* Can't do this for a 1-m socket */
3827 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3829 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3832 case SCTP_PARTIAL_DELIVERY_POINT:
3836 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3837 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3838 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3842 inp->partial_delivery_point = *value;
3845 case SCTP_FRAGMENT_INTERLEAVE:
3846 /* not yet until we re-write sctp_recvmsg() */
3850 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3851 if (*level == SCTP_FRAG_LEVEL_2) {
3852 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3853 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3854 } else if (*level == SCTP_FRAG_LEVEL_1) {
3855 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3856 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3857 } else if (*level == SCTP_FRAG_LEVEL_0) {
3858 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3859 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3862 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3867 case SCTP_INTERLEAVING_SUPPORTED:
3869 struct sctp_assoc_value *av;
3871 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3872 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3875 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3877 SCTP_TCB_UNLOCK(stcb);
3879 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3880 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3881 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3882 SCTP_INP_WLOCK(inp);
3883 if (av->assoc_value == 0) {
3884 inp->idata_supported = 0;
3886 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3887 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3888 inp->idata_supported = 1;
3894 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3898 SCTP_INP_WUNLOCK(inp);
3900 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3906 case SCTP_CMT_ON_OFF:
3907 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3908 struct sctp_assoc_value *av;
3910 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3911 if (av->assoc_value > SCTP_CMT_MAX) {
3912 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3916 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3918 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3919 SCTP_TCB_UNLOCK(stcb);
3921 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3922 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3923 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3924 (av->assoc_id == SCTP_ALL_ASSOC)) {
3925 SCTP_INP_WLOCK(inp);
3926 inp->sctp_cmt_on_off = av->assoc_value;
3927 SCTP_INP_WUNLOCK(inp);
3929 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3930 (av->assoc_id == SCTP_ALL_ASSOC)) {
3931 SCTP_INP_RLOCK(inp);
3932 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3933 SCTP_TCB_LOCK(stcb);
3934 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3935 SCTP_TCB_UNLOCK(stcb);
3937 SCTP_INP_RUNLOCK(inp);
3941 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3942 error = ENOPROTOOPT;
3945 case SCTP_PLUGGABLE_CC:
3947 struct sctp_assoc_value *av;
3948 struct sctp_nets *net;
3950 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3951 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3952 (av->assoc_value != SCTP_CC_HSTCP) &&
3953 (av->assoc_value != SCTP_CC_HTCP) &&
3954 (av->assoc_value != SCTP_CC_RTCC)) {
3955 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3959 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3961 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3962 stcb->asoc.congestion_control_module = av->assoc_value;
3963 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3964 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3965 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3968 SCTP_TCB_UNLOCK(stcb);
3970 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3971 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3972 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3973 (av->assoc_id == SCTP_ALL_ASSOC)) {
3974 SCTP_INP_WLOCK(inp);
3975 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3976 SCTP_INP_WUNLOCK(inp);
3978 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3979 (av->assoc_id == SCTP_ALL_ASSOC)) {
3980 SCTP_INP_RLOCK(inp);
3981 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3982 SCTP_TCB_LOCK(stcb);
3983 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3984 stcb->asoc.congestion_control_module = av->assoc_value;
3985 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3986 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3987 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3990 SCTP_TCB_UNLOCK(stcb);
3992 SCTP_INP_RUNLOCK(inp);
3997 case SCTP_CC_OPTION:
3999 struct sctp_cc_option *cc_opt;
4001 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4002 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4004 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
4005 SCTP_INP_RLOCK(inp);
4006 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4007 SCTP_TCB_LOCK(stcb);
4008 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4009 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4011 SCTP_TCB_UNLOCK(stcb);
4013 SCTP_INP_RUNLOCK(inp);
4018 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4021 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4024 SCTP_TCB_UNLOCK(stcb);
4028 case SCTP_PLUGGABLE_SS:
4030 struct sctp_assoc_value *av;
4032 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4033 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4034 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4035 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4036 (av->assoc_value != SCTP_SS_PRIORITY) &&
4037 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4038 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4039 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4043 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4045 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4046 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4047 stcb->asoc.stream_scheduling_module = av->assoc_value;
4048 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4049 SCTP_TCB_UNLOCK(stcb);
4051 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4052 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4053 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4054 (av->assoc_id == SCTP_ALL_ASSOC)) {
4055 SCTP_INP_WLOCK(inp);
4056 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4057 SCTP_INP_WUNLOCK(inp);
4059 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4060 (av->assoc_id == SCTP_ALL_ASSOC)) {
4061 SCTP_INP_RLOCK(inp);
4062 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4063 SCTP_TCB_LOCK(stcb);
4064 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4065 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4066 stcb->asoc.stream_scheduling_module = av->assoc_value;
4067 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4068 SCTP_TCB_UNLOCK(stcb);
4070 SCTP_INP_RUNLOCK(inp);
4077 struct sctp_stream_value *av;
4079 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4080 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4082 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4083 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4084 av->stream_value) < 0)) {
4085 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4088 SCTP_TCB_UNLOCK(stcb);
4090 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4091 SCTP_INP_RLOCK(inp);
4092 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4093 SCTP_TCB_LOCK(stcb);
4094 if (av->stream_id < stcb->asoc.streamoutcnt) {
4095 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4097 &stcb->asoc.strmout[av->stream_id],
4100 SCTP_TCB_UNLOCK(stcb);
4102 SCTP_INP_RUNLOCK(inp);
4104 /* Can't set stream value without
4106 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4112 case SCTP_CLR_STAT_LOG:
4113 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4118 struct sctp_assoc_value *av;
4120 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4121 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4124 stcb->asoc.context = av->assoc_value;
4125 SCTP_TCB_UNLOCK(stcb);
4127 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4128 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4129 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4130 (av->assoc_id == SCTP_ALL_ASSOC)) {
4131 SCTP_INP_WLOCK(inp);
4132 inp->sctp_context = av->assoc_value;
4133 SCTP_INP_WUNLOCK(inp);
4135 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4136 (av->assoc_id == SCTP_ALL_ASSOC)) {
4137 SCTP_INP_RLOCK(inp);
4138 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4139 SCTP_TCB_LOCK(stcb);
4140 stcb->asoc.context = av->assoc_value;
4141 SCTP_TCB_UNLOCK(stcb);
4143 SCTP_INP_RUNLOCK(inp);
4150 uint32_t *default_vrfid;
4152 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4153 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4154 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4158 inp->def_vrf_id = *default_vrfid;
4161 case SCTP_DEL_VRF_ID:
4163 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4167 case SCTP_ADD_VRF_ID:
4169 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4173 case SCTP_DELAYED_SACK:
4175 struct sctp_sack_info *sack;
4177 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4178 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4179 if (sack->sack_delay) {
4180 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4181 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4182 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4183 sack->sack_delay = TICKS_TO_MSEC(1);
4187 if (sack->sack_delay) {
4188 stcb->asoc.delayed_ack = sack->sack_delay;
4190 if (sack->sack_freq) {
4191 stcb->asoc.sack_freq = sack->sack_freq;
4193 SCTP_TCB_UNLOCK(stcb);
4195 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4196 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4197 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4198 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4199 SCTP_INP_WLOCK(inp);
4200 if (sack->sack_delay) {
4201 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4203 if (sack->sack_freq) {
4204 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4206 SCTP_INP_WUNLOCK(inp);
4208 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4209 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4210 SCTP_INP_RLOCK(inp);
4211 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4212 SCTP_TCB_LOCK(stcb);
4213 if (sack->sack_delay) {
4214 stcb->asoc.delayed_ack = sack->sack_delay;
4216 if (sack->sack_freq) {
4217 stcb->asoc.sack_freq = sack->sack_freq;
4219 SCTP_TCB_UNLOCK(stcb);
4221 SCTP_INP_RUNLOCK(inp);
4226 case SCTP_AUTH_CHUNK:
4228 struct sctp_authchunk *sauth;
4230 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4232 SCTP_INP_WLOCK(inp);
4233 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4234 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4237 SCTP_INP_WUNLOCK(inp);
4242 struct sctp_authkey *sca;
4243 struct sctp_keyhead *shared_keys;
4244 sctp_sharedkey_t *shared_key;
4245 sctp_key_t *key = NULL;
4248 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4249 if (sca->sca_keylength == 0) {
4250 size = optsize - sizeof(struct sctp_authkey);
4252 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4253 size = sca->sca_keylength;
4255 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4260 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4263 shared_keys = &stcb->asoc.shared_keys;
4264 /* clear the cached keys for this key id */
4265 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4267 * create the new shared key and
4271 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4273 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4275 SCTP_TCB_UNLOCK(stcb);
4279 shared_key = sctp_alloc_sharedkey();
4280 if (shared_key == NULL) {
4282 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4284 SCTP_TCB_UNLOCK(stcb);
4287 shared_key->key = key;
4288 shared_key->keyid = sca->sca_keynumber;
4289 error = sctp_insert_sharedkey(shared_keys, shared_key);
4290 SCTP_TCB_UNLOCK(stcb);
4292 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4293 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4294 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4295 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4296 SCTP_INP_WLOCK(inp);
4297 shared_keys = &inp->sctp_ep.shared_keys;
4299 * clear the cached keys on all
4300 * assocs for this key id
4302 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4304 * create the new shared key and
4308 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4310 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4312 SCTP_INP_WUNLOCK(inp);
4316 shared_key = sctp_alloc_sharedkey();
4317 if (shared_key == NULL) {
4319 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4321 SCTP_INP_WUNLOCK(inp);
4324 shared_key->key = key;
4325 shared_key->keyid = sca->sca_keynumber;
4326 error = sctp_insert_sharedkey(shared_keys, shared_key);
4327 SCTP_INP_WUNLOCK(inp);
4329 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4330 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4331 SCTP_INP_RLOCK(inp);
4332 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4333 SCTP_TCB_LOCK(stcb);
4334 shared_keys = &stcb->asoc.shared_keys;
4335 /* clear the cached keys for
4337 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4339 * create the new shared key
4340 * and insert/replace it
4343 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4345 SCTP_TCB_UNLOCK(stcb);
4349 shared_key = sctp_alloc_sharedkey();
4350 if (shared_key == NULL) {
4352 SCTP_TCB_UNLOCK(stcb);
4355 shared_key->key = key;
4356 shared_key->keyid = sca->sca_keynumber;
4357 error = sctp_insert_sharedkey(shared_keys, shared_key);
4358 SCTP_TCB_UNLOCK(stcb);
4360 SCTP_INP_RUNLOCK(inp);
4365 case SCTP_HMAC_IDENT:
4367 struct sctp_hmacalgo *shmac;
4368 sctp_hmaclist_t *hmaclist;
4372 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4373 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4374 (shmac->shmac_number_of_idents > 0xffff)) {
4375 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4379 hmaclist = sctp_alloc_hmaclist((uint16_t) shmac->shmac_number_of_idents);
4380 if (hmaclist == NULL) {
4381 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4385 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4386 hmacid = shmac->shmac_idents[i];
4387 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4388 /* invalid HMACs were found */ ;
4389 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4391 sctp_free_hmaclist(hmaclist);
4392 goto sctp_set_hmac_done;
4395 for (i = 0; i < hmaclist->num_algo; i++) {
4396 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4397 /* already in list */
4401 if (i == hmaclist->num_algo) {
4402 /* not found in list */
4403 sctp_free_hmaclist(hmaclist);
4404 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4408 /* set it on the endpoint */
4409 SCTP_INP_WLOCK(inp);
4410 if (inp->sctp_ep.local_hmacs)
4411 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4412 inp->sctp_ep.local_hmacs = hmaclist;
4413 SCTP_INP_WUNLOCK(inp);
4417 case SCTP_AUTH_ACTIVE_KEY:
4419 struct sctp_authkeyid *scact;
4421 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4422 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4424 /* set the active key on the right place */
4426 /* set the active key on the assoc */
4427 if (sctp_auth_setactivekey(stcb,
4428 scact->scact_keynumber)) {
4429 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4430 SCTP_FROM_SCTP_USRREQ,
4434 SCTP_TCB_UNLOCK(stcb);
4436 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4437 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4438 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4439 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4440 SCTP_INP_WLOCK(inp);
4441 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4442 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4445 SCTP_INP_WUNLOCK(inp);
4447 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4448 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4449 SCTP_INP_RLOCK(inp);
4450 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4451 SCTP_TCB_LOCK(stcb);
4452 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4453 SCTP_TCB_UNLOCK(stcb);
4455 SCTP_INP_RUNLOCK(inp);
4460 case SCTP_AUTH_DELETE_KEY:
4462 struct sctp_authkeyid *scdel;
4464 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4465 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4467 /* delete the key from the right place */
4469 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4470 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4473 SCTP_TCB_UNLOCK(stcb);
4475 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4476 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4477 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4478 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4479 SCTP_INP_WLOCK(inp);
4480 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4481 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4484 SCTP_INP_WUNLOCK(inp);
4486 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4487 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4488 SCTP_INP_RLOCK(inp);
4489 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4490 SCTP_TCB_LOCK(stcb);
4491 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4492 SCTP_TCB_UNLOCK(stcb);
4494 SCTP_INP_RUNLOCK(inp);
4499 case SCTP_AUTH_DEACTIVATE_KEY:
4501 struct sctp_authkeyid *keyid;
4503 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4504 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4506 /* deactivate the key from the right place */
4508 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4509 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4512 SCTP_TCB_UNLOCK(stcb);
4514 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4515 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4516 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4517 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4518 SCTP_INP_WLOCK(inp);
4519 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4520 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4523 SCTP_INP_WUNLOCK(inp);
4525 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4526 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4527 SCTP_INP_RLOCK(inp);
4528 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4529 SCTP_TCB_LOCK(stcb);
4530 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4531 SCTP_TCB_UNLOCK(stcb);
4533 SCTP_INP_RUNLOCK(inp);
4538 case SCTP_ENABLE_STREAM_RESET:
4540 struct sctp_assoc_value *av;
4542 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4543 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4544 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4548 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4550 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4551 SCTP_TCB_UNLOCK(stcb);
4553 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4554 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4555 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4556 (av->assoc_id == SCTP_ALL_ASSOC)) {
4557 SCTP_INP_WLOCK(inp);
4558 inp->local_strreset_support = (uint8_t) av->assoc_value;
4559 SCTP_INP_WUNLOCK(inp);
4561 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4562 (av->assoc_id == SCTP_ALL_ASSOC)) {
4563 SCTP_INP_RLOCK(inp);
4564 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4565 SCTP_TCB_LOCK(stcb);
4566 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4567 SCTP_TCB_UNLOCK(stcb);
4569 SCTP_INP_RUNLOCK(inp);
4574 case SCTP_RESET_STREAMS:
4576 struct sctp_reset_streams *strrst;
4577 int i, send_out = 0;
4580 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4581 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4583 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4587 if (stcb->asoc.reconfig_supported == 0) {
4589 * Peer does not support the chunk type.
4591 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4593 SCTP_TCB_UNLOCK(stcb);
4596 if (sizeof(struct sctp_reset_streams) +
4597 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4599 SCTP_TCB_UNLOCK(stcb);
4602 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4604 if (stcb->asoc.stream_reset_outstanding) {
4605 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4607 SCTP_TCB_UNLOCK(stcb);
4611 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4614 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4615 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4617 SCTP_TCB_UNLOCK(stcb);
4620 if ((send_in == 0) && (send_out == 0)) {
4621 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4623 SCTP_TCB_UNLOCK(stcb);
4626 for (i = 0; i < strrst->srs_number_streams; i++) {
4628 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4629 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4634 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4635 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4641 SCTP_TCB_UNLOCK(stcb);
4648 if (strrst->srs_number_streams) {
4649 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4650 strm = strrst->srs_stream_list[i];
4651 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4652 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4658 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4659 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4660 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4667 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4668 strrst->srs_stream_list,
4669 send_in, 0, 0, 0, 0, 0);
4671 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4674 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4677 * For outgoing streams don't report any
4678 * problems in sending the request to the
4679 * application. XXX: Double check resetting
4684 SCTP_TCB_UNLOCK(stcb);
4687 case SCTP_ADD_STREAMS:
4689 struct sctp_add_streams *stradd;
4690 uint8_t addstream = 0;
4691 uint16_t add_o_strmcnt = 0;
4692 uint16_t add_i_strmcnt = 0;
4694 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4695 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4697 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4701 if (stcb->asoc.reconfig_supported == 0) {
4703 * Peer does not support the chunk type.
4705 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4707 SCTP_TCB_UNLOCK(stcb);
4710 if (stcb->asoc.stream_reset_outstanding) {
4711 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4713 SCTP_TCB_UNLOCK(stcb);
4716 if ((stradd->sas_outstrms == 0) &&
4717 (stradd->sas_instrms == 0)) {
4721 if (stradd->sas_outstrms) {
4723 /* We allocate here */
4724 add_o_strmcnt = stradd->sas_outstrms;
4725 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4726 /* You can't have more than 64k */
4731 if (stradd->sas_instrms) {
4735 /* We allocate inside
4736 * sctp_send_str_reset_req() */
4737 add_i_strmcnt = stradd->sas_instrms;
4738 cnt = add_i_strmcnt;
4739 cnt += stcb->asoc.streamincnt;
4740 if (cnt > 0x0000ffff) {
4741 /* You can't have more than 64k */
4745 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4746 /* More than you are allowed */
4751 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4752 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4754 SCTP_TCB_UNLOCK(stcb);
4757 case SCTP_RESET_ASSOC:
4762 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4763 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4765 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4769 if (stcb->asoc.reconfig_supported == 0) {
4771 * Peer does not support the chunk type.
4773 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4775 SCTP_TCB_UNLOCK(stcb);
4778 if (stcb->asoc.stream_reset_outstanding) {
4779 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4781 SCTP_TCB_UNLOCK(stcb);
4784 /* Is there any data pending in the send or sent
4786 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4787 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4790 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4791 SCTP_TCB_UNLOCK(stcb);
4794 /* Do any streams have data queued? */
4795 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4796 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4800 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4801 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4802 SCTP_TCB_UNLOCK(stcb);
4805 case SCTP_CONNECT_X:
4806 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4807 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4811 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4813 case SCTP_CONNECT_X_DELAYED:
4814 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4815 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4819 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4821 case SCTP_CONNECT_X_COMPLETE:
4823 struct sockaddr *sa;
4825 /* FIXME MT: check correct? */
4826 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4829 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4830 SCTP_INP_RLOCK(inp);
4831 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4833 SCTP_TCB_LOCK(stcb);
4835 SCTP_INP_RUNLOCK(inp);
4838 * We increment here since
4839 * sctp_findassociation_ep_addr() wil do a
4840 * decrement if it finds the stcb as long as
4841 * the locked tcb (last argument) is NOT a
4844 SCTP_INP_INCR_REF(inp);
4845 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4847 SCTP_INP_DECR_REF(inp);
4852 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4856 if (stcb->asoc.delayed_connection == 1) {
4857 stcb->asoc.delayed_connection = 0;
4858 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4859 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4860 stcb->asoc.primary_destination,
4861 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4862 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4865 * already expired or did not use delayed
4868 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4871 SCTP_TCB_UNLOCK(stcb);
4874 case SCTP_MAX_BURST:
4876 struct sctp_assoc_value *av;
4878 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4879 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4882 stcb->asoc.max_burst = av->assoc_value;
4883 SCTP_TCB_UNLOCK(stcb);
4885 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4886 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4887 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4888 (av->assoc_id == SCTP_ALL_ASSOC)) {
4889 SCTP_INP_WLOCK(inp);
4890 inp->sctp_ep.max_burst = av->assoc_value;
4891 SCTP_INP_WUNLOCK(inp);
4893 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4894 (av->assoc_id == SCTP_ALL_ASSOC)) {
4895 SCTP_INP_RLOCK(inp);
4896 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4897 SCTP_TCB_LOCK(stcb);
4898 stcb->asoc.max_burst = av->assoc_value;
4899 SCTP_TCB_UNLOCK(stcb);
4901 SCTP_INP_RUNLOCK(inp);
4908 struct sctp_assoc_value *av;
4911 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4912 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4914 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4915 ovh = SCTP_MED_OVERHEAD;
4917 ovh = SCTP_MED_V4_OVERHEAD;
4920 if (av->assoc_value) {
4921 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4923 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4925 SCTP_TCB_UNLOCK(stcb);
4927 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4928 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4929 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4930 SCTP_INP_WLOCK(inp);
4931 /* FIXME MT: I think this is not in
4932 * tune with the API ID */
4933 if (av->assoc_value) {
4934 inp->sctp_frag_point = (av->assoc_value + ovh);
4936 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4938 SCTP_INP_WUNLOCK(inp);
4940 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4948 struct sctp_event_subscribe *events;
4950 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4952 SCTP_INP_WLOCK(inp);
4953 if (events->sctp_data_io_event) {
4954 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4956 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4959 if (events->sctp_association_event) {
4960 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4962 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4965 if (events->sctp_address_event) {
4966 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4968 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4971 if (events->sctp_send_failure_event) {
4972 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4974 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4977 if (events->sctp_peer_error_event) {
4978 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4980 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4983 if (events->sctp_shutdown_event) {
4984 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4986 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4989 if (events->sctp_partial_delivery_event) {
4990 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4992 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4995 if (events->sctp_adaptation_layer_event) {
4996 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4998 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5001 if (events->sctp_authentication_event) {
5002 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5004 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5007 if (events->sctp_sender_dry_event) {
5008 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5010 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5013 if (events->sctp_stream_reset_event) {
5014 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5016 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5018 SCTP_INP_WUNLOCK(inp);
5020 SCTP_INP_RLOCK(inp);
5021 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5022 SCTP_TCB_LOCK(stcb);
5023 if (events->sctp_association_event) {
5024 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5026 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5028 if (events->sctp_address_event) {
5029 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5031 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5033 if (events->sctp_send_failure_event) {
5034 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5036 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5038 if (events->sctp_peer_error_event) {
5039 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5041 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5043 if (events->sctp_shutdown_event) {
5044 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5046 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5048 if (events->sctp_partial_delivery_event) {
5049 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5051 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5053 if (events->sctp_adaptation_layer_event) {
5054 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5056 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5058 if (events->sctp_authentication_event) {
5059 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5061 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5063 if (events->sctp_sender_dry_event) {
5064 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5066 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5068 if (events->sctp_stream_reset_event) {
5069 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5071 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5073 SCTP_TCB_UNLOCK(stcb);
5075 /* Send up the sender dry event only for 1-to-1
5077 if (events->sctp_sender_dry_event) {
5078 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5079 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5080 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5082 SCTP_TCB_LOCK(stcb);
5083 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5084 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5085 (stcb->asoc.stream_queue_cnt == 0)) {
5086 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5088 SCTP_TCB_UNLOCK(stcb);
5092 SCTP_INP_RUNLOCK(inp);
5095 case SCTP_ADAPTATION_LAYER:
5097 struct sctp_setadaptation *adap_bits;
5099 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5100 SCTP_INP_WLOCK(inp);
5101 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5102 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5103 SCTP_INP_WUNLOCK(inp);
5107 case SCTP_SET_INITIAL_DBG_SEQ:
5111 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5112 SCTP_INP_WLOCK(inp);
5113 inp->sctp_ep.initial_sequence_debug = *vvv;
5114 SCTP_INP_WUNLOCK(inp);
5118 case SCTP_DEFAULT_SEND_PARAM:
5120 struct sctp_sndrcvinfo *s_info;
5122 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5123 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5126 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5127 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5129 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5132 SCTP_TCB_UNLOCK(stcb);
5134 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5135 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5136 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5137 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5138 SCTP_INP_WLOCK(inp);
5139 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5140 SCTP_INP_WUNLOCK(inp);
5142 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5143 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5144 SCTP_INP_RLOCK(inp);
5145 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5146 SCTP_TCB_LOCK(stcb);
5147 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5148 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5150 SCTP_TCB_UNLOCK(stcb);
5152 SCTP_INP_RUNLOCK(inp);
5157 case SCTP_PEER_ADDR_PARAMS:
5159 struct sctp_paddrparams *paddrp;
5160 struct sctp_nets *net;
5161 struct sockaddr *addr;
5162 #if defined(INET) && defined(INET6)
5163 struct sockaddr_in sin_store;
5166 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5167 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5169 #if defined(INET) && defined(INET6)
5170 if (paddrp->spp_address.ss_family == AF_INET6) {
5171 struct sockaddr_in6 *sin6;
5173 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5174 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5175 in6_sin6_2_sin(&sin_store, sin6);
5176 addr = (struct sockaddr *)&sin_store;
5178 addr = (struct sockaddr *)&paddrp->spp_address;
5181 addr = (struct sockaddr *)&paddrp->spp_address;
5184 addr = (struct sockaddr *)&paddrp->spp_address;
5187 net = sctp_findnet(stcb, addr);
5190 * We increment here since
5191 * sctp_findassociation_ep_addr() wil do a
5192 * decrement if it finds the stcb as long as
5193 * the locked tcb (last argument) is NOT a
5197 SCTP_INP_INCR_REF(inp);
5198 stcb = sctp_findassociation_ep_addr(&inp, addr,
5201 SCTP_INP_DECR_REF(inp);
5204 if ((stcb != NULL) && (net == NULL)) {
5206 if (addr->sa_family == AF_INET) {
5208 struct sockaddr_in *sin;
5210 sin = (struct sockaddr_in *)addr;
5211 if (sin->sin_addr.s_addr != INADDR_ANY) {
5212 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5213 SCTP_TCB_UNLOCK(stcb);
5220 if (addr->sa_family == AF_INET6) {
5221 struct sockaddr_in6 *sin6;
5223 sin6 = (struct sockaddr_in6 *)addr;
5224 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5225 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5226 SCTP_TCB_UNLOCK(stcb);
5233 error = EAFNOSUPPORT;
5234 SCTP_TCB_UNLOCK(stcb);
5235 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5240 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5242 SCTP_TCB_UNLOCK(stcb);
5243 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5246 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5248 SCTP_TCB_UNLOCK(stcb);
5249 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5253 /************************TCB SPECIFIC SET ******************/
5255 /************************NET SPECIFIC SET ******************/
5256 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5257 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5258 !(net->dest_state & SCTP_ADDR_NOHB)) {
5259 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5260 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5262 net->dest_state |= SCTP_ADDR_NOHB;
5264 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5265 if (paddrp->spp_hbinterval) {
5266 net->heart_beat_delay = paddrp->spp_hbinterval;
5267 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5268 net->heart_beat_delay = 0;
5270 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5271 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5272 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5273 net->dest_state &= ~SCTP_ADDR_NOHB;
5275 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5277 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5278 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5279 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5281 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5282 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5283 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5284 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5286 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5287 net->mtu = paddrp->spp_pathmtu;
5288 switch (net->ro._l_addr.sa.sa_family) {
5291 net->mtu += SCTP_MIN_V4_OVERHEAD;
5296 net->mtu += SCTP_MIN_OVERHEAD;
5302 if (net->mtu < stcb->asoc.smallest_mtu) {
5303 sctp_pathmtu_adjustment(stcb, net->mtu);
5306 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5307 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5308 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5310 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5312 if (paddrp->spp_pathmaxrxt) {
5313 if (net->dest_state & SCTP_ADDR_PF) {
5314 if (net->error_count > paddrp->spp_pathmaxrxt) {
5315 net->dest_state &= ~SCTP_ADDR_PF;
5318 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5319 (net->error_count > net->pf_threshold)) {
5320 net->dest_state |= SCTP_ADDR_PF;
5321 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5322 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5323 stcb->sctp_ep, stcb, net,
5324 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5325 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5328 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5329 if (net->error_count > paddrp->spp_pathmaxrxt) {
5330 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5331 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5334 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5335 net->dest_state |= SCTP_ADDR_REACHABLE;
5336 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5339 net->failure_threshold = paddrp->spp_pathmaxrxt;
5341 if (paddrp->spp_flags & SPP_DSCP) {
5342 net->dscp = paddrp->spp_dscp & 0xfc;
5346 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5347 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5348 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5349 net->flowlabel |= 0x80000000;
5354 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5355 if (paddrp->spp_pathmaxrxt != 0) {
5356 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5357 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5358 if (net->dest_state & SCTP_ADDR_PF) {
5359 if (net->error_count > paddrp->spp_pathmaxrxt) {
5360 net->dest_state &= ~SCTP_ADDR_PF;
5363 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5364 (net->error_count > net->pf_threshold)) {
5365 net->dest_state |= SCTP_ADDR_PF;
5366 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5367 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5368 stcb->sctp_ep, stcb, net,
5369 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5370 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5373 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5374 if (net->error_count > paddrp->spp_pathmaxrxt) {
5375 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5376 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5379 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5380 net->dest_state |= SCTP_ADDR_REACHABLE;
5381 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5384 net->failure_threshold = paddrp->spp_pathmaxrxt;
5387 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5388 if (paddrp->spp_hbinterval != 0) {
5389 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5390 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5391 stcb->asoc.heart_beat_delay = 0;
5393 /* Turn back on the timer */
5394 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5395 if (paddrp->spp_hbinterval != 0) {
5396 net->heart_beat_delay = paddrp->spp_hbinterval;
5397 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5398 net->heart_beat_delay = 0;
5400 if (net->dest_state & SCTP_ADDR_NOHB) {
5401 net->dest_state &= ~SCTP_ADDR_NOHB;
5403 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5404 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5405 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5407 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5409 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5410 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5411 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5412 net->dest_state |= SCTP_ADDR_NOHB;
5413 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5414 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5416 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5420 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5422 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5423 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5424 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5425 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5426 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5428 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5429 net->mtu = paddrp->spp_pathmtu;
5430 switch (net->ro._l_addr.sa.sa_family) {
5433 net->mtu += SCTP_MIN_V4_OVERHEAD;
5438 net->mtu += SCTP_MIN_OVERHEAD;
5444 if (net->mtu < stcb->asoc.smallest_mtu) {
5445 sctp_pathmtu_adjustment(stcb, net->mtu);
5448 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5450 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5451 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5452 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5453 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5455 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5457 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5459 if (paddrp->spp_flags & SPP_DSCP) {
5460 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5461 net->dscp = paddrp->spp_dscp & 0xfc;
5464 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5465 stcb->asoc.default_dscp |= 0x01;
5468 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5469 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5470 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5471 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5472 net->flowlabel |= 0x80000000;
5475 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5476 stcb->asoc.default_flowlabel |= 0x80000000;
5480 SCTP_TCB_UNLOCK(stcb);
5482 /************************NO TCB, SET TO default stuff ******************/
5483 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5484 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5485 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5486 SCTP_INP_WLOCK(inp);
5488 * For the TOS/FLOWLABEL stuff you
5489 * set it with the options on the
5492 if (paddrp->spp_pathmaxrxt != 0) {
5493 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5495 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5496 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5497 else if (paddrp->spp_hbinterval != 0) {
5498 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5499 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5500 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5502 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5503 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5504 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5505 } else if (paddrp->spp_hbinterval) {
5506 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5508 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5509 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5510 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5512 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5513 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5514 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5515 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5517 if (paddrp->spp_flags & SPP_DSCP) {
5518 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5519 inp->sctp_ep.default_dscp |= 0x01;
5522 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5523 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5524 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5525 inp->sctp_ep.default_flowlabel |= 0x80000000;
5529 SCTP_INP_WUNLOCK(inp);
5531 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5539 struct sctp_rtoinfo *srto;
5540 uint32_t new_init, new_min, new_max;
5542 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5543 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5546 if (srto->srto_initial)
5547 new_init = srto->srto_initial;
5549 new_init = stcb->asoc.initial_rto;
5551 new_max = srto->srto_max;
5553 new_max = stcb->asoc.maxrto;
5555 new_min = srto->srto_min;
5557 new_min = stcb->asoc.minrto;
5558 if ((new_min <= new_init) && (new_init <= new_max)) {
5559 stcb->asoc.initial_rto = new_init;
5560 stcb->asoc.maxrto = new_max;
5561 stcb->asoc.minrto = new_min;
5563 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5566 SCTP_TCB_UNLOCK(stcb);
5568 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5569 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5570 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5571 SCTP_INP_WLOCK(inp);
5572 if (srto->srto_initial)
5573 new_init = srto->srto_initial;
5575 new_init = inp->sctp_ep.initial_rto;
5577 new_max = srto->srto_max;
5579 new_max = inp->sctp_ep.sctp_maxrto;
5581 new_min = srto->srto_min;
5583 new_min = inp->sctp_ep.sctp_minrto;
5584 if ((new_min <= new_init) && (new_init <= new_max)) {
5585 inp->sctp_ep.initial_rto = new_init;
5586 inp->sctp_ep.sctp_maxrto = new_max;
5587 inp->sctp_ep.sctp_minrto = new_min;
5589 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5592 SCTP_INP_WUNLOCK(inp);
5594 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5600 case SCTP_ASSOCINFO:
5602 struct sctp_assocparams *sasoc;
5604 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5605 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5606 if (sasoc->sasoc_cookie_life) {
5607 /* boundary check the cookie life */
5608 if (sasoc->sasoc_cookie_life < 1000)
5609 sasoc->sasoc_cookie_life = 1000;
5610 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5611 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5615 if (sasoc->sasoc_asocmaxrxt)
5616 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5617 if (sasoc->sasoc_cookie_life) {
5618 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5620 SCTP_TCB_UNLOCK(stcb);
5622 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5623 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5624 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5625 SCTP_INP_WLOCK(inp);
5626 if (sasoc->sasoc_asocmaxrxt)
5627 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5628 if (sasoc->sasoc_cookie_life) {
5629 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5631 SCTP_INP_WUNLOCK(inp);
5633 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5641 struct sctp_initmsg *sinit;
5643 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5644 SCTP_INP_WLOCK(inp);
5645 if (sinit->sinit_num_ostreams)
5646 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5648 if (sinit->sinit_max_instreams)
5649 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5651 if (sinit->sinit_max_attempts)
5652 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5654 if (sinit->sinit_max_init_timeo)
5655 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5656 SCTP_INP_WUNLOCK(inp);
5659 case SCTP_PRIMARY_ADDR:
5661 struct sctp_setprim *spa;
5662 struct sctp_nets *net;
5663 struct sockaddr *addr;
5664 #if defined(INET) && defined(INET6)
5665 struct sockaddr_in sin_store;
5668 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5669 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5671 #if defined(INET) && defined(INET6)
5672 if (spa->ssp_addr.ss_family == AF_INET6) {
5673 struct sockaddr_in6 *sin6;
5675 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5676 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5677 in6_sin6_2_sin(&sin_store, sin6);
5678 addr = (struct sockaddr *)&sin_store;
5680 addr = (struct sockaddr *)&spa->ssp_addr;
5683 addr = (struct sockaddr *)&spa->ssp_addr;
5686 addr = (struct sockaddr *)&spa->ssp_addr;
5689 net = sctp_findnet(stcb, addr);
5692 * We increment here since
5693 * sctp_findassociation_ep_addr() wil do a
5694 * decrement if it finds the stcb as long as
5695 * the locked tcb (last argument) is NOT a
5699 SCTP_INP_INCR_REF(inp);
5700 stcb = sctp_findassociation_ep_addr(&inp, addr,
5703 SCTP_INP_DECR_REF(inp);
5707 if ((stcb != NULL) && (net != NULL)) {
5708 if (net != stcb->asoc.primary_destination) {
5709 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5710 /* Ok we need to set it */
5711 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5712 if ((stcb->asoc.alternate) &&
5713 (!(net->dest_state & SCTP_ADDR_PF)) &&
5714 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5715 sctp_free_remote_addr(stcb->asoc.alternate);
5716 stcb->asoc.alternate = NULL;
5719 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5723 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5728 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5732 SCTP_TCB_UNLOCK(stcb);
5736 case SCTP_SET_DYNAMIC_PRIMARY:
5738 union sctp_sockstore *ss;
5740 error = priv_check(curthread,
5741 PRIV_NETINET_RESERVEDPORT);
5745 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5746 /* SUPER USER CHECK? */
5747 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5750 case SCTP_SET_PEER_PRIMARY_ADDR:
5752 struct sctp_setpeerprim *sspp;
5753 struct sockaddr *addr;
5754 #if defined(INET) && defined(INET6)
5755 struct sockaddr_in sin_store;
5758 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5759 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5761 struct sctp_ifa *ifa;
5763 #if defined(INET) && defined(INET6)
5764 if (sspp->sspp_addr.ss_family == AF_INET6) {
5765 struct sockaddr_in6 *sin6;
5767 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5768 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5769 in6_sin6_2_sin(&sin_store, sin6);
5770 addr = (struct sockaddr *)&sin_store;
5772 addr = (struct sockaddr *)&sspp->sspp_addr;
5775 addr = (struct sockaddr *)&sspp->sspp_addr;
5778 addr = (struct sockaddr *)&sspp->sspp_addr;
5780 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5782 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5786 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5787 /* Must validate the ifa found is in
5789 struct sctp_laddr *laddr;
5792 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5793 if (laddr->ifa == NULL) {
5794 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5798 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5799 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5802 if (laddr->ifa == ifa) {
5808 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5813 switch (addr->sa_family) {
5817 struct sockaddr_in *sin;
5819 sin = (struct sockaddr_in *)addr;
5820 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5821 &sin->sin_addr) != 0) {
5822 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5832 struct sockaddr_in6 *sin6;
5834 sin6 = (struct sockaddr_in6 *)addr;
5835 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5836 &sin6->sin6_addr) != 0) {
5837 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5845 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5850 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5851 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5854 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5856 SCTP_TCB_UNLOCK(stcb);
5858 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5863 case SCTP_BINDX_ADD_ADDR:
5865 struct sctp_getaddresses *addrs;
5868 td = (struct thread *)p;
5869 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5872 if (addrs->addr->sa_family == AF_INET) {
5873 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5874 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5878 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5879 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5885 if (addrs->addr->sa_family == AF_INET6) {
5886 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5891 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5892 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5893 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5899 error = EAFNOSUPPORT;
5902 sctp_bindx_add_address(so, inp, addrs->addr,
5903 addrs->sget_assoc_id, vrf_id,
5907 case SCTP_BINDX_REM_ADDR:
5909 struct sctp_getaddresses *addrs;
5912 td = (struct thread *)p;
5914 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5916 if (addrs->addr->sa_family == AF_INET) {
5917 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5918 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5922 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5923 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5929 if (addrs->addr->sa_family == AF_INET6) {
5930 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5931 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5936 (error = prison_local_ip6(td->td_ucred,
5937 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5938 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5939 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5945 error = EAFNOSUPPORT;
5948 sctp_bindx_delete_address(inp, addrs->addr,
5949 addrs->sget_assoc_id, vrf_id,
5955 struct sctp_event *event;
5956 uint32_t event_type;
5958 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5959 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5960 switch (event->se_type) {
5961 case SCTP_ASSOC_CHANGE:
5962 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5964 case SCTP_PEER_ADDR_CHANGE:
5965 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5967 case SCTP_REMOTE_ERROR:
5968 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5970 case SCTP_SEND_FAILED:
5971 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5973 case SCTP_SHUTDOWN_EVENT:
5974 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5976 case SCTP_ADAPTATION_INDICATION:
5977 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5979 case SCTP_PARTIAL_DELIVERY_EVENT:
5980 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5982 case SCTP_AUTHENTICATION_EVENT:
5983 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5985 case SCTP_STREAM_RESET_EVENT:
5986 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5988 case SCTP_SENDER_DRY_EVENT:
5989 event_type = SCTP_PCB_FLAGS_DRYEVNT;
5991 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
5993 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5996 case SCTP_ASSOC_RESET_EVENT:
5997 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
5999 case SCTP_STREAM_CHANGE_EVENT:
6000 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6002 case SCTP_SEND_FAILED_EVENT:
6003 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6007 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6011 if (event_type > 0) {
6014 sctp_stcb_feature_on(inp, stcb, event_type);
6015 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6016 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6017 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6018 (stcb->asoc.stream_queue_cnt == 0)) {
6019 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6023 sctp_stcb_feature_off(inp, stcb, event_type);
6025 SCTP_TCB_UNLOCK(stcb);
6028 * We don't want to send up a storm
6029 * of events, so return an error for
6032 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6033 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6034 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6035 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6036 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6037 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6041 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6042 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6043 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6044 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6045 SCTP_INP_WLOCK(inp);
6047 sctp_feature_on(inp, event_type);
6049 sctp_feature_off(inp, event_type);
6051 SCTP_INP_WUNLOCK(inp);
6053 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6054 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6055 SCTP_INP_RLOCK(inp);
6056 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6057 SCTP_TCB_LOCK(stcb);
6059 sctp_stcb_feature_on(inp, stcb, event_type);
6061 sctp_stcb_feature_off(inp, stcb, event_type);
6063 SCTP_TCB_UNLOCK(stcb);
6065 SCTP_INP_RUNLOCK(inp);
6071 case SCTP_RECVRCVINFO:
6075 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6076 SCTP_INP_WLOCK(inp);
6078 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6080 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6082 SCTP_INP_WUNLOCK(inp);
6085 case SCTP_RECVNXTINFO:
6089 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6090 SCTP_INP_WLOCK(inp);
6092 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6094 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6096 SCTP_INP_WUNLOCK(inp);
6099 case SCTP_DEFAULT_SNDINFO:
6101 struct sctp_sndinfo *info;
6104 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6105 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6108 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6109 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6110 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6111 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6112 stcb->asoc.def_send.sinfo_flags |= policy;
6113 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6114 stcb->asoc.def_send.sinfo_context = info->snd_context;
6116 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6119 SCTP_TCB_UNLOCK(stcb);
6121 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6122 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6123 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6124 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6125 SCTP_INP_WLOCK(inp);
6126 inp->def_send.sinfo_stream = info->snd_sid;
6127 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6128 inp->def_send.sinfo_flags = info->snd_flags;
6129 inp->def_send.sinfo_flags |= policy;
6130 inp->def_send.sinfo_ppid = info->snd_ppid;
6131 inp->def_send.sinfo_context = info->snd_context;
6132 SCTP_INP_WUNLOCK(inp);
6134 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6135 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6136 SCTP_INP_RLOCK(inp);
6137 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6138 SCTP_TCB_LOCK(stcb);
6139 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6140 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6141 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6142 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6143 stcb->asoc.def_send.sinfo_flags |= policy;
6144 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6145 stcb->asoc.def_send.sinfo_context = info->snd_context;
6147 SCTP_TCB_UNLOCK(stcb);
6149 SCTP_INP_RUNLOCK(inp);
6154 case SCTP_DEFAULT_PRINFO:
6156 struct sctp_default_prinfo *info;
6158 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6159 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6161 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6162 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6167 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6168 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6169 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6170 SCTP_TCB_UNLOCK(stcb);
6172 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6173 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6174 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6175 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6176 SCTP_INP_WLOCK(inp);
6177 inp->def_send.sinfo_flags &= 0xfff0;
6178 inp->def_send.sinfo_flags |= info->pr_policy;
6179 inp->def_send.sinfo_timetolive = info->pr_value;
6180 SCTP_INP_WUNLOCK(inp);
6182 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6183 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6184 SCTP_INP_RLOCK(inp);
6185 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6186 SCTP_TCB_LOCK(stcb);
6187 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6188 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6189 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6190 SCTP_TCB_UNLOCK(stcb);
6192 SCTP_INP_RUNLOCK(inp);
6197 case SCTP_PEER_ADDR_THLDS:
6198 /* Applies to the specific association */
6200 struct sctp_paddrthlds *thlds;
6201 struct sctp_nets *net;
6202 struct sockaddr *addr;
6203 #if defined(INET) && defined(INET6)
6204 struct sockaddr_in sin_store;
6207 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6208 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6210 #if defined(INET) && defined(INET6)
6211 if (thlds->spt_address.ss_family == AF_INET6) {
6212 struct sockaddr_in6 *sin6;
6214 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6215 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6216 in6_sin6_2_sin(&sin_store, sin6);
6217 addr = (struct sockaddr *)&sin_store;
6219 addr = (struct sockaddr *)&thlds->spt_address;
6222 addr = (struct sockaddr *)&thlds->spt_address;
6225 addr = (struct sockaddr *)&thlds->spt_address;
6228 net = sctp_findnet(stcb, addr);
6231 * We increment here since
6232 * sctp_findassociation_ep_addr() wil do a
6233 * decrement if it finds the stcb as long as
6234 * the locked tcb (last argument) is NOT a
6238 SCTP_INP_INCR_REF(inp);
6239 stcb = sctp_findassociation_ep_addr(&inp, addr,
6242 SCTP_INP_DECR_REF(inp);
6245 if ((stcb != NULL) && (net == NULL)) {
6247 if (addr->sa_family == AF_INET) {
6249 struct sockaddr_in *sin;
6251 sin = (struct sockaddr_in *)addr;
6252 if (sin->sin_addr.s_addr != INADDR_ANY) {
6253 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6254 SCTP_TCB_UNLOCK(stcb);
6261 if (addr->sa_family == AF_INET6) {
6262 struct sockaddr_in6 *sin6;
6264 sin6 = (struct sockaddr_in6 *)addr;
6265 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6266 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6267 SCTP_TCB_UNLOCK(stcb);
6274 error = EAFNOSUPPORT;
6275 SCTP_TCB_UNLOCK(stcb);
6276 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6280 if (thlds->spt_pathcpthld != 0xffff) {
6282 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6287 net->failure_threshold = thlds->spt_pathmaxrxt;
6288 net->pf_threshold = thlds->spt_pathpfthld;
6289 if (net->dest_state & SCTP_ADDR_PF) {
6290 if ((net->error_count > net->failure_threshold) ||
6291 (net->error_count <= net->pf_threshold)) {
6292 net->dest_state &= ~SCTP_ADDR_PF;
6295 if ((net->error_count > net->pf_threshold) &&
6296 (net->error_count <= net->failure_threshold)) {
6297 net->dest_state |= SCTP_ADDR_PF;
6298 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6299 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6300 stcb->sctp_ep, stcb, net,
6301 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6302 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6305 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6306 if (net->error_count > net->failure_threshold) {
6307 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6308 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6311 if (net->error_count <= net->failure_threshold) {
6312 net->dest_state |= SCTP_ADDR_REACHABLE;
6313 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6317 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6318 net->failure_threshold = thlds->spt_pathmaxrxt;
6319 net->pf_threshold = thlds->spt_pathpfthld;
6320 if (net->dest_state & SCTP_ADDR_PF) {
6321 if ((net->error_count > net->failure_threshold) ||
6322 (net->error_count <= net->pf_threshold)) {
6323 net->dest_state &= ~SCTP_ADDR_PF;
6326 if ((net->error_count > net->pf_threshold) &&
6327 (net->error_count <= net->failure_threshold)) {
6328 net->dest_state |= SCTP_ADDR_PF;
6329 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6330 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6331 stcb->sctp_ep, stcb, net,
6332 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6333 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6336 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6337 if (net->error_count > net->failure_threshold) {
6338 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6339 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6342 if (net->error_count <= net->failure_threshold) {
6343 net->dest_state |= SCTP_ADDR_REACHABLE;
6344 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6348 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6349 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6351 SCTP_TCB_UNLOCK(stcb);
6353 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6354 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6355 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6356 SCTP_INP_WLOCK(inp);
6357 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6358 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6359 SCTP_INP_WUNLOCK(inp);
6361 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6367 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6369 struct sctp_udpencaps *encaps;
6370 struct sctp_nets *net;
6371 struct sockaddr *addr;
6372 #if defined(INET) && defined(INET6)
6373 struct sockaddr_in sin_store;
6376 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6377 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6379 #if defined(INET) && defined(INET6)
6380 if (encaps->sue_address.ss_family == AF_INET6) {
6381 struct sockaddr_in6 *sin6;
6383 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6384 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6385 in6_sin6_2_sin(&sin_store, sin6);
6386 addr = (struct sockaddr *)&sin_store;
6388 addr = (struct sockaddr *)&encaps->sue_address;
6391 addr = (struct sockaddr *)&encaps->sue_address;
6394 addr = (struct sockaddr *)&encaps->sue_address;
6397 net = sctp_findnet(stcb, addr);
6400 * We increment here since
6401 * sctp_findassociation_ep_addr() wil do a
6402 * decrement if it finds the stcb as long as
6403 * the locked tcb (last argument) is NOT a
6407 SCTP_INP_INCR_REF(inp);
6408 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6410 SCTP_INP_DECR_REF(inp);
6413 if ((stcb != NULL) && (net == NULL)) {
6415 if (addr->sa_family == AF_INET) {
6417 struct sockaddr_in *sin;
6419 sin = (struct sockaddr_in *)addr;
6420 if (sin->sin_addr.s_addr != INADDR_ANY) {
6421 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6422 SCTP_TCB_UNLOCK(stcb);
6429 if (addr->sa_family == AF_INET6) {
6430 struct sockaddr_in6 *sin6;
6432 sin6 = (struct sockaddr_in6 *)addr;
6433 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6434 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6435 SCTP_TCB_UNLOCK(stcb);
6442 error = EAFNOSUPPORT;
6443 SCTP_TCB_UNLOCK(stcb);
6444 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6450 net->port = encaps->sue_port;
6452 stcb->asoc.port = encaps->sue_port;
6454 SCTP_TCB_UNLOCK(stcb);
6456 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6457 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6458 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6459 SCTP_INP_WLOCK(inp);
6460 inp->sctp_ep.port = encaps->sue_port;
6461 SCTP_INP_WUNLOCK(inp);
6463 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6469 case SCTP_ECN_SUPPORTED:
6471 struct sctp_assoc_value *av;
6473 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6474 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6477 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6479 SCTP_TCB_UNLOCK(stcb);
6481 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6482 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6483 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6484 SCTP_INP_WLOCK(inp);
6485 if (av->assoc_value == 0) {
6486 inp->ecn_supported = 0;
6488 inp->ecn_supported = 1;
6490 SCTP_INP_WUNLOCK(inp);
6492 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6498 case SCTP_PR_SUPPORTED:
6500 struct sctp_assoc_value *av;
6502 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6503 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6506 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6508 SCTP_TCB_UNLOCK(stcb);
6510 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6511 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6512 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6513 SCTP_INP_WLOCK(inp);
6514 if (av->assoc_value == 0) {
6515 inp->prsctp_supported = 0;
6517 inp->prsctp_supported = 1;
6519 SCTP_INP_WUNLOCK(inp);
6521 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6527 case SCTP_AUTH_SUPPORTED:
6529 struct sctp_assoc_value *av;
6531 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6532 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6535 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6537 SCTP_TCB_UNLOCK(stcb);
6539 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6540 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6541 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6542 if ((av->assoc_value == 0) &&
6543 (inp->asconf_supported == 1)) {
6544 /* AUTH is required for
6546 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6549 SCTP_INP_WLOCK(inp);
6550 if (av->assoc_value == 0) {
6551 inp->auth_supported = 0;
6553 inp->auth_supported = 1;
6555 SCTP_INP_WUNLOCK(inp);
6558 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6564 case SCTP_ASCONF_SUPPORTED:
6566 struct sctp_assoc_value *av;
6568 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6569 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6572 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6574 SCTP_TCB_UNLOCK(stcb);
6576 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6577 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6578 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6579 if ((av->assoc_value != 0) &&
6580 (inp->auth_supported == 0)) {
6581 /* AUTH is required for
6583 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6586 SCTP_INP_WLOCK(inp);
6587 if (av->assoc_value == 0) {
6588 inp->asconf_supported = 0;
6589 sctp_auth_delete_chunk(SCTP_ASCONF,
6590 inp->sctp_ep.local_auth_chunks);
6591 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6592 inp->sctp_ep.local_auth_chunks);
6594 inp->asconf_supported = 1;
6595 sctp_auth_add_chunk(SCTP_ASCONF,
6596 inp->sctp_ep.local_auth_chunks);
6597 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6598 inp->sctp_ep.local_auth_chunks);
6600 SCTP_INP_WUNLOCK(inp);
6603 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6609 case SCTP_RECONFIG_SUPPORTED:
6611 struct sctp_assoc_value *av;
6613 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6614 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6617 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6619 SCTP_TCB_UNLOCK(stcb);
6621 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6622 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6623 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6624 SCTP_INP_WLOCK(inp);
6625 if (av->assoc_value == 0) {
6626 inp->reconfig_supported = 0;
6628 inp->reconfig_supported = 1;
6630 SCTP_INP_WUNLOCK(inp);
6632 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6638 case SCTP_NRSACK_SUPPORTED:
6640 struct sctp_assoc_value *av;
6642 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6643 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6646 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6648 SCTP_TCB_UNLOCK(stcb);
6650 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6651 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6652 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6653 SCTP_INP_WLOCK(inp);
6654 if (av->assoc_value == 0) {
6655 inp->nrsack_supported = 0;
6657 inp->nrsack_supported = 1;
6659 SCTP_INP_WUNLOCK(inp);
6661 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6667 case SCTP_PKTDROP_SUPPORTED:
6669 struct sctp_assoc_value *av;
6671 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6672 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6675 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6677 SCTP_TCB_UNLOCK(stcb);
6679 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6680 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6681 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6682 SCTP_INP_WLOCK(inp);
6683 if (av->assoc_value == 0) {
6684 inp->pktdrop_supported = 0;
6686 inp->pktdrop_supported = 1;
6688 SCTP_INP_WUNLOCK(inp);
6690 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6698 struct sctp_assoc_value *av;
6699 struct sctp_nets *net;
6701 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6702 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6705 stcb->asoc.max_cwnd = av->assoc_value;
6706 if (stcb->asoc.max_cwnd > 0) {
6707 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6708 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6709 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6710 net->cwnd = stcb->asoc.max_cwnd;
6711 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6712 net->cwnd = net->mtu - sizeof(struct sctphdr);
6717 SCTP_TCB_UNLOCK(stcb);
6719 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6720 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6721 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6722 SCTP_INP_WLOCK(inp);
6723 inp->max_cwnd = av->assoc_value;
6724 SCTP_INP_WUNLOCK(inp);
6726 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6733 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6734 error = ENOPROTOOPT;
6736 } /* end switch (opt) */
6741 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6743 void *optval = NULL;
6747 struct sctp_inpcb *inp;
6749 if ((sopt->sopt_level == SOL_SOCKET) &&
6750 (sopt->sopt_name == SO_SETFIB)) {
6751 inp = (struct sctp_inpcb *)so->so_pcb;
6753 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6756 SCTP_INP_WLOCK(inp);
6757 inp->fibnum = so->so_fibnum;
6758 SCTP_INP_WUNLOCK(inp);
6761 if (sopt->sopt_level != IPPROTO_SCTP) {
6762 /* wrong proto level... send back up to IP */
6764 if (INP_CHECK_SOCKAF(so, AF_INET6))
6765 error = ip6_ctloutput(so, sopt);
6767 #if defined(INET) && defined(INET6)
6771 error = ip_ctloutput(so, sopt);
6775 optsize = sopt->sopt_valsize;
6777 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6778 if (optval == NULL) {
6779 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6782 error = sooptcopyin(sopt, optval, optsize, optsize);
6784 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6788 p = (void *)sopt->sopt_td;
6789 if (sopt->sopt_dir == SOPT_SET) {
6790 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6791 } else if (sopt->sopt_dir == SOPT_GET) {
6792 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6794 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6797 if ((error == 0) && (optval != NULL)) {
6798 error = sooptcopyout(sopt, optval, optsize);
6799 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6800 } else if (optval != NULL) {
6801 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6809 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6812 int create_lock_on = 0;
6814 struct sctp_inpcb *inp;
6815 struct sctp_tcb *stcb = NULL;
6817 inp = (struct sctp_inpcb *)so->so_pcb;
6819 /* I made the same as TCP since we are not setup? */
6820 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6821 return (ECONNRESET);
6824 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6827 switch (addr->sa_family) {
6831 struct sockaddr_in6 *sin6p;
6833 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6834 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6837 sin6p = (struct sockaddr_in6 *)addr;
6838 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6839 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6848 struct sockaddr_in *sinp;
6850 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6851 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6854 sinp = (struct sockaddr_in *)addr;
6855 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6856 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6863 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6864 return (EAFNOSUPPORT);
6866 SCTP_INP_INCR_REF(inp);
6867 SCTP_ASOC_CREATE_LOCK(inp);
6871 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6872 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6873 /* Should I really unlock ? */
6874 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6879 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6880 (addr->sa_family == AF_INET6)) {
6881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6886 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6887 SCTP_PCB_FLAGS_UNBOUND) {
6888 /* Bind a ephemeral port */
6889 error = sctp_inpcb_bind(so, NULL, NULL, p);
6894 /* Now do we connect? */
6895 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6896 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6897 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6901 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6902 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6903 /* We are already connected AND the TCP model */
6904 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6908 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6909 SCTP_INP_RLOCK(inp);
6910 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6911 SCTP_INP_RUNLOCK(inp);
6914 * We increment here since sctp_findassociation_ep_addr()
6915 * will do a decrement if it finds the stcb as long as the
6916 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6918 SCTP_INP_INCR_REF(inp);
6919 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6921 SCTP_INP_DECR_REF(inp);
6923 SCTP_TCB_UNLOCK(stcb);
6927 /* Already have or am bring up an association */
6928 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
6932 vrf_id = inp->def_vrf_id;
6933 /* We are GOOD to go */
6934 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
6935 inp->sctp_ep.pre_open_stream_count,
6936 inp->sctp_ep.port, p);
6938 /* Gak! no memory */
6941 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
6942 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
6943 /* Set the connected flag so we can queue data */
6946 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
6947 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
6949 /* initialize authentication parameters for the assoc */
6950 sctp_initialize_auth_params(inp, stcb);
6952 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
6953 SCTP_TCB_UNLOCK(stcb);
6955 if (create_lock_on) {
6956 SCTP_ASOC_CREATE_UNLOCK(inp);
6958 SCTP_INP_DECR_REF(inp);
6964 sctp_listen(struct socket *so, int backlog, struct thread *p)
6967 * Note this module depends on the protocol processing being called
6968 * AFTER any socket level flags and backlog are applied to the
6969 * socket. The traditional way that the socket flags are applied is
6970 * AFTER protocol processing. We have made a change to the
6971 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
6972 * place if the socket API for SCTP is to work properly.
6976 struct sctp_inpcb *inp;
6978 inp = (struct sctp_inpcb *)so->so_pcb;
6980 /* I made the same as TCP since we are not setup? */
6981 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6982 return (ECONNRESET);
6984 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
6985 /* See if we have a listener */
6986 struct sctp_inpcb *tinp;
6987 union sctp_sockstore store;
6989 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
6991 struct sctp_laddr *laddr;
6993 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6994 memcpy(&store, &laddr->ifa->address, sizeof(store));
6995 switch (store.sa.sa_family) {
6998 store.sin.sin_port = inp->sctp_lport;
7003 store.sin6.sin6_port = inp->sctp_lport;
7009 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7010 if (tinp && (tinp != inp) &&
7011 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7012 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7013 (tinp->sctp_socket->so_qlimit)) {
7014 /* we have a listener already and
7015 * its not this inp. */
7016 SCTP_INP_DECR_REF(tinp);
7017 return (EADDRINUSE);
7019 SCTP_INP_DECR_REF(tinp);
7023 /* Setup a local addr bound all */
7024 memset(&store, 0, sizeof(store));
7026 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7027 store.sa.sa_family = AF_INET6;
7028 store.sa.sa_len = sizeof(struct sockaddr_in6);
7032 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7033 store.sa.sa_family = AF_INET;
7034 store.sa.sa_len = sizeof(struct sockaddr_in);
7037 switch (store.sa.sa_family) {
7040 store.sin.sin_port = inp->sctp_lport;
7045 store.sin6.sin6_port = inp->sctp_lport;
7051 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7052 if (tinp && (tinp != inp) &&
7053 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7054 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7055 (tinp->sctp_socket->so_qlimit)) {
7056 /* we have a listener already and its not
7058 SCTP_INP_DECR_REF(tinp);
7059 return (EADDRINUSE);
7061 SCTP_INP_DECR_REF(tinp);
7065 SCTP_INP_RLOCK(inp);
7066 #ifdef SCTP_LOCK_LOGGING
7067 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7068 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7072 error = solisten_proto_check(so);
7075 SCTP_INP_RUNLOCK(inp);
7078 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7079 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7081 * The unlucky case - We are in the tcp pool with this guy.
7082 * - Someone else is in the main inp slot. - We must move
7083 * this guy (the listener) to the main slot - We must then
7084 * move the guy that was listener to the TCP Pool.
7086 if (sctp_swap_inpcb_for_listen(inp)) {
7087 SCTP_INP_RUNLOCK(inp);
7088 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7089 return (EADDRINUSE);
7092 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7093 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7094 /* We are already connected AND the TCP model */
7095 SCTP_INP_RUNLOCK(inp);
7096 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7097 return (EADDRINUSE);
7099 SCTP_INP_RUNLOCK(inp);
7100 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7101 /* We must do a bind. */
7102 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7103 /* bind error, probably perm */
7108 /* It appears for 7.0 and on, we must always call this. */
7109 solisten_proto(so, backlog);
7110 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7111 /* remove the ACCEPTCONN flag for one-to-many sockets */
7112 so->so_options &= ~SO_ACCEPTCONN;
7115 /* turning off listen */
7116 so->so_options &= ~SO_ACCEPTCONN;
7122 static int sctp_defered_wakeup_cnt = 0;
7125 sctp_accept(struct socket *so, struct sockaddr **addr)
7127 struct sctp_tcb *stcb;
7128 struct sctp_inpcb *inp;
7129 union sctp_sockstore store;
7133 inp = (struct sctp_inpcb *)so->so_pcb;
7136 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7137 return (ECONNRESET);
7139 SCTP_INP_RLOCK(inp);
7140 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7141 SCTP_INP_RUNLOCK(inp);
7142 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7143 return (EOPNOTSUPP);
7145 if (so->so_state & SS_ISDISCONNECTED) {
7146 SCTP_INP_RUNLOCK(inp);
7147 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7148 return (ECONNABORTED);
7150 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7152 SCTP_INP_RUNLOCK(inp);
7153 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7154 return (ECONNRESET);
7156 SCTP_TCB_LOCK(stcb);
7157 SCTP_INP_RUNLOCK(inp);
7158 store = stcb->asoc.primary_destination->ro._l_addr;
7159 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
7160 SCTP_TCB_UNLOCK(stcb);
7161 switch (store.sa.sa_family) {
7165 struct sockaddr_in *sin;
7167 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7170 sin->sin_family = AF_INET;
7171 sin->sin_len = sizeof(*sin);
7172 sin->sin_port = store.sin.sin_port;
7173 sin->sin_addr = store.sin.sin_addr;
7174 *addr = (struct sockaddr *)sin;
7181 struct sockaddr_in6 *sin6;
7183 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7186 sin6->sin6_family = AF_INET6;
7187 sin6->sin6_len = sizeof(*sin6);
7188 sin6->sin6_port = store.sin6.sin6_port;
7189 sin6->sin6_addr = store.sin6.sin6_addr;
7190 if ((error = sa6_recoverscope(sin6)) != 0) {
7191 SCTP_FREE_SONAME(sin6);
7194 *addr = (struct sockaddr *)sin6;
7202 /* Wake any delayed sleep action */
7203 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7204 SCTP_INP_WLOCK(inp);
7205 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7206 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7207 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7208 SCTP_INP_WUNLOCK(inp);
7209 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7210 if (sowriteable(inp->sctp_socket)) {
7211 sowwakeup_locked(inp->sctp_socket);
7213 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7215 SCTP_INP_WLOCK(inp);
7217 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7218 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7219 SCTP_INP_WUNLOCK(inp);
7220 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7221 if (soreadable(inp->sctp_socket)) {
7222 sctp_defered_wakeup_cnt++;
7223 sorwakeup_locked(inp->sctp_socket);
7225 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7227 SCTP_INP_WLOCK(inp);
7229 SCTP_INP_WUNLOCK(inp);
7231 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7232 SCTP_TCB_LOCK(stcb);
7233 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7234 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7241 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7243 struct sockaddr_in *sin;
7245 struct sctp_inpcb *inp;
7246 struct sctp_ifa *sctp_ifa;
7249 * Do the malloc first in case it blocks.
7251 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7254 sin->sin_family = AF_INET;
7255 sin->sin_len = sizeof(*sin);
7256 inp = (struct sctp_inpcb *)so->so_pcb;
7258 SCTP_FREE_SONAME(sin);
7259 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7260 return (ECONNRESET);
7262 SCTP_INP_RLOCK(inp);
7263 sin->sin_port = inp->sctp_lport;
7264 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7265 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7266 struct sctp_tcb *stcb;
7267 struct sockaddr_in *sin_a;
7268 struct sctp_nets *net;
7271 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7277 SCTP_TCB_LOCK(stcb);
7278 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7279 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7281 /* this will make coverity happy */
7284 if (sin_a->sin_family == AF_INET) {
7289 if ((!fnd) || (sin_a == NULL)) {
7291 SCTP_TCB_UNLOCK(stcb);
7294 vrf_id = inp->def_vrf_id;
7295 sctp_ifa = sctp_source_address_selection(inp,
7297 (sctp_route_t *) & net->ro,
7300 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7301 sctp_free_ifa(sctp_ifa);
7303 SCTP_TCB_UNLOCK(stcb);
7305 /* For the bound all case you get back 0 */
7307 sin->sin_addr.s_addr = 0;
7311 /* Take the first IPv4 address in the list */
7312 struct sctp_laddr *laddr;
7315 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7316 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7317 struct sockaddr_in *sin_a;
7319 sin_a = &laddr->ifa->address.sin;
7320 sin->sin_addr = sin_a->sin_addr;
7326 SCTP_FREE_SONAME(sin);
7327 SCTP_INP_RUNLOCK(inp);
7328 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7332 SCTP_INP_RUNLOCK(inp);
7333 (*addr) = (struct sockaddr *)sin;
7338 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7340 struct sockaddr_in *sin;
7342 struct sockaddr_in *sin_a;
7343 struct sctp_inpcb *inp;
7344 struct sctp_tcb *stcb;
7345 struct sctp_nets *net;
7347 /* Do the malloc first in case it blocks. */
7348 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7351 sin->sin_family = AF_INET;
7352 sin->sin_len = sizeof(*sin);
7354 inp = (struct sctp_inpcb *)so->so_pcb;
7355 if ((inp == NULL) ||
7356 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7357 /* UDP type and listeners will drop out here */
7358 SCTP_FREE_SONAME(sin);
7359 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7362 SCTP_INP_RLOCK(inp);
7363 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7365 SCTP_TCB_LOCK(stcb);
7367 SCTP_INP_RUNLOCK(inp);
7369 SCTP_FREE_SONAME(sin);
7370 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7371 return (ECONNRESET);
7374 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7375 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7376 if (sin_a->sin_family == AF_INET) {
7378 sin->sin_port = stcb->rport;
7379 sin->sin_addr = sin_a->sin_addr;
7383 SCTP_TCB_UNLOCK(stcb);
7385 /* No IPv4 address */
7386 SCTP_FREE_SONAME(sin);
7387 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7390 (*addr) = (struct sockaddr *)sin;
7394 struct pr_usrreqs sctp_usrreqs = {
7395 .pru_abort = sctp_abort,
7396 .pru_accept = sctp_accept,
7397 .pru_attach = sctp_attach,
7398 .pru_bind = sctp_bind,
7399 .pru_connect = sctp_connect,
7400 .pru_control = in_control,
7401 .pru_close = sctp_close,
7402 .pru_detach = sctp_close,
7403 .pru_sopoll = sopoll_generic,
7404 .pru_flush = sctp_flush,
7405 .pru_disconnect = sctp_disconnect,
7406 .pru_listen = sctp_listen,
7407 .pru_peeraddr = sctp_peeraddr,
7408 .pru_send = sctp_sendm,
7409 .pru_shutdown = sctp_shutdown,
7410 .pru_sockaddr = sctp_ingetaddr,
7411 .pru_sosend = sctp_sosend,
7412 .pru_soreceive = sctp_soreceive