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>
43 #include <netinet/sctp_sysctl.h>
44 #include <netinet/sctp_output.h>
45 #include <netinet/sctp_uio.h>
46 #include <netinet/sctp_asconf.h>
47 #include <netinet/sctputil.h>
48 #include <netinet/sctp_indata.h>
49 #include <netinet/sctp_timer.h>
50 #include <netinet/sctp_auth.h>
51 #include <netinet/sctp_bsd_addr.h>
52 #include <netinet/udp.h>
56 extern struct sctp_cc_functions sctp_cc_functions[];
57 extern struct sctp_ss_functions sctp_ss_functions[];
64 /* Initialize and modify the sysctled variables */
66 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
67 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
69 * Allow a user to take no more than 1/2 the number of clusters or
70 * the SB_MAX whichever is smaller for the send window.
72 sb_max_adj = (u_long)((u_quad_t) (SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
73 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
74 (((uint32_t) nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
76 * Now for the recv window, should we take the same amount? or
77 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
78 * now I will just copy.
80 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
81 SCTP_BASE_VAR(first_time) = 0;
82 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
84 #if defined(SCTP_PACKET_LOGGING)
85 SCTP_BASE_VAR(packet_log_writers) = 0;
86 SCTP_BASE_VAR(packet_log_end) = 0;
87 bzero(&SCTP_BASE_VAR(packet_log_buffer), SCTP_PACKET_LOG_SIZE);
100 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
102 struct sctp_tmit_chunk *chk;
105 /* Adjust that too */
106 stcb->asoc.smallest_mtu = nxtsz;
107 /* now off to subtract IP_DF flag if needed */
108 overhead = IP_HDR_SIZE;
109 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
110 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
112 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
113 if ((chk->send_size + overhead) > nxtsz) {
114 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
117 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
118 if ((chk->send_size + overhead) > nxtsz) {
120 * For this guy we also mark for immediate resend
121 * since we sent to big of chunk
123 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
124 if (chk->sent < SCTP_DATAGRAM_RESEND) {
125 sctp_flight_size_decrease(chk);
126 sctp_total_flight_decrease(stcb, chk);
128 if (chk->sent != SCTP_DATAGRAM_RESEND) {
129 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
131 chk->sent = SCTP_DATAGRAM_RESEND;
132 chk->rec.data.doing_fast_retransmit = 0;
133 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
134 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
135 chk->whoTo->flight_size,
137 (uintptr_t) chk->whoTo,
138 chk->rec.data.TSN_seq);
140 /* Clear any time so NO RTT is being done */
148 sctp_notify_mbuf(struct sctp_inpcb *inp,
149 struct sctp_tcb *stcb,
150 struct sctp_nets *net,
155 int totsz, tmr_stopped = 0;
159 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
160 (ip == NULL) || (sh == NULL)) {
162 SCTP_TCB_UNLOCK(stcb);
166 /* First job is to verify the vtag matches what I would send */
167 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
168 SCTP_TCB_UNLOCK(stcb);
171 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
173 if (icmph->icmp_type != ICMP_UNREACH) {
174 /* We only care about unreachable */
175 SCTP_TCB_UNLOCK(stcb);
178 if (icmph->icmp_code != ICMP_UNREACH_NEEDFRAG) {
179 /* not a unreachable message due to frag. */
180 SCTP_TCB_UNLOCK(stcb);
185 nxtsz = ntohs(icmph->icmp_nextmtu);
188 * old type router that does not tell us what the next size
189 * mtu is. Rats we will have to guess (in a educated fashion
192 nxtsz = sctp_get_prev_mtu(totsz);
194 /* Stop any PMTU timer */
195 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
197 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
198 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
200 /* Adjust destination size limit */
201 if (net->mtu > nxtsz) {
204 net->mtu -= sizeof(struct udphdr);
207 /* now what about the ep? */
208 if (stcb->asoc.smallest_mtu > nxtsz) {
209 sctp_pathmtu_adjustment(stcb, nxtsz);
212 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
214 SCTP_TCB_UNLOCK(stcb);
220 sctp_notify(struct sctp_inpcb *inp,
224 struct sctp_tcb *stcb,
225 struct sctp_nets *net)
227 #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
234 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
235 (sh == NULL) || (to == NULL)) {
237 SCTP_TCB_UNLOCK(stcb);
240 /* First job is to verify the vtag matches what I would send */
241 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
242 SCTP_TCB_UNLOCK(stcb);
245 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
247 if (icmph->icmp_type != ICMP_UNREACH) {
248 /* We only care about unreachable */
249 SCTP_TCB_UNLOCK(stcb);
252 if ((icmph->icmp_code == ICMP_UNREACH_NET) ||
253 (icmph->icmp_code == ICMP_UNREACH_HOST) ||
254 (icmph->icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
255 (icmph->icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
256 (icmph->icmp_code == ICMP_UNREACH_ISOLATED) ||
257 (icmph->icmp_code == ICMP_UNREACH_NET_PROHIB) ||
258 (icmph->icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
259 (icmph->icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
262 * Hmm reachablity problems we must examine closely. If its
263 * not reachable, we may have lost a network. Or if there is
264 * NO protocol at the other end named SCTP. well we consider
267 if (net->dest_state & SCTP_ADDR_REACHABLE) {
268 /* Ok that destination is NOT reachable */
269 net->dest_state &= ~SCTP_ADDR_REACHABLE;
270 net->dest_state &= ~SCTP_ADDR_PF;
271 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
273 (void *)net, SCTP_SO_NOT_LOCKED);
275 SCTP_TCB_UNLOCK(stcb);
276 } else if ((icmph->icmp_code == ICMP_UNREACH_PROTOCOL) ||
277 (icmph->icmp_code == ICMP_UNREACH_PORT)) {
279 * Here the peer is either playing tricks on us, including
280 * an address that belongs to someone who does not support
281 * SCTP OR was a userland implementation that shutdown and
282 * now is dead. In either case treat it like a OOTB abort
285 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
286 #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
287 so = SCTP_INP_SO(inp);
288 atomic_add_int(&stcb->asoc.refcnt, 1);
289 SCTP_TCB_UNLOCK(stcb);
290 SCTP_SOCKET_LOCK(so, 1);
292 atomic_subtract_int(&stcb->asoc.refcnt, 1);
294 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
295 #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
296 SCTP_SOCKET_UNLOCK(so, 1);
297 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
299 /* no need to unlock here, since the TCB is gone */
301 SCTP_TCB_UNLOCK(stcb);
307 sctp_ctlinput(cmd, sa, vip)
316 /* FIX, for non-bsd is this right? */
317 vrf_id = SCTP_DEFAULT_VRFID;
318 if (sa->sa_family != AF_INET ||
319 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
322 if (PRC_IS_REDIRECT(cmd)) {
324 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
328 struct sctp_inpcb *inp = NULL;
329 struct sctp_tcb *stcb = NULL;
330 struct sctp_nets *net = NULL;
331 struct sockaddr_in to, from;
333 sh = (struct sctphdr *)((caddr_t)ip + (ip->ip_hl << 2));
334 bzero(&to, sizeof(to));
335 bzero(&from, sizeof(from));
336 from.sin_family = to.sin_family = AF_INET;
337 from.sin_len = to.sin_len = sizeof(to);
338 from.sin_port = sh->src_port;
339 from.sin_addr = ip->ip_src;
340 to.sin_port = sh->dest_port;
341 to.sin_addr = ip->ip_dst;
344 * 'to' holds the dest of the packet that failed to be sent.
345 * 'from' holds our local endpoint address. Thus we reverse
346 * the to and the from in the lookup.
348 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&from,
349 (struct sockaddr *)&to,
350 &inp, &net, 1, vrf_id);
351 if (stcb != NULL && inp && (inp->sctp_socket != NULL)) {
352 if (cmd != PRC_MSGSIZE) {
353 sctp_notify(inp, ip, sh,
354 (struct sockaddr *)&to, stcb,
357 /* handle possible ICMP size messages */
358 sctp_notify_mbuf(inp, stcb, net, ip, sh);
361 if ((stcb == NULL) && (inp != NULL)) {
362 /* reduce ref-count */
364 SCTP_INP_DECR_REF(inp);
365 SCTP_INP_WUNLOCK(inp);
368 SCTP_TCB_UNLOCK(stcb);
378 sctp_getcred(SYSCTL_HANDLER_ARGS)
381 struct sockaddr_in addrs[2];
382 struct sctp_inpcb *inp;
383 struct sctp_nets *net;
384 struct sctp_tcb *stcb;
388 /* FIX, for non-bsd is this right? */
389 vrf_id = SCTP_DEFAULT_VRFID;
391 error = priv_check(req->td, PRIV_NETINET_GETCRED);
396 error = SYSCTL_IN(req, addrs, sizeof(addrs));
400 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[0]),
402 &inp, &net, 1, vrf_id);
403 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
404 if ((inp != NULL) && (stcb == NULL)) {
405 /* reduce ref-count */
407 SCTP_INP_DECR_REF(inp);
410 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
414 SCTP_TCB_UNLOCK(stcb);
416 * We use the write lock here, only since in the error leg we need
417 * it. If we used RLOCK, then we would have to
418 * wlock/decr/unlock/rlock. Which in theory could create a hole.
419 * Better to use higher wlock.
423 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
425 SCTP_INP_WUNLOCK(inp);
428 cru2x(inp->sctp_socket->so_cred, &xuc);
429 SCTP_INP_WUNLOCK(inp);
430 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
435 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
436 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
441 sctp_abort(struct socket *so)
443 struct sctp_inpcb *inp;
446 inp = (struct sctp_inpcb *)so->so_pcb;
451 flags = inp->sctp_flags;
452 #ifdef SCTP_LOG_CLOSING
453 sctp_log_closing(inp, NULL, 17);
455 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
456 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
457 #ifdef SCTP_LOG_CLOSING
458 sctp_log_closing(inp, NULL, 16);
460 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
461 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
463 SCTP_SB_CLEAR(so->so_snd);
465 * same for the rcv ones, they are only here for the
468 SCTP_SB_CLEAR(so->so_rcv);
470 /* Now null out the reference, we are completely detached. */
474 flags = inp->sctp_flags;
475 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
476 goto sctp_must_try_again;
483 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
485 struct sctp_inpcb *inp;
486 struct inpcb *ip_inp;
488 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
495 inp = (struct sctp_inpcb *)so->so_pcb;
497 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
500 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
501 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
506 error = sctp_inpcb_alloc(so, vrf_id);
510 inp = (struct sctp_inpcb *)so->so_pcb;
512 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
513 ip_inp = &inp->ip_inp.inp;
514 ip_inp->inp_vflag |= INP_IPV4;
515 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
517 error = ipsec_init_policy(so, &ip_inp->inp_sp);
518 #ifdef SCTP_LOG_CLOSING
519 sctp_log_closing(inp, NULL, 17);
523 flags = inp->sctp_flags;
524 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
525 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
526 #ifdef SCTP_LOG_CLOSING
527 sctp_log_closing(inp, NULL, 15);
529 SCTP_INP_WUNLOCK(inp);
530 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
531 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
533 flags = inp->sctp_flags;
534 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
537 SCTP_INP_WUNLOCK(inp);
543 SCTP_INP_WUNLOCK(inp);
548 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
550 struct sctp_inpcb *inp = NULL;
554 if (addr && addr->sa_family != AF_INET) {
555 /* must be a v4 address! */
556 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
560 if (addr && (addr->sa_len != sizeof(struct sockaddr_in))) {
561 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
564 inp = (struct sctp_inpcb *)so->so_pcb;
566 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
569 error = sctp_inpcb_bind(so, addr, NULL, p);
575 sctp_close(struct socket *so)
577 struct sctp_inpcb *inp;
580 inp = (struct sctp_inpcb *)so->so_pcb;
585 * Inform all the lower layer assoc that we are done.
588 flags = inp->sctp_flags;
589 #ifdef SCTP_LOG_CLOSING
590 sctp_log_closing(inp, NULL, 17);
592 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
593 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
594 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
595 (so->so_rcv.sb_cc > 0)) {
596 #ifdef SCTP_LOG_CLOSING
597 sctp_log_closing(inp, NULL, 13);
599 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
600 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
602 #ifdef SCTP_LOG_CLOSING
603 sctp_log_closing(inp, NULL, 14);
605 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
606 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
609 * The socket is now detached, no matter what the state of
610 * the SCTP association.
613 SCTP_SB_CLEAR(so->so_snd);
615 * same for the rcv ones, they are only here for the
618 SCTP_SB_CLEAR(so->so_rcv);
620 /* Now null out the reference, we are completely detached. */
624 flags = inp->sctp_flags;
625 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
626 goto sctp_must_try_again;
634 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
635 struct mbuf *control, struct thread *p);
639 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
640 struct mbuf *control, struct thread *p)
642 struct sctp_inpcb *inp;
645 inp = (struct sctp_inpcb *)so->so_pcb;
648 sctp_m_freem(control);
651 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
655 /* Got to have an to address if we are NOT a connected socket */
656 if ((addr == NULL) &&
657 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
658 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
660 } else if (addr == NULL) {
661 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
662 error = EDESTADDRREQ;
665 sctp_m_freem(control);
671 if (addr->sa_family != AF_INET) {
672 /* must be a v4 address! */
673 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
676 sctp_m_freem(control);
679 error = EDESTADDRREQ;
684 /* now what about control */
687 SCTP_PRINTF("huh? control set?\n");
688 sctp_m_freem(inp->control);
691 inp->control = control;
695 SCTP_BUF_NEXT(inp->pkt_last) = m;
698 inp->pkt_last = inp->pkt = m;
701 /* FreeBSD uses a flag passed */
702 ((flags & PRUS_MORETOCOME) == 0)
705 * note with the current version this code will only be used
706 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
707 * re-defining sosend to use the sctp_sosend. One can
708 * optionally switch back to this code (by changing back the
709 * definitions) but this is not advisable. This code is used
710 * by FreeBSD when sending a file with sendfile() though.
714 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
724 sctp_disconnect(struct socket *so)
726 struct sctp_inpcb *inp;
728 inp = (struct sctp_inpcb *)so->so_pcb;
730 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
734 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
735 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
736 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
738 SCTP_INP_RUNLOCK(inp);
741 struct sctp_association *asoc;
742 struct sctp_tcb *stcb;
744 stcb = LIST_FIRST(&inp->sctp_asoc_list);
746 SCTP_INP_RUNLOCK(inp);
747 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
752 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
753 /* We are about to be freed, out of here */
754 SCTP_TCB_UNLOCK(stcb);
755 SCTP_INP_RUNLOCK(inp);
758 if (((so->so_options & SO_LINGER) &&
759 (so->so_linger == 0)) ||
760 (so->so_rcv.sb_cc > 0)) {
761 if (SCTP_GET_STATE(asoc) !=
762 SCTP_STATE_COOKIE_WAIT) {
763 /* Left with Data unread */
766 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_DONTWAIT, 1, MT_DATA);
772 struct sctp_paramhdr *ph;
774 ph = mtod(err, struct sctp_paramhdr *);
775 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
776 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
777 ph->param_length = htons(SCTP_BUF_LEN(err));
779 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
780 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
782 SCTP_INP_RUNLOCK(inp);
783 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
784 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
785 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
787 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
788 /* No unlock tcb assoc is gone */
791 if (TAILQ_EMPTY(&asoc->send_queue) &&
792 TAILQ_EMPTY(&asoc->sent_queue) &&
793 (asoc->stream_queue_cnt == 0)) {
794 /* there is nothing queued to send, so done */
795 if (asoc->locked_on_sending) {
798 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
799 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
800 /* only send SHUTDOWN 1st time thru */
801 struct sctp_nets *netp;
803 if (stcb->asoc.alternate) {
804 netp = stcb->asoc.alternate;
806 netp = stcb->asoc.primary_destination;
808 sctp_stop_timers_for_shutdown(stcb);
809 sctp_send_shutdown(stcb, netp);
810 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
811 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
812 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
813 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
815 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
816 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
817 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
818 stcb->sctp_ep, stcb, netp);
819 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
820 stcb->sctp_ep, stcb, netp);
825 * we still got (or just got) data to send,
826 * so set SHUTDOWN_PENDING
829 * XXX sockets draft says that SCTP_EOF
830 * should be sent with no data. currently,
831 * we will allow user data to be sent first
832 * and move to SHUTDOWN-PENDING
834 struct sctp_nets *netp;
836 if (stcb->asoc.alternate) {
837 netp = stcb->asoc.alternate;
839 netp = stcb->asoc.primary_destination;
842 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
843 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
845 if (asoc->locked_on_sending) {
846 /* Locked to send out the data */
847 struct sctp_stream_queue_pending *sp;
849 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
851 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
852 asoc->locked_on_sending->stream_no);
854 if ((sp->length == 0) && (sp->msg_is_complete == 0))
855 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
858 if (TAILQ_EMPTY(&asoc->send_queue) &&
859 TAILQ_EMPTY(&asoc->sent_queue) &&
860 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
864 op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
865 0, M_DONTWAIT, 1, MT_DATA);
871 struct sctp_paramhdr *ph;
874 SCTP_BUF_LEN(op_err) =
875 (sizeof(struct sctp_paramhdr) + sizeof(uint32_t));
877 struct sctp_paramhdr *);
878 ph->param_type = htons(
879 SCTP_CAUSE_USER_INITIATED_ABT);
880 ph->param_length = htons(SCTP_BUF_LEN(op_err));
881 ippp = (uint32_t *) (ph + 1);
882 *ippp = htonl(SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4);
884 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
885 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
886 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
887 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
888 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
889 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
891 SCTP_INP_RUNLOCK(inp);
892 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
895 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
898 soisdisconnecting(so);
899 SCTP_TCB_UNLOCK(stcb);
900 SCTP_INP_RUNLOCK(inp);
905 /* UDP model does not support this */
906 SCTP_INP_RUNLOCK(inp);
907 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
913 sctp_flush(struct socket *so, int how)
916 * We will just clear out the values and let subsequent close clear
917 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
918 * they will not be able to read the data, the socket will block
919 * that from happening.
921 struct sctp_inpcb *inp;
923 inp = (struct sctp_inpcb *)so->so_pcb;
925 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
929 /* For the 1 to many model this does nothing */
930 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
931 SCTP_INP_RUNLOCK(inp);
934 SCTP_INP_RUNLOCK(inp);
935 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
937 * First make sure the sb will be happy, we don't use these
938 * except maybe the count
941 SCTP_INP_READ_LOCK(inp);
942 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
943 SCTP_INP_READ_UNLOCK(inp);
944 SCTP_INP_WUNLOCK(inp);
945 so->so_rcv.sb_cc = 0;
946 so->so_rcv.sb_mbcnt = 0;
947 so->so_rcv.sb_mb = NULL;
949 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
951 * First make sure the sb will be happy, we don't use these
952 * except maybe the count
954 so->so_snd.sb_cc = 0;
955 so->so_snd.sb_mbcnt = 0;
956 so->so_snd.sb_mb = NULL;
963 sctp_shutdown(struct socket *so)
965 struct sctp_inpcb *inp;
967 inp = (struct sctp_inpcb *)so->so_pcb;
969 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
973 /* For UDP model this is a invalid call */
974 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
975 /* Restore the flags that the soshutdown took away. */
976 SOCKBUF_LOCK(&so->so_rcv);
977 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
978 SOCKBUF_UNLOCK(&so->so_rcv);
979 /* This proc will wakeup for read and do nothing (I hope) */
980 SCTP_INP_RUNLOCK(inp);
981 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
985 * Ok if we reach here its the TCP model and it is either a SHUT_WR
986 * or SHUT_RDWR. This means we put the shutdown flag against it.
989 struct sctp_tcb *stcb;
990 struct sctp_association *asoc;
993 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
994 SCTP_INP_RUNLOCK(inp);
999 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1002 * Ok we hit the case that the shutdown call was
1003 * made after an abort or something. Nothing to do
1006 SCTP_INP_RUNLOCK(inp);
1009 SCTP_TCB_LOCK(stcb);
1011 if (TAILQ_EMPTY(&asoc->send_queue) &&
1012 TAILQ_EMPTY(&asoc->sent_queue) &&
1013 (asoc->stream_queue_cnt == 0)) {
1014 if (asoc->locked_on_sending) {
1017 /* there is nothing queued to send, so I'm done... */
1018 if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) {
1019 /* only send SHUTDOWN the first time through */
1020 struct sctp_nets *netp;
1022 if (stcb->asoc.alternate) {
1023 netp = stcb->asoc.alternate;
1025 netp = stcb->asoc.primary_destination;
1027 sctp_stop_timers_for_shutdown(stcb);
1028 sctp_send_shutdown(stcb, netp);
1029 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
1030 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
1031 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
1032 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1034 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
1035 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
1036 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1037 stcb->sctp_ep, stcb, netp);
1038 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1039 stcb->sctp_ep, stcb, netp);
1043 * we still got (or just got) data to send, so set
1046 struct sctp_nets *netp;
1048 if (stcb->asoc.alternate) {
1049 netp = stcb->asoc.alternate;
1051 netp = stcb->asoc.primary_destination;
1054 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1055 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
1058 if (asoc->locked_on_sending) {
1059 /* Locked to send out the data */
1060 struct sctp_stream_queue_pending *sp;
1062 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
1064 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
1065 asoc->locked_on_sending->stream_no);
1067 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
1068 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
1072 if (TAILQ_EMPTY(&asoc->send_queue) &&
1073 TAILQ_EMPTY(&asoc->sent_queue) &&
1074 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1075 struct mbuf *op_err;
1078 op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
1079 0, M_DONTWAIT, 1, MT_DATA);
1081 /* Fill in the user initiated abort */
1082 struct sctp_paramhdr *ph;
1085 SCTP_BUF_LEN(op_err) =
1086 sizeof(struct sctp_paramhdr) + sizeof(uint32_t);
1088 struct sctp_paramhdr *);
1089 ph->param_type = htons(
1090 SCTP_CAUSE_USER_INITIATED_ABT);
1091 ph->param_length = htons(SCTP_BUF_LEN(op_err));
1092 ippp = (uint32_t *) (ph + 1);
1093 *ippp = htonl(SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1095 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
1096 sctp_abort_an_association(stcb->sctp_ep, stcb,
1097 op_err, SCTP_SO_LOCKED);
1100 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1103 SCTP_TCB_UNLOCK(stcb);
1106 SCTP_INP_RUNLOCK(inp);
1111 * copies a "user" presentable address and removes embedded scope, etc.
1112 * returns 0 on success, 1 on error
1115 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1118 struct sockaddr_in6 lsa6;
1120 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1123 memcpy(ss, sa, sa->sa_len);
1130 * NOTE: assumes addr lock is held
1133 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1134 struct sctp_tcb *stcb,
1136 struct sockaddr_storage *sas,
1139 struct sctp_ifn *sctp_ifn;
1140 struct sctp_ifa *sctp_ifa;
1141 int loopback_scope, ipv4_local_scope, local_scope, site_scope;
1143 int ipv4_addr_legal, ipv6_addr_legal;
1144 struct sctp_vrf *vrf;
1151 /* Turn on all the appropriate scope */
1152 loopback_scope = stcb->asoc.loopback_scope;
1153 ipv4_local_scope = stcb->asoc.ipv4_local_scope;
1154 local_scope = stcb->asoc.local_scope;
1155 site_scope = stcb->asoc.site_scope;
1157 /* Turn on ALL scope, since we look at the EP */
1158 loopback_scope = ipv4_local_scope = local_scope =
1161 ipv4_addr_legal = ipv6_addr_legal = 0;
1162 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1163 ipv6_addr_legal = 1;
1164 if (SCTP_IPV6_V6ONLY(inp) == 0) {
1165 ipv4_addr_legal = 1;
1168 ipv4_addr_legal = 1;
1170 vrf = sctp_find_vrf(vrf_id);
1174 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1175 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1176 if ((loopback_scope == 0) &&
1177 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1178 /* Skip loopback if loopback_scope not set */
1181 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1184 * For the BOUND-ALL case, the list
1185 * associated with a TCB is Always
1186 * considered a reverse list.. i.e.
1187 * it lists addresses that are NOT
1188 * part of the association. If this
1189 * is one of those we must skip it.
1191 if (sctp_is_addr_restricted(stcb,
1196 switch (sctp_ifa->address.sa.sa_family) {
1199 if (ipv4_addr_legal) {
1200 struct sockaddr_in *sin;
1202 sin = (struct sockaddr_in *)&sctp_ifa->address.sa;
1203 if (sin->sin_addr.s_addr == 0) {
1211 if ((ipv4_local_scope == 0) &&
1212 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1216 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1217 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1218 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1219 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1220 actual += sizeof(struct sockaddr_in6);
1223 memcpy(sas, sin, sizeof(*sin));
1224 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1225 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1226 actual += sizeof(*sin);
1230 if (actual >= limit) {
1240 if (ipv6_addr_legal) {
1241 struct sockaddr_in6 *sin6;
1243 sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sa;
1244 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1252 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1253 if (local_scope == 0)
1255 if (sin6->sin6_scope_id == 0) {
1256 if (sa6_recoverscope(sin6) != 0)
1274 if ((site_scope == 0) &&
1275 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1278 memcpy(sas, sin6, sizeof(*sin6));
1279 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1280 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1281 actual += sizeof(*sin6);
1282 if (actual >= limit) {
1297 struct sctp_laddr *laddr;
1299 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1301 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1305 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1308 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1309 sas = (struct sockaddr_storage *)((caddr_t)sas +
1310 laddr->ifa->address.sa.sa_len);
1311 actual += laddr->ifa->address.sa.sa_len;
1312 if (actual >= limit) {
1321 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1322 struct sctp_tcb *stcb,
1324 struct sockaddr_storage *sas)
1328 SCTP_IPI_ADDR_RLOCK();
1329 /* fill up addresses for the endpoint's default vrf */
1330 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1332 SCTP_IPI_ADDR_RUNLOCK();
1337 * NOTE: assumes addr lock is held
1340 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1343 struct sctp_vrf *vrf = NULL;
1346 * In both sub-set bound an bound_all cases we return the MAXIMUM
1347 * number of addresses that you COULD get. In reality the sub-set
1348 * bound may have an exclusion list for a given TCB OR in the
1349 * bound-all case a TCB may NOT include the loopback or other
1350 * addresses as well.
1352 vrf = sctp_find_vrf(vrf_id);
1356 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1357 struct sctp_ifn *sctp_ifn;
1358 struct sctp_ifa *sctp_ifa;
1360 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1361 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1362 /* Count them if they are the right type */
1363 switch (sctp_ifa->address.sa.sa_family) {
1366 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1367 cnt += sizeof(struct sockaddr_in6);
1369 cnt += sizeof(struct sockaddr_in);
1374 cnt += sizeof(struct sockaddr_in6);
1383 struct sctp_laddr *laddr;
1385 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1386 switch (laddr->ifa->address.sa.sa_family) {
1389 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1390 cnt += sizeof(struct sockaddr_in6);
1392 cnt += sizeof(struct sockaddr_in);
1397 cnt += sizeof(struct sockaddr_in6);
1409 sctp_count_max_addresses(struct sctp_inpcb *inp)
1413 SCTP_IPI_ADDR_RLOCK();
1414 /* count addresses for the endpoint's default VRF */
1415 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1416 SCTP_IPI_ADDR_RUNLOCK();
1421 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1422 size_t optsize, void *p, int delay)
1425 int creat_lock_on = 0;
1426 struct sctp_tcb *stcb = NULL;
1427 struct sockaddr *sa;
1428 int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1430 int bad_addresses = 0;
1433 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1435 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1436 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1437 /* We are already connected AND the TCP model */
1438 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1439 return (EADDRINUSE);
1441 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1442 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1443 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1446 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1447 SCTP_INP_RLOCK(inp);
1448 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1449 SCTP_INP_RUNLOCK(inp);
1452 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1455 SCTP_INP_INCR_REF(inp);
1456 SCTP_ASOC_CREATE_LOCK(inp);
1458 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1459 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1460 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1464 totaddrp = (int *)optval;
1465 totaddr = *totaddrp;
1466 sa = (struct sockaddr *)(totaddrp + 1);
1467 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (optsize - sizeof(int)), &bad_addresses);
1468 if ((stcb != NULL) || bad_addresses) {
1469 /* Already have or am bring up an association */
1470 SCTP_ASOC_CREATE_UNLOCK(inp);
1473 SCTP_TCB_UNLOCK(stcb);
1474 if (bad_addresses == 0) {
1475 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1481 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1486 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1488 struct in6pcb *inp6;
1490 inp6 = (struct in6pcb *)inp;
1491 if (SCTP_IPV6_V6ONLY(inp6)) {
1493 * if IPV6_V6ONLY flag, ignore connections destined
1494 * to a v4 addr or v4-mapped addr
1496 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1502 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1503 SCTP_PCB_FLAGS_UNBOUND) {
1504 /* Bind a ephemeral port */
1505 error = sctp_inpcb_bind(so, NULL, NULL, p);
1510 /* FIX ME: do we want to pass in a vrf on the connect call? */
1511 vrf_id = inp->def_vrf_id;
1514 /* We are GOOD to go */
1515 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1519 /* Gak! no memory */
1522 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1523 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1524 /* Set the connected flag so we can queue data */
1527 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1528 /* move to second address */
1529 switch (sa->sa_family) {
1532 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1537 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1545 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1546 /* Fill in the return id */
1548 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1551 a_id = (sctp_assoc_t *) optval;
1552 *a_id = sctp_get_associd(stcb);
1554 /* initialize authentication parameters for the assoc */
1555 sctp_initialize_auth_params(inp, stcb);
1558 /* doing delayed connection */
1559 stcb->asoc.delayed_connection = 1;
1560 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1562 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1563 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1565 SCTP_TCB_UNLOCK(stcb);
1566 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1567 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1568 /* Set the connected flag so we can queue data */
1572 if (creat_lock_on) {
1573 SCTP_ASOC_CREATE_UNLOCK(inp);
1575 SCTP_INP_DECR_REF(inp);
1579 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1580 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1581 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1582 SCTP_INP_RLOCK(inp); \
1583 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1585 SCTP_TCB_LOCK(stcb); \
1587 SCTP_INP_RUNLOCK(inp); \
1588 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1589 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1590 if (stcb == NULL) { \
1591 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1601 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1602 if (size < sizeof(type)) { \
1603 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1607 destp = (type *)srcp; \
1612 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1615 struct sctp_inpcb *inp = NULL;
1617 struct sctp_tcb *stcb = NULL;
1619 if (optval == NULL) {
1620 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1623 inp = (struct sctp_inpcb *)so->so_pcb;
1625 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1632 case SCTP_AUTOCLOSE:
1633 case SCTP_EXPLICIT_EOR:
1634 case SCTP_AUTO_ASCONF:
1635 case SCTP_DISABLE_FRAGMENTS:
1636 case SCTP_I_WANT_MAPPED_V4_ADDR:
1637 case SCTP_USE_EXT_RCVINFO:
1638 SCTP_INP_RLOCK(inp);
1640 case SCTP_DISABLE_FRAGMENTS:
1641 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1643 case SCTP_I_WANT_MAPPED_V4_ADDR:
1644 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1646 case SCTP_AUTO_ASCONF:
1647 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1648 /* only valid for bound all sockets */
1649 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1651 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1656 case SCTP_EXPLICIT_EOR:
1657 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1660 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1662 case SCTP_USE_EXT_RCVINFO:
1663 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1665 case SCTP_AUTOCLOSE:
1666 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1667 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1673 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1674 error = ENOPROTOOPT;
1675 } /* end switch (sopt->sopt_name) */
1676 if (*optsize < sizeof(val)) {
1677 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1681 SCTP_INP_RUNLOCK(inp);
1683 /* return the option value */
1684 *(int *)optval = val;
1685 *optsize = sizeof(val);
1688 case SCTP_GET_PACKET_LOG:
1690 #ifdef SCTP_PACKET_LOGGING
1694 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1695 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1698 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1703 case SCTP_REUSE_PORT:
1707 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1708 /* Can't do this for a 1-m socket */
1712 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1713 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1714 *optsize = sizeof(uint32_t);
1717 case SCTP_PARTIAL_DELIVERY_POINT:
1721 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1722 *value = inp->partial_delivery_point;
1723 *optsize = sizeof(uint32_t);
1726 case SCTP_FRAGMENT_INTERLEAVE:
1730 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1731 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1732 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1733 *value = SCTP_FRAG_LEVEL_2;
1735 *value = SCTP_FRAG_LEVEL_1;
1738 *value = SCTP_FRAG_LEVEL_0;
1740 *optsize = sizeof(uint32_t);
1743 case SCTP_CMT_ON_OFF:
1745 struct sctp_assoc_value *av;
1747 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1748 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1750 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1751 SCTP_TCB_UNLOCK(stcb);
1753 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1754 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1755 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1756 SCTP_INP_RLOCK(inp);
1757 av->assoc_value = inp->sctp_cmt_on_off;
1758 SCTP_INP_RUNLOCK(inp);
1760 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1765 *optsize = sizeof(struct sctp_assoc_value);
1769 case SCTP_PLUGGABLE_CC:
1771 struct sctp_assoc_value *av;
1773 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1774 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1776 av->assoc_value = stcb->asoc.congestion_control_module;
1777 SCTP_TCB_UNLOCK(stcb);
1779 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1780 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1781 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1782 SCTP_INP_RLOCK(inp);
1783 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1784 SCTP_INP_RUNLOCK(inp);
1786 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1791 *optsize = sizeof(struct sctp_assoc_value);
1795 case SCTP_CC_OPTION:
1797 struct sctp_cc_option *cc_opt;
1799 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1800 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1804 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1807 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1808 *optsize = sizeof(struct sctp_cc_option);
1810 SCTP_TCB_UNLOCK(stcb);
1814 case SCTP_PLUGGABLE_SS:
1816 struct sctp_assoc_value *av;
1818 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1819 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1821 av->assoc_value = stcb->asoc.stream_scheduling_module;
1822 SCTP_TCB_UNLOCK(stcb);
1824 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1825 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1826 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1827 SCTP_INP_RLOCK(inp);
1828 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1829 SCTP_INP_RUNLOCK(inp);
1831 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1836 *optsize = sizeof(struct sctp_assoc_value);
1842 struct sctp_stream_value *av;
1844 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1845 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1847 if (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1848 &av->stream_value) < 0) {
1849 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1852 *optsize = sizeof(struct sctp_stream_value);
1854 SCTP_TCB_UNLOCK(stcb);
1857 * Can't get stream value without
1860 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1865 case SCTP_GET_ADDR_LEN:
1867 struct sctp_assoc_value *av;
1869 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1872 if (av->assoc_value == AF_INET) {
1873 av->assoc_value = sizeof(struct sockaddr_in);
1878 if (av->assoc_value == AF_INET6) {
1879 av->assoc_value = sizeof(struct sockaddr_in6);
1884 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1886 *optsize = sizeof(struct sctp_assoc_value);
1890 case SCTP_GET_ASSOC_NUMBER:
1892 uint32_t *value, cnt;
1894 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1896 SCTP_INP_RLOCK(inp);
1897 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1900 SCTP_INP_RUNLOCK(inp);
1902 *optsize = sizeof(uint32_t);
1905 case SCTP_GET_ASSOC_ID_LIST:
1907 struct sctp_assoc_ids *ids;
1908 unsigned int at, limit;
1910 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1912 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1913 SCTP_INP_RLOCK(inp);
1914 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1916 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1919 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1923 SCTP_INP_RUNLOCK(inp);
1925 ids->gaids_number_of_ids = at;
1926 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1932 struct sctp_assoc_value *av;
1934 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1935 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1938 av->assoc_value = stcb->asoc.context;
1939 SCTP_TCB_UNLOCK(stcb);
1941 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1942 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1943 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1944 SCTP_INP_RLOCK(inp);
1945 av->assoc_value = inp->sctp_context;
1946 SCTP_INP_RUNLOCK(inp);
1948 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1953 *optsize = sizeof(struct sctp_assoc_value);
1959 uint32_t *default_vrfid;
1961 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1962 *default_vrfid = inp->def_vrf_id;
1963 *optsize = sizeof(uint32_t);
1966 case SCTP_GET_ASOC_VRF:
1968 struct sctp_assoc_value *id;
1970 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1971 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1974 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1976 id->assoc_value = stcb->asoc.vrf_id;
1977 *optsize = sizeof(struct sctp_assoc_value);
1981 case SCTP_GET_VRF_IDS:
1983 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1987 case SCTP_GET_NONCE_VALUES:
1989 struct sctp_get_nonce_values *gnv;
1991 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1992 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1995 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1996 gnv->gn_local_tag = stcb->asoc.my_vtag;
1997 SCTP_TCB_UNLOCK(stcb);
1998 *optsize = sizeof(struct sctp_get_nonce_values);
2000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2005 case SCTP_DELAYED_SACK:
2007 struct sctp_sack_info *sack;
2009 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2010 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2012 sack->sack_delay = stcb->asoc.delayed_ack;
2013 sack->sack_freq = stcb->asoc.sack_freq;
2014 SCTP_TCB_UNLOCK(stcb);
2016 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2017 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2018 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2019 SCTP_INP_RLOCK(inp);
2020 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2021 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2022 SCTP_INP_RUNLOCK(inp);
2024 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2029 *optsize = sizeof(struct sctp_sack_info);
2033 case SCTP_GET_SNDBUF_USE:
2035 struct sctp_sockstat *ss;
2037 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2038 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2041 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2042 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2043 stcb->asoc.size_on_all_streams);
2044 SCTP_TCB_UNLOCK(stcb);
2045 *optsize = sizeof(struct sctp_sockstat);
2047 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2052 case SCTP_MAX_BURST:
2054 struct sctp_assoc_value *av;
2056 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2057 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2060 av->assoc_value = stcb->asoc.max_burst;
2061 SCTP_TCB_UNLOCK(stcb);
2063 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2064 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2065 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2066 SCTP_INP_RLOCK(inp);
2067 av->assoc_value = inp->sctp_ep.max_burst;
2068 SCTP_INP_RUNLOCK(inp);
2070 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2075 *optsize = sizeof(struct sctp_assoc_value);
2081 struct sctp_assoc_value *av;
2084 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2085 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2088 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2089 SCTP_TCB_UNLOCK(stcb);
2091 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2092 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2093 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2094 SCTP_INP_RLOCK(inp);
2095 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2096 ovh = SCTP_MED_OVERHEAD;
2098 ovh = SCTP_MED_V4_OVERHEAD;
2100 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2101 av->assoc_value = 0;
2103 av->assoc_value = inp->sctp_frag_point - ovh;
2104 SCTP_INP_RUNLOCK(inp);
2106 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2111 *optsize = sizeof(struct sctp_assoc_value);
2115 case SCTP_GET_STAT_LOG:
2116 error = sctp_fill_stat_log(optval, optsize);
2120 struct sctp_event_subscribe *events;
2122 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2123 memset(events, 0, sizeof(struct sctp_event_subscribe));
2124 SCTP_INP_RLOCK(inp);
2125 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2126 events->sctp_data_io_event = 1;
2128 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2129 events->sctp_association_event = 1;
2131 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2132 events->sctp_address_event = 1;
2134 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2135 events->sctp_send_failure_event = 1;
2137 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2138 events->sctp_peer_error_event = 1;
2140 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2141 events->sctp_shutdown_event = 1;
2143 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2144 events->sctp_partial_delivery_event = 1;
2146 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2147 events->sctp_adaptation_layer_event = 1;
2149 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2150 events->sctp_authentication_event = 1;
2152 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2153 events->sctp_sender_dry_event = 1;
2155 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2156 events->sctp_stream_reset_event = 1;
2157 SCTP_INP_RUNLOCK(inp);
2158 *optsize = sizeof(struct sctp_event_subscribe);
2161 case SCTP_ADAPTATION_LAYER:
2165 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2167 SCTP_INP_RLOCK(inp);
2168 *value = inp->sctp_ep.adaptation_layer_indicator;
2169 SCTP_INP_RUNLOCK(inp);
2170 *optsize = sizeof(uint32_t);
2173 case SCTP_SET_INITIAL_DBG_SEQ:
2177 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2178 SCTP_INP_RLOCK(inp);
2179 *value = inp->sctp_ep.initial_sequence_debug;
2180 SCTP_INP_RUNLOCK(inp);
2181 *optsize = sizeof(uint32_t);
2184 case SCTP_GET_LOCAL_ADDR_SIZE:
2188 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2189 SCTP_INP_RLOCK(inp);
2190 *value = sctp_count_max_addresses(inp);
2191 SCTP_INP_RUNLOCK(inp);
2192 *optsize = sizeof(uint32_t);
2195 case SCTP_GET_REMOTE_ADDR_SIZE:
2199 struct sctp_nets *net;
2201 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2202 /* FIXME MT: change to sctp_assoc_value? */
2203 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2207 /* Count the sizes */
2208 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2209 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2210 size += sizeof(struct sockaddr_in6);
2212 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2215 size += sizeof(struct sockaddr_in);
2220 size += sizeof(struct sockaddr_in6);
2228 SCTP_TCB_UNLOCK(stcb);
2229 *value = (uint32_t) size;
2230 *optsize = sizeof(uint32_t);
2232 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2237 case SCTP_GET_PEER_ADDRESSES:
2239 * Get the address information, an array is passed in to
2240 * fill up we pack it.
2244 struct sockaddr_storage *sas;
2245 struct sctp_nets *net;
2246 struct sctp_getaddresses *saddr;
2248 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2249 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2252 left = (*optsize) - sizeof(struct sctp_getaddresses);
2253 *optsize = sizeof(struct sctp_getaddresses);
2254 sas = (struct sockaddr_storage *)&saddr->addr[0];
2256 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2257 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2258 cpsz = sizeof(struct sockaddr_in6);
2260 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2263 cpsz = sizeof(struct sockaddr_in);
2268 cpsz = sizeof(struct sockaddr_in6);
2280 /* not enough room. */
2283 #if defined(INET) && defined(INET6)
2284 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2285 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
2286 /* Must map the address */
2287 in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
2288 (struct sockaddr_in6 *)sas);
2291 memcpy(sas, &net->ro._l_addr, cpsz);
2292 #if defined(INET) && defined(INET6)
2295 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2297 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2301 SCTP_TCB_UNLOCK(stcb);
2303 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2308 case SCTP_GET_LOCAL_ADDRESSES:
2310 size_t limit, actual;
2311 struct sockaddr_storage *sas;
2312 struct sctp_getaddresses *saddr;
2314 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2315 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2317 sas = (struct sockaddr_storage *)&saddr->addr[0];
2318 limit = *optsize - sizeof(sctp_assoc_t);
2319 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2321 SCTP_TCB_UNLOCK(stcb);
2323 *optsize = sizeof(struct sockaddr_storage) + actual;
2326 case SCTP_PEER_ADDR_PARAMS:
2328 struct sctp_paddrparams *paddrp;
2329 struct sctp_nets *net;
2331 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2332 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2336 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2339 * We increment here since
2340 * sctp_findassociation_ep_addr() wil do a
2341 * decrement if it finds the stcb as long as
2342 * the locked tcb (last argument) is NOT a
2345 SCTP_INP_INCR_REF(inp);
2346 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddrp->spp_address, &net, NULL, NULL);
2348 SCTP_INP_DECR_REF(inp);
2351 if (stcb && (net == NULL)) {
2352 struct sockaddr *sa;
2354 sa = (struct sockaddr *)&paddrp->spp_address;
2356 if (sa->sa_family == AF_INET) {
2357 struct sockaddr_in *sin;
2359 sin = (struct sockaddr_in *)sa;
2360 if (sin->sin_addr.s_addr) {
2362 SCTP_TCB_UNLOCK(stcb);
2363 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2369 if (sa->sa_family == AF_INET6) {
2370 struct sockaddr_in6 *sin6;
2372 sin6 = (struct sockaddr_in6 *)sa;
2373 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2375 SCTP_TCB_UNLOCK(stcb);
2376 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2382 error = EAFNOSUPPORT;
2383 SCTP_TCB_UNLOCK(stcb);
2384 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2389 /* Applies to the specific association */
2390 paddrp->spp_flags = 0;
2394 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2395 ovh = SCTP_MED_OVERHEAD;
2397 ovh = SCTP_MED_V4_OVERHEAD;
2400 paddrp->spp_hbinterval = net->heart_beat_delay;
2401 paddrp->spp_pathmaxrxt = net->failure_threshold;
2402 paddrp->spp_pathmtu = net->mtu - ovh;
2403 /* get flags for HB */
2404 if (net->dest_state & SCTP_ADDR_NOHB) {
2405 paddrp->spp_flags |= SPP_HB_DISABLE;
2407 paddrp->spp_flags |= SPP_HB_ENABLE;
2409 /* get flags for PMTU */
2410 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2411 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2413 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2415 if (net->dscp & 0x01) {
2416 paddrp->spp_dscp = net->dscp & 0xfc;
2417 paddrp->spp_flags |= SPP_DSCP;
2420 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2421 (net->flowlabel & 0x80000000)) {
2422 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2423 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2428 * No destination so return default
2431 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2432 paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
2433 if (stcb->asoc.default_dscp & 0x01) {
2434 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2435 paddrp->spp_flags |= SPP_DSCP;
2438 if (stcb->asoc.default_flowlabel & 0x80000000) {
2439 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2440 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2443 /* default settings should be these */
2444 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2445 paddrp->spp_flags |= SPP_HB_DISABLE;
2447 paddrp->spp_flags |= SPP_HB_ENABLE;
2449 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2450 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2452 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2454 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2456 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2457 SCTP_TCB_UNLOCK(stcb);
2459 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2460 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2461 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2462 /* Use endpoint defaults */
2463 SCTP_INP_RLOCK(inp);
2464 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2465 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2466 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2467 /* get inp's default */
2468 if (inp->sctp_ep.default_dscp & 0x01) {
2469 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2470 paddrp->spp_flags |= SPP_DSCP;
2473 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2474 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2475 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2476 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2479 /* can't return this */
2480 paddrp->spp_pathmtu = 0;
2482 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2483 paddrp->spp_flags |= SPP_HB_ENABLE;
2485 paddrp->spp_flags |= SPP_HB_DISABLE;
2487 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2488 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2490 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2492 SCTP_INP_RUNLOCK(inp);
2494 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2499 *optsize = sizeof(struct sctp_paddrparams);
2503 case SCTP_GET_PEER_ADDR_INFO:
2505 struct sctp_paddrinfo *paddri;
2506 struct sctp_nets *net;
2508 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2509 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2513 net = sctp_findnet(stcb, (struct sockaddr *)&paddri->spinfo_address);
2516 * We increment here since
2517 * sctp_findassociation_ep_addr() wil do a
2518 * decrement if it finds the stcb as long as
2519 * the locked tcb (last argument) is NOT a
2522 SCTP_INP_INCR_REF(inp);
2523 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddri->spinfo_address, &net, NULL, NULL);
2525 SCTP_INP_DECR_REF(inp);
2529 if ((stcb) && (net)) {
2530 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2531 /* It's unconfirmed */
2532 paddri->spinfo_state = SCTP_UNCONFIRMED;
2533 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2535 paddri->spinfo_state = SCTP_ACTIVE;
2538 paddri->spinfo_state = SCTP_INACTIVE;
2540 paddri->spinfo_cwnd = net->cwnd;
2541 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2542 paddri->spinfo_rto = net->RTO;
2543 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2544 paddri->spinfo_mtu = net->mtu;
2545 SCTP_TCB_UNLOCK(stcb);
2546 *optsize = sizeof(struct sctp_paddrinfo);
2549 SCTP_TCB_UNLOCK(stcb);
2551 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2556 case SCTP_PCB_STATUS:
2558 struct sctp_pcbinfo *spcb;
2560 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2561 sctp_fill_pcbinfo(spcb);
2562 *optsize = sizeof(struct sctp_pcbinfo);
2567 struct sctp_nets *net;
2568 struct sctp_status *sstat;
2570 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2571 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2574 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2579 * I think passing the state is fine since
2580 * sctp_constants.h will be available to the user
2583 sstat->sstat_state = stcb->asoc.state;
2584 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2585 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2586 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2588 * We can't include chunks that have been passed to
2589 * the socket layer. Only things in queue.
2591 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2592 stcb->asoc.cnt_on_all_streams);
2595 sstat->sstat_instrms = stcb->asoc.streamincnt;
2596 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2597 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2598 memcpy(&sstat->sstat_primary.spinfo_address,
2599 &stcb->asoc.primary_destination->ro._l_addr,
2600 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2601 net = stcb->asoc.primary_destination;
2602 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2604 * Again the user can get info from sctp_constants.h
2605 * for what the state of the network is.
2607 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2608 /* It's unconfirmed */
2609 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2610 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2612 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2615 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2617 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2618 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2619 sstat->sstat_primary.spinfo_rto = net->RTO;
2620 sstat->sstat_primary.spinfo_mtu = net->mtu;
2621 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2622 SCTP_TCB_UNLOCK(stcb);
2623 *optsize = sizeof(struct sctp_status);
2628 struct sctp_rtoinfo *srto;
2630 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2631 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2634 srto->srto_initial = stcb->asoc.initial_rto;
2635 srto->srto_max = stcb->asoc.maxrto;
2636 srto->srto_min = stcb->asoc.minrto;
2637 SCTP_TCB_UNLOCK(stcb);
2639 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2640 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2641 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2642 SCTP_INP_RLOCK(inp);
2643 srto->srto_initial = inp->sctp_ep.initial_rto;
2644 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2645 srto->srto_min = inp->sctp_ep.sctp_minrto;
2646 SCTP_INP_RUNLOCK(inp);
2648 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2653 *optsize = sizeof(struct sctp_rtoinfo);
2659 struct sctp_timeouts *stimo;
2661 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2662 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2665 stimo->stimo_init = stcb->asoc.timoinit;
2666 stimo->stimo_data = stcb->asoc.timodata;
2667 stimo->stimo_sack = stcb->asoc.timosack;
2668 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2669 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2670 stimo->stimo_cookie = stcb->asoc.timocookie;
2671 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2672 SCTP_TCB_UNLOCK(stcb);
2673 *optsize = sizeof(struct sctp_timeouts);
2675 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2680 case SCTP_ASSOCINFO:
2682 struct sctp_assocparams *sasoc;
2684 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2685 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2688 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2689 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2690 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2691 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2692 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2693 SCTP_TCB_UNLOCK(stcb);
2695 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2696 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2697 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2698 SCTP_INP_RLOCK(inp);
2699 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2700 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2701 sasoc->sasoc_number_peer_destinations = 0;
2702 sasoc->sasoc_peer_rwnd = 0;
2703 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2704 SCTP_INP_RUNLOCK(inp);
2706 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2711 *optsize = sizeof(struct sctp_assocparams);
2715 case SCTP_DEFAULT_SEND_PARAM:
2717 struct sctp_sndrcvinfo *s_info;
2719 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2720 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2723 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2724 SCTP_TCB_UNLOCK(stcb);
2726 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2727 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2728 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2729 SCTP_INP_RLOCK(inp);
2730 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2731 SCTP_INP_RUNLOCK(inp);
2733 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2738 *optsize = sizeof(struct sctp_sndrcvinfo);
2744 struct sctp_initmsg *sinit;
2746 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2747 SCTP_INP_RLOCK(inp);
2748 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2749 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2750 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2751 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2752 SCTP_INP_RUNLOCK(inp);
2753 *optsize = sizeof(struct sctp_initmsg);
2756 case SCTP_PRIMARY_ADDR:
2757 /* we allow a "get" operation on this */
2759 struct sctp_setprim *ssp;
2761 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2762 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2765 /* simply copy out the sockaddr_storage... */
2769 if (len > stcb->asoc.primary_destination->ro._l_addr.sa.sa_len)
2770 len = stcb->asoc.primary_destination->ro._l_addr.sa.sa_len;
2772 memcpy(&ssp->ssp_addr,
2773 &stcb->asoc.primary_destination->ro._l_addr,
2775 SCTP_TCB_UNLOCK(stcb);
2776 *optsize = sizeof(struct sctp_setprim);
2778 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2783 case SCTP_HMAC_IDENT:
2785 struct sctp_hmacalgo *shmac;
2786 sctp_hmaclist_t *hmaclist;
2790 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2792 SCTP_INP_RLOCK(inp);
2793 hmaclist = inp->sctp_ep.local_hmacs;
2794 if (hmaclist == NULL) {
2795 /* no HMACs to return */
2796 *optsize = sizeof(*shmac);
2797 SCTP_INP_RUNLOCK(inp);
2800 /* is there room for all of the hmac ids? */
2801 size = sizeof(*shmac) + (hmaclist->num_algo *
2802 sizeof(shmac->shmac_idents[0]));
2803 if ((size_t)(*optsize) < size) {
2804 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2806 SCTP_INP_RUNLOCK(inp);
2809 /* copy in the list */
2810 shmac->shmac_number_of_idents = hmaclist->num_algo;
2811 for (i = 0; i < hmaclist->num_algo; i++) {
2812 shmac->shmac_idents[i] = hmaclist->hmac[i];
2814 SCTP_INP_RUNLOCK(inp);
2818 case SCTP_AUTH_ACTIVE_KEY:
2820 struct sctp_authkeyid *scact;
2822 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2823 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2826 /* get the active key on the assoc */
2827 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2828 SCTP_TCB_UNLOCK(stcb);
2830 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2831 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2832 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2833 /* get the endpoint active key */
2834 SCTP_INP_RLOCK(inp);
2835 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2836 SCTP_INP_RUNLOCK(inp);
2838 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2843 *optsize = sizeof(struct sctp_authkeyid);
2847 case SCTP_LOCAL_AUTH_CHUNKS:
2849 struct sctp_authchunks *sac;
2850 sctp_auth_chklist_t *chklist = NULL;
2853 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2854 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2857 /* get off the assoc */
2858 chklist = stcb->asoc.local_auth_chunks;
2859 /* is there enough space? */
2860 size = sctp_auth_get_chklist_size(chklist);
2861 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2863 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2865 /* copy in the chunks */
2866 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2867 sac->gauth_number_of_chunks = (uint32_t) size;
2868 *optsize = sizeof(struct sctp_authchunks) + size;
2870 SCTP_TCB_UNLOCK(stcb);
2872 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2873 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2874 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2875 /* get off the endpoint */
2876 SCTP_INP_RLOCK(inp);
2877 chklist = inp->sctp_ep.local_auth_chunks;
2878 /* is there enough space? */
2879 size = sctp_auth_get_chklist_size(chklist);
2880 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2882 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2884 /* copy in the chunks */
2885 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2886 sac->gauth_number_of_chunks = (uint32_t) size;
2887 *optsize = sizeof(struct sctp_authchunks) + size;
2889 SCTP_INP_RUNLOCK(inp);
2891 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2897 case SCTP_PEER_AUTH_CHUNKS:
2899 struct sctp_authchunks *sac;
2900 sctp_auth_chklist_t *chklist = NULL;
2903 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2904 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2907 /* get off the assoc */
2908 chklist = stcb->asoc.peer_auth_chunks;
2909 /* is there enough space? */
2910 size = sctp_auth_get_chklist_size(chklist);
2911 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2915 /* copy in the chunks */
2916 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2917 sac->gauth_number_of_chunks = (uint32_t) size;
2918 *optsize = sizeof(struct sctp_authchunks) + size;
2920 SCTP_TCB_UNLOCK(stcb);
2922 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2929 struct sctp_event *event;
2930 uint32_t event_type;
2932 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2933 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
2935 switch (event->se_type) {
2936 case SCTP_ASSOC_CHANGE:
2937 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
2939 case SCTP_PEER_ADDR_CHANGE:
2940 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
2942 case SCTP_REMOTE_ERROR:
2943 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
2945 case SCTP_SEND_FAILED:
2946 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
2948 case SCTP_SHUTDOWN_EVENT:
2949 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
2951 case SCTP_ADAPTATION_INDICATION:
2952 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
2954 case SCTP_PARTIAL_DELIVERY_EVENT:
2955 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
2957 case SCTP_AUTHENTICATION_EVENT:
2958 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
2960 case SCTP_STREAM_RESET_EVENT:
2961 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
2963 case SCTP_SENDER_DRY_EVENT:
2964 event_type = SCTP_PCB_FLAGS_DRYEVNT;
2966 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
2968 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
2971 case SCTP_ASSOC_RESET_EVENT:
2972 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
2974 case SCTP_STREAM_CHANGE_EVENT:
2975 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
2977 case SCTP_SEND_FAILED_EVENT:
2978 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
2982 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2986 if (event_type > 0) {
2988 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
2989 SCTP_TCB_UNLOCK(stcb);
2991 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2992 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2993 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
2994 SCTP_INP_RLOCK(inp);
2995 event->se_on = sctp_is_feature_on(inp, event_type);
2996 SCTP_INP_RUNLOCK(inp);
2998 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3004 *optsize = sizeof(struct sctp_event);
3008 case SCTP_RECVRCVINFO:
3012 if (*optsize < sizeof(int)) {
3013 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3016 SCTP_INP_RLOCK(inp);
3017 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3018 SCTP_INP_RUNLOCK(inp);
3021 /* return the option value */
3022 *(int *)optval = onoff;
3023 *optsize = sizeof(int);
3027 case SCTP_RECVNXTINFO:
3031 if (*optsize < sizeof(int)) {
3032 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3035 SCTP_INP_RLOCK(inp);
3036 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3037 SCTP_INP_RUNLOCK(inp);
3040 /* return the option value */
3041 *(int *)optval = onoff;
3042 *optsize = sizeof(int);
3046 case SCTP_DEFAULT_SNDINFO:
3048 struct sctp_sndinfo *info;
3050 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3051 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3054 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3055 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3056 info->snd_flags &= 0xfff0;
3057 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3058 info->snd_context = stcb->asoc.def_send.sinfo_context;
3059 SCTP_TCB_UNLOCK(stcb);
3061 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3062 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3063 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3064 SCTP_INP_RLOCK(inp);
3065 info->snd_sid = inp->def_send.sinfo_stream;
3066 info->snd_flags = inp->def_send.sinfo_flags;
3067 info->snd_flags &= 0xfff0;
3068 info->snd_ppid = inp->def_send.sinfo_ppid;
3069 info->snd_context = inp->def_send.sinfo_context;
3070 SCTP_INP_RUNLOCK(inp);
3072 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3077 *optsize = sizeof(struct sctp_sndinfo);
3081 case SCTP_DEFAULT_PRINFO:
3083 struct sctp_default_prinfo *info;
3085 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3086 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3089 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3090 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3091 SCTP_TCB_UNLOCK(stcb);
3093 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3094 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3095 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3096 SCTP_INP_RLOCK(inp);
3097 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3098 info->pr_value = inp->def_send.sinfo_timetolive;
3099 SCTP_INP_RUNLOCK(inp);
3101 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3106 *optsize = sizeof(struct sctp_default_prinfo);
3110 case SCTP_PEER_ADDR_THLDS:
3112 struct sctp_paddrthlds *thlds;
3113 struct sctp_nets *net;
3115 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3116 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3120 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_address);
3123 * We increment here since
3124 * sctp_findassociation_ep_addr() wil do a
3125 * decrement if it finds the stcb as long as
3126 * the locked tcb (last argument) is NOT a
3129 SCTP_INP_INCR_REF(inp);
3130 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&thlds->spt_address, &net, NULL, NULL);
3132 SCTP_INP_DECR_REF(inp);
3135 if (stcb && (net == NULL)) {
3136 struct sockaddr *sa;
3138 sa = (struct sockaddr *)&thlds->spt_address;
3140 if (sa->sa_family == AF_INET) {
3141 struct sockaddr_in *sin;
3143 sin = (struct sockaddr_in *)sa;
3144 if (sin->sin_addr.s_addr) {
3146 SCTP_TCB_UNLOCK(stcb);
3147 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3153 if (sa->sa_family == AF_INET6) {
3154 struct sockaddr_in6 *sin6;
3156 sin6 = (struct sockaddr_in6 *)sa;
3157 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3159 SCTP_TCB_UNLOCK(stcb);
3160 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3166 error = EAFNOSUPPORT;
3167 SCTP_TCB_UNLOCK(stcb);
3168 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3174 thlds->spt_pathmaxrxt = net->failure_threshold;
3175 thlds->spt_pathpfthld = net->pf_threshold;
3177 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3178 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3180 thlds->spt_assoc_id = sctp_get_associd(stcb);
3181 SCTP_TCB_UNLOCK(stcb);
3183 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3184 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3185 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3186 /* Use endpoint defaults */
3187 SCTP_INP_RLOCK(inp);
3188 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3189 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3190 SCTP_INP_RUNLOCK(inp);
3192 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3197 *optsize = sizeof(struct sctp_paddrthlds);
3201 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3203 struct sctp_udpencaps *encaps;
3204 struct sctp_nets *net;
3206 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3207 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3210 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
3213 * We increment here since
3214 * sctp_findassociation_ep_addr() wil do a
3215 * decrement if it finds the stcb as long as
3216 * the locked tcb (last argument) is NOT a
3220 SCTP_INP_INCR_REF(inp);
3221 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
3223 SCTP_INP_DECR_REF(inp);
3226 if (stcb && (net == NULL)) {
3227 struct sockaddr *sa;
3229 sa = (struct sockaddr *)&encaps->sue_address;
3231 if (sa->sa_family == AF_INET) {
3232 struct sockaddr_in *sin;
3234 sin = (struct sockaddr_in *)sa;
3235 if (sin->sin_addr.s_addr) {
3237 SCTP_TCB_UNLOCK(stcb);
3238 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3244 if (sa->sa_family == AF_INET6) {
3245 struct sockaddr_in6 *sin6;
3247 sin6 = (struct sockaddr_in6 *)sa;
3248 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3250 SCTP_TCB_UNLOCK(stcb);
3251 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3257 error = EAFNOSUPPORT;
3258 SCTP_TCB_UNLOCK(stcb);
3259 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3265 encaps->sue_port = net->port;
3267 encaps->sue_port = stcb->asoc.port;
3269 SCTP_TCB_UNLOCK(stcb);
3271 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3272 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3273 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3274 SCTP_INP_RLOCK(inp);
3275 encaps->sue_port = inp->sctp_ep.port;
3276 SCTP_INP_RUNLOCK(inp);
3278 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3283 *optsize = sizeof(struct sctp_paddrparams);
3287 case SCTP_ENABLE_STREAM_RESET:
3289 struct sctp_assoc_value *av;
3291 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3292 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3295 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3296 SCTP_TCB_UNLOCK(stcb);
3298 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3299 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3300 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3301 SCTP_INP_RLOCK(inp);
3302 av->assoc_value = (uint32_t) inp->local_strreset_support;
3303 SCTP_INP_RUNLOCK(inp);
3305 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3310 *optsize = sizeof(struct sctp_assoc_value);
3315 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3316 error = ENOPROTOOPT;
3318 } /* end switch (sopt->sopt_name) */
3326 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3331 struct sctp_tcb *stcb = NULL;
3332 struct sctp_inpcb *inp = NULL;
3335 if (optval == NULL) {
3336 SCTP_PRINTF("optval is NULL\n");
3337 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3340 inp = (struct sctp_inpcb *)so->so_pcb;
3342 SCTP_PRINTF("inp is NULL?\n");
3343 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3346 vrf_id = inp->def_vrf_id;
3351 case SCTP_AUTOCLOSE:
3352 case SCTP_AUTO_ASCONF:
3353 case SCTP_EXPLICIT_EOR:
3354 case SCTP_DISABLE_FRAGMENTS:
3355 case SCTP_USE_EXT_RCVINFO:
3356 case SCTP_I_WANT_MAPPED_V4_ADDR:
3357 /* copy in the option value */
3358 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3363 case SCTP_DISABLE_FRAGMENTS:
3364 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3366 case SCTP_AUTO_ASCONF:
3368 * NOTE: we don't really support this flag
3370 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3371 /* only valid for bound all sockets */
3372 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3374 /* forbidden by admin */
3375 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3378 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3380 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3384 case SCTP_EXPLICIT_EOR:
3385 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3387 case SCTP_USE_EXT_RCVINFO:
3388 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3390 case SCTP_I_WANT_MAPPED_V4_ADDR:
3391 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3392 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3394 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3399 set_opt = SCTP_PCB_FLAGS_NODELAY;
3401 case SCTP_AUTOCLOSE:
3402 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3403 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3404 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3407 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3409 * The value is in ticks. Note this does not effect
3410 * old associations, only new ones.
3412 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3415 SCTP_INP_WLOCK(inp);
3417 sctp_feature_on(inp, set_opt);
3419 sctp_feature_off(inp, set_opt);
3421 SCTP_INP_WUNLOCK(inp);
3423 case SCTP_REUSE_PORT:
3425 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3426 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3427 /* Can't set it after we are bound */
3431 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3432 /* Can't do this for a 1-m socket */
3437 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3439 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3442 case SCTP_PARTIAL_DELIVERY_POINT:
3446 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3447 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3448 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3452 inp->partial_delivery_point = *value;
3455 case SCTP_FRAGMENT_INTERLEAVE:
3456 /* not yet until we re-write sctp_recvmsg() */
3460 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3461 if (*level == SCTP_FRAG_LEVEL_2) {
3462 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3463 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3464 } else if (*level == SCTP_FRAG_LEVEL_1) {
3465 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3466 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3467 } else if (*level == SCTP_FRAG_LEVEL_0) {
3468 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3469 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3472 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3477 case SCTP_CMT_ON_OFF:
3478 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3479 struct sctp_assoc_value *av;
3481 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3482 if (av->assoc_value > SCTP_CMT_MAX) {
3483 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3487 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3489 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3490 SCTP_TCB_UNLOCK(stcb);
3492 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3493 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3494 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3495 (av->assoc_id == SCTP_ALL_ASSOC)) {
3496 SCTP_INP_WLOCK(inp);
3497 inp->sctp_cmt_on_off = av->assoc_value;
3498 SCTP_INP_WUNLOCK(inp);
3500 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3501 (av->assoc_id == SCTP_ALL_ASSOC)) {
3502 SCTP_INP_RLOCK(inp);
3503 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3504 SCTP_TCB_LOCK(stcb);
3505 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3506 SCTP_TCB_UNLOCK(stcb);
3508 SCTP_INP_RUNLOCK(inp);
3512 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3513 error = ENOPROTOOPT;
3516 case SCTP_PLUGGABLE_CC:
3518 struct sctp_assoc_value *av;
3519 struct sctp_nets *net;
3521 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3522 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3523 (av->assoc_value != SCTP_CC_HSTCP) &&
3524 (av->assoc_value != SCTP_CC_HTCP) &&
3525 (av->assoc_value != SCTP_CC_RTCC)) {
3526 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3530 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3532 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3533 stcb->asoc.congestion_control_module = av->assoc_value;
3534 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3535 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3536 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3539 SCTP_TCB_UNLOCK(stcb);
3541 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3542 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3543 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3544 (av->assoc_id == SCTP_ALL_ASSOC)) {
3545 SCTP_INP_WLOCK(inp);
3546 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3547 SCTP_INP_WUNLOCK(inp);
3549 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3550 (av->assoc_id == SCTP_ALL_ASSOC)) {
3551 SCTP_INP_RLOCK(inp);
3552 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3553 SCTP_TCB_LOCK(stcb);
3554 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3555 stcb->asoc.congestion_control_module = av->assoc_value;
3556 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3557 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3558 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3561 SCTP_TCB_UNLOCK(stcb);
3563 SCTP_INP_RUNLOCK(inp);
3568 case SCTP_CC_OPTION:
3570 struct sctp_cc_option *cc_opt;
3572 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
3573 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
3575 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
3576 SCTP_INP_RLOCK(inp);
3577 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3578 SCTP_TCB_LOCK(stcb);
3579 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
3580 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
3582 SCTP_TCB_UNLOCK(stcb);
3584 SCTP_INP_RUNLOCK(inp);
3589 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
3592 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
3595 SCTP_TCB_UNLOCK(stcb);
3599 case SCTP_PLUGGABLE_SS:
3601 struct sctp_assoc_value *av;
3603 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3604 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
3605 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
3606 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
3607 (av->assoc_value != SCTP_SS_PRIORITY) &&
3608 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
3609 (av->assoc_value != SCTP_SS_FIRST_COME)) {
3610 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3614 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3616 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3617 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3618 stcb->asoc.stream_scheduling_module = av->assoc_value;
3619 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3620 SCTP_TCB_UNLOCK(stcb);
3622 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3623 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3624 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3625 (av->assoc_id == SCTP_ALL_ASSOC)) {
3626 SCTP_INP_WLOCK(inp);
3627 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
3628 SCTP_INP_WUNLOCK(inp);
3630 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3631 (av->assoc_id == SCTP_ALL_ASSOC)) {
3632 SCTP_INP_RLOCK(inp);
3633 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3634 SCTP_TCB_LOCK(stcb);
3635 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3636 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3637 stcb->asoc.stream_scheduling_module = av->assoc_value;
3638 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3639 SCTP_TCB_UNLOCK(stcb);
3641 SCTP_INP_RUNLOCK(inp);
3648 struct sctp_stream_value *av;
3650 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
3651 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3653 if (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
3654 av->stream_value) < 0) {
3655 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3658 SCTP_TCB_UNLOCK(stcb);
3660 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
3661 SCTP_INP_RLOCK(inp);
3662 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3663 SCTP_TCB_LOCK(stcb);
3664 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
3666 &stcb->asoc.strmout[av->stream_id],
3668 SCTP_TCB_UNLOCK(stcb);
3670 SCTP_INP_RUNLOCK(inp);
3674 * Can't set stream value without
3677 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3683 case SCTP_CLR_STAT_LOG:
3684 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3689 struct sctp_assoc_value *av;
3691 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3692 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3695 stcb->asoc.context = av->assoc_value;
3696 SCTP_TCB_UNLOCK(stcb);
3698 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3699 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3700 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3701 (av->assoc_id == SCTP_ALL_ASSOC)) {
3702 SCTP_INP_WLOCK(inp);
3703 inp->sctp_context = av->assoc_value;
3704 SCTP_INP_WUNLOCK(inp);
3706 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3707 (av->assoc_id == SCTP_ALL_ASSOC)) {
3708 SCTP_INP_RLOCK(inp);
3709 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3710 SCTP_TCB_LOCK(stcb);
3711 stcb->asoc.context = av->assoc_value;
3712 SCTP_TCB_UNLOCK(stcb);
3714 SCTP_INP_RUNLOCK(inp);
3721 uint32_t *default_vrfid;
3723 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
3724 if (*default_vrfid > SCTP_MAX_VRF_ID) {
3725 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3729 inp->def_vrf_id = *default_vrfid;
3732 case SCTP_DEL_VRF_ID:
3734 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3738 case SCTP_ADD_VRF_ID:
3740 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3744 case SCTP_DELAYED_SACK:
3746 struct sctp_sack_info *sack;
3748 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
3749 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
3750 if (sack->sack_delay) {
3751 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
3752 sack->sack_delay = SCTP_MAX_SACK_DELAY;
3753 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
3754 sack->sack_delay = TICKS_TO_MSEC(1);
3758 if (sack->sack_delay) {
3759 stcb->asoc.delayed_ack = sack->sack_delay;
3761 if (sack->sack_freq) {
3762 stcb->asoc.sack_freq = sack->sack_freq;
3764 SCTP_TCB_UNLOCK(stcb);
3766 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3767 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3768 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
3769 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3770 SCTP_INP_WLOCK(inp);
3771 if (sack->sack_delay) {
3772 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
3774 if (sack->sack_freq) {
3775 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
3777 SCTP_INP_WUNLOCK(inp);
3779 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
3780 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3781 SCTP_INP_RLOCK(inp);
3782 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3783 SCTP_TCB_LOCK(stcb);
3784 if (sack->sack_delay) {
3785 stcb->asoc.delayed_ack = sack->sack_delay;
3787 if (sack->sack_freq) {
3788 stcb->asoc.sack_freq = sack->sack_freq;
3790 SCTP_TCB_UNLOCK(stcb);
3792 SCTP_INP_RUNLOCK(inp);
3797 case SCTP_AUTH_CHUNK:
3799 struct sctp_authchunk *sauth;
3801 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
3803 SCTP_INP_WLOCK(inp);
3804 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
3805 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3808 SCTP_INP_WUNLOCK(inp);
3813 struct sctp_authkey *sca;
3814 struct sctp_keyhead *shared_keys;
3815 sctp_sharedkey_t *shared_key;
3816 sctp_key_t *key = NULL;
3819 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
3820 if (sca->sca_keylength == 0) {
3821 size = optsize - sizeof(struct sctp_authkey);
3823 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
3824 size = sca->sca_keylength;
3826 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3831 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
3834 shared_keys = &stcb->asoc.shared_keys;
3835 /* clear the cached keys for this key id */
3836 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3838 * create the new shared key and
3842 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3844 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3846 SCTP_TCB_UNLOCK(stcb);
3850 shared_key = sctp_alloc_sharedkey();
3851 if (shared_key == NULL) {
3853 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3855 SCTP_TCB_UNLOCK(stcb);
3858 shared_key->key = key;
3859 shared_key->keyid = sca->sca_keynumber;
3860 error = sctp_insert_sharedkey(shared_keys, shared_key);
3861 SCTP_TCB_UNLOCK(stcb);
3863 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3864 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3865 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
3866 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3867 SCTP_INP_WLOCK(inp);
3868 shared_keys = &inp->sctp_ep.shared_keys;
3870 * clear the cached keys on all
3871 * assocs for this key id
3873 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
3875 * create the new shared key and
3879 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3883 SCTP_INP_WUNLOCK(inp);
3887 shared_key = sctp_alloc_sharedkey();
3888 if (shared_key == NULL) {
3890 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3892 SCTP_INP_WUNLOCK(inp);
3895 shared_key->key = key;
3896 shared_key->keyid = sca->sca_keynumber;
3897 error = sctp_insert_sharedkey(shared_keys, shared_key);
3898 SCTP_INP_WUNLOCK(inp);
3900 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
3901 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3902 SCTP_INP_RLOCK(inp);
3903 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3904 SCTP_TCB_LOCK(stcb);
3905 shared_keys = &stcb->asoc.shared_keys;
3907 * clear the cached keys for
3910 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3912 * create the new shared key
3913 * and insert/replace it
3916 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3918 SCTP_TCB_UNLOCK(stcb);
3922 shared_key = sctp_alloc_sharedkey();
3923 if (shared_key == NULL) {
3925 SCTP_TCB_UNLOCK(stcb);
3928 shared_key->key = key;
3929 shared_key->keyid = sca->sca_keynumber;
3930 error = sctp_insert_sharedkey(shared_keys, shared_key);
3931 SCTP_TCB_UNLOCK(stcb);
3933 SCTP_INP_RUNLOCK(inp);
3938 case SCTP_HMAC_IDENT:
3940 struct sctp_hmacalgo *shmac;
3941 sctp_hmaclist_t *hmaclist;
3946 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
3947 if (optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) {
3948 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3952 hmaclist = sctp_alloc_hmaclist(shmac->shmac_number_of_idents);
3953 if (hmaclist == NULL) {
3954 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3958 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
3959 hmacid = shmac->shmac_idents[i];
3960 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
3961 /* invalid HMACs were found */ ;
3962 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3964 sctp_free_hmaclist(hmaclist);
3965 goto sctp_set_hmac_done;
3969 for (i = 0; i < hmaclist->num_algo; i++) {
3970 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
3971 /* already in list */
3976 sctp_free_hmaclist(hmaclist);
3977 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3981 /* set it on the endpoint */
3982 SCTP_INP_WLOCK(inp);
3983 if (inp->sctp_ep.local_hmacs)
3984 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
3985 inp->sctp_ep.local_hmacs = hmaclist;
3986 SCTP_INP_WUNLOCK(inp);
3990 case SCTP_AUTH_ACTIVE_KEY:
3992 struct sctp_authkeyid *scact;
3994 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
3995 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
3997 /* set the active key on the right place */
3999 /* set the active key on the assoc */
4000 if (sctp_auth_setactivekey(stcb,
4001 scact->scact_keynumber)) {
4002 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4003 SCTP_FROM_SCTP_USRREQ,
4007 SCTP_TCB_UNLOCK(stcb);
4009 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4010 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4011 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4012 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4013 SCTP_INP_WLOCK(inp);
4014 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4015 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4018 SCTP_INP_WUNLOCK(inp);
4020 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4021 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4022 SCTP_INP_RLOCK(inp);
4023 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4024 SCTP_TCB_LOCK(stcb);
4025 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4026 SCTP_TCB_UNLOCK(stcb);
4028 SCTP_INP_RUNLOCK(inp);
4033 case SCTP_AUTH_DELETE_KEY:
4035 struct sctp_authkeyid *scdel;
4037 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4038 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4040 /* delete the key from the right place */
4042 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4043 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4046 SCTP_TCB_UNLOCK(stcb);
4048 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4049 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4050 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4051 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4052 SCTP_INP_WLOCK(inp);
4053 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4054 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4057 SCTP_INP_WUNLOCK(inp);
4059 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4060 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4061 SCTP_INP_RLOCK(inp);
4062 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4063 SCTP_TCB_LOCK(stcb);
4064 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4065 SCTP_TCB_UNLOCK(stcb);
4067 SCTP_INP_RUNLOCK(inp);
4072 case SCTP_AUTH_DEACTIVATE_KEY:
4074 struct sctp_authkeyid *keyid;
4076 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4077 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4079 /* deactivate the key from the right place */
4081 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4082 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4085 SCTP_TCB_UNLOCK(stcb);
4087 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4088 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4089 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4090 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4091 SCTP_INP_WLOCK(inp);
4092 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4093 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4096 SCTP_INP_WUNLOCK(inp);
4098 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4099 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4100 SCTP_INP_RLOCK(inp);
4101 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4102 SCTP_TCB_LOCK(stcb);
4103 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4104 SCTP_TCB_UNLOCK(stcb);
4106 SCTP_INP_RUNLOCK(inp);
4111 case SCTP_ENABLE_STREAM_RESET:
4113 struct sctp_assoc_value *av;
4115 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4116 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4117 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4121 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4123 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4124 SCTP_TCB_UNLOCK(stcb);
4126 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4127 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4128 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4129 (av->assoc_id == SCTP_ALL_ASSOC)) {
4130 SCTP_INP_WLOCK(inp);
4131 inp->local_strreset_support = (uint8_t) av->assoc_value;
4132 SCTP_INP_WUNLOCK(inp);
4134 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4135 (av->assoc_id == SCTP_ALL_ASSOC)) {
4136 SCTP_INP_RLOCK(inp);
4137 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4138 SCTP_TCB_LOCK(stcb);
4139 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4140 SCTP_TCB_UNLOCK(stcb);
4142 SCTP_INP_RUNLOCK(inp);
4147 case SCTP_RESET_STREAMS:
4149 struct sctp_reset_streams *strrst;
4150 int i, send_out = 0;
4153 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4154 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4156 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4160 if (stcb->asoc.peer_supports_strreset == 0) {
4162 * Peer does not support the chunk type.
4164 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4166 SCTP_TCB_UNLOCK(stcb);
4169 if (stcb->asoc.stream_reset_outstanding) {
4170 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4172 SCTP_TCB_UNLOCK(stcb);
4175 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4178 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4181 if ((send_in == 0) && (send_out == 0)) {
4182 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4184 SCTP_TCB_UNLOCK(stcb);
4187 for (i = 0; i < strrst->srs_number_streams; i++) {
4189 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4190 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4195 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4196 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4202 SCTP_TCB_UNLOCK(stcb);
4205 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4206 strrst->srs_stream_list,
4207 send_out, send_in, 0, 0, 0, 0, 0);
4209 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4210 SCTP_TCB_UNLOCK(stcb);
4213 case SCTP_ADD_STREAMS:
4215 struct sctp_add_streams *stradd;
4216 uint8_t addstream = 0;
4217 uint16_t add_o_strmcnt = 0;
4218 uint16_t add_i_strmcnt = 0;
4220 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4221 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4223 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4227 if (stcb->asoc.peer_supports_strreset == 0) {
4229 * Peer does not support the chunk type.
4231 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4233 SCTP_TCB_UNLOCK(stcb);
4236 if (stcb->asoc.stream_reset_outstanding) {
4237 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4239 SCTP_TCB_UNLOCK(stcb);
4242 if ((stradd->sas_outstrms == 0) &&
4243 (stradd->sas_instrms == 0)) {
4247 if (stradd->sas_outstrms) {
4249 /* We allocate here */
4250 add_o_strmcnt = stradd->sas_outstrms;
4251 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4252 /* You can't have more than 64k */
4257 if (stradd->sas_instrms) {
4262 * We allocate inside
4263 * sctp_send_str_reset_req()
4265 add_i_strmcnt = stradd->sas_instrms;
4266 cnt = add_i_strmcnt;
4267 cnt += stcb->asoc.streamincnt;
4268 if (cnt > 0x0000ffff) {
4269 /* You can't have more than 64k */
4273 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4274 /* More than you are allowed */
4279 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4280 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4282 SCTP_TCB_UNLOCK(stcb);
4285 case SCTP_RESET_ASSOC:
4289 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4290 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4292 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4296 if (stcb->asoc.peer_supports_strreset == 0) {
4298 * Peer does not support the chunk type.
4300 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4302 SCTP_TCB_UNLOCK(stcb);
4305 if (stcb->asoc.stream_reset_outstanding) {
4306 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4308 SCTP_TCB_UNLOCK(stcb);
4311 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 1, 0, 0, 0, 0);
4312 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4313 SCTP_TCB_UNLOCK(stcb);
4316 case SCTP_CONNECT_X:
4317 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4318 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4322 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4324 case SCTP_CONNECT_X_DELAYED:
4325 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4326 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4330 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4332 case SCTP_CONNECT_X_COMPLETE:
4334 struct sockaddr *sa;
4335 struct sctp_nets *net;
4337 /* FIXME MT: check correct? */
4338 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4341 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4342 SCTP_INP_RLOCK(inp);
4343 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4345 SCTP_TCB_LOCK(stcb);
4346 net = sctp_findnet(stcb, sa);
4348 SCTP_INP_RUNLOCK(inp);
4351 * We increment here since
4352 * sctp_findassociation_ep_addr() wil do a
4353 * decrement if it finds the stcb as long as
4354 * the locked tcb (last argument) is NOT a
4357 SCTP_INP_INCR_REF(inp);
4358 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
4360 SCTP_INP_DECR_REF(inp);
4365 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4369 if (stcb->asoc.delayed_connection == 1) {
4370 stcb->asoc.delayed_connection = 0;
4371 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4372 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4373 stcb->asoc.primary_destination,
4374 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
4375 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4378 * already expired or did not use delayed
4381 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4384 SCTP_TCB_UNLOCK(stcb);
4387 case SCTP_MAX_BURST:
4389 struct sctp_assoc_value *av;
4391 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4392 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4395 stcb->asoc.max_burst = av->assoc_value;
4396 SCTP_TCB_UNLOCK(stcb);
4398 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4399 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4400 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4401 (av->assoc_id == SCTP_ALL_ASSOC)) {
4402 SCTP_INP_WLOCK(inp);
4403 inp->sctp_ep.max_burst = av->assoc_value;
4404 SCTP_INP_WUNLOCK(inp);
4406 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4407 (av->assoc_id == SCTP_ALL_ASSOC)) {
4408 SCTP_INP_RLOCK(inp);
4409 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4410 SCTP_TCB_LOCK(stcb);
4411 stcb->asoc.max_burst = av->assoc_value;
4412 SCTP_TCB_UNLOCK(stcb);
4414 SCTP_INP_RUNLOCK(inp);
4421 struct sctp_assoc_value *av;
4424 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4425 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4427 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4428 ovh = SCTP_MED_OVERHEAD;
4430 ovh = SCTP_MED_V4_OVERHEAD;
4433 if (av->assoc_value) {
4434 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4436 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4438 SCTP_TCB_UNLOCK(stcb);
4440 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4441 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4442 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4443 SCTP_INP_WLOCK(inp);
4445 * FIXME MT: I think this is not in
4446 * tune with the API ID
4448 if (av->assoc_value) {
4449 inp->sctp_frag_point = (av->assoc_value + ovh);
4451 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4453 SCTP_INP_WUNLOCK(inp);
4455 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4463 struct sctp_event_subscribe *events;
4465 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4467 SCTP_INP_WLOCK(inp);
4468 if (events->sctp_data_io_event) {
4469 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4471 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4474 if (events->sctp_association_event) {
4475 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4477 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4480 if (events->sctp_address_event) {
4481 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4483 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4486 if (events->sctp_send_failure_event) {
4487 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4489 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4492 if (events->sctp_peer_error_event) {
4493 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4495 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4498 if (events->sctp_shutdown_event) {
4499 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4501 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4504 if (events->sctp_partial_delivery_event) {
4505 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4507 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4510 if (events->sctp_adaptation_layer_event) {
4511 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4513 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4516 if (events->sctp_authentication_event) {
4517 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4519 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4522 if (events->sctp_sender_dry_event) {
4523 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
4525 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
4528 if (events->sctp_stream_reset_event) {
4529 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4531 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4533 SCTP_INP_WUNLOCK(inp);
4535 SCTP_INP_RLOCK(inp);
4536 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4537 SCTP_TCB_LOCK(stcb);
4538 if (events->sctp_association_event) {
4539 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4541 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4543 if (events->sctp_address_event) {
4544 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4546 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4548 if (events->sctp_send_failure_event) {
4549 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4551 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4553 if (events->sctp_peer_error_event) {
4554 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4556 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4558 if (events->sctp_shutdown_event) {
4559 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4561 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4563 if (events->sctp_partial_delivery_event) {
4564 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4566 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4568 if (events->sctp_adaptation_layer_event) {
4569 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4571 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4573 if (events->sctp_authentication_event) {
4574 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4576 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4578 if (events->sctp_sender_dry_event) {
4579 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4581 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4583 if (events->sctp_stream_reset_event) {
4584 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4586 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4588 SCTP_TCB_UNLOCK(stcb);
4591 * Send up the sender dry event only for 1-to-1
4594 if (events->sctp_sender_dry_event) {
4595 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4596 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
4597 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4599 SCTP_TCB_LOCK(stcb);
4600 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
4601 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
4602 (stcb->asoc.stream_queue_cnt == 0)) {
4603 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
4605 SCTP_TCB_UNLOCK(stcb);
4609 SCTP_INP_RUNLOCK(inp);
4612 case SCTP_ADAPTATION_LAYER:
4614 struct sctp_setadaptation *adap_bits;
4616 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
4617 SCTP_INP_WLOCK(inp);
4618 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
4619 SCTP_INP_WUNLOCK(inp);
4623 case SCTP_SET_INITIAL_DBG_SEQ:
4627 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
4628 SCTP_INP_WLOCK(inp);
4629 inp->sctp_ep.initial_sequence_debug = *vvv;
4630 SCTP_INP_WUNLOCK(inp);
4634 case SCTP_DEFAULT_SEND_PARAM:
4636 struct sctp_sndrcvinfo *s_info;
4638 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
4639 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
4642 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4643 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4645 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4648 SCTP_TCB_UNLOCK(stcb);
4650 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4651 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4652 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
4653 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4654 SCTP_INP_WLOCK(inp);
4655 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
4656 SCTP_INP_WUNLOCK(inp);
4658 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
4659 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4660 SCTP_INP_RLOCK(inp);
4661 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4662 SCTP_TCB_LOCK(stcb);
4663 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4664 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4666 SCTP_TCB_UNLOCK(stcb);
4668 SCTP_INP_RUNLOCK(inp);
4673 case SCTP_PEER_ADDR_PARAMS:
4675 struct sctp_paddrparams *paddrp;
4676 struct sctp_nets *net;
4678 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
4679 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
4682 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
4685 * We increment here since
4686 * sctp_findassociation_ep_addr() wil do a
4687 * decrement if it finds the stcb as long as
4688 * the locked tcb (last argument) is NOT a
4691 SCTP_INP_INCR_REF(inp);
4692 stcb = sctp_findassociation_ep_addr(&inp,
4693 (struct sockaddr *)&paddrp->spp_address,
4696 SCTP_INP_DECR_REF(inp);
4699 if (stcb && (net == NULL)) {
4700 struct sockaddr *sa;
4702 sa = (struct sockaddr *)&paddrp->spp_address;
4704 if (sa->sa_family == AF_INET) {
4706 struct sockaddr_in *sin;
4708 sin = (struct sockaddr_in *)sa;
4709 if (sin->sin_addr.s_addr) {
4710 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4711 SCTP_TCB_UNLOCK(stcb);
4718 if (sa->sa_family == AF_INET6) {
4719 struct sockaddr_in6 *sin6;
4721 sin6 = (struct sockaddr_in6 *)sa;
4722 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
4723 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4724 SCTP_TCB_UNLOCK(stcb);
4731 error = EAFNOSUPPORT;
4732 SCTP_TCB_UNLOCK(stcb);
4733 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4738 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
4740 SCTP_TCB_UNLOCK(stcb);
4741 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4744 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
4746 SCTP_TCB_UNLOCK(stcb);
4747 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4751 /************************TCB SPECIFIC SET ******************/
4753 * do we change the timer for HB, we run
4758 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4759 ovh = SCTP_MED_OVERHEAD;
4761 ovh = SCTP_MED_V4_OVERHEAD;
4764 /* network sets ? */
4766 /************************NET SPECIFIC SET ******************/
4767 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4768 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
4769 !(net->dest_state & SCTP_ADDR_NOHB)) {
4770 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4771 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4773 net->dest_state |= SCTP_ADDR_NOHB;
4775 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4776 if (paddrp->spp_hbinterval) {
4777 net->heart_beat_delay = paddrp->spp_hbinterval;
4778 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4779 net->heart_beat_delay = 0;
4781 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4782 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4783 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4784 net->dest_state &= ~SCTP_ADDR_NOHB;
4786 if (paddrp->spp_flags & SPP_HB_DEMAND) {
4788 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4789 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
4790 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4792 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4793 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4794 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4795 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4797 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4798 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4799 net->mtu = paddrp->spp_pathmtu + ovh;
4800 if (net->mtu < stcb->asoc.smallest_mtu) {
4801 sctp_pathmtu_adjustment(stcb, net->mtu);
4805 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4806 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4807 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4809 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4811 if (paddrp->spp_pathmaxrxt) {
4812 if (net->dest_state & SCTP_ADDR_PF) {
4813 if (net->error_count > paddrp->spp_pathmaxrxt) {
4814 net->dest_state &= ~SCTP_ADDR_PF;
4817 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4818 (net->error_count > net->pf_threshold)) {
4819 net->dest_state |= SCTP_ADDR_PF;
4820 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4821 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4822 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4825 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4826 if (net->error_count > paddrp->spp_pathmaxrxt) {
4827 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4828 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
4831 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4832 net->dest_state |= SCTP_ADDR_REACHABLE;
4833 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
4836 net->failure_threshold = paddrp->spp_pathmaxrxt;
4838 if (paddrp->spp_flags & SPP_DSCP) {
4839 net->dscp = paddrp->spp_dscp & 0xfc;
4843 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4844 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4845 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4846 net->flowlabel |= 0x80000000;
4851 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
4852 if (paddrp->spp_pathmaxrxt) {
4853 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
4854 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4855 if (net->dest_state & SCTP_ADDR_PF) {
4856 if (net->error_count > paddrp->spp_pathmaxrxt) {
4857 net->dest_state &= ~SCTP_ADDR_PF;
4860 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4861 (net->error_count > net->pf_threshold)) {
4862 net->dest_state |= SCTP_ADDR_PF;
4863 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4864 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4865 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4868 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4869 if (net->error_count > paddrp->spp_pathmaxrxt) {
4870 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4871 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
4874 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4875 net->dest_state |= SCTP_ADDR_REACHABLE;
4876 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
4879 net->failure_threshold = paddrp->spp_pathmaxrxt;
4882 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4883 if (paddrp->spp_hbinterval) {
4884 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
4885 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4886 stcb->asoc.heart_beat_delay = 0;
4888 /* Turn back on the timer */
4889 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4890 if (paddrp->spp_hbinterval) {
4891 net->heart_beat_delay = paddrp->spp_hbinterval;
4892 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4893 net->heart_beat_delay = 0;
4895 if (net->dest_state & SCTP_ADDR_NOHB) {
4896 net->dest_state &= ~SCTP_ADDR_NOHB;
4898 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4899 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4900 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4902 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4904 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4905 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4906 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
4907 net->dest_state |= SCTP_ADDR_NOHB;
4908 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
4909 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4913 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4915 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4916 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4917 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4918 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4919 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4921 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4922 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4923 net->mtu = paddrp->spp_pathmtu + ovh;
4924 if (net->mtu < stcb->asoc.smallest_mtu) {
4925 sctp_pathmtu_adjustment(stcb, net->mtu);
4929 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4931 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4932 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4933 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4934 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4936 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4938 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4940 if (paddrp->spp_flags & SPP_DSCP) {
4941 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4942 net->dscp = paddrp->spp_dscp & 0xfc;
4945 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
4946 stcb->asoc.default_dscp |= 0x01;
4949 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4950 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4951 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4952 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4953 net->flowlabel |= 0x80000000;
4956 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4957 stcb->asoc.default_flowlabel |= 0x80000000;
4961 SCTP_TCB_UNLOCK(stcb);
4963 /************************NO TCB, SET TO default stuff ******************/
4964 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4965 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4966 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
4967 SCTP_INP_WLOCK(inp);
4969 * For the TOS/FLOWLABEL stuff you
4970 * set it with the options on the
4973 if (paddrp->spp_pathmaxrxt) {
4974 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
4976 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
4977 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4978 else if (paddrp->spp_hbinterval) {
4979 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
4980 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
4981 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4983 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4984 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4985 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4986 } else if (paddrp->spp_hbinterval) {
4987 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4989 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4990 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
4991 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4993 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4994 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4995 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
4996 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4998 if (paddrp->spp_flags & SPP_DSCP) {
4999 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5000 inp->sctp_ep.default_dscp |= 0x01;
5003 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5004 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5005 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5006 inp->sctp_ep.default_flowlabel |= 0x80000000;
5010 SCTP_INP_WUNLOCK(inp);
5012 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5020 struct sctp_rtoinfo *srto;
5021 uint32_t new_init, new_min, new_max;
5023 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5024 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5027 if (srto->srto_initial)
5028 new_init = srto->srto_initial;
5030 new_init = stcb->asoc.initial_rto;
5032 new_max = srto->srto_max;
5034 new_max = stcb->asoc.maxrto;
5036 new_min = srto->srto_min;
5038 new_min = stcb->asoc.minrto;
5039 if ((new_min <= new_init) && (new_init <= new_max)) {
5040 stcb->asoc.initial_rto = new_init;
5041 stcb->asoc.maxrto = new_max;
5042 stcb->asoc.minrto = new_min;
5044 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5047 SCTP_TCB_UNLOCK(stcb);
5049 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5050 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5051 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5052 SCTP_INP_WLOCK(inp);
5053 if (srto->srto_initial)
5054 new_init = srto->srto_initial;
5056 new_init = inp->sctp_ep.initial_rto;
5058 new_max = srto->srto_max;
5060 new_max = inp->sctp_ep.sctp_maxrto;
5062 new_min = srto->srto_min;
5064 new_min = inp->sctp_ep.sctp_minrto;
5065 if ((new_min <= new_init) && (new_init <= new_max)) {
5066 inp->sctp_ep.initial_rto = new_init;
5067 inp->sctp_ep.sctp_maxrto = new_max;
5068 inp->sctp_ep.sctp_minrto = new_min;
5070 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5073 SCTP_INP_WUNLOCK(inp);
5075 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5081 case SCTP_ASSOCINFO:
5083 struct sctp_assocparams *sasoc;
5085 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5086 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5087 if (sasoc->sasoc_cookie_life) {
5088 /* boundary check the cookie life */
5089 if (sasoc->sasoc_cookie_life < 1000)
5090 sasoc->sasoc_cookie_life = 1000;
5091 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5092 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5096 if (sasoc->sasoc_asocmaxrxt)
5097 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5098 if (sasoc->sasoc_cookie_life) {
5099 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5101 SCTP_TCB_UNLOCK(stcb);
5103 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5104 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5105 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5106 SCTP_INP_WLOCK(inp);
5107 if (sasoc->sasoc_asocmaxrxt)
5108 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5109 if (sasoc->sasoc_cookie_life) {
5110 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5112 SCTP_INP_WUNLOCK(inp);
5114 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5122 struct sctp_initmsg *sinit;
5124 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5125 SCTP_INP_WLOCK(inp);
5126 if (sinit->sinit_num_ostreams)
5127 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5129 if (sinit->sinit_max_instreams)
5130 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5132 if (sinit->sinit_max_attempts)
5133 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5135 if (sinit->sinit_max_init_timeo)
5136 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5137 SCTP_INP_WUNLOCK(inp);
5140 case SCTP_PRIMARY_ADDR:
5142 struct sctp_setprim *spa;
5143 struct sctp_nets *net;
5145 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5146 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5150 net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
5153 * We increment here since
5154 * sctp_findassociation_ep_addr() wil do a
5155 * decrement if it finds the stcb as long as
5156 * the locked tcb (last argument) is NOT a
5159 SCTP_INP_INCR_REF(inp);
5160 stcb = sctp_findassociation_ep_addr(&inp,
5161 (struct sockaddr *)&spa->ssp_addr,
5164 SCTP_INP_DECR_REF(inp);
5168 if ((stcb) && (net)) {
5169 if ((net != stcb->asoc.primary_destination) &&
5170 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
5171 /* Ok we need to set it */
5172 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5173 if ((stcb->asoc.alternate) &&
5174 (!(net->dest_state & SCTP_ADDR_PF)) &&
5175 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5176 sctp_free_remote_addr(stcb->asoc.alternate);
5177 stcb->asoc.alternate = NULL;
5182 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5186 SCTP_TCB_UNLOCK(stcb);
5190 case SCTP_SET_DYNAMIC_PRIMARY:
5192 union sctp_sockstore *ss;
5194 error = priv_check(curthread,
5195 PRIV_NETINET_RESERVEDPORT);
5199 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5200 /* SUPER USER CHECK? */
5201 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5204 case SCTP_SET_PEER_PRIMARY_ADDR:
5206 struct sctp_setpeerprim *sspp;
5208 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5209 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5211 struct sctp_ifa *ifa;
5213 ifa = sctp_find_ifa_by_addr((struct sockaddr *)&sspp->sspp_addr,
5214 stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5216 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5220 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5222 * Must validate the ifa found is in
5225 struct sctp_laddr *laddr;
5228 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5229 if (laddr->ifa == NULL) {
5230 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5234 if (laddr->ifa == ifa) {
5240 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5245 if (sctp_set_primary_ip_address_sa(stcb,
5246 (struct sockaddr *)&sspp->sspp_addr) != 0) {
5247 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5251 SCTP_TCB_UNLOCK(stcb);
5253 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5258 case SCTP_BINDX_ADD_ADDR:
5260 struct sctp_getaddresses *addrs;
5263 td = (struct thread *)p;
5264 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5267 if (addrs->addr->sa_family == AF_INET) {
5268 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5269 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5273 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5274 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5280 if (addrs->addr->sa_family == AF_INET6) {
5281 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5282 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5286 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5287 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5288 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5294 error = EAFNOSUPPORT;
5297 sctp_bindx_add_address(so, inp, addrs->addr,
5298 addrs->sget_assoc_id, vrf_id,
5302 case SCTP_BINDX_REM_ADDR:
5304 struct sctp_getaddresses *addrs;
5307 td = (struct thread *)p;
5309 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5311 if (addrs->addr->sa_family == AF_INET) {
5312 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5313 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5317 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5318 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5324 if (addrs->addr->sa_family == AF_INET6) {
5325 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5326 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5331 (error = prison_local_ip6(td->td_ucred,
5332 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5333 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5334 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5340 error = EAFNOSUPPORT;
5343 sctp_bindx_delete_address(inp, addrs->addr,
5344 addrs->sget_assoc_id, vrf_id,
5350 struct sctp_event *event;
5351 uint32_t event_type;
5353 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5354 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5355 switch (event->se_type) {
5356 case SCTP_ASSOC_CHANGE:
5357 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5359 case SCTP_PEER_ADDR_CHANGE:
5360 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5362 case SCTP_REMOTE_ERROR:
5363 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5365 case SCTP_SEND_FAILED:
5366 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5368 case SCTP_SHUTDOWN_EVENT:
5369 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5371 case SCTP_ADAPTATION_INDICATION:
5372 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5374 case SCTP_PARTIAL_DELIVERY_EVENT:
5375 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5377 case SCTP_AUTHENTICATION_EVENT:
5378 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5380 case SCTP_STREAM_RESET_EVENT:
5381 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5383 case SCTP_SENDER_DRY_EVENT:
5384 event_type = SCTP_PCB_FLAGS_DRYEVNT;
5386 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
5388 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5391 case SCTP_ASSOC_RESET_EVENT:
5392 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
5394 case SCTP_STREAM_CHANGE_EVENT:
5395 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
5397 case SCTP_SEND_FAILED_EVENT:
5398 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
5402 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5406 if (event_type > 0) {
5409 sctp_stcb_feature_on(inp, stcb, event_type);
5410 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
5411 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5412 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5413 (stcb->asoc.stream_queue_cnt == 0)) {
5414 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5418 sctp_stcb_feature_off(inp, stcb, event_type);
5420 SCTP_TCB_UNLOCK(stcb);
5423 * We don't want to send up a storm
5424 * of events, so return an error for
5427 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
5428 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
5429 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
5430 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
5431 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
5432 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5436 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5437 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5438 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
5439 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5440 SCTP_INP_WLOCK(inp);
5442 sctp_feature_on(inp, event_type);
5444 sctp_feature_off(inp, event_type);
5446 SCTP_INP_WUNLOCK(inp);
5448 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
5449 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5450 SCTP_INP_RLOCK(inp);
5451 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5452 SCTP_TCB_LOCK(stcb);
5454 sctp_stcb_feature_on(inp, stcb, event_type);
5456 sctp_stcb_feature_off(inp, stcb, event_type);
5458 SCTP_TCB_UNLOCK(stcb);
5460 SCTP_INP_RUNLOCK(inp);
5466 case SCTP_RECVRCVINFO:
5470 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5471 SCTP_INP_WLOCK(inp);
5473 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5475 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5477 SCTP_INP_WUNLOCK(inp);
5480 case SCTP_RECVNXTINFO:
5484 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5485 SCTP_INP_WLOCK(inp);
5487 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5489 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5491 SCTP_INP_WUNLOCK(inp);
5494 case SCTP_DEFAULT_SNDINFO:
5496 struct sctp_sndinfo *info;
5499 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
5500 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
5503 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5504 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5505 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5506 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5507 stcb->asoc.def_send.sinfo_flags |= policy;
5508 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5509 stcb->asoc.def_send.sinfo_context = info->snd_context;
5511 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5514 SCTP_TCB_UNLOCK(stcb);
5516 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5517 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5518 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
5519 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5520 SCTP_INP_WLOCK(inp);
5521 inp->def_send.sinfo_stream = info->snd_sid;
5522 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
5523 inp->def_send.sinfo_flags = info->snd_flags;
5524 inp->def_send.sinfo_flags |= policy;
5525 inp->def_send.sinfo_ppid = info->snd_ppid;
5526 inp->def_send.sinfo_context = info->snd_context;
5527 SCTP_INP_WUNLOCK(inp);
5529 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
5530 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5531 SCTP_INP_RLOCK(inp);
5532 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5533 SCTP_TCB_LOCK(stcb);
5534 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5535 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5536 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5537 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5538 stcb->asoc.def_send.sinfo_flags |= policy;
5539 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5540 stcb->asoc.def_send.sinfo_context = info->snd_context;
5542 SCTP_TCB_UNLOCK(stcb);
5544 SCTP_INP_RUNLOCK(inp);
5549 case SCTP_DEFAULT_PRINFO:
5551 struct sctp_default_prinfo *info;
5553 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
5554 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
5556 if (PR_SCTP_INVALID_POLICY(info->pr_policy)) {
5557 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5562 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5563 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5564 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5565 SCTP_TCB_UNLOCK(stcb);
5567 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5568 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5569 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
5570 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5571 SCTP_INP_WLOCK(inp);
5572 inp->def_send.sinfo_flags &= 0xfff0;
5573 inp->def_send.sinfo_flags |= info->pr_policy;
5574 inp->def_send.sinfo_timetolive = info->pr_value;
5575 SCTP_INP_WUNLOCK(inp);
5577 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
5578 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5579 SCTP_INP_RLOCK(inp);
5580 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5581 SCTP_TCB_LOCK(stcb);
5582 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5583 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5584 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5585 SCTP_TCB_UNLOCK(stcb);
5587 SCTP_INP_RUNLOCK(inp);
5592 case SCTP_PEER_ADDR_THLDS:
5593 /* Applies to the specific association */
5595 struct sctp_paddrthlds *thlds;
5596 struct sctp_nets *net;
5598 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
5599 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
5602 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_assoc_id);
5605 * We increment here since
5606 * sctp_findassociation_ep_addr() wil do a
5607 * decrement if it finds the stcb as long as
5608 * the locked tcb (last argument) is NOT a
5611 SCTP_INP_INCR_REF(inp);
5612 stcb = sctp_findassociation_ep_addr(&inp,
5613 (struct sockaddr *)&thlds->spt_assoc_id,
5616 SCTP_INP_DECR_REF(inp);
5619 if (stcb && (net == NULL)) {
5620 struct sockaddr *sa;
5622 sa = (struct sockaddr *)&thlds->spt_assoc_id;
5624 if (sa->sa_family == AF_INET) {
5626 struct sockaddr_in *sin;
5628 sin = (struct sockaddr_in *)sa;
5629 if (sin->sin_addr.s_addr) {
5630 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5631 SCTP_TCB_UNLOCK(stcb);
5638 if (sa->sa_family == AF_INET6) {
5639 struct sockaddr_in6 *sin6;
5641 sin6 = (struct sockaddr_in6 *)sa;
5642 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5643 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5644 SCTP_TCB_UNLOCK(stcb);
5651 error = EAFNOSUPPORT;
5652 SCTP_TCB_UNLOCK(stcb);
5653 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5659 if (net->dest_state & SCTP_ADDR_PF) {
5660 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5661 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5662 net->dest_state &= ~SCTP_ADDR_PF;
5665 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5666 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5667 net->dest_state |= SCTP_ADDR_PF;
5668 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5669 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5670 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5673 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5674 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5675 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5676 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5679 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5680 net->dest_state |= SCTP_ADDR_REACHABLE;
5681 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5684 net->failure_threshold = thlds->spt_pathmaxrxt;
5685 net->pf_threshold = thlds->spt_pathpfthld;
5687 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5688 if (net->dest_state & SCTP_ADDR_PF) {
5689 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5690 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5691 net->dest_state &= ~SCTP_ADDR_PF;
5694 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5695 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5696 net->dest_state |= SCTP_ADDR_PF;
5697 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5698 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5699 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5702 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5703 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5704 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5705 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5708 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5709 net->dest_state |= SCTP_ADDR_REACHABLE;
5710 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5713 net->failure_threshold = thlds->spt_pathmaxrxt;
5714 net->pf_threshold = thlds->spt_pathpfthld;
5716 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
5717 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
5720 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5721 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5722 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
5723 SCTP_INP_WLOCK(inp);
5724 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
5725 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
5726 SCTP_INP_WUNLOCK(inp);
5728 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5734 case SCTP_REMOTE_UDP_ENCAPS_PORT:
5736 struct sctp_udpencaps *encaps;
5737 struct sctp_nets *net;
5739 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
5740 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
5742 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
5745 * We increment here since
5746 * sctp_findassociation_ep_addr() wil do a
5747 * decrement if it finds the stcb as long as
5748 * the locked tcb (last argument) is NOT a
5752 SCTP_INP_INCR_REF(inp);
5753 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
5755 SCTP_INP_DECR_REF(inp);
5758 if (stcb && (net == NULL)) {
5759 struct sockaddr *sa;
5761 sa = (struct sockaddr *)&encaps->sue_address;
5763 if (sa->sa_family == AF_INET) {
5765 struct sockaddr_in *sin;
5767 sin = (struct sockaddr_in *)sa;
5768 if (sin->sin_addr.s_addr) {
5769 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5770 SCTP_TCB_UNLOCK(stcb);
5777 if (sa->sa_family == AF_INET6) {
5778 struct sockaddr_in6 *sin6;
5780 sin6 = (struct sockaddr_in6 *)sa;
5781 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5782 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5783 SCTP_TCB_UNLOCK(stcb);
5790 error = EAFNOSUPPORT;
5791 SCTP_TCB_UNLOCK(stcb);
5792 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5798 net->port = encaps->sue_port;
5800 stcb->asoc.port = encaps->sue_port;
5802 SCTP_TCB_UNLOCK(stcb);
5804 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5805 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5806 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
5807 SCTP_INP_WLOCK(inp);
5808 inp->sctp_ep.port = encaps->sue_port;
5809 SCTP_INP_WUNLOCK(inp);
5811 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5818 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
5819 error = ENOPROTOOPT;
5821 } /* end switch (opt) */
5826 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
5828 void *optval = NULL;
5833 if (sopt->sopt_level != IPPROTO_SCTP) {
5834 /* wrong proto level... send back up to IP */
5836 if (INP_CHECK_SOCKAF(so, AF_INET6))
5837 error = ip6_ctloutput(so, sopt);
5839 #if defined(INET) && defined (INET6)
5843 error = ip_ctloutput(so, sopt);
5847 optsize = sopt->sopt_valsize;
5849 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
5850 if (optval == NULL) {
5851 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
5854 error = sooptcopyin(sopt, optval, optsize, optsize);
5856 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5860 p = (void *)sopt->sopt_td;
5861 if (sopt->sopt_dir == SOPT_SET) {
5862 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
5863 } else if (sopt->sopt_dir == SOPT_GET) {
5864 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
5866 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5869 if ((error == 0) && (optval != NULL)) {
5870 error = sooptcopyout(sopt, optval, optsize);
5871 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5872 } else if (optval != NULL) {
5873 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5881 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
5884 int create_lock_on = 0;
5886 struct sctp_inpcb *inp;
5887 struct sctp_tcb *stcb = NULL;
5889 inp = (struct sctp_inpcb *)so->so_pcb;
5891 /* I made the same as TCP since we are not setup? */
5892 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5893 return (ECONNRESET);
5896 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5899 switch (addr->sa_family) {
5903 struct sockaddr_in6 *sin6p;
5905 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
5906 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5909 sin6p = (struct sockaddr_in6 *)addr;
5910 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
5911 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5920 struct sockaddr_in *sinp;
5922 if (addr->sa_len != sizeof(struct sockaddr_in)) {
5923 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5926 sinp = (struct sockaddr_in *)addr;
5927 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
5928 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5935 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
5936 return (EAFNOSUPPORT);
5938 SCTP_INP_INCR_REF(inp);
5939 SCTP_ASOC_CREATE_LOCK(inp);
5943 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
5944 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
5945 /* Should I really unlock ? */
5946 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
5951 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
5952 (addr->sa_family == AF_INET6)) {
5953 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5958 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
5959 SCTP_PCB_FLAGS_UNBOUND) {
5960 /* Bind a ephemeral port */
5961 error = sctp_inpcb_bind(so, NULL, NULL, p);
5966 /* Now do we connect? */
5967 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
5968 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
5969 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5973 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
5974 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
5975 /* We are already connected AND the TCP model */
5976 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
5980 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
5981 SCTP_INP_RLOCK(inp);
5982 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5983 SCTP_INP_RUNLOCK(inp);
5986 * We increment here since sctp_findassociation_ep_addr()
5987 * will do a decrement if it finds the stcb as long as the
5988 * locked tcb (last argument) is NOT a TCB.. aka NULL.
5990 SCTP_INP_INCR_REF(inp);
5991 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
5993 SCTP_INP_DECR_REF(inp);
5995 SCTP_TCB_UNLOCK(stcb);
5999 /* Already have or am bring up an association */
6000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
6004 vrf_id = inp->def_vrf_id;
6005 /* We are GOOD to go */
6006 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
6008 /* Gak! no memory */
6011 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
6012 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
6013 /* Set the connected flag so we can queue data */
6016 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
6017 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
6019 /* initialize authentication parameters for the assoc */
6020 sctp_initialize_auth_params(inp, stcb);
6022 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
6023 SCTP_TCB_UNLOCK(stcb);
6025 if (create_lock_on) {
6026 SCTP_ASOC_CREATE_UNLOCK(inp);
6028 SCTP_INP_DECR_REF(inp);
6035 sctp_listen(struct socket *so, int backlog, struct thread *p)
6038 * Note this module depends on the protocol processing being called
6039 * AFTER any socket level flags and backlog are applied to the
6040 * socket. The traditional way that the socket flags are applied is
6041 * AFTER protocol processing. We have made a change to the
6042 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
6043 * place if the socket API for SCTP is to work properly.
6047 struct sctp_inpcb *inp;
6049 inp = (struct sctp_inpcb *)so->so_pcb;
6051 /* I made the same as TCP since we are not setup? */
6052 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6053 return (ECONNRESET);
6055 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
6056 /* See if we have a listener */
6057 struct sctp_inpcb *tinp;
6058 union sctp_sockstore store, *sp;
6061 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
6063 struct sctp_laddr *laddr;
6065 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6066 memcpy(&store, &laddr->ifa->address, sizeof(store));
6067 switch (sp->sa.sa_family) {
6070 sp->sin.sin_port = inp->sctp_lport;
6075 sp->sin6.sin6_port = inp->sctp_lport;
6081 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6082 if (tinp && (tinp != inp) &&
6083 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6084 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6085 (tinp->sctp_socket->so_qlimit)) {
6087 * we have a listener already and
6090 SCTP_INP_DECR_REF(tinp);
6091 return (EADDRINUSE);
6093 SCTP_INP_DECR_REF(tinp);
6097 /* Setup a local addr bound all */
6098 memset(&store, 0, sizeof(store));
6099 switch (sp->sa.sa_family) {
6102 store.sin.sin_port = inp->sctp_lport;
6107 sp->sin6.sin6_port = inp->sctp_lport;
6114 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
6115 store.sa.sa_family = AF_INET6;
6116 store.sa.sa_len = sizeof(struct sockaddr_in6);
6120 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
6121 store.sa.sa_family = AF_INET;
6122 store.sa.sa_len = sizeof(struct sockaddr_in);
6125 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6126 if (tinp && (tinp != inp) &&
6127 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6128 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6129 (tinp->sctp_socket->so_qlimit)) {
6131 * we have a listener already and its not
6134 SCTP_INP_DECR_REF(tinp);
6135 return (EADDRINUSE);
6137 SCTP_INP_DECR_REF(inp);
6141 SCTP_INP_RLOCK(inp);
6142 #ifdef SCTP_LOCK_LOGGING
6143 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
6144 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
6148 error = solisten_proto_check(so);
6151 SCTP_INP_RUNLOCK(inp);
6154 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
6155 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
6157 * The unlucky case - We are in the tcp pool with this guy.
6158 * - Someone else is in the main inp slot. - We must move
6159 * this guy (the listener) to the main slot - We must then
6160 * move the guy that was listener to the TCP Pool.
6162 if (sctp_swap_inpcb_for_listen(inp)) {
6166 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6167 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6168 /* We are already connected AND the TCP model */
6170 SCTP_INP_RUNLOCK(inp);
6172 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6173 return (EADDRINUSE);
6175 SCTP_INP_RUNLOCK(inp);
6176 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
6177 /* We must do a bind. */
6179 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
6180 /* bind error, probably perm */
6185 /* It appears for 7.0 and on, we must always call this. */
6186 solisten_proto(so, backlog);
6187 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6188 /* remove the ACCEPTCONN flag for one-to-many sockets */
6189 so->so_options &= ~SO_ACCEPTCONN;
6192 /* turning off listen */
6193 so->so_options &= ~SO_ACCEPTCONN;
6199 static int sctp_defered_wakeup_cnt = 0;
6202 sctp_accept(struct socket *so, struct sockaddr **addr)
6204 struct sctp_tcb *stcb;
6205 struct sctp_inpcb *inp;
6206 union sctp_sockstore store;
6212 inp = (struct sctp_inpcb *)so->so_pcb;
6215 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6216 return (ECONNRESET);
6218 SCTP_INP_RLOCK(inp);
6219 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6220 SCTP_INP_RUNLOCK(inp);
6221 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
6222 return (EOPNOTSUPP);
6224 if (so->so_state & SS_ISDISCONNECTED) {
6225 SCTP_INP_RUNLOCK(inp);
6226 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
6227 return (ECONNABORTED);
6229 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6231 SCTP_INP_RUNLOCK(inp);
6232 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6233 return (ECONNRESET);
6235 SCTP_TCB_LOCK(stcb);
6236 SCTP_INP_RUNLOCK(inp);
6237 store = stcb->asoc.primary_destination->ro._l_addr;
6238 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
6239 SCTP_TCB_UNLOCK(stcb);
6240 switch (store.sa.sa_family) {
6244 struct sockaddr_in *sin;
6246 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6249 sin->sin_family = AF_INET;
6250 sin->sin_len = sizeof(*sin);
6251 sin->sin_port = ((struct sockaddr_in *)&store)->sin_port;
6252 sin->sin_addr = ((struct sockaddr_in *)&store)->sin_addr;
6253 *addr = (struct sockaddr *)sin;
6260 struct sockaddr_in6 *sin6;
6262 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
6265 sin6->sin6_family = AF_INET6;
6266 sin6->sin6_len = sizeof(*sin6);
6267 sin6->sin6_port = ((struct sockaddr_in6 *)&store)->sin6_port;
6269 sin6->sin6_addr = ((struct sockaddr_in6 *)&store)->sin6_addr;
6270 if ((error = sa6_recoverscope(sin6)) != 0) {
6271 SCTP_FREE_SONAME(sin6);
6274 *addr = (struct sockaddr *)sin6;
6282 /* Wake any delayed sleep action */
6283 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
6284 SCTP_INP_WLOCK(inp);
6285 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
6286 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
6287 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
6288 SCTP_INP_WUNLOCK(inp);
6289 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
6290 if (sowriteable(inp->sctp_socket)) {
6291 sowwakeup_locked(inp->sctp_socket);
6293 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
6295 SCTP_INP_WLOCK(inp);
6297 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
6298 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
6299 SCTP_INP_WUNLOCK(inp);
6300 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
6301 if (soreadable(inp->sctp_socket)) {
6302 sctp_defered_wakeup_cnt++;
6303 sorwakeup_locked(inp->sctp_socket);
6305 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
6307 SCTP_INP_WLOCK(inp);
6309 SCTP_INP_WUNLOCK(inp);
6311 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
6312 SCTP_TCB_LOCK(stcb);
6313 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
6320 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
6322 struct sockaddr_in *sin;
6324 struct sctp_inpcb *inp;
6325 struct sctp_ifa *sctp_ifa;
6328 * Do the malloc first in case it blocks.
6330 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6333 sin->sin_family = AF_INET;
6334 sin->sin_len = sizeof(*sin);
6335 inp = (struct sctp_inpcb *)so->so_pcb;
6337 SCTP_FREE_SONAME(sin);
6338 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6339 return (ECONNRESET);
6341 SCTP_INP_RLOCK(inp);
6342 sin->sin_port = inp->sctp_lport;
6343 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
6344 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6345 struct sctp_tcb *stcb;
6346 struct sockaddr_in *sin_a;
6347 struct sctp_nets *net;
6350 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6356 SCTP_TCB_LOCK(stcb);
6357 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6358 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6360 /* this will make coverity happy */
6363 if (sin_a->sin_family == AF_INET) {
6368 if ((!fnd) || (sin_a == NULL)) {
6370 SCTP_TCB_UNLOCK(stcb);
6373 vrf_id = inp->def_vrf_id;
6374 sctp_ifa = sctp_source_address_selection(inp,
6376 (sctp_route_t *) & net->ro,
6379 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
6380 sctp_free_ifa(sctp_ifa);
6382 SCTP_TCB_UNLOCK(stcb);
6384 /* For the bound all case you get back 0 */
6386 sin->sin_addr.s_addr = 0;
6390 /* Take the first IPv4 address in the list */
6391 struct sctp_laddr *laddr;
6394 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6395 if (laddr->ifa->address.sa.sa_family == AF_INET) {
6396 struct sockaddr_in *sin_a;
6398 sin_a = (struct sockaddr_in *)&laddr->ifa->address.sa;
6399 sin->sin_addr = sin_a->sin_addr;
6405 SCTP_FREE_SONAME(sin);
6406 SCTP_INP_RUNLOCK(inp);
6407 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6411 SCTP_INP_RUNLOCK(inp);
6412 (*addr) = (struct sockaddr *)sin;
6417 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
6419 struct sockaddr_in *sin;
6421 struct sockaddr_in *sin_a;
6422 struct sctp_inpcb *inp;
6423 struct sctp_tcb *stcb;
6424 struct sctp_nets *net;
6426 /* Do the malloc first in case it blocks. */
6427 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6430 sin->sin_family = AF_INET;
6431 sin->sin_len = sizeof(*sin);
6433 inp = (struct sctp_inpcb *)so->so_pcb;
6434 if ((inp == NULL) ||
6435 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
6436 /* UDP type and listeners will drop out here */
6437 SCTP_FREE_SONAME(sin);
6438 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
6441 SCTP_INP_RLOCK(inp);
6442 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6444 SCTP_TCB_LOCK(stcb);
6446 SCTP_INP_RUNLOCK(inp);
6448 SCTP_FREE_SONAME(sin);
6449 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6450 return (ECONNRESET);
6453 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6454 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6455 if (sin_a->sin_family == AF_INET) {
6457 sin->sin_port = stcb->rport;
6458 sin->sin_addr = sin_a->sin_addr;
6462 SCTP_TCB_UNLOCK(stcb);
6464 /* No IPv4 address */
6465 SCTP_FREE_SONAME(sin);
6466 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6469 (*addr) = (struct sockaddr *)sin;
6473 struct pr_usrreqs sctp_usrreqs = {
6474 .pru_abort = sctp_abort,
6475 .pru_accept = sctp_accept,
6476 .pru_attach = sctp_attach,
6477 .pru_bind = sctp_bind,
6478 .pru_connect = sctp_connect,
6479 .pru_control = in_control,
6480 .pru_close = sctp_close,
6481 .pru_detach = sctp_close,
6482 .pru_sopoll = sopoll_generic,
6483 .pru_flush = sctp_flush,
6484 .pru_disconnect = sctp_disconnect,
6485 .pru_listen = sctp_listen,
6486 .pru_peeraddr = sctp_peeraddr,
6487 .pru_send = sctp_sendm,
6488 .pru_shutdown = sctp_shutdown,
6489 .pru_sockaddr = sctp_ingetaddr,
6490 .pru_sosend = sctp_sosend,
6491 .pru_soreceive = sctp_soreceive