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)
163 if (icmp_type != ICMP_UNREACH) {
164 /* We only care about unreachable */
165 SCTP_TCB_UNLOCK(stcb);
168 if ((icmp_code == ICMP_UNREACH_NET) ||
169 (icmp_code == ICMP_UNREACH_HOST) ||
170 (icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
171 (icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
172 (icmp_code == ICMP_UNREACH_ISOLATED) ||
173 (icmp_code == ICMP_UNREACH_NET_PROHIB) ||
174 (icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
175 (icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
176 /* Mark the net unreachable. */
177 if (net->dest_state & SCTP_ADDR_REACHABLE) {
178 /* OK, that destination is NOT reachable. */
179 net->dest_state &= ~SCTP_ADDR_REACHABLE;
180 net->dest_state &= ~SCTP_ADDR_PF;
181 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
183 (void *)net, SCTP_SO_NOT_LOCKED);
185 SCTP_TCB_UNLOCK(stcb);
186 } else if ((icmp_code == ICMP_UNREACH_PROTOCOL) ||
187 (icmp_code == ICMP_UNREACH_PORT)) {
188 /* Treat it like an ABORT. */
189 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
190 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
191 so = SCTP_INP_SO(inp);
192 atomic_add_int(&stcb->asoc.refcnt, 1);
193 SCTP_TCB_UNLOCK(stcb);
194 SCTP_SOCKET_LOCK(so, 1);
196 atomic_subtract_int(&stcb->asoc.refcnt, 1);
198 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
199 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
200 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
201 SCTP_SOCKET_UNLOCK(so, 1);
202 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
204 /* no need to unlock here, since the TCB is gone */
205 } else if (icmp_code == ICMP_UNREACH_NEEDFRAG) {
206 /* Find the next (smaller) MTU */
209 * Old type router that does not tell us what the
210 * next MTU is. Rats we will have to guess (in a
211 * educated fashion of course).
213 next_mtu = sctp_get_prev_mtu(ip_len);
215 /* Stop the PMTU timer. */
216 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
218 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
219 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
223 /* Update the path MTU. */
224 if (net->mtu > next_mtu) {
227 net->mtu -= sizeof(struct udphdr);
230 /* Update the association MTU */
231 if (stcb->asoc.smallest_mtu > next_mtu) {
232 sctp_pathmtu_adjustment(stcb, next_mtu);
234 /* Finally, start the PMTU timer if it was running before. */
236 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
238 SCTP_TCB_UNLOCK(stcb);
240 SCTP_TCB_UNLOCK(stcb);
245 sctp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
251 struct sctp_inpcb *inp;
252 struct sctp_tcb *stcb;
253 struct sctp_nets *net;
254 struct sctp_init_chunk *ch;
255 struct sockaddr_in src, dst;
257 if (sa->sa_family != AF_INET ||
258 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
261 if (PRC_IS_REDIRECT(cmd)) {
263 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
267 inner_ip = (struct ip *)vip;
268 icmp = (struct icmp *)((caddr_t)inner_ip -
269 (sizeof(struct icmp) - sizeof(struct ip)));
270 outer_ip = (struct ip *)((caddr_t)icmp - sizeof(struct ip));
271 sh = (struct sctphdr *)((caddr_t)inner_ip + (inner_ip->ip_hl << 2));
272 memset(&src, 0, sizeof(struct sockaddr_in));
273 src.sin_family = AF_INET;
274 src.sin_len = sizeof(struct sockaddr_in);
275 src.sin_port = sh->src_port;
276 src.sin_addr = inner_ip->ip_src;
277 memset(&dst, 0, sizeof(struct sockaddr_in));
278 dst.sin_family = AF_INET;
279 dst.sin_len = sizeof(struct sockaddr_in);
280 dst.sin_port = sh->dest_port;
281 dst.sin_addr = inner_ip->ip_dst;
283 * 'dst' holds the dest of the packet that failed to be
284 * sent. 'src' holds our local endpoint address. Thus we
285 * reverse the dst and the src in the lookup.
289 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst,
290 (struct sockaddr *)&src,
293 if ((stcb != NULL) &&
296 /* Check the verification tag */
297 if (ntohl(sh->v_tag) != 0) {
299 * This must be the verification tag used
300 * for sending out packets. We don't
301 * consider packets reflecting the
304 if (ntohl(sh->v_tag) != stcb->asoc.peer_vtag) {
305 SCTP_TCB_UNLOCK(stcb);
309 if (ntohs(outer_ip->ip_len) >=
311 8 + (inner_ip->ip_hl << 2) + 20) {
313 * In this case we can check if we
314 * got an INIT chunk and if the
315 * initiate tag matches.
317 ch = (struct sctp_init_chunk *)(sh + 1);
318 if ((ch->ch.chunk_type != SCTP_INITIATION) ||
319 (ntohl(ch->init.initiate_tag) != stcb->asoc.my_vtag)) {
320 SCTP_TCB_UNLOCK(stcb);
324 SCTP_TCB_UNLOCK(stcb);
328 sctp_notify(inp, stcb, net,
331 ntohs(inner_ip->ip_len),
332 ntohs(icmp->icmp_nextmtu));
334 if ((stcb == NULL) && (inp != NULL)) {
335 /* reduce ref-count */
337 SCTP_INP_DECR_REF(inp);
338 SCTP_INP_WUNLOCK(inp);
341 SCTP_TCB_UNLOCK(stcb);
351 sctp_getcred(SYSCTL_HANDLER_ARGS)
354 struct sockaddr_in addrs[2];
355 struct sctp_inpcb *inp;
356 struct sctp_nets *net;
357 struct sctp_tcb *stcb;
361 /* FIX, for non-bsd is this right? */
362 vrf_id = SCTP_DEFAULT_VRFID;
364 error = priv_check(req->td, PRIV_NETINET_GETCRED);
369 error = SYSCTL_IN(req, addrs, sizeof(addrs));
373 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
375 &inp, &net, 1, vrf_id);
376 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
377 if ((inp != NULL) && (stcb == NULL)) {
378 /* reduce ref-count */
380 SCTP_INP_DECR_REF(inp);
383 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
387 SCTP_TCB_UNLOCK(stcb);
389 * We use the write lock here, only since in the error leg we need
390 * it. If we used RLOCK, then we would have to
391 * wlock/decr/unlock/rlock. Which in theory could create a hole.
392 * Better to use higher wlock.
396 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
398 SCTP_INP_WUNLOCK(inp);
401 cru2x(inp->sctp_socket->so_cred, &xuc);
402 SCTP_INP_WUNLOCK(inp);
403 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
408 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
409 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
414 sctp_abort(struct socket *so)
416 struct sctp_inpcb *inp;
419 inp = (struct sctp_inpcb *)so->so_pcb;
424 flags = inp->sctp_flags;
425 #ifdef SCTP_LOG_CLOSING
426 sctp_log_closing(inp, NULL, 17);
428 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
429 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
430 #ifdef SCTP_LOG_CLOSING
431 sctp_log_closing(inp, NULL, 16);
433 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
434 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
436 SCTP_SB_CLEAR(so->so_snd);
438 * same for the rcv ones, they are only here for the
441 SCTP_SB_CLEAR(so->so_rcv);
443 /* Now null out the reference, we are completely detached. */
447 flags = inp->sctp_flags;
448 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
449 goto sctp_must_try_again;
456 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
458 struct sctp_inpcb *inp;
459 struct inpcb *ip_inp;
461 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
463 inp = (struct sctp_inpcb *)so->so_pcb;
465 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
468 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
469 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
474 error = sctp_inpcb_alloc(so, vrf_id);
478 inp = (struct sctp_inpcb *)so->so_pcb;
480 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
481 ip_inp = &inp->ip_inp.inp;
482 ip_inp->inp_vflag |= INP_IPV4;
483 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
484 SCTP_INP_WUNLOCK(inp);
489 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
491 struct sctp_inpcb *inp;
493 inp = (struct sctp_inpcb *)so->so_pcb;
495 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
499 if ((addr->sa_family != AF_INET) ||
500 (addr->sa_len != sizeof(struct sockaddr_in))) {
501 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
505 return (sctp_inpcb_bind(so, addr, NULL, p));
510 sctp_close(struct socket *so)
512 struct sctp_inpcb *inp;
515 inp = (struct sctp_inpcb *)so->so_pcb;
520 * Inform all the lower layer assoc that we are done.
523 flags = inp->sctp_flags;
524 #ifdef SCTP_LOG_CLOSING
525 sctp_log_closing(inp, NULL, 17);
527 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
528 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
529 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
530 (so->so_rcv.sb_cc > 0)) {
531 #ifdef SCTP_LOG_CLOSING
532 sctp_log_closing(inp, NULL, 13);
534 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
535 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
537 #ifdef SCTP_LOG_CLOSING
538 sctp_log_closing(inp, NULL, 14);
540 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
541 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
544 * The socket is now detached, no matter what the state of
545 * the SCTP association.
548 SCTP_SB_CLEAR(so->so_snd);
550 * same for the rcv ones, they are only here for the
553 SCTP_SB_CLEAR(so->so_rcv);
555 /* Now null out the reference, we are completely detached. */
559 flags = inp->sctp_flags;
560 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
561 goto sctp_must_try_again;
569 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
570 struct mbuf *control, struct thread *p);
574 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
575 struct mbuf *control, struct thread *p)
577 struct sctp_inpcb *inp;
580 inp = (struct sctp_inpcb *)so->so_pcb;
583 sctp_m_freem(control);
586 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
590 /* Got to have an to address if we are NOT a connected socket */
591 if ((addr == NULL) &&
592 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
593 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
595 } else if (addr == NULL) {
596 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
597 error = EDESTADDRREQ;
600 sctp_m_freem(control);
606 if (addr->sa_family != AF_INET) {
607 /* must be a v4 address! */
608 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
611 sctp_m_freem(control);
614 error = EDESTADDRREQ;
619 /* now what about control */
622 SCTP_PRINTF("huh? control set?\n");
623 sctp_m_freem(inp->control);
626 inp->control = control;
630 SCTP_BUF_NEXT(inp->pkt_last) = m;
633 inp->pkt_last = inp->pkt = m;
636 /* FreeBSD uses a flag passed */
637 ((flags & PRUS_MORETOCOME) == 0)
640 * note with the current version this code will only be used
641 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
642 * re-defining sosend to use the sctp_sosend. One can
643 * optionally switch back to this code (by changing back the
644 * definitions) but this is not advisable. This code is used
645 * by FreeBSD when sending a file with sendfile() though.
649 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
659 sctp_disconnect(struct socket *so)
661 struct sctp_inpcb *inp;
663 inp = (struct sctp_inpcb *)so->so_pcb;
665 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
669 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
670 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
671 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
673 SCTP_INP_RUNLOCK(inp);
676 struct sctp_association *asoc;
677 struct sctp_tcb *stcb;
679 stcb = LIST_FIRST(&inp->sctp_asoc_list);
681 SCTP_INP_RUNLOCK(inp);
682 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
687 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
688 /* We are about to be freed, out of here */
689 SCTP_TCB_UNLOCK(stcb);
690 SCTP_INP_RUNLOCK(inp);
693 if (((so->so_options & SO_LINGER) &&
694 (so->so_linger == 0)) ||
695 (so->so_rcv.sb_cc > 0)) {
696 if (SCTP_GET_STATE(asoc) !=
697 SCTP_STATE_COOKIE_WAIT) {
698 /* Left with Data unread */
701 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_NOWAIT, 1, MT_DATA);
707 struct sctp_paramhdr *ph;
709 ph = mtod(err, struct sctp_paramhdr *);
710 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
711 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
712 ph->param_length = htons(SCTP_BUF_LEN(err));
714 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
715 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
717 SCTP_INP_RUNLOCK(inp);
718 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
719 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
720 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
722 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
723 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
724 /* No unlock tcb assoc is gone */
727 if (TAILQ_EMPTY(&asoc->send_queue) &&
728 TAILQ_EMPTY(&asoc->sent_queue) &&
729 (asoc->stream_queue_cnt == 0)) {
730 /* there is nothing queued to send, so done */
731 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
734 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
735 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
736 /* only send SHUTDOWN 1st time thru */
737 struct sctp_nets *netp;
739 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
740 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
741 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
743 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
744 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
745 sctp_stop_timers_for_shutdown(stcb);
746 if (stcb->asoc.alternate) {
747 netp = stcb->asoc.alternate;
749 netp = stcb->asoc.primary_destination;
751 sctp_send_shutdown(stcb, netp);
752 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
753 stcb->sctp_ep, stcb, netp);
754 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
755 stcb->sctp_ep, stcb, netp);
756 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
760 * we still got (or just got) data to send,
761 * so set SHUTDOWN_PENDING
764 * XXX sockets draft says that SCTP_EOF
765 * should be sent with no data. currently,
766 * we will allow user data to be sent first
767 * and move to SHUTDOWN-PENDING
769 struct sctp_nets *netp;
771 if (stcb->asoc.alternate) {
772 netp = stcb->asoc.alternate;
774 netp = stcb->asoc.primary_destination;
777 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
778 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
780 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
781 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
783 if (TAILQ_EMPTY(&asoc->send_queue) &&
784 TAILQ_EMPTY(&asoc->sent_queue) &&
785 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
789 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
790 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
791 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
792 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
793 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
794 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
795 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
797 SCTP_INP_RUNLOCK(inp);
798 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
799 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
802 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
805 soisdisconnecting(so);
806 SCTP_TCB_UNLOCK(stcb);
807 SCTP_INP_RUNLOCK(inp);
812 /* UDP model does not support this */
813 SCTP_INP_RUNLOCK(inp);
814 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
820 sctp_flush(struct socket *so, int how)
823 * We will just clear out the values and let subsequent close clear
824 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
825 * they will not be able to read the data, the socket will block
826 * that from happening.
828 struct sctp_inpcb *inp;
830 inp = (struct sctp_inpcb *)so->so_pcb;
832 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
836 /* For the 1 to many model this does nothing */
837 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
838 SCTP_INP_RUNLOCK(inp);
841 SCTP_INP_RUNLOCK(inp);
842 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
844 * First make sure the sb will be happy, we don't use these
845 * except maybe the count
848 SCTP_INP_READ_LOCK(inp);
849 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
850 SCTP_INP_READ_UNLOCK(inp);
851 SCTP_INP_WUNLOCK(inp);
852 so->so_rcv.sb_cc = 0;
853 so->so_rcv.sb_mbcnt = 0;
854 so->so_rcv.sb_mb = NULL;
856 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
858 * First make sure the sb will be happy, we don't use these
859 * except maybe the count
861 so->so_snd.sb_cc = 0;
862 so->so_snd.sb_mbcnt = 0;
863 so->so_snd.sb_mb = NULL;
870 sctp_shutdown(struct socket *so)
872 struct sctp_inpcb *inp;
874 inp = (struct sctp_inpcb *)so->so_pcb;
876 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
880 /* For UDP model this is a invalid call */
881 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
882 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
883 /* Restore the flags that the soshutdown took away. */
884 SOCKBUF_LOCK(&so->so_rcv);
885 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
886 SOCKBUF_UNLOCK(&so->so_rcv);
887 /* This proc will wakeup for read and do nothing (I hope) */
888 SCTP_INP_RUNLOCK(inp);
889 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
893 * Ok, if we reach here its the TCP model and it is either a
894 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
897 struct sctp_tcb *stcb;
898 struct sctp_association *asoc;
899 struct sctp_nets *netp;
902 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
903 SCTP_INP_RUNLOCK(inp);
908 stcb = LIST_FIRST(&inp->sctp_asoc_list);
911 * Ok, we hit the case that the shutdown call was
912 * made after an abort or something. Nothing to do
915 SCTP_INP_RUNLOCK(inp);
920 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
921 SCTP_TCB_UNLOCK(stcb);
922 SCTP_INP_RUNLOCK(inp);
925 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_WAIT) &&
926 (SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_ECHOED) &&
927 (SCTP_GET_STATE(asoc) != SCTP_STATE_OPEN)) {
929 * If we are not in or before ESTABLISHED, there is
930 * no protocol action required.
932 SCTP_TCB_UNLOCK(stcb);
933 SCTP_INP_RUNLOCK(inp);
936 if (stcb->asoc.alternate) {
937 netp = stcb->asoc.alternate;
939 netp = stcb->asoc.primary_destination;
941 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) &&
942 TAILQ_EMPTY(&asoc->send_queue) &&
943 TAILQ_EMPTY(&asoc->sent_queue) &&
944 (asoc->stream_queue_cnt == 0)) {
945 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
948 /* there is nothing queued to send, so I'm done... */
949 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
950 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
951 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
952 sctp_stop_timers_for_shutdown(stcb);
953 sctp_send_shutdown(stcb, netp);
954 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
955 stcb->sctp_ep, stcb, netp);
958 * We still got (or just got) data to send, so set
961 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
962 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
963 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_PARTIAL_MSG_LEFT);
965 if (TAILQ_EMPTY(&asoc->send_queue) &&
966 TAILQ_EMPTY(&asoc->sent_queue) &&
967 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
971 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
972 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
973 sctp_abort_an_association(stcb->sctp_ep, stcb,
974 op_err, SCTP_SO_LOCKED);
975 SCTP_INP_RUNLOCK(inp);
979 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, netp);
981 * XXX: Why do this in the case where we have still data
984 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
985 SCTP_TCB_UNLOCK(stcb);
986 SCTP_INP_RUNLOCK(inp);
992 * copies a "user" presentable address and removes embedded scope, etc.
993 * returns 0 on success, 1 on error
996 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
999 struct sockaddr_in6 lsa6;
1001 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1004 memcpy(ss, sa, sa->sa_len);
1011 * NOTE: assumes addr lock is held
1014 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1015 struct sctp_tcb *stcb,
1017 struct sockaddr_storage *sas,
1020 struct sctp_ifn *sctp_ifn;
1021 struct sctp_ifa *sctp_ifa;
1026 int ipv4_local_scope, ipv4_addr_legal;
1030 int local_scope, site_scope, ipv6_addr_legal;
1033 struct sctp_vrf *vrf;
1040 /* Turn on all the appropriate scope */
1041 loopback_scope = stcb->asoc.scope.loopback_scope;
1043 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1044 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1047 local_scope = stcb->asoc.scope.local_scope;
1048 site_scope = stcb->asoc.scope.site_scope;
1049 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1052 /* Use generic values for endpoints. */
1055 ipv4_local_scope = 1;
1061 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1063 ipv6_addr_legal = 1;
1066 if (SCTP_IPV6_V6ONLY(inp)) {
1067 ipv4_addr_legal = 0;
1069 ipv4_addr_legal = 1;
1074 ipv6_addr_legal = 0;
1077 ipv4_addr_legal = 1;
1081 vrf = sctp_find_vrf(vrf_id);
1085 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1086 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1087 if ((loopback_scope == 0) &&
1088 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1089 /* Skip loopback if loopback_scope not set */
1092 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1095 * For the BOUND-ALL case, the list
1096 * associated with a TCB is Always
1097 * considered a reverse list.. i.e.
1098 * it lists addresses that are NOT
1099 * part of the association. If this
1100 * is one of those we must skip it.
1102 if (sctp_is_addr_restricted(stcb,
1107 switch (sctp_ifa->address.sa.sa_family) {
1110 if (ipv4_addr_legal) {
1111 struct sockaddr_in *sin;
1113 sin = &sctp_ifa->address.sin;
1114 if (sin->sin_addr.s_addr == 0) {
1122 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1123 &sin->sin_addr) != 0) {
1126 if ((ipv4_local_scope == 0) &&
1127 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1131 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1132 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1133 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1134 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1135 actual += sizeof(struct sockaddr_in6);
1138 memcpy(sas, sin, sizeof(*sin));
1139 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1140 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1141 actual += sizeof(*sin);
1145 if (actual >= limit) {
1155 if (ipv6_addr_legal) {
1156 struct sockaddr_in6 *sin6;
1158 sin6 = &sctp_ifa->address.sin6;
1159 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1167 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1168 &sin6->sin6_addr) != 0) {
1171 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1172 if (local_scope == 0)
1174 if (sin6->sin6_scope_id == 0) {
1175 if (sa6_recoverscope(sin6) != 0)
1193 if ((site_scope == 0) &&
1194 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1197 memcpy(sas, sin6, sizeof(*sin6));
1198 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1199 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1200 actual += sizeof(*sin6);
1201 if (actual >= limit) {
1216 struct sctp_laddr *laddr;
1218 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1220 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1224 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1226 switch (laddr->ifa->address.sa.sa_family) {
1229 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1234 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1241 sas = (struct sockaddr_storage *)((caddr_t)sas +
1242 laddr->ifa->address.sa.sa_len);
1243 actual += laddr->ifa->address.sa.sa_len;
1244 if (actual >= limit) {
1253 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1254 struct sctp_tcb *stcb,
1256 struct sockaddr_storage *sas)
1260 SCTP_IPI_ADDR_RLOCK();
1261 /* fill up addresses for the endpoint's default vrf */
1262 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1264 SCTP_IPI_ADDR_RUNLOCK();
1269 * NOTE: assumes addr lock is held
1272 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1275 struct sctp_vrf *vrf = NULL;
1278 * In both sub-set bound an bound_all cases we return the MAXIMUM
1279 * number of addresses that you COULD get. In reality the sub-set
1280 * bound may have an exclusion list for a given TCB OR in the
1281 * bound-all case a TCB may NOT include the loopback or other
1282 * addresses as well.
1284 vrf = sctp_find_vrf(vrf_id);
1288 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1289 struct sctp_ifn *sctp_ifn;
1290 struct sctp_ifa *sctp_ifa;
1292 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1293 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1294 /* Count them if they are the right type */
1295 switch (sctp_ifa->address.sa.sa_family) {
1299 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1300 cnt += sizeof(struct sockaddr_in6);
1302 cnt += sizeof(struct sockaddr_in);
1304 cnt += sizeof(struct sockaddr_in);
1310 cnt += sizeof(struct sockaddr_in6);
1319 struct sctp_laddr *laddr;
1321 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1322 switch (laddr->ifa->address.sa.sa_family) {
1326 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1327 cnt += sizeof(struct sockaddr_in6);
1329 cnt += sizeof(struct sockaddr_in);
1331 cnt += sizeof(struct sockaddr_in);
1337 cnt += sizeof(struct sockaddr_in6);
1349 sctp_count_max_addresses(struct sctp_inpcb *inp)
1353 SCTP_IPI_ADDR_RLOCK();
1354 /* count addresses for the endpoint's default VRF */
1355 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1356 SCTP_IPI_ADDR_RUNLOCK();
1361 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1362 size_t optsize, void *p, int delay)
1365 int creat_lock_on = 0;
1366 struct sctp_tcb *stcb = NULL;
1367 struct sockaddr *sa;
1368 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1370 int bad_addresses = 0;
1373 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1375 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1376 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1377 /* We are already connected AND the TCP model */
1378 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1379 return (EADDRINUSE);
1381 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1382 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1383 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1386 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1387 SCTP_INP_RLOCK(inp);
1388 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1389 SCTP_INP_RUNLOCK(inp);
1392 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1395 SCTP_INP_INCR_REF(inp);
1396 SCTP_ASOC_CREATE_LOCK(inp);
1398 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1399 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1400 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1404 totaddrp = (unsigned int *)optval;
1405 totaddr = *totaddrp;
1406 sa = (struct sockaddr *)(totaddrp + 1);
1407 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (unsigned int)(optsize - sizeof(int)), &bad_addresses);
1408 if ((stcb != NULL) || bad_addresses) {
1409 /* Already have or am bring up an association */
1410 SCTP_ASOC_CREATE_UNLOCK(inp);
1413 SCTP_TCB_UNLOCK(stcb);
1414 if (bad_addresses == 0) {
1415 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1421 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1426 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1428 struct in6pcb *inp6;
1430 inp6 = (struct in6pcb *)inp;
1431 if (SCTP_IPV6_V6ONLY(inp6)) {
1433 * if IPV6_V6ONLY flag, ignore connections destined
1434 * to a v4 addr or v4-mapped addr
1436 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1442 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1443 SCTP_PCB_FLAGS_UNBOUND) {
1444 /* Bind a ephemeral port */
1445 error = sctp_inpcb_bind(so, NULL, NULL, p);
1450 /* FIX ME: do we want to pass in a vrf on the connect call? */
1451 vrf_id = inp->def_vrf_id;
1454 /* We are GOOD to go */
1455 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1456 inp->sctp_ep.pre_open_stream_count,
1461 /* Gak! no memory */
1464 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1465 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1466 /* Set the connected flag so we can queue data */
1469 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1470 /* move to second address */
1471 switch (sa->sa_family) {
1474 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1479 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1487 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1488 /* Fill in the return id */
1490 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE,
1491 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
1494 a_id = (sctp_assoc_t *) optval;
1495 *a_id = sctp_get_associd(stcb);
1497 /* initialize authentication parameters for the assoc */
1498 sctp_initialize_auth_params(inp, stcb);
1501 /* doing delayed connection */
1502 stcb->asoc.delayed_connection = 1;
1503 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1505 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1506 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1508 SCTP_TCB_UNLOCK(stcb);
1509 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1510 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1511 /* Set the connected flag so we can queue data */
1515 if (creat_lock_on) {
1516 SCTP_ASOC_CREATE_UNLOCK(inp);
1518 SCTP_INP_DECR_REF(inp);
1522 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1523 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1524 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1525 SCTP_INP_RLOCK(inp); \
1526 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1528 SCTP_TCB_LOCK(stcb); \
1530 SCTP_INP_RUNLOCK(inp); \
1531 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1532 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1533 if (stcb == NULL) { \
1534 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1544 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1545 if (size < sizeof(type)) { \
1546 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1550 destp = (type *)srcp; \
1555 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1558 struct sctp_inpcb *inp = NULL;
1560 struct sctp_tcb *stcb = NULL;
1562 if (optval == NULL) {
1563 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1566 inp = (struct sctp_inpcb *)so->so_pcb;
1568 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1575 case SCTP_AUTOCLOSE:
1576 case SCTP_EXPLICIT_EOR:
1577 case SCTP_AUTO_ASCONF:
1578 case SCTP_DISABLE_FRAGMENTS:
1579 case SCTP_I_WANT_MAPPED_V4_ADDR:
1580 case SCTP_USE_EXT_RCVINFO:
1581 SCTP_INP_RLOCK(inp);
1583 case SCTP_DISABLE_FRAGMENTS:
1584 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1586 case SCTP_I_WANT_MAPPED_V4_ADDR:
1587 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1589 case SCTP_AUTO_ASCONF:
1590 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1591 /* only valid for bound all sockets */
1592 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1594 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1599 case SCTP_EXPLICIT_EOR:
1600 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1603 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1605 case SCTP_USE_EXT_RCVINFO:
1606 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1608 case SCTP_AUTOCLOSE:
1609 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1610 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1616 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1617 error = ENOPROTOOPT;
1618 } /* end switch (sopt->sopt_name) */
1619 if (*optsize < sizeof(val)) {
1620 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1624 SCTP_INP_RUNLOCK(inp);
1626 /* return the option value */
1627 *(int *)optval = val;
1628 *optsize = sizeof(val);
1631 case SCTP_GET_PACKET_LOG:
1633 #ifdef SCTP_PACKET_LOGGING
1637 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1638 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1641 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1646 case SCTP_REUSE_PORT:
1650 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1651 /* Can't do this for a 1-m socket */
1655 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1656 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1657 *optsize = sizeof(uint32_t);
1660 case SCTP_PARTIAL_DELIVERY_POINT:
1664 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1665 *value = inp->partial_delivery_point;
1666 *optsize = sizeof(uint32_t);
1669 case SCTP_FRAGMENT_INTERLEAVE:
1673 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1674 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1675 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1676 *value = SCTP_FRAG_LEVEL_2;
1678 *value = SCTP_FRAG_LEVEL_1;
1681 *value = SCTP_FRAG_LEVEL_0;
1683 *optsize = sizeof(uint32_t);
1686 case SCTP_INTERLEAVING_SUPPORTED:
1688 struct sctp_assoc_value *av;
1690 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1691 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1694 av->assoc_value = stcb->asoc.idata_supported;
1695 SCTP_TCB_UNLOCK(stcb);
1697 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1698 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1699 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1700 SCTP_INP_RLOCK(inp);
1701 if (inp->idata_supported) {
1702 av->assoc_value = 1;
1704 av->assoc_value = 0;
1706 SCTP_INP_RUNLOCK(inp);
1708 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1713 *optsize = sizeof(struct sctp_assoc_value);
1717 case SCTP_CMT_ON_OFF:
1719 struct sctp_assoc_value *av;
1721 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1722 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1724 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1725 SCTP_TCB_UNLOCK(stcb);
1727 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1728 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1729 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1730 SCTP_INP_RLOCK(inp);
1731 av->assoc_value = inp->sctp_cmt_on_off;
1732 SCTP_INP_RUNLOCK(inp);
1734 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1739 *optsize = sizeof(struct sctp_assoc_value);
1743 case SCTP_PLUGGABLE_CC:
1745 struct sctp_assoc_value *av;
1747 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1748 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1750 av->assoc_value = stcb->asoc.congestion_control_module;
1751 SCTP_TCB_UNLOCK(stcb);
1753 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1754 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1755 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1756 SCTP_INP_RLOCK(inp);
1757 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1758 SCTP_INP_RUNLOCK(inp);
1760 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1765 *optsize = sizeof(struct sctp_assoc_value);
1769 case SCTP_CC_OPTION:
1771 struct sctp_cc_option *cc_opt;
1773 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1774 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1778 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1781 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1782 *optsize = sizeof(struct sctp_cc_option);
1784 SCTP_TCB_UNLOCK(stcb);
1788 case SCTP_PLUGGABLE_SS:
1790 struct sctp_assoc_value *av;
1792 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1793 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1795 av->assoc_value = stcb->asoc.stream_scheduling_module;
1796 SCTP_TCB_UNLOCK(stcb);
1798 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1799 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1800 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1801 SCTP_INP_RLOCK(inp);
1802 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1803 SCTP_INP_RUNLOCK(inp);
1805 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1810 *optsize = sizeof(struct sctp_assoc_value);
1816 struct sctp_stream_value *av;
1818 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1819 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1821 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1822 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1823 &av->stream_value) < 0)) {
1824 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1827 *optsize = sizeof(struct sctp_stream_value);
1829 SCTP_TCB_UNLOCK(stcb);
1832 * Can't get stream value without
1835 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1840 case SCTP_GET_ADDR_LEN:
1842 struct sctp_assoc_value *av;
1844 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1847 if (av->assoc_value == AF_INET) {
1848 av->assoc_value = sizeof(struct sockaddr_in);
1853 if (av->assoc_value == AF_INET6) {
1854 av->assoc_value = sizeof(struct sockaddr_in6);
1859 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1861 *optsize = sizeof(struct sctp_assoc_value);
1865 case SCTP_GET_ASSOC_NUMBER:
1867 uint32_t *value, cnt;
1869 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1870 SCTP_INP_RLOCK(inp);
1871 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1872 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1873 /* Can't do this for a 1-1 socket */
1875 SCTP_INP_RUNLOCK(inp);
1879 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1882 SCTP_INP_RUNLOCK(inp);
1884 *optsize = sizeof(uint32_t);
1887 case SCTP_GET_ASSOC_ID_LIST:
1889 struct sctp_assoc_ids *ids;
1893 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1894 SCTP_INP_RLOCK(inp);
1895 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1896 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1897 /* Can't do this for a 1-1 socket */
1899 SCTP_INP_RUNLOCK(inp);
1903 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1904 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1906 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1909 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1914 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1918 SCTP_INP_RUNLOCK(inp);
1920 ids->gaids_number_of_ids = at;
1921 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1927 struct sctp_assoc_value *av;
1929 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1930 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1933 av->assoc_value = stcb->asoc.context;
1934 SCTP_TCB_UNLOCK(stcb);
1936 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1937 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1938 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1939 SCTP_INP_RLOCK(inp);
1940 av->assoc_value = inp->sctp_context;
1941 SCTP_INP_RUNLOCK(inp);
1943 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1948 *optsize = sizeof(struct sctp_assoc_value);
1954 uint32_t *default_vrfid;
1956 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1957 *default_vrfid = inp->def_vrf_id;
1958 *optsize = sizeof(uint32_t);
1961 case SCTP_GET_ASOC_VRF:
1963 struct sctp_assoc_value *id;
1965 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1966 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1969 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1971 id->assoc_value = stcb->asoc.vrf_id;
1972 *optsize = sizeof(struct sctp_assoc_value);
1976 case SCTP_GET_VRF_IDS:
1978 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1982 case SCTP_GET_NONCE_VALUES:
1984 struct sctp_get_nonce_values *gnv;
1986 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1987 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1990 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1991 gnv->gn_local_tag = stcb->asoc.my_vtag;
1992 SCTP_TCB_UNLOCK(stcb);
1993 *optsize = sizeof(struct sctp_get_nonce_values);
1995 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2000 case SCTP_DELAYED_SACK:
2002 struct sctp_sack_info *sack;
2004 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2005 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2007 sack->sack_delay = stcb->asoc.delayed_ack;
2008 sack->sack_freq = stcb->asoc.sack_freq;
2009 SCTP_TCB_UNLOCK(stcb);
2011 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2012 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2013 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2014 SCTP_INP_RLOCK(inp);
2015 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2016 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2017 SCTP_INP_RUNLOCK(inp);
2019 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2024 *optsize = sizeof(struct sctp_sack_info);
2028 case SCTP_GET_SNDBUF_USE:
2030 struct sctp_sockstat *ss;
2032 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2033 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2036 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2037 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2038 stcb->asoc.size_on_all_streams);
2039 SCTP_TCB_UNLOCK(stcb);
2040 *optsize = sizeof(struct sctp_sockstat);
2042 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2047 case SCTP_MAX_BURST:
2049 struct sctp_assoc_value *av;
2051 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2052 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2055 av->assoc_value = stcb->asoc.max_burst;
2056 SCTP_TCB_UNLOCK(stcb);
2058 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2059 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2060 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2061 SCTP_INP_RLOCK(inp);
2062 av->assoc_value = inp->sctp_ep.max_burst;
2063 SCTP_INP_RUNLOCK(inp);
2065 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2070 *optsize = sizeof(struct sctp_assoc_value);
2076 struct sctp_assoc_value *av;
2079 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2080 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2083 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2084 SCTP_TCB_UNLOCK(stcb);
2086 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2087 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2088 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2089 SCTP_INP_RLOCK(inp);
2090 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2091 ovh = SCTP_MED_OVERHEAD;
2093 ovh = SCTP_MED_V4_OVERHEAD;
2095 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2096 av->assoc_value = 0;
2098 av->assoc_value = inp->sctp_frag_point - ovh;
2099 SCTP_INP_RUNLOCK(inp);
2101 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2106 *optsize = sizeof(struct sctp_assoc_value);
2110 case SCTP_GET_STAT_LOG:
2111 error = sctp_fill_stat_log(optval, optsize);
2115 struct sctp_event_subscribe *events;
2117 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2118 memset(events, 0, sizeof(struct sctp_event_subscribe));
2119 SCTP_INP_RLOCK(inp);
2120 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2121 events->sctp_data_io_event = 1;
2123 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2124 events->sctp_association_event = 1;
2126 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2127 events->sctp_address_event = 1;
2129 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2130 events->sctp_send_failure_event = 1;
2132 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2133 events->sctp_peer_error_event = 1;
2135 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2136 events->sctp_shutdown_event = 1;
2138 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2139 events->sctp_partial_delivery_event = 1;
2141 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2142 events->sctp_adaptation_layer_event = 1;
2144 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2145 events->sctp_authentication_event = 1;
2147 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2148 events->sctp_sender_dry_event = 1;
2150 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2151 events->sctp_stream_reset_event = 1;
2152 SCTP_INP_RUNLOCK(inp);
2153 *optsize = sizeof(struct sctp_event_subscribe);
2156 case SCTP_ADAPTATION_LAYER:
2160 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2162 SCTP_INP_RLOCK(inp);
2163 *value = inp->sctp_ep.adaptation_layer_indicator;
2164 SCTP_INP_RUNLOCK(inp);
2165 *optsize = sizeof(uint32_t);
2168 case SCTP_SET_INITIAL_DBG_SEQ:
2172 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2173 SCTP_INP_RLOCK(inp);
2174 *value = inp->sctp_ep.initial_sequence_debug;
2175 SCTP_INP_RUNLOCK(inp);
2176 *optsize = sizeof(uint32_t);
2179 case SCTP_GET_LOCAL_ADDR_SIZE:
2183 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2184 SCTP_INP_RLOCK(inp);
2185 *value = sctp_count_max_addresses(inp);
2186 SCTP_INP_RUNLOCK(inp);
2187 *optsize = sizeof(uint32_t);
2190 case SCTP_GET_REMOTE_ADDR_SIZE:
2194 struct sctp_nets *net;
2196 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2197 /* FIXME MT: change to sctp_assoc_value? */
2198 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2202 /* Count the sizes */
2203 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2204 switch (net->ro._l_addr.sa.sa_family) {
2208 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2209 size += sizeof(struct sockaddr_in6);
2211 size += sizeof(struct sockaddr_in);
2214 size += sizeof(struct sockaddr_in);
2220 size += sizeof(struct sockaddr_in6);
2227 SCTP_TCB_UNLOCK(stcb);
2228 *value = (uint32_t) size;
2229 *optsize = sizeof(uint32_t);
2231 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2236 case SCTP_GET_PEER_ADDRESSES:
2238 * Get the address information, an array is passed in to
2239 * fill up we pack it.
2243 struct sockaddr_storage *sas;
2244 struct sctp_nets *net;
2245 struct sctp_getaddresses *saddr;
2247 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2248 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2251 left = (*optsize) - sizeof(struct sctp_getaddresses);
2252 *optsize = sizeof(struct sctp_getaddresses);
2253 sas = (struct sockaddr_storage *)&saddr->addr[0];
2255 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2256 switch (net->ro._l_addr.sa.sa_family) {
2260 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2261 cpsz = sizeof(struct sockaddr_in6);
2263 cpsz = sizeof(struct sockaddr_in);
2266 cpsz = sizeof(struct sockaddr_in);
2272 cpsz = sizeof(struct sockaddr_in6);
2283 /* not enough room. */
2286 #if defined(INET) && defined(INET6)
2287 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2288 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2289 /* Must map the address */
2290 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2291 (struct sockaddr_in6 *)sas);
2293 memcpy(sas, &net->ro._l_addr, cpsz);
2296 memcpy(sas, &net->ro._l_addr, cpsz);
2298 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2300 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2304 SCTP_TCB_UNLOCK(stcb);
2306 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2311 case SCTP_GET_LOCAL_ADDRESSES:
2313 size_t limit, actual;
2314 struct sockaddr_storage *sas;
2315 struct sctp_getaddresses *saddr;
2317 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2318 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2320 sas = (struct sockaddr_storage *)&saddr->addr[0];
2321 limit = *optsize - sizeof(sctp_assoc_t);
2322 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2324 SCTP_TCB_UNLOCK(stcb);
2326 *optsize = sizeof(struct sockaddr_storage) + actual;
2329 case SCTP_PEER_ADDR_PARAMS:
2331 struct sctp_paddrparams *paddrp;
2332 struct sctp_nets *net;
2333 struct sockaddr *addr;
2335 #if defined(INET) && defined(INET6)
2336 struct sockaddr_in sin_store;
2340 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2341 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2343 #if defined(INET) && defined(INET6)
2344 if (paddrp->spp_address.ss_family == AF_INET6) {
2345 struct sockaddr_in6 *sin6;
2347 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2348 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2349 in6_sin6_2_sin(&sin_store, sin6);
2350 addr = (struct sockaddr *)&sin_store;
2352 addr = (struct sockaddr *)&paddrp->spp_address;
2355 addr = (struct sockaddr *)&paddrp->spp_address;
2358 addr = (struct sockaddr *)&paddrp->spp_address;
2361 net = sctp_findnet(stcb, addr);
2364 * We increment here since
2365 * sctp_findassociation_ep_addr() wil do a
2366 * decrement if it finds the stcb as long as
2367 * the locked tcb (last argument) is NOT a
2371 SCTP_INP_INCR_REF(inp);
2372 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2374 SCTP_INP_DECR_REF(inp);
2377 if ((stcb != NULL) && (net == NULL)) {
2379 if (addr->sa_family == AF_INET) {
2380 struct sockaddr_in *sin;
2382 sin = (struct sockaddr_in *)addr;
2383 if (sin->sin_addr.s_addr != INADDR_ANY) {
2385 SCTP_TCB_UNLOCK(stcb);
2386 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2392 if (addr->sa_family == AF_INET6) {
2393 struct sockaddr_in6 *sin6;
2395 sin6 = (struct sockaddr_in6 *)addr;
2396 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2398 SCTP_TCB_UNLOCK(stcb);
2399 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2405 error = EAFNOSUPPORT;
2406 SCTP_TCB_UNLOCK(stcb);
2407 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2412 /* Applies to the specific association */
2413 paddrp->spp_flags = 0;
2415 paddrp->spp_hbinterval = net->heart_beat_delay;
2416 paddrp->spp_pathmaxrxt = net->failure_threshold;
2417 paddrp->spp_pathmtu = net->mtu;
2418 switch (net->ro._l_addr.sa.sa_family) {
2421 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2426 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2432 /* get flags for HB */
2433 if (net->dest_state & SCTP_ADDR_NOHB) {
2434 paddrp->spp_flags |= SPP_HB_DISABLE;
2436 paddrp->spp_flags |= SPP_HB_ENABLE;
2438 /* get flags for PMTU */
2439 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2440 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2442 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2444 if (net->dscp & 0x01) {
2445 paddrp->spp_dscp = net->dscp & 0xfc;
2446 paddrp->spp_flags |= SPP_DSCP;
2449 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2450 (net->flowlabel & 0x80000000)) {
2451 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2452 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2457 * No destination so return default
2460 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2461 paddrp->spp_pathmtu = 0;
2462 if (stcb->asoc.default_dscp & 0x01) {
2463 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2464 paddrp->spp_flags |= SPP_DSCP;
2467 if (stcb->asoc.default_flowlabel & 0x80000000) {
2468 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2469 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2472 /* default settings should be these */
2473 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2474 paddrp->spp_flags |= SPP_HB_DISABLE;
2476 paddrp->spp_flags |= SPP_HB_ENABLE;
2478 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2479 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2481 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2483 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2485 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2486 SCTP_TCB_UNLOCK(stcb);
2488 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2489 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2490 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2491 /* Use endpoint defaults */
2492 SCTP_INP_RLOCK(inp);
2493 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2494 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2495 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2496 /* get inp's default */
2497 if (inp->sctp_ep.default_dscp & 0x01) {
2498 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2499 paddrp->spp_flags |= SPP_DSCP;
2502 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2503 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2504 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2505 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2508 /* can't return this */
2509 paddrp->spp_pathmtu = 0;
2511 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2512 paddrp->spp_flags |= SPP_HB_ENABLE;
2514 paddrp->spp_flags |= SPP_HB_DISABLE;
2516 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2517 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2519 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2521 SCTP_INP_RUNLOCK(inp);
2523 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2528 *optsize = sizeof(struct sctp_paddrparams);
2532 case SCTP_GET_PEER_ADDR_INFO:
2534 struct sctp_paddrinfo *paddri;
2535 struct sctp_nets *net;
2536 struct sockaddr *addr;
2538 #if defined(INET) && defined(INET6)
2539 struct sockaddr_in sin_store;
2543 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2544 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2546 #if defined(INET) && defined(INET6)
2547 if (paddri->spinfo_address.ss_family == AF_INET6) {
2548 struct sockaddr_in6 *sin6;
2550 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2551 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2552 in6_sin6_2_sin(&sin_store, sin6);
2553 addr = (struct sockaddr *)&sin_store;
2555 addr = (struct sockaddr *)&paddri->spinfo_address;
2558 addr = (struct sockaddr *)&paddri->spinfo_address;
2561 addr = (struct sockaddr *)&paddri->spinfo_address;
2564 net = sctp_findnet(stcb, addr);
2567 * We increment here since
2568 * sctp_findassociation_ep_addr() wil do a
2569 * decrement if it finds the stcb as long as
2570 * the locked tcb (last argument) is NOT a
2574 SCTP_INP_INCR_REF(inp);
2575 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2577 SCTP_INP_DECR_REF(inp);
2581 if ((stcb != NULL) && (net != NULL)) {
2582 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2583 /* It's unconfirmed */
2584 paddri->spinfo_state = SCTP_UNCONFIRMED;
2585 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2587 paddri->spinfo_state = SCTP_ACTIVE;
2590 paddri->spinfo_state = SCTP_INACTIVE;
2592 paddri->spinfo_cwnd = net->cwnd;
2593 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2594 paddri->spinfo_rto = net->RTO;
2595 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2596 paddri->spinfo_mtu = net->mtu;
2597 switch (addr->sa_family) {
2600 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2605 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2611 SCTP_TCB_UNLOCK(stcb);
2612 *optsize = sizeof(struct sctp_paddrinfo);
2615 SCTP_TCB_UNLOCK(stcb);
2617 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2622 case SCTP_PCB_STATUS:
2624 struct sctp_pcbinfo *spcb;
2626 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2627 sctp_fill_pcbinfo(spcb);
2628 *optsize = sizeof(struct sctp_pcbinfo);
2633 struct sctp_nets *net;
2634 struct sctp_status *sstat;
2636 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2637 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2640 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2644 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2645 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2646 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2647 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2649 * We can't include chunks that have been passed to
2650 * the socket layer. Only things in queue.
2652 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2653 stcb->asoc.cnt_on_all_streams);
2656 sstat->sstat_instrms = stcb->asoc.streamincnt;
2657 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2658 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2659 memcpy(&sstat->sstat_primary.spinfo_address,
2660 &stcb->asoc.primary_destination->ro._l_addr,
2661 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2662 net = stcb->asoc.primary_destination;
2663 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2665 * Again the user can get info from sctp_constants.h
2666 * for what the state of the network is.
2668 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2669 /* It's unconfirmed */
2670 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2671 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2673 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2676 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2678 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2679 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2680 sstat->sstat_primary.spinfo_rto = net->RTO;
2681 sstat->sstat_primary.spinfo_mtu = net->mtu;
2682 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2685 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2690 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2696 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2697 SCTP_TCB_UNLOCK(stcb);
2698 *optsize = sizeof(struct sctp_status);
2703 struct sctp_rtoinfo *srto;
2705 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2706 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2709 srto->srto_initial = stcb->asoc.initial_rto;
2710 srto->srto_max = stcb->asoc.maxrto;
2711 srto->srto_min = stcb->asoc.minrto;
2712 SCTP_TCB_UNLOCK(stcb);
2714 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2715 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2716 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2717 SCTP_INP_RLOCK(inp);
2718 srto->srto_initial = inp->sctp_ep.initial_rto;
2719 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2720 srto->srto_min = inp->sctp_ep.sctp_minrto;
2721 SCTP_INP_RUNLOCK(inp);
2723 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2728 *optsize = sizeof(struct sctp_rtoinfo);
2734 struct sctp_timeouts *stimo;
2736 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2737 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2740 stimo->stimo_init = stcb->asoc.timoinit;
2741 stimo->stimo_data = stcb->asoc.timodata;
2742 stimo->stimo_sack = stcb->asoc.timosack;
2743 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2744 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2745 stimo->stimo_cookie = stcb->asoc.timocookie;
2746 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2747 SCTP_TCB_UNLOCK(stcb);
2748 *optsize = sizeof(struct sctp_timeouts);
2750 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2755 case SCTP_ASSOCINFO:
2757 struct sctp_assocparams *sasoc;
2759 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2760 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2763 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2764 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2765 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2766 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2767 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2768 SCTP_TCB_UNLOCK(stcb);
2770 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2771 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2772 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2773 SCTP_INP_RLOCK(inp);
2774 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2775 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2776 sasoc->sasoc_number_peer_destinations = 0;
2777 sasoc->sasoc_peer_rwnd = 0;
2778 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2779 SCTP_INP_RUNLOCK(inp);
2781 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2786 *optsize = sizeof(struct sctp_assocparams);
2790 case SCTP_DEFAULT_SEND_PARAM:
2792 struct sctp_sndrcvinfo *s_info;
2794 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2795 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2798 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2799 SCTP_TCB_UNLOCK(stcb);
2801 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2802 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2803 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2804 SCTP_INP_RLOCK(inp);
2805 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2806 SCTP_INP_RUNLOCK(inp);
2808 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2813 *optsize = sizeof(struct sctp_sndrcvinfo);
2819 struct sctp_initmsg *sinit;
2821 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2822 SCTP_INP_RLOCK(inp);
2823 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2824 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2825 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2826 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2827 SCTP_INP_RUNLOCK(inp);
2828 *optsize = sizeof(struct sctp_initmsg);
2831 case SCTP_PRIMARY_ADDR:
2832 /* we allow a "get" operation on this */
2834 struct sctp_setprim *ssp;
2836 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2837 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2840 union sctp_sockstore *addr;
2842 addr = &stcb->asoc.primary_destination->ro._l_addr;
2843 switch (addr->sa.sa_family) {
2847 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2848 in6_sin_2_v4mapsin6(&addr->sin,
2849 (struct sockaddr_in6 *)&ssp->ssp_addr);
2851 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2854 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2860 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2866 SCTP_TCB_UNLOCK(stcb);
2867 *optsize = sizeof(struct sctp_setprim);
2869 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2874 case SCTP_HMAC_IDENT:
2876 struct sctp_hmacalgo *shmac;
2877 sctp_hmaclist_t *hmaclist;
2881 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2883 SCTP_INP_RLOCK(inp);
2884 hmaclist = inp->sctp_ep.local_hmacs;
2885 if (hmaclist == NULL) {
2886 /* no HMACs to return */
2887 *optsize = sizeof(*shmac);
2888 SCTP_INP_RUNLOCK(inp);
2891 /* is there room for all of the hmac ids? */
2892 size = sizeof(*shmac) + (hmaclist->num_algo *
2893 sizeof(shmac->shmac_idents[0]));
2894 if ((size_t)(*optsize) < size) {
2895 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2897 SCTP_INP_RUNLOCK(inp);
2900 /* copy in the list */
2901 shmac->shmac_number_of_idents = hmaclist->num_algo;
2902 for (i = 0; i < hmaclist->num_algo; i++) {
2903 shmac->shmac_idents[i] = hmaclist->hmac[i];
2905 SCTP_INP_RUNLOCK(inp);
2909 case SCTP_AUTH_ACTIVE_KEY:
2911 struct sctp_authkeyid *scact;
2913 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2914 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2917 /* get the active key on the assoc */
2918 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2919 SCTP_TCB_UNLOCK(stcb);
2921 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2922 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2923 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2924 /* get the endpoint active key */
2925 SCTP_INP_RLOCK(inp);
2926 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2927 SCTP_INP_RUNLOCK(inp);
2929 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2934 *optsize = sizeof(struct sctp_authkeyid);
2938 case SCTP_LOCAL_AUTH_CHUNKS:
2940 struct sctp_authchunks *sac;
2941 sctp_auth_chklist_t *chklist = NULL;
2944 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2945 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2948 /* get off the assoc */
2949 chklist = stcb->asoc.local_auth_chunks;
2950 /* is there enough space? */
2951 size = sctp_auth_get_chklist_size(chklist);
2952 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2954 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2956 /* copy in the chunks */
2957 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2958 sac->gauth_number_of_chunks = (uint32_t) size;
2959 *optsize = sizeof(struct sctp_authchunks) + size;
2961 SCTP_TCB_UNLOCK(stcb);
2963 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2964 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2965 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2966 /* get off the endpoint */
2967 SCTP_INP_RLOCK(inp);
2968 chklist = inp->sctp_ep.local_auth_chunks;
2969 /* is there enough space? */
2970 size = sctp_auth_get_chklist_size(chklist);
2971 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2973 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2975 /* copy in the chunks */
2976 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2977 sac->gauth_number_of_chunks = (uint32_t) size;
2978 *optsize = sizeof(struct sctp_authchunks) + size;
2980 SCTP_INP_RUNLOCK(inp);
2982 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2988 case SCTP_PEER_AUTH_CHUNKS:
2990 struct sctp_authchunks *sac;
2991 sctp_auth_chklist_t *chklist = NULL;
2994 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2995 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2998 /* get off the assoc */
2999 chklist = stcb->asoc.peer_auth_chunks;
3000 /* is there enough space? */
3001 size = sctp_auth_get_chklist_size(chklist);
3002 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
3004 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3006 /* copy in the chunks */
3007 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
3008 sac->gauth_number_of_chunks = (uint32_t) size;
3009 *optsize = sizeof(struct sctp_authchunks) + size;
3011 SCTP_TCB_UNLOCK(stcb);
3013 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3020 struct sctp_event *event;
3021 uint32_t event_type;
3023 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3024 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3026 switch (event->se_type) {
3027 case SCTP_ASSOC_CHANGE:
3028 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3030 case SCTP_PEER_ADDR_CHANGE:
3031 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3033 case SCTP_REMOTE_ERROR:
3034 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3036 case SCTP_SEND_FAILED:
3037 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3039 case SCTP_SHUTDOWN_EVENT:
3040 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3042 case SCTP_ADAPTATION_INDICATION:
3043 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3045 case SCTP_PARTIAL_DELIVERY_EVENT:
3046 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3048 case SCTP_AUTHENTICATION_EVENT:
3049 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3051 case SCTP_STREAM_RESET_EVENT:
3052 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3054 case SCTP_SENDER_DRY_EVENT:
3055 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3057 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3059 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3062 case SCTP_ASSOC_RESET_EVENT:
3063 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3065 case SCTP_STREAM_CHANGE_EVENT:
3066 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3068 case SCTP_SEND_FAILED_EVENT:
3069 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3073 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3077 if (event_type > 0) {
3079 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3080 SCTP_TCB_UNLOCK(stcb);
3082 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3083 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3084 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3085 SCTP_INP_RLOCK(inp);
3086 event->se_on = sctp_is_feature_on(inp, event_type);
3087 SCTP_INP_RUNLOCK(inp);
3089 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3095 *optsize = sizeof(struct sctp_event);
3099 case SCTP_RECVRCVINFO:
3103 if (*optsize < sizeof(int)) {
3104 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3107 SCTP_INP_RLOCK(inp);
3108 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3109 SCTP_INP_RUNLOCK(inp);
3112 /* return the option value */
3113 *(int *)optval = onoff;
3114 *optsize = sizeof(int);
3118 case SCTP_RECVNXTINFO:
3122 if (*optsize < sizeof(int)) {
3123 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3126 SCTP_INP_RLOCK(inp);
3127 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3128 SCTP_INP_RUNLOCK(inp);
3131 /* return the option value */
3132 *(int *)optval = onoff;
3133 *optsize = sizeof(int);
3137 case SCTP_DEFAULT_SNDINFO:
3139 struct sctp_sndinfo *info;
3141 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3142 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3145 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3146 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3147 info->snd_flags &= 0xfff0;
3148 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3149 info->snd_context = stcb->asoc.def_send.sinfo_context;
3150 SCTP_TCB_UNLOCK(stcb);
3152 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3153 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3154 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3155 SCTP_INP_RLOCK(inp);
3156 info->snd_sid = inp->def_send.sinfo_stream;
3157 info->snd_flags = inp->def_send.sinfo_flags;
3158 info->snd_flags &= 0xfff0;
3159 info->snd_ppid = inp->def_send.sinfo_ppid;
3160 info->snd_context = inp->def_send.sinfo_context;
3161 SCTP_INP_RUNLOCK(inp);
3163 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3168 *optsize = sizeof(struct sctp_sndinfo);
3172 case SCTP_DEFAULT_PRINFO:
3174 struct sctp_default_prinfo *info;
3176 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3177 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3180 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3181 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3182 SCTP_TCB_UNLOCK(stcb);
3184 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3185 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3186 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3187 SCTP_INP_RLOCK(inp);
3188 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3189 info->pr_value = inp->def_send.sinfo_timetolive;
3190 SCTP_INP_RUNLOCK(inp);
3192 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3197 *optsize = sizeof(struct sctp_default_prinfo);
3201 case SCTP_PEER_ADDR_THLDS:
3203 struct sctp_paddrthlds *thlds;
3204 struct sctp_nets *net;
3205 struct sockaddr *addr;
3207 #if defined(INET) && defined(INET6)
3208 struct sockaddr_in sin_store;
3212 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3213 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3215 #if defined(INET) && defined(INET6)
3216 if (thlds->spt_address.ss_family == AF_INET6) {
3217 struct sockaddr_in6 *sin6;
3219 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3220 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3221 in6_sin6_2_sin(&sin_store, sin6);
3222 addr = (struct sockaddr *)&sin_store;
3224 addr = (struct sockaddr *)&thlds->spt_address;
3227 addr = (struct sockaddr *)&thlds->spt_address;
3230 addr = (struct sockaddr *)&thlds->spt_address;
3233 net = sctp_findnet(stcb, addr);
3236 * We increment here since
3237 * sctp_findassociation_ep_addr() wil do a
3238 * decrement if it finds the stcb as long as
3239 * the locked tcb (last argument) is NOT a
3243 SCTP_INP_INCR_REF(inp);
3244 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3246 SCTP_INP_DECR_REF(inp);
3249 if ((stcb != NULL) && (net == NULL)) {
3251 if (addr->sa_family == AF_INET) {
3252 struct sockaddr_in *sin;
3254 sin = (struct sockaddr_in *)addr;
3255 if (sin->sin_addr.s_addr != INADDR_ANY) {
3257 SCTP_TCB_UNLOCK(stcb);
3258 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3264 if (addr->sa_family == AF_INET6) {
3265 struct sockaddr_in6 *sin6;
3267 sin6 = (struct sockaddr_in6 *)addr;
3268 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3270 SCTP_TCB_UNLOCK(stcb);
3271 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3277 error = EAFNOSUPPORT;
3278 SCTP_TCB_UNLOCK(stcb);
3279 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3285 thlds->spt_pathmaxrxt = net->failure_threshold;
3286 thlds->spt_pathpfthld = net->pf_threshold;
3287 thlds->spt_pathcpthld = 0xffff;
3289 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3290 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3291 thlds->spt_pathcpthld = 0xffff;
3293 thlds->spt_assoc_id = sctp_get_associd(stcb);
3294 SCTP_TCB_UNLOCK(stcb);
3296 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3297 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3298 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3299 /* Use endpoint defaults */
3300 SCTP_INP_RLOCK(inp);
3301 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3302 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3303 thlds->spt_pathcpthld = 0xffff;
3304 SCTP_INP_RUNLOCK(inp);
3306 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3311 *optsize = sizeof(struct sctp_paddrthlds);
3315 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3317 struct sctp_udpencaps *encaps;
3318 struct sctp_nets *net;
3319 struct sockaddr *addr;
3321 #if defined(INET) && defined(INET6)
3322 struct sockaddr_in sin_store;
3326 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3327 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3329 #if defined(INET) && defined(INET6)
3330 if (encaps->sue_address.ss_family == AF_INET6) {
3331 struct sockaddr_in6 *sin6;
3333 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3334 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3335 in6_sin6_2_sin(&sin_store, sin6);
3336 addr = (struct sockaddr *)&sin_store;
3338 addr = (struct sockaddr *)&encaps->sue_address;
3341 addr = (struct sockaddr *)&encaps->sue_address;
3344 addr = (struct sockaddr *)&encaps->sue_address;
3347 net = sctp_findnet(stcb, addr);
3350 * We increment here since
3351 * sctp_findassociation_ep_addr() wil do a
3352 * decrement if it finds the stcb as long as
3353 * the locked tcb (last argument) is NOT a
3357 SCTP_INP_INCR_REF(inp);
3358 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3360 SCTP_INP_DECR_REF(inp);
3363 if ((stcb != NULL) && (net == NULL)) {
3365 if (addr->sa_family == AF_INET) {
3366 struct sockaddr_in *sin;
3368 sin = (struct sockaddr_in *)addr;
3369 if (sin->sin_addr.s_addr != INADDR_ANY) {
3371 SCTP_TCB_UNLOCK(stcb);
3372 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3378 if (addr->sa_family == AF_INET6) {
3379 struct sockaddr_in6 *sin6;
3381 sin6 = (struct sockaddr_in6 *)addr;
3382 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3384 SCTP_TCB_UNLOCK(stcb);
3385 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3391 error = EAFNOSUPPORT;
3392 SCTP_TCB_UNLOCK(stcb);
3393 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3399 encaps->sue_port = net->port;
3401 encaps->sue_port = stcb->asoc.port;
3403 SCTP_TCB_UNLOCK(stcb);
3405 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3406 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3407 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3408 SCTP_INP_RLOCK(inp);
3409 encaps->sue_port = inp->sctp_ep.port;
3410 SCTP_INP_RUNLOCK(inp);
3412 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3417 *optsize = sizeof(struct sctp_udpencaps);
3421 case SCTP_ECN_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.ecn_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->ecn_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_PR_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.prsctp_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->prsctp_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_AUTH_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.auth_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->auth_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_ASCONF_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.asconf_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->asconf_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_RECONFIG_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.reconfig_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->reconfig_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_NRSACK_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.nrsack_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->nrsack_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_PKTDROP_SUPPORTED:
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 = stcb->asoc.pktdrop_supported;
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 = inp->pktdrop_supported;
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_ENABLE_STREAM_RESET:
3612 struct sctp_assoc_value *av;
3614 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3615 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3618 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3619 SCTP_TCB_UNLOCK(stcb);
3621 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3622 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3623 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3624 SCTP_INP_RLOCK(inp);
3625 av->assoc_value = (uint32_t) inp->local_strreset_support;
3626 SCTP_INP_RUNLOCK(inp);
3628 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3633 *optsize = sizeof(struct sctp_assoc_value);
3637 case SCTP_PR_STREAM_STATUS:
3639 struct sctp_prstatus *sprstat;
3643 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3644 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3646 sid = sprstat->sprstat_sid;
3647 policy = sprstat->sprstat_policy;
3648 #if defined(SCTP_DETAILED_STR_STATS)
3649 if ((stcb != NULL) &&
3650 (sid < stcb->asoc.streamoutcnt) &&
3651 (policy != SCTP_PR_SCTP_NONE) &&
3652 ((policy <= SCTP_PR_SCTP_MAX) ||
3653 (policy == SCTP_PR_SCTP_ALL))) {
3654 if (policy == SCTP_PR_SCTP_ALL) {
3655 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3656 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3658 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3659 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3662 if ((stcb != NULL) &&
3663 (sid < stcb->asoc.streamoutcnt) &&
3664 (policy == SCTP_PR_SCTP_ALL)) {
3665 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3666 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3668 SCTP_TCB_UNLOCK(stcb);
3669 *optsize = sizeof(struct sctp_prstatus);
3671 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3676 case SCTP_PR_ASSOC_STATUS:
3678 struct sctp_prstatus *sprstat;
3681 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3682 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3684 policy = sprstat->sprstat_policy;
3685 if ((stcb != NULL) &&
3686 (policy != SCTP_PR_SCTP_NONE) &&
3687 ((policy <= SCTP_PR_SCTP_MAX) ||
3688 (policy == SCTP_PR_SCTP_ALL))) {
3689 if (policy == SCTP_PR_SCTP_ALL) {
3690 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3691 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3693 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3694 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3696 SCTP_TCB_UNLOCK(stcb);
3697 *optsize = sizeof(struct sctp_prstatus);
3699 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3706 struct sctp_assoc_value *av;
3708 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3709 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3712 av->assoc_value = stcb->asoc.max_cwnd;
3713 SCTP_TCB_UNLOCK(stcb);
3715 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3716 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3717 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3718 SCTP_INP_RLOCK(inp);
3719 av->assoc_value = inp->max_cwnd;
3720 SCTP_INP_RUNLOCK(inp);
3722 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3727 *optsize = sizeof(struct sctp_assoc_value);
3732 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3733 error = ENOPROTOOPT;
3735 } /* end switch (sopt->sopt_name) */
3743 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3748 struct sctp_tcb *stcb = NULL;
3749 struct sctp_inpcb *inp = NULL;
3752 if (optval == NULL) {
3753 SCTP_PRINTF("optval is NULL\n");
3754 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3757 inp = (struct sctp_inpcb *)so->so_pcb;
3759 SCTP_PRINTF("inp is NULL?\n");
3760 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3763 vrf_id = inp->def_vrf_id;
3768 case SCTP_AUTOCLOSE:
3769 case SCTP_AUTO_ASCONF:
3770 case SCTP_EXPLICIT_EOR:
3771 case SCTP_DISABLE_FRAGMENTS:
3772 case SCTP_USE_EXT_RCVINFO:
3773 case SCTP_I_WANT_MAPPED_V4_ADDR:
3774 /* copy in the option value */
3775 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3780 case SCTP_DISABLE_FRAGMENTS:
3781 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3783 case SCTP_AUTO_ASCONF:
3785 * NOTE: we don't really support this flag
3787 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3788 /* only valid for bound all sockets */
3789 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3791 /* forbidden by admin */
3792 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3795 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3797 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3801 case SCTP_EXPLICIT_EOR:
3802 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3804 case SCTP_USE_EXT_RCVINFO:
3805 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3807 case SCTP_I_WANT_MAPPED_V4_ADDR:
3808 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3809 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3811 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3816 set_opt = SCTP_PCB_FLAGS_NODELAY;
3818 case SCTP_AUTOCLOSE:
3819 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3820 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3821 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3824 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3826 * The value is in ticks. Note this does not effect
3827 * old associations, only new ones.
3829 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3832 SCTP_INP_WLOCK(inp);
3834 sctp_feature_on(inp, set_opt);
3836 sctp_feature_off(inp, set_opt);
3838 SCTP_INP_WUNLOCK(inp);
3840 case SCTP_REUSE_PORT:
3842 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3843 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3844 /* Can't set it after we are bound */
3848 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3849 /* Can't do this for a 1-m socket */
3854 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3856 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3859 case SCTP_PARTIAL_DELIVERY_POINT:
3863 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3864 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3865 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3869 inp->partial_delivery_point = *value;
3872 case SCTP_FRAGMENT_INTERLEAVE:
3873 /* not yet until we re-write sctp_recvmsg() */
3877 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3878 if (*level == SCTP_FRAG_LEVEL_2) {
3879 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3880 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3881 } else if (*level == SCTP_FRAG_LEVEL_1) {
3882 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3883 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3884 } else if (*level == SCTP_FRAG_LEVEL_0) {
3885 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3886 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3889 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3894 case SCTP_INTERLEAVING_SUPPORTED:
3896 struct sctp_assoc_value *av;
3898 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3899 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3902 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3904 SCTP_TCB_UNLOCK(stcb);
3906 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3907 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3908 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3909 SCTP_INP_WLOCK(inp);
3910 if (av->assoc_value == 0) {
3911 inp->idata_supported = 0;
3913 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3914 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3915 inp->idata_supported = 1;
3923 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3927 SCTP_INP_WUNLOCK(inp);
3929 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3935 case SCTP_CMT_ON_OFF:
3936 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3937 struct sctp_assoc_value *av;
3939 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3940 if (av->assoc_value > SCTP_CMT_MAX) {
3941 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3945 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3947 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3948 SCTP_TCB_UNLOCK(stcb);
3950 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3951 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3952 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3953 (av->assoc_id == SCTP_ALL_ASSOC)) {
3954 SCTP_INP_WLOCK(inp);
3955 inp->sctp_cmt_on_off = av->assoc_value;
3956 SCTP_INP_WUNLOCK(inp);
3958 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3959 (av->assoc_id == SCTP_ALL_ASSOC)) {
3960 SCTP_INP_RLOCK(inp);
3961 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3962 SCTP_TCB_LOCK(stcb);
3963 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3964 SCTP_TCB_UNLOCK(stcb);
3966 SCTP_INP_RUNLOCK(inp);
3970 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3971 error = ENOPROTOOPT;
3974 case SCTP_PLUGGABLE_CC:
3976 struct sctp_assoc_value *av;
3977 struct sctp_nets *net;
3979 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3980 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3981 (av->assoc_value != SCTP_CC_HSTCP) &&
3982 (av->assoc_value != SCTP_CC_HTCP) &&
3983 (av->assoc_value != SCTP_CC_RTCC)) {
3984 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3988 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3990 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3991 stcb->asoc.congestion_control_module = av->assoc_value;
3992 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3993 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3994 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3997 SCTP_TCB_UNLOCK(stcb);
3999 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4000 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4001 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4002 (av->assoc_id == SCTP_ALL_ASSOC)) {
4003 SCTP_INP_WLOCK(inp);
4004 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
4005 SCTP_INP_WUNLOCK(inp);
4007 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4008 (av->assoc_id == SCTP_ALL_ASSOC)) {
4009 SCTP_INP_RLOCK(inp);
4010 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4011 SCTP_TCB_LOCK(stcb);
4012 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4013 stcb->asoc.congestion_control_module = av->assoc_value;
4014 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4015 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4016 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4019 SCTP_TCB_UNLOCK(stcb);
4021 SCTP_INP_RUNLOCK(inp);
4026 case SCTP_CC_OPTION:
4028 struct sctp_cc_option *cc_opt;
4030 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4031 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4033 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
4034 SCTP_INP_RLOCK(inp);
4035 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4036 SCTP_TCB_LOCK(stcb);
4037 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4038 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4040 SCTP_TCB_UNLOCK(stcb);
4042 SCTP_INP_RUNLOCK(inp);
4047 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4050 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4053 SCTP_TCB_UNLOCK(stcb);
4057 case SCTP_PLUGGABLE_SS:
4059 struct sctp_assoc_value *av;
4061 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4062 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4063 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4064 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4065 (av->assoc_value != SCTP_SS_PRIORITY) &&
4066 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4067 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4068 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4072 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4074 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4075 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4076 stcb->asoc.stream_scheduling_module = av->assoc_value;
4077 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4078 SCTP_TCB_UNLOCK(stcb);
4080 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4081 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4082 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4083 (av->assoc_id == SCTP_ALL_ASSOC)) {
4084 SCTP_INP_WLOCK(inp);
4085 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4086 SCTP_INP_WUNLOCK(inp);
4088 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4089 (av->assoc_id == SCTP_ALL_ASSOC)) {
4090 SCTP_INP_RLOCK(inp);
4091 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4092 SCTP_TCB_LOCK(stcb);
4093 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4094 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4095 stcb->asoc.stream_scheduling_module = av->assoc_value;
4096 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4097 SCTP_TCB_UNLOCK(stcb);
4099 SCTP_INP_RUNLOCK(inp);
4106 struct sctp_stream_value *av;
4108 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4109 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4111 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4112 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4113 av->stream_value) < 0)) {
4114 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4117 SCTP_TCB_UNLOCK(stcb);
4119 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4120 SCTP_INP_RLOCK(inp);
4121 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4122 SCTP_TCB_LOCK(stcb);
4123 if (av->stream_id < stcb->asoc.streamoutcnt) {
4124 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4126 &stcb->asoc.strmout[av->stream_id],
4129 SCTP_TCB_UNLOCK(stcb);
4131 SCTP_INP_RUNLOCK(inp);
4134 * Can't set stream value without
4137 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4143 case SCTP_CLR_STAT_LOG:
4144 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4149 struct sctp_assoc_value *av;
4151 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4152 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4155 stcb->asoc.context = av->assoc_value;
4156 SCTP_TCB_UNLOCK(stcb);
4158 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4159 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4160 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4161 (av->assoc_id == SCTP_ALL_ASSOC)) {
4162 SCTP_INP_WLOCK(inp);
4163 inp->sctp_context = av->assoc_value;
4164 SCTP_INP_WUNLOCK(inp);
4166 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4167 (av->assoc_id == SCTP_ALL_ASSOC)) {
4168 SCTP_INP_RLOCK(inp);
4169 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4170 SCTP_TCB_LOCK(stcb);
4171 stcb->asoc.context = av->assoc_value;
4172 SCTP_TCB_UNLOCK(stcb);
4174 SCTP_INP_RUNLOCK(inp);
4181 uint32_t *default_vrfid;
4183 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4184 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4185 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4189 inp->def_vrf_id = *default_vrfid;
4192 case SCTP_DEL_VRF_ID:
4194 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4198 case SCTP_ADD_VRF_ID:
4200 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4204 case SCTP_DELAYED_SACK:
4206 struct sctp_sack_info *sack;
4208 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4209 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4210 if (sack->sack_delay) {
4211 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4212 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4213 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4214 sack->sack_delay = TICKS_TO_MSEC(1);
4218 if (sack->sack_delay) {
4219 stcb->asoc.delayed_ack = sack->sack_delay;
4221 if (sack->sack_freq) {
4222 stcb->asoc.sack_freq = sack->sack_freq;
4224 SCTP_TCB_UNLOCK(stcb);
4226 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4227 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4228 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4229 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4230 SCTP_INP_WLOCK(inp);
4231 if (sack->sack_delay) {
4232 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4234 if (sack->sack_freq) {
4235 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4237 SCTP_INP_WUNLOCK(inp);
4239 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4240 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4241 SCTP_INP_RLOCK(inp);
4242 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4243 SCTP_TCB_LOCK(stcb);
4244 if (sack->sack_delay) {
4245 stcb->asoc.delayed_ack = sack->sack_delay;
4247 if (sack->sack_freq) {
4248 stcb->asoc.sack_freq = sack->sack_freq;
4250 SCTP_TCB_UNLOCK(stcb);
4252 SCTP_INP_RUNLOCK(inp);
4257 case SCTP_AUTH_CHUNK:
4259 struct sctp_authchunk *sauth;
4261 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4263 SCTP_INP_WLOCK(inp);
4264 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4265 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4268 SCTP_INP_WUNLOCK(inp);
4273 struct sctp_authkey *sca;
4274 struct sctp_keyhead *shared_keys;
4275 sctp_sharedkey_t *shared_key;
4276 sctp_key_t *key = NULL;
4279 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4280 if (sca->sca_keylength == 0) {
4281 size = optsize - sizeof(struct sctp_authkey);
4283 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4284 size = sca->sca_keylength;
4286 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4291 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4294 shared_keys = &stcb->asoc.shared_keys;
4295 /* clear the cached keys for this key id */
4296 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4298 * create the new shared key and
4302 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4304 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4306 SCTP_TCB_UNLOCK(stcb);
4310 shared_key = sctp_alloc_sharedkey();
4311 if (shared_key == NULL) {
4313 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4315 SCTP_TCB_UNLOCK(stcb);
4318 shared_key->key = key;
4319 shared_key->keyid = sca->sca_keynumber;
4320 error = sctp_insert_sharedkey(shared_keys, shared_key);
4321 SCTP_TCB_UNLOCK(stcb);
4323 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4324 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4325 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4326 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4327 SCTP_INP_WLOCK(inp);
4328 shared_keys = &inp->sctp_ep.shared_keys;
4330 * clear the cached keys on all
4331 * assocs for this key id
4333 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4335 * create the new shared key and
4339 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4341 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4343 SCTP_INP_WUNLOCK(inp);
4347 shared_key = sctp_alloc_sharedkey();
4348 if (shared_key == NULL) {
4350 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4352 SCTP_INP_WUNLOCK(inp);
4355 shared_key->key = key;
4356 shared_key->keyid = sca->sca_keynumber;
4357 error = sctp_insert_sharedkey(shared_keys, shared_key);
4358 SCTP_INP_WUNLOCK(inp);
4360 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4361 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4362 SCTP_INP_RLOCK(inp);
4363 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4364 SCTP_TCB_LOCK(stcb);
4365 shared_keys = &stcb->asoc.shared_keys;
4367 * clear the cached keys for
4370 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4372 * create the new shared key
4373 * and insert/replace it
4376 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4378 SCTP_TCB_UNLOCK(stcb);
4382 shared_key = sctp_alloc_sharedkey();
4383 if (shared_key == NULL) {
4385 SCTP_TCB_UNLOCK(stcb);
4388 shared_key->key = key;
4389 shared_key->keyid = sca->sca_keynumber;
4390 error = sctp_insert_sharedkey(shared_keys, shared_key);
4391 SCTP_TCB_UNLOCK(stcb);
4393 SCTP_INP_RUNLOCK(inp);
4398 case SCTP_HMAC_IDENT:
4400 struct sctp_hmacalgo *shmac;
4401 sctp_hmaclist_t *hmaclist;
4405 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4406 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4407 (shmac->shmac_number_of_idents > 0xffff)) {
4408 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4412 hmaclist = sctp_alloc_hmaclist((uint16_t) shmac->shmac_number_of_idents);
4413 if (hmaclist == NULL) {
4414 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4418 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4419 hmacid = shmac->shmac_idents[i];
4420 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4421 /* invalid HMACs were found */ ;
4422 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4424 sctp_free_hmaclist(hmaclist);
4425 goto sctp_set_hmac_done;
4428 for (i = 0; i < hmaclist->num_algo; i++) {
4429 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4430 /* already in list */
4434 if (i == hmaclist->num_algo) {
4435 /* not found in list */
4436 sctp_free_hmaclist(hmaclist);
4437 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4441 /* set it on the endpoint */
4442 SCTP_INP_WLOCK(inp);
4443 if (inp->sctp_ep.local_hmacs)
4444 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4445 inp->sctp_ep.local_hmacs = hmaclist;
4446 SCTP_INP_WUNLOCK(inp);
4450 case SCTP_AUTH_ACTIVE_KEY:
4452 struct sctp_authkeyid *scact;
4454 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4455 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4457 /* set the active key on the right place */
4459 /* set the active key on the assoc */
4460 if (sctp_auth_setactivekey(stcb,
4461 scact->scact_keynumber)) {
4462 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4463 SCTP_FROM_SCTP_USRREQ,
4467 SCTP_TCB_UNLOCK(stcb);
4469 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4470 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4471 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4472 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4473 SCTP_INP_WLOCK(inp);
4474 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4475 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4478 SCTP_INP_WUNLOCK(inp);
4480 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4481 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4482 SCTP_INP_RLOCK(inp);
4483 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4484 SCTP_TCB_LOCK(stcb);
4485 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4486 SCTP_TCB_UNLOCK(stcb);
4488 SCTP_INP_RUNLOCK(inp);
4493 case SCTP_AUTH_DELETE_KEY:
4495 struct sctp_authkeyid *scdel;
4497 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4498 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4500 /* delete the key from the right place */
4502 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4503 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4506 SCTP_TCB_UNLOCK(stcb);
4508 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4509 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4510 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4511 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4512 SCTP_INP_WLOCK(inp);
4513 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4514 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4517 SCTP_INP_WUNLOCK(inp);
4519 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4520 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4521 SCTP_INP_RLOCK(inp);
4522 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4523 SCTP_TCB_LOCK(stcb);
4524 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4525 SCTP_TCB_UNLOCK(stcb);
4527 SCTP_INP_RUNLOCK(inp);
4532 case SCTP_AUTH_DEACTIVATE_KEY:
4534 struct sctp_authkeyid *keyid;
4536 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4537 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4539 /* deactivate the key from the right place */
4541 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4542 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4545 SCTP_TCB_UNLOCK(stcb);
4547 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4548 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4549 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4550 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4551 SCTP_INP_WLOCK(inp);
4552 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4553 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4556 SCTP_INP_WUNLOCK(inp);
4558 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4559 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4560 SCTP_INP_RLOCK(inp);
4561 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4562 SCTP_TCB_LOCK(stcb);
4563 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4564 SCTP_TCB_UNLOCK(stcb);
4566 SCTP_INP_RUNLOCK(inp);
4571 case SCTP_ENABLE_STREAM_RESET:
4573 struct sctp_assoc_value *av;
4575 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4576 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4577 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4581 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4583 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4584 SCTP_TCB_UNLOCK(stcb);
4586 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4587 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4588 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4589 (av->assoc_id == SCTP_ALL_ASSOC)) {
4590 SCTP_INP_WLOCK(inp);
4591 inp->local_strreset_support = (uint8_t) av->assoc_value;
4592 SCTP_INP_WUNLOCK(inp);
4594 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4595 (av->assoc_id == SCTP_ALL_ASSOC)) {
4596 SCTP_INP_RLOCK(inp);
4597 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4598 SCTP_TCB_LOCK(stcb);
4599 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4600 SCTP_TCB_UNLOCK(stcb);
4602 SCTP_INP_RUNLOCK(inp);
4607 case SCTP_RESET_STREAMS:
4609 struct sctp_reset_streams *strrst;
4610 int i, send_out = 0;
4613 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4614 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4616 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4620 if (stcb->asoc.reconfig_supported == 0) {
4622 * Peer does not support the chunk type.
4624 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4626 SCTP_TCB_UNLOCK(stcb);
4629 if (sizeof(struct sctp_reset_streams) +
4630 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4632 SCTP_TCB_UNLOCK(stcb);
4635 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4637 if (stcb->asoc.stream_reset_outstanding) {
4638 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4640 SCTP_TCB_UNLOCK(stcb);
4644 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4647 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4648 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4650 SCTP_TCB_UNLOCK(stcb);
4653 if ((send_in == 0) && (send_out == 0)) {
4654 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4656 SCTP_TCB_UNLOCK(stcb);
4659 for (i = 0; i < strrst->srs_number_streams; i++) {
4661 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4662 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4667 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4668 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4674 SCTP_TCB_UNLOCK(stcb);
4681 if (strrst->srs_number_streams) {
4682 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4683 strm = strrst->srs_stream_list[i];
4684 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4685 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4691 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4692 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4693 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4700 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4701 strrst->srs_stream_list,
4702 send_in, 0, 0, 0, 0, 0);
4704 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4707 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4710 * For outgoing streams don't report any
4711 * problems in sending the request to the
4712 * application. XXX: Double check resetting
4717 SCTP_TCB_UNLOCK(stcb);
4720 case SCTP_ADD_STREAMS:
4722 struct sctp_add_streams *stradd;
4723 uint8_t addstream = 0;
4724 uint16_t add_o_strmcnt = 0;
4725 uint16_t add_i_strmcnt = 0;
4727 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4728 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4730 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4734 if (stcb->asoc.reconfig_supported == 0) {
4736 * Peer does not support the chunk type.
4738 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4740 SCTP_TCB_UNLOCK(stcb);
4743 if (stcb->asoc.stream_reset_outstanding) {
4744 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4746 SCTP_TCB_UNLOCK(stcb);
4749 if ((stradd->sas_outstrms == 0) &&
4750 (stradd->sas_instrms == 0)) {
4754 if (stradd->sas_outstrms) {
4756 /* We allocate here */
4757 add_o_strmcnt = stradd->sas_outstrms;
4758 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4759 /* You can't have more than 64k */
4764 if (stradd->sas_instrms) {
4769 * We allocate inside
4770 * sctp_send_str_reset_req()
4772 add_i_strmcnt = stradd->sas_instrms;
4773 cnt = add_i_strmcnt;
4774 cnt += stcb->asoc.streamincnt;
4775 if (cnt > 0x0000ffff) {
4776 /* You can't have more than 64k */
4780 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4781 /* More than you are allowed */
4786 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4787 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4789 SCTP_TCB_UNLOCK(stcb);
4792 case SCTP_RESET_ASSOC:
4797 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4798 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4804 if (stcb->asoc.reconfig_supported == 0) {
4806 * Peer does not support the chunk type.
4808 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4810 SCTP_TCB_UNLOCK(stcb);
4813 if (stcb->asoc.stream_reset_outstanding) {
4814 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4816 SCTP_TCB_UNLOCK(stcb);
4820 * Is there any data pending in the send or sent
4823 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4824 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4827 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4828 SCTP_TCB_UNLOCK(stcb);
4831 /* Do any streams have data queued? */
4832 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4833 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4837 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4838 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4839 SCTP_TCB_UNLOCK(stcb);
4842 case SCTP_CONNECT_X:
4843 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4844 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4848 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4850 case SCTP_CONNECT_X_DELAYED:
4851 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4852 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4856 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4858 case SCTP_CONNECT_X_COMPLETE:
4860 struct sockaddr *sa;
4862 /* FIXME MT: check correct? */
4863 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4866 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4867 SCTP_INP_RLOCK(inp);
4868 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4870 SCTP_TCB_LOCK(stcb);
4872 SCTP_INP_RUNLOCK(inp);
4875 * We increment here since
4876 * sctp_findassociation_ep_addr() wil do a
4877 * decrement if it finds the stcb as long as
4878 * the locked tcb (last argument) is NOT a
4881 SCTP_INP_INCR_REF(inp);
4882 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4884 SCTP_INP_DECR_REF(inp);
4889 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4893 if (stcb->asoc.delayed_connection == 1) {
4894 stcb->asoc.delayed_connection = 0;
4895 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4896 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4897 stcb->asoc.primary_destination,
4898 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4899 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4902 * already expired or did not use delayed
4905 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4908 SCTP_TCB_UNLOCK(stcb);
4911 case SCTP_MAX_BURST:
4913 struct sctp_assoc_value *av;
4915 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4916 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4919 stcb->asoc.max_burst = av->assoc_value;
4920 SCTP_TCB_UNLOCK(stcb);
4922 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4923 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4924 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4925 (av->assoc_id == SCTP_ALL_ASSOC)) {
4926 SCTP_INP_WLOCK(inp);
4927 inp->sctp_ep.max_burst = av->assoc_value;
4928 SCTP_INP_WUNLOCK(inp);
4930 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4931 (av->assoc_id == SCTP_ALL_ASSOC)) {
4932 SCTP_INP_RLOCK(inp);
4933 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4934 SCTP_TCB_LOCK(stcb);
4935 stcb->asoc.max_burst = av->assoc_value;
4936 SCTP_TCB_UNLOCK(stcb);
4938 SCTP_INP_RUNLOCK(inp);
4945 struct sctp_assoc_value *av;
4948 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4949 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4951 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4952 ovh = SCTP_MED_OVERHEAD;
4954 ovh = SCTP_MED_V4_OVERHEAD;
4957 if (av->assoc_value) {
4958 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4960 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4962 SCTP_TCB_UNLOCK(stcb);
4964 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4965 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4966 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4967 SCTP_INP_WLOCK(inp);
4969 * FIXME MT: I think this is not in
4970 * tune with the API ID
4972 if (av->assoc_value) {
4973 inp->sctp_frag_point = (av->assoc_value + ovh);
4975 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4977 SCTP_INP_WUNLOCK(inp);
4979 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4987 struct sctp_event_subscribe *events;
4989 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4991 SCTP_INP_WLOCK(inp);
4992 if (events->sctp_data_io_event) {
4993 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4995 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4998 if (events->sctp_association_event) {
4999 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5001 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5004 if (events->sctp_address_event) {
5005 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5007 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5010 if (events->sctp_send_failure_event) {
5011 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5013 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5016 if (events->sctp_peer_error_event) {
5017 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5019 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5022 if (events->sctp_shutdown_event) {
5023 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5025 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5028 if (events->sctp_partial_delivery_event) {
5029 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5031 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5034 if (events->sctp_adaptation_layer_event) {
5035 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5037 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5040 if (events->sctp_authentication_event) {
5041 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5043 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5046 if (events->sctp_sender_dry_event) {
5047 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5049 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5052 if (events->sctp_stream_reset_event) {
5053 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5055 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5057 SCTP_INP_WUNLOCK(inp);
5059 SCTP_INP_RLOCK(inp);
5060 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5061 SCTP_TCB_LOCK(stcb);
5062 if (events->sctp_association_event) {
5063 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5065 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5067 if (events->sctp_address_event) {
5068 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5070 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5072 if (events->sctp_send_failure_event) {
5073 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5075 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5077 if (events->sctp_peer_error_event) {
5078 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5080 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5082 if (events->sctp_shutdown_event) {
5083 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5085 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5087 if (events->sctp_partial_delivery_event) {
5088 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5090 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5092 if (events->sctp_adaptation_layer_event) {
5093 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5095 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5097 if (events->sctp_authentication_event) {
5098 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5100 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5102 if (events->sctp_sender_dry_event) {
5103 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5105 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5107 if (events->sctp_stream_reset_event) {
5108 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5110 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5112 SCTP_TCB_UNLOCK(stcb);
5115 * Send up the sender dry event only for 1-to-1
5118 if (events->sctp_sender_dry_event) {
5119 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5120 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5121 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5123 SCTP_TCB_LOCK(stcb);
5124 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5125 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5126 (stcb->asoc.stream_queue_cnt == 0)) {
5127 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5129 SCTP_TCB_UNLOCK(stcb);
5133 SCTP_INP_RUNLOCK(inp);
5136 case SCTP_ADAPTATION_LAYER:
5138 struct sctp_setadaptation *adap_bits;
5140 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5141 SCTP_INP_WLOCK(inp);
5142 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5143 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5144 SCTP_INP_WUNLOCK(inp);
5148 case SCTP_SET_INITIAL_DBG_SEQ:
5152 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5153 SCTP_INP_WLOCK(inp);
5154 inp->sctp_ep.initial_sequence_debug = *vvv;
5155 SCTP_INP_WUNLOCK(inp);
5159 case SCTP_DEFAULT_SEND_PARAM:
5161 struct sctp_sndrcvinfo *s_info;
5163 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5164 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5167 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5168 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5170 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5173 SCTP_TCB_UNLOCK(stcb);
5175 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5176 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5177 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5178 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5179 SCTP_INP_WLOCK(inp);
5180 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5181 SCTP_INP_WUNLOCK(inp);
5183 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5184 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5185 SCTP_INP_RLOCK(inp);
5186 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5187 SCTP_TCB_LOCK(stcb);
5188 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5189 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5191 SCTP_TCB_UNLOCK(stcb);
5193 SCTP_INP_RUNLOCK(inp);
5198 case SCTP_PEER_ADDR_PARAMS:
5200 struct sctp_paddrparams *paddrp;
5201 struct sctp_nets *net;
5202 struct sockaddr *addr;
5204 #if defined(INET) && defined(INET6)
5205 struct sockaddr_in sin_store;
5209 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5210 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5212 #if defined(INET) && defined(INET6)
5213 if (paddrp->spp_address.ss_family == AF_INET6) {
5214 struct sockaddr_in6 *sin6;
5216 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5217 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5218 in6_sin6_2_sin(&sin_store, sin6);
5219 addr = (struct sockaddr *)&sin_store;
5221 addr = (struct sockaddr *)&paddrp->spp_address;
5224 addr = (struct sockaddr *)&paddrp->spp_address;
5227 addr = (struct sockaddr *)&paddrp->spp_address;
5230 net = sctp_findnet(stcb, addr);
5233 * We increment here since
5234 * sctp_findassociation_ep_addr() wil do a
5235 * decrement if it finds the stcb as long as
5236 * the locked tcb (last argument) is NOT a
5240 SCTP_INP_INCR_REF(inp);
5241 stcb = sctp_findassociation_ep_addr(&inp, addr,
5244 SCTP_INP_DECR_REF(inp);
5247 if ((stcb != NULL) && (net == NULL)) {
5249 if (addr->sa_family == AF_INET) {
5251 struct sockaddr_in *sin;
5253 sin = (struct sockaddr_in *)addr;
5254 if (sin->sin_addr.s_addr != INADDR_ANY) {
5255 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5256 SCTP_TCB_UNLOCK(stcb);
5263 if (addr->sa_family == AF_INET6) {
5264 struct sockaddr_in6 *sin6;
5266 sin6 = (struct sockaddr_in6 *)addr;
5267 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5268 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5269 SCTP_TCB_UNLOCK(stcb);
5276 error = EAFNOSUPPORT;
5277 SCTP_TCB_UNLOCK(stcb);
5278 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5283 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5285 SCTP_TCB_UNLOCK(stcb);
5286 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5289 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5291 SCTP_TCB_UNLOCK(stcb);
5292 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5296 /************************TCB SPECIFIC SET ******************/
5298 /************************NET SPECIFIC SET ******************/
5299 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5300 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5301 !(net->dest_state & SCTP_ADDR_NOHB)) {
5302 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5303 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5305 net->dest_state |= SCTP_ADDR_NOHB;
5307 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5308 if (paddrp->spp_hbinterval) {
5309 net->heart_beat_delay = paddrp->spp_hbinterval;
5310 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5311 net->heart_beat_delay = 0;
5313 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5314 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5315 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5316 net->dest_state &= ~SCTP_ADDR_NOHB;
5318 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5320 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5321 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5322 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5324 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5325 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5326 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5327 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5329 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5330 net->mtu = paddrp->spp_pathmtu;
5331 switch (net->ro._l_addr.sa.sa_family) {
5334 net->mtu += SCTP_MIN_V4_OVERHEAD;
5339 net->mtu += SCTP_MIN_OVERHEAD;
5345 if (net->mtu < stcb->asoc.smallest_mtu) {
5346 sctp_pathmtu_adjustment(stcb, net->mtu);
5349 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5350 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5351 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5353 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5355 if (paddrp->spp_pathmaxrxt) {
5356 if (net->dest_state & SCTP_ADDR_PF) {
5357 if (net->error_count > paddrp->spp_pathmaxrxt) {
5358 net->dest_state &= ~SCTP_ADDR_PF;
5361 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5362 (net->error_count > net->pf_threshold)) {
5363 net->dest_state |= SCTP_ADDR_PF;
5364 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5365 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5366 stcb->sctp_ep, stcb, net,
5367 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5368 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5371 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5372 if (net->error_count > paddrp->spp_pathmaxrxt) {
5373 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5374 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5377 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5378 net->dest_state |= SCTP_ADDR_REACHABLE;
5379 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5382 net->failure_threshold = paddrp->spp_pathmaxrxt;
5384 if (paddrp->spp_flags & SPP_DSCP) {
5385 net->dscp = paddrp->spp_dscp & 0xfc;
5389 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5390 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5391 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5392 net->flowlabel |= 0x80000000;
5397 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5398 if (paddrp->spp_pathmaxrxt != 0) {
5399 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5400 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5401 if (net->dest_state & SCTP_ADDR_PF) {
5402 if (net->error_count > paddrp->spp_pathmaxrxt) {
5403 net->dest_state &= ~SCTP_ADDR_PF;
5406 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5407 (net->error_count > net->pf_threshold)) {
5408 net->dest_state |= SCTP_ADDR_PF;
5409 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5410 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5411 stcb->sctp_ep, stcb, net,
5412 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5413 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5416 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5417 if (net->error_count > paddrp->spp_pathmaxrxt) {
5418 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5419 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5422 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5423 net->dest_state |= SCTP_ADDR_REACHABLE;
5424 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5427 net->failure_threshold = paddrp->spp_pathmaxrxt;
5430 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5431 if (paddrp->spp_hbinterval != 0) {
5432 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5433 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5434 stcb->asoc.heart_beat_delay = 0;
5436 /* Turn back on the timer */
5437 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5438 if (paddrp->spp_hbinterval != 0) {
5439 net->heart_beat_delay = paddrp->spp_hbinterval;
5440 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5441 net->heart_beat_delay = 0;
5443 if (net->dest_state & SCTP_ADDR_NOHB) {
5444 net->dest_state &= ~SCTP_ADDR_NOHB;
5446 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5447 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5448 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5450 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5452 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5453 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5454 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5455 net->dest_state |= SCTP_ADDR_NOHB;
5456 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5457 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5459 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5463 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5465 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5466 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5467 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5468 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5469 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5471 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5472 net->mtu = paddrp->spp_pathmtu;
5473 switch (net->ro._l_addr.sa.sa_family) {
5476 net->mtu += SCTP_MIN_V4_OVERHEAD;
5481 net->mtu += SCTP_MIN_OVERHEAD;
5487 if (net->mtu < stcb->asoc.smallest_mtu) {
5488 sctp_pathmtu_adjustment(stcb, net->mtu);
5491 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5493 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5494 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5495 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5496 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5498 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5500 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5502 if (paddrp->spp_flags & SPP_DSCP) {
5503 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5504 net->dscp = paddrp->spp_dscp & 0xfc;
5507 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5508 stcb->asoc.default_dscp |= 0x01;
5511 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5512 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5513 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5514 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5515 net->flowlabel |= 0x80000000;
5518 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5519 stcb->asoc.default_flowlabel |= 0x80000000;
5523 SCTP_TCB_UNLOCK(stcb);
5525 /************************NO TCB, SET TO default stuff ******************/
5526 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5527 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5528 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5529 SCTP_INP_WLOCK(inp);
5531 * For the TOS/FLOWLABEL stuff you
5532 * set it with the options on the
5535 if (paddrp->spp_pathmaxrxt != 0) {
5536 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5538 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5539 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5540 else if (paddrp->spp_hbinterval != 0) {
5541 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5542 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5543 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5545 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5546 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5547 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5548 } else if (paddrp->spp_hbinterval) {
5549 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5551 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5552 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5553 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5555 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5556 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5557 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5558 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5560 if (paddrp->spp_flags & SPP_DSCP) {
5561 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5562 inp->sctp_ep.default_dscp |= 0x01;
5565 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5566 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5567 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5568 inp->sctp_ep.default_flowlabel |= 0x80000000;
5572 SCTP_INP_WUNLOCK(inp);
5574 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5582 struct sctp_rtoinfo *srto;
5583 uint32_t new_init, new_min, new_max;
5585 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5586 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5589 if (srto->srto_initial)
5590 new_init = srto->srto_initial;
5592 new_init = stcb->asoc.initial_rto;
5594 new_max = srto->srto_max;
5596 new_max = stcb->asoc.maxrto;
5598 new_min = srto->srto_min;
5600 new_min = stcb->asoc.minrto;
5601 if ((new_min <= new_init) && (new_init <= new_max)) {
5602 stcb->asoc.initial_rto = new_init;
5603 stcb->asoc.maxrto = new_max;
5604 stcb->asoc.minrto = new_min;
5606 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5609 SCTP_TCB_UNLOCK(stcb);
5611 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5612 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5613 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5614 SCTP_INP_WLOCK(inp);
5615 if (srto->srto_initial)
5616 new_init = srto->srto_initial;
5618 new_init = inp->sctp_ep.initial_rto;
5620 new_max = srto->srto_max;
5622 new_max = inp->sctp_ep.sctp_maxrto;
5624 new_min = srto->srto_min;
5626 new_min = inp->sctp_ep.sctp_minrto;
5627 if ((new_min <= new_init) && (new_init <= new_max)) {
5628 inp->sctp_ep.initial_rto = new_init;
5629 inp->sctp_ep.sctp_maxrto = new_max;
5630 inp->sctp_ep.sctp_minrto = new_min;
5632 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5635 SCTP_INP_WUNLOCK(inp);
5637 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5643 case SCTP_ASSOCINFO:
5645 struct sctp_assocparams *sasoc;
5647 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5648 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5649 if (sasoc->sasoc_cookie_life) {
5650 /* boundary check the cookie life */
5651 if (sasoc->sasoc_cookie_life < 1000)
5652 sasoc->sasoc_cookie_life = 1000;
5653 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5654 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5658 if (sasoc->sasoc_asocmaxrxt)
5659 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5660 if (sasoc->sasoc_cookie_life) {
5661 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5663 SCTP_TCB_UNLOCK(stcb);
5665 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5666 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5667 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5668 SCTP_INP_WLOCK(inp);
5669 if (sasoc->sasoc_asocmaxrxt)
5670 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5671 if (sasoc->sasoc_cookie_life) {
5672 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5674 SCTP_INP_WUNLOCK(inp);
5676 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5684 struct sctp_initmsg *sinit;
5686 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5687 SCTP_INP_WLOCK(inp);
5688 if (sinit->sinit_num_ostreams)
5689 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5691 if (sinit->sinit_max_instreams)
5692 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5694 if (sinit->sinit_max_attempts)
5695 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5697 if (sinit->sinit_max_init_timeo)
5698 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5699 SCTP_INP_WUNLOCK(inp);
5702 case SCTP_PRIMARY_ADDR:
5704 struct sctp_setprim *spa;
5705 struct sctp_nets *net;
5706 struct sockaddr *addr;
5708 #if defined(INET) && defined(INET6)
5709 struct sockaddr_in sin_store;
5713 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5714 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5716 #if defined(INET) && defined(INET6)
5717 if (spa->ssp_addr.ss_family == AF_INET6) {
5718 struct sockaddr_in6 *sin6;
5720 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5721 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5722 in6_sin6_2_sin(&sin_store, sin6);
5723 addr = (struct sockaddr *)&sin_store;
5725 addr = (struct sockaddr *)&spa->ssp_addr;
5728 addr = (struct sockaddr *)&spa->ssp_addr;
5731 addr = (struct sockaddr *)&spa->ssp_addr;
5734 net = sctp_findnet(stcb, addr);
5737 * We increment here since
5738 * sctp_findassociation_ep_addr() wil do a
5739 * decrement if it finds the stcb as long as
5740 * the locked tcb (last argument) is NOT a
5744 SCTP_INP_INCR_REF(inp);
5745 stcb = sctp_findassociation_ep_addr(&inp, addr,
5748 SCTP_INP_DECR_REF(inp);
5752 if ((stcb != NULL) && (net != NULL)) {
5753 if (net != stcb->asoc.primary_destination) {
5754 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5755 /* Ok we need to set it */
5756 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5757 if ((stcb->asoc.alternate) &&
5758 (!(net->dest_state & SCTP_ADDR_PF)) &&
5759 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5760 sctp_free_remote_addr(stcb->asoc.alternate);
5761 stcb->asoc.alternate = NULL;
5764 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5768 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5773 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5777 SCTP_TCB_UNLOCK(stcb);
5781 case SCTP_SET_DYNAMIC_PRIMARY:
5783 union sctp_sockstore *ss;
5785 error = priv_check(curthread,
5786 PRIV_NETINET_RESERVEDPORT);
5790 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5791 /* SUPER USER CHECK? */
5792 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5795 case SCTP_SET_PEER_PRIMARY_ADDR:
5797 struct sctp_setpeerprim *sspp;
5798 struct sockaddr *addr;
5800 #if defined(INET) && defined(INET6)
5801 struct sockaddr_in sin_store;
5805 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5806 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5808 struct sctp_ifa *ifa;
5810 #if defined(INET) && defined(INET6)
5811 if (sspp->sspp_addr.ss_family == AF_INET6) {
5812 struct sockaddr_in6 *sin6;
5814 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5815 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5816 in6_sin6_2_sin(&sin_store, sin6);
5817 addr = (struct sockaddr *)&sin_store;
5819 addr = (struct sockaddr *)&sspp->sspp_addr;
5822 addr = (struct sockaddr *)&sspp->sspp_addr;
5825 addr = (struct sockaddr *)&sspp->sspp_addr;
5827 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5829 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5833 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5835 * Must validate the ifa found is in
5838 struct sctp_laddr *laddr;
5841 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5842 if (laddr->ifa == NULL) {
5843 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5847 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5848 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5851 if (laddr->ifa == ifa) {
5857 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5862 switch (addr->sa_family) {
5866 struct sockaddr_in *sin;
5868 sin = (struct sockaddr_in *)addr;
5869 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5870 &sin->sin_addr) != 0) {
5871 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5881 struct sockaddr_in6 *sin6;
5883 sin6 = (struct sockaddr_in6 *)addr;
5884 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5885 &sin6->sin6_addr) != 0) {
5886 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5894 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5899 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5900 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5903 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5905 SCTP_TCB_UNLOCK(stcb);
5907 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5912 case SCTP_BINDX_ADD_ADDR:
5914 struct sctp_getaddresses *addrs;
5917 td = (struct thread *)p;
5918 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5921 if (addrs->addr->sa_family == AF_INET) {
5922 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5923 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5927 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5928 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5934 if (addrs->addr->sa_family == AF_INET6) {
5935 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5936 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5940 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5941 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5942 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5948 error = EAFNOSUPPORT;
5951 sctp_bindx_add_address(so, inp, addrs->addr,
5952 addrs->sget_assoc_id, vrf_id,
5956 case SCTP_BINDX_REM_ADDR:
5958 struct sctp_getaddresses *addrs;
5961 td = (struct thread *)p;
5963 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5965 if (addrs->addr->sa_family == AF_INET) {
5966 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5967 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5971 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5972 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5978 if (addrs->addr->sa_family == AF_INET6) {
5979 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5980 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5985 (error = prison_local_ip6(td->td_ucred,
5986 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5987 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5988 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5994 error = EAFNOSUPPORT;
5997 sctp_bindx_delete_address(inp, addrs->addr,
5998 addrs->sget_assoc_id, vrf_id,
6004 struct sctp_event *event;
6005 uint32_t event_type;
6007 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6008 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6009 switch (event->se_type) {
6010 case SCTP_ASSOC_CHANGE:
6011 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6013 case SCTP_PEER_ADDR_CHANGE:
6014 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6016 case SCTP_REMOTE_ERROR:
6017 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6019 case SCTP_SEND_FAILED:
6020 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6022 case SCTP_SHUTDOWN_EVENT:
6023 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6025 case SCTP_ADAPTATION_INDICATION:
6026 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6028 case SCTP_PARTIAL_DELIVERY_EVENT:
6029 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6031 case SCTP_AUTHENTICATION_EVENT:
6032 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6034 case SCTP_STREAM_RESET_EVENT:
6035 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6037 case SCTP_SENDER_DRY_EVENT:
6038 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6040 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6042 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6045 case SCTP_ASSOC_RESET_EVENT:
6046 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6048 case SCTP_STREAM_CHANGE_EVENT:
6049 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6051 case SCTP_SEND_FAILED_EVENT:
6052 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6056 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6060 if (event_type > 0) {
6063 sctp_stcb_feature_on(inp, stcb, event_type);
6064 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6065 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6066 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6067 (stcb->asoc.stream_queue_cnt == 0)) {
6068 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6072 sctp_stcb_feature_off(inp, stcb, event_type);
6074 SCTP_TCB_UNLOCK(stcb);
6077 * We don't want to send up a storm
6078 * of events, so return an error for
6081 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6082 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6083 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6084 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6085 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6086 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6090 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6091 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6092 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6093 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6094 SCTP_INP_WLOCK(inp);
6096 sctp_feature_on(inp, event_type);
6098 sctp_feature_off(inp, event_type);
6100 SCTP_INP_WUNLOCK(inp);
6102 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6103 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6104 SCTP_INP_RLOCK(inp);
6105 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6106 SCTP_TCB_LOCK(stcb);
6108 sctp_stcb_feature_on(inp, stcb, event_type);
6110 sctp_stcb_feature_off(inp, stcb, event_type);
6112 SCTP_TCB_UNLOCK(stcb);
6114 SCTP_INP_RUNLOCK(inp);
6120 case SCTP_RECVRCVINFO:
6124 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6125 SCTP_INP_WLOCK(inp);
6127 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6129 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6131 SCTP_INP_WUNLOCK(inp);
6134 case SCTP_RECVNXTINFO:
6138 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6139 SCTP_INP_WLOCK(inp);
6141 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6143 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6145 SCTP_INP_WUNLOCK(inp);
6148 case SCTP_DEFAULT_SNDINFO:
6150 struct sctp_sndinfo *info;
6153 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6154 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6157 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6158 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6159 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6160 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6161 stcb->asoc.def_send.sinfo_flags |= policy;
6162 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6163 stcb->asoc.def_send.sinfo_context = info->snd_context;
6165 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6168 SCTP_TCB_UNLOCK(stcb);
6170 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6171 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6172 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6173 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6174 SCTP_INP_WLOCK(inp);
6175 inp->def_send.sinfo_stream = info->snd_sid;
6176 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6177 inp->def_send.sinfo_flags = info->snd_flags;
6178 inp->def_send.sinfo_flags |= policy;
6179 inp->def_send.sinfo_ppid = info->snd_ppid;
6180 inp->def_send.sinfo_context = info->snd_context;
6181 SCTP_INP_WUNLOCK(inp);
6183 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6184 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6185 SCTP_INP_RLOCK(inp);
6186 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6187 SCTP_TCB_LOCK(stcb);
6188 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6189 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6190 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6191 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6192 stcb->asoc.def_send.sinfo_flags |= policy;
6193 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6194 stcb->asoc.def_send.sinfo_context = info->snd_context;
6196 SCTP_TCB_UNLOCK(stcb);
6198 SCTP_INP_RUNLOCK(inp);
6203 case SCTP_DEFAULT_PRINFO:
6205 struct sctp_default_prinfo *info;
6207 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6208 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6210 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6211 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6216 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6217 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6218 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6219 SCTP_TCB_UNLOCK(stcb);
6221 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6222 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6223 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6224 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6225 SCTP_INP_WLOCK(inp);
6226 inp->def_send.sinfo_flags &= 0xfff0;
6227 inp->def_send.sinfo_flags |= info->pr_policy;
6228 inp->def_send.sinfo_timetolive = info->pr_value;
6229 SCTP_INP_WUNLOCK(inp);
6231 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6232 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6233 SCTP_INP_RLOCK(inp);
6234 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6235 SCTP_TCB_LOCK(stcb);
6236 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6237 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6238 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6239 SCTP_TCB_UNLOCK(stcb);
6241 SCTP_INP_RUNLOCK(inp);
6246 case SCTP_PEER_ADDR_THLDS:
6247 /* Applies to the specific association */
6249 struct sctp_paddrthlds *thlds;
6250 struct sctp_nets *net;
6251 struct sockaddr *addr;
6253 #if defined(INET) && defined(INET6)
6254 struct sockaddr_in sin_store;
6258 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6259 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6261 #if defined(INET) && defined(INET6)
6262 if (thlds->spt_address.ss_family == AF_INET6) {
6263 struct sockaddr_in6 *sin6;
6265 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6266 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6267 in6_sin6_2_sin(&sin_store, sin6);
6268 addr = (struct sockaddr *)&sin_store;
6270 addr = (struct sockaddr *)&thlds->spt_address;
6273 addr = (struct sockaddr *)&thlds->spt_address;
6276 addr = (struct sockaddr *)&thlds->spt_address;
6279 net = sctp_findnet(stcb, addr);
6282 * We increment here since
6283 * sctp_findassociation_ep_addr() wil do a
6284 * decrement if it finds the stcb as long as
6285 * the locked tcb (last argument) is NOT a
6289 SCTP_INP_INCR_REF(inp);
6290 stcb = sctp_findassociation_ep_addr(&inp, addr,
6293 SCTP_INP_DECR_REF(inp);
6296 if ((stcb != NULL) && (net == NULL)) {
6298 if (addr->sa_family == AF_INET) {
6300 struct sockaddr_in *sin;
6302 sin = (struct sockaddr_in *)addr;
6303 if (sin->sin_addr.s_addr != INADDR_ANY) {
6304 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6305 SCTP_TCB_UNLOCK(stcb);
6312 if (addr->sa_family == AF_INET6) {
6313 struct sockaddr_in6 *sin6;
6315 sin6 = (struct sockaddr_in6 *)addr;
6316 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6317 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6318 SCTP_TCB_UNLOCK(stcb);
6325 error = EAFNOSUPPORT;
6326 SCTP_TCB_UNLOCK(stcb);
6327 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6331 if (thlds->spt_pathcpthld != 0xffff) {
6333 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6338 net->failure_threshold = thlds->spt_pathmaxrxt;
6339 net->pf_threshold = thlds->spt_pathpfthld;
6340 if (net->dest_state & SCTP_ADDR_PF) {
6341 if ((net->error_count > net->failure_threshold) ||
6342 (net->error_count <= net->pf_threshold)) {
6343 net->dest_state &= ~SCTP_ADDR_PF;
6346 if ((net->error_count > net->pf_threshold) &&
6347 (net->error_count <= net->failure_threshold)) {
6348 net->dest_state |= SCTP_ADDR_PF;
6349 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6350 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6351 stcb->sctp_ep, stcb, net,
6352 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6353 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6356 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6357 if (net->error_count > net->failure_threshold) {
6358 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6359 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6362 if (net->error_count <= net->failure_threshold) {
6363 net->dest_state |= SCTP_ADDR_REACHABLE;
6364 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6368 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6369 net->failure_threshold = thlds->spt_pathmaxrxt;
6370 net->pf_threshold = thlds->spt_pathpfthld;
6371 if (net->dest_state & SCTP_ADDR_PF) {
6372 if ((net->error_count > net->failure_threshold) ||
6373 (net->error_count <= net->pf_threshold)) {
6374 net->dest_state &= ~SCTP_ADDR_PF;
6377 if ((net->error_count > net->pf_threshold) &&
6378 (net->error_count <= net->failure_threshold)) {
6379 net->dest_state |= SCTP_ADDR_PF;
6380 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6381 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6382 stcb->sctp_ep, stcb, net,
6383 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6384 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6387 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6388 if (net->error_count > net->failure_threshold) {
6389 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6390 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6393 if (net->error_count <= net->failure_threshold) {
6394 net->dest_state |= SCTP_ADDR_REACHABLE;
6395 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6399 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6400 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6402 SCTP_TCB_UNLOCK(stcb);
6404 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6405 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6406 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6407 SCTP_INP_WLOCK(inp);
6408 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6409 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6410 SCTP_INP_WUNLOCK(inp);
6412 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6418 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6420 struct sctp_udpencaps *encaps;
6421 struct sctp_nets *net;
6422 struct sockaddr *addr;
6424 #if defined(INET) && defined(INET6)
6425 struct sockaddr_in sin_store;
6429 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6430 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6432 #if defined(INET) && defined(INET6)
6433 if (encaps->sue_address.ss_family == AF_INET6) {
6434 struct sockaddr_in6 *sin6;
6436 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6437 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6438 in6_sin6_2_sin(&sin_store, sin6);
6439 addr = (struct sockaddr *)&sin_store;
6441 addr = (struct sockaddr *)&encaps->sue_address;
6444 addr = (struct sockaddr *)&encaps->sue_address;
6447 addr = (struct sockaddr *)&encaps->sue_address;
6450 net = sctp_findnet(stcb, addr);
6453 * We increment here since
6454 * sctp_findassociation_ep_addr() wil do a
6455 * decrement if it finds the stcb as long as
6456 * the locked tcb (last argument) is NOT a
6460 SCTP_INP_INCR_REF(inp);
6461 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6463 SCTP_INP_DECR_REF(inp);
6466 if ((stcb != NULL) && (net == NULL)) {
6468 if (addr->sa_family == AF_INET) {
6470 struct sockaddr_in *sin;
6472 sin = (struct sockaddr_in *)addr;
6473 if (sin->sin_addr.s_addr != INADDR_ANY) {
6474 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6475 SCTP_TCB_UNLOCK(stcb);
6482 if (addr->sa_family == AF_INET6) {
6483 struct sockaddr_in6 *sin6;
6485 sin6 = (struct sockaddr_in6 *)addr;
6486 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6487 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6488 SCTP_TCB_UNLOCK(stcb);
6495 error = EAFNOSUPPORT;
6496 SCTP_TCB_UNLOCK(stcb);
6497 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6503 net->port = encaps->sue_port;
6505 stcb->asoc.port = encaps->sue_port;
6507 SCTP_TCB_UNLOCK(stcb);
6509 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6510 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6511 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6512 SCTP_INP_WLOCK(inp);
6513 inp->sctp_ep.port = encaps->sue_port;
6514 SCTP_INP_WUNLOCK(inp);
6516 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6522 case SCTP_ECN_SUPPORTED:
6524 struct sctp_assoc_value *av;
6526 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6527 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6530 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6532 SCTP_TCB_UNLOCK(stcb);
6534 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6535 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6536 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6537 SCTP_INP_WLOCK(inp);
6538 if (av->assoc_value == 0) {
6539 inp->ecn_supported = 0;
6541 inp->ecn_supported = 1;
6543 SCTP_INP_WUNLOCK(inp);
6545 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6551 case SCTP_PR_SUPPORTED:
6553 struct sctp_assoc_value *av;
6555 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6556 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6559 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6561 SCTP_TCB_UNLOCK(stcb);
6563 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6564 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6565 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6566 SCTP_INP_WLOCK(inp);
6567 if (av->assoc_value == 0) {
6568 inp->prsctp_supported = 0;
6570 inp->prsctp_supported = 1;
6572 SCTP_INP_WUNLOCK(inp);
6574 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6580 case SCTP_AUTH_SUPPORTED:
6582 struct sctp_assoc_value *av;
6584 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6585 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6588 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6590 SCTP_TCB_UNLOCK(stcb);
6592 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6593 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6594 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6595 if ((av->assoc_value == 0) &&
6596 (inp->asconf_supported == 1)) {
6598 * AUTH is required for
6601 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6604 SCTP_INP_WLOCK(inp);
6605 if (av->assoc_value == 0) {
6606 inp->auth_supported = 0;
6608 inp->auth_supported = 1;
6610 SCTP_INP_WUNLOCK(inp);
6613 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6619 case SCTP_ASCONF_SUPPORTED:
6621 struct sctp_assoc_value *av;
6623 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6624 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6627 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6629 SCTP_TCB_UNLOCK(stcb);
6631 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6632 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6633 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6634 if ((av->assoc_value != 0) &&
6635 (inp->auth_supported == 0)) {
6637 * AUTH is required for
6640 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6643 SCTP_INP_WLOCK(inp);
6644 if (av->assoc_value == 0) {
6645 inp->asconf_supported = 0;
6646 sctp_auth_delete_chunk(SCTP_ASCONF,
6647 inp->sctp_ep.local_auth_chunks);
6648 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6649 inp->sctp_ep.local_auth_chunks);
6651 inp->asconf_supported = 1;
6652 sctp_auth_add_chunk(SCTP_ASCONF,
6653 inp->sctp_ep.local_auth_chunks);
6654 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6655 inp->sctp_ep.local_auth_chunks);
6657 SCTP_INP_WUNLOCK(inp);
6660 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6666 case SCTP_RECONFIG_SUPPORTED:
6668 struct sctp_assoc_value *av;
6670 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6671 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6674 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6676 SCTP_TCB_UNLOCK(stcb);
6678 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6679 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6680 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6681 SCTP_INP_WLOCK(inp);
6682 if (av->assoc_value == 0) {
6683 inp->reconfig_supported = 0;
6685 inp->reconfig_supported = 1;
6687 SCTP_INP_WUNLOCK(inp);
6689 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6695 case SCTP_NRSACK_SUPPORTED:
6697 struct sctp_assoc_value *av;
6699 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6700 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6703 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6705 SCTP_TCB_UNLOCK(stcb);
6707 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6708 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6709 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6710 SCTP_INP_WLOCK(inp);
6711 if (av->assoc_value == 0) {
6712 inp->nrsack_supported = 0;
6714 inp->nrsack_supported = 1;
6716 SCTP_INP_WUNLOCK(inp);
6718 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6724 case SCTP_PKTDROP_SUPPORTED:
6726 struct sctp_assoc_value *av;
6728 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6729 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6732 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6734 SCTP_TCB_UNLOCK(stcb);
6736 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6737 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6738 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6739 SCTP_INP_WLOCK(inp);
6740 if (av->assoc_value == 0) {
6741 inp->pktdrop_supported = 0;
6743 inp->pktdrop_supported = 1;
6745 SCTP_INP_WUNLOCK(inp);
6747 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6755 struct sctp_assoc_value *av;
6756 struct sctp_nets *net;
6758 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6759 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6762 stcb->asoc.max_cwnd = av->assoc_value;
6763 if (stcb->asoc.max_cwnd > 0) {
6764 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6765 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6766 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6767 net->cwnd = stcb->asoc.max_cwnd;
6768 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6769 net->cwnd = net->mtu - sizeof(struct sctphdr);
6774 SCTP_TCB_UNLOCK(stcb);
6776 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6777 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6778 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6779 SCTP_INP_WLOCK(inp);
6780 inp->max_cwnd = av->assoc_value;
6781 SCTP_INP_WUNLOCK(inp);
6783 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6790 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6791 error = ENOPROTOOPT;
6793 } /* end switch (opt) */
6798 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6800 void *optval = NULL;
6804 struct sctp_inpcb *inp;
6806 if ((sopt->sopt_level == SOL_SOCKET) &&
6807 (sopt->sopt_name == SO_SETFIB)) {
6808 inp = (struct sctp_inpcb *)so->so_pcb;
6810 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6813 SCTP_INP_WLOCK(inp);
6814 inp->fibnum = so->so_fibnum;
6815 SCTP_INP_WUNLOCK(inp);
6818 if (sopt->sopt_level != IPPROTO_SCTP) {
6819 /* wrong proto level... send back up to IP */
6821 if (INP_CHECK_SOCKAF(so, AF_INET6))
6822 error = ip6_ctloutput(so, sopt);
6824 #if defined(INET) && defined(INET6)
6828 error = ip_ctloutput(so, sopt);
6832 optsize = sopt->sopt_valsize;
6834 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6835 if (optval == NULL) {
6836 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6839 error = sooptcopyin(sopt, optval, optsize, optsize);
6841 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6845 p = (void *)sopt->sopt_td;
6846 if (sopt->sopt_dir == SOPT_SET) {
6847 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6848 } else if (sopt->sopt_dir == SOPT_GET) {
6849 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6851 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6854 if ((error == 0) && (optval != NULL)) {
6855 error = sooptcopyout(sopt, optval, optsize);
6856 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6857 } else if (optval != NULL) {
6858 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6866 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6869 int create_lock_on = 0;
6871 struct sctp_inpcb *inp;
6872 struct sctp_tcb *stcb = NULL;
6874 inp = (struct sctp_inpcb *)so->so_pcb;
6876 /* I made the same as TCP since we are not setup? */
6877 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6878 return (ECONNRESET);
6881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6884 switch (addr->sa_family) {
6888 struct sockaddr_in6 *sin6p;
6890 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6891 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6894 sin6p = (struct sockaddr_in6 *)addr;
6895 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6896 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6905 struct sockaddr_in *sinp;
6907 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6908 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6911 sinp = (struct sockaddr_in *)addr;
6912 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6920 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6921 return (EAFNOSUPPORT);
6923 SCTP_INP_INCR_REF(inp);
6924 SCTP_ASOC_CREATE_LOCK(inp);
6928 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6929 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6930 /* Should I really unlock ? */
6931 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6936 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6937 (addr->sa_family == AF_INET6)) {
6938 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6943 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6944 SCTP_PCB_FLAGS_UNBOUND) {
6945 /* Bind a ephemeral port */
6946 error = sctp_inpcb_bind(so, NULL, NULL, p);
6951 /* Now do we connect? */
6952 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6953 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6954 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6958 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6959 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6960 /* We are already connected AND the TCP model */
6961 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6965 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6966 SCTP_INP_RLOCK(inp);
6967 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6968 SCTP_INP_RUNLOCK(inp);
6971 * We increment here since sctp_findassociation_ep_addr()
6972 * will do a decrement if it finds the stcb as long as the
6973 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6975 SCTP_INP_INCR_REF(inp);
6976 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6978 SCTP_INP_DECR_REF(inp);
6980 SCTP_TCB_UNLOCK(stcb);
6984 /* Already have or am bring up an association */
6985 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
6989 vrf_id = inp->def_vrf_id;
6990 /* We are GOOD to go */
6991 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
6992 inp->sctp_ep.pre_open_stream_count,
6993 inp->sctp_ep.port, p);
6995 /* Gak! no memory */
6998 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
6999 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
7000 /* Set the connected flag so we can queue data */
7003 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
7004 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7006 /* initialize authentication parameters for the assoc */
7007 sctp_initialize_auth_params(inp, stcb);
7009 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7010 SCTP_TCB_UNLOCK(stcb);
7012 if (create_lock_on) {
7013 SCTP_ASOC_CREATE_UNLOCK(inp);
7015 SCTP_INP_DECR_REF(inp);
7022 sctp_listen(struct socket *so, int backlog, struct thread *p)
7025 * Note this module depends on the protocol processing being called
7026 * AFTER any socket level flags and backlog are applied to the
7027 * socket. The traditional way that the socket flags are applied is
7028 * AFTER protocol processing. We have made a change to the
7029 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7030 * place if the socket API for SCTP is to work properly.
7034 struct sctp_inpcb *inp;
7036 inp = (struct sctp_inpcb *)so->so_pcb;
7038 /* I made the same as TCP since we are not setup? */
7039 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7040 return (ECONNRESET);
7042 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7043 /* See if we have a listener */
7044 struct sctp_inpcb *tinp;
7045 union sctp_sockstore store;
7047 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7049 struct sctp_laddr *laddr;
7051 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7052 memcpy(&store, &laddr->ifa->address, sizeof(store));
7053 switch (store.sa.sa_family) {
7056 store.sin.sin_port = inp->sctp_lport;
7061 store.sin6.sin6_port = inp->sctp_lport;
7067 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7068 if (tinp && (tinp != inp) &&
7069 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7070 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7071 (tinp->sctp_socket->so_qlimit)) {
7073 * we have a listener already and
7076 SCTP_INP_DECR_REF(tinp);
7077 return (EADDRINUSE);
7079 SCTP_INP_DECR_REF(tinp);
7083 /* Setup a local addr bound all */
7084 memset(&store, 0, sizeof(store));
7086 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7087 store.sa.sa_family = AF_INET6;
7088 store.sa.sa_len = sizeof(struct sockaddr_in6);
7092 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7093 store.sa.sa_family = AF_INET;
7094 store.sa.sa_len = sizeof(struct sockaddr_in);
7097 switch (store.sa.sa_family) {
7100 store.sin.sin_port = inp->sctp_lport;
7105 store.sin6.sin6_port = inp->sctp_lport;
7111 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7112 if (tinp && (tinp != inp) &&
7113 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7114 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7115 (tinp->sctp_socket->so_qlimit)) {
7117 * we have a listener already and its not
7120 SCTP_INP_DECR_REF(tinp);
7121 return (EADDRINUSE);
7123 SCTP_INP_DECR_REF(tinp);
7127 SCTP_INP_RLOCK(inp);
7128 #ifdef SCTP_LOCK_LOGGING
7129 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7130 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7134 error = solisten_proto_check(so);
7137 SCTP_INP_RUNLOCK(inp);
7140 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7141 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7143 * The unlucky case - We are in the tcp pool with this guy.
7144 * - Someone else is in the main inp slot. - We must move
7145 * this guy (the listener) to the main slot - We must then
7146 * move the guy that was listener to the TCP Pool.
7148 if (sctp_swap_inpcb_for_listen(inp)) {
7149 SCTP_INP_RUNLOCK(inp);
7150 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7151 return (EADDRINUSE);
7154 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7155 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7156 /* We are already connected AND the TCP model */
7157 SCTP_INP_RUNLOCK(inp);
7158 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7159 return (EADDRINUSE);
7161 SCTP_INP_RUNLOCK(inp);
7162 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7163 /* We must do a bind. */
7164 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7165 /* bind error, probably perm */
7170 /* It appears for 7.0 and on, we must always call this. */
7171 solisten_proto(so, backlog);
7172 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7173 /* remove the ACCEPTCONN flag for one-to-many sockets */
7174 so->so_options &= ~SO_ACCEPTCONN;
7177 /* turning off listen */
7178 so->so_options &= ~SO_ACCEPTCONN;
7184 static int sctp_defered_wakeup_cnt = 0;
7187 sctp_accept(struct socket *so, struct sockaddr **addr)
7189 struct sctp_tcb *stcb;
7190 struct sctp_inpcb *inp;
7191 union sctp_sockstore store;
7197 inp = (struct sctp_inpcb *)so->so_pcb;
7200 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7201 return (ECONNRESET);
7203 SCTP_INP_RLOCK(inp);
7204 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7205 SCTP_INP_RUNLOCK(inp);
7206 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7207 return (EOPNOTSUPP);
7209 if (so->so_state & SS_ISDISCONNECTED) {
7210 SCTP_INP_RUNLOCK(inp);
7211 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7212 return (ECONNABORTED);
7214 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7216 SCTP_INP_RUNLOCK(inp);
7217 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7218 return (ECONNRESET);
7220 SCTP_TCB_LOCK(stcb);
7221 SCTP_INP_RUNLOCK(inp);
7222 store = stcb->asoc.primary_destination->ro._l_addr;
7223 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
7224 SCTP_TCB_UNLOCK(stcb);
7225 switch (store.sa.sa_family) {
7229 struct sockaddr_in *sin;
7231 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7234 sin->sin_family = AF_INET;
7235 sin->sin_len = sizeof(*sin);
7236 sin->sin_port = store.sin.sin_port;
7237 sin->sin_addr = store.sin.sin_addr;
7238 *addr = (struct sockaddr *)sin;
7245 struct sockaddr_in6 *sin6;
7247 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7250 sin6->sin6_family = AF_INET6;
7251 sin6->sin6_len = sizeof(*sin6);
7252 sin6->sin6_port = store.sin6.sin6_port;
7253 sin6->sin6_addr = store.sin6.sin6_addr;
7254 if ((error = sa6_recoverscope(sin6)) != 0) {
7255 SCTP_FREE_SONAME(sin6);
7258 *addr = (struct sockaddr *)sin6;
7266 /* Wake any delayed sleep action */
7267 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7268 SCTP_INP_WLOCK(inp);
7269 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7270 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7271 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7272 SCTP_INP_WUNLOCK(inp);
7273 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7274 if (sowriteable(inp->sctp_socket)) {
7275 sowwakeup_locked(inp->sctp_socket);
7277 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7279 SCTP_INP_WLOCK(inp);
7281 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7282 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7283 SCTP_INP_WUNLOCK(inp);
7284 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7285 if (soreadable(inp->sctp_socket)) {
7286 sctp_defered_wakeup_cnt++;
7287 sorwakeup_locked(inp->sctp_socket);
7289 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7291 SCTP_INP_WLOCK(inp);
7293 SCTP_INP_WUNLOCK(inp);
7295 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7296 SCTP_TCB_LOCK(stcb);
7297 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7298 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7305 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7307 struct sockaddr_in *sin;
7309 struct sctp_inpcb *inp;
7310 struct sctp_ifa *sctp_ifa;
7313 * Do the malloc first in case it blocks.
7315 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7318 sin->sin_family = AF_INET;
7319 sin->sin_len = sizeof(*sin);
7320 inp = (struct sctp_inpcb *)so->so_pcb;
7322 SCTP_FREE_SONAME(sin);
7323 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7324 return (ECONNRESET);
7326 SCTP_INP_RLOCK(inp);
7327 sin->sin_port = inp->sctp_lport;
7328 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7329 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7330 struct sctp_tcb *stcb;
7331 struct sockaddr_in *sin_a;
7332 struct sctp_nets *net;
7335 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7341 SCTP_TCB_LOCK(stcb);
7342 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7343 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7345 /* this will make coverity happy */
7348 if (sin_a->sin_family == AF_INET) {
7353 if ((!fnd) || (sin_a == NULL)) {
7355 SCTP_TCB_UNLOCK(stcb);
7358 vrf_id = inp->def_vrf_id;
7359 sctp_ifa = sctp_source_address_selection(inp,
7361 (sctp_route_t *) & net->ro,
7364 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7365 sctp_free_ifa(sctp_ifa);
7367 SCTP_TCB_UNLOCK(stcb);
7369 /* For the bound all case you get back 0 */
7371 sin->sin_addr.s_addr = 0;
7375 /* Take the first IPv4 address in the list */
7376 struct sctp_laddr *laddr;
7379 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7380 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7381 struct sockaddr_in *sin_a;
7383 sin_a = &laddr->ifa->address.sin;
7384 sin->sin_addr = sin_a->sin_addr;
7390 SCTP_FREE_SONAME(sin);
7391 SCTP_INP_RUNLOCK(inp);
7392 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7396 SCTP_INP_RUNLOCK(inp);
7397 (*addr) = (struct sockaddr *)sin;
7402 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7404 struct sockaddr_in *sin;
7406 struct sockaddr_in *sin_a;
7407 struct sctp_inpcb *inp;
7408 struct sctp_tcb *stcb;
7409 struct sctp_nets *net;
7411 /* Do the malloc first in case it blocks. */
7412 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7415 sin->sin_family = AF_INET;
7416 sin->sin_len = sizeof(*sin);
7418 inp = (struct sctp_inpcb *)so->so_pcb;
7419 if ((inp == NULL) ||
7420 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7421 /* UDP type and listeners will drop out here */
7422 SCTP_FREE_SONAME(sin);
7423 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7426 SCTP_INP_RLOCK(inp);
7427 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7429 SCTP_TCB_LOCK(stcb);
7431 SCTP_INP_RUNLOCK(inp);
7433 SCTP_FREE_SONAME(sin);
7434 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7435 return (ECONNRESET);
7438 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7439 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7440 if (sin_a->sin_family == AF_INET) {
7442 sin->sin_port = stcb->rport;
7443 sin->sin_addr = sin_a->sin_addr;
7447 SCTP_TCB_UNLOCK(stcb);
7449 /* No IPv4 address */
7450 SCTP_FREE_SONAME(sin);
7451 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7454 (*addr) = (struct sockaddr *)sin;
7458 struct pr_usrreqs sctp_usrreqs = {
7459 .pru_abort = sctp_abort,
7460 .pru_accept = sctp_accept,
7461 .pru_attach = sctp_attach,
7462 .pru_bind = sctp_bind,
7463 .pru_connect = sctp_connect,
7464 .pru_control = in_control,
7465 .pru_close = sctp_close,
7466 .pru_detach = sctp_close,
7467 .pru_sopoll = sopoll_generic,
7468 .pru_flush = sctp_flush,
7469 .pru_disconnect = sctp_disconnect,
7470 .pru_listen = sctp_listen,
7471 .pru_peeraddr = sctp_peeraddr,
7472 .pru_send = sctp_sendm,
7473 .pru_shutdown = sctp_shutdown,
7474 .pru_sockaddr = sctp_ingetaddr,
7475 .pru_sosend = sctp_sosend,
7476 .pru_soreceive = sctp_soreceive