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);
1510 if (creat_lock_on) {
1511 SCTP_ASOC_CREATE_UNLOCK(inp);
1513 SCTP_INP_DECR_REF(inp);
1517 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1518 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1519 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1520 SCTP_INP_RLOCK(inp); \
1521 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1523 SCTP_TCB_LOCK(stcb); \
1525 SCTP_INP_RUNLOCK(inp); \
1526 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1527 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1528 if (stcb == NULL) { \
1529 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1539 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1540 if (size < sizeof(type)) { \
1541 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1545 destp = (type *)srcp; \
1550 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1553 struct sctp_inpcb *inp = NULL;
1555 struct sctp_tcb *stcb = NULL;
1557 if (optval == NULL) {
1558 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1561 inp = (struct sctp_inpcb *)so->so_pcb;
1563 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1570 case SCTP_AUTOCLOSE:
1571 case SCTP_EXPLICIT_EOR:
1572 case SCTP_AUTO_ASCONF:
1573 case SCTP_DISABLE_FRAGMENTS:
1574 case SCTP_I_WANT_MAPPED_V4_ADDR:
1575 case SCTP_USE_EXT_RCVINFO:
1576 SCTP_INP_RLOCK(inp);
1578 case SCTP_DISABLE_FRAGMENTS:
1579 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1581 case SCTP_I_WANT_MAPPED_V4_ADDR:
1582 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1584 case SCTP_AUTO_ASCONF:
1585 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1586 /* only valid for bound all sockets */
1587 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1589 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1594 case SCTP_EXPLICIT_EOR:
1595 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1598 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1600 case SCTP_USE_EXT_RCVINFO:
1601 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1603 case SCTP_AUTOCLOSE:
1604 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1605 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1611 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1612 error = ENOPROTOOPT;
1613 } /* end switch (sopt->sopt_name) */
1614 if (*optsize < sizeof(val)) {
1615 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1619 SCTP_INP_RUNLOCK(inp);
1621 /* return the option value */
1622 *(int *)optval = val;
1623 *optsize = sizeof(val);
1626 case SCTP_GET_PACKET_LOG:
1628 #ifdef SCTP_PACKET_LOGGING
1632 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1633 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1636 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1641 case SCTP_REUSE_PORT:
1645 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1646 /* Can't do this for a 1-m socket */
1650 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1651 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1652 *optsize = sizeof(uint32_t);
1655 case SCTP_PARTIAL_DELIVERY_POINT:
1659 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1660 *value = inp->partial_delivery_point;
1661 *optsize = sizeof(uint32_t);
1664 case SCTP_FRAGMENT_INTERLEAVE:
1668 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1669 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1670 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1671 *value = SCTP_FRAG_LEVEL_2;
1673 *value = SCTP_FRAG_LEVEL_1;
1676 *value = SCTP_FRAG_LEVEL_0;
1678 *optsize = sizeof(uint32_t);
1681 case SCTP_INTERLEAVING_SUPPORTED:
1683 struct sctp_assoc_value *av;
1685 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1686 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1689 av->assoc_value = stcb->asoc.idata_supported;
1690 SCTP_TCB_UNLOCK(stcb);
1692 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1693 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1694 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1695 SCTP_INP_RLOCK(inp);
1696 if (inp->idata_supported) {
1697 av->assoc_value = 1;
1699 av->assoc_value = 0;
1701 SCTP_INP_RUNLOCK(inp);
1703 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1708 *optsize = sizeof(struct sctp_assoc_value);
1712 case SCTP_CMT_ON_OFF:
1714 struct sctp_assoc_value *av;
1716 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1717 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1719 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1720 SCTP_TCB_UNLOCK(stcb);
1722 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1723 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1724 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1725 SCTP_INP_RLOCK(inp);
1726 av->assoc_value = inp->sctp_cmt_on_off;
1727 SCTP_INP_RUNLOCK(inp);
1729 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1734 *optsize = sizeof(struct sctp_assoc_value);
1738 case SCTP_PLUGGABLE_CC:
1740 struct sctp_assoc_value *av;
1742 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1743 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1745 av->assoc_value = stcb->asoc.congestion_control_module;
1746 SCTP_TCB_UNLOCK(stcb);
1748 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1749 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1750 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1751 SCTP_INP_RLOCK(inp);
1752 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1753 SCTP_INP_RUNLOCK(inp);
1755 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1760 *optsize = sizeof(struct sctp_assoc_value);
1764 case SCTP_CC_OPTION:
1766 struct sctp_cc_option *cc_opt;
1768 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1769 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1773 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1776 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1777 *optsize = sizeof(struct sctp_cc_option);
1779 SCTP_TCB_UNLOCK(stcb);
1783 case SCTP_PLUGGABLE_SS:
1785 struct sctp_assoc_value *av;
1787 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1788 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1790 av->assoc_value = stcb->asoc.stream_scheduling_module;
1791 SCTP_TCB_UNLOCK(stcb);
1793 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1794 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1795 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1796 SCTP_INP_RLOCK(inp);
1797 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1798 SCTP_INP_RUNLOCK(inp);
1800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1805 *optsize = sizeof(struct sctp_assoc_value);
1811 struct sctp_stream_value *av;
1813 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1814 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1816 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1817 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1818 &av->stream_value) < 0)) {
1819 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1822 *optsize = sizeof(struct sctp_stream_value);
1824 SCTP_TCB_UNLOCK(stcb);
1827 * Can't get stream value without
1830 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1835 case SCTP_GET_ADDR_LEN:
1837 struct sctp_assoc_value *av;
1839 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1842 if (av->assoc_value == AF_INET) {
1843 av->assoc_value = sizeof(struct sockaddr_in);
1848 if (av->assoc_value == AF_INET6) {
1849 av->assoc_value = sizeof(struct sockaddr_in6);
1854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1856 *optsize = sizeof(struct sctp_assoc_value);
1860 case SCTP_GET_ASSOC_NUMBER:
1862 uint32_t *value, cnt;
1864 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1865 SCTP_INP_RLOCK(inp);
1866 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1867 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1868 /* Can't do this for a 1-1 socket */
1870 SCTP_INP_RUNLOCK(inp);
1874 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1877 SCTP_INP_RUNLOCK(inp);
1879 *optsize = sizeof(uint32_t);
1882 case SCTP_GET_ASSOC_ID_LIST:
1884 struct sctp_assoc_ids *ids;
1888 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1889 SCTP_INP_RLOCK(inp);
1890 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1891 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1892 /* Can't do this for a 1-1 socket */
1894 SCTP_INP_RUNLOCK(inp);
1898 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1899 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1901 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1904 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1909 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1913 SCTP_INP_RUNLOCK(inp);
1915 ids->gaids_number_of_ids = at;
1916 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1922 struct sctp_assoc_value *av;
1924 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1925 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1928 av->assoc_value = stcb->asoc.context;
1929 SCTP_TCB_UNLOCK(stcb);
1931 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1932 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1933 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1934 SCTP_INP_RLOCK(inp);
1935 av->assoc_value = inp->sctp_context;
1936 SCTP_INP_RUNLOCK(inp);
1938 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1943 *optsize = sizeof(struct sctp_assoc_value);
1949 uint32_t *default_vrfid;
1951 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1952 *default_vrfid = inp->def_vrf_id;
1953 *optsize = sizeof(uint32_t);
1956 case SCTP_GET_ASOC_VRF:
1958 struct sctp_assoc_value *id;
1960 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1961 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1964 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1966 id->assoc_value = stcb->asoc.vrf_id;
1967 *optsize = sizeof(struct sctp_assoc_value);
1971 case SCTP_GET_VRF_IDS:
1973 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1977 case SCTP_GET_NONCE_VALUES:
1979 struct sctp_get_nonce_values *gnv;
1981 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1982 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1985 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1986 gnv->gn_local_tag = stcb->asoc.my_vtag;
1987 SCTP_TCB_UNLOCK(stcb);
1988 *optsize = sizeof(struct sctp_get_nonce_values);
1990 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1995 case SCTP_DELAYED_SACK:
1997 struct sctp_sack_info *sack;
1999 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2000 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2002 sack->sack_delay = stcb->asoc.delayed_ack;
2003 sack->sack_freq = stcb->asoc.sack_freq;
2004 SCTP_TCB_UNLOCK(stcb);
2006 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2007 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2008 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2009 SCTP_INP_RLOCK(inp);
2010 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2011 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2012 SCTP_INP_RUNLOCK(inp);
2014 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2019 *optsize = sizeof(struct sctp_sack_info);
2023 case SCTP_GET_SNDBUF_USE:
2025 struct sctp_sockstat *ss;
2027 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2028 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2031 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2032 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2033 stcb->asoc.size_on_all_streams);
2034 SCTP_TCB_UNLOCK(stcb);
2035 *optsize = sizeof(struct sctp_sockstat);
2037 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2042 case SCTP_MAX_BURST:
2044 struct sctp_assoc_value *av;
2046 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2047 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2050 av->assoc_value = stcb->asoc.max_burst;
2051 SCTP_TCB_UNLOCK(stcb);
2053 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2054 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2055 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2056 SCTP_INP_RLOCK(inp);
2057 av->assoc_value = inp->sctp_ep.max_burst;
2058 SCTP_INP_RUNLOCK(inp);
2060 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2065 *optsize = sizeof(struct sctp_assoc_value);
2071 struct sctp_assoc_value *av;
2074 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2075 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2078 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2079 SCTP_TCB_UNLOCK(stcb);
2081 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2082 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2083 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2084 SCTP_INP_RLOCK(inp);
2085 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2086 ovh = SCTP_MED_OVERHEAD;
2088 ovh = SCTP_MED_V4_OVERHEAD;
2090 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2091 av->assoc_value = 0;
2093 av->assoc_value = inp->sctp_frag_point - ovh;
2094 SCTP_INP_RUNLOCK(inp);
2096 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2101 *optsize = sizeof(struct sctp_assoc_value);
2105 case SCTP_GET_STAT_LOG:
2106 error = sctp_fill_stat_log(optval, optsize);
2110 struct sctp_event_subscribe *events;
2112 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2113 memset(events, 0, sizeof(struct sctp_event_subscribe));
2114 SCTP_INP_RLOCK(inp);
2115 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2116 events->sctp_data_io_event = 1;
2118 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2119 events->sctp_association_event = 1;
2121 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2122 events->sctp_address_event = 1;
2124 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2125 events->sctp_send_failure_event = 1;
2127 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2128 events->sctp_peer_error_event = 1;
2130 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2131 events->sctp_shutdown_event = 1;
2133 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2134 events->sctp_partial_delivery_event = 1;
2136 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2137 events->sctp_adaptation_layer_event = 1;
2139 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2140 events->sctp_authentication_event = 1;
2142 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2143 events->sctp_sender_dry_event = 1;
2145 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2146 events->sctp_stream_reset_event = 1;
2147 SCTP_INP_RUNLOCK(inp);
2148 *optsize = sizeof(struct sctp_event_subscribe);
2151 case SCTP_ADAPTATION_LAYER:
2155 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2157 SCTP_INP_RLOCK(inp);
2158 *value = inp->sctp_ep.adaptation_layer_indicator;
2159 SCTP_INP_RUNLOCK(inp);
2160 *optsize = sizeof(uint32_t);
2163 case SCTP_SET_INITIAL_DBG_SEQ:
2167 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2168 SCTP_INP_RLOCK(inp);
2169 *value = inp->sctp_ep.initial_sequence_debug;
2170 SCTP_INP_RUNLOCK(inp);
2171 *optsize = sizeof(uint32_t);
2174 case SCTP_GET_LOCAL_ADDR_SIZE:
2178 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2179 SCTP_INP_RLOCK(inp);
2180 *value = sctp_count_max_addresses(inp);
2181 SCTP_INP_RUNLOCK(inp);
2182 *optsize = sizeof(uint32_t);
2185 case SCTP_GET_REMOTE_ADDR_SIZE:
2189 struct sctp_nets *net;
2191 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2192 /* FIXME MT: change to sctp_assoc_value? */
2193 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2197 /* Count the sizes */
2198 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2199 switch (net->ro._l_addr.sa.sa_family) {
2203 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2204 size += sizeof(struct sockaddr_in6);
2206 size += sizeof(struct sockaddr_in);
2209 size += sizeof(struct sockaddr_in);
2215 size += sizeof(struct sockaddr_in6);
2222 SCTP_TCB_UNLOCK(stcb);
2223 *value = (uint32_t) size;
2224 *optsize = sizeof(uint32_t);
2226 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2231 case SCTP_GET_PEER_ADDRESSES:
2233 * Get the address information, an array is passed in to
2234 * fill up we pack it.
2238 struct sockaddr_storage *sas;
2239 struct sctp_nets *net;
2240 struct sctp_getaddresses *saddr;
2242 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2243 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2246 left = (*optsize) - sizeof(struct sctp_getaddresses);
2247 *optsize = sizeof(struct sctp_getaddresses);
2248 sas = (struct sockaddr_storage *)&saddr->addr[0];
2250 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2251 switch (net->ro._l_addr.sa.sa_family) {
2255 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2256 cpsz = sizeof(struct sockaddr_in6);
2258 cpsz = sizeof(struct sockaddr_in);
2261 cpsz = sizeof(struct sockaddr_in);
2267 cpsz = sizeof(struct sockaddr_in6);
2278 /* not enough room. */
2281 #if defined(INET) && defined(INET6)
2282 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2283 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2284 /* Must map the address */
2285 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2286 (struct sockaddr_in6 *)sas);
2288 memcpy(sas, &net->ro._l_addr, cpsz);
2291 memcpy(sas, &net->ro._l_addr, cpsz);
2293 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2295 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2299 SCTP_TCB_UNLOCK(stcb);
2301 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2306 case SCTP_GET_LOCAL_ADDRESSES:
2308 size_t limit, actual;
2309 struct sockaddr_storage *sas;
2310 struct sctp_getaddresses *saddr;
2312 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2313 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2315 sas = (struct sockaddr_storage *)&saddr->addr[0];
2316 limit = *optsize - sizeof(sctp_assoc_t);
2317 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2319 SCTP_TCB_UNLOCK(stcb);
2321 *optsize = sizeof(struct sockaddr_storage) + actual;
2324 case SCTP_PEER_ADDR_PARAMS:
2326 struct sctp_paddrparams *paddrp;
2327 struct sctp_nets *net;
2328 struct sockaddr *addr;
2330 #if defined(INET) && defined(INET6)
2331 struct sockaddr_in sin_store;
2335 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2336 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2338 #if defined(INET) && defined(INET6)
2339 if (paddrp->spp_address.ss_family == AF_INET6) {
2340 struct sockaddr_in6 *sin6;
2342 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2343 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2344 in6_sin6_2_sin(&sin_store, sin6);
2345 addr = (struct sockaddr *)&sin_store;
2347 addr = (struct sockaddr *)&paddrp->spp_address;
2350 addr = (struct sockaddr *)&paddrp->spp_address;
2353 addr = (struct sockaddr *)&paddrp->spp_address;
2356 net = sctp_findnet(stcb, addr);
2359 * We increment here since
2360 * sctp_findassociation_ep_addr() wil do a
2361 * decrement if it finds the stcb as long as
2362 * the locked tcb (last argument) is NOT a
2366 SCTP_INP_INCR_REF(inp);
2367 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2369 SCTP_INP_DECR_REF(inp);
2372 if ((stcb != NULL) && (net == NULL)) {
2374 if (addr->sa_family == AF_INET) {
2375 struct sockaddr_in *sin;
2377 sin = (struct sockaddr_in *)addr;
2378 if (sin->sin_addr.s_addr != INADDR_ANY) {
2380 SCTP_TCB_UNLOCK(stcb);
2381 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2387 if (addr->sa_family == AF_INET6) {
2388 struct sockaddr_in6 *sin6;
2390 sin6 = (struct sockaddr_in6 *)addr;
2391 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2393 SCTP_TCB_UNLOCK(stcb);
2394 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2400 error = EAFNOSUPPORT;
2401 SCTP_TCB_UNLOCK(stcb);
2402 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2407 /* Applies to the specific association */
2408 paddrp->spp_flags = 0;
2410 paddrp->spp_hbinterval = net->heart_beat_delay;
2411 paddrp->spp_pathmaxrxt = net->failure_threshold;
2412 paddrp->spp_pathmtu = net->mtu;
2413 switch (net->ro._l_addr.sa.sa_family) {
2416 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2421 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2427 /* get flags for HB */
2428 if (net->dest_state & SCTP_ADDR_NOHB) {
2429 paddrp->spp_flags |= SPP_HB_DISABLE;
2431 paddrp->spp_flags |= SPP_HB_ENABLE;
2433 /* get flags for PMTU */
2434 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2435 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2437 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2439 if (net->dscp & 0x01) {
2440 paddrp->spp_dscp = net->dscp & 0xfc;
2441 paddrp->spp_flags |= SPP_DSCP;
2444 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2445 (net->flowlabel & 0x80000000)) {
2446 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2447 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2452 * No destination so return default
2455 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2456 paddrp->spp_pathmtu = 0;
2457 if (stcb->asoc.default_dscp & 0x01) {
2458 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2459 paddrp->spp_flags |= SPP_DSCP;
2462 if (stcb->asoc.default_flowlabel & 0x80000000) {
2463 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2464 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2467 /* default settings should be these */
2468 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2469 paddrp->spp_flags |= SPP_HB_DISABLE;
2471 paddrp->spp_flags |= SPP_HB_ENABLE;
2473 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2474 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2476 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2478 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2480 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2481 SCTP_TCB_UNLOCK(stcb);
2483 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2484 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2485 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2486 /* Use endpoint defaults */
2487 SCTP_INP_RLOCK(inp);
2488 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2489 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2490 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2491 /* get inp's default */
2492 if (inp->sctp_ep.default_dscp & 0x01) {
2493 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2494 paddrp->spp_flags |= SPP_DSCP;
2497 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2498 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2499 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2500 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2503 /* can't return this */
2504 paddrp->spp_pathmtu = 0;
2506 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2507 paddrp->spp_flags |= SPP_HB_ENABLE;
2509 paddrp->spp_flags |= SPP_HB_DISABLE;
2511 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2512 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2514 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2516 SCTP_INP_RUNLOCK(inp);
2518 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2523 *optsize = sizeof(struct sctp_paddrparams);
2527 case SCTP_GET_PEER_ADDR_INFO:
2529 struct sctp_paddrinfo *paddri;
2530 struct sctp_nets *net;
2531 struct sockaddr *addr;
2533 #if defined(INET) && defined(INET6)
2534 struct sockaddr_in sin_store;
2538 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2539 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2541 #if defined(INET) && defined(INET6)
2542 if (paddri->spinfo_address.ss_family == AF_INET6) {
2543 struct sockaddr_in6 *sin6;
2545 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2546 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2547 in6_sin6_2_sin(&sin_store, sin6);
2548 addr = (struct sockaddr *)&sin_store;
2550 addr = (struct sockaddr *)&paddri->spinfo_address;
2553 addr = (struct sockaddr *)&paddri->spinfo_address;
2556 addr = (struct sockaddr *)&paddri->spinfo_address;
2559 net = sctp_findnet(stcb, addr);
2562 * We increment here since
2563 * sctp_findassociation_ep_addr() wil do a
2564 * decrement if it finds the stcb as long as
2565 * the locked tcb (last argument) is NOT a
2569 SCTP_INP_INCR_REF(inp);
2570 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2572 SCTP_INP_DECR_REF(inp);
2576 if ((stcb != NULL) && (net != NULL)) {
2577 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2578 /* It's unconfirmed */
2579 paddri->spinfo_state = SCTP_UNCONFIRMED;
2580 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2582 paddri->spinfo_state = SCTP_ACTIVE;
2585 paddri->spinfo_state = SCTP_INACTIVE;
2587 paddri->spinfo_cwnd = net->cwnd;
2588 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2589 paddri->spinfo_rto = net->RTO;
2590 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2591 paddri->spinfo_mtu = net->mtu;
2592 switch (addr->sa_family) {
2595 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2600 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2606 SCTP_TCB_UNLOCK(stcb);
2607 *optsize = sizeof(struct sctp_paddrinfo);
2610 SCTP_TCB_UNLOCK(stcb);
2612 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2617 case SCTP_PCB_STATUS:
2619 struct sctp_pcbinfo *spcb;
2621 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2622 sctp_fill_pcbinfo(spcb);
2623 *optsize = sizeof(struct sctp_pcbinfo);
2628 struct sctp_nets *net;
2629 struct sctp_status *sstat;
2631 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2632 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2635 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2639 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2640 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2641 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2642 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2644 * We can't include chunks that have been passed to
2645 * the socket layer. Only things in queue.
2647 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2648 stcb->asoc.cnt_on_all_streams);
2651 sstat->sstat_instrms = stcb->asoc.streamincnt;
2652 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2653 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2654 memcpy(&sstat->sstat_primary.spinfo_address,
2655 &stcb->asoc.primary_destination->ro._l_addr,
2656 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2657 net = stcb->asoc.primary_destination;
2658 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2660 * Again the user can get info from sctp_constants.h
2661 * for what the state of the network is.
2663 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2664 /* It's unconfirmed */
2665 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2666 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2668 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2671 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2673 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2674 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2675 sstat->sstat_primary.spinfo_rto = net->RTO;
2676 sstat->sstat_primary.spinfo_mtu = net->mtu;
2677 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2680 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2685 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2691 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2692 SCTP_TCB_UNLOCK(stcb);
2693 *optsize = sizeof(struct sctp_status);
2698 struct sctp_rtoinfo *srto;
2700 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2701 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2704 srto->srto_initial = stcb->asoc.initial_rto;
2705 srto->srto_max = stcb->asoc.maxrto;
2706 srto->srto_min = stcb->asoc.minrto;
2707 SCTP_TCB_UNLOCK(stcb);
2709 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2710 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2711 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2712 SCTP_INP_RLOCK(inp);
2713 srto->srto_initial = inp->sctp_ep.initial_rto;
2714 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2715 srto->srto_min = inp->sctp_ep.sctp_minrto;
2716 SCTP_INP_RUNLOCK(inp);
2718 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2723 *optsize = sizeof(struct sctp_rtoinfo);
2729 struct sctp_timeouts *stimo;
2731 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2732 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2735 stimo->stimo_init = stcb->asoc.timoinit;
2736 stimo->stimo_data = stcb->asoc.timodata;
2737 stimo->stimo_sack = stcb->asoc.timosack;
2738 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2739 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2740 stimo->stimo_cookie = stcb->asoc.timocookie;
2741 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2742 SCTP_TCB_UNLOCK(stcb);
2743 *optsize = sizeof(struct sctp_timeouts);
2745 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2750 case SCTP_ASSOCINFO:
2752 struct sctp_assocparams *sasoc;
2754 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2755 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2758 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2759 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2760 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2761 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2762 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2763 SCTP_TCB_UNLOCK(stcb);
2765 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2766 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2767 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2768 SCTP_INP_RLOCK(inp);
2769 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2770 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2771 sasoc->sasoc_number_peer_destinations = 0;
2772 sasoc->sasoc_peer_rwnd = 0;
2773 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2774 SCTP_INP_RUNLOCK(inp);
2776 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2781 *optsize = sizeof(struct sctp_assocparams);
2785 case SCTP_DEFAULT_SEND_PARAM:
2787 struct sctp_sndrcvinfo *s_info;
2789 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2790 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2793 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2794 SCTP_TCB_UNLOCK(stcb);
2796 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2797 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2798 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2799 SCTP_INP_RLOCK(inp);
2800 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2801 SCTP_INP_RUNLOCK(inp);
2803 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2808 *optsize = sizeof(struct sctp_sndrcvinfo);
2814 struct sctp_initmsg *sinit;
2816 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2817 SCTP_INP_RLOCK(inp);
2818 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2819 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2820 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2821 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2822 SCTP_INP_RUNLOCK(inp);
2823 *optsize = sizeof(struct sctp_initmsg);
2826 case SCTP_PRIMARY_ADDR:
2827 /* we allow a "get" operation on this */
2829 struct sctp_setprim *ssp;
2831 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2832 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2835 union sctp_sockstore *addr;
2837 addr = &stcb->asoc.primary_destination->ro._l_addr;
2838 switch (addr->sa.sa_family) {
2842 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2843 in6_sin_2_v4mapsin6(&addr->sin,
2844 (struct sockaddr_in6 *)&ssp->ssp_addr);
2846 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2849 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2855 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2861 SCTP_TCB_UNLOCK(stcb);
2862 *optsize = sizeof(struct sctp_setprim);
2864 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2869 case SCTP_HMAC_IDENT:
2871 struct sctp_hmacalgo *shmac;
2872 sctp_hmaclist_t *hmaclist;
2876 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2878 SCTP_INP_RLOCK(inp);
2879 hmaclist = inp->sctp_ep.local_hmacs;
2880 if (hmaclist == NULL) {
2881 /* no HMACs to return */
2882 *optsize = sizeof(*shmac);
2883 SCTP_INP_RUNLOCK(inp);
2886 /* is there room for all of the hmac ids? */
2887 size = sizeof(*shmac) + (hmaclist->num_algo *
2888 sizeof(shmac->shmac_idents[0]));
2889 if ((size_t)(*optsize) < size) {
2890 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2892 SCTP_INP_RUNLOCK(inp);
2895 /* copy in the list */
2896 shmac->shmac_number_of_idents = hmaclist->num_algo;
2897 for (i = 0; i < hmaclist->num_algo; i++) {
2898 shmac->shmac_idents[i] = hmaclist->hmac[i];
2900 SCTP_INP_RUNLOCK(inp);
2904 case SCTP_AUTH_ACTIVE_KEY:
2906 struct sctp_authkeyid *scact;
2908 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2909 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2912 /* get the active key on the assoc */
2913 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2914 SCTP_TCB_UNLOCK(stcb);
2916 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2917 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2918 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2919 /* get the endpoint active key */
2920 SCTP_INP_RLOCK(inp);
2921 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2922 SCTP_INP_RUNLOCK(inp);
2924 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2929 *optsize = sizeof(struct sctp_authkeyid);
2933 case SCTP_LOCAL_AUTH_CHUNKS:
2935 struct sctp_authchunks *sac;
2936 sctp_auth_chklist_t *chklist = NULL;
2939 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2940 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2943 /* get off the assoc */
2944 chklist = stcb->asoc.local_auth_chunks;
2945 /* is there enough space? */
2946 size = sctp_auth_get_chklist_size(chklist);
2947 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2949 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2951 /* copy in the chunks */
2952 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2953 sac->gauth_number_of_chunks = (uint32_t) size;
2954 *optsize = sizeof(struct sctp_authchunks) + size;
2956 SCTP_TCB_UNLOCK(stcb);
2958 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2959 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2960 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2961 /* get off the endpoint */
2962 SCTP_INP_RLOCK(inp);
2963 chklist = inp->sctp_ep.local_auth_chunks;
2964 /* is there enough space? */
2965 size = sctp_auth_get_chklist_size(chklist);
2966 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2968 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2970 /* copy in the chunks */
2971 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2972 sac->gauth_number_of_chunks = (uint32_t) size;
2973 *optsize = sizeof(struct sctp_authchunks) + size;
2975 SCTP_INP_RUNLOCK(inp);
2977 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2983 case SCTP_PEER_AUTH_CHUNKS:
2985 struct sctp_authchunks *sac;
2986 sctp_auth_chklist_t *chklist = NULL;
2989 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2990 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2993 /* get off the assoc */
2994 chklist = stcb->asoc.peer_auth_chunks;
2995 /* is there enough space? */
2996 size = sctp_auth_get_chklist_size(chklist);
2997 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2999 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3001 /* copy in the chunks */
3002 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
3003 sac->gauth_number_of_chunks = (uint32_t) size;
3004 *optsize = sizeof(struct sctp_authchunks) + size;
3006 SCTP_TCB_UNLOCK(stcb);
3008 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3015 struct sctp_event *event;
3016 uint32_t event_type;
3018 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3019 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3021 switch (event->se_type) {
3022 case SCTP_ASSOC_CHANGE:
3023 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3025 case SCTP_PEER_ADDR_CHANGE:
3026 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3028 case SCTP_REMOTE_ERROR:
3029 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3031 case SCTP_SEND_FAILED:
3032 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3034 case SCTP_SHUTDOWN_EVENT:
3035 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3037 case SCTP_ADAPTATION_INDICATION:
3038 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3040 case SCTP_PARTIAL_DELIVERY_EVENT:
3041 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3043 case SCTP_AUTHENTICATION_EVENT:
3044 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3046 case SCTP_STREAM_RESET_EVENT:
3047 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3049 case SCTP_SENDER_DRY_EVENT:
3050 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3052 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3054 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3057 case SCTP_ASSOC_RESET_EVENT:
3058 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3060 case SCTP_STREAM_CHANGE_EVENT:
3061 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3063 case SCTP_SEND_FAILED_EVENT:
3064 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3068 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3072 if (event_type > 0) {
3074 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3075 SCTP_TCB_UNLOCK(stcb);
3077 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3078 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3079 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3080 SCTP_INP_RLOCK(inp);
3081 event->se_on = sctp_is_feature_on(inp, event_type);
3082 SCTP_INP_RUNLOCK(inp);
3084 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3090 *optsize = sizeof(struct sctp_event);
3094 case SCTP_RECVRCVINFO:
3098 if (*optsize < sizeof(int)) {
3099 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3102 SCTP_INP_RLOCK(inp);
3103 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3104 SCTP_INP_RUNLOCK(inp);
3107 /* return the option value */
3108 *(int *)optval = onoff;
3109 *optsize = sizeof(int);
3113 case SCTP_RECVNXTINFO:
3117 if (*optsize < sizeof(int)) {
3118 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3121 SCTP_INP_RLOCK(inp);
3122 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3123 SCTP_INP_RUNLOCK(inp);
3126 /* return the option value */
3127 *(int *)optval = onoff;
3128 *optsize = sizeof(int);
3132 case SCTP_DEFAULT_SNDINFO:
3134 struct sctp_sndinfo *info;
3136 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3137 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3140 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3141 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3142 info->snd_flags &= 0xfff0;
3143 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3144 info->snd_context = stcb->asoc.def_send.sinfo_context;
3145 SCTP_TCB_UNLOCK(stcb);
3147 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3148 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3149 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3150 SCTP_INP_RLOCK(inp);
3151 info->snd_sid = inp->def_send.sinfo_stream;
3152 info->snd_flags = inp->def_send.sinfo_flags;
3153 info->snd_flags &= 0xfff0;
3154 info->snd_ppid = inp->def_send.sinfo_ppid;
3155 info->snd_context = inp->def_send.sinfo_context;
3156 SCTP_INP_RUNLOCK(inp);
3158 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3163 *optsize = sizeof(struct sctp_sndinfo);
3167 case SCTP_DEFAULT_PRINFO:
3169 struct sctp_default_prinfo *info;
3171 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3172 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3175 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3176 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3177 SCTP_TCB_UNLOCK(stcb);
3179 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3180 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3181 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3182 SCTP_INP_RLOCK(inp);
3183 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3184 info->pr_value = inp->def_send.sinfo_timetolive;
3185 SCTP_INP_RUNLOCK(inp);
3187 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3192 *optsize = sizeof(struct sctp_default_prinfo);
3196 case SCTP_PEER_ADDR_THLDS:
3198 struct sctp_paddrthlds *thlds;
3199 struct sctp_nets *net;
3200 struct sockaddr *addr;
3202 #if defined(INET) && defined(INET6)
3203 struct sockaddr_in sin_store;
3207 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3208 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3210 #if defined(INET) && defined(INET6)
3211 if (thlds->spt_address.ss_family == AF_INET6) {
3212 struct sockaddr_in6 *sin6;
3214 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3215 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3216 in6_sin6_2_sin(&sin_store, sin6);
3217 addr = (struct sockaddr *)&sin_store;
3219 addr = (struct sockaddr *)&thlds->spt_address;
3222 addr = (struct sockaddr *)&thlds->spt_address;
3225 addr = (struct sockaddr *)&thlds->spt_address;
3228 net = sctp_findnet(stcb, addr);
3231 * We increment here since
3232 * sctp_findassociation_ep_addr() wil do a
3233 * decrement if it finds the stcb as long as
3234 * the locked tcb (last argument) is NOT a
3238 SCTP_INP_INCR_REF(inp);
3239 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3241 SCTP_INP_DECR_REF(inp);
3244 if ((stcb != NULL) && (net == NULL)) {
3246 if (addr->sa_family == AF_INET) {
3247 struct sockaddr_in *sin;
3249 sin = (struct sockaddr_in *)addr;
3250 if (sin->sin_addr.s_addr != INADDR_ANY) {
3252 SCTP_TCB_UNLOCK(stcb);
3253 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3259 if (addr->sa_family == AF_INET6) {
3260 struct sockaddr_in6 *sin6;
3262 sin6 = (struct sockaddr_in6 *)addr;
3263 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3265 SCTP_TCB_UNLOCK(stcb);
3266 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3272 error = EAFNOSUPPORT;
3273 SCTP_TCB_UNLOCK(stcb);
3274 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3280 thlds->spt_pathmaxrxt = net->failure_threshold;
3281 thlds->spt_pathpfthld = net->pf_threshold;
3282 thlds->spt_pathcpthld = 0xffff;
3284 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3285 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3286 thlds->spt_pathcpthld = 0xffff;
3288 thlds->spt_assoc_id = sctp_get_associd(stcb);
3289 SCTP_TCB_UNLOCK(stcb);
3291 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3292 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3293 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3294 /* Use endpoint defaults */
3295 SCTP_INP_RLOCK(inp);
3296 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3297 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3298 thlds->spt_pathcpthld = 0xffff;
3299 SCTP_INP_RUNLOCK(inp);
3301 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3306 *optsize = sizeof(struct sctp_paddrthlds);
3310 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3312 struct sctp_udpencaps *encaps;
3313 struct sctp_nets *net;
3314 struct sockaddr *addr;
3316 #if defined(INET) && defined(INET6)
3317 struct sockaddr_in sin_store;
3321 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3322 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3324 #if defined(INET) && defined(INET6)
3325 if (encaps->sue_address.ss_family == AF_INET6) {
3326 struct sockaddr_in6 *sin6;
3328 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3329 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3330 in6_sin6_2_sin(&sin_store, sin6);
3331 addr = (struct sockaddr *)&sin_store;
3333 addr = (struct sockaddr *)&encaps->sue_address;
3336 addr = (struct sockaddr *)&encaps->sue_address;
3339 addr = (struct sockaddr *)&encaps->sue_address;
3342 net = sctp_findnet(stcb, addr);
3345 * We increment here since
3346 * sctp_findassociation_ep_addr() wil do a
3347 * decrement if it finds the stcb as long as
3348 * the locked tcb (last argument) is NOT a
3352 SCTP_INP_INCR_REF(inp);
3353 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3355 SCTP_INP_DECR_REF(inp);
3358 if ((stcb != NULL) && (net == NULL)) {
3360 if (addr->sa_family == AF_INET) {
3361 struct sockaddr_in *sin;
3363 sin = (struct sockaddr_in *)addr;
3364 if (sin->sin_addr.s_addr != INADDR_ANY) {
3366 SCTP_TCB_UNLOCK(stcb);
3367 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3373 if (addr->sa_family == AF_INET6) {
3374 struct sockaddr_in6 *sin6;
3376 sin6 = (struct sockaddr_in6 *)addr;
3377 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3379 SCTP_TCB_UNLOCK(stcb);
3380 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3386 error = EAFNOSUPPORT;
3387 SCTP_TCB_UNLOCK(stcb);
3388 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3394 encaps->sue_port = net->port;
3396 encaps->sue_port = stcb->asoc.port;
3398 SCTP_TCB_UNLOCK(stcb);
3400 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3401 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3402 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3403 SCTP_INP_RLOCK(inp);
3404 encaps->sue_port = inp->sctp_ep.port;
3405 SCTP_INP_RUNLOCK(inp);
3407 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3412 *optsize = sizeof(struct sctp_udpencaps);
3416 case SCTP_ECN_SUPPORTED:
3418 struct sctp_assoc_value *av;
3420 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3421 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3424 av->assoc_value = stcb->asoc.ecn_supported;
3425 SCTP_TCB_UNLOCK(stcb);
3427 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3428 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3429 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3430 SCTP_INP_RLOCK(inp);
3431 av->assoc_value = inp->ecn_supported;
3432 SCTP_INP_RUNLOCK(inp);
3434 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3439 *optsize = sizeof(struct sctp_assoc_value);
3443 case SCTP_PR_SUPPORTED:
3445 struct sctp_assoc_value *av;
3447 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3448 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3451 av->assoc_value = stcb->asoc.prsctp_supported;
3452 SCTP_TCB_UNLOCK(stcb);
3454 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3455 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3456 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3457 SCTP_INP_RLOCK(inp);
3458 av->assoc_value = inp->prsctp_supported;
3459 SCTP_INP_RUNLOCK(inp);
3461 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3466 *optsize = sizeof(struct sctp_assoc_value);
3470 case SCTP_AUTH_SUPPORTED:
3472 struct sctp_assoc_value *av;
3474 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3475 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3478 av->assoc_value = stcb->asoc.auth_supported;
3479 SCTP_TCB_UNLOCK(stcb);
3481 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3482 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3483 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3484 SCTP_INP_RLOCK(inp);
3485 av->assoc_value = inp->auth_supported;
3486 SCTP_INP_RUNLOCK(inp);
3488 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3493 *optsize = sizeof(struct sctp_assoc_value);
3497 case SCTP_ASCONF_SUPPORTED:
3499 struct sctp_assoc_value *av;
3501 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3502 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3505 av->assoc_value = stcb->asoc.asconf_supported;
3506 SCTP_TCB_UNLOCK(stcb);
3508 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3509 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3510 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3511 SCTP_INP_RLOCK(inp);
3512 av->assoc_value = inp->asconf_supported;
3513 SCTP_INP_RUNLOCK(inp);
3515 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3520 *optsize = sizeof(struct sctp_assoc_value);
3524 case SCTP_RECONFIG_SUPPORTED:
3526 struct sctp_assoc_value *av;
3528 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3529 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3532 av->assoc_value = stcb->asoc.reconfig_supported;
3533 SCTP_TCB_UNLOCK(stcb);
3535 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3536 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3537 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3538 SCTP_INP_RLOCK(inp);
3539 av->assoc_value = inp->reconfig_supported;
3540 SCTP_INP_RUNLOCK(inp);
3542 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3547 *optsize = sizeof(struct sctp_assoc_value);
3551 case SCTP_NRSACK_SUPPORTED:
3553 struct sctp_assoc_value *av;
3555 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3556 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3559 av->assoc_value = stcb->asoc.nrsack_supported;
3560 SCTP_TCB_UNLOCK(stcb);
3562 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3563 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3564 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3565 SCTP_INP_RLOCK(inp);
3566 av->assoc_value = inp->nrsack_supported;
3567 SCTP_INP_RUNLOCK(inp);
3569 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3574 *optsize = sizeof(struct sctp_assoc_value);
3578 case SCTP_PKTDROP_SUPPORTED:
3580 struct sctp_assoc_value *av;
3582 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3583 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3586 av->assoc_value = stcb->asoc.pktdrop_supported;
3587 SCTP_TCB_UNLOCK(stcb);
3589 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3590 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3591 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3592 SCTP_INP_RLOCK(inp);
3593 av->assoc_value = inp->pktdrop_supported;
3594 SCTP_INP_RUNLOCK(inp);
3596 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3601 *optsize = sizeof(struct sctp_assoc_value);
3605 case SCTP_ENABLE_STREAM_RESET:
3607 struct sctp_assoc_value *av;
3609 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3610 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3613 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3614 SCTP_TCB_UNLOCK(stcb);
3616 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3617 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3618 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3619 SCTP_INP_RLOCK(inp);
3620 av->assoc_value = (uint32_t) inp->local_strreset_support;
3621 SCTP_INP_RUNLOCK(inp);
3623 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3628 *optsize = sizeof(struct sctp_assoc_value);
3632 case SCTP_PR_STREAM_STATUS:
3634 struct sctp_prstatus *sprstat;
3638 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3639 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3641 sid = sprstat->sprstat_sid;
3642 policy = sprstat->sprstat_policy;
3643 #if defined(SCTP_DETAILED_STR_STATS)
3644 if ((stcb != NULL) &&
3645 (sid < stcb->asoc.streamoutcnt) &&
3646 (policy != SCTP_PR_SCTP_NONE) &&
3647 ((policy <= SCTP_PR_SCTP_MAX) ||
3648 (policy == SCTP_PR_SCTP_ALL))) {
3649 if (policy == SCTP_PR_SCTP_ALL) {
3650 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3651 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3653 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3654 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3657 if ((stcb != NULL) &&
3658 (sid < stcb->asoc.streamoutcnt) &&
3659 (policy == SCTP_PR_SCTP_ALL)) {
3660 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3661 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3663 SCTP_TCB_UNLOCK(stcb);
3664 *optsize = sizeof(struct sctp_prstatus);
3666 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3671 case SCTP_PR_ASSOC_STATUS:
3673 struct sctp_prstatus *sprstat;
3676 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3677 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3679 policy = sprstat->sprstat_policy;
3680 if ((stcb != NULL) &&
3681 (policy != SCTP_PR_SCTP_NONE) &&
3682 ((policy <= SCTP_PR_SCTP_MAX) ||
3683 (policy == SCTP_PR_SCTP_ALL))) {
3684 if (policy == SCTP_PR_SCTP_ALL) {
3685 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3686 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3688 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3689 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3691 SCTP_TCB_UNLOCK(stcb);
3692 *optsize = sizeof(struct sctp_prstatus);
3694 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3701 struct sctp_assoc_value *av;
3703 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3704 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3707 av->assoc_value = stcb->asoc.max_cwnd;
3708 SCTP_TCB_UNLOCK(stcb);
3710 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3711 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3712 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3713 SCTP_INP_RLOCK(inp);
3714 av->assoc_value = inp->max_cwnd;
3715 SCTP_INP_RUNLOCK(inp);
3717 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3722 *optsize = sizeof(struct sctp_assoc_value);
3727 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3728 error = ENOPROTOOPT;
3730 } /* end switch (sopt->sopt_name) */
3738 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3743 struct sctp_tcb *stcb = NULL;
3744 struct sctp_inpcb *inp = NULL;
3747 if (optval == NULL) {
3748 SCTP_PRINTF("optval is NULL\n");
3749 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3752 inp = (struct sctp_inpcb *)so->so_pcb;
3754 SCTP_PRINTF("inp is NULL?\n");
3755 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3758 vrf_id = inp->def_vrf_id;
3763 case SCTP_AUTOCLOSE:
3764 case SCTP_AUTO_ASCONF:
3765 case SCTP_EXPLICIT_EOR:
3766 case SCTP_DISABLE_FRAGMENTS:
3767 case SCTP_USE_EXT_RCVINFO:
3768 case SCTP_I_WANT_MAPPED_V4_ADDR:
3769 /* copy in the option value */
3770 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3775 case SCTP_DISABLE_FRAGMENTS:
3776 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3778 case SCTP_AUTO_ASCONF:
3780 * NOTE: we don't really support this flag
3782 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3783 /* only valid for bound all sockets */
3784 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3786 /* forbidden by admin */
3787 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3790 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3792 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3796 case SCTP_EXPLICIT_EOR:
3797 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3799 case SCTP_USE_EXT_RCVINFO:
3800 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3802 case SCTP_I_WANT_MAPPED_V4_ADDR:
3803 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3804 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3806 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3811 set_opt = SCTP_PCB_FLAGS_NODELAY;
3813 case SCTP_AUTOCLOSE:
3814 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3815 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3816 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3819 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3821 * The value is in ticks. Note this does not effect
3822 * old associations, only new ones.
3824 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3827 SCTP_INP_WLOCK(inp);
3829 sctp_feature_on(inp, set_opt);
3831 sctp_feature_off(inp, set_opt);
3833 SCTP_INP_WUNLOCK(inp);
3835 case SCTP_REUSE_PORT:
3837 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3838 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3839 /* Can't set it after we are bound */
3843 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3844 /* Can't do this for a 1-m socket */
3849 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3851 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3854 case SCTP_PARTIAL_DELIVERY_POINT:
3858 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3859 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3860 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3864 inp->partial_delivery_point = *value;
3867 case SCTP_FRAGMENT_INTERLEAVE:
3868 /* not yet until we re-write sctp_recvmsg() */
3872 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3873 if (*level == SCTP_FRAG_LEVEL_2) {
3874 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3875 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3876 } else if (*level == SCTP_FRAG_LEVEL_1) {
3877 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3878 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3879 } else if (*level == SCTP_FRAG_LEVEL_0) {
3880 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3881 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3884 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3889 case SCTP_INTERLEAVING_SUPPORTED:
3891 struct sctp_assoc_value *av;
3893 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3894 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3897 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3899 SCTP_TCB_UNLOCK(stcb);
3901 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3902 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3903 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3904 SCTP_INP_WLOCK(inp);
3905 if (av->assoc_value == 0) {
3906 inp->idata_supported = 0;
3908 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3909 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3910 inp->idata_supported = 1;
3918 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3922 SCTP_INP_WUNLOCK(inp);
3924 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3930 case SCTP_CMT_ON_OFF:
3931 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3932 struct sctp_assoc_value *av;
3934 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3935 if (av->assoc_value > SCTP_CMT_MAX) {
3936 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3940 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3942 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3943 SCTP_TCB_UNLOCK(stcb);
3945 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3946 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3947 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3948 (av->assoc_id == SCTP_ALL_ASSOC)) {
3949 SCTP_INP_WLOCK(inp);
3950 inp->sctp_cmt_on_off = av->assoc_value;
3951 SCTP_INP_WUNLOCK(inp);
3953 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3954 (av->assoc_id == SCTP_ALL_ASSOC)) {
3955 SCTP_INP_RLOCK(inp);
3956 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3957 SCTP_TCB_LOCK(stcb);
3958 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3959 SCTP_TCB_UNLOCK(stcb);
3961 SCTP_INP_RUNLOCK(inp);
3965 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3966 error = ENOPROTOOPT;
3969 case SCTP_PLUGGABLE_CC:
3971 struct sctp_assoc_value *av;
3972 struct sctp_nets *net;
3974 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3975 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3976 (av->assoc_value != SCTP_CC_HSTCP) &&
3977 (av->assoc_value != SCTP_CC_HTCP) &&
3978 (av->assoc_value != SCTP_CC_RTCC)) {
3979 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3983 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3985 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3986 stcb->asoc.congestion_control_module = av->assoc_value;
3987 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3988 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3989 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3992 SCTP_TCB_UNLOCK(stcb);
3994 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3995 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3996 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3997 (av->assoc_id == SCTP_ALL_ASSOC)) {
3998 SCTP_INP_WLOCK(inp);
3999 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
4000 SCTP_INP_WUNLOCK(inp);
4002 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4003 (av->assoc_id == SCTP_ALL_ASSOC)) {
4004 SCTP_INP_RLOCK(inp);
4005 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4006 SCTP_TCB_LOCK(stcb);
4007 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4008 stcb->asoc.congestion_control_module = av->assoc_value;
4009 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4010 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4011 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4014 SCTP_TCB_UNLOCK(stcb);
4016 SCTP_INP_RUNLOCK(inp);
4021 case SCTP_CC_OPTION:
4023 struct sctp_cc_option *cc_opt;
4025 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4026 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4028 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
4029 SCTP_INP_RLOCK(inp);
4030 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4031 SCTP_TCB_LOCK(stcb);
4032 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4033 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4035 SCTP_TCB_UNLOCK(stcb);
4037 SCTP_INP_RUNLOCK(inp);
4042 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4045 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4048 SCTP_TCB_UNLOCK(stcb);
4052 case SCTP_PLUGGABLE_SS:
4054 struct sctp_assoc_value *av;
4056 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4057 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4058 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4059 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4060 (av->assoc_value != SCTP_SS_PRIORITY) &&
4061 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4062 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4063 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4067 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4069 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4070 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4071 stcb->asoc.stream_scheduling_module = av->assoc_value;
4072 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4073 SCTP_TCB_UNLOCK(stcb);
4075 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4076 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4077 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4078 (av->assoc_id == SCTP_ALL_ASSOC)) {
4079 SCTP_INP_WLOCK(inp);
4080 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4081 SCTP_INP_WUNLOCK(inp);
4083 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4084 (av->assoc_id == SCTP_ALL_ASSOC)) {
4085 SCTP_INP_RLOCK(inp);
4086 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4087 SCTP_TCB_LOCK(stcb);
4088 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4089 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4090 stcb->asoc.stream_scheduling_module = av->assoc_value;
4091 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4092 SCTP_TCB_UNLOCK(stcb);
4094 SCTP_INP_RUNLOCK(inp);
4101 struct sctp_stream_value *av;
4103 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4104 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4106 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4107 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4108 av->stream_value) < 0)) {
4109 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4112 SCTP_TCB_UNLOCK(stcb);
4114 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4115 SCTP_INP_RLOCK(inp);
4116 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4117 SCTP_TCB_LOCK(stcb);
4118 if (av->stream_id < stcb->asoc.streamoutcnt) {
4119 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4121 &stcb->asoc.strmout[av->stream_id],
4124 SCTP_TCB_UNLOCK(stcb);
4126 SCTP_INP_RUNLOCK(inp);
4129 * Can't set stream value without
4132 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4138 case SCTP_CLR_STAT_LOG:
4139 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4144 struct sctp_assoc_value *av;
4146 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4147 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4150 stcb->asoc.context = av->assoc_value;
4151 SCTP_TCB_UNLOCK(stcb);
4153 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4154 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4155 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4156 (av->assoc_id == SCTP_ALL_ASSOC)) {
4157 SCTP_INP_WLOCK(inp);
4158 inp->sctp_context = av->assoc_value;
4159 SCTP_INP_WUNLOCK(inp);
4161 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4162 (av->assoc_id == SCTP_ALL_ASSOC)) {
4163 SCTP_INP_RLOCK(inp);
4164 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4165 SCTP_TCB_LOCK(stcb);
4166 stcb->asoc.context = av->assoc_value;
4167 SCTP_TCB_UNLOCK(stcb);
4169 SCTP_INP_RUNLOCK(inp);
4176 uint32_t *default_vrfid;
4178 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4179 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4180 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4184 inp->def_vrf_id = *default_vrfid;
4187 case SCTP_DEL_VRF_ID:
4189 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4193 case SCTP_ADD_VRF_ID:
4195 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4199 case SCTP_DELAYED_SACK:
4201 struct sctp_sack_info *sack;
4203 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4204 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4205 if (sack->sack_delay) {
4206 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4207 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4208 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4209 sack->sack_delay = TICKS_TO_MSEC(1);
4213 if (sack->sack_delay) {
4214 stcb->asoc.delayed_ack = sack->sack_delay;
4216 if (sack->sack_freq) {
4217 stcb->asoc.sack_freq = sack->sack_freq;
4219 SCTP_TCB_UNLOCK(stcb);
4221 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4222 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4223 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4224 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4225 SCTP_INP_WLOCK(inp);
4226 if (sack->sack_delay) {
4227 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4229 if (sack->sack_freq) {
4230 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4232 SCTP_INP_WUNLOCK(inp);
4234 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4235 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4236 SCTP_INP_RLOCK(inp);
4237 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4238 SCTP_TCB_LOCK(stcb);
4239 if (sack->sack_delay) {
4240 stcb->asoc.delayed_ack = sack->sack_delay;
4242 if (sack->sack_freq) {
4243 stcb->asoc.sack_freq = sack->sack_freq;
4245 SCTP_TCB_UNLOCK(stcb);
4247 SCTP_INP_RUNLOCK(inp);
4252 case SCTP_AUTH_CHUNK:
4254 struct sctp_authchunk *sauth;
4256 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4258 SCTP_INP_WLOCK(inp);
4259 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4260 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4263 SCTP_INP_WUNLOCK(inp);
4268 struct sctp_authkey *sca;
4269 struct sctp_keyhead *shared_keys;
4270 sctp_sharedkey_t *shared_key;
4271 sctp_key_t *key = NULL;
4274 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4275 if (sca->sca_keylength == 0) {
4276 size = optsize - sizeof(struct sctp_authkey);
4278 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4279 size = sca->sca_keylength;
4281 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4286 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4289 shared_keys = &stcb->asoc.shared_keys;
4290 /* clear the cached keys for this key id */
4291 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4293 * create the new shared key and
4297 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4299 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4301 SCTP_TCB_UNLOCK(stcb);
4305 shared_key = sctp_alloc_sharedkey();
4306 if (shared_key == NULL) {
4308 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4310 SCTP_TCB_UNLOCK(stcb);
4313 shared_key->key = key;
4314 shared_key->keyid = sca->sca_keynumber;
4315 error = sctp_insert_sharedkey(shared_keys, shared_key);
4316 SCTP_TCB_UNLOCK(stcb);
4318 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4319 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4320 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4321 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4322 SCTP_INP_WLOCK(inp);
4323 shared_keys = &inp->sctp_ep.shared_keys;
4325 * clear the cached keys on all
4326 * assocs for this key id
4328 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4330 * create the new shared key and
4334 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4336 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4338 SCTP_INP_WUNLOCK(inp);
4342 shared_key = sctp_alloc_sharedkey();
4343 if (shared_key == NULL) {
4345 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4347 SCTP_INP_WUNLOCK(inp);
4350 shared_key->key = key;
4351 shared_key->keyid = sca->sca_keynumber;
4352 error = sctp_insert_sharedkey(shared_keys, shared_key);
4353 SCTP_INP_WUNLOCK(inp);
4355 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4356 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4357 SCTP_INP_RLOCK(inp);
4358 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4359 SCTP_TCB_LOCK(stcb);
4360 shared_keys = &stcb->asoc.shared_keys;
4362 * clear the cached keys for
4365 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4367 * create the new shared key
4368 * and insert/replace it
4371 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4373 SCTP_TCB_UNLOCK(stcb);
4377 shared_key = sctp_alloc_sharedkey();
4378 if (shared_key == NULL) {
4380 SCTP_TCB_UNLOCK(stcb);
4383 shared_key->key = key;
4384 shared_key->keyid = sca->sca_keynumber;
4385 error = sctp_insert_sharedkey(shared_keys, shared_key);
4386 SCTP_TCB_UNLOCK(stcb);
4388 SCTP_INP_RUNLOCK(inp);
4393 case SCTP_HMAC_IDENT:
4395 struct sctp_hmacalgo *shmac;
4396 sctp_hmaclist_t *hmaclist;
4400 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4401 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4402 (shmac->shmac_number_of_idents > 0xffff)) {
4403 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4407 hmaclist = sctp_alloc_hmaclist((uint16_t) shmac->shmac_number_of_idents);
4408 if (hmaclist == NULL) {
4409 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4413 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4414 hmacid = shmac->shmac_idents[i];
4415 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4416 /* invalid HMACs were found */ ;
4417 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4419 sctp_free_hmaclist(hmaclist);
4420 goto sctp_set_hmac_done;
4423 for (i = 0; i < hmaclist->num_algo; i++) {
4424 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4425 /* already in list */
4429 if (i == hmaclist->num_algo) {
4430 /* not found in list */
4431 sctp_free_hmaclist(hmaclist);
4432 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4436 /* set it on the endpoint */
4437 SCTP_INP_WLOCK(inp);
4438 if (inp->sctp_ep.local_hmacs)
4439 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4440 inp->sctp_ep.local_hmacs = hmaclist;
4441 SCTP_INP_WUNLOCK(inp);
4445 case SCTP_AUTH_ACTIVE_KEY:
4447 struct sctp_authkeyid *scact;
4449 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4450 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4452 /* set the active key on the right place */
4454 /* set the active key on the assoc */
4455 if (sctp_auth_setactivekey(stcb,
4456 scact->scact_keynumber)) {
4457 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4458 SCTP_FROM_SCTP_USRREQ,
4462 SCTP_TCB_UNLOCK(stcb);
4464 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4465 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4466 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4467 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4468 SCTP_INP_WLOCK(inp);
4469 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4470 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4473 SCTP_INP_WUNLOCK(inp);
4475 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4476 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4477 SCTP_INP_RLOCK(inp);
4478 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4479 SCTP_TCB_LOCK(stcb);
4480 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4481 SCTP_TCB_UNLOCK(stcb);
4483 SCTP_INP_RUNLOCK(inp);
4488 case SCTP_AUTH_DELETE_KEY:
4490 struct sctp_authkeyid *scdel;
4492 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4493 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4495 /* delete the key from the right place */
4497 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4498 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4501 SCTP_TCB_UNLOCK(stcb);
4503 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4504 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4505 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4506 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4507 SCTP_INP_WLOCK(inp);
4508 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4509 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4512 SCTP_INP_WUNLOCK(inp);
4514 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4515 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4516 SCTP_INP_RLOCK(inp);
4517 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4518 SCTP_TCB_LOCK(stcb);
4519 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4520 SCTP_TCB_UNLOCK(stcb);
4522 SCTP_INP_RUNLOCK(inp);
4527 case SCTP_AUTH_DEACTIVATE_KEY:
4529 struct sctp_authkeyid *keyid;
4531 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4532 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4534 /* deactivate the key from the right place */
4536 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4537 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4540 SCTP_TCB_UNLOCK(stcb);
4542 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4543 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4544 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4545 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4546 SCTP_INP_WLOCK(inp);
4547 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4548 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4551 SCTP_INP_WUNLOCK(inp);
4553 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4554 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4555 SCTP_INP_RLOCK(inp);
4556 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4557 SCTP_TCB_LOCK(stcb);
4558 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4559 SCTP_TCB_UNLOCK(stcb);
4561 SCTP_INP_RUNLOCK(inp);
4566 case SCTP_ENABLE_STREAM_RESET:
4568 struct sctp_assoc_value *av;
4570 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4571 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4572 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4576 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4578 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4579 SCTP_TCB_UNLOCK(stcb);
4581 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4582 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4583 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4584 (av->assoc_id == SCTP_ALL_ASSOC)) {
4585 SCTP_INP_WLOCK(inp);
4586 inp->local_strreset_support = (uint8_t) av->assoc_value;
4587 SCTP_INP_WUNLOCK(inp);
4589 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4590 (av->assoc_id == SCTP_ALL_ASSOC)) {
4591 SCTP_INP_RLOCK(inp);
4592 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4593 SCTP_TCB_LOCK(stcb);
4594 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4595 SCTP_TCB_UNLOCK(stcb);
4597 SCTP_INP_RUNLOCK(inp);
4602 case SCTP_RESET_STREAMS:
4604 struct sctp_reset_streams *strrst;
4605 int i, send_out = 0;
4608 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4609 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4611 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4615 if (stcb->asoc.reconfig_supported == 0) {
4617 * Peer does not support the chunk type.
4619 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4621 SCTP_TCB_UNLOCK(stcb);
4624 if (sizeof(struct sctp_reset_streams) +
4625 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4627 SCTP_TCB_UNLOCK(stcb);
4630 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4632 if (stcb->asoc.stream_reset_outstanding) {
4633 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4635 SCTP_TCB_UNLOCK(stcb);
4639 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4642 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4643 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4645 SCTP_TCB_UNLOCK(stcb);
4648 if ((send_in == 0) && (send_out == 0)) {
4649 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4651 SCTP_TCB_UNLOCK(stcb);
4654 for (i = 0; i < strrst->srs_number_streams; i++) {
4656 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4657 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4662 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4663 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4669 SCTP_TCB_UNLOCK(stcb);
4676 if (strrst->srs_number_streams) {
4677 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4678 strm = strrst->srs_stream_list[i];
4679 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4680 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4686 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4687 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4688 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4695 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4696 strrst->srs_stream_list,
4697 send_in, 0, 0, 0, 0, 0);
4699 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4702 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4705 * For outgoing streams don't report any
4706 * problems in sending the request to the
4707 * application. XXX: Double check resetting
4712 SCTP_TCB_UNLOCK(stcb);
4715 case SCTP_ADD_STREAMS:
4717 struct sctp_add_streams *stradd;
4718 uint8_t addstream = 0;
4719 uint16_t add_o_strmcnt = 0;
4720 uint16_t add_i_strmcnt = 0;
4722 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4723 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4725 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4729 if (stcb->asoc.reconfig_supported == 0) {
4731 * Peer does not support the chunk type.
4733 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4735 SCTP_TCB_UNLOCK(stcb);
4738 if (stcb->asoc.stream_reset_outstanding) {
4739 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4741 SCTP_TCB_UNLOCK(stcb);
4744 if ((stradd->sas_outstrms == 0) &&
4745 (stradd->sas_instrms == 0)) {
4749 if (stradd->sas_outstrms) {
4751 /* We allocate here */
4752 add_o_strmcnt = stradd->sas_outstrms;
4753 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4754 /* You can't have more than 64k */
4759 if (stradd->sas_instrms) {
4764 * We allocate inside
4765 * sctp_send_str_reset_req()
4767 add_i_strmcnt = stradd->sas_instrms;
4768 cnt = add_i_strmcnt;
4769 cnt += stcb->asoc.streamincnt;
4770 if (cnt > 0x0000ffff) {
4771 /* You can't have more than 64k */
4775 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4776 /* More than you are allowed */
4781 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4782 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4784 SCTP_TCB_UNLOCK(stcb);
4787 case SCTP_RESET_ASSOC:
4792 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4793 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4795 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4799 if (stcb->asoc.reconfig_supported == 0) {
4801 * Peer does not support the chunk type.
4803 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4805 SCTP_TCB_UNLOCK(stcb);
4808 if (stcb->asoc.stream_reset_outstanding) {
4809 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4811 SCTP_TCB_UNLOCK(stcb);
4815 * Is there any data pending in the send or sent
4818 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4819 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4822 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4823 SCTP_TCB_UNLOCK(stcb);
4826 /* Do any streams have data queued? */
4827 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4828 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4832 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4833 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4834 SCTP_TCB_UNLOCK(stcb);
4837 case SCTP_CONNECT_X:
4838 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4839 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4843 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4845 case SCTP_CONNECT_X_DELAYED:
4846 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4847 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4851 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4853 case SCTP_CONNECT_X_COMPLETE:
4855 struct sockaddr *sa;
4857 /* FIXME MT: check correct? */
4858 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4861 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4862 SCTP_INP_RLOCK(inp);
4863 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4865 SCTP_TCB_LOCK(stcb);
4867 SCTP_INP_RUNLOCK(inp);
4870 * We increment here since
4871 * sctp_findassociation_ep_addr() wil do a
4872 * decrement if it finds the stcb as long as
4873 * the locked tcb (last argument) is NOT a
4876 SCTP_INP_INCR_REF(inp);
4877 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4879 SCTP_INP_DECR_REF(inp);
4884 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4888 if (stcb->asoc.delayed_connection == 1) {
4889 stcb->asoc.delayed_connection = 0;
4890 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4891 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4892 stcb->asoc.primary_destination,
4893 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4894 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4897 * already expired or did not use delayed
4900 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4903 SCTP_TCB_UNLOCK(stcb);
4906 case SCTP_MAX_BURST:
4908 struct sctp_assoc_value *av;
4910 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4911 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4914 stcb->asoc.max_burst = av->assoc_value;
4915 SCTP_TCB_UNLOCK(stcb);
4917 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4918 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4919 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4920 (av->assoc_id == SCTP_ALL_ASSOC)) {
4921 SCTP_INP_WLOCK(inp);
4922 inp->sctp_ep.max_burst = av->assoc_value;
4923 SCTP_INP_WUNLOCK(inp);
4925 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4926 (av->assoc_id == SCTP_ALL_ASSOC)) {
4927 SCTP_INP_RLOCK(inp);
4928 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4929 SCTP_TCB_LOCK(stcb);
4930 stcb->asoc.max_burst = av->assoc_value;
4931 SCTP_TCB_UNLOCK(stcb);
4933 SCTP_INP_RUNLOCK(inp);
4940 struct sctp_assoc_value *av;
4943 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4944 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4946 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4947 ovh = SCTP_MED_OVERHEAD;
4949 ovh = SCTP_MED_V4_OVERHEAD;
4952 if (av->assoc_value) {
4953 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4955 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4957 SCTP_TCB_UNLOCK(stcb);
4959 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4960 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4961 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4962 SCTP_INP_WLOCK(inp);
4964 * FIXME MT: I think this is not in
4965 * tune with the API ID
4967 if (av->assoc_value) {
4968 inp->sctp_frag_point = (av->assoc_value + ovh);
4970 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4972 SCTP_INP_WUNLOCK(inp);
4974 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4982 struct sctp_event_subscribe *events;
4984 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4986 SCTP_INP_WLOCK(inp);
4987 if (events->sctp_data_io_event) {
4988 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4990 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4993 if (events->sctp_association_event) {
4994 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4996 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4999 if (events->sctp_address_event) {
5000 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5002 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5005 if (events->sctp_send_failure_event) {
5006 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5008 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5011 if (events->sctp_peer_error_event) {
5012 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5014 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5017 if (events->sctp_shutdown_event) {
5018 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5020 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5023 if (events->sctp_partial_delivery_event) {
5024 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5026 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5029 if (events->sctp_adaptation_layer_event) {
5030 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5032 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5035 if (events->sctp_authentication_event) {
5036 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5038 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5041 if (events->sctp_sender_dry_event) {
5042 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5044 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5047 if (events->sctp_stream_reset_event) {
5048 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5050 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5052 SCTP_INP_WUNLOCK(inp);
5054 SCTP_INP_RLOCK(inp);
5055 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5056 SCTP_TCB_LOCK(stcb);
5057 if (events->sctp_association_event) {
5058 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5060 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5062 if (events->sctp_address_event) {
5063 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5065 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5067 if (events->sctp_send_failure_event) {
5068 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5070 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5072 if (events->sctp_peer_error_event) {
5073 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5075 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5077 if (events->sctp_shutdown_event) {
5078 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5080 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5082 if (events->sctp_partial_delivery_event) {
5083 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5085 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5087 if (events->sctp_adaptation_layer_event) {
5088 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5090 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5092 if (events->sctp_authentication_event) {
5093 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5095 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5097 if (events->sctp_sender_dry_event) {
5098 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5100 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5102 if (events->sctp_stream_reset_event) {
5103 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5105 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5107 SCTP_TCB_UNLOCK(stcb);
5110 * Send up the sender dry event only for 1-to-1
5113 if (events->sctp_sender_dry_event) {
5114 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5115 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5116 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5118 SCTP_TCB_LOCK(stcb);
5119 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5120 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5121 (stcb->asoc.stream_queue_cnt == 0)) {
5122 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5124 SCTP_TCB_UNLOCK(stcb);
5128 SCTP_INP_RUNLOCK(inp);
5131 case SCTP_ADAPTATION_LAYER:
5133 struct sctp_setadaptation *adap_bits;
5135 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5136 SCTP_INP_WLOCK(inp);
5137 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5138 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5139 SCTP_INP_WUNLOCK(inp);
5143 case SCTP_SET_INITIAL_DBG_SEQ:
5147 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5148 SCTP_INP_WLOCK(inp);
5149 inp->sctp_ep.initial_sequence_debug = *vvv;
5150 SCTP_INP_WUNLOCK(inp);
5154 case SCTP_DEFAULT_SEND_PARAM:
5156 struct sctp_sndrcvinfo *s_info;
5158 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5159 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5162 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5163 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5165 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5168 SCTP_TCB_UNLOCK(stcb);
5170 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5171 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5172 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5173 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5174 SCTP_INP_WLOCK(inp);
5175 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5176 SCTP_INP_WUNLOCK(inp);
5178 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5179 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5180 SCTP_INP_RLOCK(inp);
5181 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5182 SCTP_TCB_LOCK(stcb);
5183 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5184 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5186 SCTP_TCB_UNLOCK(stcb);
5188 SCTP_INP_RUNLOCK(inp);
5193 case SCTP_PEER_ADDR_PARAMS:
5195 struct sctp_paddrparams *paddrp;
5196 struct sctp_nets *net;
5197 struct sockaddr *addr;
5199 #if defined(INET) && defined(INET6)
5200 struct sockaddr_in sin_store;
5204 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5205 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5207 #if defined(INET) && defined(INET6)
5208 if (paddrp->spp_address.ss_family == AF_INET6) {
5209 struct sockaddr_in6 *sin6;
5211 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5212 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5213 in6_sin6_2_sin(&sin_store, sin6);
5214 addr = (struct sockaddr *)&sin_store;
5216 addr = (struct sockaddr *)&paddrp->spp_address;
5219 addr = (struct sockaddr *)&paddrp->spp_address;
5222 addr = (struct sockaddr *)&paddrp->spp_address;
5225 net = sctp_findnet(stcb, addr);
5228 * We increment here since
5229 * sctp_findassociation_ep_addr() wil do a
5230 * decrement if it finds the stcb as long as
5231 * the locked tcb (last argument) is NOT a
5235 SCTP_INP_INCR_REF(inp);
5236 stcb = sctp_findassociation_ep_addr(&inp, addr,
5239 SCTP_INP_DECR_REF(inp);
5242 if ((stcb != NULL) && (net == NULL)) {
5244 if (addr->sa_family == AF_INET) {
5246 struct sockaddr_in *sin;
5248 sin = (struct sockaddr_in *)addr;
5249 if (sin->sin_addr.s_addr != INADDR_ANY) {
5250 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5251 SCTP_TCB_UNLOCK(stcb);
5258 if (addr->sa_family == AF_INET6) {
5259 struct sockaddr_in6 *sin6;
5261 sin6 = (struct sockaddr_in6 *)addr;
5262 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5263 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5264 SCTP_TCB_UNLOCK(stcb);
5271 error = EAFNOSUPPORT;
5272 SCTP_TCB_UNLOCK(stcb);
5273 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5278 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5280 SCTP_TCB_UNLOCK(stcb);
5281 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5284 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5286 SCTP_TCB_UNLOCK(stcb);
5287 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5291 /************************TCB SPECIFIC SET ******************/
5293 /************************NET SPECIFIC SET ******************/
5294 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5295 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5296 !(net->dest_state & SCTP_ADDR_NOHB)) {
5297 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5298 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5300 net->dest_state |= SCTP_ADDR_NOHB;
5302 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5303 if (paddrp->spp_hbinterval) {
5304 net->heart_beat_delay = paddrp->spp_hbinterval;
5305 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5306 net->heart_beat_delay = 0;
5308 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5309 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5310 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5311 net->dest_state &= ~SCTP_ADDR_NOHB;
5313 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5315 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5316 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5317 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5319 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5320 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5321 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5322 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5324 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5325 net->mtu = paddrp->spp_pathmtu;
5326 switch (net->ro._l_addr.sa.sa_family) {
5329 net->mtu += SCTP_MIN_V4_OVERHEAD;
5334 net->mtu += SCTP_MIN_OVERHEAD;
5340 if (net->mtu < stcb->asoc.smallest_mtu) {
5341 sctp_pathmtu_adjustment(stcb, net->mtu);
5344 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5345 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5346 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5348 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5350 if (paddrp->spp_pathmaxrxt) {
5351 if (net->dest_state & SCTP_ADDR_PF) {
5352 if (net->error_count > paddrp->spp_pathmaxrxt) {
5353 net->dest_state &= ~SCTP_ADDR_PF;
5356 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5357 (net->error_count > net->pf_threshold)) {
5358 net->dest_state |= SCTP_ADDR_PF;
5359 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5360 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5361 stcb->sctp_ep, stcb, net,
5362 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5363 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5366 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5367 if (net->error_count > paddrp->spp_pathmaxrxt) {
5368 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5369 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5372 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5373 net->dest_state |= SCTP_ADDR_REACHABLE;
5374 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5377 net->failure_threshold = paddrp->spp_pathmaxrxt;
5379 if (paddrp->spp_flags & SPP_DSCP) {
5380 net->dscp = paddrp->spp_dscp & 0xfc;
5384 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5385 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5386 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5387 net->flowlabel |= 0x80000000;
5392 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5393 if (paddrp->spp_pathmaxrxt != 0) {
5394 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5395 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5396 if (net->dest_state & SCTP_ADDR_PF) {
5397 if (net->error_count > paddrp->spp_pathmaxrxt) {
5398 net->dest_state &= ~SCTP_ADDR_PF;
5401 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5402 (net->error_count > net->pf_threshold)) {
5403 net->dest_state |= SCTP_ADDR_PF;
5404 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5405 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5406 stcb->sctp_ep, stcb, net,
5407 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5408 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5411 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5412 if (net->error_count > paddrp->spp_pathmaxrxt) {
5413 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5414 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5417 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5418 net->dest_state |= SCTP_ADDR_REACHABLE;
5419 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5422 net->failure_threshold = paddrp->spp_pathmaxrxt;
5425 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5426 if (paddrp->spp_hbinterval != 0) {
5427 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5428 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5429 stcb->asoc.heart_beat_delay = 0;
5431 /* Turn back on the timer */
5432 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5433 if (paddrp->spp_hbinterval != 0) {
5434 net->heart_beat_delay = paddrp->spp_hbinterval;
5435 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5436 net->heart_beat_delay = 0;
5438 if (net->dest_state & SCTP_ADDR_NOHB) {
5439 net->dest_state &= ~SCTP_ADDR_NOHB;
5441 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5442 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5443 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5445 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5447 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5448 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5449 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5450 net->dest_state |= SCTP_ADDR_NOHB;
5451 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5452 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5454 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5458 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5460 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5461 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5462 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5463 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5464 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5466 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5467 net->mtu = paddrp->spp_pathmtu;
5468 switch (net->ro._l_addr.sa.sa_family) {
5471 net->mtu += SCTP_MIN_V4_OVERHEAD;
5476 net->mtu += SCTP_MIN_OVERHEAD;
5482 if (net->mtu < stcb->asoc.smallest_mtu) {
5483 sctp_pathmtu_adjustment(stcb, net->mtu);
5486 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5488 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5489 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5490 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5491 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5493 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5495 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5497 if (paddrp->spp_flags & SPP_DSCP) {
5498 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5499 net->dscp = paddrp->spp_dscp & 0xfc;
5502 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5503 stcb->asoc.default_dscp |= 0x01;
5506 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5507 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5508 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5509 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5510 net->flowlabel |= 0x80000000;
5513 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5514 stcb->asoc.default_flowlabel |= 0x80000000;
5518 SCTP_TCB_UNLOCK(stcb);
5520 /************************NO TCB, SET TO default stuff ******************/
5521 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5522 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5523 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5524 SCTP_INP_WLOCK(inp);
5526 * For the TOS/FLOWLABEL stuff you
5527 * set it with the options on the
5530 if (paddrp->spp_pathmaxrxt != 0) {
5531 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5533 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5534 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5535 else if (paddrp->spp_hbinterval != 0) {
5536 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5537 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5538 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5540 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5541 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5542 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5543 } else if (paddrp->spp_hbinterval) {
5544 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5546 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5547 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5548 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5550 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5551 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5552 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5553 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5555 if (paddrp->spp_flags & SPP_DSCP) {
5556 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5557 inp->sctp_ep.default_dscp |= 0x01;
5560 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5561 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5562 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5563 inp->sctp_ep.default_flowlabel |= 0x80000000;
5567 SCTP_INP_WUNLOCK(inp);
5569 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5577 struct sctp_rtoinfo *srto;
5578 uint32_t new_init, new_min, new_max;
5580 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5581 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5584 if (srto->srto_initial)
5585 new_init = srto->srto_initial;
5587 new_init = stcb->asoc.initial_rto;
5589 new_max = srto->srto_max;
5591 new_max = stcb->asoc.maxrto;
5593 new_min = srto->srto_min;
5595 new_min = stcb->asoc.minrto;
5596 if ((new_min <= new_init) && (new_init <= new_max)) {
5597 stcb->asoc.initial_rto = new_init;
5598 stcb->asoc.maxrto = new_max;
5599 stcb->asoc.minrto = new_min;
5601 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5604 SCTP_TCB_UNLOCK(stcb);
5606 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5607 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5608 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5609 SCTP_INP_WLOCK(inp);
5610 if (srto->srto_initial)
5611 new_init = srto->srto_initial;
5613 new_init = inp->sctp_ep.initial_rto;
5615 new_max = srto->srto_max;
5617 new_max = inp->sctp_ep.sctp_maxrto;
5619 new_min = srto->srto_min;
5621 new_min = inp->sctp_ep.sctp_minrto;
5622 if ((new_min <= new_init) && (new_init <= new_max)) {
5623 inp->sctp_ep.initial_rto = new_init;
5624 inp->sctp_ep.sctp_maxrto = new_max;
5625 inp->sctp_ep.sctp_minrto = new_min;
5627 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5630 SCTP_INP_WUNLOCK(inp);
5632 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5638 case SCTP_ASSOCINFO:
5640 struct sctp_assocparams *sasoc;
5642 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5643 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5644 if (sasoc->sasoc_cookie_life) {
5645 /* boundary check the cookie life */
5646 if (sasoc->sasoc_cookie_life < 1000)
5647 sasoc->sasoc_cookie_life = 1000;
5648 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5649 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5653 if (sasoc->sasoc_asocmaxrxt)
5654 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5655 if (sasoc->sasoc_cookie_life) {
5656 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5658 SCTP_TCB_UNLOCK(stcb);
5660 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5661 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5662 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5663 SCTP_INP_WLOCK(inp);
5664 if (sasoc->sasoc_asocmaxrxt)
5665 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5666 if (sasoc->sasoc_cookie_life) {
5667 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5669 SCTP_INP_WUNLOCK(inp);
5671 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5679 struct sctp_initmsg *sinit;
5681 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5682 SCTP_INP_WLOCK(inp);
5683 if (sinit->sinit_num_ostreams)
5684 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5686 if (sinit->sinit_max_instreams)
5687 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5689 if (sinit->sinit_max_attempts)
5690 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5692 if (sinit->sinit_max_init_timeo)
5693 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5694 SCTP_INP_WUNLOCK(inp);
5697 case SCTP_PRIMARY_ADDR:
5699 struct sctp_setprim *spa;
5700 struct sctp_nets *net;
5701 struct sockaddr *addr;
5703 #if defined(INET) && defined(INET6)
5704 struct sockaddr_in sin_store;
5708 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5709 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5711 #if defined(INET) && defined(INET6)
5712 if (spa->ssp_addr.ss_family == AF_INET6) {
5713 struct sockaddr_in6 *sin6;
5715 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5716 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5717 in6_sin6_2_sin(&sin_store, sin6);
5718 addr = (struct sockaddr *)&sin_store;
5720 addr = (struct sockaddr *)&spa->ssp_addr;
5723 addr = (struct sockaddr *)&spa->ssp_addr;
5726 addr = (struct sockaddr *)&spa->ssp_addr;
5729 net = sctp_findnet(stcb, addr);
5732 * We increment here since
5733 * sctp_findassociation_ep_addr() wil do a
5734 * decrement if it finds the stcb as long as
5735 * the locked tcb (last argument) is NOT a
5739 SCTP_INP_INCR_REF(inp);
5740 stcb = sctp_findassociation_ep_addr(&inp, addr,
5743 SCTP_INP_DECR_REF(inp);
5747 if ((stcb != NULL) && (net != NULL)) {
5748 if (net != stcb->asoc.primary_destination) {
5749 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5750 /* Ok we need to set it */
5751 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5752 if ((stcb->asoc.alternate) &&
5753 (!(net->dest_state & SCTP_ADDR_PF)) &&
5754 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5755 sctp_free_remote_addr(stcb->asoc.alternate);
5756 stcb->asoc.alternate = NULL;
5759 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5763 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);
5772 SCTP_TCB_UNLOCK(stcb);
5776 case SCTP_SET_DYNAMIC_PRIMARY:
5778 union sctp_sockstore *ss;
5780 error = priv_check(curthread,
5781 PRIV_NETINET_RESERVEDPORT);
5785 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5786 /* SUPER USER CHECK? */
5787 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5790 case SCTP_SET_PEER_PRIMARY_ADDR:
5792 struct sctp_setpeerprim *sspp;
5793 struct sockaddr *addr;
5795 #if defined(INET) && defined(INET6)
5796 struct sockaddr_in sin_store;
5800 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5801 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5803 struct sctp_ifa *ifa;
5805 #if defined(INET) && defined(INET6)
5806 if (sspp->sspp_addr.ss_family == AF_INET6) {
5807 struct sockaddr_in6 *sin6;
5809 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5810 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5811 in6_sin6_2_sin(&sin_store, sin6);
5812 addr = (struct sockaddr *)&sin_store;
5814 addr = (struct sockaddr *)&sspp->sspp_addr;
5817 addr = (struct sockaddr *)&sspp->sspp_addr;
5820 addr = (struct sockaddr *)&sspp->sspp_addr;
5822 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5824 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5828 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5830 * Must validate the ifa found is in
5833 struct sctp_laddr *laddr;
5836 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5837 if (laddr->ifa == NULL) {
5838 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5842 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5843 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5846 if (laddr->ifa == ifa) {
5852 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5857 switch (addr->sa_family) {
5861 struct sockaddr_in *sin;
5863 sin = (struct sockaddr_in *)addr;
5864 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5865 &sin->sin_addr) != 0) {
5866 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5876 struct sockaddr_in6 *sin6;
5878 sin6 = (struct sockaddr_in6 *)addr;
5879 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5880 &sin6->sin6_addr) != 0) {
5881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5889 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5894 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5895 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5898 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5900 SCTP_TCB_UNLOCK(stcb);
5902 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5907 case SCTP_BINDX_ADD_ADDR:
5909 struct sctp_getaddresses *addrs;
5912 td = (struct thread *)p;
5913 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5916 if (addrs->addr->sa_family == AF_INET) {
5917 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5918 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5922 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5923 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5929 if (addrs->addr->sa_family == AF_INET6) {
5930 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5931 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5935 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5936 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5937 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5943 error = EAFNOSUPPORT;
5946 sctp_bindx_add_address(so, inp, addrs->addr,
5947 addrs->sget_assoc_id, vrf_id,
5951 case SCTP_BINDX_REM_ADDR:
5953 struct sctp_getaddresses *addrs;
5956 td = (struct thread *)p;
5958 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5960 if (addrs->addr->sa_family == AF_INET) {
5961 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5962 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5966 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5967 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5973 if (addrs->addr->sa_family == AF_INET6) {
5974 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5975 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5980 (error = prison_local_ip6(td->td_ucred,
5981 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5982 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5983 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5989 error = EAFNOSUPPORT;
5992 sctp_bindx_delete_address(inp, addrs->addr,
5993 addrs->sget_assoc_id, vrf_id,
5999 struct sctp_event *event;
6000 uint32_t event_type;
6002 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6003 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6004 switch (event->se_type) {
6005 case SCTP_ASSOC_CHANGE:
6006 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6008 case SCTP_PEER_ADDR_CHANGE:
6009 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6011 case SCTP_REMOTE_ERROR:
6012 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6014 case SCTP_SEND_FAILED:
6015 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6017 case SCTP_SHUTDOWN_EVENT:
6018 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6020 case SCTP_ADAPTATION_INDICATION:
6021 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6023 case SCTP_PARTIAL_DELIVERY_EVENT:
6024 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6026 case SCTP_AUTHENTICATION_EVENT:
6027 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6029 case SCTP_STREAM_RESET_EVENT:
6030 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6032 case SCTP_SENDER_DRY_EVENT:
6033 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6035 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6037 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6040 case SCTP_ASSOC_RESET_EVENT:
6041 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6043 case SCTP_STREAM_CHANGE_EVENT:
6044 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6046 case SCTP_SEND_FAILED_EVENT:
6047 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6051 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6055 if (event_type > 0) {
6058 sctp_stcb_feature_on(inp, stcb, event_type);
6059 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6060 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6061 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6062 (stcb->asoc.stream_queue_cnt == 0)) {
6063 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6067 sctp_stcb_feature_off(inp, stcb, event_type);
6069 SCTP_TCB_UNLOCK(stcb);
6072 * We don't want to send up a storm
6073 * of events, so return an error for
6076 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6077 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6078 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6079 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6080 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6081 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6085 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6086 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6087 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6088 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6089 SCTP_INP_WLOCK(inp);
6091 sctp_feature_on(inp, event_type);
6093 sctp_feature_off(inp, event_type);
6095 SCTP_INP_WUNLOCK(inp);
6097 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6098 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6099 SCTP_INP_RLOCK(inp);
6100 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6101 SCTP_TCB_LOCK(stcb);
6103 sctp_stcb_feature_on(inp, stcb, event_type);
6105 sctp_stcb_feature_off(inp, stcb, event_type);
6107 SCTP_TCB_UNLOCK(stcb);
6109 SCTP_INP_RUNLOCK(inp);
6115 case SCTP_RECVRCVINFO:
6119 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6120 SCTP_INP_WLOCK(inp);
6122 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6124 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6126 SCTP_INP_WUNLOCK(inp);
6129 case SCTP_RECVNXTINFO:
6133 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6134 SCTP_INP_WLOCK(inp);
6136 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6138 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6140 SCTP_INP_WUNLOCK(inp);
6143 case SCTP_DEFAULT_SNDINFO:
6145 struct sctp_sndinfo *info;
6148 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6149 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6152 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6153 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6154 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6155 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6156 stcb->asoc.def_send.sinfo_flags |= policy;
6157 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6158 stcb->asoc.def_send.sinfo_context = info->snd_context;
6160 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6163 SCTP_TCB_UNLOCK(stcb);
6165 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6166 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6167 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6168 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6169 SCTP_INP_WLOCK(inp);
6170 inp->def_send.sinfo_stream = info->snd_sid;
6171 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6172 inp->def_send.sinfo_flags = info->snd_flags;
6173 inp->def_send.sinfo_flags |= policy;
6174 inp->def_send.sinfo_ppid = info->snd_ppid;
6175 inp->def_send.sinfo_context = info->snd_context;
6176 SCTP_INP_WUNLOCK(inp);
6178 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6179 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6180 SCTP_INP_RLOCK(inp);
6181 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6182 SCTP_TCB_LOCK(stcb);
6183 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6184 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6185 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6186 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6187 stcb->asoc.def_send.sinfo_flags |= policy;
6188 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6189 stcb->asoc.def_send.sinfo_context = info->snd_context;
6191 SCTP_TCB_UNLOCK(stcb);
6193 SCTP_INP_RUNLOCK(inp);
6198 case SCTP_DEFAULT_PRINFO:
6200 struct sctp_default_prinfo *info;
6202 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6203 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6205 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6206 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6211 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6212 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6213 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6214 SCTP_TCB_UNLOCK(stcb);
6216 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6217 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6218 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6219 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6220 SCTP_INP_WLOCK(inp);
6221 inp->def_send.sinfo_flags &= 0xfff0;
6222 inp->def_send.sinfo_flags |= info->pr_policy;
6223 inp->def_send.sinfo_timetolive = info->pr_value;
6224 SCTP_INP_WUNLOCK(inp);
6226 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6227 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6228 SCTP_INP_RLOCK(inp);
6229 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6230 SCTP_TCB_LOCK(stcb);
6231 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6232 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6233 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6234 SCTP_TCB_UNLOCK(stcb);
6236 SCTP_INP_RUNLOCK(inp);
6241 case SCTP_PEER_ADDR_THLDS:
6242 /* Applies to the specific association */
6244 struct sctp_paddrthlds *thlds;
6245 struct sctp_nets *net;
6246 struct sockaddr *addr;
6248 #if defined(INET) && defined(INET6)
6249 struct sockaddr_in sin_store;
6253 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6254 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6256 #if defined(INET) && defined(INET6)
6257 if (thlds->spt_address.ss_family == AF_INET6) {
6258 struct sockaddr_in6 *sin6;
6260 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6261 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6262 in6_sin6_2_sin(&sin_store, sin6);
6263 addr = (struct sockaddr *)&sin_store;
6265 addr = (struct sockaddr *)&thlds->spt_address;
6268 addr = (struct sockaddr *)&thlds->spt_address;
6271 addr = (struct sockaddr *)&thlds->spt_address;
6274 net = sctp_findnet(stcb, addr);
6277 * We increment here since
6278 * sctp_findassociation_ep_addr() wil do a
6279 * decrement if it finds the stcb as long as
6280 * the locked tcb (last argument) is NOT a
6284 SCTP_INP_INCR_REF(inp);
6285 stcb = sctp_findassociation_ep_addr(&inp, addr,
6288 SCTP_INP_DECR_REF(inp);
6291 if ((stcb != NULL) && (net == NULL)) {
6293 if (addr->sa_family == AF_INET) {
6295 struct sockaddr_in *sin;
6297 sin = (struct sockaddr_in *)addr;
6298 if (sin->sin_addr.s_addr != INADDR_ANY) {
6299 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6300 SCTP_TCB_UNLOCK(stcb);
6307 if (addr->sa_family == AF_INET6) {
6308 struct sockaddr_in6 *sin6;
6310 sin6 = (struct sockaddr_in6 *)addr;
6311 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6312 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6313 SCTP_TCB_UNLOCK(stcb);
6320 error = EAFNOSUPPORT;
6321 SCTP_TCB_UNLOCK(stcb);
6322 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6326 if (thlds->spt_pathcpthld != 0xffff) {
6328 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6333 net->failure_threshold = thlds->spt_pathmaxrxt;
6334 net->pf_threshold = thlds->spt_pathpfthld;
6335 if (net->dest_state & SCTP_ADDR_PF) {
6336 if ((net->error_count > net->failure_threshold) ||
6337 (net->error_count <= net->pf_threshold)) {
6338 net->dest_state &= ~SCTP_ADDR_PF;
6341 if ((net->error_count > net->pf_threshold) &&
6342 (net->error_count <= net->failure_threshold)) {
6343 net->dest_state |= SCTP_ADDR_PF;
6344 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6345 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6346 stcb->sctp_ep, stcb, net,
6347 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6348 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6351 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6352 if (net->error_count > net->failure_threshold) {
6353 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6354 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6357 if (net->error_count <= net->failure_threshold) {
6358 net->dest_state |= SCTP_ADDR_REACHABLE;
6359 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6363 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6364 net->failure_threshold = thlds->spt_pathmaxrxt;
6365 net->pf_threshold = thlds->spt_pathpfthld;
6366 if (net->dest_state & SCTP_ADDR_PF) {
6367 if ((net->error_count > net->failure_threshold) ||
6368 (net->error_count <= net->pf_threshold)) {
6369 net->dest_state &= ~SCTP_ADDR_PF;
6372 if ((net->error_count > net->pf_threshold) &&
6373 (net->error_count <= net->failure_threshold)) {
6374 net->dest_state |= SCTP_ADDR_PF;
6375 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6376 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6377 stcb->sctp_ep, stcb, net,
6378 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6379 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6382 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6383 if (net->error_count > net->failure_threshold) {
6384 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6385 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6388 if (net->error_count <= net->failure_threshold) {
6389 net->dest_state |= SCTP_ADDR_REACHABLE;
6390 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6394 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6395 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6397 SCTP_TCB_UNLOCK(stcb);
6399 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6400 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6401 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6402 SCTP_INP_WLOCK(inp);
6403 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6404 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6405 SCTP_INP_WUNLOCK(inp);
6407 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6413 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6415 struct sctp_udpencaps *encaps;
6416 struct sctp_nets *net;
6417 struct sockaddr *addr;
6419 #if defined(INET) && defined(INET6)
6420 struct sockaddr_in sin_store;
6424 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6425 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6427 #if defined(INET) && defined(INET6)
6428 if (encaps->sue_address.ss_family == AF_INET6) {
6429 struct sockaddr_in6 *sin6;
6431 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6432 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6433 in6_sin6_2_sin(&sin_store, sin6);
6434 addr = (struct sockaddr *)&sin_store;
6436 addr = (struct sockaddr *)&encaps->sue_address;
6439 addr = (struct sockaddr *)&encaps->sue_address;
6442 addr = (struct sockaddr *)&encaps->sue_address;
6445 net = sctp_findnet(stcb, addr);
6448 * We increment here since
6449 * sctp_findassociation_ep_addr() wil do a
6450 * decrement if it finds the stcb as long as
6451 * the locked tcb (last argument) is NOT a
6455 SCTP_INP_INCR_REF(inp);
6456 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6458 SCTP_INP_DECR_REF(inp);
6461 if ((stcb != NULL) && (net == NULL)) {
6463 if (addr->sa_family == AF_INET) {
6465 struct sockaddr_in *sin;
6467 sin = (struct sockaddr_in *)addr;
6468 if (sin->sin_addr.s_addr != INADDR_ANY) {
6469 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6470 SCTP_TCB_UNLOCK(stcb);
6477 if (addr->sa_family == AF_INET6) {
6478 struct sockaddr_in6 *sin6;
6480 sin6 = (struct sockaddr_in6 *)addr;
6481 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6482 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6483 SCTP_TCB_UNLOCK(stcb);
6490 error = EAFNOSUPPORT;
6491 SCTP_TCB_UNLOCK(stcb);
6492 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6498 net->port = encaps->sue_port;
6500 stcb->asoc.port = encaps->sue_port;
6502 SCTP_TCB_UNLOCK(stcb);
6504 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6505 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6506 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6507 SCTP_INP_WLOCK(inp);
6508 inp->sctp_ep.port = encaps->sue_port;
6509 SCTP_INP_WUNLOCK(inp);
6511 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6517 case SCTP_ECN_SUPPORTED:
6519 struct sctp_assoc_value *av;
6521 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6522 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6525 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6527 SCTP_TCB_UNLOCK(stcb);
6529 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6530 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6531 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6532 SCTP_INP_WLOCK(inp);
6533 if (av->assoc_value == 0) {
6534 inp->ecn_supported = 0;
6536 inp->ecn_supported = 1;
6538 SCTP_INP_WUNLOCK(inp);
6540 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6546 case SCTP_PR_SUPPORTED:
6548 struct sctp_assoc_value *av;
6550 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6551 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6554 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6556 SCTP_TCB_UNLOCK(stcb);
6558 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6559 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6560 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6561 SCTP_INP_WLOCK(inp);
6562 if (av->assoc_value == 0) {
6563 inp->prsctp_supported = 0;
6565 inp->prsctp_supported = 1;
6567 SCTP_INP_WUNLOCK(inp);
6569 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6575 case SCTP_AUTH_SUPPORTED:
6577 struct sctp_assoc_value *av;
6579 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6580 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6583 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6585 SCTP_TCB_UNLOCK(stcb);
6587 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6588 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6589 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6590 if ((av->assoc_value == 0) &&
6591 (inp->asconf_supported == 1)) {
6593 * AUTH is required for
6596 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6599 SCTP_INP_WLOCK(inp);
6600 if (av->assoc_value == 0) {
6601 inp->auth_supported = 0;
6603 inp->auth_supported = 1;
6605 SCTP_INP_WUNLOCK(inp);
6608 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6614 case SCTP_ASCONF_SUPPORTED:
6616 struct sctp_assoc_value *av;
6618 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6619 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6622 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6624 SCTP_TCB_UNLOCK(stcb);
6626 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6627 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6628 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6629 if ((av->assoc_value != 0) &&
6630 (inp->auth_supported == 0)) {
6632 * AUTH is required for
6635 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6638 SCTP_INP_WLOCK(inp);
6639 if (av->assoc_value == 0) {
6640 inp->asconf_supported = 0;
6641 sctp_auth_delete_chunk(SCTP_ASCONF,
6642 inp->sctp_ep.local_auth_chunks);
6643 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6644 inp->sctp_ep.local_auth_chunks);
6646 inp->asconf_supported = 1;
6647 sctp_auth_add_chunk(SCTP_ASCONF,
6648 inp->sctp_ep.local_auth_chunks);
6649 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6650 inp->sctp_ep.local_auth_chunks);
6652 SCTP_INP_WUNLOCK(inp);
6655 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6661 case SCTP_RECONFIG_SUPPORTED:
6663 struct sctp_assoc_value *av;
6665 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6666 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6669 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6671 SCTP_TCB_UNLOCK(stcb);
6673 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6674 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6675 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6676 SCTP_INP_WLOCK(inp);
6677 if (av->assoc_value == 0) {
6678 inp->reconfig_supported = 0;
6680 inp->reconfig_supported = 1;
6682 SCTP_INP_WUNLOCK(inp);
6684 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6690 case SCTP_NRSACK_SUPPORTED:
6692 struct sctp_assoc_value *av;
6694 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6695 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6698 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6700 SCTP_TCB_UNLOCK(stcb);
6702 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6703 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6704 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6705 SCTP_INP_WLOCK(inp);
6706 if (av->assoc_value == 0) {
6707 inp->nrsack_supported = 0;
6709 inp->nrsack_supported = 1;
6711 SCTP_INP_WUNLOCK(inp);
6713 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6719 case SCTP_PKTDROP_SUPPORTED:
6721 struct sctp_assoc_value *av;
6723 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6724 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6727 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6729 SCTP_TCB_UNLOCK(stcb);
6731 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6732 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6733 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6734 SCTP_INP_WLOCK(inp);
6735 if (av->assoc_value == 0) {
6736 inp->pktdrop_supported = 0;
6738 inp->pktdrop_supported = 1;
6740 SCTP_INP_WUNLOCK(inp);
6742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6750 struct sctp_assoc_value *av;
6751 struct sctp_nets *net;
6753 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6754 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6757 stcb->asoc.max_cwnd = av->assoc_value;
6758 if (stcb->asoc.max_cwnd > 0) {
6759 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6760 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6761 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6762 net->cwnd = stcb->asoc.max_cwnd;
6763 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6764 net->cwnd = net->mtu - sizeof(struct sctphdr);
6769 SCTP_TCB_UNLOCK(stcb);
6771 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6772 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6773 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6774 SCTP_INP_WLOCK(inp);
6775 inp->max_cwnd = av->assoc_value;
6776 SCTP_INP_WUNLOCK(inp);
6778 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6785 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6786 error = ENOPROTOOPT;
6788 } /* end switch (opt) */
6793 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6795 void *optval = NULL;
6799 struct sctp_inpcb *inp;
6801 if ((sopt->sopt_level == SOL_SOCKET) &&
6802 (sopt->sopt_name == SO_SETFIB)) {
6803 inp = (struct sctp_inpcb *)so->so_pcb;
6805 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6808 SCTP_INP_WLOCK(inp);
6809 inp->fibnum = so->so_fibnum;
6810 SCTP_INP_WUNLOCK(inp);
6813 if (sopt->sopt_level != IPPROTO_SCTP) {
6814 /* wrong proto level... send back up to IP */
6816 if (INP_CHECK_SOCKAF(so, AF_INET6))
6817 error = ip6_ctloutput(so, sopt);
6819 #if defined(INET) && defined(INET6)
6823 error = ip_ctloutput(so, sopt);
6827 optsize = sopt->sopt_valsize;
6829 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6830 if (optval == NULL) {
6831 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6834 error = sooptcopyin(sopt, optval, optsize, optsize);
6836 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6840 p = (void *)sopt->sopt_td;
6841 if (sopt->sopt_dir == SOPT_SET) {
6842 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6843 } else if (sopt->sopt_dir == SOPT_GET) {
6844 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6846 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6849 if ((error == 0) && (optval != NULL)) {
6850 error = sooptcopyout(sopt, optval, optsize);
6851 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6852 } else if (optval != NULL) {
6853 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6861 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6864 int create_lock_on = 0;
6866 struct sctp_inpcb *inp;
6867 struct sctp_tcb *stcb = NULL;
6869 inp = (struct sctp_inpcb *)so->so_pcb;
6871 /* I made the same as TCP since we are not setup? */
6872 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6873 return (ECONNRESET);
6876 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6879 switch (addr->sa_family) {
6883 struct sockaddr_in6 *sin6p;
6885 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6886 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6889 sin6p = (struct sockaddr_in6 *)addr;
6890 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6891 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6900 struct sockaddr_in *sinp;
6902 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6903 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6906 sinp = (struct sockaddr_in *)addr;
6907 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6908 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6915 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6916 return (EAFNOSUPPORT);
6918 SCTP_INP_INCR_REF(inp);
6919 SCTP_ASOC_CREATE_LOCK(inp);
6923 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6924 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6925 /* Should I really unlock ? */
6926 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6931 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6932 (addr->sa_family == AF_INET6)) {
6933 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6938 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6939 SCTP_PCB_FLAGS_UNBOUND) {
6940 /* Bind a ephemeral port */
6941 error = sctp_inpcb_bind(so, NULL, NULL, p);
6946 /* Now do we connect? */
6947 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6948 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6949 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6953 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6954 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6955 /* We are already connected AND the TCP model */
6956 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6960 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6961 SCTP_INP_RLOCK(inp);
6962 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6963 SCTP_INP_RUNLOCK(inp);
6966 * We increment here since sctp_findassociation_ep_addr()
6967 * will do a decrement if it finds the stcb as long as the
6968 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6970 SCTP_INP_INCR_REF(inp);
6971 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6973 SCTP_INP_DECR_REF(inp);
6975 SCTP_TCB_UNLOCK(stcb);
6979 /* Already have or am bring up an association */
6980 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
6984 vrf_id = inp->def_vrf_id;
6985 /* We are GOOD to go */
6986 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
6987 inp->sctp_ep.pre_open_stream_count,
6988 inp->sctp_ep.port, p);
6990 /* Gak! no memory */
6993 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
6994 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
6995 /* Set the connected flag so we can queue data */
6998 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
6999 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7001 /* initialize authentication parameters for the assoc */
7002 sctp_initialize_auth_params(inp, stcb);
7004 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7005 SCTP_TCB_UNLOCK(stcb);
7007 if (create_lock_on) {
7008 SCTP_ASOC_CREATE_UNLOCK(inp);
7010 SCTP_INP_DECR_REF(inp);
7017 sctp_listen(struct socket *so, int backlog, struct thread *p)
7020 * Note this module depends on the protocol processing being called
7021 * AFTER any socket level flags and backlog are applied to the
7022 * socket. The traditional way that the socket flags are applied is
7023 * AFTER protocol processing. We have made a change to the
7024 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7025 * place if the socket API for SCTP is to work properly.
7029 struct sctp_inpcb *inp;
7031 inp = (struct sctp_inpcb *)so->so_pcb;
7033 /* I made the same as TCP since we are not setup? */
7034 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7035 return (ECONNRESET);
7037 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7038 /* See if we have a listener */
7039 struct sctp_inpcb *tinp;
7040 union sctp_sockstore store;
7042 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7044 struct sctp_laddr *laddr;
7046 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7047 memcpy(&store, &laddr->ifa->address, sizeof(store));
7048 switch (store.sa.sa_family) {
7051 store.sin.sin_port = inp->sctp_lport;
7056 store.sin6.sin6_port = inp->sctp_lport;
7062 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7063 if (tinp && (tinp != inp) &&
7064 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7065 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7066 (tinp->sctp_socket->so_qlimit)) {
7068 * we have a listener already and
7071 SCTP_INP_DECR_REF(tinp);
7072 return (EADDRINUSE);
7074 SCTP_INP_DECR_REF(tinp);
7078 /* Setup a local addr bound all */
7079 memset(&store, 0, sizeof(store));
7081 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7082 store.sa.sa_family = AF_INET6;
7083 store.sa.sa_len = sizeof(struct sockaddr_in6);
7087 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7088 store.sa.sa_family = AF_INET;
7089 store.sa.sa_len = sizeof(struct sockaddr_in);
7092 switch (store.sa.sa_family) {
7095 store.sin.sin_port = inp->sctp_lport;
7100 store.sin6.sin6_port = inp->sctp_lport;
7106 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7107 if (tinp && (tinp != inp) &&
7108 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7109 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7110 (tinp->sctp_socket->so_qlimit)) {
7112 * we have a listener already and its not
7115 SCTP_INP_DECR_REF(tinp);
7116 return (EADDRINUSE);
7118 SCTP_INP_DECR_REF(tinp);
7122 SCTP_INP_RLOCK(inp);
7123 #ifdef SCTP_LOCK_LOGGING
7124 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7125 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7129 error = solisten_proto_check(so);
7132 SCTP_INP_RUNLOCK(inp);
7135 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7136 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7138 * The unlucky case - We are in the tcp pool with this guy.
7139 * - Someone else is in the main inp slot. - We must move
7140 * this guy (the listener) to the main slot - We must then
7141 * move the guy that was listener to the TCP Pool.
7143 if (sctp_swap_inpcb_for_listen(inp)) {
7144 SCTP_INP_RUNLOCK(inp);
7145 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7146 return (EADDRINUSE);
7149 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7150 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7151 /* We are already connected AND the TCP model */
7152 SCTP_INP_RUNLOCK(inp);
7153 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7154 return (EADDRINUSE);
7156 SCTP_INP_RUNLOCK(inp);
7157 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7158 /* We must do a bind. */
7159 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7160 /* bind error, probably perm */
7165 /* It appears for 7.0 and on, we must always call this. */
7166 solisten_proto(so, backlog);
7167 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7168 /* remove the ACCEPTCONN flag for one-to-many sockets */
7169 so->so_options &= ~SO_ACCEPTCONN;
7172 /* turning off listen */
7173 so->so_options &= ~SO_ACCEPTCONN;
7179 static int sctp_defered_wakeup_cnt = 0;
7182 sctp_accept(struct socket *so, struct sockaddr **addr)
7184 struct sctp_tcb *stcb;
7185 struct sctp_inpcb *inp;
7186 union sctp_sockstore store;
7192 inp = (struct sctp_inpcb *)so->so_pcb;
7195 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7196 return (ECONNRESET);
7198 SCTP_INP_RLOCK(inp);
7199 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7200 SCTP_INP_RUNLOCK(inp);
7201 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7202 return (EOPNOTSUPP);
7204 if (so->so_state & SS_ISDISCONNECTED) {
7205 SCTP_INP_RUNLOCK(inp);
7206 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7207 return (ECONNABORTED);
7209 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7211 SCTP_INP_RUNLOCK(inp);
7212 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7213 return (ECONNRESET);
7215 SCTP_TCB_LOCK(stcb);
7216 SCTP_INP_RUNLOCK(inp);
7217 store = stcb->asoc.primary_destination->ro._l_addr;
7218 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
7219 SCTP_TCB_UNLOCK(stcb);
7220 switch (store.sa.sa_family) {
7224 struct sockaddr_in *sin;
7226 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7229 sin->sin_family = AF_INET;
7230 sin->sin_len = sizeof(*sin);
7231 sin->sin_port = store.sin.sin_port;
7232 sin->sin_addr = store.sin.sin_addr;
7233 *addr = (struct sockaddr *)sin;
7240 struct sockaddr_in6 *sin6;
7242 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7245 sin6->sin6_family = AF_INET6;
7246 sin6->sin6_len = sizeof(*sin6);
7247 sin6->sin6_port = store.sin6.sin6_port;
7248 sin6->sin6_addr = store.sin6.sin6_addr;
7249 if ((error = sa6_recoverscope(sin6)) != 0) {
7250 SCTP_FREE_SONAME(sin6);
7253 *addr = (struct sockaddr *)sin6;
7261 /* Wake any delayed sleep action */
7262 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7263 SCTP_INP_WLOCK(inp);
7264 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7265 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7266 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7267 SCTP_INP_WUNLOCK(inp);
7268 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7269 if (sowriteable(inp->sctp_socket)) {
7270 sowwakeup_locked(inp->sctp_socket);
7272 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7274 SCTP_INP_WLOCK(inp);
7276 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7277 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7278 SCTP_INP_WUNLOCK(inp);
7279 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7280 if (soreadable(inp->sctp_socket)) {
7281 sctp_defered_wakeup_cnt++;
7282 sorwakeup_locked(inp->sctp_socket);
7284 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7286 SCTP_INP_WLOCK(inp);
7288 SCTP_INP_WUNLOCK(inp);
7290 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7291 SCTP_TCB_LOCK(stcb);
7292 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7293 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7300 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7302 struct sockaddr_in *sin;
7304 struct sctp_inpcb *inp;
7305 struct sctp_ifa *sctp_ifa;
7308 * Do the malloc first in case it blocks.
7310 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7313 sin->sin_family = AF_INET;
7314 sin->sin_len = sizeof(*sin);
7315 inp = (struct sctp_inpcb *)so->so_pcb;
7317 SCTP_FREE_SONAME(sin);
7318 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7319 return (ECONNRESET);
7321 SCTP_INP_RLOCK(inp);
7322 sin->sin_port = inp->sctp_lport;
7323 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7324 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7325 struct sctp_tcb *stcb;
7326 struct sockaddr_in *sin_a;
7327 struct sctp_nets *net;
7330 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7336 SCTP_TCB_LOCK(stcb);
7337 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7338 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7340 /* this will make coverity happy */
7343 if (sin_a->sin_family == AF_INET) {
7348 if ((!fnd) || (sin_a == NULL)) {
7350 SCTP_TCB_UNLOCK(stcb);
7353 vrf_id = inp->def_vrf_id;
7354 sctp_ifa = sctp_source_address_selection(inp,
7356 (sctp_route_t *) & net->ro,
7359 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7360 sctp_free_ifa(sctp_ifa);
7362 SCTP_TCB_UNLOCK(stcb);
7364 /* For the bound all case you get back 0 */
7366 sin->sin_addr.s_addr = 0;
7370 /* Take the first IPv4 address in the list */
7371 struct sctp_laddr *laddr;
7374 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7375 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7376 struct sockaddr_in *sin_a;
7378 sin_a = &laddr->ifa->address.sin;
7379 sin->sin_addr = sin_a->sin_addr;
7385 SCTP_FREE_SONAME(sin);
7386 SCTP_INP_RUNLOCK(inp);
7387 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7391 SCTP_INP_RUNLOCK(inp);
7392 (*addr) = (struct sockaddr *)sin;
7397 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7399 struct sockaddr_in *sin;
7401 struct sockaddr_in *sin_a;
7402 struct sctp_inpcb *inp;
7403 struct sctp_tcb *stcb;
7404 struct sctp_nets *net;
7406 /* Do the malloc first in case it blocks. */
7407 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7410 sin->sin_family = AF_INET;
7411 sin->sin_len = sizeof(*sin);
7413 inp = (struct sctp_inpcb *)so->so_pcb;
7414 if ((inp == NULL) ||
7415 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7416 /* UDP type and listeners will drop out here */
7417 SCTP_FREE_SONAME(sin);
7418 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7421 SCTP_INP_RLOCK(inp);
7422 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7424 SCTP_TCB_LOCK(stcb);
7426 SCTP_INP_RUNLOCK(inp);
7428 SCTP_FREE_SONAME(sin);
7429 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7430 return (ECONNRESET);
7433 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7434 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7435 if (sin_a->sin_family == AF_INET) {
7437 sin->sin_port = stcb->rport;
7438 sin->sin_addr = sin_a->sin_addr;
7442 SCTP_TCB_UNLOCK(stcb);
7444 /* No IPv4 address */
7445 SCTP_FREE_SONAME(sin);
7446 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7449 (*addr) = (struct sockaddr *)sin;
7453 struct pr_usrreqs sctp_usrreqs = {
7454 .pru_abort = sctp_abort,
7455 .pru_accept = sctp_accept,
7456 .pru_attach = sctp_attach,
7457 .pru_bind = sctp_bind,
7458 .pru_connect = sctp_connect,
7459 .pru_control = in_control,
7460 .pru_close = sctp_close,
7461 .pru_detach = sctp_close,
7462 .pru_sopoll = sopoll_generic,
7463 .pru_flush = sctp_flush,
7464 .pru_disconnect = sctp_disconnect,
7465 .pru_listen = sctp_listen,
7466 .pru_peeraddr = sctp_peeraddr,
7467 .pru_send = sctp_sendm,
7468 .pru_shutdown = sctp_shutdown,
7469 .pru_sockaddr = sctp_ingetaddr,
7470 .pru_sosend = sctp_sosend,
7471 .pru_soreceive = sctp_soreceive