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 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1867 &av->stream_value) < 0) {
1868 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1871 *optsize = sizeof(struct sctp_stream_value);
1873 SCTP_TCB_UNLOCK(stcb);
1876 * Can't get stream value without
1879 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1884 case SCTP_GET_ADDR_LEN:
1886 struct sctp_assoc_value *av;
1888 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1891 if (av->assoc_value == AF_INET) {
1892 av->assoc_value = sizeof(struct sockaddr_in);
1897 if (av->assoc_value == AF_INET6) {
1898 av->assoc_value = sizeof(struct sockaddr_in6);
1903 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1905 *optsize = sizeof(struct sctp_assoc_value);
1909 case SCTP_GET_ASSOC_NUMBER:
1911 uint32_t *value, cnt;
1913 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1915 SCTP_INP_RLOCK(inp);
1916 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1919 SCTP_INP_RUNLOCK(inp);
1921 *optsize = sizeof(uint32_t);
1924 case SCTP_GET_ASSOC_ID_LIST:
1926 struct sctp_assoc_ids *ids;
1927 unsigned int at, limit;
1929 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1931 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1932 SCTP_INP_RLOCK(inp);
1933 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1935 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1938 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1942 SCTP_INP_RUNLOCK(inp);
1944 ids->gaids_number_of_ids = at;
1945 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1951 struct sctp_assoc_value *av;
1953 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1954 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1957 av->assoc_value = stcb->asoc.context;
1958 SCTP_TCB_UNLOCK(stcb);
1960 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1961 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1962 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1963 SCTP_INP_RLOCK(inp);
1964 av->assoc_value = inp->sctp_context;
1965 SCTP_INP_RUNLOCK(inp);
1967 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1972 *optsize = sizeof(struct sctp_assoc_value);
1978 uint32_t *default_vrfid;
1980 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1981 *default_vrfid = inp->def_vrf_id;
1982 *optsize = sizeof(uint32_t);
1985 case SCTP_GET_ASOC_VRF:
1987 struct sctp_assoc_value *id;
1989 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1990 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1993 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1995 id->assoc_value = stcb->asoc.vrf_id;
1996 *optsize = sizeof(struct sctp_assoc_value);
2000 case SCTP_GET_VRF_IDS:
2002 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
2006 case SCTP_GET_NONCE_VALUES:
2008 struct sctp_get_nonce_values *gnv;
2010 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
2011 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
2014 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
2015 gnv->gn_local_tag = stcb->asoc.my_vtag;
2016 SCTP_TCB_UNLOCK(stcb);
2017 *optsize = sizeof(struct sctp_get_nonce_values);
2019 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2024 case SCTP_DELAYED_SACK:
2026 struct sctp_sack_info *sack;
2028 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2029 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2031 sack->sack_delay = stcb->asoc.delayed_ack;
2032 sack->sack_freq = stcb->asoc.sack_freq;
2033 SCTP_TCB_UNLOCK(stcb);
2035 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2036 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2037 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2038 SCTP_INP_RLOCK(inp);
2039 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2040 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2041 SCTP_INP_RUNLOCK(inp);
2043 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2048 *optsize = sizeof(struct sctp_sack_info);
2052 case SCTP_GET_SNDBUF_USE:
2054 struct sctp_sockstat *ss;
2056 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2057 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2060 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2061 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2062 stcb->asoc.size_on_all_streams);
2063 SCTP_TCB_UNLOCK(stcb);
2064 *optsize = sizeof(struct sctp_sockstat);
2066 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2071 case SCTP_MAX_BURST:
2073 struct sctp_assoc_value *av;
2075 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2076 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2079 av->assoc_value = stcb->asoc.max_burst;
2080 SCTP_TCB_UNLOCK(stcb);
2082 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2083 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2084 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2085 SCTP_INP_RLOCK(inp);
2086 av->assoc_value = inp->sctp_ep.max_burst;
2087 SCTP_INP_RUNLOCK(inp);
2089 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2094 *optsize = sizeof(struct sctp_assoc_value);
2100 struct sctp_assoc_value *av;
2103 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2104 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2107 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2108 SCTP_TCB_UNLOCK(stcb);
2110 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2111 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2112 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2113 SCTP_INP_RLOCK(inp);
2114 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2115 ovh = SCTP_MED_OVERHEAD;
2117 ovh = SCTP_MED_V4_OVERHEAD;
2119 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2120 av->assoc_value = 0;
2122 av->assoc_value = inp->sctp_frag_point - ovh;
2123 SCTP_INP_RUNLOCK(inp);
2125 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2130 *optsize = sizeof(struct sctp_assoc_value);
2134 case SCTP_GET_STAT_LOG:
2135 error = sctp_fill_stat_log(optval, optsize);
2139 struct sctp_event_subscribe *events;
2141 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2142 memset(events, 0, sizeof(struct sctp_event_subscribe));
2143 SCTP_INP_RLOCK(inp);
2144 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2145 events->sctp_data_io_event = 1;
2147 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2148 events->sctp_association_event = 1;
2150 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2151 events->sctp_address_event = 1;
2153 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2154 events->sctp_send_failure_event = 1;
2156 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2157 events->sctp_peer_error_event = 1;
2159 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2160 events->sctp_shutdown_event = 1;
2162 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2163 events->sctp_partial_delivery_event = 1;
2165 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2166 events->sctp_adaptation_layer_event = 1;
2168 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2169 events->sctp_authentication_event = 1;
2171 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2172 events->sctp_sender_dry_event = 1;
2174 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2175 events->sctp_stream_reset_event = 1;
2176 SCTP_INP_RUNLOCK(inp);
2177 *optsize = sizeof(struct sctp_event_subscribe);
2180 case SCTP_ADAPTATION_LAYER:
2184 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2186 SCTP_INP_RLOCK(inp);
2187 *value = inp->sctp_ep.adaptation_layer_indicator;
2188 SCTP_INP_RUNLOCK(inp);
2189 *optsize = sizeof(uint32_t);
2192 case SCTP_SET_INITIAL_DBG_SEQ:
2196 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2197 SCTP_INP_RLOCK(inp);
2198 *value = inp->sctp_ep.initial_sequence_debug;
2199 SCTP_INP_RUNLOCK(inp);
2200 *optsize = sizeof(uint32_t);
2203 case SCTP_GET_LOCAL_ADDR_SIZE:
2207 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2208 SCTP_INP_RLOCK(inp);
2209 *value = sctp_count_max_addresses(inp);
2210 SCTP_INP_RUNLOCK(inp);
2211 *optsize = sizeof(uint32_t);
2214 case SCTP_GET_REMOTE_ADDR_SIZE:
2218 struct sctp_nets *net;
2220 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2221 /* FIXME MT: change to sctp_assoc_value? */
2222 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2226 /* Count the sizes */
2227 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2228 switch (net->ro._l_addr.sa.sa_family) {
2232 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2233 size += sizeof(struct sockaddr_in6);
2235 size += sizeof(struct sockaddr_in);
2238 size += sizeof(struct sockaddr_in);
2244 size += sizeof(struct sockaddr_in6);
2251 SCTP_TCB_UNLOCK(stcb);
2252 *value = (uint32_t) size;
2253 *optsize = sizeof(uint32_t);
2255 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2260 case SCTP_GET_PEER_ADDRESSES:
2262 * Get the address information, an array is passed in to
2263 * fill up we pack it.
2267 struct sockaddr_storage *sas;
2268 struct sctp_nets *net;
2269 struct sctp_getaddresses *saddr;
2271 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2272 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2275 left = (*optsize) - sizeof(struct sctp_getaddresses);
2276 *optsize = sizeof(struct sctp_getaddresses);
2277 sas = (struct sockaddr_storage *)&saddr->addr[0];
2279 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2280 switch (net->ro._l_addr.sa.sa_family) {
2284 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2285 cpsz = sizeof(struct sockaddr_in6);
2287 cpsz = sizeof(struct sockaddr_in);
2290 cpsz = sizeof(struct sockaddr_in);
2296 cpsz = sizeof(struct sockaddr_in6);
2307 /* not enough room. */
2310 #if defined(INET) && defined(INET6)
2311 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2312 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2313 /* Must map the address */
2314 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2315 (struct sockaddr_in6 *)sas);
2317 memcpy(sas, &net->ro._l_addr, cpsz);
2320 memcpy(sas, &net->ro._l_addr, cpsz);
2322 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2324 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2328 SCTP_TCB_UNLOCK(stcb);
2330 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2335 case SCTP_GET_LOCAL_ADDRESSES:
2337 size_t limit, actual;
2338 struct sockaddr_storage *sas;
2339 struct sctp_getaddresses *saddr;
2341 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2342 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2344 sas = (struct sockaddr_storage *)&saddr->addr[0];
2345 limit = *optsize - sizeof(sctp_assoc_t);
2346 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2348 SCTP_TCB_UNLOCK(stcb);
2350 *optsize = sizeof(struct sockaddr_storage) + actual;
2353 case SCTP_PEER_ADDR_PARAMS:
2355 struct sctp_paddrparams *paddrp;
2356 struct sctp_nets *net;
2357 struct sockaddr *addr;
2359 #if defined(INET) && defined(INET6)
2360 struct sockaddr_in sin_store;
2364 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2365 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2367 #if defined(INET) && defined(INET6)
2368 if (paddrp->spp_address.ss_family == AF_INET6) {
2369 struct sockaddr_in6 *sin6;
2371 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2372 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2373 in6_sin6_2_sin(&sin_store, sin6);
2374 addr = (struct sockaddr *)&sin_store;
2376 addr = (struct sockaddr *)&paddrp->spp_address;
2379 addr = (struct sockaddr *)&paddrp->spp_address;
2382 addr = (struct sockaddr *)&paddrp->spp_address;
2385 net = sctp_findnet(stcb, addr);
2388 * We increment here since
2389 * sctp_findassociation_ep_addr() wil do a
2390 * decrement if it finds the stcb as long as
2391 * the locked tcb (last argument) is NOT a
2395 SCTP_INP_INCR_REF(inp);
2396 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2398 SCTP_INP_DECR_REF(inp);
2401 if ((stcb != NULL) && (net == NULL)) {
2403 if (addr->sa_family == AF_INET) {
2404 struct sockaddr_in *sin;
2406 sin = (struct sockaddr_in *)addr;
2407 if (sin->sin_addr.s_addr != INADDR_ANY) {
2409 SCTP_TCB_UNLOCK(stcb);
2410 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2416 if (addr->sa_family == AF_INET6) {
2417 struct sockaddr_in6 *sin6;
2419 sin6 = (struct sockaddr_in6 *)addr;
2420 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2422 SCTP_TCB_UNLOCK(stcb);
2423 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2429 error = EAFNOSUPPORT;
2430 SCTP_TCB_UNLOCK(stcb);
2431 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2436 /* Applies to the specific association */
2437 paddrp->spp_flags = 0;
2441 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2442 ovh = SCTP_MED_OVERHEAD;
2444 ovh = SCTP_MED_V4_OVERHEAD;
2447 paddrp->spp_hbinterval = net->heart_beat_delay;
2448 paddrp->spp_pathmaxrxt = net->failure_threshold;
2449 paddrp->spp_pathmtu = net->mtu - ovh;
2450 /* get flags for HB */
2451 if (net->dest_state & SCTP_ADDR_NOHB) {
2452 paddrp->spp_flags |= SPP_HB_DISABLE;
2454 paddrp->spp_flags |= SPP_HB_ENABLE;
2456 /* get flags for PMTU */
2457 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2458 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2460 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2462 if (net->dscp & 0x01) {
2463 paddrp->spp_dscp = net->dscp & 0xfc;
2464 paddrp->spp_flags |= SPP_DSCP;
2467 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2468 (net->flowlabel & 0x80000000)) {
2469 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2470 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2475 * No destination so return default
2478 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2479 paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
2480 if (stcb->asoc.default_dscp & 0x01) {
2481 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2482 paddrp->spp_flags |= SPP_DSCP;
2485 if (stcb->asoc.default_flowlabel & 0x80000000) {
2486 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2487 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2490 /* default settings should be these */
2491 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2492 paddrp->spp_flags |= SPP_HB_DISABLE;
2494 paddrp->spp_flags |= SPP_HB_ENABLE;
2496 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2497 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2499 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2501 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2503 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2504 SCTP_TCB_UNLOCK(stcb);
2506 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2507 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2508 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2509 /* Use endpoint defaults */
2510 SCTP_INP_RLOCK(inp);
2511 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2512 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2513 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2514 /* get inp's default */
2515 if (inp->sctp_ep.default_dscp & 0x01) {
2516 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2517 paddrp->spp_flags |= SPP_DSCP;
2520 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2521 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2522 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2523 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2526 /* can't return this */
2527 paddrp->spp_pathmtu = 0;
2529 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2530 paddrp->spp_flags |= SPP_HB_ENABLE;
2532 paddrp->spp_flags |= SPP_HB_DISABLE;
2534 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2535 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2537 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2539 SCTP_INP_RUNLOCK(inp);
2541 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2546 *optsize = sizeof(struct sctp_paddrparams);
2550 case SCTP_GET_PEER_ADDR_INFO:
2552 struct sctp_paddrinfo *paddri;
2553 struct sctp_nets *net;
2554 struct sockaddr *addr;
2556 #if defined(INET) && defined(INET6)
2557 struct sockaddr_in sin_store;
2561 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2562 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2564 #if defined(INET) && defined(INET6)
2565 if (paddri->spinfo_address.ss_family == AF_INET6) {
2566 struct sockaddr_in6 *sin6;
2568 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2569 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2570 in6_sin6_2_sin(&sin_store, sin6);
2571 addr = (struct sockaddr *)&sin_store;
2573 addr = (struct sockaddr *)&paddri->spinfo_address;
2576 addr = (struct sockaddr *)&paddri->spinfo_address;
2579 addr = (struct sockaddr *)&paddri->spinfo_address;
2582 net = sctp_findnet(stcb, addr);
2585 * We increment here since
2586 * sctp_findassociation_ep_addr() wil do a
2587 * decrement if it finds the stcb as long as
2588 * the locked tcb (last argument) is NOT a
2592 SCTP_INP_INCR_REF(inp);
2593 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2595 SCTP_INP_DECR_REF(inp);
2599 if ((stcb != NULL) && (net != NULL)) {
2600 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2601 /* It's unconfirmed */
2602 paddri->spinfo_state = SCTP_UNCONFIRMED;
2603 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2605 paddri->spinfo_state = SCTP_ACTIVE;
2608 paddri->spinfo_state = SCTP_INACTIVE;
2610 paddri->spinfo_cwnd = net->cwnd;
2611 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2612 paddri->spinfo_rto = net->RTO;
2613 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2614 paddri->spinfo_mtu = net->mtu;
2615 SCTP_TCB_UNLOCK(stcb);
2616 *optsize = sizeof(struct sctp_paddrinfo);
2619 SCTP_TCB_UNLOCK(stcb);
2621 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2626 case SCTP_PCB_STATUS:
2628 struct sctp_pcbinfo *spcb;
2630 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2631 sctp_fill_pcbinfo(spcb);
2632 *optsize = sizeof(struct sctp_pcbinfo);
2637 struct sctp_nets *net;
2638 struct sctp_status *sstat;
2640 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2641 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2644 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2649 * I think passing the state is fine since
2650 * sctp_constants.h will be available to the user
2653 sstat->sstat_state = stcb->asoc.state;
2654 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2655 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2656 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2658 * We can't include chunks that have been passed to
2659 * the socket layer. Only things in queue.
2661 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2662 stcb->asoc.cnt_on_all_streams);
2665 sstat->sstat_instrms = stcb->asoc.streamincnt;
2666 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2667 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2668 memcpy(&sstat->sstat_primary.spinfo_address,
2669 &stcb->asoc.primary_destination->ro._l_addr,
2670 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2671 net = stcb->asoc.primary_destination;
2672 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2674 * Again the user can get info from sctp_constants.h
2675 * for what the state of the network is.
2677 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2678 /* It's unconfirmed */
2679 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2680 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2682 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2685 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2687 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2688 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2689 sstat->sstat_primary.spinfo_rto = net->RTO;
2690 sstat->sstat_primary.spinfo_mtu = net->mtu;
2691 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2692 SCTP_TCB_UNLOCK(stcb);
2693 *optsize = sizeof(struct sctp_status);
2698 struct sctp_rtoinfo *srto;
2700 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2701 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2704 srto->srto_initial = stcb->asoc.initial_rto;
2705 srto->srto_max = stcb->asoc.maxrto;
2706 srto->srto_min = stcb->asoc.minrto;
2707 SCTP_TCB_UNLOCK(stcb);
2709 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2710 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2711 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2712 SCTP_INP_RLOCK(inp);
2713 srto->srto_initial = inp->sctp_ep.initial_rto;
2714 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2715 srto->srto_min = inp->sctp_ep.sctp_minrto;
2716 SCTP_INP_RUNLOCK(inp);
2718 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2723 *optsize = sizeof(struct sctp_rtoinfo);
2729 struct sctp_timeouts *stimo;
2731 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2732 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2735 stimo->stimo_init = stcb->asoc.timoinit;
2736 stimo->stimo_data = stcb->asoc.timodata;
2737 stimo->stimo_sack = stcb->asoc.timosack;
2738 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2739 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2740 stimo->stimo_cookie = stcb->asoc.timocookie;
2741 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2742 SCTP_TCB_UNLOCK(stcb);
2743 *optsize = sizeof(struct sctp_timeouts);
2745 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2750 case SCTP_ASSOCINFO:
2752 struct sctp_assocparams *sasoc;
2754 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2755 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2758 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2759 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2760 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2761 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2762 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2763 SCTP_TCB_UNLOCK(stcb);
2765 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2766 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2767 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2768 SCTP_INP_RLOCK(inp);
2769 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2770 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2771 sasoc->sasoc_number_peer_destinations = 0;
2772 sasoc->sasoc_peer_rwnd = 0;
2773 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2774 SCTP_INP_RUNLOCK(inp);
2776 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2781 *optsize = sizeof(struct sctp_assocparams);
2785 case SCTP_DEFAULT_SEND_PARAM:
2787 struct sctp_sndrcvinfo *s_info;
2789 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2790 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2793 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2794 SCTP_TCB_UNLOCK(stcb);
2796 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2797 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2798 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2799 SCTP_INP_RLOCK(inp);
2800 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2801 SCTP_INP_RUNLOCK(inp);
2803 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2808 *optsize = sizeof(struct sctp_sndrcvinfo);
2814 struct sctp_initmsg *sinit;
2816 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2817 SCTP_INP_RLOCK(inp);
2818 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2819 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2820 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2821 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2822 SCTP_INP_RUNLOCK(inp);
2823 *optsize = sizeof(struct sctp_initmsg);
2826 case SCTP_PRIMARY_ADDR:
2827 /* we allow a "get" operation on this */
2829 struct sctp_setprim *ssp;
2831 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2832 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2835 union sctp_sockstore *addr;
2837 addr = &stcb->asoc.primary_destination->ro._l_addr;
2838 switch (addr->sa.sa_family) {
2842 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2843 in6_sin_2_v4mapsin6(&addr->sin,
2844 (struct sockaddr_in6 *)&ssp->ssp_addr);
2846 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2849 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2855 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2861 SCTP_TCB_UNLOCK(stcb);
2862 *optsize = sizeof(struct sctp_setprim);
2864 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2869 case SCTP_HMAC_IDENT:
2871 struct sctp_hmacalgo *shmac;
2872 sctp_hmaclist_t *hmaclist;
2876 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2878 SCTP_INP_RLOCK(inp);
2879 hmaclist = inp->sctp_ep.local_hmacs;
2880 if (hmaclist == NULL) {
2881 /* no HMACs to return */
2882 *optsize = sizeof(*shmac);
2883 SCTP_INP_RUNLOCK(inp);
2886 /* is there room for all of the hmac ids? */
2887 size = sizeof(*shmac) + (hmaclist->num_algo *
2888 sizeof(shmac->shmac_idents[0]));
2889 if ((size_t)(*optsize) < size) {
2890 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2892 SCTP_INP_RUNLOCK(inp);
2895 /* copy in the list */
2896 shmac->shmac_number_of_idents = hmaclist->num_algo;
2897 for (i = 0; i < hmaclist->num_algo; i++) {
2898 shmac->shmac_idents[i] = hmaclist->hmac[i];
2900 SCTP_INP_RUNLOCK(inp);
2904 case SCTP_AUTH_ACTIVE_KEY:
2906 struct sctp_authkeyid *scact;
2908 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2909 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2912 /* get the active key on the assoc */
2913 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2914 SCTP_TCB_UNLOCK(stcb);
2916 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2917 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2918 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2919 /* get the endpoint active key */
2920 SCTP_INP_RLOCK(inp);
2921 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2922 SCTP_INP_RUNLOCK(inp);
2924 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2929 *optsize = sizeof(struct sctp_authkeyid);
2933 case SCTP_LOCAL_AUTH_CHUNKS:
2935 struct sctp_authchunks *sac;
2936 sctp_auth_chklist_t *chklist = NULL;
2939 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2940 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2943 /* get off the assoc */
2944 chklist = stcb->asoc.local_auth_chunks;
2945 /* is there enough space? */
2946 size = sctp_auth_get_chklist_size(chklist);
2947 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2949 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2951 /* copy in the chunks */
2952 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2953 sac->gauth_number_of_chunks = (uint32_t) size;
2954 *optsize = sizeof(struct sctp_authchunks) + size;
2956 SCTP_TCB_UNLOCK(stcb);
2958 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2959 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2960 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2961 /* get off the endpoint */
2962 SCTP_INP_RLOCK(inp);
2963 chklist = inp->sctp_ep.local_auth_chunks;
2964 /* is there enough space? */
2965 size = sctp_auth_get_chklist_size(chklist);
2966 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2968 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2970 /* copy in the chunks */
2971 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2972 sac->gauth_number_of_chunks = (uint32_t) size;
2973 *optsize = sizeof(struct sctp_authchunks) + size;
2975 SCTP_INP_RUNLOCK(inp);
2977 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2983 case SCTP_PEER_AUTH_CHUNKS:
2985 struct sctp_authchunks *sac;
2986 sctp_auth_chklist_t *chklist = NULL;
2989 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2990 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2993 /* get off the assoc */
2994 chklist = stcb->asoc.peer_auth_chunks;
2995 /* is there enough space? */
2996 size = sctp_auth_get_chklist_size(chklist);
2997 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2999 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3001 /* copy in the chunks */
3002 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
3003 sac->gauth_number_of_chunks = (uint32_t) size;
3004 *optsize = sizeof(struct sctp_authchunks) + size;
3006 SCTP_TCB_UNLOCK(stcb);
3008 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3015 struct sctp_event *event;
3016 uint32_t event_type;
3018 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3019 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3021 switch (event->se_type) {
3022 case SCTP_ASSOC_CHANGE:
3023 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3025 case SCTP_PEER_ADDR_CHANGE:
3026 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3028 case SCTP_REMOTE_ERROR:
3029 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3031 case SCTP_SEND_FAILED:
3032 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3034 case SCTP_SHUTDOWN_EVENT:
3035 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3037 case SCTP_ADAPTATION_INDICATION:
3038 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3040 case SCTP_PARTIAL_DELIVERY_EVENT:
3041 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3043 case SCTP_AUTHENTICATION_EVENT:
3044 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3046 case SCTP_STREAM_RESET_EVENT:
3047 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3049 case SCTP_SENDER_DRY_EVENT:
3050 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3052 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3054 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3057 case SCTP_ASSOC_RESET_EVENT:
3058 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3060 case SCTP_STREAM_CHANGE_EVENT:
3061 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3063 case SCTP_SEND_FAILED_EVENT:
3064 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3068 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3072 if (event_type > 0) {
3074 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3075 SCTP_TCB_UNLOCK(stcb);
3077 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3078 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3079 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3080 SCTP_INP_RLOCK(inp);
3081 event->se_on = sctp_is_feature_on(inp, event_type);
3082 SCTP_INP_RUNLOCK(inp);
3084 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3090 *optsize = sizeof(struct sctp_event);
3094 case SCTP_RECVRCVINFO:
3098 if (*optsize < sizeof(int)) {
3099 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3102 SCTP_INP_RLOCK(inp);
3103 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3104 SCTP_INP_RUNLOCK(inp);
3107 /* return the option value */
3108 *(int *)optval = onoff;
3109 *optsize = sizeof(int);
3113 case SCTP_RECVNXTINFO:
3117 if (*optsize < sizeof(int)) {
3118 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3121 SCTP_INP_RLOCK(inp);
3122 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3123 SCTP_INP_RUNLOCK(inp);
3126 /* return the option value */
3127 *(int *)optval = onoff;
3128 *optsize = sizeof(int);
3132 case SCTP_DEFAULT_SNDINFO:
3134 struct sctp_sndinfo *info;
3136 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3137 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3140 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3141 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3142 info->snd_flags &= 0xfff0;
3143 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3144 info->snd_context = stcb->asoc.def_send.sinfo_context;
3145 SCTP_TCB_UNLOCK(stcb);
3147 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3148 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3149 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3150 SCTP_INP_RLOCK(inp);
3151 info->snd_sid = inp->def_send.sinfo_stream;
3152 info->snd_flags = inp->def_send.sinfo_flags;
3153 info->snd_flags &= 0xfff0;
3154 info->snd_ppid = inp->def_send.sinfo_ppid;
3155 info->snd_context = inp->def_send.sinfo_context;
3156 SCTP_INP_RUNLOCK(inp);
3158 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3163 *optsize = sizeof(struct sctp_sndinfo);
3167 case SCTP_DEFAULT_PRINFO:
3169 struct sctp_default_prinfo *info;
3171 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3172 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3175 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3176 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3177 SCTP_TCB_UNLOCK(stcb);
3179 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3180 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3181 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3182 SCTP_INP_RLOCK(inp);
3183 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3184 info->pr_value = inp->def_send.sinfo_timetolive;
3185 SCTP_INP_RUNLOCK(inp);
3187 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3192 *optsize = sizeof(struct sctp_default_prinfo);
3196 case SCTP_PEER_ADDR_THLDS:
3198 struct sctp_paddrthlds *thlds;
3199 struct sctp_nets *net;
3200 struct sockaddr *addr;
3202 #if defined(INET) && defined(INET6)
3203 struct sockaddr_in sin_store;
3207 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3208 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3210 #if defined(INET) && defined(INET6)
3211 if (thlds->spt_address.ss_family == AF_INET6) {
3212 struct sockaddr_in6 *sin6;
3214 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3215 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3216 in6_sin6_2_sin(&sin_store, sin6);
3217 addr = (struct sockaddr *)&sin_store;
3219 addr = (struct sockaddr *)&thlds->spt_address;
3222 addr = (struct sockaddr *)&thlds->spt_address;
3225 addr = (struct sockaddr *)&thlds->spt_address;
3228 net = sctp_findnet(stcb, addr);
3231 * We increment here since
3232 * sctp_findassociation_ep_addr() wil do a
3233 * decrement if it finds the stcb as long as
3234 * the locked tcb (last argument) is NOT a
3238 SCTP_INP_INCR_REF(inp);
3239 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3241 SCTP_INP_DECR_REF(inp);
3244 if ((stcb != NULL) && (net == NULL)) {
3246 if (addr->sa_family == AF_INET) {
3247 struct sockaddr_in *sin;
3249 sin = (struct sockaddr_in *)addr;
3250 if (sin->sin_addr.s_addr != INADDR_ANY) {
3252 SCTP_TCB_UNLOCK(stcb);
3253 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3259 if (addr->sa_family == AF_INET6) {
3260 struct sockaddr_in6 *sin6;
3262 sin6 = (struct sockaddr_in6 *)addr;
3263 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3265 SCTP_TCB_UNLOCK(stcb);
3266 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3272 error = EAFNOSUPPORT;
3273 SCTP_TCB_UNLOCK(stcb);
3274 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3280 thlds->spt_pathmaxrxt = net->failure_threshold;
3281 thlds->spt_pathpfthld = net->pf_threshold;
3283 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3284 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3286 thlds->spt_assoc_id = sctp_get_associd(stcb);
3287 SCTP_TCB_UNLOCK(stcb);
3289 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3290 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3291 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3292 /* Use endpoint defaults */
3293 SCTP_INP_RLOCK(inp);
3294 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3295 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3296 SCTP_INP_RUNLOCK(inp);
3298 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3303 *optsize = sizeof(struct sctp_paddrthlds);
3307 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3309 struct sctp_udpencaps *encaps;
3310 struct sctp_nets *net;
3311 struct sockaddr *addr;
3313 #if defined(INET) && defined(INET6)
3314 struct sockaddr_in sin_store;
3318 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3319 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3321 #if defined(INET) && defined(INET6)
3322 if (encaps->sue_address.ss_family == AF_INET6) {
3323 struct sockaddr_in6 *sin6;
3325 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3326 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3327 in6_sin6_2_sin(&sin_store, sin6);
3328 addr = (struct sockaddr *)&sin_store;
3330 addr = (struct sockaddr *)&encaps->sue_address;
3333 addr = (struct sockaddr *)&encaps->sue_address;
3336 addr = (struct sockaddr *)&encaps->sue_address;
3339 net = sctp_findnet(stcb, addr);
3342 * We increment here since
3343 * sctp_findassociation_ep_addr() wil do a
3344 * decrement if it finds the stcb as long as
3345 * the locked tcb (last argument) is NOT a
3349 SCTP_INP_INCR_REF(inp);
3350 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3352 SCTP_INP_DECR_REF(inp);
3355 if ((stcb != NULL) && (net == NULL)) {
3357 if (addr->sa_family == AF_INET) {
3358 struct sockaddr_in *sin;
3360 sin = (struct sockaddr_in *)addr;
3361 if (sin->sin_addr.s_addr != INADDR_ANY) {
3363 SCTP_TCB_UNLOCK(stcb);
3364 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3370 if (addr->sa_family == AF_INET6) {
3371 struct sockaddr_in6 *sin6;
3373 sin6 = (struct sockaddr_in6 *)addr;
3374 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3376 SCTP_TCB_UNLOCK(stcb);
3377 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3383 error = EAFNOSUPPORT;
3384 SCTP_TCB_UNLOCK(stcb);
3385 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3391 encaps->sue_port = net->port;
3393 encaps->sue_port = stcb->asoc.port;
3395 SCTP_TCB_UNLOCK(stcb);
3397 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3398 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3399 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3400 SCTP_INP_RLOCK(inp);
3401 encaps->sue_port = inp->sctp_ep.port;
3402 SCTP_INP_RUNLOCK(inp);
3404 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3409 *optsize = sizeof(struct sctp_udpencaps);
3413 case SCTP_ECN_SUPPORTED:
3415 struct sctp_assoc_value *av;
3417 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3418 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3421 av->assoc_value = stcb->asoc.ecn_supported;
3422 SCTP_TCB_UNLOCK(stcb);
3424 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3425 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3426 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3427 SCTP_INP_RLOCK(inp);
3428 av->assoc_value = inp->ecn_supported;
3429 SCTP_INP_RUNLOCK(inp);
3431 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3436 *optsize = sizeof(struct sctp_assoc_value);
3440 case SCTP_PR_SUPPORTED:
3442 struct sctp_assoc_value *av;
3444 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3445 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3448 av->assoc_value = stcb->asoc.prsctp_supported;
3449 SCTP_TCB_UNLOCK(stcb);
3451 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3452 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3453 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3454 SCTP_INP_RLOCK(inp);
3455 av->assoc_value = inp->prsctp_supported;
3456 SCTP_INP_RUNLOCK(inp);
3458 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3463 *optsize = sizeof(struct sctp_assoc_value);
3467 case SCTP_AUTH_SUPPORTED:
3469 struct sctp_assoc_value *av;
3471 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3472 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3475 av->assoc_value = stcb->asoc.auth_supported;
3476 SCTP_TCB_UNLOCK(stcb);
3478 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3479 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3480 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3481 SCTP_INP_RLOCK(inp);
3482 av->assoc_value = inp->auth_supported;
3483 SCTP_INP_RUNLOCK(inp);
3485 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3490 *optsize = sizeof(struct sctp_assoc_value);
3494 case SCTP_ASCONF_SUPPORTED:
3496 struct sctp_assoc_value *av;
3498 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3499 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3502 av->assoc_value = stcb->asoc.asconf_supported;
3503 SCTP_TCB_UNLOCK(stcb);
3505 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3506 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3507 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3508 SCTP_INP_RLOCK(inp);
3509 av->assoc_value = inp->asconf_supported;
3510 SCTP_INP_RUNLOCK(inp);
3512 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3517 *optsize = sizeof(struct sctp_assoc_value);
3521 case SCTP_RECONFIG_SUPPORTED:
3523 struct sctp_assoc_value *av;
3525 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3526 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3529 av->assoc_value = stcb->asoc.reconfig_supported;
3530 SCTP_TCB_UNLOCK(stcb);
3532 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3533 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3534 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3535 SCTP_INP_RLOCK(inp);
3536 av->assoc_value = inp->reconfig_supported;
3537 SCTP_INP_RUNLOCK(inp);
3539 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3544 *optsize = sizeof(struct sctp_assoc_value);
3548 case SCTP_NRSACK_SUPPORTED:
3550 struct sctp_assoc_value *av;
3552 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3553 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3556 av->assoc_value = stcb->asoc.nrsack_supported;
3557 SCTP_TCB_UNLOCK(stcb);
3559 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3560 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3561 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3562 SCTP_INP_RLOCK(inp);
3563 av->assoc_value = inp->nrsack_supported;
3564 SCTP_INP_RUNLOCK(inp);
3566 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3571 *optsize = sizeof(struct sctp_assoc_value);
3575 case SCTP_PKTDROP_SUPPORTED:
3577 struct sctp_assoc_value *av;
3579 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3580 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3583 av->assoc_value = stcb->asoc.pktdrop_supported;
3584 SCTP_TCB_UNLOCK(stcb);
3586 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3587 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3588 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3589 SCTP_INP_RLOCK(inp);
3590 av->assoc_value = inp->pktdrop_supported;
3591 SCTP_INP_RUNLOCK(inp);
3593 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3598 *optsize = sizeof(struct sctp_assoc_value);
3602 case SCTP_ENABLE_STREAM_RESET:
3604 struct sctp_assoc_value *av;
3606 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3607 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3610 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3611 SCTP_TCB_UNLOCK(stcb);
3613 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3614 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3615 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3616 SCTP_INP_RLOCK(inp);
3617 av->assoc_value = (uint32_t) inp->local_strreset_support;
3618 SCTP_INP_RUNLOCK(inp);
3620 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3625 *optsize = sizeof(struct sctp_assoc_value);
3629 case SCTP_PR_STREAM_STATUS:
3631 struct sctp_prstatus *sprstat;
3635 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3636 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3638 sid = sprstat->sprstat_sid;
3639 policy = sprstat->sprstat_policy;
3640 #if defined(SCTP_DETAILED_STR_STATS)
3641 if ((stcb != NULL) &&
3642 (sid < stcb->asoc.streamoutcnt) &&
3643 (policy != SCTP_PR_SCTP_NONE) &&
3644 ((policy <= SCTP_PR_SCTP_MAX) ||
3645 (policy == SCTP_PR_SCTP_ALL))) {
3646 if (policy == SCTP_PR_SCTP_ALL) {
3647 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3648 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3650 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3651 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3654 if ((stcb != NULL) &&
3655 (sid < stcb->asoc.streamoutcnt) &&
3656 (policy == SCTP_PR_SCTP_ALL)) {
3657 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3658 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3660 SCTP_TCB_UNLOCK(stcb);
3661 *optsize = sizeof(struct sctp_prstatus);
3663 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3668 case SCTP_PR_ASSOC_STATUS:
3670 struct sctp_prstatus *sprstat;
3673 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3674 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3676 policy = sprstat->sprstat_policy;
3677 if ((stcb != NULL) &&
3678 (policy != SCTP_PR_SCTP_NONE) &&
3679 ((policy <= SCTP_PR_SCTP_MAX) ||
3680 (policy == SCTP_PR_SCTP_ALL))) {
3681 if (policy == SCTP_PR_SCTP_ALL) {
3682 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3683 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3685 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3686 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3688 SCTP_TCB_UNLOCK(stcb);
3689 *optsize = sizeof(struct sctp_prstatus);
3691 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3697 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3698 error = ENOPROTOOPT;
3700 } /* end switch (sopt->sopt_name) */
3708 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3713 struct sctp_tcb *stcb = NULL;
3714 struct sctp_inpcb *inp = NULL;
3717 if (optval == NULL) {
3718 SCTP_PRINTF("optval is NULL\n");
3719 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3722 inp = (struct sctp_inpcb *)so->so_pcb;
3724 SCTP_PRINTF("inp is NULL?\n");
3725 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3728 vrf_id = inp->def_vrf_id;
3733 case SCTP_AUTOCLOSE:
3734 case SCTP_AUTO_ASCONF:
3735 case SCTP_EXPLICIT_EOR:
3736 case SCTP_DISABLE_FRAGMENTS:
3737 case SCTP_USE_EXT_RCVINFO:
3738 case SCTP_I_WANT_MAPPED_V4_ADDR:
3739 /* copy in the option value */
3740 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3745 case SCTP_DISABLE_FRAGMENTS:
3746 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3748 case SCTP_AUTO_ASCONF:
3750 * NOTE: we don't really support this flag
3752 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3753 /* only valid for bound all sockets */
3754 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3756 /* forbidden by admin */
3757 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3760 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3762 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3766 case SCTP_EXPLICIT_EOR:
3767 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3769 case SCTP_USE_EXT_RCVINFO:
3770 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3772 case SCTP_I_WANT_MAPPED_V4_ADDR:
3773 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3774 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3776 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3781 set_opt = SCTP_PCB_FLAGS_NODELAY;
3783 case SCTP_AUTOCLOSE:
3784 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3785 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3786 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3789 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3791 * The value is in ticks. Note this does not effect
3792 * old associations, only new ones.
3794 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3797 SCTP_INP_WLOCK(inp);
3799 sctp_feature_on(inp, set_opt);
3801 sctp_feature_off(inp, set_opt);
3803 SCTP_INP_WUNLOCK(inp);
3805 case SCTP_REUSE_PORT:
3807 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3808 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3809 /* Can't set it after we are bound */
3813 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3814 /* Can't do this for a 1-m socket */
3819 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3821 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3824 case SCTP_PARTIAL_DELIVERY_POINT:
3828 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3829 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3830 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3834 inp->partial_delivery_point = *value;
3837 case SCTP_FRAGMENT_INTERLEAVE:
3838 /* not yet until we re-write sctp_recvmsg() */
3842 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3843 if (*level == SCTP_FRAG_LEVEL_2) {
3844 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3845 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3846 } else if (*level == SCTP_FRAG_LEVEL_1) {
3847 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3848 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3849 } else if (*level == SCTP_FRAG_LEVEL_0) {
3850 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3851 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3859 case SCTP_CMT_ON_OFF:
3860 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3861 struct sctp_assoc_value *av;
3863 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3864 if (av->assoc_value > SCTP_CMT_MAX) {
3865 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3869 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3871 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3872 SCTP_TCB_UNLOCK(stcb);
3874 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3875 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3876 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3877 (av->assoc_id == SCTP_ALL_ASSOC)) {
3878 SCTP_INP_WLOCK(inp);
3879 inp->sctp_cmt_on_off = av->assoc_value;
3880 SCTP_INP_WUNLOCK(inp);
3882 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3883 (av->assoc_id == SCTP_ALL_ASSOC)) {
3884 SCTP_INP_RLOCK(inp);
3885 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3886 SCTP_TCB_LOCK(stcb);
3887 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3888 SCTP_TCB_UNLOCK(stcb);
3890 SCTP_INP_RUNLOCK(inp);
3894 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3895 error = ENOPROTOOPT;
3898 case SCTP_PLUGGABLE_CC:
3900 struct sctp_assoc_value *av;
3901 struct sctp_nets *net;
3903 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3904 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3905 (av->assoc_value != SCTP_CC_HSTCP) &&
3906 (av->assoc_value != SCTP_CC_HTCP) &&
3907 (av->assoc_value != SCTP_CC_RTCC)) {
3908 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3912 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3914 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3915 stcb->asoc.congestion_control_module = av->assoc_value;
3916 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3917 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3918 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3921 SCTP_TCB_UNLOCK(stcb);
3923 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3924 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3925 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3926 (av->assoc_id == SCTP_ALL_ASSOC)) {
3927 SCTP_INP_WLOCK(inp);
3928 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3929 SCTP_INP_WUNLOCK(inp);
3931 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3932 (av->assoc_id == SCTP_ALL_ASSOC)) {
3933 SCTP_INP_RLOCK(inp);
3934 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3935 SCTP_TCB_LOCK(stcb);
3936 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3937 stcb->asoc.congestion_control_module = av->assoc_value;
3938 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3939 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3940 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3943 SCTP_TCB_UNLOCK(stcb);
3945 SCTP_INP_RUNLOCK(inp);
3950 case SCTP_CC_OPTION:
3952 struct sctp_cc_option *cc_opt;
3954 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
3955 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
3957 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
3958 SCTP_INP_RLOCK(inp);
3959 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3960 SCTP_TCB_LOCK(stcb);
3961 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
3962 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
3964 SCTP_TCB_UNLOCK(stcb);
3966 SCTP_INP_RUNLOCK(inp);
3971 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
3974 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
3977 SCTP_TCB_UNLOCK(stcb);
3981 case SCTP_PLUGGABLE_SS:
3983 struct sctp_assoc_value *av;
3985 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3986 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
3987 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
3988 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
3989 (av->assoc_value != SCTP_SS_PRIORITY) &&
3990 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
3991 (av->assoc_value != SCTP_SS_FIRST_COME)) {
3992 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3996 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3998 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3999 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4000 stcb->asoc.stream_scheduling_module = av->assoc_value;
4001 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4002 SCTP_TCB_UNLOCK(stcb);
4004 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4005 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4006 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4007 (av->assoc_id == SCTP_ALL_ASSOC)) {
4008 SCTP_INP_WLOCK(inp);
4009 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4010 SCTP_INP_WUNLOCK(inp);
4012 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4013 (av->assoc_id == SCTP_ALL_ASSOC)) {
4014 SCTP_INP_RLOCK(inp);
4015 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4016 SCTP_TCB_LOCK(stcb);
4017 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4018 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4019 stcb->asoc.stream_scheduling_module = av->assoc_value;
4020 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4021 SCTP_TCB_UNLOCK(stcb);
4023 SCTP_INP_RUNLOCK(inp);
4030 struct sctp_stream_value *av;
4032 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4033 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4035 if (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4036 av->stream_value) < 0) {
4037 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4040 SCTP_TCB_UNLOCK(stcb);
4042 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4043 SCTP_INP_RLOCK(inp);
4044 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4045 SCTP_TCB_LOCK(stcb);
4046 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4048 &stcb->asoc.strmout[av->stream_id],
4050 SCTP_TCB_UNLOCK(stcb);
4052 SCTP_INP_RUNLOCK(inp);
4056 * Can't set stream value without
4059 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4065 case SCTP_CLR_STAT_LOG:
4066 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4071 struct sctp_assoc_value *av;
4073 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4074 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4077 stcb->asoc.context = av->assoc_value;
4078 SCTP_TCB_UNLOCK(stcb);
4080 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4081 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4082 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4083 (av->assoc_id == SCTP_ALL_ASSOC)) {
4084 SCTP_INP_WLOCK(inp);
4085 inp->sctp_context = av->assoc_value;
4086 SCTP_INP_WUNLOCK(inp);
4088 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4089 (av->assoc_id == SCTP_ALL_ASSOC)) {
4090 SCTP_INP_RLOCK(inp);
4091 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4092 SCTP_TCB_LOCK(stcb);
4093 stcb->asoc.context = av->assoc_value;
4094 SCTP_TCB_UNLOCK(stcb);
4096 SCTP_INP_RUNLOCK(inp);
4103 uint32_t *default_vrfid;
4105 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4106 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4107 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4111 inp->def_vrf_id = *default_vrfid;
4114 case SCTP_DEL_VRF_ID:
4116 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4120 case SCTP_ADD_VRF_ID:
4122 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4126 case SCTP_DELAYED_SACK:
4128 struct sctp_sack_info *sack;
4130 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4131 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4132 if (sack->sack_delay) {
4133 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4134 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4135 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4136 sack->sack_delay = TICKS_TO_MSEC(1);
4140 if (sack->sack_delay) {
4141 stcb->asoc.delayed_ack = sack->sack_delay;
4143 if (sack->sack_freq) {
4144 stcb->asoc.sack_freq = sack->sack_freq;
4146 SCTP_TCB_UNLOCK(stcb);
4148 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4149 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4150 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4151 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4152 SCTP_INP_WLOCK(inp);
4153 if (sack->sack_delay) {
4154 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4156 if (sack->sack_freq) {
4157 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4159 SCTP_INP_WUNLOCK(inp);
4161 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4162 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4163 SCTP_INP_RLOCK(inp);
4164 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4165 SCTP_TCB_LOCK(stcb);
4166 if (sack->sack_delay) {
4167 stcb->asoc.delayed_ack = sack->sack_delay;
4169 if (sack->sack_freq) {
4170 stcb->asoc.sack_freq = sack->sack_freq;
4172 SCTP_TCB_UNLOCK(stcb);
4174 SCTP_INP_RUNLOCK(inp);
4179 case SCTP_AUTH_CHUNK:
4181 struct sctp_authchunk *sauth;
4183 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4185 SCTP_INP_WLOCK(inp);
4186 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4187 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4190 SCTP_INP_WUNLOCK(inp);
4195 struct sctp_authkey *sca;
4196 struct sctp_keyhead *shared_keys;
4197 sctp_sharedkey_t *shared_key;
4198 sctp_key_t *key = NULL;
4201 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4202 if (sca->sca_keylength == 0) {
4203 size = optsize - sizeof(struct sctp_authkey);
4205 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4206 size = sca->sca_keylength;
4208 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4213 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4216 shared_keys = &stcb->asoc.shared_keys;
4217 /* clear the cached keys for this key id */
4218 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4220 * create the new shared key and
4224 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4226 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4228 SCTP_TCB_UNLOCK(stcb);
4232 shared_key = sctp_alloc_sharedkey();
4233 if (shared_key == NULL) {
4235 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4237 SCTP_TCB_UNLOCK(stcb);
4240 shared_key->key = key;
4241 shared_key->keyid = sca->sca_keynumber;
4242 error = sctp_insert_sharedkey(shared_keys, shared_key);
4243 SCTP_TCB_UNLOCK(stcb);
4245 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4246 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4247 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4248 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4249 SCTP_INP_WLOCK(inp);
4250 shared_keys = &inp->sctp_ep.shared_keys;
4252 * clear the cached keys on all
4253 * assocs for this key id
4255 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4257 * create the new shared key and
4261 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4263 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4265 SCTP_INP_WUNLOCK(inp);
4269 shared_key = sctp_alloc_sharedkey();
4270 if (shared_key == NULL) {
4272 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4274 SCTP_INP_WUNLOCK(inp);
4277 shared_key->key = key;
4278 shared_key->keyid = sca->sca_keynumber;
4279 error = sctp_insert_sharedkey(shared_keys, shared_key);
4280 SCTP_INP_WUNLOCK(inp);
4282 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4283 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4284 SCTP_INP_RLOCK(inp);
4285 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4286 SCTP_TCB_LOCK(stcb);
4287 shared_keys = &stcb->asoc.shared_keys;
4289 * clear the cached keys for
4292 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4294 * create the new shared key
4295 * and insert/replace it
4298 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4300 SCTP_TCB_UNLOCK(stcb);
4304 shared_key = sctp_alloc_sharedkey();
4305 if (shared_key == NULL) {
4307 SCTP_TCB_UNLOCK(stcb);
4310 shared_key->key = key;
4311 shared_key->keyid = sca->sca_keynumber;
4312 error = sctp_insert_sharedkey(shared_keys, shared_key);
4313 SCTP_TCB_UNLOCK(stcb);
4315 SCTP_INP_RUNLOCK(inp);
4320 case SCTP_HMAC_IDENT:
4322 struct sctp_hmacalgo *shmac;
4323 sctp_hmaclist_t *hmaclist;
4327 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4328 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4329 (shmac->shmac_number_of_idents > 0xffff)) {
4330 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4334 hmaclist = sctp_alloc_hmaclist((uint16_t) shmac->shmac_number_of_idents);
4335 if (hmaclist == NULL) {
4336 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4340 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4341 hmacid = shmac->shmac_idents[i];
4342 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4343 /* invalid HMACs were found */ ;
4344 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4346 sctp_free_hmaclist(hmaclist);
4347 goto sctp_set_hmac_done;
4350 for (i = 0; i < hmaclist->num_algo; i++) {
4351 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4352 /* already in list */
4356 if (i == hmaclist->num_algo) {
4357 /* not found in list */
4358 sctp_free_hmaclist(hmaclist);
4359 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4363 /* set it on the endpoint */
4364 SCTP_INP_WLOCK(inp);
4365 if (inp->sctp_ep.local_hmacs)
4366 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4367 inp->sctp_ep.local_hmacs = hmaclist;
4368 SCTP_INP_WUNLOCK(inp);
4372 case SCTP_AUTH_ACTIVE_KEY:
4374 struct sctp_authkeyid *scact;
4376 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4377 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4379 /* set the active key on the right place */
4381 /* set the active key on the assoc */
4382 if (sctp_auth_setactivekey(stcb,
4383 scact->scact_keynumber)) {
4384 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4385 SCTP_FROM_SCTP_USRREQ,
4389 SCTP_TCB_UNLOCK(stcb);
4391 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4392 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4393 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4394 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4395 SCTP_INP_WLOCK(inp);
4396 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4397 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4400 SCTP_INP_WUNLOCK(inp);
4402 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4403 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4404 SCTP_INP_RLOCK(inp);
4405 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4406 SCTP_TCB_LOCK(stcb);
4407 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4408 SCTP_TCB_UNLOCK(stcb);
4410 SCTP_INP_RUNLOCK(inp);
4415 case SCTP_AUTH_DELETE_KEY:
4417 struct sctp_authkeyid *scdel;
4419 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4420 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4422 /* delete the key from the right place */
4424 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4425 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4428 SCTP_TCB_UNLOCK(stcb);
4430 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4431 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4432 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4433 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4434 SCTP_INP_WLOCK(inp);
4435 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4436 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4439 SCTP_INP_WUNLOCK(inp);
4441 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4442 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4443 SCTP_INP_RLOCK(inp);
4444 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4445 SCTP_TCB_LOCK(stcb);
4446 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4447 SCTP_TCB_UNLOCK(stcb);
4449 SCTP_INP_RUNLOCK(inp);
4454 case SCTP_AUTH_DEACTIVATE_KEY:
4456 struct sctp_authkeyid *keyid;
4458 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4459 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4461 /* deactivate the key from the right place */
4463 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4464 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4467 SCTP_TCB_UNLOCK(stcb);
4469 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4470 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4471 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4472 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4473 SCTP_INP_WLOCK(inp);
4474 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4475 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4478 SCTP_INP_WUNLOCK(inp);
4480 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4481 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4482 SCTP_INP_RLOCK(inp);
4483 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4484 SCTP_TCB_LOCK(stcb);
4485 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4486 SCTP_TCB_UNLOCK(stcb);
4488 SCTP_INP_RUNLOCK(inp);
4493 case SCTP_ENABLE_STREAM_RESET:
4495 struct sctp_assoc_value *av;
4497 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4498 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4499 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4503 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4505 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4506 SCTP_TCB_UNLOCK(stcb);
4508 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4509 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4510 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4511 (av->assoc_id == SCTP_ALL_ASSOC)) {
4512 SCTP_INP_WLOCK(inp);
4513 inp->local_strreset_support = (uint8_t) av->assoc_value;
4514 SCTP_INP_WUNLOCK(inp);
4516 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4517 (av->assoc_id == SCTP_ALL_ASSOC)) {
4518 SCTP_INP_RLOCK(inp);
4519 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4520 SCTP_TCB_LOCK(stcb);
4521 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4522 SCTP_TCB_UNLOCK(stcb);
4524 SCTP_INP_RUNLOCK(inp);
4529 case SCTP_RESET_STREAMS:
4531 struct sctp_reset_streams *strrst;
4532 int i, send_out = 0;
4535 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4536 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4538 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4542 if (stcb->asoc.reconfig_supported == 0) {
4544 * Peer does not support the chunk type.
4546 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4548 SCTP_TCB_UNLOCK(stcb);
4551 if (sizeof(struct sctp_reset_streams) +
4552 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4554 SCTP_TCB_UNLOCK(stcb);
4557 if (stcb->asoc.stream_reset_outstanding) {
4558 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4560 SCTP_TCB_UNLOCK(stcb);
4563 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4566 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4569 if ((send_in == 0) && (send_out == 0)) {
4570 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4572 SCTP_TCB_UNLOCK(stcb);
4575 for (i = 0; i < strrst->srs_number_streams; i++) {
4577 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4578 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4583 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4584 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4590 SCTP_TCB_UNLOCK(stcb);
4593 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4594 strrst->srs_stream_list,
4595 send_out, send_in, 0, 0, 0, 0, 0);
4597 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4598 SCTP_TCB_UNLOCK(stcb);
4601 case SCTP_ADD_STREAMS:
4603 struct sctp_add_streams *stradd;
4604 uint8_t addstream = 0;
4605 uint16_t add_o_strmcnt = 0;
4606 uint16_t add_i_strmcnt = 0;
4608 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4609 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4611 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4615 if (stcb->asoc.reconfig_supported == 0) {
4617 * Peer does not support the chunk type.
4619 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4621 SCTP_TCB_UNLOCK(stcb);
4624 if (stcb->asoc.stream_reset_outstanding) {
4625 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4627 SCTP_TCB_UNLOCK(stcb);
4630 if ((stradd->sas_outstrms == 0) &&
4631 (stradd->sas_instrms == 0)) {
4635 if (stradd->sas_outstrms) {
4637 /* We allocate here */
4638 add_o_strmcnt = stradd->sas_outstrms;
4639 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4640 /* You can't have more than 64k */
4645 if (stradd->sas_instrms) {
4650 * We allocate inside
4651 * sctp_send_str_reset_req()
4653 add_i_strmcnt = stradd->sas_instrms;
4654 cnt = add_i_strmcnt;
4655 cnt += stcb->asoc.streamincnt;
4656 if (cnt > 0x0000ffff) {
4657 /* You can't have more than 64k */
4661 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4662 /* More than you are allowed */
4667 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4668 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4670 SCTP_TCB_UNLOCK(stcb);
4673 case SCTP_RESET_ASSOC:
4677 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4678 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4680 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4684 if (stcb->asoc.reconfig_supported == 0) {
4686 * Peer does not support the chunk type.
4688 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4690 SCTP_TCB_UNLOCK(stcb);
4693 if (stcb->asoc.stream_reset_outstanding) {
4694 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4696 SCTP_TCB_UNLOCK(stcb);
4699 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 1, 0, 0, 0, 0);
4700 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4701 SCTP_TCB_UNLOCK(stcb);
4704 case SCTP_CONNECT_X:
4705 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4706 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4710 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4712 case SCTP_CONNECT_X_DELAYED:
4713 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4714 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4718 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4720 case SCTP_CONNECT_X_COMPLETE:
4722 struct sockaddr *sa;
4723 struct sctp_nets *net;
4725 /* FIXME MT: check correct? */
4726 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4729 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4730 SCTP_INP_RLOCK(inp);
4731 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4733 SCTP_TCB_LOCK(stcb);
4734 net = sctp_findnet(stcb, sa);
4736 SCTP_INP_RUNLOCK(inp);
4739 * We increment here since
4740 * sctp_findassociation_ep_addr() wil do a
4741 * decrement if it finds the stcb as long as
4742 * the locked tcb (last argument) is NOT a
4745 SCTP_INP_INCR_REF(inp);
4746 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
4748 SCTP_INP_DECR_REF(inp);
4753 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4757 if (stcb->asoc.delayed_connection == 1) {
4758 stcb->asoc.delayed_connection = 0;
4759 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4760 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4761 stcb->asoc.primary_destination,
4762 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
4763 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4766 * already expired or did not use delayed
4769 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4772 SCTP_TCB_UNLOCK(stcb);
4775 case SCTP_MAX_BURST:
4777 struct sctp_assoc_value *av;
4779 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4780 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4783 stcb->asoc.max_burst = av->assoc_value;
4784 SCTP_TCB_UNLOCK(stcb);
4786 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4787 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4788 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4789 (av->assoc_id == SCTP_ALL_ASSOC)) {
4790 SCTP_INP_WLOCK(inp);
4791 inp->sctp_ep.max_burst = av->assoc_value;
4792 SCTP_INP_WUNLOCK(inp);
4794 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4795 (av->assoc_id == SCTP_ALL_ASSOC)) {
4796 SCTP_INP_RLOCK(inp);
4797 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4798 SCTP_TCB_LOCK(stcb);
4799 stcb->asoc.max_burst = av->assoc_value;
4800 SCTP_TCB_UNLOCK(stcb);
4802 SCTP_INP_RUNLOCK(inp);
4809 struct sctp_assoc_value *av;
4812 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4813 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4815 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4816 ovh = SCTP_MED_OVERHEAD;
4818 ovh = SCTP_MED_V4_OVERHEAD;
4821 if (av->assoc_value) {
4822 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4824 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4826 SCTP_TCB_UNLOCK(stcb);
4828 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4829 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4830 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4831 SCTP_INP_WLOCK(inp);
4833 * FIXME MT: I think this is not in
4834 * tune with the API ID
4836 if (av->assoc_value) {
4837 inp->sctp_frag_point = (av->assoc_value + ovh);
4839 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4841 SCTP_INP_WUNLOCK(inp);
4843 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4851 struct sctp_event_subscribe *events;
4853 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4855 SCTP_INP_WLOCK(inp);
4856 if (events->sctp_data_io_event) {
4857 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4859 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4862 if (events->sctp_association_event) {
4863 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4865 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4868 if (events->sctp_address_event) {
4869 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4871 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4874 if (events->sctp_send_failure_event) {
4875 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4877 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4880 if (events->sctp_peer_error_event) {
4881 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4883 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4886 if (events->sctp_shutdown_event) {
4887 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4889 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4892 if (events->sctp_partial_delivery_event) {
4893 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4895 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4898 if (events->sctp_adaptation_layer_event) {
4899 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4901 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4904 if (events->sctp_authentication_event) {
4905 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4907 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4910 if (events->sctp_sender_dry_event) {
4911 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
4913 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
4916 if (events->sctp_stream_reset_event) {
4917 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4919 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4921 SCTP_INP_WUNLOCK(inp);
4923 SCTP_INP_RLOCK(inp);
4924 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4925 SCTP_TCB_LOCK(stcb);
4926 if (events->sctp_association_event) {
4927 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4929 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4931 if (events->sctp_address_event) {
4932 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4934 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4936 if (events->sctp_send_failure_event) {
4937 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4939 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4941 if (events->sctp_peer_error_event) {
4942 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4944 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4946 if (events->sctp_shutdown_event) {
4947 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4949 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4951 if (events->sctp_partial_delivery_event) {
4952 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4954 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4956 if (events->sctp_adaptation_layer_event) {
4957 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4959 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4961 if (events->sctp_authentication_event) {
4962 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4964 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4966 if (events->sctp_sender_dry_event) {
4967 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4969 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4971 if (events->sctp_stream_reset_event) {
4972 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4974 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4976 SCTP_TCB_UNLOCK(stcb);
4979 * Send up the sender dry event only for 1-to-1
4982 if (events->sctp_sender_dry_event) {
4983 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4984 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
4985 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4987 SCTP_TCB_LOCK(stcb);
4988 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
4989 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
4990 (stcb->asoc.stream_queue_cnt == 0)) {
4991 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
4993 SCTP_TCB_UNLOCK(stcb);
4997 SCTP_INP_RUNLOCK(inp);
5000 case SCTP_ADAPTATION_LAYER:
5002 struct sctp_setadaptation *adap_bits;
5004 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5005 SCTP_INP_WLOCK(inp);
5006 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5007 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5008 SCTP_INP_WUNLOCK(inp);
5012 case SCTP_SET_INITIAL_DBG_SEQ:
5016 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5017 SCTP_INP_WLOCK(inp);
5018 inp->sctp_ep.initial_sequence_debug = *vvv;
5019 SCTP_INP_WUNLOCK(inp);
5023 case SCTP_DEFAULT_SEND_PARAM:
5025 struct sctp_sndrcvinfo *s_info;
5027 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5028 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5031 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5032 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5034 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5037 SCTP_TCB_UNLOCK(stcb);
5039 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5040 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5041 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5042 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5043 SCTP_INP_WLOCK(inp);
5044 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5045 SCTP_INP_WUNLOCK(inp);
5047 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5048 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5049 SCTP_INP_RLOCK(inp);
5050 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5051 SCTP_TCB_LOCK(stcb);
5052 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5053 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5055 SCTP_TCB_UNLOCK(stcb);
5057 SCTP_INP_RUNLOCK(inp);
5062 case SCTP_PEER_ADDR_PARAMS:
5064 struct sctp_paddrparams *paddrp;
5065 struct sctp_nets *net;
5066 struct sockaddr *addr;
5068 #if defined(INET) && defined(INET6)
5069 struct sockaddr_in sin_store;
5073 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5074 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5076 #if defined(INET) && defined(INET6)
5077 if (paddrp->spp_address.ss_family == AF_INET6) {
5078 struct sockaddr_in6 *sin6;
5080 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5081 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5082 in6_sin6_2_sin(&sin_store, sin6);
5083 addr = (struct sockaddr *)&sin_store;
5085 addr = (struct sockaddr *)&paddrp->spp_address;
5088 addr = (struct sockaddr *)&paddrp->spp_address;
5091 addr = (struct sockaddr *)&paddrp->spp_address;
5094 net = sctp_findnet(stcb, addr);
5097 * We increment here since
5098 * sctp_findassociation_ep_addr() wil do a
5099 * decrement if it finds the stcb as long as
5100 * the locked tcb (last argument) is NOT a
5104 SCTP_INP_INCR_REF(inp);
5105 stcb = sctp_findassociation_ep_addr(&inp, addr,
5108 SCTP_INP_DECR_REF(inp);
5111 if ((stcb != NULL) && (net == NULL)) {
5113 if (addr->sa_family == AF_INET) {
5115 struct sockaddr_in *sin;
5117 sin = (struct sockaddr_in *)addr;
5118 if (sin->sin_addr.s_addr != INADDR_ANY) {
5119 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5120 SCTP_TCB_UNLOCK(stcb);
5127 if (addr->sa_family == AF_INET6) {
5128 struct sockaddr_in6 *sin6;
5130 sin6 = (struct sockaddr_in6 *)addr;
5131 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5132 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5133 SCTP_TCB_UNLOCK(stcb);
5140 error = EAFNOSUPPORT;
5141 SCTP_TCB_UNLOCK(stcb);
5142 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5147 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5149 SCTP_TCB_UNLOCK(stcb);
5150 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5153 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5155 SCTP_TCB_UNLOCK(stcb);
5156 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5160 /************************TCB SPECIFIC SET ******************/
5162 * do we change the timer for HB, we run
5167 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5168 ovh = SCTP_MED_OVERHEAD;
5170 ovh = SCTP_MED_V4_OVERHEAD;
5173 /* network sets ? */
5175 /************************NET SPECIFIC SET ******************/
5176 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5177 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5178 !(net->dest_state & SCTP_ADDR_NOHB)) {
5179 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5180 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5182 net->dest_state |= SCTP_ADDR_NOHB;
5184 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5185 if (paddrp->spp_hbinterval) {
5186 net->heart_beat_delay = paddrp->spp_hbinterval;
5187 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5188 net->heart_beat_delay = 0;
5190 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5191 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5192 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5193 net->dest_state &= ~SCTP_ADDR_NOHB;
5195 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5197 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5198 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5199 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5201 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5202 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5203 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5204 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5206 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5207 net->mtu = paddrp->spp_pathmtu + ovh;
5208 if (net->mtu < stcb->asoc.smallest_mtu) {
5209 sctp_pathmtu_adjustment(stcb, net->mtu);
5212 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5213 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5214 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5216 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5218 if (paddrp->spp_pathmaxrxt) {
5219 if (net->dest_state & SCTP_ADDR_PF) {
5220 if (net->error_count > paddrp->spp_pathmaxrxt) {
5221 net->dest_state &= ~SCTP_ADDR_PF;
5224 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5225 (net->error_count > net->pf_threshold)) {
5226 net->dest_state |= SCTP_ADDR_PF;
5227 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5228 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5229 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5232 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5233 if (net->error_count > paddrp->spp_pathmaxrxt) {
5234 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5235 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5238 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5239 net->dest_state |= SCTP_ADDR_REACHABLE;
5240 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5243 net->failure_threshold = paddrp->spp_pathmaxrxt;
5245 if (paddrp->spp_flags & SPP_DSCP) {
5246 net->dscp = paddrp->spp_dscp & 0xfc;
5250 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5251 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5252 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5253 net->flowlabel |= 0x80000000;
5258 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5259 if (paddrp->spp_pathmaxrxt != 0) {
5260 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5261 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5262 if (net->dest_state & SCTP_ADDR_PF) {
5263 if (net->error_count > paddrp->spp_pathmaxrxt) {
5264 net->dest_state &= ~SCTP_ADDR_PF;
5267 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5268 (net->error_count > net->pf_threshold)) {
5269 net->dest_state |= SCTP_ADDR_PF;
5270 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5271 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5272 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5275 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5276 if (net->error_count > paddrp->spp_pathmaxrxt) {
5277 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5278 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5281 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5282 net->dest_state |= SCTP_ADDR_REACHABLE;
5283 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5286 net->failure_threshold = paddrp->spp_pathmaxrxt;
5289 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5290 if (paddrp->spp_hbinterval != 0) {
5291 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5292 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5293 stcb->asoc.heart_beat_delay = 0;
5295 /* Turn back on the timer */
5296 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5297 if (paddrp->spp_hbinterval != 0) {
5298 net->heart_beat_delay = paddrp->spp_hbinterval;
5299 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5300 net->heart_beat_delay = 0;
5302 if (net->dest_state & SCTP_ADDR_NOHB) {
5303 net->dest_state &= ~SCTP_ADDR_NOHB;
5305 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5306 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5307 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5309 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5311 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5312 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5313 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5314 net->dest_state |= SCTP_ADDR_NOHB;
5315 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5316 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5320 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5322 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5323 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5324 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5325 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5326 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5328 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5329 net->mtu = paddrp->spp_pathmtu + ovh;
5330 if (net->mtu < stcb->asoc.smallest_mtu) {
5331 sctp_pathmtu_adjustment(stcb, net->mtu);
5334 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5336 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5337 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5338 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5339 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5341 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5343 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5345 if (paddrp->spp_flags & SPP_DSCP) {
5346 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5347 net->dscp = paddrp->spp_dscp & 0xfc;
5350 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5351 stcb->asoc.default_dscp |= 0x01;
5354 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5355 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5356 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5357 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5358 net->flowlabel |= 0x80000000;
5361 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5362 stcb->asoc.default_flowlabel |= 0x80000000;
5366 SCTP_TCB_UNLOCK(stcb);
5368 /************************NO TCB, SET TO default stuff ******************/
5369 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5370 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5371 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5372 SCTP_INP_WLOCK(inp);
5374 * For the TOS/FLOWLABEL stuff you
5375 * set it with the options on the
5378 if (paddrp->spp_pathmaxrxt != 0) {
5379 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5381 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5382 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5383 else if (paddrp->spp_hbinterval != 0) {
5384 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5385 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5386 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5388 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5389 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5390 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5391 } else if (paddrp->spp_hbinterval) {
5392 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5394 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5395 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5396 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5398 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5399 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5400 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5401 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5403 if (paddrp->spp_flags & SPP_DSCP) {
5404 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5405 inp->sctp_ep.default_dscp |= 0x01;
5408 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5409 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5410 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5411 inp->sctp_ep.default_flowlabel |= 0x80000000;
5415 SCTP_INP_WUNLOCK(inp);
5417 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5425 struct sctp_rtoinfo *srto;
5426 uint32_t new_init, new_min, new_max;
5428 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5429 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5432 if (srto->srto_initial)
5433 new_init = srto->srto_initial;
5435 new_init = stcb->asoc.initial_rto;
5437 new_max = srto->srto_max;
5439 new_max = stcb->asoc.maxrto;
5441 new_min = srto->srto_min;
5443 new_min = stcb->asoc.minrto;
5444 if ((new_min <= new_init) && (new_init <= new_max)) {
5445 stcb->asoc.initial_rto = new_init;
5446 stcb->asoc.maxrto = new_max;
5447 stcb->asoc.minrto = new_min;
5449 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5452 SCTP_TCB_UNLOCK(stcb);
5454 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5455 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5456 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5457 SCTP_INP_WLOCK(inp);
5458 if (srto->srto_initial)
5459 new_init = srto->srto_initial;
5461 new_init = inp->sctp_ep.initial_rto;
5463 new_max = srto->srto_max;
5465 new_max = inp->sctp_ep.sctp_maxrto;
5467 new_min = srto->srto_min;
5469 new_min = inp->sctp_ep.sctp_minrto;
5470 if ((new_min <= new_init) && (new_init <= new_max)) {
5471 inp->sctp_ep.initial_rto = new_init;
5472 inp->sctp_ep.sctp_maxrto = new_max;
5473 inp->sctp_ep.sctp_minrto = new_min;
5475 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5478 SCTP_INP_WUNLOCK(inp);
5480 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5486 case SCTP_ASSOCINFO:
5488 struct sctp_assocparams *sasoc;
5490 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5491 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5492 if (sasoc->sasoc_cookie_life) {
5493 /* boundary check the cookie life */
5494 if (sasoc->sasoc_cookie_life < 1000)
5495 sasoc->sasoc_cookie_life = 1000;
5496 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5497 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5501 if (sasoc->sasoc_asocmaxrxt)
5502 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5503 if (sasoc->sasoc_cookie_life) {
5504 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5506 SCTP_TCB_UNLOCK(stcb);
5508 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5509 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5510 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5511 SCTP_INP_WLOCK(inp);
5512 if (sasoc->sasoc_asocmaxrxt)
5513 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5514 if (sasoc->sasoc_cookie_life) {
5515 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5517 SCTP_INP_WUNLOCK(inp);
5519 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5527 struct sctp_initmsg *sinit;
5529 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5530 SCTP_INP_WLOCK(inp);
5531 if (sinit->sinit_num_ostreams)
5532 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5534 if (sinit->sinit_max_instreams)
5535 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5537 if (sinit->sinit_max_attempts)
5538 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5540 if (sinit->sinit_max_init_timeo)
5541 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5542 SCTP_INP_WUNLOCK(inp);
5545 case SCTP_PRIMARY_ADDR:
5547 struct sctp_setprim *spa;
5548 struct sctp_nets *net;
5549 struct sockaddr *addr;
5551 #if defined(INET) && defined(INET6)
5552 struct sockaddr_in sin_store;
5556 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5557 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5559 #if defined(INET) && defined(INET6)
5560 if (spa->ssp_addr.ss_family == AF_INET6) {
5561 struct sockaddr_in6 *sin6;
5563 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5564 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5565 in6_sin6_2_sin(&sin_store, sin6);
5566 addr = (struct sockaddr *)&sin_store;
5568 addr = (struct sockaddr *)&spa->ssp_addr;
5571 addr = (struct sockaddr *)&spa->ssp_addr;
5574 addr = (struct sockaddr *)&spa->ssp_addr;
5577 net = sctp_findnet(stcb, addr);
5580 * We increment here since
5581 * sctp_findassociation_ep_addr() wil do a
5582 * decrement if it finds the stcb as long as
5583 * the locked tcb (last argument) is NOT a
5587 SCTP_INP_INCR_REF(inp);
5588 stcb = sctp_findassociation_ep_addr(&inp, addr,
5591 SCTP_INP_DECR_REF(inp);
5595 if ((stcb != NULL) && (net != NULL)) {
5596 if ((net != stcb->asoc.primary_destination) &&
5597 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
5598 /* Ok we need to set it */
5599 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5600 if ((stcb->asoc.alternate) &&
5601 (!(net->dest_state & SCTP_ADDR_PF)) &&
5602 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5603 sctp_free_remote_addr(stcb->asoc.alternate);
5604 stcb->asoc.alternate = NULL;
5609 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5613 SCTP_TCB_UNLOCK(stcb);
5617 case SCTP_SET_DYNAMIC_PRIMARY:
5619 union sctp_sockstore *ss;
5621 error = priv_check(curthread,
5622 PRIV_NETINET_RESERVEDPORT);
5626 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5627 /* SUPER USER CHECK? */
5628 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5631 case SCTP_SET_PEER_PRIMARY_ADDR:
5633 struct sctp_setpeerprim *sspp;
5634 struct sockaddr *addr;
5636 #if defined(INET) && defined(INET6)
5637 struct sockaddr_in sin_store;
5641 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5642 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5644 struct sctp_ifa *ifa;
5646 #if defined(INET) && defined(INET6)
5647 if (sspp->sspp_addr.ss_family == AF_INET6) {
5648 struct sockaddr_in6 *sin6;
5650 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5651 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5652 in6_sin6_2_sin(&sin_store, sin6);
5653 addr = (struct sockaddr *)&sin_store;
5655 addr = (struct sockaddr *)&sspp->sspp_addr;
5658 addr = (struct sockaddr *)&sspp->sspp_addr;
5661 addr = (struct sockaddr *)&sspp->sspp_addr;
5663 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5665 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5669 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5671 * Must validate the ifa found is in
5674 struct sctp_laddr *laddr;
5677 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5678 if (laddr->ifa == NULL) {
5679 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5683 if (laddr->ifa == ifa) {
5689 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5694 switch (addr->sa_family) {
5698 struct sockaddr_in *sin;
5700 sin = (struct sockaddr_in *)addr;
5701 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5702 &sin->sin_addr) != 0) {
5703 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5713 struct sockaddr_in6 *sin6;
5715 sin6 = (struct sockaddr_in6 *)addr;
5716 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5717 &sin6->sin6_addr) != 0) {
5718 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5726 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5731 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5732 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5736 SCTP_TCB_UNLOCK(stcb);
5738 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5743 case SCTP_BINDX_ADD_ADDR:
5745 struct sctp_getaddresses *addrs;
5748 td = (struct thread *)p;
5749 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5752 if (addrs->addr->sa_family == AF_INET) {
5753 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5754 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5758 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5759 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5765 if (addrs->addr->sa_family == AF_INET6) {
5766 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5767 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5771 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5772 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5773 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5779 error = EAFNOSUPPORT;
5782 sctp_bindx_add_address(so, inp, addrs->addr,
5783 addrs->sget_assoc_id, vrf_id,
5787 case SCTP_BINDX_REM_ADDR:
5789 struct sctp_getaddresses *addrs;
5792 td = (struct thread *)p;
5794 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5796 if (addrs->addr->sa_family == AF_INET) {
5797 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5798 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5802 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5803 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5809 if (addrs->addr->sa_family == AF_INET6) {
5810 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5811 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5816 (error = prison_local_ip6(td->td_ucred,
5817 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5818 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5819 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5825 error = EAFNOSUPPORT;
5828 sctp_bindx_delete_address(inp, addrs->addr,
5829 addrs->sget_assoc_id, vrf_id,
5835 struct sctp_event *event;
5836 uint32_t event_type;
5838 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5839 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5840 switch (event->se_type) {
5841 case SCTP_ASSOC_CHANGE:
5842 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5844 case SCTP_PEER_ADDR_CHANGE:
5845 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5847 case SCTP_REMOTE_ERROR:
5848 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5850 case SCTP_SEND_FAILED:
5851 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5853 case SCTP_SHUTDOWN_EVENT:
5854 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5856 case SCTP_ADAPTATION_INDICATION:
5857 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5859 case SCTP_PARTIAL_DELIVERY_EVENT:
5860 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5862 case SCTP_AUTHENTICATION_EVENT:
5863 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5865 case SCTP_STREAM_RESET_EVENT:
5866 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5868 case SCTP_SENDER_DRY_EVENT:
5869 event_type = SCTP_PCB_FLAGS_DRYEVNT;
5871 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
5873 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5876 case SCTP_ASSOC_RESET_EVENT:
5877 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
5879 case SCTP_STREAM_CHANGE_EVENT:
5880 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
5882 case SCTP_SEND_FAILED_EVENT:
5883 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
5887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5891 if (event_type > 0) {
5894 sctp_stcb_feature_on(inp, stcb, event_type);
5895 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
5896 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5897 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5898 (stcb->asoc.stream_queue_cnt == 0)) {
5899 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5903 sctp_stcb_feature_off(inp, stcb, event_type);
5905 SCTP_TCB_UNLOCK(stcb);
5908 * We don't want to send up a storm
5909 * of events, so return an error for
5912 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
5913 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
5914 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
5915 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
5916 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
5917 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5921 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5922 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5923 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
5924 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5925 SCTP_INP_WLOCK(inp);
5927 sctp_feature_on(inp, event_type);
5929 sctp_feature_off(inp, event_type);
5931 SCTP_INP_WUNLOCK(inp);
5933 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
5934 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5935 SCTP_INP_RLOCK(inp);
5936 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5937 SCTP_TCB_LOCK(stcb);
5939 sctp_stcb_feature_on(inp, stcb, event_type);
5941 sctp_stcb_feature_off(inp, stcb, event_type);
5943 SCTP_TCB_UNLOCK(stcb);
5945 SCTP_INP_RUNLOCK(inp);
5951 case SCTP_RECVRCVINFO:
5955 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5956 SCTP_INP_WLOCK(inp);
5958 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5960 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5962 SCTP_INP_WUNLOCK(inp);
5965 case SCTP_RECVNXTINFO:
5969 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5970 SCTP_INP_WLOCK(inp);
5972 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5974 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5976 SCTP_INP_WUNLOCK(inp);
5979 case SCTP_DEFAULT_SNDINFO:
5981 struct sctp_sndinfo *info;
5984 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
5985 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
5988 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5989 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5990 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5991 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5992 stcb->asoc.def_send.sinfo_flags |= policy;
5993 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5994 stcb->asoc.def_send.sinfo_context = info->snd_context;
5996 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5999 SCTP_TCB_UNLOCK(stcb);
6001 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6002 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6003 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6004 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6005 SCTP_INP_WLOCK(inp);
6006 inp->def_send.sinfo_stream = info->snd_sid;
6007 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6008 inp->def_send.sinfo_flags = info->snd_flags;
6009 inp->def_send.sinfo_flags |= policy;
6010 inp->def_send.sinfo_ppid = info->snd_ppid;
6011 inp->def_send.sinfo_context = info->snd_context;
6012 SCTP_INP_WUNLOCK(inp);
6014 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6015 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6016 SCTP_INP_RLOCK(inp);
6017 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6018 SCTP_TCB_LOCK(stcb);
6019 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6020 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6021 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6022 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6023 stcb->asoc.def_send.sinfo_flags |= policy;
6024 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6025 stcb->asoc.def_send.sinfo_context = info->snd_context;
6027 SCTP_TCB_UNLOCK(stcb);
6029 SCTP_INP_RUNLOCK(inp);
6034 case SCTP_DEFAULT_PRINFO:
6036 struct sctp_default_prinfo *info;
6038 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6039 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6041 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6042 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6047 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6048 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6049 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6050 SCTP_TCB_UNLOCK(stcb);
6052 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6053 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6054 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6055 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6056 SCTP_INP_WLOCK(inp);
6057 inp->def_send.sinfo_flags &= 0xfff0;
6058 inp->def_send.sinfo_flags |= info->pr_policy;
6059 inp->def_send.sinfo_timetolive = info->pr_value;
6060 SCTP_INP_WUNLOCK(inp);
6062 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6063 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6064 SCTP_INP_RLOCK(inp);
6065 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6066 SCTP_TCB_LOCK(stcb);
6067 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6068 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6069 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6070 SCTP_TCB_UNLOCK(stcb);
6072 SCTP_INP_RUNLOCK(inp);
6077 case SCTP_PEER_ADDR_THLDS:
6078 /* Applies to the specific association */
6080 struct sctp_paddrthlds *thlds;
6081 struct sctp_nets *net;
6082 struct sockaddr *addr;
6084 #if defined(INET) && defined(INET6)
6085 struct sockaddr_in sin_store;
6089 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6090 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6092 #if defined(INET) && defined(INET6)
6093 if (thlds->spt_address.ss_family == AF_INET6) {
6094 struct sockaddr_in6 *sin6;
6096 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6097 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6098 in6_sin6_2_sin(&sin_store, sin6);
6099 addr = (struct sockaddr *)&sin_store;
6101 addr = (struct sockaddr *)&thlds->spt_address;
6104 addr = (struct sockaddr *)&thlds->spt_address;
6107 addr = (struct sockaddr *)&thlds->spt_address;
6110 net = sctp_findnet(stcb, addr);
6113 * We increment here since
6114 * sctp_findassociation_ep_addr() wil do a
6115 * decrement if it finds the stcb as long as
6116 * the locked tcb (last argument) is NOT a
6120 SCTP_INP_INCR_REF(inp);
6121 stcb = sctp_findassociation_ep_addr(&inp, addr,
6124 SCTP_INP_DECR_REF(inp);
6127 if ((stcb != NULL) && (net == NULL)) {
6129 if (addr->sa_family == AF_INET) {
6131 struct sockaddr_in *sin;
6133 sin = (struct sockaddr_in *)addr;
6134 if (sin->sin_addr.s_addr != INADDR_ANY) {
6135 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6136 SCTP_TCB_UNLOCK(stcb);
6143 if (addr->sa_family == AF_INET6) {
6144 struct sockaddr_in6 *sin6;
6146 sin6 = (struct sockaddr_in6 *)addr;
6147 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6148 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6149 SCTP_TCB_UNLOCK(stcb);
6156 error = EAFNOSUPPORT;
6157 SCTP_TCB_UNLOCK(stcb);
6158 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6164 if (net->dest_state & SCTP_ADDR_PF) {
6165 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
6166 (net->failure_threshold <= thlds->spt_pathpfthld)) {
6167 net->dest_state &= ~SCTP_ADDR_PF;
6170 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
6171 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
6172 net->dest_state |= SCTP_ADDR_PF;
6173 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6174 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
6175 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6178 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6179 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
6180 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6181 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6184 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
6185 net->dest_state |= SCTP_ADDR_REACHABLE;
6186 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6189 net->failure_threshold = thlds->spt_pathmaxrxt;
6190 net->pf_threshold = thlds->spt_pathpfthld;
6192 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6193 if (net->dest_state & SCTP_ADDR_PF) {
6194 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
6195 (net->failure_threshold <= thlds->spt_pathpfthld)) {
6196 net->dest_state &= ~SCTP_ADDR_PF;
6199 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
6200 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
6201 net->dest_state |= SCTP_ADDR_PF;
6202 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6203 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
6204 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6207 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6208 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
6209 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6210 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6213 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
6214 net->dest_state |= SCTP_ADDR_REACHABLE;
6215 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6218 net->failure_threshold = thlds->spt_pathmaxrxt;
6219 net->pf_threshold = thlds->spt_pathpfthld;
6221 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6222 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6225 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6226 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6227 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6228 SCTP_INP_WLOCK(inp);
6229 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6230 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6231 SCTP_INP_WUNLOCK(inp);
6233 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6239 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6241 struct sctp_udpencaps *encaps;
6242 struct sctp_nets *net;
6243 struct sockaddr *addr;
6245 #if defined(INET) && defined(INET6)
6246 struct sockaddr_in sin_store;
6250 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6251 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6253 #if defined(INET) && defined(INET6)
6254 if (encaps->sue_address.ss_family == AF_INET6) {
6255 struct sockaddr_in6 *sin6;
6257 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6258 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6259 in6_sin6_2_sin(&sin_store, sin6);
6260 addr = (struct sockaddr *)&sin_store;
6262 addr = (struct sockaddr *)&encaps->sue_address;
6265 addr = (struct sockaddr *)&encaps->sue_address;
6268 addr = (struct sockaddr *)&encaps->sue_address;
6271 net = sctp_findnet(stcb, addr);
6274 * We increment here since
6275 * sctp_findassociation_ep_addr() wil do a
6276 * decrement if it finds the stcb as long as
6277 * the locked tcb (last argument) is NOT a
6281 SCTP_INP_INCR_REF(inp);
6282 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6284 SCTP_INP_DECR_REF(inp);
6287 if ((stcb != NULL) && (net == NULL)) {
6289 if (addr->sa_family == AF_INET) {
6291 struct sockaddr_in *sin;
6293 sin = (struct sockaddr_in *)addr;
6294 if (sin->sin_addr.s_addr != INADDR_ANY) {
6295 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6296 SCTP_TCB_UNLOCK(stcb);
6303 if (addr->sa_family == AF_INET6) {
6304 struct sockaddr_in6 *sin6;
6306 sin6 = (struct sockaddr_in6 *)addr;
6307 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6308 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6309 SCTP_TCB_UNLOCK(stcb);
6316 error = EAFNOSUPPORT;
6317 SCTP_TCB_UNLOCK(stcb);
6318 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6324 net->port = encaps->sue_port;
6326 stcb->asoc.port = encaps->sue_port;
6328 SCTP_TCB_UNLOCK(stcb);
6330 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6331 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6332 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6333 SCTP_INP_WLOCK(inp);
6334 inp->sctp_ep.port = encaps->sue_port;
6335 SCTP_INP_WUNLOCK(inp);
6337 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6343 case SCTP_ECN_SUPPORTED:
6345 struct sctp_assoc_value *av;
6347 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6348 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6351 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6353 SCTP_TCB_UNLOCK(stcb);
6355 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6356 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6357 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6358 SCTP_INP_WLOCK(inp);
6359 if (av->assoc_value == 0) {
6360 inp->ecn_supported = 0;
6362 inp->ecn_supported = 1;
6364 SCTP_INP_WUNLOCK(inp);
6366 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6372 case SCTP_PR_SUPPORTED:
6374 struct sctp_assoc_value *av;
6376 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6377 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6380 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6382 SCTP_TCB_UNLOCK(stcb);
6384 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6385 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6386 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6387 SCTP_INP_WLOCK(inp);
6388 if (av->assoc_value == 0) {
6389 inp->prsctp_supported = 0;
6391 inp->prsctp_supported = 1;
6393 SCTP_INP_WUNLOCK(inp);
6395 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6401 case SCTP_AUTH_SUPPORTED:
6403 struct sctp_assoc_value *av;
6405 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6406 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6409 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6411 SCTP_TCB_UNLOCK(stcb);
6413 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6414 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6415 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6416 if ((av->assoc_value == 0) &&
6417 (inp->asconf_supported == 1)) {
6419 * AUTH is required for
6422 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6425 SCTP_INP_WLOCK(inp);
6426 if (av->assoc_value == 0) {
6427 inp->auth_supported = 0;
6429 inp->auth_supported = 1;
6431 SCTP_INP_WUNLOCK(inp);
6434 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6440 case SCTP_ASCONF_SUPPORTED:
6442 struct sctp_assoc_value *av;
6444 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6445 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6448 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6450 SCTP_TCB_UNLOCK(stcb);
6452 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6453 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6454 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6455 if ((av->assoc_value != 0) &&
6456 (inp->auth_supported == 0)) {
6458 * AUTH is required for
6461 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6464 SCTP_INP_WLOCK(inp);
6465 if (av->assoc_value == 0) {
6466 inp->asconf_supported = 0;
6467 sctp_auth_delete_chunk(SCTP_ASCONF,
6468 inp->sctp_ep.local_auth_chunks);
6469 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6470 inp->sctp_ep.local_auth_chunks);
6472 inp->asconf_supported = 1;
6473 sctp_auth_add_chunk(SCTP_ASCONF,
6474 inp->sctp_ep.local_auth_chunks);
6475 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6476 inp->sctp_ep.local_auth_chunks);
6478 SCTP_INP_WUNLOCK(inp);
6481 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6487 case SCTP_RECONFIG_SUPPORTED:
6489 struct sctp_assoc_value *av;
6491 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6492 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6495 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6497 SCTP_TCB_UNLOCK(stcb);
6499 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6500 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6501 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6502 SCTP_INP_WLOCK(inp);
6503 if (av->assoc_value == 0) {
6504 inp->reconfig_supported = 0;
6506 inp->reconfig_supported = 1;
6508 SCTP_INP_WUNLOCK(inp);
6510 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6516 case SCTP_NRSACK_SUPPORTED:
6518 struct sctp_assoc_value *av;
6520 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6521 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6524 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6526 SCTP_TCB_UNLOCK(stcb);
6528 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6529 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6530 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6531 SCTP_INP_WLOCK(inp);
6532 if (av->assoc_value == 0) {
6533 inp->nrsack_supported = 0;
6535 inp->nrsack_supported = 1;
6537 SCTP_INP_WUNLOCK(inp);
6539 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6545 case SCTP_PKTDROP_SUPPORTED:
6547 struct sctp_assoc_value *av;
6549 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6550 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6553 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6555 SCTP_TCB_UNLOCK(stcb);
6557 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6558 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6559 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6560 SCTP_INP_WLOCK(inp);
6561 if (av->assoc_value == 0) {
6562 inp->pktdrop_supported = 0;
6564 inp->pktdrop_supported = 1;
6566 SCTP_INP_WUNLOCK(inp);
6568 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6575 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6576 error = ENOPROTOOPT;
6578 } /* end switch (opt) */
6583 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6585 void *optval = NULL;
6590 if (sopt->sopt_level != IPPROTO_SCTP) {
6591 /* wrong proto level... send back up to IP */
6593 if (INP_CHECK_SOCKAF(so, AF_INET6))
6594 error = ip6_ctloutput(so, sopt);
6596 #if defined(INET) && defined(INET6)
6600 error = ip_ctloutput(so, sopt);
6604 optsize = sopt->sopt_valsize;
6606 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6607 if (optval == NULL) {
6608 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6611 error = sooptcopyin(sopt, optval, optsize, optsize);
6613 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6617 p = (void *)sopt->sopt_td;
6618 if (sopt->sopt_dir == SOPT_SET) {
6619 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6620 } else if (sopt->sopt_dir == SOPT_GET) {
6621 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6623 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6626 if ((error == 0) && (optval != NULL)) {
6627 error = sooptcopyout(sopt, optval, optsize);
6628 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6629 } else if (optval != NULL) {
6630 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6638 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6641 int create_lock_on = 0;
6643 struct sctp_inpcb *inp;
6644 struct sctp_tcb *stcb = NULL;
6646 inp = (struct sctp_inpcb *)so->so_pcb;
6648 /* I made the same as TCP since we are not setup? */
6649 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6650 return (ECONNRESET);
6653 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6656 switch (addr->sa_family) {
6660 struct sockaddr_in6 *sin6p;
6662 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6663 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6666 sin6p = (struct sockaddr_in6 *)addr;
6667 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6668 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6677 struct sockaddr_in *sinp;
6679 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6680 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6683 sinp = (struct sockaddr_in *)addr;
6684 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6685 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6693 return (EAFNOSUPPORT);
6695 SCTP_INP_INCR_REF(inp);
6696 SCTP_ASOC_CREATE_LOCK(inp);
6700 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6701 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6702 /* Should I really unlock ? */
6703 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6708 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6709 (addr->sa_family == AF_INET6)) {
6710 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6715 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6716 SCTP_PCB_FLAGS_UNBOUND) {
6717 /* Bind a ephemeral port */
6718 error = sctp_inpcb_bind(so, NULL, NULL, p);
6723 /* Now do we connect? */
6724 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6725 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6726 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6730 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6731 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6732 /* We are already connected AND the TCP model */
6733 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6737 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6738 SCTP_INP_RLOCK(inp);
6739 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6740 SCTP_INP_RUNLOCK(inp);
6743 * We increment here since sctp_findassociation_ep_addr()
6744 * will do a decrement if it finds the stcb as long as the
6745 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6747 SCTP_INP_INCR_REF(inp);
6748 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6750 SCTP_INP_DECR_REF(inp);
6752 SCTP_TCB_UNLOCK(stcb);
6756 /* Already have or am bring up an association */
6757 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
6761 vrf_id = inp->def_vrf_id;
6762 /* We are GOOD to go */
6763 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
6765 /* Gak! no memory */
6768 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
6769 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
6770 /* Set the connected flag so we can queue data */
6773 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
6774 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
6776 /* initialize authentication parameters for the assoc */
6777 sctp_initialize_auth_params(inp, stcb);
6779 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
6780 SCTP_TCB_UNLOCK(stcb);
6782 if (create_lock_on) {
6783 SCTP_ASOC_CREATE_UNLOCK(inp);
6785 SCTP_INP_DECR_REF(inp);
6792 sctp_listen(struct socket *so, int backlog, struct thread *p)
6795 * Note this module depends on the protocol processing being called
6796 * AFTER any socket level flags and backlog are applied to the
6797 * socket. The traditional way that the socket flags are applied is
6798 * AFTER protocol processing. We have made a change to the
6799 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
6800 * place if the socket API for SCTP is to work properly.
6804 struct sctp_inpcb *inp;
6806 inp = (struct sctp_inpcb *)so->so_pcb;
6808 /* I made the same as TCP since we are not setup? */
6809 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6810 return (ECONNRESET);
6812 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
6813 /* See if we have a listener */
6814 struct sctp_inpcb *tinp;
6815 union sctp_sockstore store;
6817 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
6819 struct sctp_laddr *laddr;
6821 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6822 memcpy(&store, &laddr->ifa->address, sizeof(store));
6823 switch (store.sa.sa_family) {
6826 store.sin.sin_port = inp->sctp_lport;
6831 store.sin6.sin6_port = inp->sctp_lport;
6837 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
6838 if (tinp && (tinp != inp) &&
6839 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6840 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6841 (tinp->sctp_socket->so_qlimit)) {
6843 * we have a listener already and
6846 SCTP_INP_DECR_REF(tinp);
6847 return (EADDRINUSE);
6849 SCTP_INP_DECR_REF(tinp);
6853 /* Setup a local addr bound all */
6854 memset(&store, 0, sizeof(store));
6856 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
6857 store.sa.sa_family = AF_INET6;
6858 store.sa.sa_len = sizeof(struct sockaddr_in6);
6862 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
6863 store.sa.sa_family = AF_INET;
6864 store.sa.sa_len = sizeof(struct sockaddr_in);
6867 switch (store.sa.sa_family) {
6870 store.sin.sin_port = inp->sctp_lport;
6875 store.sin6.sin6_port = inp->sctp_lport;
6881 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
6882 if (tinp && (tinp != inp) &&
6883 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6884 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6885 (tinp->sctp_socket->so_qlimit)) {
6887 * we have a listener already and its not
6890 SCTP_INP_DECR_REF(tinp);
6891 return (EADDRINUSE);
6893 SCTP_INP_DECR_REF(inp);
6897 SCTP_INP_RLOCK(inp);
6898 #ifdef SCTP_LOCK_LOGGING
6899 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
6900 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
6904 error = solisten_proto_check(so);
6907 SCTP_INP_RUNLOCK(inp);
6910 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
6911 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
6913 * The unlucky case - We are in the tcp pool with this guy.
6914 * - Someone else is in the main inp slot. - We must move
6915 * this guy (the listener) to the main slot - We must then
6916 * move the guy that was listener to the TCP Pool.
6918 if (sctp_swap_inpcb_for_listen(inp)) {
6922 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6923 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6924 /* We are already connected AND the TCP model */
6926 SCTP_INP_RUNLOCK(inp);
6928 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6929 return (EADDRINUSE);
6931 SCTP_INP_RUNLOCK(inp);
6932 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
6933 /* We must do a bind. */
6935 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
6936 /* bind error, probably perm */
6941 /* It appears for 7.0 and on, we must always call this. */
6942 solisten_proto(so, backlog);
6943 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6944 /* remove the ACCEPTCONN flag for one-to-many sockets */
6945 so->so_options &= ~SO_ACCEPTCONN;
6948 /* turning off listen */
6949 so->so_options &= ~SO_ACCEPTCONN;
6955 static int sctp_defered_wakeup_cnt = 0;
6958 sctp_accept(struct socket *so, struct sockaddr **addr)
6960 struct sctp_tcb *stcb;
6961 struct sctp_inpcb *inp;
6962 union sctp_sockstore store;
6968 inp = (struct sctp_inpcb *)so->so_pcb;
6971 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6972 return (ECONNRESET);
6974 SCTP_INP_RLOCK(inp);
6975 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6976 SCTP_INP_RUNLOCK(inp);
6977 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
6978 return (EOPNOTSUPP);
6980 if (so->so_state & SS_ISDISCONNECTED) {
6981 SCTP_INP_RUNLOCK(inp);
6982 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
6983 return (ECONNABORTED);
6985 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6987 SCTP_INP_RUNLOCK(inp);
6988 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6989 return (ECONNRESET);
6991 SCTP_TCB_LOCK(stcb);
6992 SCTP_INP_RUNLOCK(inp);
6993 store = stcb->asoc.primary_destination->ro._l_addr;
6994 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
6995 SCTP_TCB_UNLOCK(stcb);
6996 switch (store.sa.sa_family) {
7000 struct sockaddr_in *sin;
7002 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7005 sin->sin_family = AF_INET;
7006 sin->sin_len = sizeof(*sin);
7007 sin->sin_port = store.sin.sin_port;
7008 sin->sin_addr = store.sin.sin_addr;
7009 *addr = (struct sockaddr *)sin;
7016 struct sockaddr_in6 *sin6;
7018 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7021 sin6->sin6_family = AF_INET6;
7022 sin6->sin6_len = sizeof(*sin6);
7023 sin6->sin6_port = store.sin6.sin6_port;
7024 sin6->sin6_addr = store.sin6.sin6_addr;
7025 if ((error = sa6_recoverscope(sin6)) != 0) {
7026 SCTP_FREE_SONAME(sin6);
7029 *addr = (struct sockaddr *)sin6;
7037 /* Wake any delayed sleep action */
7038 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7039 SCTP_INP_WLOCK(inp);
7040 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7041 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7042 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7043 SCTP_INP_WUNLOCK(inp);
7044 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7045 if (sowriteable(inp->sctp_socket)) {
7046 sowwakeup_locked(inp->sctp_socket);
7048 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7050 SCTP_INP_WLOCK(inp);
7052 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7053 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7054 SCTP_INP_WUNLOCK(inp);
7055 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7056 if (soreadable(inp->sctp_socket)) {
7057 sctp_defered_wakeup_cnt++;
7058 sorwakeup_locked(inp->sctp_socket);
7060 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7062 SCTP_INP_WLOCK(inp);
7064 SCTP_INP_WUNLOCK(inp);
7066 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7067 SCTP_TCB_LOCK(stcb);
7068 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
7075 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7077 struct sockaddr_in *sin;
7079 struct sctp_inpcb *inp;
7080 struct sctp_ifa *sctp_ifa;
7083 * Do the malloc first in case it blocks.
7085 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7088 sin->sin_family = AF_INET;
7089 sin->sin_len = sizeof(*sin);
7090 inp = (struct sctp_inpcb *)so->so_pcb;
7092 SCTP_FREE_SONAME(sin);
7093 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7094 return (ECONNRESET);
7096 SCTP_INP_RLOCK(inp);
7097 sin->sin_port = inp->sctp_lport;
7098 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7099 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7100 struct sctp_tcb *stcb;
7101 struct sockaddr_in *sin_a;
7102 struct sctp_nets *net;
7105 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7111 SCTP_TCB_LOCK(stcb);
7112 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7113 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7115 /* this will make coverity happy */
7118 if (sin_a->sin_family == AF_INET) {
7123 if ((!fnd) || (sin_a == NULL)) {
7125 SCTP_TCB_UNLOCK(stcb);
7128 vrf_id = inp->def_vrf_id;
7129 sctp_ifa = sctp_source_address_selection(inp,
7131 (sctp_route_t *) & net->ro,
7134 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7135 sctp_free_ifa(sctp_ifa);
7137 SCTP_TCB_UNLOCK(stcb);
7139 /* For the bound all case you get back 0 */
7141 sin->sin_addr.s_addr = 0;
7145 /* Take the first IPv4 address in the list */
7146 struct sctp_laddr *laddr;
7149 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7150 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7151 struct sockaddr_in *sin_a;
7153 sin_a = &laddr->ifa->address.sin;
7154 sin->sin_addr = sin_a->sin_addr;
7160 SCTP_FREE_SONAME(sin);
7161 SCTP_INP_RUNLOCK(inp);
7162 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7166 SCTP_INP_RUNLOCK(inp);
7167 (*addr) = (struct sockaddr *)sin;
7172 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7174 struct sockaddr_in *sin;
7176 struct sockaddr_in *sin_a;
7177 struct sctp_inpcb *inp;
7178 struct sctp_tcb *stcb;
7179 struct sctp_nets *net;
7181 /* Do the malloc first in case it blocks. */
7182 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7185 sin->sin_family = AF_INET;
7186 sin->sin_len = sizeof(*sin);
7188 inp = (struct sctp_inpcb *)so->so_pcb;
7189 if ((inp == NULL) ||
7190 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7191 /* UDP type and listeners will drop out here */
7192 SCTP_FREE_SONAME(sin);
7193 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7196 SCTP_INP_RLOCK(inp);
7197 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7199 SCTP_TCB_LOCK(stcb);
7201 SCTP_INP_RUNLOCK(inp);
7203 SCTP_FREE_SONAME(sin);
7204 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7205 return (ECONNRESET);
7208 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7209 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7210 if (sin_a->sin_family == AF_INET) {
7212 sin->sin_port = stcb->rport;
7213 sin->sin_addr = sin_a->sin_addr;
7217 SCTP_TCB_UNLOCK(stcb);
7219 /* No IPv4 address */
7220 SCTP_FREE_SONAME(sin);
7221 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7224 (*addr) = (struct sockaddr *)sin;
7228 struct pr_usrreqs sctp_usrreqs = {
7229 .pru_abort = sctp_abort,
7230 .pru_accept = sctp_accept,
7231 .pru_attach = sctp_attach,
7232 .pru_bind = sctp_bind,
7233 .pru_connect = sctp_connect,
7234 .pru_control = in_control,
7235 .pru_close = sctp_close,
7236 .pru_detach = sctp_close,
7237 .pru_sopoll = sopoll_generic,
7238 .pru_flush = sctp_flush,
7239 .pru_disconnect = sctp_disconnect,
7240 .pru_listen = sctp_listen,
7241 .pru_peeraddr = sctp_peeraddr,
7242 .pru_send = sctp_sendm,
7243 .pru_shutdown = sctp_shutdown,
7244 .pru_sockaddr = sctp_ingetaddr,
7245 .pru_sosend = sctp_sosend,
7246 .pru_soreceive = sctp_soreceive