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 struct sctp_cc_functions sctp_cc_functions[];
58 extern struct sctp_ss_functions sctp_ss_functions[];
65 /* Initialize and modify the sysctled variables */
67 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
68 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
70 * Allow a user to take no more than 1/2 the number of clusters or
71 * the SB_MAX whichever is smaller for the send window.
73 sb_max_adj = (u_long)((u_quad_t) (SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
74 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
75 (((uint32_t) nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
77 * Now for the recv window, should we take the same amount? or
78 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
79 * now I will just copy.
81 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
82 SCTP_BASE_VAR(first_time) = 0;
83 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
85 #if defined(SCTP_PACKET_LOGGING)
86 SCTP_BASE_VAR(packet_log_writers) = 0;
87 SCTP_BASE_VAR(packet_log_end) = 0;
88 bzero(&SCTP_BASE_VAR(packet_log_buffer), SCTP_PACKET_LOG_SIZE);
101 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
103 struct sctp_tmit_chunk *chk;
106 /* Adjust that too */
107 stcb->asoc.smallest_mtu = nxtsz;
108 /* now off to subtract IP_DF flag if needed */
109 overhead = IP_HDR_SIZE;
110 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
111 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
113 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
114 if ((chk->send_size + overhead) > nxtsz) {
115 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
118 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
119 if ((chk->send_size + overhead) > nxtsz) {
121 * For this guy we also mark for immediate resend
122 * since we sent to big of chunk
124 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
125 if (chk->sent < SCTP_DATAGRAM_RESEND) {
126 sctp_flight_size_decrease(chk);
127 sctp_total_flight_decrease(stcb, chk);
129 if (chk->sent != SCTP_DATAGRAM_RESEND) {
130 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
132 chk->sent = SCTP_DATAGRAM_RESEND;
133 chk->rec.data.doing_fast_retransmit = 0;
134 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
135 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
136 chk->whoTo->flight_size,
138 (uintptr_t) chk->whoTo,
139 chk->rec.data.TSN_seq);
141 /* Clear any time so NO RTT is being done */
149 sctp_notify_mbuf(struct sctp_inpcb *inp,
150 struct sctp_tcb *stcb,
151 struct sctp_nets *net,
156 int totsz, tmr_stopped = 0;
160 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
161 (ip == NULL) || (sh == NULL)) {
163 SCTP_TCB_UNLOCK(stcb);
167 /* First job is to verify the vtag matches what I would send */
168 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
169 SCTP_TCB_UNLOCK(stcb);
172 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
174 if (icmph->icmp_type != ICMP_UNREACH) {
175 /* We only care about unreachable */
176 SCTP_TCB_UNLOCK(stcb);
179 if (icmph->icmp_code != ICMP_UNREACH_NEEDFRAG) {
180 /* not a unreachable message due to frag. */
181 SCTP_TCB_UNLOCK(stcb);
184 totsz = ntohs(ip->ip_len);
186 nxtsz = ntohs(icmph->icmp_nextmtu);
189 * old type router that does not tell us what the next size
190 * mtu is. Rats we will have to guess (in a educated fashion
193 nxtsz = sctp_get_prev_mtu(totsz);
195 /* Stop any PMTU timer */
196 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
198 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
199 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
201 /* Adjust destination size limit */
202 if (net->mtu > nxtsz) {
205 net->mtu -= sizeof(struct udphdr);
208 /* now what about the ep? */
209 if (stcb->asoc.smallest_mtu > nxtsz) {
210 sctp_pathmtu_adjustment(stcb, nxtsz);
213 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
215 SCTP_TCB_UNLOCK(stcb);
219 sctp_notify(struct sctp_inpcb *inp,
223 struct sctp_tcb *stcb,
224 struct sctp_nets *net)
226 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
233 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
234 (sh == NULL) || (to == NULL)) {
236 SCTP_TCB_UNLOCK(stcb);
239 /* First job is to verify the vtag matches what I would send */
240 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
241 SCTP_TCB_UNLOCK(stcb);
244 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
246 if (icmph->icmp_type != ICMP_UNREACH) {
247 /* We only care about unreachable */
248 SCTP_TCB_UNLOCK(stcb);
251 if ((icmph->icmp_code == ICMP_UNREACH_NET) ||
252 (icmph->icmp_code == ICMP_UNREACH_HOST) ||
253 (icmph->icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
254 (icmph->icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
255 (icmph->icmp_code == ICMP_UNREACH_ISOLATED) ||
256 (icmph->icmp_code == ICMP_UNREACH_NET_PROHIB) ||
257 (icmph->icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
258 (icmph->icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
261 * Hmm reachablity problems we must examine closely. If its
262 * not reachable, we may have lost a network. Or if there is
263 * NO protocol at the other end named SCTP. well we consider
266 if (net->dest_state & SCTP_ADDR_REACHABLE) {
267 /* Ok that destination is NOT reachable */
268 net->dest_state &= ~SCTP_ADDR_REACHABLE;
269 net->dest_state &= ~SCTP_ADDR_PF;
270 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
272 (void *)net, SCTP_SO_NOT_LOCKED);
274 SCTP_TCB_UNLOCK(stcb);
275 } else if ((icmph->icmp_code == ICMP_UNREACH_PROTOCOL) ||
276 (icmph->icmp_code == ICMP_UNREACH_PORT)) {
278 * Here the peer is either playing tricks on us, including
279 * an address that belongs to someone who does not support
280 * SCTP OR was a userland implementation that shutdown and
281 * now is dead. In either case treat it like a OOTB abort
284 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
285 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
286 so = SCTP_INP_SO(inp);
287 atomic_add_int(&stcb->asoc.refcnt, 1);
288 SCTP_TCB_UNLOCK(stcb);
289 SCTP_SOCKET_LOCK(so, 1);
291 atomic_subtract_int(&stcb->asoc.refcnt, 1);
293 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
294 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
295 SCTP_SOCKET_UNLOCK(so, 1);
296 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
298 /* no need to unlock here, since the TCB is gone */
300 SCTP_TCB_UNLOCK(stcb);
308 sctp_ctlinput(cmd, sa, vip)
317 /* FIX, for non-bsd is this right? */
318 vrf_id = SCTP_DEFAULT_VRFID;
319 if (sa->sa_family != AF_INET ||
320 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
323 if (PRC_IS_REDIRECT(cmd)) {
325 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
329 struct sctp_inpcb *inp = NULL;
330 struct sctp_tcb *stcb = NULL;
331 struct sctp_nets *net = NULL;
332 struct sockaddr_in to, from;
334 sh = (struct sctphdr *)((caddr_t)ip + (ip->ip_hl << 2));
335 bzero(&to, sizeof(to));
336 bzero(&from, sizeof(from));
337 from.sin_family = to.sin_family = AF_INET;
338 from.sin_len = to.sin_len = sizeof(to);
339 from.sin_port = sh->src_port;
340 from.sin_addr = ip->ip_src;
341 to.sin_port = sh->dest_port;
342 to.sin_addr = ip->ip_dst;
345 * 'to' holds the dest of the packet that failed to be sent.
346 * 'from' holds our local endpoint address. Thus we reverse
347 * the to and the from in the lookup.
349 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&to,
350 (struct sockaddr *)&from,
351 &inp, &net, 1, vrf_id);
352 if (stcb != NULL && inp && (inp->sctp_socket != NULL)) {
353 if (cmd != PRC_MSGSIZE) {
354 sctp_notify(inp, ip, sh,
355 (struct sockaddr *)&to, stcb,
358 /* handle possible ICMP size messages */
359 sctp_notify_mbuf(inp, stcb, net, ip, sh);
362 if ((stcb == NULL) && (inp != NULL)) {
363 /* reduce ref-count */
365 SCTP_INP_DECR_REF(inp);
366 SCTP_INP_WUNLOCK(inp);
369 SCTP_TCB_UNLOCK(stcb);
379 sctp_getcred(SYSCTL_HANDLER_ARGS)
382 struct sockaddr_in addrs[2];
383 struct sctp_inpcb *inp;
384 struct sctp_nets *net;
385 struct sctp_tcb *stcb;
389 /* FIX, for non-bsd is this right? */
390 vrf_id = SCTP_DEFAULT_VRFID;
392 error = priv_check(req->td, PRIV_NETINET_GETCRED);
397 error = SYSCTL_IN(req, addrs, sizeof(addrs));
401 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
403 &inp, &net, 1, vrf_id);
404 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
405 if ((inp != NULL) && (stcb == NULL)) {
406 /* reduce ref-count */
408 SCTP_INP_DECR_REF(inp);
411 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
415 SCTP_TCB_UNLOCK(stcb);
417 * We use the write lock here, only since in the error leg we need
418 * it. If we used RLOCK, then we would have to
419 * wlock/decr/unlock/rlock. Which in theory could create a hole.
420 * Better to use higher wlock.
424 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
426 SCTP_INP_WUNLOCK(inp);
429 cru2x(inp->sctp_socket->so_cred, &xuc);
430 SCTP_INP_WUNLOCK(inp);
431 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
436 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
437 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
442 sctp_abort(struct socket *so)
444 struct sctp_inpcb *inp;
447 inp = (struct sctp_inpcb *)so->so_pcb;
452 flags = inp->sctp_flags;
453 #ifdef SCTP_LOG_CLOSING
454 sctp_log_closing(inp, NULL, 17);
456 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
457 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
458 #ifdef SCTP_LOG_CLOSING
459 sctp_log_closing(inp, NULL, 16);
461 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
462 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
464 SCTP_SB_CLEAR(so->so_snd);
466 * same for the rcv ones, they are only here for the
469 SCTP_SB_CLEAR(so->so_rcv);
471 /* Now null out the reference, we are completely detached. */
475 flags = inp->sctp_flags;
476 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
477 goto sctp_must_try_again;
484 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
486 struct sctp_inpcb *inp;
487 struct inpcb *ip_inp;
489 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
496 inp = (struct sctp_inpcb *)so->so_pcb;
498 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
501 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
502 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
507 error = sctp_inpcb_alloc(so, vrf_id);
511 inp = (struct sctp_inpcb *)so->so_pcb;
513 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
514 ip_inp = &inp->ip_inp.inp;
515 ip_inp->inp_vflag |= INP_IPV4;
516 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
518 error = ipsec_init_policy(so, &ip_inp->inp_sp);
519 #ifdef SCTP_LOG_CLOSING
520 sctp_log_closing(inp, NULL, 17);
524 flags = inp->sctp_flags;
525 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
526 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
527 #ifdef SCTP_LOG_CLOSING
528 sctp_log_closing(inp, NULL, 15);
530 SCTP_INP_WUNLOCK(inp);
531 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
532 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
534 flags = inp->sctp_flags;
535 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
538 SCTP_INP_WUNLOCK(inp);
544 SCTP_INP_WUNLOCK(inp);
549 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
551 struct sctp_inpcb *inp;
553 inp = (struct sctp_inpcb *)so->so_pcb;
555 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
559 if ((addr->sa_family != AF_INET) ||
560 (addr->sa_len != sizeof(struct sockaddr_in))) {
561 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
565 return (sctp_inpcb_bind(so, addr, NULL, p));
570 sctp_close(struct socket *so)
572 struct sctp_inpcb *inp;
575 inp = (struct sctp_inpcb *)so->so_pcb;
580 * Inform all the lower layer assoc that we are done.
583 flags = inp->sctp_flags;
584 #ifdef SCTP_LOG_CLOSING
585 sctp_log_closing(inp, NULL, 17);
587 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
588 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
589 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
590 (so->so_rcv.sb_cc > 0)) {
591 #ifdef SCTP_LOG_CLOSING
592 sctp_log_closing(inp, NULL, 13);
594 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
595 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
597 #ifdef SCTP_LOG_CLOSING
598 sctp_log_closing(inp, NULL, 14);
600 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
601 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
604 * The socket is now detached, no matter what the state of
605 * the SCTP association.
608 SCTP_SB_CLEAR(so->so_snd);
610 * same for the rcv ones, they are only here for the
613 SCTP_SB_CLEAR(so->so_rcv);
615 /* Now null out the reference, we are completely detached. */
619 flags = inp->sctp_flags;
620 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
621 goto sctp_must_try_again;
629 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
630 struct mbuf *control, struct thread *p);
634 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
635 struct mbuf *control, struct thread *p)
637 struct sctp_inpcb *inp;
640 inp = (struct sctp_inpcb *)so->so_pcb;
643 sctp_m_freem(control);
646 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
650 /* Got to have an to address if we are NOT a connected socket */
651 if ((addr == NULL) &&
652 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
653 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
655 } else if (addr == NULL) {
656 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
657 error = EDESTADDRREQ;
660 sctp_m_freem(control);
666 if (addr->sa_family != AF_INET) {
667 /* must be a v4 address! */
668 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
671 sctp_m_freem(control);
674 error = EDESTADDRREQ;
679 /* now what about control */
682 SCTP_PRINTF("huh? control set?\n");
683 sctp_m_freem(inp->control);
686 inp->control = control;
690 SCTP_BUF_NEXT(inp->pkt_last) = m;
693 inp->pkt_last = inp->pkt = m;
696 /* FreeBSD uses a flag passed */
697 ((flags & PRUS_MORETOCOME) == 0)
700 * note with the current version this code will only be used
701 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
702 * re-defining sosend to use the sctp_sosend. One can
703 * optionally switch back to this code (by changing back the
704 * definitions) but this is not advisable. This code is used
705 * by FreeBSD when sending a file with sendfile() though.
709 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
719 sctp_disconnect(struct socket *so)
721 struct sctp_inpcb *inp;
723 inp = (struct sctp_inpcb *)so->so_pcb;
725 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
729 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
730 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
731 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
733 SCTP_INP_RUNLOCK(inp);
736 struct sctp_association *asoc;
737 struct sctp_tcb *stcb;
739 stcb = LIST_FIRST(&inp->sctp_asoc_list);
741 SCTP_INP_RUNLOCK(inp);
742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
747 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
748 /* We are about to be freed, out of here */
749 SCTP_TCB_UNLOCK(stcb);
750 SCTP_INP_RUNLOCK(inp);
753 if (((so->so_options & SO_LINGER) &&
754 (so->so_linger == 0)) ||
755 (so->so_rcv.sb_cc > 0)) {
756 if (SCTP_GET_STATE(asoc) !=
757 SCTP_STATE_COOKIE_WAIT) {
758 /* Left with Data unread */
761 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_NOWAIT, 1, MT_DATA);
767 struct sctp_paramhdr *ph;
769 ph = mtod(err, struct sctp_paramhdr *);
770 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
771 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
772 ph->param_length = htons(SCTP_BUF_LEN(err));
774 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
775 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
777 SCTP_INP_RUNLOCK(inp);
778 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
779 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
780 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
782 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
783 /* No unlock tcb assoc is gone */
786 if (TAILQ_EMPTY(&asoc->send_queue) &&
787 TAILQ_EMPTY(&asoc->sent_queue) &&
788 (asoc->stream_queue_cnt == 0)) {
789 /* there is nothing queued to send, so done */
790 if (asoc->locked_on_sending) {
793 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
794 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
795 /* only send SHUTDOWN 1st time thru */
796 struct sctp_nets *netp;
798 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
799 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
800 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
802 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
803 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
804 sctp_stop_timers_for_shutdown(stcb);
805 if (stcb->asoc.alternate) {
806 netp = stcb->asoc.alternate;
808 netp = stcb->asoc.primary_destination;
810 sctp_send_shutdown(stcb, netp);
811 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
812 stcb->sctp_ep, stcb, netp);
813 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
814 stcb->sctp_ep, stcb, netp);
815 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
819 * we still got (or just got) data to send,
820 * so set SHUTDOWN_PENDING
823 * XXX sockets draft says that SCTP_EOF
824 * should be sent with no data. currently,
825 * we will allow user data to be sent first
826 * and move to SHUTDOWN-PENDING
828 struct sctp_nets *netp;
830 if (stcb->asoc.alternate) {
831 netp = stcb->asoc.alternate;
833 netp = stcb->asoc.primary_destination;
836 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
837 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
839 if (asoc->locked_on_sending) {
840 /* Locked to send out the data */
841 struct sctp_stream_queue_pending *sp;
843 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
845 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
846 asoc->locked_on_sending->stream_no);
848 if ((sp->length == 0) && (sp->msg_is_complete == 0))
849 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
852 if (TAILQ_EMPTY(&asoc->send_queue) &&
853 TAILQ_EMPTY(&asoc->sent_queue) &&
854 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
858 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
859 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
860 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
861 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
862 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
863 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
864 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
866 SCTP_INP_RUNLOCK(inp);
867 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
870 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
873 soisdisconnecting(so);
874 SCTP_TCB_UNLOCK(stcb);
875 SCTP_INP_RUNLOCK(inp);
880 /* UDP model does not support this */
881 SCTP_INP_RUNLOCK(inp);
882 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
888 sctp_flush(struct socket *so, int how)
891 * We will just clear out the values and let subsequent close clear
892 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
893 * they will not be able to read the data, the socket will block
894 * that from happening.
896 struct sctp_inpcb *inp;
898 inp = (struct sctp_inpcb *)so->so_pcb;
900 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
904 /* For the 1 to many model this does nothing */
905 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
906 SCTP_INP_RUNLOCK(inp);
909 SCTP_INP_RUNLOCK(inp);
910 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
912 * First make sure the sb will be happy, we don't use these
913 * except maybe the count
916 SCTP_INP_READ_LOCK(inp);
917 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
918 SCTP_INP_READ_UNLOCK(inp);
919 SCTP_INP_WUNLOCK(inp);
920 so->so_rcv.sb_cc = 0;
921 so->so_rcv.sb_mbcnt = 0;
922 so->so_rcv.sb_mb = NULL;
924 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
926 * First make sure the sb will be happy, we don't use these
927 * except maybe the count
929 so->so_snd.sb_cc = 0;
930 so->so_snd.sb_mbcnt = 0;
931 so->so_snd.sb_mb = NULL;
938 sctp_shutdown(struct socket *so)
940 struct sctp_inpcb *inp;
942 inp = (struct sctp_inpcb *)so->so_pcb;
944 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
948 /* For UDP model this is a invalid call */
949 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
950 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
951 /* Restore the flags that the soshutdown took away. */
952 SOCKBUF_LOCK(&so->so_rcv);
953 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
954 SOCKBUF_UNLOCK(&so->so_rcv);
955 /* This proc will wakeup for read and do nothing (I hope) */
956 SCTP_INP_RUNLOCK(inp);
957 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
961 * Ok if we reach here its the TCP model and it is either a SHUT_WR
962 * or SHUT_RDWR. This means we put the shutdown flag against it.
965 struct sctp_tcb *stcb;
966 struct sctp_association *asoc;
969 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
970 SCTP_INP_RUNLOCK(inp);
975 stcb = LIST_FIRST(&inp->sctp_asoc_list);
978 * Ok we hit the case that the shutdown call was
979 * made after an abort or something. Nothing to do
982 SCTP_INP_RUNLOCK(inp);
987 if (TAILQ_EMPTY(&asoc->send_queue) &&
988 TAILQ_EMPTY(&asoc->sent_queue) &&
989 (asoc->stream_queue_cnt == 0)) {
990 if (asoc->locked_on_sending) {
993 /* there is nothing queued to send, so I'm done... */
994 if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) {
995 /* only send SHUTDOWN the first time through */
996 struct sctp_nets *netp;
998 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
999 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
1000 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1002 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
1003 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
1004 sctp_stop_timers_for_shutdown(stcb);
1005 if (stcb->asoc.alternate) {
1006 netp = stcb->asoc.alternate;
1008 netp = stcb->asoc.primary_destination;
1010 sctp_send_shutdown(stcb, netp);
1011 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1012 stcb->sctp_ep, stcb, netp);
1013 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1014 stcb->sctp_ep, stcb, netp);
1015 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
1019 * we still got (or just got) data to send, so set
1022 struct sctp_nets *netp;
1024 if (stcb->asoc.alternate) {
1025 netp = stcb->asoc.alternate;
1027 netp = stcb->asoc.primary_destination;
1030 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1031 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
1034 if (asoc->locked_on_sending) {
1035 /* Locked to send out the data */
1036 struct sctp_stream_queue_pending *sp;
1038 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
1040 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
1041 asoc->locked_on_sending->stream_no);
1043 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
1044 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
1048 if (TAILQ_EMPTY(&asoc->send_queue) &&
1049 TAILQ_EMPTY(&asoc->sent_queue) &&
1050 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1051 struct mbuf *op_err;
1054 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
1055 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
1056 sctp_abort_an_association(stcb->sctp_ep, stcb,
1057 op_err, SCTP_SO_LOCKED);
1060 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1063 SCTP_TCB_UNLOCK(stcb);
1066 SCTP_INP_RUNLOCK(inp);
1071 * copies a "user" presentable address and removes embedded scope, etc.
1072 * returns 0 on success, 1 on error
1075 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1078 struct sockaddr_in6 lsa6;
1080 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1083 memcpy(ss, sa, sa->sa_len);
1090 * NOTE: assumes addr lock is held
1093 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1094 struct sctp_tcb *stcb,
1096 struct sockaddr_storage *sas,
1099 struct sctp_ifn *sctp_ifn;
1100 struct sctp_ifa *sctp_ifa;
1105 int ipv4_local_scope, ipv4_addr_legal;
1109 int local_scope, site_scope, ipv6_addr_legal;
1112 struct sctp_vrf *vrf;
1119 /* Turn on all the appropriate scope */
1120 loopback_scope = stcb->asoc.scope.loopback_scope;
1122 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1123 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1126 local_scope = stcb->asoc.scope.local_scope;
1127 site_scope = stcb->asoc.scope.site_scope;
1128 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1131 /* Use generic values for endpoints. */
1134 ipv4_local_scope = 1;
1140 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1142 ipv6_addr_legal = 1;
1145 if (SCTP_IPV6_V6ONLY(inp)) {
1146 ipv4_addr_legal = 0;
1148 ipv4_addr_legal = 1;
1153 ipv6_addr_legal = 0;
1156 ipv4_addr_legal = 1;
1160 vrf = sctp_find_vrf(vrf_id);
1164 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1165 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1166 if ((loopback_scope == 0) &&
1167 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1168 /* Skip loopback if loopback_scope not set */
1171 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1174 * For the BOUND-ALL case, the list
1175 * associated with a TCB is Always
1176 * considered a reverse list.. i.e.
1177 * it lists addresses that are NOT
1178 * part of the association. If this
1179 * is one of those we must skip it.
1181 if (sctp_is_addr_restricted(stcb,
1186 switch (sctp_ifa->address.sa.sa_family) {
1189 if (ipv4_addr_legal) {
1190 struct sockaddr_in *sin;
1192 sin = &sctp_ifa->address.sin;
1193 if (sin->sin_addr.s_addr == 0) {
1201 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1202 &sin->sin_addr) != 0) {
1205 if ((ipv4_local_scope == 0) &&
1206 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1210 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1211 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1212 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1213 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1214 actual += sizeof(struct sockaddr_in6);
1217 memcpy(sas, sin, sizeof(*sin));
1218 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1219 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1220 actual += sizeof(*sin);
1224 if (actual >= limit) {
1234 if (ipv6_addr_legal) {
1235 struct sockaddr_in6 *sin6;
1237 sin6 = &sctp_ifa->address.sin6;
1238 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1246 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1247 &sin6->sin6_addr) != 0) {
1250 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1251 if (local_scope == 0)
1253 if (sin6->sin6_scope_id == 0) {
1254 if (sa6_recoverscope(sin6) != 0)
1272 if ((site_scope == 0) &&
1273 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1276 memcpy(sas, sin6, sizeof(*sin6));
1277 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1278 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1279 actual += sizeof(*sin6);
1280 if (actual >= limit) {
1295 struct sctp_laddr *laddr;
1297 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1299 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1303 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1305 switch (laddr->ifa->address.sa.sa_family) {
1308 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1313 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1320 sas = (struct sockaddr_storage *)((caddr_t)sas +
1321 laddr->ifa->address.sa.sa_len);
1322 actual += laddr->ifa->address.sa.sa_len;
1323 if (actual >= limit) {
1332 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1333 struct sctp_tcb *stcb,
1335 struct sockaddr_storage *sas)
1339 SCTP_IPI_ADDR_RLOCK();
1340 /* fill up addresses for the endpoint's default vrf */
1341 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1343 SCTP_IPI_ADDR_RUNLOCK();
1348 * NOTE: assumes addr lock is held
1351 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1354 struct sctp_vrf *vrf = NULL;
1357 * In both sub-set bound an bound_all cases we return the MAXIMUM
1358 * number of addresses that you COULD get. In reality the sub-set
1359 * bound may have an exclusion list for a given TCB OR in the
1360 * bound-all case a TCB may NOT include the loopback or other
1361 * addresses as well.
1363 vrf = sctp_find_vrf(vrf_id);
1367 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1368 struct sctp_ifn *sctp_ifn;
1369 struct sctp_ifa *sctp_ifa;
1371 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1372 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1373 /* Count them if they are the right type */
1374 switch (sctp_ifa->address.sa.sa_family) {
1378 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1379 cnt += sizeof(struct sockaddr_in6);
1381 cnt += sizeof(struct sockaddr_in);
1383 cnt += sizeof(struct sockaddr_in);
1389 cnt += sizeof(struct sockaddr_in6);
1398 struct sctp_laddr *laddr;
1400 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1401 switch (laddr->ifa->address.sa.sa_family) {
1405 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1406 cnt += sizeof(struct sockaddr_in6);
1408 cnt += sizeof(struct sockaddr_in);
1410 cnt += sizeof(struct sockaddr_in);
1416 cnt += sizeof(struct sockaddr_in6);
1428 sctp_count_max_addresses(struct sctp_inpcb *inp)
1432 SCTP_IPI_ADDR_RLOCK();
1433 /* count addresses for the endpoint's default VRF */
1434 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1435 SCTP_IPI_ADDR_RUNLOCK();
1440 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1441 size_t optsize, void *p, int delay)
1444 int creat_lock_on = 0;
1445 struct sctp_tcb *stcb = NULL;
1446 struct sockaddr *sa;
1447 int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1449 int bad_addresses = 0;
1452 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1454 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1455 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1456 /* We are already connected AND the TCP model */
1457 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1458 return (EADDRINUSE);
1460 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1461 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1462 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1465 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1466 SCTP_INP_RLOCK(inp);
1467 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1468 SCTP_INP_RUNLOCK(inp);
1471 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1474 SCTP_INP_INCR_REF(inp);
1475 SCTP_ASOC_CREATE_LOCK(inp);
1477 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1478 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1479 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1483 totaddrp = (int *)optval;
1484 totaddr = *totaddrp;
1485 sa = (struct sockaddr *)(totaddrp + 1);
1486 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (optsize - sizeof(int)), &bad_addresses);
1487 if ((stcb != NULL) || bad_addresses) {
1488 /* Already have or am bring up an association */
1489 SCTP_ASOC_CREATE_UNLOCK(inp);
1492 SCTP_TCB_UNLOCK(stcb);
1493 if (bad_addresses == 0) {
1494 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1500 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1505 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1507 struct in6pcb *inp6;
1509 inp6 = (struct in6pcb *)inp;
1510 if (SCTP_IPV6_V6ONLY(inp6)) {
1512 * if IPV6_V6ONLY flag, ignore connections destined
1513 * to a v4 addr or v4-mapped addr
1515 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1521 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1522 SCTP_PCB_FLAGS_UNBOUND) {
1523 /* Bind a ephemeral port */
1524 error = sctp_inpcb_bind(so, NULL, NULL, p);
1529 /* FIX ME: do we want to pass in a vrf on the connect call? */
1530 vrf_id = inp->def_vrf_id;
1533 /* We are GOOD to go */
1534 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1538 /* Gak! no memory */
1541 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1542 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1543 /* Set the connected flag so we can queue data */
1546 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1547 /* move to second address */
1548 switch (sa->sa_family) {
1551 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1556 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1564 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1565 /* Fill in the return id */
1567 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1570 a_id = (sctp_assoc_t *) optval;
1571 *a_id = sctp_get_associd(stcb);
1573 /* initialize authentication parameters for the assoc */
1574 sctp_initialize_auth_params(inp, stcb);
1577 /* doing delayed connection */
1578 stcb->asoc.delayed_connection = 1;
1579 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1581 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1582 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1584 SCTP_TCB_UNLOCK(stcb);
1585 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1586 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1587 /* Set the connected flag so we can queue data */
1591 if (creat_lock_on) {
1592 SCTP_ASOC_CREATE_UNLOCK(inp);
1594 SCTP_INP_DECR_REF(inp);
1598 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1599 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1600 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1601 SCTP_INP_RLOCK(inp); \
1602 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1604 SCTP_TCB_LOCK(stcb); \
1606 SCTP_INP_RUNLOCK(inp); \
1607 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1608 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1609 if (stcb == NULL) { \
1610 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1620 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1621 if (size < sizeof(type)) { \
1622 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1626 destp = (type *)srcp; \
1631 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1634 struct sctp_inpcb *inp = NULL;
1636 struct sctp_tcb *stcb = NULL;
1638 if (optval == NULL) {
1639 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1642 inp = (struct sctp_inpcb *)so->so_pcb;
1644 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1651 case SCTP_AUTOCLOSE:
1652 case SCTP_EXPLICIT_EOR:
1653 case SCTP_AUTO_ASCONF:
1654 case SCTP_DISABLE_FRAGMENTS:
1655 case SCTP_I_WANT_MAPPED_V4_ADDR:
1656 case SCTP_USE_EXT_RCVINFO:
1657 SCTP_INP_RLOCK(inp);
1659 case SCTP_DISABLE_FRAGMENTS:
1660 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1662 case SCTP_I_WANT_MAPPED_V4_ADDR:
1663 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1665 case SCTP_AUTO_ASCONF:
1666 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1667 /* only valid for bound all sockets */
1668 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1670 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1675 case SCTP_EXPLICIT_EOR:
1676 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1679 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1681 case SCTP_USE_EXT_RCVINFO:
1682 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1684 case SCTP_AUTOCLOSE:
1685 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1686 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1693 error = ENOPROTOOPT;
1694 } /* end switch (sopt->sopt_name) */
1695 if (*optsize < sizeof(val)) {
1696 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1700 SCTP_INP_RUNLOCK(inp);
1702 /* return the option value */
1703 *(int *)optval = val;
1704 *optsize = sizeof(val);
1707 case SCTP_GET_PACKET_LOG:
1709 #ifdef SCTP_PACKET_LOGGING
1713 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1714 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1717 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1722 case SCTP_REUSE_PORT:
1726 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1727 /* Can't do this for a 1-m socket */
1731 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1732 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1733 *optsize = sizeof(uint32_t);
1736 case SCTP_PARTIAL_DELIVERY_POINT:
1740 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1741 *value = inp->partial_delivery_point;
1742 *optsize = sizeof(uint32_t);
1745 case SCTP_FRAGMENT_INTERLEAVE:
1749 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1750 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1751 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1752 *value = SCTP_FRAG_LEVEL_2;
1754 *value = SCTP_FRAG_LEVEL_1;
1757 *value = SCTP_FRAG_LEVEL_0;
1759 *optsize = sizeof(uint32_t);
1762 case SCTP_CMT_ON_OFF:
1764 struct sctp_assoc_value *av;
1766 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1767 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1769 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1770 SCTP_TCB_UNLOCK(stcb);
1772 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1773 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1774 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1775 SCTP_INP_RLOCK(inp);
1776 av->assoc_value = inp->sctp_cmt_on_off;
1777 SCTP_INP_RUNLOCK(inp);
1779 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1784 *optsize = sizeof(struct sctp_assoc_value);
1788 case SCTP_PLUGGABLE_CC:
1790 struct sctp_assoc_value *av;
1792 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1793 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1795 av->assoc_value = stcb->asoc.congestion_control_module;
1796 SCTP_TCB_UNLOCK(stcb);
1798 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1799 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1800 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1801 SCTP_INP_RLOCK(inp);
1802 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1803 SCTP_INP_RUNLOCK(inp);
1805 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1810 *optsize = sizeof(struct sctp_assoc_value);
1814 case SCTP_CC_OPTION:
1816 struct sctp_cc_option *cc_opt;
1818 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1819 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1823 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1826 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1827 *optsize = sizeof(struct sctp_cc_option);
1829 SCTP_TCB_UNLOCK(stcb);
1833 case SCTP_PLUGGABLE_SS:
1835 struct sctp_assoc_value *av;
1837 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1838 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1840 av->assoc_value = stcb->asoc.stream_scheduling_module;
1841 SCTP_TCB_UNLOCK(stcb);
1843 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1844 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1845 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1846 SCTP_INP_RLOCK(inp);
1847 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1848 SCTP_INP_RUNLOCK(inp);
1850 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1855 *optsize = sizeof(struct sctp_assoc_value);
1861 struct sctp_stream_value *av;
1863 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1864 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1866 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1867 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1868 &av->stream_value) < 0)) {
1869 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1872 *optsize = sizeof(struct sctp_stream_value);
1874 SCTP_TCB_UNLOCK(stcb);
1877 * Can't get stream value without
1880 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1885 case SCTP_GET_ADDR_LEN:
1887 struct sctp_assoc_value *av;
1889 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1892 if (av->assoc_value == AF_INET) {
1893 av->assoc_value = sizeof(struct sockaddr_in);
1898 if (av->assoc_value == AF_INET6) {
1899 av->assoc_value = sizeof(struct sockaddr_in6);
1904 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1906 *optsize = sizeof(struct sctp_assoc_value);
1910 case SCTP_GET_ASSOC_NUMBER:
1912 uint32_t *value, cnt;
1914 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1916 SCTP_INP_RLOCK(inp);
1917 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1920 SCTP_INP_RUNLOCK(inp);
1922 *optsize = sizeof(uint32_t);
1925 case SCTP_GET_ASSOC_ID_LIST:
1927 struct sctp_assoc_ids *ids;
1928 unsigned int at, limit;
1930 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1932 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1933 SCTP_INP_RLOCK(inp);
1934 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1936 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1939 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1943 SCTP_INP_RUNLOCK(inp);
1945 ids->gaids_number_of_ids = at;
1946 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1952 struct sctp_assoc_value *av;
1954 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1955 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1958 av->assoc_value = stcb->asoc.context;
1959 SCTP_TCB_UNLOCK(stcb);
1961 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1962 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1963 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1964 SCTP_INP_RLOCK(inp);
1965 av->assoc_value = inp->sctp_context;
1966 SCTP_INP_RUNLOCK(inp);
1968 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1973 *optsize = sizeof(struct sctp_assoc_value);
1979 uint32_t *default_vrfid;
1981 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1982 *default_vrfid = inp->def_vrf_id;
1983 *optsize = sizeof(uint32_t);
1986 case SCTP_GET_ASOC_VRF:
1988 struct sctp_assoc_value *id;
1990 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1991 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1994 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1996 id->assoc_value = stcb->asoc.vrf_id;
1997 *optsize = sizeof(struct sctp_assoc_value);
2001 case SCTP_GET_VRF_IDS:
2003 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
2007 case SCTP_GET_NONCE_VALUES:
2009 struct sctp_get_nonce_values *gnv;
2011 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
2012 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
2015 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
2016 gnv->gn_local_tag = stcb->asoc.my_vtag;
2017 SCTP_TCB_UNLOCK(stcb);
2018 *optsize = sizeof(struct sctp_get_nonce_values);
2020 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2025 case SCTP_DELAYED_SACK:
2027 struct sctp_sack_info *sack;
2029 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2030 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2032 sack->sack_delay = stcb->asoc.delayed_ack;
2033 sack->sack_freq = stcb->asoc.sack_freq;
2034 SCTP_TCB_UNLOCK(stcb);
2036 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2037 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2038 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2039 SCTP_INP_RLOCK(inp);
2040 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2041 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2042 SCTP_INP_RUNLOCK(inp);
2044 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2049 *optsize = sizeof(struct sctp_sack_info);
2053 case SCTP_GET_SNDBUF_USE:
2055 struct sctp_sockstat *ss;
2057 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2058 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2061 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2062 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2063 stcb->asoc.size_on_all_streams);
2064 SCTP_TCB_UNLOCK(stcb);
2065 *optsize = sizeof(struct sctp_sockstat);
2067 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2072 case SCTP_MAX_BURST:
2074 struct sctp_assoc_value *av;
2076 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2077 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2080 av->assoc_value = stcb->asoc.max_burst;
2081 SCTP_TCB_UNLOCK(stcb);
2083 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2084 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2085 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2086 SCTP_INP_RLOCK(inp);
2087 av->assoc_value = inp->sctp_ep.max_burst;
2088 SCTP_INP_RUNLOCK(inp);
2090 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2095 *optsize = sizeof(struct sctp_assoc_value);
2101 struct sctp_assoc_value *av;
2104 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2105 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2108 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2109 SCTP_TCB_UNLOCK(stcb);
2111 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2112 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2113 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2114 SCTP_INP_RLOCK(inp);
2115 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2116 ovh = SCTP_MED_OVERHEAD;
2118 ovh = SCTP_MED_V4_OVERHEAD;
2120 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2121 av->assoc_value = 0;
2123 av->assoc_value = inp->sctp_frag_point - ovh;
2124 SCTP_INP_RUNLOCK(inp);
2126 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2131 *optsize = sizeof(struct sctp_assoc_value);
2135 case SCTP_GET_STAT_LOG:
2136 error = sctp_fill_stat_log(optval, optsize);
2140 struct sctp_event_subscribe *events;
2142 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2143 memset(events, 0, sizeof(struct sctp_event_subscribe));
2144 SCTP_INP_RLOCK(inp);
2145 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2146 events->sctp_data_io_event = 1;
2148 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2149 events->sctp_association_event = 1;
2151 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2152 events->sctp_address_event = 1;
2154 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2155 events->sctp_send_failure_event = 1;
2157 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2158 events->sctp_peer_error_event = 1;
2160 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2161 events->sctp_shutdown_event = 1;
2163 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2164 events->sctp_partial_delivery_event = 1;
2166 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2167 events->sctp_adaptation_layer_event = 1;
2169 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2170 events->sctp_authentication_event = 1;
2172 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2173 events->sctp_sender_dry_event = 1;
2175 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2176 events->sctp_stream_reset_event = 1;
2177 SCTP_INP_RUNLOCK(inp);
2178 *optsize = sizeof(struct sctp_event_subscribe);
2181 case SCTP_ADAPTATION_LAYER:
2185 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2187 SCTP_INP_RLOCK(inp);
2188 *value = inp->sctp_ep.adaptation_layer_indicator;
2189 SCTP_INP_RUNLOCK(inp);
2190 *optsize = sizeof(uint32_t);
2193 case SCTP_SET_INITIAL_DBG_SEQ:
2197 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2198 SCTP_INP_RLOCK(inp);
2199 *value = inp->sctp_ep.initial_sequence_debug;
2200 SCTP_INP_RUNLOCK(inp);
2201 *optsize = sizeof(uint32_t);
2204 case SCTP_GET_LOCAL_ADDR_SIZE:
2208 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2209 SCTP_INP_RLOCK(inp);
2210 *value = sctp_count_max_addresses(inp);
2211 SCTP_INP_RUNLOCK(inp);
2212 *optsize = sizeof(uint32_t);
2215 case SCTP_GET_REMOTE_ADDR_SIZE:
2219 struct sctp_nets *net;
2221 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2222 /* FIXME MT: change to sctp_assoc_value? */
2223 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2227 /* Count the sizes */
2228 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2229 switch (net->ro._l_addr.sa.sa_family) {
2233 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2234 size += sizeof(struct sockaddr_in6);
2236 size += sizeof(struct sockaddr_in);
2239 size += sizeof(struct sockaddr_in);
2245 size += sizeof(struct sockaddr_in6);
2252 SCTP_TCB_UNLOCK(stcb);
2253 *value = (uint32_t) size;
2254 *optsize = sizeof(uint32_t);
2256 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2261 case SCTP_GET_PEER_ADDRESSES:
2263 * Get the address information, an array is passed in to
2264 * fill up we pack it.
2268 struct sockaddr_storage *sas;
2269 struct sctp_nets *net;
2270 struct sctp_getaddresses *saddr;
2272 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2273 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2276 left = (*optsize) - sizeof(struct sctp_getaddresses);
2277 *optsize = sizeof(struct sctp_getaddresses);
2278 sas = (struct sockaddr_storage *)&saddr->addr[0];
2280 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2281 switch (net->ro._l_addr.sa.sa_family) {
2285 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2286 cpsz = sizeof(struct sockaddr_in6);
2288 cpsz = sizeof(struct sockaddr_in);
2291 cpsz = sizeof(struct sockaddr_in);
2297 cpsz = sizeof(struct sockaddr_in6);
2308 /* not enough room. */
2311 #if defined(INET) && defined(INET6)
2312 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2313 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2314 /* Must map the address */
2315 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2316 (struct sockaddr_in6 *)sas);
2318 memcpy(sas, &net->ro._l_addr, cpsz);
2321 memcpy(sas, &net->ro._l_addr, cpsz);
2323 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2325 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2329 SCTP_TCB_UNLOCK(stcb);
2331 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2336 case SCTP_GET_LOCAL_ADDRESSES:
2338 size_t limit, actual;
2339 struct sockaddr_storage *sas;
2340 struct sctp_getaddresses *saddr;
2342 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2343 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2345 sas = (struct sockaddr_storage *)&saddr->addr[0];
2346 limit = *optsize - sizeof(sctp_assoc_t);
2347 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2349 SCTP_TCB_UNLOCK(stcb);
2351 *optsize = sizeof(struct sockaddr_storage) + actual;
2354 case SCTP_PEER_ADDR_PARAMS:
2356 struct sctp_paddrparams *paddrp;
2357 struct sctp_nets *net;
2358 struct sockaddr *addr;
2360 #if defined(INET) && defined(INET6)
2361 struct sockaddr_in sin_store;
2365 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2366 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2368 #if defined(INET) && defined(INET6)
2369 if (paddrp->spp_address.ss_family == AF_INET6) {
2370 struct sockaddr_in6 *sin6;
2372 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2373 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2374 in6_sin6_2_sin(&sin_store, sin6);
2375 addr = (struct sockaddr *)&sin_store;
2377 addr = (struct sockaddr *)&paddrp->spp_address;
2380 addr = (struct sockaddr *)&paddrp->spp_address;
2383 addr = (struct sockaddr *)&paddrp->spp_address;
2386 net = sctp_findnet(stcb, addr);
2389 * We increment here since
2390 * sctp_findassociation_ep_addr() wil do a
2391 * decrement if it finds the stcb as long as
2392 * the locked tcb (last argument) is NOT a
2396 SCTP_INP_INCR_REF(inp);
2397 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2399 SCTP_INP_DECR_REF(inp);
2402 if ((stcb != NULL) && (net == NULL)) {
2404 if (addr->sa_family == AF_INET) {
2405 struct sockaddr_in *sin;
2407 sin = (struct sockaddr_in *)addr;
2408 if (sin->sin_addr.s_addr != INADDR_ANY) {
2410 SCTP_TCB_UNLOCK(stcb);
2411 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2417 if (addr->sa_family == AF_INET6) {
2418 struct sockaddr_in6 *sin6;
2420 sin6 = (struct sockaddr_in6 *)addr;
2421 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2423 SCTP_TCB_UNLOCK(stcb);
2424 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2430 error = EAFNOSUPPORT;
2431 SCTP_TCB_UNLOCK(stcb);
2432 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2437 /* Applies to the specific association */
2438 paddrp->spp_flags = 0;
2442 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2443 ovh = SCTP_MED_OVERHEAD;
2445 ovh = SCTP_MED_V4_OVERHEAD;
2448 paddrp->spp_hbinterval = net->heart_beat_delay;
2449 paddrp->spp_pathmaxrxt = net->failure_threshold;
2450 paddrp->spp_pathmtu = net->mtu - ovh;
2451 /* get flags for HB */
2452 if (net->dest_state & SCTP_ADDR_NOHB) {
2453 paddrp->spp_flags |= SPP_HB_DISABLE;
2455 paddrp->spp_flags |= SPP_HB_ENABLE;
2457 /* get flags for PMTU */
2458 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2459 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2461 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2463 if (net->dscp & 0x01) {
2464 paddrp->spp_dscp = net->dscp & 0xfc;
2465 paddrp->spp_flags |= SPP_DSCP;
2468 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2469 (net->flowlabel & 0x80000000)) {
2470 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2471 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2476 * No destination so return default
2479 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2480 paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
2481 if (stcb->asoc.default_dscp & 0x01) {
2482 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2483 paddrp->spp_flags |= SPP_DSCP;
2486 if (stcb->asoc.default_flowlabel & 0x80000000) {
2487 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2488 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2491 /* default settings should be these */
2492 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2493 paddrp->spp_flags |= SPP_HB_DISABLE;
2495 paddrp->spp_flags |= SPP_HB_ENABLE;
2497 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2498 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2500 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2502 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2504 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2505 SCTP_TCB_UNLOCK(stcb);
2507 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2508 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2509 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2510 /* Use endpoint defaults */
2511 SCTP_INP_RLOCK(inp);
2512 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2513 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2514 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2515 /* get inp's default */
2516 if (inp->sctp_ep.default_dscp & 0x01) {
2517 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2518 paddrp->spp_flags |= SPP_DSCP;
2521 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2522 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2523 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2524 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2527 /* can't return this */
2528 paddrp->spp_pathmtu = 0;
2530 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2531 paddrp->spp_flags |= SPP_HB_ENABLE;
2533 paddrp->spp_flags |= SPP_HB_DISABLE;
2535 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2536 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2538 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2540 SCTP_INP_RUNLOCK(inp);
2542 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2547 *optsize = sizeof(struct sctp_paddrparams);
2551 case SCTP_GET_PEER_ADDR_INFO:
2553 struct sctp_paddrinfo *paddri;
2554 struct sctp_nets *net;
2555 struct sockaddr *addr;
2557 #if defined(INET) && defined(INET6)
2558 struct sockaddr_in sin_store;
2562 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2563 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2565 #if defined(INET) && defined(INET6)
2566 if (paddri->spinfo_address.ss_family == AF_INET6) {
2567 struct sockaddr_in6 *sin6;
2569 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2570 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2571 in6_sin6_2_sin(&sin_store, sin6);
2572 addr = (struct sockaddr *)&sin_store;
2574 addr = (struct sockaddr *)&paddri->spinfo_address;
2577 addr = (struct sockaddr *)&paddri->spinfo_address;
2580 addr = (struct sockaddr *)&paddri->spinfo_address;
2583 net = sctp_findnet(stcb, addr);
2586 * We increment here since
2587 * sctp_findassociation_ep_addr() wil do a
2588 * decrement if it finds the stcb as long as
2589 * the locked tcb (last argument) is NOT a
2593 SCTP_INP_INCR_REF(inp);
2594 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2596 SCTP_INP_DECR_REF(inp);
2600 if ((stcb != NULL) && (net != NULL)) {
2601 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2602 /* It's unconfirmed */
2603 paddri->spinfo_state = SCTP_UNCONFIRMED;
2604 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2606 paddri->spinfo_state = SCTP_ACTIVE;
2609 paddri->spinfo_state = SCTP_INACTIVE;
2611 paddri->spinfo_cwnd = net->cwnd;
2612 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2613 paddri->spinfo_rto = net->RTO;
2614 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2615 paddri->spinfo_mtu = net->mtu;
2616 SCTP_TCB_UNLOCK(stcb);
2617 *optsize = sizeof(struct sctp_paddrinfo);
2620 SCTP_TCB_UNLOCK(stcb);
2622 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2627 case SCTP_PCB_STATUS:
2629 struct sctp_pcbinfo *spcb;
2631 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2632 sctp_fill_pcbinfo(spcb);
2633 *optsize = sizeof(struct sctp_pcbinfo);
2638 struct sctp_nets *net;
2639 struct sctp_status *sstat;
2641 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2642 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2645 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2650 * I think passing the state is fine since
2651 * sctp_constants.h will be available to the user
2654 sstat->sstat_state = stcb->asoc.state;
2655 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2656 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2657 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2659 * We can't include chunks that have been passed to
2660 * the socket layer. Only things in queue.
2662 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2663 stcb->asoc.cnt_on_all_streams);
2666 sstat->sstat_instrms = stcb->asoc.streamincnt;
2667 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2668 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2669 memcpy(&sstat->sstat_primary.spinfo_address,
2670 &stcb->asoc.primary_destination->ro._l_addr,
2671 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2672 net = stcb->asoc.primary_destination;
2673 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2675 * Again the user can get info from sctp_constants.h
2676 * for what the state of the network is.
2678 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2679 /* It's unconfirmed */
2680 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2681 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2683 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2686 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2688 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2689 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2690 sstat->sstat_primary.spinfo_rto = net->RTO;
2691 sstat->sstat_primary.spinfo_mtu = net->mtu;
2692 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2693 SCTP_TCB_UNLOCK(stcb);
2694 *optsize = sizeof(struct sctp_status);
2699 struct sctp_rtoinfo *srto;
2701 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2702 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2705 srto->srto_initial = stcb->asoc.initial_rto;
2706 srto->srto_max = stcb->asoc.maxrto;
2707 srto->srto_min = stcb->asoc.minrto;
2708 SCTP_TCB_UNLOCK(stcb);
2710 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2711 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2712 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2713 SCTP_INP_RLOCK(inp);
2714 srto->srto_initial = inp->sctp_ep.initial_rto;
2715 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2716 srto->srto_min = inp->sctp_ep.sctp_minrto;
2717 SCTP_INP_RUNLOCK(inp);
2719 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2724 *optsize = sizeof(struct sctp_rtoinfo);
2730 struct sctp_timeouts *stimo;
2732 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2733 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2736 stimo->stimo_init = stcb->asoc.timoinit;
2737 stimo->stimo_data = stcb->asoc.timodata;
2738 stimo->stimo_sack = stcb->asoc.timosack;
2739 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2740 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2741 stimo->stimo_cookie = stcb->asoc.timocookie;
2742 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2743 SCTP_TCB_UNLOCK(stcb);
2744 *optsize = sizeof(struct sctp_timeouts);
2746 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2751 case SCTP_ASSOCINFO:
2753 struct sctp_assocparams *sasoc;
2755 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2756 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2759 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2760 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2761 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2762 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2763 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2764 SCTP_TCB_UNLOCK(stcb);
2766 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2767 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2768 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2769 SCTP_INP_RLOCK(inp);
2770 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2771 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2772 sasoc->sasoc_number_peer_destinations = 0;
2773 sasoc->sasoc_peer_rwnd = 0;
2774 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2775 SCTP_INP_RUNLOCK(inp);
2777 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2782 *optsize = sizeof(struct sctp_assocparams);
2786 case SCTP_DEFAULT_SEND_PARAM:
2788 struct sctp_sndrcvinfo *s_info;
2790 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2791 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2794 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2795 SCTP_TCB_UNLOCK(stcb);
2797 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2798 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2799 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2800 SCTP_INP_RLOCK(inp);
2801 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2802 SCTP_INP_RUNLOCK(inp);
2804 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2809 *optsize = sizeof(struct sctp_sndrcvinfo);
2815 struct sctp_initmsg *sinit;
2817 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2818 SCTP_INP_RLOCK(inp);
2819 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2820 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2821 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2822 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2823 SCTP_INP_RUNLOCK(inp);
2824 *optsize = sizeof(struct sctp_initmsg);
2827 case SCTP_PRIMARY_ADDR:
2828 /* we allow a "get" operation on this */
2830 struct sctp_setprim *ssp;
2832 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2833 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2836 union sctp_sockstore *addr;
2838 addr = &stcb->asoc.primary_destination->ro._l_addr;
2839 switch (addr->sa.sa_family) {
2843 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2844 in6_sin_2_v4mapsin6(&addr->sin,
2845 (struct sockaddr_in6 *)&ssp->ssp_addr);
2847 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2850 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2856 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2862 SCTP_TCB_UNLOCK(stcb);
2863 *optsize = sizeof(struct sctp_setprim);
2865 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2870 case SCTP_HMAC_IDENT:
2872 struct sctp_hmacalgo *shmac;
2873 sctp_hmaclist_t *hmaclist;
2877 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2879 SCTP_INP_RLOCK(inp);
2880 hmaclist = inp->sctp_ep.local_hmacs;
2881 if (hmaclist == NULL) {
2882 /* no HMACs to return */
2883 *optsize = sizeof(*shmac);
2884 SCTP_INP_RUNLOCK(inp);
2887 /* is there room for all of the hmac ids? */
2888 size = sizeof(*shmac) + (hmaclist->num_algo *
2889 sizeof(shmac->shmac_idents[0]));
2890 if ((size_t)(*optsize) < size) {
2891 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2893 SCTP_INP_RUNLOCK(inp);
2896 /* copy in the list */
2897 shmac->shmac_number_of_idents = hmaclist->num_algo;
2898 for (i = 0; i < hmaclist->num_algo; i++) {
2899 shmac->shmac_idents[i] = hmaclist->hmac[i];
2901 SCTP_INP_RUNLOCK(inp);
2905 case SCTP_AUTH_ACTIVE_KEY:
2907 struct sctp_authkeyid *scact;
2909 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2910 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2913 /* get the active key on the assoc */
2914 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2915 SCTP_TCB_UNLOCK(stcb);
2917 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2918 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2919 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2920 /* get the endpoint active key */
2921 SCTP_INP_RLOCK(inp);
2922 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2923 SCTP_INP_RUNLOCK(inp);
2925 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2930 *optsize = sizeof(struct sctp_authkeyid);
2934 case SCTP_LOCAL_AUTH_CHUNKS:
2936 struct sctp_authchunks *sac;
2937 sctp_auth_chklist_t *chklist = NULL;
2940 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2941 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2944 /* get off the assoc */
2945 chklist = stcb->asoc.local_auth_chunks;
2946 /* is there enough space? */
2947 size = sctp_auth_get_chklist_size(chklist);
2948 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2950 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2952 /* copy in the chunks */
2953 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2954 sac->gauth_number_of_chunks = (uint32_t) size;
2955 *optsize = sizeof(struct sctp_authchunks) + size;
2957 SCTP_TCB_UNLOCK(stcb);
2959 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2960 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2961 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2962 /* get off the endpoint */
2963 SCTP_INP_RLOCK(inp);
2964 chklist = inp->sctp_ep.local_auth_chunks;
2965 /* is there enough space? */
2966 size = sctp_auth_get_chklist_size(chklist);
2967 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2969 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2971 /* copy in the chunks */
2972 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2973 sac->gauth_number_of_chunks = (uint32_t) size;
2974 *optsize = sizeof(struct sctp_authchunks) + size;
2976 SCTP_INP_RUNLOCK(inp);
2978 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2984 case SCTP_PEER_AUTH_CHUNKS:
2986 struct sctp_authchunks *sac;
2987 sctp_auth_chklist_t *chklist = NULL;
2990 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2991 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2994 /* get off the assoc */
2995 chklist = stcb->asoc.peer_auth_chunks;
2996 /* is there enough space? */
2997 size = sctp_auth_get_chklist_size(chklist);
2998 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
3000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3002 /* copy in the chunks */
3003 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
3004 sac->gauth_number_of_chunks = (uint32_t) size;
3005 *optsize = sizeof(struct sctp_authchunks) + size;
3007 SCTP_TCB_UNLOCK(stcb);
3009 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3016 struct sctp_event *event;
3017 uint32_t event_type;
3019 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3020 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3022 switch (event->se_type) {
3023 case SCTP_ASSOC_CHANGE:
3024 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3026 case SCTP_PEER_ADDR_CHANGE:
3027 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3029 case SCTP_REMOTE_ERROR:
3030 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3032 case SCTP_SEND_FAILED:
3033 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3035 case SCTP_SHUTDOWN_EVENT:
3036 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3038 case SCTP_ADAPTATION_INDICATION:
3039 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3041 case SCTP_PARTIAL_DELIVERY_EVENT:
3042 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3044 case SCTP_AUTHENTICATION_EVENT:
3045 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3047 case SCTP_STREAM_RESET_EVENT:
3048 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3050 case SCTP_SENDER_DRY_EVENT:
3051 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3053 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3055 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3058 case SCTP_ASSOC_RESET_EVENT:
3059 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3061 case SCTP_STREAM_CHANGE_EVENT:
3062 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3064 case SCTP_SEND_FAILED_EVENT:
3065 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3069 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3073 if (event_type > 0) {
3075 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3076 SCTP_TCB_UNLOCK(stcb);
3078 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3079 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3080 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3081 SCTP_INP_RLOCK(inp);
3082 event->se_on = sctp_is_feature_on(inp, event_type);
3083 SCTP_INP_RUNLOCK(inp);
3085 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3091 *optsize = sizeof(struct sctp_event);
3095 case SCTP_RECVRCVINFO:
3099 if (*optsize < sizeof(int)) {
3100 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3103 SCTP_INP_RLOCK(inp);
3104 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3105 SCTP_INP_RUNLOCK(inp);
3108 /* return the option value */
3109 *(int *)optval = onoff;
3110 *optsize = sizeof(int);
3114 case SCTP_RECVNXTINFO:
3118 if (*optsize < sizeof(int)) {
3119 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3122 SCTP_INP_RLOCK(inp);
3123 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3124 SCTP_INP_RUNLOCK(inp);
3127 /* return the option value */
3128 *(int *)optval = onoff;
3129 *optsize = sizeof(int);
3133 case SCTP_DEFAULT_SNDINFO:
3135 struct sctp_sndinfo *info;
3137 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3138 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3141 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3142 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3143 info->snd_flags &= 0xfff0;
3144 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3145 info->snd_context = stcb->asoc.def_send.sinfo_context;
3146 SCTP_TCB_UNLOCK(stcb);
3148 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3149 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3150 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3151 SCTP_INP_RLOCK(inp);
3152 info->snd_sid = inp->def_send.sinfo_stream;
3153 info->snd_flags = inp->def_send.sinfo_flags;
3154 info->snd_flags &= 0xfff0;
3155 info->snd_ppid = inp->def_send.sinfo_ppid;
3156 info->snd_context = inp->def_send.sinfo_context;
3157 SCTP_INP_RUNLOCK(inp);
3159 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3164 *optsize = sizeof(struct sctp_sndinfo);
3168 case SCTP_DEFAULT_PRINFO:
3170 struct sctp_default_prinfo *info;
3172 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3173 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3176 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3177 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3178 SCTP_TCB_UNLOCK(stcb);
3180 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3181 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3182 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3183 SCTP_INP_RLOCK(inp);
3184 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3185 info->pr_value = inp->def_send.sinfo_timetolive;
3186 SCTP_INP_RUNLOCK(inp);
3188 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3193 *optsize = sizeof(struct sctp_default_prinfo);
3197 case SCTP_PEER_ADDR_THLDS:
3199 struct sctp_paddrthlds *thlds;
3200 struct sctp_nets *net;
3201 struct sockaddr *addr;
3203 #if defined(INET) && defined(INET6)
3204 struct sockaddr_in sin_store;
3208 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3209 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3211 #if defined(INET) && defined(INET6)
3212 if (thlds->spt_address.ss_family == AF_INET6) {
3213 struct sockaddr_in6 *sin6;
3215 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3216 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3217 in6_sin6_2_sin(&sin_store, sin6);
3218 addr = (struct sockaddr *)&sin_store;
3220 addr = (struct sockaddr *)&thlds->spt_address;
3223 addr = (struct sockaddr *)&thlds->spt_address;
3226 addr = (struct sockaddr *)&thlds->spt_address;
3229 net = sctp_findnet(stcb, addr);
3232 * We increment here since
3233 * sctp_findassociation_ep_addr() wil do a
3234 * decrement if it finds the stcb as long as
3235 * the locked tcb (last argument) is NOT a
3239 SCTP_INP_INCR_REF(inp);
3240 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3242 SCTP_INP_DECR_REF(inp);
3245 if ((stcb != NULL) && (net == NULL)) {
3247 if (addr->sa_family == AF_INET) {
3248 struct sockaddr_in *sin;
3250 sin = (struct sockaddr_in *)addr;
3251 if (sin->sin_addr.s_addr != INADDR_ANY) {
3253 SCTP_TCB_UNLOCK(stcb);
3254 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3260 if (addr->sa_family == AF_INET6) {
3261 struct sockaddr_in6 *sin6;
3263 sin6 = (struct sockaddr_in6 *)addr;
3264 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3266 SCTP_TCB_UNLOCK(stcb);
3267 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3273 error = EAFNOSUPPORT;
3274 SCTP_TCB_UNLOCK(stcb);
3275 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3281 thlds->spt_pathmaxrxt = net->failure_threshold;
3282 thlds->spt_pathpfthld = net->pf_threshold;
3284 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3285 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3287 thlds->spt_assoc_id = sctp_get_associd(stcb);
3288 SCTP_TCB_UNLOCK(stcb);
3290 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3291 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3292 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3293 /* Use endpoint defaults */
3294 SCTP_INP_RLOCK(inp);
3295 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3296 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3297 SCTP_INP_RUNLOCK(inp);
3299 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3304 *optsize = sizeof(struct sctp_paddrthlds);
3308 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3310 struct sctp_udpencaps *encaps;
3311 struct sctp_nets *net;
3312 struct sockaddr *addr;
3314 #if defined(INET) && defined(INET6)
3315 struct sockaddr_in sin_store;
3319 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3320 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3322 #if defined(INET) && defined(INET6)
3323 if (encaps->sue_address.ss_family == AF_INET6) {
3324 struct sockaddr_in6 *sin6;
3326 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3327 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3328 in6_sin6_2_sin(&sin_store, sin6);
3329 addr = (struct sockaddr *)&sin_store;
3331 addr = (struct sockaddr *)&encaps->sue_address;
3334 addr = (struct sockaddr *)&encaps->sue_address;
3337 addr = (struct sockaddr *)&encaps->sue_address;
3340 net = sctp_findnet(stcb, addr);
3343 * We increment here since
3344 * sctp_findassociation_ep_addr() wil do a
3345 * decrement if it finds the stcb as long as
3346 * the locked tcb (last argument) is NOT a
3350 SCTP_INP_INCR_REF(inp);
3351 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3353 SCTP_INP_DECR_REF(inp);
3356 if ((stcb != NULL) && (net == NULL)) {
3358 if (addr->sa_family == AF_INET) {
3359 struct sockaddr_in *sin;
3361 sin = (struct sockaddr_in *)addr;
3362 if (sin->sin_addr.s_addr != INADDR_ANY) {
3364 SCTP_TCB_UNLOCK(stcb);
3365 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3371 if (addr->sa_family == AF_INET6) {
3372 struct sockaddr_in6 *sin6;
3374 sin6 = (struct sockaddr_in6 *)addr;
3375 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3377 SCTP_TCB_UNLOCK(stcb);
3378 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3384 error = EAFNOSUPPORT;
3385 SCTP_TCB_UNLOCK(stcb);
3386 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3392 encaps->sue_port = net->port;
3394 encaps->sue_port = stcb->asoc.port;
3396 SCTP_TCB_UNLOCK(stcb);
3398 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3399 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3400 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3401 SCTP_INP_RLOCK(inp);
3402 encaps->sue_port = inp->sctp_ep.port;
3403 SCTP_INP_RUNLOCK(inp);
3405 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3410 *optsize = sizeof(struct sctp_udpencaps);
3414 case SCTP_ECN_SUPPORTED:
3416 struct sctp_assoc_value *av;
3418 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3419 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3422 av->assoc_value = stcb->asoc.ecn_supported;
3423 SCTP_TCB_UNLOCK(stcb);
3425 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3426 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3427 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3428 SCTP_INP_RLOCK(inp);
3429 av->assoc_value = inp->ecn_supported;
3430 SCTP_INP_RUNLOCK(inp);
3432 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3437 *optsize = sizeof(struct sctp_assoc_value);
3441 case SCTP_PR_SUPPORTED:
3443 struct sctp_assoc_value *av;
3445 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3446 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3449 av->assoc_value = stcb->asoc.prsctp_supported;
3450 SCTP_TCB_UNLOCK(stcb);
3452 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3453 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3454 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3455 SCTP_INP_RLOCK(inp);
3456 av->assoc_value = inp->prsctp_supported;
3457 SCTP_INP_RUNLOCK(inp);
3459 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3464 *optsize = sizeof(struct sctp_assoc_value);
3468 case SCTP_AUTH_SUPPORTED:
3470 struct sctp_assoc_value *av;
3472 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3473 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3476 av->assoc_value = stcb->asoc.auth_supported;
3477 SCTP_TCB_UNLOCK(stcb);
3479 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3480 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3481 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3482 SCTP_INP_RLOCK(inp);
3483 av->assoc_value = inp->auth_supported;
3484 SCTP_INP_RUNLOCK(inp);
3486 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3491 *optsize = sizeof(struct sctp_assoc_value);
3495 case SCTP_ASCONF_SUPPORTED:
3497 struct sctp_assoc_value *av;
3499 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3500 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3503 av->assoc_value = stcb->asoc.asconf_supported;
3504 SCTP_TCB_UNLOCK(stcb);
3506 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3507 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3508 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3509 SCTP_INP_RLOCK(inp);
3510 av->assoc_value = inp->asconf_supported;
3511 SCTP_INP_RUNLOCK(inp);
3513 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3518 *optsize = sizeof(struct sctp_assoc_value);
3522 case SCTP_RECONFIG_SUPPORTED:
3524 struct sctp_assoc_value *av;
3526 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3527 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3530 av->assoc_value = stcb->asoc.reconfig_supported;
3531 SCTP_TCB_UNLOCK(stcb);
3533 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3534 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3535 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3536 SCTP_INP_RLOCK(inp);
3537 av->assoc_value = inp->reconfig_supported;
3538 SCTP_INP_RUNLOCK(inp);
3540 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3545 *optsize = sizeof(struct sctp_assoc_value);
3549 case SCTP_NRSACK_SUPPORTED:
3551 struct sctp_assoc_value *av;
3553 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3554 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3557 av->assoc_value = stcb->asoc.nrsack_supported;
3558 SCTP_TCB_UNLOCK(stcb);
3560 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3561 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3562 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3563 SCTP_INP_RLOCK(inp);
3564 av->assoc_value = inp->nrsack_supported;
3565 SCTP_INP_RUNLOCK(inp);
3567 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3572 *optsize = sizeof(struct sctp_assoc_value);
3576 case SCTP_PKTDROP_SUPPORTED:
3578 struct sctp_assoc_value *av;
3580 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3581 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3584 av->assoc_value = stcb->asoc.pktdrop_supported;
3585 SCTP_TCB_UNLOCK(stcb);
3587 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3588 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3589 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3590 SCTP_INP_RLOCK(inp);
3591 av->assoc_value = inp->pktdrop_supported;
3592 SCTP_INP_RUNLOCK(inp);
3594 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3599 *optsize = sizeof(struct sctp_assoc_value);
3603 case SCTP_ENABLE_STREAM_RESET:
3605 struct sctp_assoc_value *av;
3607 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3608 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3611 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3612 SCTP_TCB_UNLOCK(stcb);
3614 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3615 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3616 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3617 SCTP_INP_RLOCK(inp);
3618 av->assoc_value = (uint32_t) inp->local_strreset_support;
3619 SCTP_INP_RUNLOCK(inp);
3621 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3626 *optsize = sizeof(struct sctp_assoc_value);
3630 case SCTP_PR_STREAM_STATUS:
3632 struct sctp_prstatus *sprstat;
3636 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3637 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3639 sid = sprstat->sprstat_sid;
3640 policy = sprstat->sprstat_policy;
3641 #if defined(SCTP_DETAILED_STR_STATS)
3642 if ((stcb != NULL) &&
3643 (sid < stcb->asoc.streamoutcnt) &&
3644 (policy != SCTP_PR_SCTP_NONE) &&
3645 ((policy <= SCTP_PR_SCTP_MAX) ||
3646 (policy == SCTP_PR_SCTP_ALL))) {
3647 if (policy == SCTP_PR_SCTP_ALL) {
3648 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3649 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3651 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3652 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3655 if ((stcb != NULL) &&
3656 (sid < stcb->asoc.streamoutcnt) &&
3657 (policy == SCTP_PR_SCTP_ALL)) {
3658 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3659 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3661 SCTP_TCB_UNLOCK(stcb);
3662 *optsize = sizeof(struct sctp_prstatus);
3664 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3669 case SCTP_PR_ASSOC_STATUS:
3671 struct sctp_prstatus *sprstat;
3674 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3675 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3677 policy = sprstat->sprstat_policy;
3678 if ((stcb != NULL) &&
3679 (policy != SCTP_PR_SCTP_NONE) &&
3680 ((policy <= SCTP_PR_SCTP_MAX) ||
3681 (policy == SCTP_PR_SCTP_ALL))) {
3682 if (policy == SCTP_PR_SCTP_ALL) {
3683 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3684 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3686 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3687 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3689 SCTP_TCB_UNLOCK(stcb);
3690 *optsize = sizeof(struct sctp_prstatus);
3692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3698 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3699 error = ENOPROTOOPT;
3701 } /* end switch (sopt->sopt_name) */
3709 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3714 struct sctp_tcb *stcb = NULL;
3715 struct sctp_inpcb *inp = NULL;
3718 if (optval == NULL) {
3719 SCTP_PRINTF("optval is NULL\n");
3720 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3723 inp = (struct sctp_inpcb *)so->so_pcb;
3725 SCTP_PRINTF("inp is NULL?\n");
3726 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3729 vrf_id = inp->def_vrf_id;
3734 case SCTP_AUTOCLOSE:
3735 case SCTP_AUTO_ASCONF:
3736 case SCTP_EXPLICIT_EOR:
3737 case SCTP_DISABLE_FRAGMENTS:
3738 case SCTP_USE_EXT_RCVINFO:
3739 case SCTP_I_WANT_MAPPED_V4_ADDR:
3740 /* copy in the option value */
3741 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3746 case SCTP_DISABLE_FRAGMENTS:
3747 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3749 case SCTP_AUTO_ASCONF:
3751 * NOTE: we don't really support this flag
3753 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3754 /* only valid for bound all sockets */
3755 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3757 /* forbidden by admin */
3758 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3761 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3763 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3767 case SCTP_EXPLICIT_EOR:
3768 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3770 case SCTP_USE_EXT_RCVINFO:
3771 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3773 case SCTP_I_WANT_MAPPED_V4_ADDR:
3774 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3775 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3777 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3782 set_opt = SCTP_PCB_FLAGS_NODELAY;
3784 case SCTP_AUTOCLOSE:
3785 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3786 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3787 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3790 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3792 * The value is in ticks. Note this does not effect
3793 * old associations, only new ones.
3795 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3798 SCTP_INP_WLOCK(inp);
3800 sctp_feature_on(inp, set_opt);
3802 sctp_feature_off(inp, set_opt);
3804 SCTP_INP_WUNLOCK(inp);
3806 case SCTP_REUSE_PORT:
3808 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3809 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3810 /* Can't set it after we are bound */
3814 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3815 /* Can't do this for a 1-m socket */
3820 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3822 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3825 case SCTP_PARTIAL_DELIVERY_POINT:
3829 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3830 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3831 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3835 inp->partial_delivery_point = *value;
3838 case SCTP_FRAGMENT_INTERLEAVE:
3839 /* not yet until we re-write sctp_recvmsg() */
3843 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3844 if (*level == SCTP_FRAG_LEVEL_2) {
3845 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3846 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3847 } else if (*level == SCTP_FRAG_LEVEL_1) {
3848 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3849 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3850 } else if (*level == SCTP_FRAG_LEVEL_0) {
3851 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3852 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3855 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3860 case SCTP_CMT_ON_OFF:
3861 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3862 struct sctp_assoc_value *av;
3864 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3865 if (av->assoc_value > SCTP_CMT_MAX) {
3866 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3870 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3872 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3873 SCTP_TCB_UNLOCK(stcb);
3875 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3876 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3877 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3878 (av->assoc_id == SCTP_ALL_ASSOC)) {
3879 SCTP_INP_WLOCK(inp);
3880 inp->sctp_cmt_on_off = av->assoc_value;
3881 SCTP_INP_WUNLOCK(inp);
3883 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3884 (av->assoc_id == SCTP_ALL_ASSOC)) {
3885 SCTP_INP_RLOCK(inp);
3886 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3887 SCTP_TCB_LOCK(stcb);
3888 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3889 SCTP_TCB_UNLOCK(stcb);
3891 SCTP_INP_RUNLOCK(inp);
3895 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3896 error = ENOPROTOOPT;
3899 case SCTP_PLUGGABLE_CC:
3901 struct sctp_assoc_value *av;
3902 struct sctp_nets *net;
3904 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3905 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3906 (av->assoc_value != SCTP_CC_HSTCP) &&
3907 (av->assoc_value != SCTP_CC_HTCP) &&
3908 (av->assoc_value != SCTP_CC_RTCC)) {
3909 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3913 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3915 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3916 stcb->asoc.congestion_control_module = av->assoc_value;
3917 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3918 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3919 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3922 SCTP_TCB_UNLOCK(stcb);
3924 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3925 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3926 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3927 (av->assoc_id == SCTP_ALL_ASSOC)) {
3928 SCTP_INP_WLOCK(inp);
3929 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3930 SCTP_INP_WUNLOCK(inp);
3932 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3933 (av->assoc_id == SCTP_ALL_ASSOC)) {
3934 SCTP_INP_RLOCK(inp);
3935 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3936 SCTP_TCB_LOCK(stcb);
3937 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3938 stcb->asoc.congestion_control_module = av->assoc_value;
3939 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3940 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3941 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3944 SCTP_TCB_UNLOCK(stcb);
3946 SCTP_INP_RUNLOCK(inp);
3951 case SCTP_CC_OPTION:
3953 struct sctp_cc_option *cc_opt;
3955 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
3956 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
3958 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
3959 SCTP_INP_RLOCK(inp);
3960 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3961 SCTP_TCB_LOCK(stcb);
3962 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
3963 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
3965 SCTP_TCB_UNLOCK(stcb);
3967 SCTP_INP_RUNLOCK(inp);
3972 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
3975 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
3978 SCTP_TCB_UNLOCK(stcb);
3982 case SCTP_PLUGGABLE_SS:
3984 struct sctp_assoc_value *av;
3986 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3987 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
3988 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
3989 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
3990 (av->assoc_value != SCTP_SS_PRIORITY) &&
3991 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
3992 (av->assoc_value != SCTP_SS_FIRST_COME)) {
3993 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3997 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3999 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4000 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4001 stcb->asoc.stream_scheduling_module = av->assoc_value;
4002 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4003 SCTP_TCB_UNLOCK(stcb);
4005 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4006 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4007 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4008 (av->assoc_id == SCTP_ALL_ASSOC)) {
4009 SCTP_INP_WLOCK(inp);
4010 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4011 SCTP_INP_WUNLOCK(inp);
4013 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4014 (av->assoc_id == SCTP_ALL_ASSOC)) {
4015 SCTP_INP_RLOCK(inp);
4016 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4017 SCTP_TCB_LOCK(stcb);
4018 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4019 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4020 stcb->asoc.stream_scheduling_module = av->assoc_value;
4021 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4022 SCTP_TCB_UNLOCK(stcb);
4024 SCTP_INP_RUNLOCK(inp);
4031 struct sctp_stream_value *av;
4033 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4034 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4036 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4037 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4038 av->stream_value) < 0)) {
4039 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4042 SCTP_TCB_UNLOCK(stcb);
4044 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4045 SCTP_INP_RLOCK(inp);
4046 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4047 SCTP_TCB_LOCK(stcb);
4048 if (av->stream_id < stcb->asoc.streamoutcnt) {
4049 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4051 &stcb->asoc.strmout[av->stream_id],
4054 SCTP_TCB_UNLOCK(stcb);
4056 SCTP_INP_RUNLOCK(inp);
4060 * Can't set stream value without
4063 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4069 case SCTP_CLR_STAT_LOG:
4070 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4075 struct sctp_assoc_value *av;
4077 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4078 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4081 stcb->asoc.context = av->assoc_value;
4082 SCTP_TCB_UNLOCK(stcb);
4084 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4085 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4086 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4087 (av->assoc_id == SCTP_ALL_ASSOC)) {
4088 SCTP_INP_WLOCK(inp);
4089 inp->sctp_context = av->assoc_value;
4090 SCTP_INP_WUNLOCK(inp);
4092 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4093 (av->assoc_id == SCTP_ALL_ASSOC)) {
4094 SCTP_INP_RLOCK(inp);
4095 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4096 SCTP_TCB_LOCK(stcb);
4097 stcb->asoc.context = av->assoc_value;
4098 SCTP_TCB_UNLOCK(stcb);
4100 SCTP_INP_RUNLOCK(inp);
4107 uint32_t *default_vrfid;
4109 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4110 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4111 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4115 inp->def_vrf_id = *default_vrfid;
4118 case SCTP_DEL_VRF_ID:
4120 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4124 case SCTP_ADD_VRF_ID:
4126 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4130 case SCTP_DELAYED_SACK:
4132 struct sctp_sack_info *sack;
4134 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4135 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4136 if (sack->sack_delay) {
4137 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4138 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4139 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4140 sack->sack_delay = TICKS_TO_MSEC(1);
4144 if (sack->sack_delay) {
4145 stcb->asoc.delayed_ack = sack->sack_delay;
4147 if (sack->sack_freq) {
4148 stcb->asoc.sack_freq = sack->sack_freq;
4150 SCTP_TCB_UNLOCK(stcb);
4152 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4153 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4154 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4155 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4156 SCTP_INP_WLOCK(inp);
4157 if (sack->sack_delay) {
4158 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4160 if (sack->sack_freq) {
4161 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4163 SCTP_INP_WUNLOCK(inp);
4165 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4166 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4167 SCTP_INP_RLOCK(inp);
4168 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4169 SCTP_TCB_LOCK(stcb);
4170 if (sack->sack_delay) {
4171 stcb->asoc.delayed_ack = sack->sack_delay;
4173 if (sack->sack_freq) {
4174 stcb->asoc.sack_freq = sack->sack_freq;
4176 SCTP_TCB_UNLOCK(stcb);
4178 SCTP_INP_RUNLOCK(inp);
4183 case SCTP_AUTH_CHUNK:
4185 struct sctp_authchunk *sauth;
4187 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4189 SCTP_INP_WLOCK(inp);
4190 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4191 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4194 SCTP_INP_WUNLOCK(inp);
4199 struct sctp_authkey *sca;
4200 struct sctp_keyhead *shared_keys;
4201 sctp_sharedkey_t *shared_key;
4202 sctp_key_t *key = NULL;
4205 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4206 if (sca->sca_keylength == 0) {
4207 size = optsize - sizeof(struct sctp_authkey);
4209 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4210 size = sca->sca_keylength;
4212 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4217 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4220 shared_keys = &stcb->asoc.shared_keys;
4221 /* clear the cached keys for this key id */
4222 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4224 * create the new shared key and
4228 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4230 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4232 SCTP_TCB_UNLOCK(stcb);
4236 shared_key = sctp_alloc_sharedkey();
4237 if (shared_key == NULL) {
4239 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4241 SCTP_TCB_UNLOCK(stcb);
4244 shared_key->key = key;
4245 shared_key->keyid = sca->sca_keynumber;
4246 error = sctp_insert_sharedkey(shared_keys, shared_key);
4247 SCTP_TCB_UNLOCK(stcb);
4249 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4250 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4251 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4252 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4253 SCTP_INP_WLOCK(inp);
4254 shared_keys = &inp->sctp_ep.shared_keys;
4256 * clear the cached keys on all
4257 * assocs for this key id
4259 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4261 * create the new shared key and
4265 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4267 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4269 SCTP_INP_WUNLOCK(inp);
4273 shared_key = sctp_alloc_sharedkey();
4274 if (shared_key == NULL) {
4276 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4278 SCTP_INP_WUNLOCK(inp);
4281 shared_key->key = key;
4282 shared_key->keyid = sca->sca_keynumber;
4283 error = sctp_insert_sharedkey(shared_keys, shared_key);
4284 SCTP_INP_WUNLOCK(inp);
4286 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4287 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4288 SCTP_INP_RLOCK(inp);
4289 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4290 SCTP_TCB_LOCK(stcb);
4291 shared_keys = &stcb->asoc.shared_keys;
4293 * clear the cached keys for
4296 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4298 * create the new shared key
4299 * and insert/replace it
4302 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4304 SCTP_TCB_UNLOCK(stcb);
4308 shared_key = sctp_alloc_sharedkey();
4309 if (shared_key == NULL) {
4311 SCTP_TCB_UNLOCK(stcb);
4314 shared_key->key = key;
4315 shared_key->keyid = sca->sca_keynumber;
4316 error = sctp_insert_sharedkey(shared_keys, shared_key);
4317 SCTP_TCB_UNLOCK(stcb);
4319 SCTP_INP_RUNLOCK(inp);
4324 case SCTP_HMAC_IDENT:
4326 struct sctp_hmacalgo *shmac;
4327 sctp_hmaclist_t *hmaclist;
4331 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4332 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4333 (shmac->shmac_number_of_idents > 0xffff)) {
4334 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4338 hmaclist = sctp_alloc_hmaclist((uint16_t) shmac->shmac_number_of_idents);
4339 if (hmaclist == NULL) {
4340 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4344 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4345 hmacid = shmac->shmac_idents[i];
4346 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4347 /* invalid HMACs were found */ ;
4348 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4350 sctp_free_hmaclist(hmaclist);
4351 goto sctp_set_hmac_done;
4354 for (i = 0; i < hmaclist->num_algo; i++) {
4355 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4356 /* already in list */
4360 if (i == hmaclist->num_algo) {
4361 /* not found in list */
4362 sctp_free_hmaclist(hmaclist);
4363 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4367 /* set it on the endpoint */
4368 SCTP_INP_WLOCK(inp);
4369 if (inp->sctp_ep.local_hmacs)
4370 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4371 inp->sctp_ep.local_hmacs = hmaclist;
4372 SCTP_INP_WUNLOCK(inp);
4376 case SCTP_AUTH_ACTIVE_KEY:
4378 struct sctp_authkeyid *scact;
4380 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4381 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4383 /* set the active key on the right place */
4385 /* set the active key on the assoc */
4386 if (sctp_auth_setactivekey(stcb,
4387 scact->scact_keynumber)) {
4388 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4389 SCTP_FROM_SCTP_USRREQ,
4393 SCTP_TCB_UNLOCK(stcb);
4395 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4396 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4397 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4398 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4399 SCTP_INP_WLOCK(inp);
4400 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4401 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4404 SCTP_INP_WUNLOCK(inp);
4406 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4407 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4408 SCTP_INP_RLOCK(inp);
4409 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4410 SCTP_TCB_LOCK(stcb);
4411 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4412 SCTP_TCB_UNLOCK(stcb);
4414 SCTP_INP_RUNLOCK(inp);
4419 case SCTP_AUTH_DELETE_KEY:
4421 struct sctp_authkeyid *scdel;
4423 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4424 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4426 /* delete the key from the right place */
4428 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4429 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4432 SCTP_TCB_UNLOCK(stcb);
4434 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4435 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4436 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4437 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4438 SCTP_INP_WLOCK(inp);
4439 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4440 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4443 SCTP_INP_WUNLOCK(inp);
4445 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4446 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4447 SCTP_INP_RLOCK(inp);
4448 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4449 SCTP_TCB_LOCK(stcb);
4450 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4451 SCTP_TCB_UNLOCK(stcb);
4453 SCTP_INP_RUNLOCK(inp);
4458 case SCTP_AUTH_DEACTIVATE_KEY:
4460 struct sctp_authkeyid *keyid;
4462 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4463 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4465 /* deactivate the key from the right place */
4467 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4468 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4471 SCTP_TCB_UNLOCK(stcb);
4473 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4474 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4475 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4476 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4477 SCTP_INP_WLOCK(inp);
4478 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4479 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4482 SCTP_INP_WUNLOCK(inp);
4484 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4485 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4486 SCTP_INP_RLOCK(inp);
4487 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4488 SCTP_TCB_LOCK(stcb);
4489 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4490 SCTP_TCB_UNLOCK(stcb);
4492 SCTP_INP_RUNLOCK(inp);
4497 case SCTP_ENABLE_STREAM_RESET:
4499 struct sctp_assoc_value *av;
4501 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4502 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4503 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4507 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4509 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4510 SCTP_TCB_UNLOCK(stcb);
4512 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4513 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4514 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4515 (av->assoc_id == SCTP_ALL_ASSOC)) {
4516 SCTP_INP_WLOCK(inp);
4517 inp->local_strreset_support = (uint8_t) av->assoc_value;
4518 SCTP_INP_WUNLOCK(inp);
4520 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4521 (av->assoc_id == SCTP_ALL_ASSOC)) {
4522 SCTP_INP_RLOCK(inp);
4523 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4524 SCTP_TCB_LOCK(stcb);
4525 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4526 SCTP_TCB_UNLOCK(stcb);
4528 SCTP_INP_RUNLOCK(inp);
4533 case SCTP_RESET_STREAMS:
4535 struct sctp_reset_streams *strrst;
4536 int i, send_out = 0;
4539 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4540 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4542 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4546 if (stcb->asoc.reconfig_supported == 0) {
4548 * Peer does not support the chunk type.
4550 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4552 SCTP_TCB_UNLOCK(stcb);
4555 if (sizeof(struct sctp_reset_streams) +
4556 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4558 SCTP_TCB_UNLOCK(stcb);
4561 if (stcb->asoc.stream_reset_outstanding) {
4562 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4564 SCTP_TCB_UNLOCK(stcb);
4567 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4570 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4573 if ((send_in == 0) && (send_out == 0)) {
4574 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4576 SCTP_TCB_UNLOCK(stcb);
4579 for (i = 0; i < strrst->srs_number_streams; i++) {
4581 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4582 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4587 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4588 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4594 SCTP_TCB_UNLOCK(stcb);
4597 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4598 strrst->srs_stream_list,
4599 send_out, send_in, 0, 0, 0, 0, 0);
4601 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4602 SCTP_TCB_UNLOCK(stcb);
4605 case SCTP_ADD_STREAMS:
4607 struct sctp_add_streams *stradd;
4608 uint8_t addstream = 0;
4609 uint16_t add_o_strmcnt = 0;
4610 uint16_t add_i_strmcnt = 0;
4612 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4613 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4615 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4619 if (stcb->asoc.reconfig_supported == 0) {
4621 * Peer does not support the chunk type.
4623 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4625 SCTP_TCB_UNLOCK(stcb);
4628 if (stcb->asoc.stream_reset_outstanding) {
4629 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4631 SCTP_TCB_UNLOCK(stcb);
4634 if ((stradd->sas_outstrms == 0) &&
4635 (stradd->sas_instrms == 0)) {
4639 if (stradd->sas_outstrms) {
4641 /* We allocate here */
4642 add_o_strmcnt = stradd->sas_outstrms;
4643 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4644 /* You can't have more than 64k */
4649 if (stradd->sas_instrms) {
4654 * We allocate inside
4655 * sctp_send_str_reset_req()
4657 add_i_strmcnt = stradd->sas_instrms;
4658 cnt = add_i_strmcnt;
4659 cnt += stcb->asoc.streamincnt;
4660 if (cnt > 0x0000ffff) {
4661 /* You can't have more than 64k */
4665 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4666 /* More than you are allowed */
4671 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4672 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4674 SCTP_TCB_UNLOCK(stcb);
4677 case SCTP_RESET_ASSOC:
4681 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4682 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4684 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4688 if (stcb->asoc.reconfig_supported == 0) {
4690 * Peer does not support the chunk type.
4692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4694 SCTP_TCB_UNLOCK(stcb);
4697 if (stcb->asoc.stream_reset_outstanding) {
4698 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4700 SCTP_TCB_UNLOCK(stcb);
4703 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 1, 0, 0, 0, 0);
4704 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4705 SCTP_TCB_UNLOCK(stcb);
4708 case SCTP_CONNECT_X:
4709 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4710 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4714 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4716 case SCTP_CONNECT_X_DELAYED:
4717 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4718 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4722 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4724 case SCTP_CONNECT_X_COMPLETE:
4726 struct sockaddr *sa;
4727 struct sctp_nets *net;
4729 /* FIXME MT: check correct? */
4730 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4733 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4734 SCTP_INP_RLOCK(inp);
4735 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4737 SCTP_TCB_LOCK(stcb);
4738 net = sctp_findnet(stcb, sa);
4740 SCTP_INP_RUNLOCK(inp);
4743 * We increment here since
4744 * sctp_findassociation_ep_addr() wil do a
4745 * decrement if it finds the stcb as long as
4746 * the locked tcb (last argument) is NOT a
4749 SCTP_INP_INCR_REF(inp);
4750 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
4752 SCTP_INP_DECR_REF(inp);
4757 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4761 if (stcb->asoc.delayed_connection == 1) {
4762 stcb->asoc.delayed_connection = 0;
4763 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4764 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4765 stcb->asoc.primary_destination,
4766 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
4767 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4770 * already expired or did not use delayed
4773 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4776 SCTP_TCB_UNLOCK(stcb);
4779 case SCTP_MAX_BURST:
4781 struct sctp_assoc_value *av;
4783 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4784 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4787 stcb->asoc.max_burst = av->assoc_value;
4788 SCTP_TCB_UNLOCK(stcb);
4790 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4791 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4792 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4793 (av->assoc_id == SCTP_ALL_ASSOC)) {
4794 SCTP_INP_WLOCK(inp);
4795 inp->sctp_ep.max_burst = av->assoc_value;
4796 SCTP_INP_WUNLOCK(inp);
4798 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4799 (av->assoc_id == SCTP_ALL_ASSOC)) {
4800 SCTP_INP_RLOCK(inp);
4801 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4802 SCTP_TCB_LOCK(stcb);
4803 stcb->asoc.max_burst = av->assoc_value;
4804 SCTP_TCB_UNLOCK(stcb);
4806 SCTP_INP_RUNLOCK(inp);
4813 struct sctp_assoc_value *av;
4816 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4817 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4819 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4820 ovh = SCTP_MED_OVERHEAD;
4822 ovh = SCTP_MED_V4_OVERHEAD;
4825 if (av->assoc_value) {
4826 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4828 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4830 SCTP_TCB_UNLOCK(stcb);
4832 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4833 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4834 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4835 SCTP_INP_WLOCK(inp);
4837 * FIXME MT: I think this is not in
4838 * tune with the API ID
4840 if (av->assoc_value) {
4841 inp->sctp_frag_point = (av->assoc_value + ovh);
4843 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4845 SCTP_INP_WUNLOCK(inp);
4847 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4855 struct sctp_event_subscribe *events;
4857 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4859 SCTP_INP_WLOCK(inp);
4860 if (events->sctp_data_io_event) {
4861 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4863 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4866 if (events->sctp_association_event) {
4867 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4869 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4872 if (events->sctp_address_event) {
4873 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4875 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4878 if (events->sctp_send_failure_event) {
4879 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4881 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4884 if (events->sctp_peer_error_event) {
4885 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4887 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4890 if (events->sctp_shutdown_event) {
4891 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4893 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4896 if (events->sctp_partial_delivery_event) {
4897 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4899 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4902 if (events->sctp_adaptation_layer_event) {
4903 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4905 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4908 if (events->sctp_authentication_event) {
4909 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4911 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4914 if (events->sctp_sender_dry_event) {
4915 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
4917 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
4920 if (events->sctp_stream_reset_event) {
4921 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4923 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4925 SCTP_INP_WUNLOCK(inp);
4927 SCTP_INP_RLOCK(inp);
4928 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4929 SCTP_TCB_LOCK(stcb);
4930 if (events->sctp_association_event) {
4931 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4933 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4935 if (events->sctp_address_event) {
4936 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4938 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4940 if (events->sctp_send_failure_event) {
4941 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4943 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4945 if (events->sctp_peer_error_event) {
4946 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4948 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4950 if (events->sctp_shutdown_event) {
4951 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4953 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4955 if (events->sctp_partial_delivery_event) {
4956 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4958 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4960 if (events->sctp_adaptation_layer_event) {
4961 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4963 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4965 if (events->sctp_authentication_event) {
4966 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4968 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4970 if (events->sctp_sender_dry_event) {
4971 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4973 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4975 if (events->sctp_stream_reset_event) {
4976 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4978 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4980 SCTP_TCB_UNLOCK(stcb);
4983 * Send up the sender dry event only for 1-to-1
4986 if (events->sctp_sender_dry_event) {
4987 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4988 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
4989 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4991 SCTP_TCB_LOCK(stcb);
4992 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
4993 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
4994 (stcb->asoc.stream_queue_cnt == 0)) {
4995 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
4997 SCTP_TCB_UNLOCK(stcb);
5001 SCTP_INP_RUNLOCK(inp);
5004 case SCTP_ADAPTATION_LAYER:
5006 struct sctp_setadaptation *adap_bits;
5008 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5009 SCTP_INP_WLOCK(inp);
5010 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5011 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5012 SCTP_INP_WUNLOCK(inp);
5016 case SCTP_SET_INITIAL_DBG_SEQ:
5020 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5021 SCTP_INP_WLOCK(inp);
5022 inp->sctp_ep.initial_sequence_debug = *vvv;
5023 SCTP_INP_WUNLOCK(inp);
5027 case SCTP_DEFAULT_SEND_PARAM:
5029 struct sctp_sndrcvinfo *s_info;
5031 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5032 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5035 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5036 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5038 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5041 SCTP_TCB_UNLOCK(stcb);
5043 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5044 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5045 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5046 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5047 SCTP_INP_WLOCK(inp);
5048 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5049 SCTP_INP_WUNLOCK(inp);
5051 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5052 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5053 SCTP_INP_RLOCK(inp);
5054 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5055 SCTP_TCB_LOCK(stcb);
5056 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5057 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5059 SCTP_TCB_UNLOCK(stcb);
5061 SCTP_INP_RUNLOCK(inp);
5066 case SCTP_PEER_ADDR_PARAMS:
5068 struct sctp_paddrparams *paddrp;
5069 struct sctp_nets *net;
5070 struct sockaddr *addr;
5072 #if defined(INET) && defined(INET6)
5073 struct sockaddr_in sin_store;
5077 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5078 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5080 #if defined(INET) && defined(INET6)
5081 if (paddrp->spp_address.ss_family == AF_INET6) {
5082 struct sockaddr_in6 *sin6;
5084 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5085 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5086 in6_sin6_2_sin(&sin_store, sin6);
5087 addr = (struct sockaddr *)&sin_store;
5089 addr = (struct sockaddr *)&paddrp->spp_address;
5092 addr = (struct sockaddr *)&paddrp->spp_address;
5095 addr = (struct sockaddr *)&paddrp->spp_address;
5098 net = sctp_findnet(stcb, addr);
5101 * We increment here since
5102 * sctp_findassociation_ep_addr() wil do a
5103 * decrement if it finds the stcb as long as
5104 * the locked tcb (last argument) is NOT a
5108 SCTP_INP_INCR_REF(inp);
5109 stcb = sctp_findassociation_ep_addr(&inp, addr,
5112 SCTP_INP_DECR_REF(inp);
5115 if ((stcb != NULL) && (net == NULL)) {
5117 if (addr->sa_family == AF_INET) {
5119 struct sockaddr_in *sin;
5121 sin = (struct sockaddr_in *)addr;
5122 if (sin->sin_addr.s_addr != INADDR_ANY) {
5123 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5124 SCTP_TCB_UNLOCK(stcb);
5131 if (addr->sa_family == AF_INET6) {
5132 struct sockaddr_in6 *sin6;
5134 sin6 = (struct sockaddr_in6 *)addr;
5135 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5136 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5137 SCTP_TCB_UNLOCK(stcb);
5144 error = EAFNOSUPPORT;
5145 SCTP_TCB_UNLOCK(stcb);
5146 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5151 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5153 SCTP_TCB_UNLOCK(stcb);
5154 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5157 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5159 SCTP_TCB_UNLOCK(stcb);
5160 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5164 /************************TCB SPECIFIC SET ******************/
5166 * do we change the timer for HB, we run
5171 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5172 ovh = SCTP_MED_OVERHEAD;
5174 ovh = SCTP_MED_V4_OVERHEAD;
5177 /* network sets ? */
5179 /************************NET SPECIFIC SET ******************/
5180 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5181 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5182 !(net->dest_state & SCTP_ADDR_NOHB)) {
5183 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5184 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5186 net->dest_state |= SCTP_ADDR_NOHB;
5188 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5189 if (paddrp->spp_hbinterval) {
5190 net->heart_beat_delay = paddrp->spp_hbinterval;
5191 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5192 net->heart_beat_delay = 0;
5194 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5195 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5196 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5197 net->dest_state &= ~SCTP_ADDR_NOHB;
5199 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5201 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5202 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5203 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5205 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5206 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5207 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5208 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5210 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5211 net->mtu = paddrp->spp_pathmtu + ovh;
5212 if (net->mtu < stcb->asoc.smallest_mtu) {
5213 sctp_pathmtu_adjustment(stcb, net->mtu);
5216 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5217 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5218 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5220 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5222 if (paddrp->spp_pathmaxrxt) {
5223 if (net->dest_state & SCTP_ADDR_PF) {
5224 if (net->error_count > paddrp->spp_pathmaxrxt) {
5225 net->dest_state &= ~SCTP_ADDR_PF;
5228 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5229 (net->error_count > net->pf_threshold)) {
5230 net->dest_state |= SCTP_ADDR_PF;
5231 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5232 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5233 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5236 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5237 if (net->error_count > paddrp->spp_pathmaxrxt) {
5238 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5239 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5242 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5243 net->dest_state |= SCTP_ADDR_REACHABLE;
5244 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5247 net->failure_threshold = paddrp->spp_pathmaxrxt;
5249 if (paddrp->spp_flags & SPP_DSCP) {
5250 net->dscp = paddrp->spp_dscp & 0xfc;
5254 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5255 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5256 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5257 net->flowlabel |= 0x80000000;
5262 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5263 if (paddrp->spp_pathmaxrxt != 0) {
5264 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5265 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5266 if (net->dest_state & SCTP_ADDR_PF) {
5267 if (net->error_count > paddrp->spp_pathmaxrxt) {
5268 net->dest_state &= ~SCTP_ADDR_PF;
5271 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5272 (net->error_count > net->pf_threshold)) {
5273 net->dest_state |= SCTP_ADDR_PF;
5274 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5275 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5276 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5279 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5280 if (net->error_count > paddrp->spp_pathmaxrxt) {
5281 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5282 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5285 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5286 net->dest_state |= SCTP_ADDR_REACHABLE;
5287 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5290 net->failure_threshold = paddrp->spp_pathmaxrxt;
5293 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5294 if (paddrp->spp_hbinterval != 0) {
5295 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5296 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5297 stcb->asoc.heart_beat_delay = 0;
5299 /* Turn back on the timer */
5300 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5301 if (paddrp->spp_hbinterval != 0) {
5302 net->heart_beat_delay = paddrp->spp_hbinterval;
5303 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5304 net->heart_beat_delay = 0;
5306 if (net->dest_state & SCTP_ADDR_NOHB) {
5307 net->dest_state &= ~SCTP_ADDR_NOHB;
5309 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5310 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5311 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5313 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5315 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5316 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5317 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5318 net->dest_state |= SCTP_ADDR_NOHB;
5319 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5320 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5324 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5326 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5327 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5328 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5329 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5330 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5332 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5333 net->mtu = paddrp->spp_pathmtu + ovh;
5334 if (net->mtu < stcb->asoc.smallest_mtu) {
5335 sctp_pathmtu_adjustment(stcb, net->mtu);
5338 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5340 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5341 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5342 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5343 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5345 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5347 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5349 if (paddrp->spp_flags & SPP_DSCP) {
5350 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5351 net->dscp = paddrp->spp_dscp & 0xfc;
5354 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5355 stcb->asoc.default_dscp |= 0x01;
5358 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5359 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5360 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5361 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5362 net->flowlabel |= 0x80000000;
5365 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5366 stcb->asoc.default_flowlabel |= 0x80000000;
5370 SCTP_TCB_UNLOCK(stcb);
5372 /************************NO TCB, SET TO default stuff ******************/
5373 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5374 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5375 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5376 SCTP_INP_WLOCK(inp);
5378 * For the TOS/FLOWLABEL stuff you
5379 * set it with the options on the
5382 if (paddrp->spp_pathmaxrxt != 0) {
5383 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5385 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5386 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5387 else if (paddrp->spp_hbinterval != 0) {
5388 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5389 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5390 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5392 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5393 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5394 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5395 } else if (paddrp->spp_hbinterval) {
5396 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5398 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5399 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5400 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5402 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5403 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5404 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5405 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5407 if (paddrp->spp_flags & SPP_DSCP) {
5408 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5409 inp->sctp_ep.default_dscp |= 0x01;
5412 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5413 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5414 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5415 inp->sctp_ep.default_flowlabel |= 0x80000000;
5419 SCTP_INP_WUNLOCK(inp);
5421 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5429 struct sctp_rtoinfo *srto;
5430 uint32_t new_init, new_min, new_max;
5432 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5433 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5436 if (srto->srto_initial)
5437 new_init = srto->srto_initial;
5439 new_init = stcb->asoc.initial_rto;
5441 new_max = srto->srto_max;
5443 new_max = stcb->asoc.maxrto;
5445 new_min = srto->srto_min;
5447 new_min = stcb->asoc.minrto;
5448 if ((new_min <= new_init) && (new_init <= new_max)) {
5449 stcb->asoc.initial_rto = new_init;
5450 stcb->asoc.maxrto = new_max;
5451 stcb->asoc.minrto = new_min;
5453 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5456 SCTP_TCB_UNLOCK(stcb);
5458 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5459 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5460 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5461 SCTP_INP_WLOCK(inp);
5462 if (srto->srto_initial)
5463 new_init = srto->srto_initial;
5465 new_init = inp->sctp_ep.initial_rto;
5467 new_max = srto->srto_max;
5469 new_max = inp->sctp_ep.sctp_maxrto;
5471 new_min = srto->srto_min;
5473 new_min = inp->sctp_ep.sctp_minrto;
5474 if ((new_min <= new_init) && (new_init <= new_max)) {
5475 inp->sctp_ep.initial_rto = new_init;
5476 inp->sctp_ep.sctp_maxrto = new_max;
5477 inp->sctp_ep.sctp_minrto = new_min;
5479 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5482 SCTP_INP_WUNLOCK(inp);
5484 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5490 case SCTP_ASSOCINFO:
5492 struct sctp_assocparams *sasoc;
5494 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5495 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5496 if (sasoc->sasoc_cookie_life) {
5497 /* boundary check the cookie life */
5498 if (sasoc->sasoc_cookie_life < 1000)
5499 sasoc->sasoc_cookie_life = 1000;
5500 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5501 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5505 if (sasoc->sasoc_asocmaxrxt)
5506 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5507 if (sasoc->sasoc_cookie_life) {
5508 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5510 SCTP_TCB_UNLOCK(stcb);
5512 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5513 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5514 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5515 SCTP_INP_WLOCK(inp);
5516 if (sasoc->sasoc_asocmaxrxt)
5517 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5518 if (sasoc->sasoc_cookie_life) {
5519 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5521 SCTP_INP_WUNLOCK(inp);
5523 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5531 struct sctp_initmsg *sinit;
5533 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5534 SCTP_INP_WLOCK(inp);
5535 if (sinit->sinit_num_ostreams)
5536 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5538 if (sinit->sinit_max_instreams)
5539 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5541 if (sinit->sinit_max_attempts)
5542 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5544 if (sinit->sinit_max_init_timeo)
5545 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5546 SCTP_INP_WUNLOCK(inp);
5549 case SCTP_PRIMARY_ADDR:
5551 struct sctp_setprim *spa;
5552 struct sctp_nets *net;
5553 struct sockaddr *addr;
5555 #if defined(INET) && defined(INET6)
5556 struct sockaddr_in sin_store;
5560 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5561 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5563 #if defined(INET) && defined(INET6)
5564 if (spa->ssp_addr.ss_family == AF_INET6) {
5565 struct sockaddr_in6 *sin6;
5567 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5568 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5569 in6_sin6_2_sin(&sin_store, sin6);
5570 addr = (struct sockaddr *)&sin_store;
5572 addr = (struct sockaddr *)&spa->ssp_addr;
5575 addr = (struct sockaddr *)&spa->ssp_addr;
5578 addr = (struct sockaddr *)&spa->ssp_addr;
5581 net = sctp_findnet(stcb, addr);
5584 * We increment here since
5585 * sctp_findassociation_ep_addr() wil do a
5586 * decrement if it finds the stcb as long as
5587 * the locked tcb (last argument) is NOT a
5591 SCTP_INP_INCR_REF(inp);
5592 stcb = sctp_findassociation_ep_addr(&inp, addr,
5595 SCTP_INP_DECR_REF(inp);
5599 if ((stcb != NULL) && (net != NULL)) {
5600 if ((net != stcb->asoc.primary_destination) &&
5601 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
5602 /* Ok we need to set it */
5603 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5604 if ((stcb->asoc.alternate) &&
5605 (!(net->dest_state & SCTP_ADDR_PF)) &&
5606 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5607 sctp_free_remote_addr(stcb->asoc.alternate);
5608 stcb->asoc.alternate = NULL;
5613 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5617 SCTP_TCB_UNLOCK(stcb);
5621 case SCTP_SET_DYNAMIC_PRIMARY:
5623 union sctp_sockstore *ss;
5625 error = priv_check(curthread,
5626 PRIV_NETINET_RESERVEDPORT);
5630 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5631 /* SUPER USER CHECK? */
5632 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5635 case SCTP_SET_PEER_PRIMARY_ADDR:
5637 struct sctp_setpeerprim *sspp;
5638 struct sockaddr *addr;
5640 #if defined(INET) && defined(INET6)
5641 struct sockaddr_in sin_store;
5645 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5646 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5648 struct sctp_ifa *ifa;
5650 #if defined(INET) && defined(INET6)
5651 if (sspp->sspp_addr.ss_family == AF_INET6) {
5652 struct sockaddr_in6 *sin6;
5654 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5655 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5656 in6_sin6_2_sin(&sin_store, sin6);
5657 addr = (struct sockaddr *)&sin_store;
5659 addr = (struct sockaddr *)&sspp->sspp_addr;
5662 addr = (struct sockaddr *)&sspp->sspp_addr;
5665 addr = (struct sockaddr *)&sspp->sspp_addr;
5667 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5669 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5673 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5675 * Must validate the ifa found is in
5678 struct sctp_laddr *laddr;
5681 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5682 if (laddr->ifa == NULL) {
5683 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5687 if (laddr->ifa == ifa) {
5693 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5698 switch (addr->sa_family) {
5702 struct sockaddr_in *sin;
5704 sin = (struct sockaddr_in *)addr;
5705 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5706 &sin->sin_addr) != 0) {
5707 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5717 struct sockaddr_in6 *sin6;
5719 sin6 = (struct sockaddr_in6 *)addr;
5720 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5721 &sin6->sin6_addr) != 0) {
5722 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5730 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5735 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5736 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5740 SCTP_TCB_UNLOCK(stcb);
5742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5747 case SCTP_BINDX_ADD_ADDR:
5749 struct sctp_getaddresses *addrs;
5752 td = (struct thread *)p;
5753 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5756 if (addrs->addr->sa_family == AF_INET) {
5757 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5758 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5762 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5763 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5769 if (addrs->addr->sa_family == AF_INET6) {
5770 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5771 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5775 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5776 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5777 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5783 error = EAFNOSUPPORT;
5786 sctp_bindx_add_address(so, inp, addrs->addr,
5787 addrs->sget_assoc_id, vrf_id,
5791 case SCTP_BINDX_REM_ADDR:
5793 struct sctp_getaddresses *addrs;
5796 td = (struct thread *)p;
5798 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5800 if (addrs->addr->sa_family == AF_INET) {
5801 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5802 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5806 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5807 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5813 if (addrs->addr->sa_family == AF_INET6) {
5814 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5815 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5820 (error = prison_local_ip6(td->td_ucred,
5821 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5822 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5823 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5829 error = EAFNOSUPPORT;
5832 sctp_bindx_delete_address(inp, addrs->addr,
5833 addrs->sget_assoc_id, vrf_id,
5839 struct sctp_event *event;
5840 uint32_t event_type;
5842 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5843 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5844 switch (event->se_type) {
5845 case SCTP_ASSOC_CHANGE:
5846 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5848 case SCTP_PEER_ADDR_CHANGE:
5849 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5851 case SCTP_REMOTE_ERROR:
5852 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5854 case SCTP_SEND_FAILED:
5855 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5857 case SCTP_SHUTDOWN_EVENT:
5858 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5860 case SCTP_ADAPTATION_INDICATION:
5861 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5863 case SCTP_PARTIAL_DELIVERY_EVENT:
5864 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5866 case SCTP_AUTHENTICATION_EVENT:
5867 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5869 case SCTP_STREAM_RESET_EVENT:
5870 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5872 case SCTP_SENDER_DRY_EVENT:
5873 event_type = SCTP_PCB_FLAGS_DRYEVNT;
5875 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
5877 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5880 case SCTP_ASSOC_RESET_EVENT:
5881 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
5883 case SCTP_STREAM_CHANGE_EVENT:
5884 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
5886 case SCTP_SEND_FAILED_EVENT:
5887 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
5891 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5895 if (event_type > 0) {
5898 sctp_stcb_feature_on(inp, stcb, event_type);
5899 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
5900 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5901 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5902 (stcb->asoc.stream_queue_cnt == 0)) {
5903 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5907 sctp_stcb_feature_off(inp, stcb, event_type);
5909 SCTP_TCB_UNLOCK(stcb);
5912 * We don't want to send up a storm
5913 * of events, so return an error for
5916 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
5917 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
5918 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
5919 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
5920 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
5921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5925 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5926 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5927 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
5928 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5929 SCTP_INP_WLOCK(inp);
5931 sctp_feature_on(inp, event_type);
5933 sctp_feature_off(inp, event_type);
5935 SCTP_INP_WUNLOCK(inp);
5937 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
5938 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5939 SCTP_INP_RLOCK(inp);
5940 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5941 SCTP_TCB_LOCK(stcb);
5943 sctp_stcb_feature_on(inp, stcb, event_type);
5945 sctp_stcb_feature_off(inp, stcb, event_type);
5947 SCTP_TCB_UNLOCK(stcb);
5949 SCTP_INP_RUNLOCK(inp);
5955 case SCTP_RECVRCVINFO:
5959 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5960 SCTP_INP_WLOCK(inp);
5962 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5964 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5966 SCTP_INP_WUNLOCK(inp);
5969 case SCTP_RECVNXTINFO:
5973 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5974 SCTP_INP_WLOCK(inp);
5976 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5978 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5980 SCTP_INP_WUNLOCK(inp);
5983 case SCTP_DEFAULT_SNDINFO:
5985 struct sctp_sndinfo *info;
5988 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
5989 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
5992 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5993 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5994 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5995 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5996 stcb->asoc.def_send.sinfo_flags |= policy;
5997 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5998 stcb->asoc.def_send.sinfo_context = info->snd_context;
6000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6003 SCTP_TCB_UNLOCK(stcb);
6005 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6006 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6007 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6008 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6009 SCTP_INP_WLOCK(inp);
6010 inp->def_send.sinfo_stream = info->snd_sid;
6011 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6012 inp->def_send.sinfo_flags = info->snd_flags;
6013 inp->def_send.sinfo_flags |= policy;
6014 inp->def_send.sinfo_ppid = info->snd_ppid;
6015 inp->def_send.sinfo_context = info->snd_context;
6016 SCTP_INP_WUNLOCK(inp);
6018 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6019 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6020 SCTP_INP_RLOCK(inp);
6021 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6022 SCTP_TCB_LOCK(stcb);
6023 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6024 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6025 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6026 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6027 stcb->asoc.def_send.sinfo_flags |= policy;
6028 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6029 stcb->asoc.def_send.sinfo_context = info->snd_context;
6031 SCTP_TCB_UNLOCK(stcb);
6033 SCTP_INP_RUNLOCK(inp);
6038 case SCTP_DEFAULT_PRINFO:
6040 struct sctp_default_prinfo *info;
6042 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6043 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6045 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6046 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6051 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6052 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6053 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6054 SCTP_TCB_UNLOCK(stcb);
6056 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6057 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6058 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6059 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6060 SCTP_INP_WLOCK(inp);
6061 inp->def_send.sinfo_flags &= 0xfff0;
6062 inp->def_send.sinfo_flags |= info->pr_policy;
6063 inp->def_send.sinfo_timetolive = info->pr_value;
6064 SCTP_INP_WUNLOCK(inp);
6066 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6067 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6068 SCTP_INP_RLOCK(inp);
6069 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6070 SCTP_TCB_LOCK(stcb);
6071 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6072 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6073 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6074 SCTP_TCB_UNLOCK(stcb);
6076 SCTP_INP_RUNLOCK(inp);
6081 case SCTP_PEER_ADDR_THLDS:
6082 /* Applies to the specific association */
6084 struct sctp_paddrthlds *thlds;
6085 struct sctp_nets *net;
6086 struct sockaddr *addr;
6088 #if defined(INET) && defined(INET6)
6089 struct sockaddr_in sin_store;
6093 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6094 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6096 #if defined(INET) && defined(INET6)
6097 if (thlds->spt_address.ss_family == AF_INET6) {
6098 struct sockaddr_in6 *sin6;
6100 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6101 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6102 in6_sin6_2_sin(&sin_store, sin6);
6103 addr = (struct sockaddr *)&sin_store;
6105 addr = (struct sockaddr *)&thlds->spt_address;
6108 addr = (struct sockaddr *)&thlds->spt_address;
6111 addr = (struct sockaddr *)&thlds->spt_address;
6114 net = sctp_findnet(stcb, addr);
6117 * We increment here since
6118 * sctp_findassociation_ep_addr() wil do a
6119 * decrement if it finds the stcb as long as
6120 * the locked tcb (last argument) is NOT a
6124 SCTP_INP_INCR_REF(inp);
6125 stcb = sctp_findassociation_ep_addr(&inp, addr,
6128 SCTP_INP_DECR_REF(inp);
6131 if ((stcb != NULL) && (net == NULL)) {
6133 if (addr->sa_family == AF_INET) {
6135 struct sockaddr_in *sin;
6137 sin = (struct sockaddr_in *)addr;
6138 if (sin->sin_addr.s_addr != INADDR_ANY) {
6139 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6140 SCTP_TCB_UNLOCK(stcb);
6147 if (addr->sa_family == AF_INET6) {
6148 struct sockaddr_in6 *sin6;
6150 sin6 = (struct sockaddr_in6 *)addr;
6151 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6152 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6153 SCTP_TCB_UNLOCK(stcb);
6160 error = EAFNOSUPPORT;
6161 SCTP_TCB_UNLOCK(stcb);
6162 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6168 if (net->dest_state & SCTP_ADDR_PF) {
6169 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
6170 (net->failure_threshold <= thlds->spt_pathpfthld)) {
6171 net->dest_state &= ~SCTP_ADDR_PF;
6174 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
6175 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
6176 net->dest_state |= SCTP_ADDR_PF;
6177 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6178 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
6179 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6182 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6183 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
6184 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6185 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6188 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
6189 net->dest_state |= SCTP_ADDR_REACHABLE;
6190 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6193 net->failure_threshold = thlds->spt_pathmaxrxt;
6194 net->pf_threshold = thlds->spt_pathpfthld;
6196 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6197 if (net->dest_state & SCTP_ADDR_PF) {
6198 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
6199 (net->failure_threshold <= thlds->spt_pathpfthld)) {
6200 net->dest_state &= ~SCTP_ADDR_PF;
6203 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
6204 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
6205 net->dest_state |= SCTP_ADDR_PF;
6206 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6207 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
6208 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6211 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6212 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
6213 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6214 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6217 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
6218 net->dest_state |= SCTP_ADDR_REACHABLE;
6219 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6222 net->failure_threshold = thlds->spt_pathmaxrxt;
6223 net->pf_threshold = thlds->spt_pathpfthld;
6225 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6226 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6229 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6230 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6231 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6232 SCTP_INP_WLOCK(inp);
6233 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6234 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6235 SCTP_INP_WUNLOCK(inp);
6237 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6243 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6245 struct sctp_udpencaps *encaps;
6246 struct sctp_nets *net;
6247 struct sockaddr *addr;
6249 #if defined(INET) && defined(INET6)
6250 struct sockaddr_in sin_store;
6254 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6255 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6257 #if defined(INET) && defined(INET6)
6258 if (encaps->sue_address.ss_family == AF_INET6) {
6259 struct sockaddr_in6 *sin6;
6261 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6262 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6263 in6_sin6_2_sin(&sin_store, sin6);
6264 addr = (struct sockaddr *)&sin_store;
6266 addr = (struct sockaddr *)&encaps->sue_address;
6269 addr = (struct sockaddr *)&encaps->sue_address;
6272 addr = (struct sockaddr *)&encaps->sue_address;
6275 net = sctp_findnet(stcb, addr);
6278 * We increment here since
6279 * sctp_findassociation_ep_addr() wil do a
6280 * decrement if it finds the stcb as long as
6281 * the locked tcb (last argument) is NOT a
6285 SCTP_INP_INCR_REF(inp);
6286 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
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);
6328 net->port = encaps->sue_port;
6330 stcb->asoc.port = encaps->sue_port;
6332 SCTP_TCB_UNLOCK(stcb);
6334 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6335 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6336 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6337 SCTP_INP_WLOCK(inp);
6338 inp->sctp_ep.port = encaps->sue_port;
6339 SCTP_INP_WUNLOCK(inp);
6341 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6347 case SCTP_ECN_SUPPORTED:
6349 struct sctp_assoc_value *av;
6351 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6352 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6355 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6357 SCTP_TCB_UNLOCK(stcb);
6359 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6360 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6361 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6362 SCTP_INP_WLOCK(inp);
6363 if (av->assoc_value == 0) {
6364 inp->ecn_supported = 0;
6366 inp->ecn_supported = 1;
6368 SCTP_INP_WUNLOCK(inp);
6370 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6376 case SCTP_PR_SUPPORTED:
6378 struct sctp_assoc_value *av;
6380 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6381 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6384 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6386 SCTP_TCB_UNLOCK(stcb);
6388 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6389 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6390 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6391 SCTP_INP_WLOCK(inp);
6392 if (av->assoc_value == 0) {
6393 inp->prsctp_supported = 0;
6395 inp->prsctp_supported = 1;
6397 SCTP_INP_WUNLOCK(inp);
6399 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6405 case SCTP_AUTH_SUPPORTED:
6407 struct sctp_assoc_value *av;
6409 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6410 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6413 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6415 SCTP_TCB_UNLOCK(stcb);
6417 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6418 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6419 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6420 if ((av->assoc_value == 0) &&
6421 (inp->asconf_supported == 1)) {
6423 * AUTH is required for
6426 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6429 SCTP_INP_WLOCK(inp);
6430 if (av->assoc_value == 0) {
6431 inp->auth_supported = 0;
6433 inp->auth_supported = 1;
6435 SCTP_INP_WUNLOCK(inp);
6438 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6444 case SCTP_ASCONF_SUPPORTED:
6446 struct sctp_assoc_value *av;
6448 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6449 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6452 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6454 SCTP_TCB_UNLOCK(stcb);
6456 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6457 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6458 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6459 if ((av->assoc_value != 0) &&
6460 (inp->auth_supported == 0)) {
6462 * AUTH is required for
6465 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6468 SCTP_INP_WLOCK(inp);
6469 if (av->assoc_value == 0) {
6470 inp->asconf_supported = 0;
6471 sctp_auth_delete_chunk(SCTP_ASCONF,
6472 inp->sctp_ep.local_auth_chunks);
6473 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6474 inp->sctp_ep.local_auth_chunks);
6476 inp->asconf_supported = 1;
6477 sctp_auth_add_chunk(SCTP_ASCONF,
6478 inp->sctp_ep.local_auth_chunks);
6479 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6480 inp->sctp_ep.local_auth_chunks);
6482 SCTP_INP_WUNLOCK(inp);
6485 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6491 case SCTP_RECONFIG_SUPPORTED:
6493 struct sctp_assoc_value *av;
6495 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6496 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6499 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6501 SCTP_TCB_UNLOCK(stcb);
6503 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6504 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6505 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6506 SCTP_INP_WLOCK(inp);
6507 if (av->assoc_value == 0) {
6508 inp->reconfig_supported = 0;
6510 inp->reconfig_supported = 1;
6512 SCTP_INP_WUNLOCK(inp);
6514 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6520 case SCTP_NRSACK_SUPPORTED:
6522 struct sctp_assoc_value *av;
6524 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6525 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6528 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6530 SCTP_TCB_UNLOCK(stcb);
6532 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6533 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6534 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6535 SCTP_INP_WLOCK(inp);
6536 if (av->assoc_value == 0) {
6537 inp->nrsack_supported = 0;
6539 inp->nrsack_supported = 1;
6541 SCTP_INP_WUNLOCK(inp);
6543 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6549 case SCTP_PKTDROP_SUPPORTED:
6551 struct sctp_assoc_value *av;
6553 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6554 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6557 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6559 SCTP_TCB_UNLOCK(stcb);
6561 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6562 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6563 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6564 SCTP_INP_WLOCK(inp);
6565 if (av->assoc_value == 0) {
6566 inp->pktdrop_supported = 0;
6568 inp->pktdrop_supported = 1;
6570 SCTP_INP_WUNLOCK(inp);
6572 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6579 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6580 error = ENOPROTOOPT;
6582 } /* end switch (opt) */
6587 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6589 void *optval = NULL;
6594 if (sopt->sopt_level != IPPROTO_SCTP) {
6595 /* wrong proto level... send back up to IP */
6597 if (INP_CHECK_SOCKAF(so, AF_INET6))
6598 error = ip6_ctloutput(so, sopt);
6600 #if defined(INET) && defined(INET6)
6604 error = ip_ctloutput(so, sopt);
6608 optsize = sopt->sopt_valsize;
6610 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6611 if (optval == NULL) {
6612 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6615 error = sooptcopyin(sopt, optval, optsize, optsize);
6617 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6621 p = (void *)sopt->sopt_td;
6622 if (sopt->sopt_dir == SOPT_SET) {
6623 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6624 } else if (sopt->sopt_dir == SOPT_GET) {
6625 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6627 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6630 if ((error == 0) && (optval != NULL)) {
6631 error = sooptcopyout(sopt, optval, optsize);
6632 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6633 } else if (optval != NULL) {
6634 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6642 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6645 int create_lock_on = 0;
6647 struct sctp_inpcb *inp;
6648 struct sctp_tcb *stcb = NULL;
6650 inp = (struct sctp_inpcb *)so->so_pcb;
6652 /* I made the same as TCP since we are not setup? */
6653 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6654 return (ECONNRESET);
6657 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6660 switch (addr->sa_family) {
6664 struct sockaddr_in6 *sin6p;
6666 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6667 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6670 sin6p = (struct sockaddr_in6 *)addr;
6671 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6672 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6681 struct sockaddr_in *sinp;
6683 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6684 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6687 sinp = (struct sockaddr_in *)addr;
6688 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6689 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6696 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6697 return (EAFNOSUPPORT);
6699 SCTP_INP_INCR_REF(inp);
6700 SCTP_ASOC_CREATE_LOCK(inp);
6704 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6705 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6706 /* Should I really unlock ? */
6707 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6712 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6713 (addr->sa_family == AF_INET6)) {
6714 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6719 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6720 SCTP_PCB_FLAGS_UNBOUND) {
6721 /* Bind a ephemeral port */
6722 error = sctp_inpcb_bind(so, NULL, NULL, p);
6727 /* Now do we connect? */
6728 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6729 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6730 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6734 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6735 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6736 /* We are already connected AND the TCP model */
6737 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6741 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6742 SCTP_INP_RLOCK(inp);
6743 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6744 SCTP_INP_RUNLOCK(inp);
6747 * We increment here since sctp_findassociation_ep_addr()
6748 * will do a decrement if it finds the stcb as long as the
6749 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6751 SCTP_INP_INCR_REF(inp);
6752 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6754 SCTP_INP_DECR_REF(inp);
6756 SCTP_TCB_UNLOCK(stcb);
6760 /* Already have or am bring up an association */
6761 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
6765 vrf_id = inp->def_vrf_id;
6766 /* We are GOOD to go */
6767 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
6769 /* Gak! no memory */
6772 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
6773 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
6774 /* Set the connected flag so we can queue data */
6777 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
6778 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
6780 /* initialize authentication parameters for the assoc */
6781 sctp_initialize_auth_params(inp, stcb);
6783 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
6784 SCTP_TCB_UNLOCK(stcb);
6786 if (create_lock_on) {
6787 SCTP_ASOC_CREATE_UNLOCK(inp);
6789 SCTP_INP_DECR_REF(inp);
6796 sctp_listen(struct socket *so, int backlog, struct thread *p)
6799 * Note this module depends on the protocol processing being called
6800 * AFTER any socket level flags and backlog are applied to the
6801 * socket. The traditional way that the socket flags are applied is
6802 * AFTER protocol processing. We have made a change to the
6803 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
6804 * place if the socket API for SCTP is to work properly.
6808 struct sctp_inpcb *inp;
6810 inp = (struct sctp_inpcb *)so->so_pcb;
6812 /* I made the same as TCP since we are not setup? */
6813 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6814 return (ECONNRESET);
6816 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
6817 /* See if we have a listener */
6818 struct sctp_inpcb *tinp;
6819 union sctp_sockstore store;
6821 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
6823 struct sctp_laddr *laddr;
6825 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6826 memcpy(&store, &laddr->ifa->address, sizeof(store));
6827 switch (store.sa.sa_family) {
6830 store.sin.sin_port = inp->sctp_lport;
6835 store.sin6.sin6_port = inp->sctp_lport;
6841 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
6842 if (tinp && (tinp != inp) &&
6843 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6844 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6845 (tinp->sctp_socket->so_qlimit)) {
6847 * we have a listener already and
6850 SCTP_INP_DECR_REF(tinp);
6851 return (EADDRINUSE);
6853 SCTP_INP_DECR_REF(tinp);
6857 /* Setup a local addr bound all */
6858 memset(&store, 0, sizeof(store));
6860 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
6861 store.sa.sa_family = AF_INET6;
6862 store.sa.sa_len = sizeof(struct sockaddr_in6);
6866 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
6867 store.sa.sa_family = AF_INET;
6868 store.sa.sa_len = sizeof(struct sockaddr_in);
6871 switch (store.sa.sa_family) {
6874 store.sin.sin_port = inp->sctp_lport;
6879 store.sin6.sin6_port = inp->sctp_lport;
6885 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
6886 if (tinp && (tinp != inp) &&
6887 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6888 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6889 (tinp->sctp_socket->so_qlimit)) {
6891 * we have a listener already and its not
6894 SCTP_INP_DECR_REF(tinp);
6895 return (EADDRINUSE);
6897 SCTP_INP_DECR_REF(inp);
6901 SCTP_INP_RLOCK(inp);
6902 #ifdef SCTP_LOCK_LOGGING
6903 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
6904 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
6908 error = solisten_proto_check(so);
6911 SCTP_INP_RUNLOCK(inp);
6914 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
6915 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
6917 * The unlucky case - We are in the tcp pool with this guy.
6918 * - Someone else is in the main inp slot. - We must move
6919 * this guy (the listener) to the main slot - We must then
6920 * move the guy that was listener to the TCP Pool.
6922 if (sctp_swap_inpcb_for_listen(inp)) {
6926 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6927 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6928 /* We are already connected AND the TCP model */
6930 SCTP_INP_RUNLOCK(inp);
6932 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6933 return (EADDRINUSE);
6935 SCTP_INP_RUNLOCK(inp);
6936 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
6937 /* We must do a bind. */
6939 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
6940 /* bind error, probably perm */
6945 /* It appears for 7.0 and on, we must always call this. */
6946 solisten_proto(so, backlog);
6947 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6948 /* remove the ACCEPTCONN flag for one-to-many sockets */
6949 so->so_options &= ~SO_ACCEPTCONN;
6952 /* turning off listen */
6953 so->so_options &= ~SO_ACCEPTCONN;
6959 static int sctp_defered_wakeup_cnt = 0;
6962 sctp_accept(struct socket *so, struct sockaddr **addr)
6964 struct sctp_tcb *stcb;
6965 struct sctp_inpcb *inp;
6966 union sctp_sockstore store;
6972 inp = (struct sctp_inpcb *)so->so_pcb;
6975 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6976 return (ECONNRESET);
6978 SCTP_INP_RLOCK(inp);
6979 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6980 SCTP_INP_RUNLOCK(inp);
6981 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
6982 return (EOPNOTSUPP);
6984 if (so->so_state & SS_ISDISCONNECTED) {
6985 SCTP_INP_RUNLOCK(inp);
6986 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
6987 return (ECONNABORTED);
6989 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6991 SCTP_INP_RUNLOCK(inp);
6992 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6993 return (ECONNRESET);
6995 SCTP_TCB_LOCK(stcb);
6996 SCTP_INP_RUNLOCK(inp);
6997 store = stcb->asoc.primary_destination->ro._l_addr;
6998 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
6999 SCTP_TCB_UNLOCK(stcb);
7000 switch (store.sa.sa_family) {
7004 struct sockaddr_in *sin;
7006 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7009 sin->sin_family = AF_INET;
7010 sin->sin_len = sizeof(*sin);
7011 sin->sin_port = store.sin.sin_port;
7012 sin->sin_addr = store.sin.sin_addr;
7013 *addr = (struct sockaddr *)sin;
7020 struct sockaddr_in6 *sin6;
7022 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7025 sin6->sin6_family = AF_INET6;
7026 sin6->sin6_len = sizeof(*sin6);
7027 sin6->sin6_port = store.sin6.sin6_port;
7028 sin6->sin6_addr = store.sin6.sin6_addr;
7029 if ((error = sa6_recoverscope(sin6)) != 0) {
7030 SCTP_FREE_SONAME(sin6);
7033 *addr = (struct sockaddr *)sin6;
7041 /* Wake any delayed sleep action */
7042 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7043 SCTP_INP_WLOCK(inp);
7044 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7045 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7046 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7047 SCTP_INP_WUNLOCK(inp);
7048 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7049 if (sowriteable(inp->sctp_socket)) {
7050 sowwakeup_locked(inp->sctp_socket);
7052 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7054 SCTP_INP_WLOCK(inp);
7056 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7057 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7058 SCTP_INP_WUNLOCK(inp);
7059 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7060 if (soreadable(inp->sctp_socket)) {
7061 sctp_defered_wakeup_cnt++;
7062 sorwakeup_locked(inp->sctp_socket);
7064 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7066 SCTP_INP_WLOCK(inp);
7068 SCTP_INP_WUNLOCK(inp);
7070 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7071 SCTP_TCB_LOCK(stcb);
7072 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
7079 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7081 struct sockaddr_in *sin;
7083 struct sctp_inpcb *inp;
7084 struct sctp_ifa *sctp_ifa;
7087 * Do the malloc first in case it blocks.
7089 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7092 sin->sin_family = AF_INET;
7093 sin->sin_len = sizeof(*sin);
7094 inp = (struct sctp_inpcb *)so->so_pcb;
7096 SCTP_FREE_SONAME(sin);
7097 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7098 return (ECONNRESET);
7100 SCTP_INP_RLOCK(inp);
7101 sin->sin_port = inp->sctp_lport;
7102 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7103 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7104 struct sctp_tcb *stcb;
7105 struct sockaddr_in *sin_a;
7106 struct sctp_nets *net;
7109 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7115 SCTP_TCB_LOCK(stcb);
7116 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7117 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7119 /* this will make coverity happy */
7122 if (sin_a->sin_family == AF_INET) {
7127 if ((!fnd) || (sin_a == NULL)) {
7129 SCTP_TCB_UNLOCK(stcb);
7132 vrf_id = inp->def_vrf_id;
7133 sctp_ifa = sctp_source_address_selection(inp,
7135 (sctp_route_t *) & net->ro,
7138 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7139 sctp_free_ifa(sctp_ifa);
7141 SCTP_TCB_UNLOCK(stcb);
7143 /* For the bound all case you get back 0 */
7145 sin->sin_addr.s_addr = 0;
7149 /* Take the first IPv4 address in the list */
7150 struct sctp_laddr *laddr;
7153 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7154 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7155 struct sockaddr_in *sin_a;
7157 sin_a = &laddr->ifa->address.sin;
7158 sin->sin_addr = sin_a->sin_addr;
7164 SCTP_FREE_SONAME(sin);
7165 SCTP_INP_RUNLOCK(inp);
7166 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7170 SCTP_INP_RUNLOCK(inp);
7171 (*addr) = (struct sockaddr *)sin;
7176 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7178 struct sockaddr_in *sin;
7180 struct sockaddr_in *sin_a;
7181 struct sctp_inpcb *inp;
7182 struct sctp_tcb *stcb;
7183 struct sctp_nets *net;
7185 /* Do the malloc first in case it blocks. */
7186 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7189 sin->sin_family = AF_INET;
7190 sin->sin_len = sizeof(*sin);
7192 inp = (struct sctp_inpcb *)so->so_pcb;
7193 if ((inp == NULL) ||
7194 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7195 /* UDP type and listeners will drop out here */
7196 SCTP_FREE_SONAME(sin);
7197 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7200 SCTP_INP_RLOCK(inp);
7201 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7203 SCTP_TCB_LOCK(stcb);
7205 SCTP_INP_RUNLOCK(inp);
7207 SCTP_FREE_SONAME(sin);
7208 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7209 return (ECONNRESET);
7212 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7213 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7214 if (sin_a->sin_family == AF_INET) {
7216 sin->sin_port = stcb->rport;
7217 sin->sin_addr = sin_a->sin_addr;
7221 SCTP_TCB_UNLOCK(stcb);
7223 /* No IPv4 address */
7224 SCTP_FREE_SONAME(sin);
7225 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7228 (*addr) = (struct sockaddr *)sin;
7232 struct pr_usrreqs sctp_usrreqs = {
7233 .pru_abort = sctp_abort,
7234 .pru_accept = sctp_accept,
7235 .pru_attach = sctp_attach,
7236 .pru_bind = sctp_bind,
7237 .pru_connect = sctp_connect,
7238 .pru_control = in_control,
7239 .pru_close = sctp_close,
7240 .pru_detach = sctp_close,
7241 .pru_sopoll = sopoll_generic,
7242 .pru_flush = sctp_flush,
7243 .pru_disconnect = sctp_disconnect,
7244 .pru_listen = sctp_listen,
7245 .pru_peeraddr = sctp_peeraddr,
7246 .pru_send = sctp_sendm,
7247 .pru_shutdown = sctp_shutdown,
7248 .pru_sockaddr = sctp_ingetaddr,
7249 .pru_sosend = sctp_sosend,
7250 .pru_soreceive = sctp_soreceive