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 *)&to,
349 (struct sockaddr *)&from,
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[1]),
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:
2056 SCTP_CHECK_AND_CAST(value, optval, uint8_t, *optsize);
2058 SCTP_INP_RLOCK(inp);
2059 if (inp->sctp_ep.max_burst < 256) {
2060 *value = inp->sctp_ep.max_burst;
2064 SCTP_INP_RUNLOCK(inp);
2065 *optsize = sizeof(uint8_t);
2070 struct sctp_assoc_value *av;
2073 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2074 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2077 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2078 SCTP_TCB_UNLOCK(stcb);
2080 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2081 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2082 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2083 SCTP_INP_RLOCK(inp);
2084 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2085 ovh = SCTP_MED_OVERHEAD;
2087 ovh = SCTP_MED_V4_OVERHEAD;
2089 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2090 av->assoc_value = 0;
2092 av->assoc_value = inp->sctp_frag_point - ovh;
2093 SCTP_INP_RUNLOCK(inp);
2095 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2100 *optsize = sizeof(struct sctp_assoc_value);
2104 case SCTP_GET_STAT_LOG:
2105 error = sctp_fill_stat_log(optval, optsize);
2109 struct sctp_event_subscribe *events;
2111 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2112 memset(events, 0, sizeof(struct sctp_event_subscribe));
2113 SCTP_INP_RLOCK(inp);
2114 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2115 events->sctp_data_io_event = 1;
2117 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2118 events->sctp_association_event = 1;
2120 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2121 events->sctp_address_event = 1;
2123 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2124 events->sctp_send_failure_event = 1;
2126 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2127 events->sctp_peer_error_event = 1;
2129 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2130 events->sctp_shutdown_event = 1;
2132 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2133 events->sctp_partial_delivery_event = 1;
2135 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2136 events->sctp_adaptation_layer_event = 1;
2138 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2139 events->sctp_authentication_event = 1;
2141 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2142 events->sctp_sender_dry_event = 1;
2144 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2145 events->sctp_stream_reset_event = 1;
2146 SCTP_INP_RUNLOCK(inp);
2147 *optsize = sizeof(struct sctp_event_subscribe);
2150 case SCTP_ADAPTATION_LAYER:
2154 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2156 SCTP_INP_RLOCK(inp);
2157 *value = inp->sctp_ep.adaptation_layer_indicator;
2158 SCTP_INP_RUNLOCK(inp);
2159 *optsize = sizeof(uint32_t);
2162 case SCTP_SET_INITIAL_DBG_SEQ:
2166 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2167 SCTP_INP_RLOCK(inp);
2168 *value = inp->sctp_ep.initial_sequence_debug;
2169 SCTP_INP_RUNLOCK(inp);
2170 *optsize = sizeof(uint32_t);
2173 case SCTP_GET_LOCAL_ADDR_SIZE:
2177 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2178 SCTP_INP_RLOCK(inp);
2179 *value = sctp_count_max_addresses(inp);
2180 SCTP_INP_RUNLOCK(inp);
2181 *optsize = sizeof(uint32_t);
2184 case SCTP_GET_REMOTE_ADDR_SIZE:
2188 struct sctp_nets *net;
2190 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2191 /* FIXME MT: change to sctp_assoc_value? */
2192 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2196 /* Count the sizes */
2197 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2198 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2199 size += sizeof(struct sockaddr_in6);
2201 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2204 size += sizeof(struct sockaddr_in);
2209 size += sizeof(struct sockaddr_in6);
2217 SCTP_TCB_UNLOCK(stcb);
2218 *value = (uint32_t) size;
2219 *optsize = sizeof(uint32_t);
2221 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2226 case SCTP_GET_PEER_ADDRESSES:
2228 * Get the address information, an array is passed in to
2229 * fill up we pack it.
2233 struct sockaddr_storage *sas;
2234 struct sctp_nets *net;
2235 struct sctp_getaddresses *saddr;
2237 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2238 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2241 left = (*optsize) - sizeof(struct sctp_getaddresses);
2242 *optsize = sizeof(struct sctp_getaddresses);
2243 sas = (struct sockaddr_storage *)&saddr->addr[0];
2245 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2246 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2247 cpsz = sizeof(struct sockaddr_in6);
2249 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2252 cpsz = sizeof(struct sockaddr_in);
2257 cpsz = sizeof(struct sockaddr_in6);
2269 /* not enough room. */
2272 #if defined(INET) && defined(INET6)
2273 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2274 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
2275 /* Must map the address */
2276 in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
2277 (struct sockaddr_in6 *)sas);
2280 memcpy(sas, &net->ro._l_addr, cpsz);
2281 #if defined(INET) && defined(INET6)
2284 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2286 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2290 SCTP_TCB_UNLOCK(stcb);
2292 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2297 case SCTP_GET_LOCAL_ADDRESSES:
2299 size_t limit, actual;
2300 struct sockaddr_storage *sas;
2301 struct sctp_getaddresses *saddr;
2303 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2304 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2306 sas = (struct sockaddr_storage *)&saddr->addr[0];
2307 limit = *optsize - sizeof(sctp_assoc_t);
2308 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2310 SCTP_TCB_UNLOCK(stcb);
2312 *optsize = sizeof(struct sockaddr_storage) + actual;
2315 case SCTP_PEER_ADDR_PARAMS:
2317 struct sctp_paddrparams *paddrp;
2318 struct sctp_nets *net;
2320 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2321 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2325 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2328 * We increment here since
2329 * sctp_findassociation_ep_addr() wil do a
2330 * decrement if it finds the stcb as long as
2331 * the locked tcb (last argument) is NOT a
2334 SCTP_INP_INCR_REF(inp);
2335 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddrp->spp_address, &net, NULL, NULL);
2337 SCTP_INP_DECR_REF(inp);
2340 if (stcb && (net == NULL)) {
2341 struct sockaddr *sa;
2343 sa = (struct sockaddr *)&paddrp->spp_address;
2345 if (sa->sa_family == AF_INET) {
2346 struct sockaddr_in *sin;
2348 sin = (struct sockaddr_in *)sa;
2349 if (sin->sin_addr.s_addr) {
2351 SCTP_TCB_UNLOCK(stcb);
2352 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2358 if (sa->sa_family == AF_INET6) {
2359 struct sockaddr_in6 *sin6;
2361 sin6 = (struct sockaddr_in6 *)sa;
2362 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2364 SCTP_TCB_UNLOCK(stcb);
2365 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2371 error = EAFNOSUPPORT;
2372 SCTP_TCB_UNLOCK(stcb);
2373 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2378 /* Applies to the specific association */
2379 paddrp->spp_flags = 0;
2383 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2384 ovh = SCTP_MED_OVERHEAD;
2386 ovh = SCTP_MED_V4_OVERHEAD;
2389 paddrp->spp_hbinterval = net->heart_beat_delay;
2390 paddrp->spp_pathmaxrxt = net->failure_threshold;
2391 paddrp->spp_pathmtu = net->mtu - ovh;
2392 /* get flags for HB */
2393 if (net->dest_state & SCTP_ADDR_NOHB) {
2394 paddrp->spp_flags |= SPP_HB_DISABLE;
2396 paddrp->spp_flags |= SPP_HB_ENABLE;
2398 /* get flags for PMTU */
2399 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2400 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2402 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2404 if (net->dscp & 0x01) {
2405 paddrp->spp_dscp = net->dscp & 0xfc;
2406 paddrp->spp_flags |= SPP_DSCP;
2409 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2410 (net->flowlabel & 0x80000000)) {
2411 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2412 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2417 * No destination so return default
2420 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2421 paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
2422 if (stcb->asoc.default_dscp & 0x01) {
2423 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2424 paddrp->spp_flags |= SPP_DSCP;
2427 if (stcb->asoc.default_flowlabel & 0x80000000) {
2428 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2429 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2432 /* default settings should be these */
2433 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2434 paddrp->spp_flags |= SPP_HB_DISABLE;
2436 paddrp->spp_flags |= SPP_HB_ENABLE;
2438 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2439 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2441 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2443 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2445 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2446 SCTP_TCB_UNLOCK(stcb);
2448 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2449 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2450 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2451 /* Use endpoint defaults */
2452 SCTP_INP_RLOCK(inp);
2453 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2454 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2455 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2456 /* get inp's default */
2457 if (inp->sctp_ep.default_dscp & 0x01) {
2458 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2459 paddrp->spp_flags |= SPP_DSCP;
2462 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2463 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2464 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2465 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2468 /* can't return this */
2469 paddrp->spp_pathmtu = 0;
2471 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2472 paddrp->spp_flags |= SPP_HB_ENABLE;
2474 paddrp->spp_flags |= SPP_HB_DISABLE;
2476 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2477 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2479 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2481 SCTP_INP_RUNLOCK(inp);
2483 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2488 *optsize = sizeof(struct sctp_paddrparams);
2492 case SCTP_GET_PEER_ADDR_INFO:
2494 struct sctp_paddrinfo *paddri;
2495 struct sctp_nets *net;
2497 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2498 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2502 net = sctp_findnet(stcb, (struct sockaddr *)&paddri->spinfo_address);
2505 * We increment here since
2506 * sctp_findassociation_ep_addr() wil do a
2507 * decrement if it finds the stcb as long as
2508 * the locked tcb (last argument) is NOT a
2511 SCTP_INP_INCR_REF(inp);
2512 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddri->spinfo_address, &net, NULL, NULL);
2514 SCTP_INP_DECR_REF(inp);
2518 if ((stcb) && (net)) {
2519 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2520 /* It's unconfirmed */
2521 paddri->spinfo_state = SCTP_UNCONFIRMED;
2522 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2524 paddri->spinfo_state = SCTP_ACTIVE;
2527 paddri->spinfo_state = SCTP_INACTIVE;
2529 paddri->spinfo_cwnd = net->cwnd;
2530 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2531 paddri->spinfo_rto = net->RTO;
2532 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2533 paddri->spinfo_mtu = net->mtu;
2534 SCTP_TCB_UNLOCK(stcb);
2535 *optsize = sizeof(struct sctp_paddrinfo);
2538 SCTP_TCB_UNLOCK(stcb);
2540 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2545 case SCTP_PCB_STATUS:
2547 struct sctp_pcbinfo *spcb;
2549 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2550 sctp_fill_pcbinfo(spcb);
2551 *optsize = sizeof(struct sctp_pcbinfo);
2556 struct sctp_nets *net;
2557 struct sctp_status *sstat;
2559 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2560 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2563 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2568 * I think passing the state is fine since
2569 * sctp_constants.h will be available to the user
2572 sstat->sstat_state = stcb->asoc.state;
2573 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2574 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2575 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2577 * We can't include chunks that have been passed to
2578 * the socket layer. Only things in queue.
2580 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2581 stcb->asoc.cnt_on_all_streams);
2584 sstat->sstat_instrms = stcb->asoc.streamincnt;
2585 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2586 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2587 memcpy(&sstat->sstat_primary.spinfo_address,
2588 &stcb->asoc.primary_destination->ro._l_addr,
2589 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2590 net = stcb->asoc.primary_destination;
2591 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2593 * Again the user can get info from sctp_constants.h
2594 * for what the state of the network is.
2596 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2597 /* It's unconfirmed */
2598 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2599 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2601 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2604 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2606 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2607 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2608 sstat->sstat_primary.spinfo_rto = net->RTO;
2609 sstat->sstat_primary.spinfo_mtu = net->mtu;
2610 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2611 SCTP_TCB_UNLOCK(stcb);
2612 *optsize = sizeof(struct sctp_status);
2617 struct sctp_rtoinfo *srto;
2619 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2620 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2623 srto->srto_initial = stcb->asoc.initial_rto;
2624 srto->srto_max = stcb->asoc.maxrto;
2625 srto->srto_min = stcb->asoc.minrto;
2626 SCTP_TCB_UNLOCK(stcb);
2628 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2629 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2630 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2631 SCTP_INP_RLOCK(inp);
2632 srto->srto_initial = inp->sctp_ep.initial_rto;
2633 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2634 srto->srto_min = inp->sctp_ep.sctp_minrto;
2635 SCTP_INP_RUNLOCK(inp);
2637 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2642 *optsize = sizeof(struct sctp_rtoinfo);
2648 struct sctp_timeouts *stimo;
2650 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2651 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2654 stimo->stimo_init = stcb->asoc.timoinit;
2655 stimo->stimo_data = stcb->asoc.timodata;
2656 stimo->stimo_sack = stcb->asoc.timosack;
2657 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2658 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2659 stimo->stimo_cookie = stcb->asoc.timocookie;
2660 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2661 SCTP_TCB_UNLOCK(stcb);
2662 *optsize = sizeof(struct sctp_timeouts);
2664 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2669 case SCTP_ASSOCINFO:
2671 struct sctp_assocparams *sasoc;
2673 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2674 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2677 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2678 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2679 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2680 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2681 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2682 SCTP_TCB_UNLOCK(stcb);
2684 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2685 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2686 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2687 SCTP_INP_RLOCK(inp);
2688 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2689 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2690 sasoc->sasoc_number_peer_destinations = 0;
2691 sasoc->sasoc_peer_rwnd = 0;
2692 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2693 SCTP_INP_RUNLOCK(inp);
2695 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2700 *optsize = sizeof(struct sctp_assocparams);
2704 case SCTP_DEFAULT_SEND_PARAM:
2706 struct sctp_sndrcvinfo *s_info;
2708 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2709 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2712 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2713 SCTP_TCB_UNLOCK(stcb);
2715 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2716 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2717 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2718 SCTP_INP_RLOCK(inp);
2719 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2720 SCTP_INP_RUNLOCK(inp);
2722 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2727 *optsize = sizeof(struct sctp_sndrcvinfo);
2733 struct sctp_initmsg *sinit;
2735 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2736 SCTP_INP_RLOCK(inp);
2737 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2738 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2739 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2740 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2741 SCTP_INP_RUNLOCK(inp);
2742 *optsize = sizeof(struct sctp_initmsg);
2745 case SCTP_PRIMARY_ADDR:
2746 /* we allow a "get" operation on this */
2748 struct sctp_setprim *ssp;
2750 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2751 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2754 /* simply copy out the sockaddr_storage... */
2758 if (len > stcb->asoc.primary_destination->ro._l_addr.sa.sa_len)
2759 len = stcb->asoc.primary_destination->ro._l_addr.sa.sa_len;
2761 memcpy(&ssp->ssp_addr,
2762 &stcb->asoc.primary_destination->ro._l_addr,
2764 SCTP_TCB_UNLOCK(stcb);
2765 *optsize = sizeof(struct sctp_setprim);
2767 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2772 case SCTP_HMAC_IDENT:
2774 struct sctp_hmacalgo *shmac;
2775 sctp_hmaclist_t *hmaclist;
2779 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2781 SCTP_INP_RLOCK(inp);
2782 hmaclist = inp->sctp_ep.local_hmacs;
2783 if (hmaclist == NULL) {
2784 /* no HMACs to return */
2785 *optsize = sizeof(*shmac);
2786 SCTP_INP_RUNLOCK(inp);
2789 /* is there room for all of the hmac ids? */
2790 size = sizeof(*shmac) + (hmaclist->num_algo *
2791 sizeof(shmac->shmac_idents[0]));
2792 if ((size_t)(*optsize) < size) {
2793 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2795 SCTP_INP_RUNLOCK(inp);
2798 /* copy in the list */
2799 shmac->shmac_number_of_idents = hmaclist->num_algo;
2800 for (i = 0; i < hmaclist->num_algo; i++) {
2801 shmac->shmac_idents[i] = hmaclist->hmac[i];
2803 SCTP_INP_RUNLOCK(inp);
2807 case SCTP_AUTH_ACTIVE_KEY:
2809 struct sctp_authkeyid *scact;
2811 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2812 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2815 /* get the active key on the assoc */
2816 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2817 SCTP_TCB_UNLOCK(stcb);
2819 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2820 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2821 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2822 /* get the endpoint active key */
2823 SCTP_INP_RLOCK(inp);
2824 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2825 SCTP_INP_RUNLOCK(inp);
2827 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2832 *optsize = sizeof(struct sctp_authkeyid);
2836 case SCTP_LOCAL_AUTH_CHUNKS:
2838 struct sctp_authchunks *sac;
2839 sctp_auth_chklist_t *chklist = NULL;
2842 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2843 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2846 /* get off the assoc */
2847 chklist = stcb->asoc.local_auth_chunks;
2848 /* is there enough space? */
2849 size = sctp_auth_get_chklist_size(chklist);
2850 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2852 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2854 /* copy in the chunks */
2855 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2856 sac->gauth_number_of_chunks = (uint32_t) size;
2857 *optsize = sizeof(struct sctp_authchunks) + size;
2859 SCTP_TCB_UNLOCK(stcb);
2861 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2862 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2863 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2864 /* get off the endpoint */
2865 SCTP_INP_RLOCK(inp);
2866 chklist = inp->sctp_ep.local_auth_chunks;
2867 /* is there enough space? */
2868 size = sctp_auth_get_chklist_size(chklist);
2869 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2871 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2873 /* copy in the chunks */
2874 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2875 sac->gauth_number_of_chunks = (uint32_t) size;
2876 *optsize = sizeof(struct sctp_authchunks) + size;
2878 SCTP_INP_RUNLOCK(inp);
2880 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2886 case SCTP_PEER_AUTH_CHUNKS:
2888 struct sctp_authchunks *sac;
2889 sctp_auth_chklist_t *chklist = NULL;
2892 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2893 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2896 /* get off the assoc */
2897 chklist = stcb->asoc.peer_auth_chunks;
2898 /* is there enough space? */
2899 size = sctp_auth_get_chklist_size(chklist);
2900 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2902 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2904 /* copy in the chunks */
2905 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2906 sac->gauth_number_of_chunks = (uint32_t) size;
2907 *optsize = sizeof(struct sctp_authchunks) + size;
2909 SCTP_TCB_UNLOCK(stcb);
2911 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2918 struct sctp_event *event;
2919 uint32_t event_type;
2921 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2922 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
2924 switch (event->se_type) {
2925 case SCTP_ASSOC_CHANGE:
2926 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
2928 case SCTP_PEER_ADDR_CHANGE:
2929 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
2931 case SCTP_REMOTE_ERROR:
2932 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
2934 case SCTP_SEND_FAILED:
2935 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
2937 case SCTP_SHUTDOWN_EVENT:
2938 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
2940 case SCTP_ADAPTATION_INDICATION:
2941 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
2943 case SCTP_PARTIAL_DELIVERY_EVENT:
2944 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
2946 case SCTP_AUTHENTICATION_EVENT:
2947 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
2949 case SCTP_STREAM_RESET_EVENT:
2950 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
2952 case SCTP_SENDER_DRY_EVENT:
2953 event_type = SCTP_PCB_FLAGS_DRYEVNT;
2955 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
2957 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
2960 case SCTP_ASSOC_RESET_EVENT:
2961 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
2963 case SCTP_STREAM_CHANGE_EVENT:
2964 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
2966 case SCTP_SEND_FAILED_EVENT:
2967 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
2971 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2975 if (event_type > 0) {
2977 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
2978 SCTP_TCB_UNLOCK(stcb);
2980 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2981 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2982 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
2983 SCTP_INP_RLOCK(inp);
2984 event->se_on = sctp_is_feature_on(inp, event_type);
2985 SCTP_INP_RUNLOCK(inp);
2987 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2993 *optsize = sizeof(struct sctp_event);
2997 case SCTP_RECVRCVINFO:
3001 if (*optsize < sizeof(int)) {
3002 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3005 SCTP_INP_RLOCK(inp);
3006 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3007 SCTP_INP_RUNLOCK(inp);
3010 /* return the option value */
3011 *(int *)optval = onoff;
3012 *optsize = sizeof(int);
3016 case SCTP_RECVNXTINFO:
3020 if (*optsize < sizeof(int)) {
3021 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3024 SCTP_INP_RLOCK(inp);
3025 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3026 SCTP_INP_RUNLOCK(inp);
3029 /* return the option value */
3030 *(int *)optval = onoff;
3031 *optsize = sizeof(int);
3035 case SCTP_DEFAULT_SNDINFO:
3037 struct sctp_sndinfo *info;
3039 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3040 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3043 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3044 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3045 info->snd_flags &= 0xfff0;
3046 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3047 info->snd_context = stcb->asoc.def_send.sinfo_context;
3048 SCTP_TCB_UNLOCK(stcb);
3050 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3051 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3052 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3053 SCTP_INP_RLOCK(inp);
3054 info->snd_sid = inp->def_send.sinfo_stream;
3055 info->snd_flags = inp->def_send.sinfo_flags;
3056 info->snd_flags &= 0xfff0;
3057 info->snd_ppid = inp->def_send.sinfo_ppid;
3058 info->snd_context = inp->def_send.sinfo_context;
3059 SCTP_INP_RUNLOCK(inp);
3061 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3066 *optsize = sizeof(struct sctp_sndinfo);
3070 case SCTP_DEFAULT_PRINFO:
3072 struct sctp_default_prinfo *info;
3074 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3075 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3078 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3079 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3080 SCTP_TCB_UNLOCK(stcb);
3082 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3083 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3084 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3085 SCTP_INP_RLOCK(inp);
3086 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3087 info->pr_value = inp->def_send.sinfo_timetolive;
3088 SCTP_INP_RUNLOCK(inp);
3090 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3095 *optsize = sizeof(struct sctp_default_prinfo);
3099 case SCTP_PEER_ADDR_THLDS:
3101 struct sctp_paddrthlds *thlds;
3102 struct sctp_nets *net;
3104 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3105 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3109 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_address);
3112 * We increment here since
3113 * sctp_findassociation_ep_addr() wil do a
3114 * decrement if it finds the stcb as long as
3115 * the locked tcb (last argument) is NOT a
3118 SCTP_INP_INCR_REF(inp);
3119 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&thlds->spt_address, &net, NULL, NULL);
3121 SCTP_INP_DECR_REF(inp);
3124 if (stcb && (net == NULL)) {
3125 struct sockaddr *sa;
3127 sa = (struct sockaddr *)&thlds->spt_address;
3129 if (sa->sa_family == AF_INET) {
3130 struct sockaddr_in *sin;
3132 sin = (struct sockaddr_in *)sa;
3133 if (sin->sin_addr.s_addr) {
3135 SCTP_TCB_UNLOCK(stcb);
3136 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3142 if (sa->sa_family == AF_INET6) {
3143 struct sockaddr_in6 *sin6;
3145 sin6 = (struct sockaddr_in6 *)sa;
3146 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3148 SCTP_TCB_UNLOCK(stcb);
3149 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3155 error = EAFNOSUPPORT;
3156 SCTP_TCB_UNLOCK(stcb);
3157 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3163 thlds->spt_pathmaxrxt = net->failure_threshold;
3164 thlds->spt_pathpfthld = net->pf_threshold;
3166 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3167 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3169 thlds->spt_assoc_id = sctp_get_associd(stcb);
3170 SCTP_TCB_UNLOCK(stcb);
3172 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3173 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3174 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3175 /* Use endpoint defaults */
3176 SCTP_INP_RLOCK(inp);
3177 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3178 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3179 SCTP_INP_RUNLOCK(inp);
3181 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3186 *optsize = sizeof(struct sctp_paddrthlds);
3190 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3192 struct sctp_udpencaps *encaps;
3193 struct sctp_nets *net;
3195 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3196 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3199 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
3202 * We increment here since
3203 * sctp_findassociation_ep_addr() wil do a
3204 * decrement if it finds the stcb as long as
3205 * the locked tcb (last argument) is NOT a
3209 SCTP_INP_INCR_REF(inp);
3210 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
3212 SCTP_INP_DECR_REF(inp);
3215 if (stcb && (net == NULL)) {
3216 struct sockaddr *sa;
3218 sa = (struct sockaddr *)&encaps->sue_address;
3220 if (sa->sa_family == AF_INET) {
3221 struct sockaddr_in *sin;
3223 sin = (struct sockaddr_in *)sa;
3224 if (sin->sin_addr.s_addr) {
3226 SCTP_TCB_UNLOCK(stcb);
3227 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3233 if (sa->sa_family == AF_INET6) {
3234 struct sockaddr_in6 *sin6;
3236 sin6 = (struct sockaddr_in6 *)sa;
3237 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3239 SCTP_TCB_UNLOCK(stcb);
3240 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3246 error = EAFNOSUPPORT;
3247 SCTP_TCB_UNLOCK(stcb);
3248 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3254 encaps->sue_port = net->port;
3256 encaps->sue_port = stcb->asoc.port;
3258 SCTP_TCB_UNLOCK(stcb);
3260 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3261 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3262 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3263 SCTP_INP_RLOCK(inp);
3264 encaps->sue_port = inp->sctp_ep.port;
3265 SCTP_INP_RUNLOCK(inp);
3267 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3272 *optsize = sizeof(struct sctp_paddrparams);
3276 case SCTP_ENABLE_STREAM_RESET:
3278 struct sctp_assoc_value *av;
3280 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3281 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3284 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3285 SCTP_TCB_UNLOCK(stcb);
3287 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3288 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3289 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3290 SCTP_INP_RLOCK(inp);
3291 av->assoc_value = (uint32_t) inp->local_strreset_support;
3292 SCTP_INP_RUNLOCK(inp);
3294 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3299 *optsize = sizeof(struct sctp_assoc_value);
3304 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3305 error = ENOPROTOOPT;
3307 } /* end switch (sopt->sopt_name) */
3315 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3320 struct sctp_tcb *stcb = NULL;
3321 struct sctp_inpcb *inp = NULL;
3324 if (optval == NULL) {
3325 SCTP_PRINTF("optval is NULL\n");
3326 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3329 inp = (struct sctp_inpcb *)so->so_pcb;
3331 SCTP_PRINTF("inp is NULL?\n");
3332 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3335 vrf_id = inp->def_vrf_id;
3340 case SCTP_AUTOCLOSE:
3341 case SCTP_AUTO_ASCONF:
3342 case SCTP_EXPLICIT_EOR:
3343 case SCTP_DISABLE_FRAGMENTS:
3344 case SCTP_USE_EXT_RCVINFO:
3345 case SCTP_I_WANT_MAPPED_V4_ADDR:
3346 /* copy in the option value */
3347 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3352 case SCTP_DISABLE_FRAGMENTS:
3353 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3355 case SCTP_AUTO_ASCONF:
3357 * NOTE: we don't really support this flag
3359 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3360 /* only valid for bound all sockets */
3361 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3363 /* forbidden by admin */
3364 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3367 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3369 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3373 case SCTP_EXPLICIT_EOR:
3374 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3376 case SCTP_USE_EXT_RCVINFO:
3377 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3379 case SCTP_I_WANT_MAPPED_V4_ADDR:
3380 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3381 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3383 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3388 set_opt = SCTP_PCB_FLAGS_NODELAY;
3390 case SCTP_AUTOCLOSE:
3391 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3392 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3393 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3396 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3398 * The value is in ticks. Note this does not effect
3399 * old associations, only new ones.
3401 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3404 SCTP_INP_WLOCK(inp);
3406 sctp_feature_on(inp, set_opt);
3408 sctp_feature_off(inp, set_opt);
3410 SCTP_INP_WUNLOCK(inp);
3412 case SCTP_REUSE_PORT:
3414 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3415 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3416 /* Can't set it after we are bound */
3420 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3421 /* Can't do this for a 1-m socket */
3426 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3428 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3431 case SCTP_PARTIAL_DELIVERY_POINT:
3435 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3436 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3437 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3441 inp->partial_delivery_point = *value;
3444 case SCTP_FRAGMENT_INTERLEAVE:
3445 /* not yet until we re-write sctp_recvmsg() */
3449 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3450 if (*level == SCTP_FRAG_LEVEL_2) {
3451 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3452 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3453 } else if (*level == SCTP_FRAG_LEVEL_1) {
3454 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3455 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3456 } else if (*level == SCTP_FRAG_LEVEL_0) {
3457 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3458 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3461 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3466 case SCTP_CMT_ON_OFF:
3467 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3468 struct sctp_assoc_value *av;
3470 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3471 if (av->assoc_value > SCTP_CMT_MAX) {
3472 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3476 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3478 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3479 SCTP_TCB_UNLOCK(stcb);
3481 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3482 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3483 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3484 (av->assoc_id == SCTP_ALL_ASSOC)) {
3485 SCTP_INP_WLOCK(inp);
3486 inp->sctp_cmt_on_off = av->assoc_value;
3487 SCTP_INP_WUNLOCK(inp);
3489 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3490 (av->assoc_id == SCTP_ALL_ASSOC)) {
3491 SCTP_INP_RLOCK(inp);
3492 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3493 SCTP_TCB_LOCK(stcb);
3494 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3495 SCTP_TCB_UNLOCK(stcb);
3497 SCTP_INP_RUNLOCK(inp);
3501 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3502 error = ENOPROTOOPT;
3505 case SCTP_PLUGGABLE_CC:
3507 struct sctp_assoc_value *av;
3508 struct sctp_nets *net;
3510 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3511 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3512 (av->assoc_value != SCTP_CC_HSTCP) &&
3513 (av->assoc_value != SCTP_CC_HTCP) &&
3514 (av->assoc_value != SCTP_CC_RTCC)) {
3515 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3519 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3521 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3522 stcb->asoc.congestion_control_module = av->assoc_value;
3523 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3524 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3525 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3528 SCTP_TCB_UNLOCK(stcb);
3530 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3531 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3532 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3533 (av->assoc_id == SCTP_ALL_ASSOC)) {
3534 SCTP_INP_WLOCK(inp);
3535 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3536 SCTP_INP_WUNLOCK(inp);
3538 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3539 (av->assoc_id == SCTP_ALL_ASSOC)) {
3540 SCTP_INP_RLOCK(inp);
3541 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3542 SCTP_TCB_LOCK(stcb);
3543 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3544 stcb->asoc.congestion_control_module = av->assoc_value;
3545 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3546 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3547 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3550 SCTP_TCB_UNLOCK(stcb);
3552 SCTP_INP_RUNLOCK(inp);
3557 case SCTP_CC_OPTION:
3559 struct sctp_cc_option *cc_opt;
3561 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
3562 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
3564 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
3565 SCTP_INP_RLOCK(inp);
3566 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3567 SCTP_TCB_LOCK(stcb);
3568 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
3569 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
3571 SCTP_TCB_UNLOCK(stcb);
3573 SCTP_INP_RUNLOCK(inp);
3578 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
3581 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
3584 SCTP_TCB_UNLOCK(stcb);
3588 case SCTP_PLUGGABLE_SS:
3590 struct sctp_assoc_value *av;
3592 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3593 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
3594 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
3595 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
3596 (av->assoc_value != SCTP_SS_PRIORITY) &&
3597 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
3598 (av->assoc_value != SCTP_SS_FIRST_COME)) {
3599 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3603 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3605 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3606 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3607 stcb->asoc.stream_scheduling_module = av->assoc_value;
3608 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3609 SCTP_TCB_UNLOCK(stcb);
3611 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3612 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3613 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3614 (av->assoc_id == SCTP_ALL_ASSOC)) {
3615 SCTP_INP_WLOCK(inp);
3616 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
3617 SCTP_INP_WUNLOCK(inp);
3619 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3620 (av->assoc_id == SCTP_ALL_ASSOC)) {
3621 SCTP_INP_RLOCK(inp);
3622 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3623 SCTP_TCB_LOCK(stcb);
3624 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3625 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3626 stcb->asoc.stream_scheduling_module = av->assoc_value;
3627 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3628 SCTP_TCB_UNLOCK(stcb);
3630 SCTP_INP_RUNLOCK(inp);
3637 struct sctp_stream_value *av;
3639 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
3640 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3642 if (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
3643 av->stream_value) < 0) {
3644 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3647 SCTP_TCB_UNLOCK(stcb);
3649 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
3650 SCTP_INP_RLOCK(inp);
3651 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3652 SCTP_TCB_LOCK(stcb);
3653 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
3655 &stcb->asoc.strmout[av->stream_id],
3657 SCTP_TCB_UNLOCK(stcb);
3659 SCTP_INP_RUNLOCK(inp);
3663 * Can't set stream value without
3666 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3672 case SCTP_CLR_STAT_LOG:
3673 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3678 struct sctp_assoc_value *av;
3680 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3681 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3684 stcb->asoc.context = av->assoc_value;
3685 SCTP_TCB_UNLOCK(stcb);
3687 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3688 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3689 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3690 (av->assoc_id == SCTP_ALL_ASSOC)) {
3691 SCTP_INP_WLOCK(inp);
3692 inp->sctp_context = av->assoc_value;
3693 SCTP_INP_WUNLOCK(inp);
3695 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3696 (av->assoc_id == SCTP_ALL_ASSOC)) {
3697 SCTP_INP_RLOCK(inp);
3698 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3699 SCTP_TCB_LOCK(stcb);
3700 stcb->asoc.context = av->assoc_value;
3701 SCTP_TCB_UNLOCK(stcb);
3703 SCTP_INP_RUNLOCK(inp);
3710 uint32_t *default_vrfid;
3712 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
3713 if (*default_vrfid > SCTP_MAX_VRF_ID) {
3714 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3718 inp->def_vrf_id = *default_vrfid;
3721 case SCTP_DEL_VRF_ID:
3723 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3727 case SCTP_ADD_VRF_ID:
3729 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3733 case SCTP_DELAYED_SACK:
3735 struct sctp_sack_info *sack;
3737 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
3738 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
3739 if (sack->sack_delay) {
3740 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
3741 sack->sack_delay = SCTP_MAX_SACK_DELAY;
3742 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
3743 sack->sack_delay = TICKS_TO_MSEC(1);
3747 if (sack->sack_delay) {
3748 stcb->asoc.delayed_ack = sack->sack_delay;
3750 if (sack->sack_freq) {
3751 stcb->asoc.sack_freq = sack->sack_freq;
3753 SCTP_TCB_UNLOCK(stcb);
3755 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3756 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3757 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
3758 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3759 SCTP_INP_WLOCK(inp);
3760 if (sack->sack_delay) {
3761 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
3763 if (sack->sack_freq) {
3764 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
3766 SCTP_INP_WUNLOCK(inp);
3768 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
3769 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3770 SCTP_INP_RLOCK(inp);
3771 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3772 SCTP_TCB_LOCK(stcb);
3773 if (sack->sack_delay) {
3774 stcb->asoc.delayed_ack = sack->sack_delay;
3776 if (sack->sack_freq) {
3777 stcb->asoc.sack_freq = sack->sack_freq;
3779 SCTP_TCB_UNLOCK(stcb);
3781 SCTP_INP_RUNLOCK(inp);
3786 case SCTP_AUTH_CHUNK:
3788 struct sctp_authchunk *sauth;
3790 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
3792 SCTP_INP_WLOCK(inp);
3793 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
3794 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3797 SCTP_INP_WUNLOCK(inp);
3802 struct sctp_authkey *sca;
3803 struct sctp_keyhead *shared_keys;
3804 sctp_sharedkey_t *shared_key;
3805 sctp_key_t *key = NULL;
3808 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
3809 if (sca->sca_keylength == 0) {
3810 size = optsize - sizeof(struct sctp_authkey);
3812 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
3813 size = sca->sca_keylength;
3815 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3820 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
3823 shared_keys = &stcb->asoc.shared_keys;
3824 /* clear the cached keys for this key id */
3825 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3827 * create the new shared key and
3831 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3833 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3835 SCTP_TCB_UNLOCK(stcb);
3839 shared_key = sctp_alloc_sharedkey();
3840 if (shared_key == NULL) {
3842 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3844 SCTP_TCB_UNLOCK(stcb);
3847 shared_key->key = key;
3848 shared_key->keyid = sca->sca_keynumber;
3849 error = sctp_insert_sharedkey(shared_keys, shared_key);
3850 SCTP_TCB_UNLOCK(stcb);
3852 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3853 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3854 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
3855 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3856 SCTP_INP_WLOCK(inp);
3857 shared_keys = &inp->sctp_ep.shared_keys;
3859 * clear the cached keys on all
3860 * assocs for this key id
3862 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
3864 * create the new shared key and
3868 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3870 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3872 SCTP_INP_WUNLOCK(inp);
3876 shared_key = sctp_alloc_sharedkey();
3877 if (shared_key == NULL) {
3879 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3881 SCTP_INP_WUNLOCK(inp);
3884 shared_key->key = key;
3885 shared_key->keyid = sca->sca_keynumber;
3886 error = sctp_insert_sharedkey(shared_keys, shared_key);
3887 SCTP_INP_WUNLOCK(inp);
3889 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
3890 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3891 SCTP_INP_RLOCK(inp);
3892 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3893 SCTP_TCB_LOCK(stcb);
3894 shared_keys = &stcb->asoc.shared_keys;
3896 * clear the cached keys for
3899 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3901 * create the new shared key
3902 * and insert/replace it
3905 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3907 SCTP_TCB_UNLOCK(stcb);
3911 shared_key = sctp_alloc_sharedkey();
3912 if (shared_key == NULL) {
3914 SCTP_TCB_UNLOCK(stcb);
3917 shared_key->key = key;
3918 shared_key->keyid = sca->sca_keynumber;
3919 error = sctp_insert_sharedkey(shared_keys, shared_key);
3920 SCTP_TCB_UNLOCK(stcb);
3922 SCTP_INP_RUNLOCK(inp);
3927 case SCTP_HMAC_IDENT:
3929 struct sctp_hmacalgo *shmac;
3930 sctp_hmaclist_t *hmaclist;
3935 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
3936 if (optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) {
3937 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3941 hmaclist = sctp_alloc_hmaclist(shmac->shmac_number_of_idents);
3942 if (hmaclist == NULL) {
3943 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3947 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
3948 hmacid = shmac->shmac_idents[i];
3949 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
3950 /* invalid HMACs were found */ ;
3951 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3953 sctp_free_hmaclist(hmaclist);
3954 goto sctp_set_hmac_done;
3958 for (i = 0; i < hmaclist->num_algo; i++) {
3959 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
3960 /* already in list */
3965 sctp_free_hmaclist(hmaclist);
3966 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3970 /* set it on the endpoint */
3971 SCTP_INP_WLOCK(inp);
3972 if (inp->sctp_ep.local_hmacs)
3973 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
3974 inp->sctp_ep.local_hmacs = hmaclist;
3975 SCTP_INP_WUNLOCK(inp);
3979 case SCTP_AUTH_ACTIVE_KEY:
3981 struct sctp_authkeyid *scact;
3983 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
3984 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
3986 /* set the active key on the right place */
3988 /* set the active key on the assoc */
3989 if (sctp_auth_setactivekey(stcb,
3990 scact->scact_keynumber)) {
3991 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
3992 SCTP_FROM_SCTP_USRREQ,
3996 SCTP_TCB_UNLOCK(stcb);
3998 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3999 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4000 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4001 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4002 SCTP_INP_WLOCK(inp);
4003 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4004 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4007 SCTP_INP_WUNLOCK(inp);
4009 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4010 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4011 SCTP_INP_RLOCK(inp);
4012 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4013 SCTP_TCB_LOCK(stcb);
4014 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4015 SCTP_TCB_UNLOCK(stcb);
4017 SCTP_INP_RUNLOCK(inp);
4022 case SCTP_AUTH_DELETE_KEY:
4024 struct sctp_authkeyid *scdel;
4026 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4027 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4029 /* delete the key from the right place */
4031 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4032 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4035 SCTP_TCB_UNLOCK(stcb);
4037 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4038 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4039 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4040 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4041 SCTP_INP_WLOCK(inp);
4042 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4043 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4046 SCTP_INP_WUNLOCK(inp);
4048 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4049 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4050 SCTP_INP_RLOCK(inp);
4051 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4052 SCTP_TCB_LOCK(stcb);
4053 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4054 SCTP_TCB_UNLOCK(stcb);
4056 SCTP_INP_RUNLOCK(inp);
4061 case SCTP_AUTH_DEACTIVATE_KEY:
4063 struct sctp_authkeyid *keyid;
4065 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4066 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4068 /* deactivate the key from the right place */
4070 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4071 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4074 SCTP_TCB_UNLOCK(stcb);
4076 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4077 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4078 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4079 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4080 SCTP_INP_WLOCK(inp);
4081 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4082 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4085 SCTP_INP_WUNLOCK(inp);
4087 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4088 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4089 SCTP_INP_RLOCK(inp);
4090 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4091 SCTP_TCB_LOCK(stcb);
4092 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4093 SCTP_TCB_UNLOCK(stcb);
4095 SCTP_INP_RUNLOCK(inp);
4100 case SCTP_ENABLE_STREAM_RESET:
4102 struct sctp_assoc_value *av;
4104 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4105 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4106 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4110 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4112 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4113 SCTP_TCB_UNLOCK(stcb);
4115 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4116 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4117 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4118 (av->assoc_id == SCTP_ALL_ASSOC)) {
4119 SCTP_INP_WLOCK(inp);
4120 inp->local_strreset_support = (uint8_t) av->assoc_value;
4121 SCTP_INP_WUNLOCK(inp);
4123 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4124 (av->assoc_id == SCTP_ALL_ASSOC)) {
4125 SCTP_INP_RLOCK(inp);
4126 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4127 SCTP_TCB_LOCK(stcb);
4128 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4129 SCTP_TCB_UNLOCK(stcb);
4131 SCTP_INP_RUNLOCK(inp);
4136 case SCTP_RESET_STREAMS:
4138 struct sctp_reset_streams *strrst;
4139 int i, send_out = 0;
4142 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4143 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4145 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4149 if (stcb->asoc.peer_supports_strreset == 0) {
4151 * Peer does not support the chunk type.
4153 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4155 SCTP_TCB_UNLOCK(stcb);
4158 if (stcb->asoc.stream_reset_outstanding) {
4159 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4161 SCTP_TCB_UNLOCK(stcb);
4164 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4167 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4170 if ((send_in == 0) && (send_out == 0)) {
4171 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4173 SCTP_TCB_UNLOCK(stcb);
4176 for (i = 0; i < strrst->srs_number_streams; i++) {
4178 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4179 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4184 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4185 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4191 SCTP_TCB_UNLOCK(stcb);
4194 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4195 strrst->srs_stream_list,
4196 send_out, send_in, 0, 0, 0, 0, 0);
4198 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4199 SCTP_TCB_UNLOCK(stcb);
4202 case SCTP_ADD_STREAMS:
4204 struct sctp_add_streams *stradd;
4205 uint8_t addstream = 0;
4206 uint16_t add_o_strmcnt = 0;
4207 uint16_t add_i_strmcnt = 0;
4209 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4210 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4212 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4216 if (stcb->asoc.peer_supports_strreset == 0) {
4218 * Peer does not support the chunk type.
4220 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4222 SCTP_TCB_UNLOCK(stcb);
4225 if (stcb->asoc.stream_reset_outstanding) {
4226 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4228 SCTP_TCB_UNLOCK(stcb);
4231 if ((stradd->sas_outstrms == 0) &&
4232 (stradd->sas_instrms == 0)) {
4236 if (stradd->sas_outstrms) {
4238 /* We allocate here */
4239 add_o_strmcnt = stradd->sas_outstrms;
4240 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4241 /* You can't have more than 64k */
4246 if (stradd->sas_instrms) {
4251 * We allocate inside
4252 * sctp_send_str_reset_req()
4254 add_i_strmcnt = stradd->sas_instrms;
4255 cnt = add_i_strmcnt;
4256 cnt += stcb->asoc.streamincnt;
4257 if (cnt > 0x0000ffff) {
4258 /* You can't have more than 64k */
4262 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4263 /* More than you are allowed */
4268 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4269 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4271 SCTP_TCB_UNLOCK(stcb);
4274 case SCTP_RESET_ASSOC:
4278 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4279 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4281 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4285 if (stcb->asoc.peer_supports_strreset == 0) {
4287 * Peer does not support the chunk type.
4289 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4291 SCTP_TCB_UNLOCK(stcb);
4294 if (stcb->asoc.stream_reset_outstanding) {
4295 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4297 SCTP_TCB_UNLOCK(stcb);
4300 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 1, 0, 0, 0, 0);
4301 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4302 SCTP_TCB_UNLOCK(stcb);
4305 case SCTP_CONNECT_X:
4306 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4307 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4311 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4313 case SCTP_CONNECT_X_DELAYED:
4314 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4315 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4319 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4321 case SCTP_CONNECT_X_COMPLETE:
4323 struct sockaddr *sa;
4324 struct sctp_nets *net;
4326 /* FIXME MT: check correct? */
4327 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4330 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4331 SCTP_INP_RLOCK(inp);
4332 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4334 SCTP_TCB_LOCK(stcb);
4335 net = sctp_findnet(stcb, sa);
4337 SCTP_INP_RUNLOCK(inp);
4340 * We increment here since
4341 * sctp_findassociation_ep_addr() wil do a
4342 * decrement if it finds the stcb as long as
4343 * the locked tcb (last argument) is NOT a
4346 SCTP_INP_INCR_REF(inp);
4347 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
4349 SCTP_INP_DECR_REF(inp);
4354 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4358 if (stcb->asoc.delayed_connection == 1) {
4359 stcb->asoc.delayed_connection = 0;
4360 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4361 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4362 stcb->asoc.primary_destination,
4363 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
4364 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4367 * already expired or did not use delayed
4370 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4373 SCTP_TCB_UNLOCK(stcb);
4376 case SCTP_MAX_BURST:
4380 SCTP_CHECK_AND_CAST(burst, optval, uint8_t, optsize);
4382 SCTP_INP_WLOCK(inp);
4383 inp->sctp_ep.max_burst = *burst;
4384 SCTP_INP_WUNLOCK(inp);
4389 struct sctp_assoc_value *av;
4392 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4393 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4395 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4396 ovh = SCTP_MED_OVERHEAD;
4398 ovh = SCTP_MED_V4_OVERHEAD;
4401 if (av->assoc_value) {
4402 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4404 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4406 SCTP_TCB_UNLOCK(stcb);
4408 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4409 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4410 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4411 SCTP_INP_WLOCK(inp);
4413 * FIXME MT: I think this is not in
4414 * tune with the API ID
4416 if (av->assoc_value) {
4417 inp->sctp_frag_point = (av->assoc_value + ovh);
4419 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4421 SCTP_INP_WUNLOCK(inp);
4423 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4431 struct sctp_event_subscribe *events;
4433 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4435 SCTP_INP_WLOCK(inp);
4436 if (events->sctp_data_io_event) {
4437 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4439 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4442 if (events->sctp_association_event) {
4443 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4445 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4448 if (events->sctp_address_event) {
4449 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4451 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4454 if (events->sctp_send_failure_event) {
4455 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4457 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4460 if (events->sctp_peer_error_event) {
4461 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4463 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4466 if (events->sctp_shutdown_event) {
4467 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4469 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4472 if (events->sctp_partial_delivery_event) {
4473 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4475 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4478 if (events->sctp_adaptation_layer_event) {
4479 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4481 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4484 if (events->sctp_authentication_event) {
4485 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4487 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4490 if (events->sctp_sender_dry_event) {
4491 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
4493 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
4496 if (events->sctp_stream_reset_event) {
4497 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4499 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4501 SCTP_INP_WUNLOCK(inp);
4503 SCTP_INP_RLOCK(inp);
4504 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4505 SCTP_TCB_LOCK(stcb);
4506 if (events->sctp_association_event) {
4507 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4509 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4511 if (events->sctp_address_event) {
4512 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4514 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4516 if (events->sctp_send_failure_event) {
4517 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4519 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4521 if (events->sctp_peer_error_event) {
4522 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4524 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4526 if (events->sctp_shutdown_event) {
4527 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4529 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4531 if (events->sctp_partial_delivery_event) {
4532 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4534 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4536 if (events->sctp_adaptation_layer_event) {
4537 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4539 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4541 if (events->sctp_authentication_event) {
4542 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4544 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4546 if (events->sctp_sender_dry_event) {
4547 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4549 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4551 if (events->sctp_stream_reset_event) {
4552 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4554 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4556 SCTP_TCB_UNLOCK(stcb);
4559 * Send up the sender dry event only for 1-to-1
4562 if (events->sctp_sender_dry_event) {
4563 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4564 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
4565 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4567 SCTP_TCB_LOCK(stcb);
4568 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
4569 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
4570 (stcb->asoc.stream_queue_cnt == 0)) {
4571 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
4573 SCTP_TCB_UNLOCK(stcb);
4577 SCTP_INP_RUNLOCK(inp);
4580 case SCTP_ADAPTATION_LAYER:
4582 struct sctp_setadaptation *adap_bits;
4584 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
4585 SCTP_INP_WLOCK(inp);
4586 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
4587 SCTP_INP_WUNLOCK(inp);
4591 case SCTP_SET_INITIAL_DBG_SEQ:
4595 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
4596 SCTP_INP_WLOCK(inp);
4597 inp->sctp_ep.initial_sequence_debug = *vvv;
4598 SCTP_INP_WUNLOCK(inp);
4602 case SCTP_DEFAULT_SEND_PARAM:
4604 struct sctp_sndrcvinfo *s_info;
4606 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
4607 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
4610 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4611 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4613 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4616 SCTP_TCB_UNLOCK(stcb);
4618 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4619 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4620 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
4621 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4622 SCTP_INP_WLOCK(inp);
4623 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
4624 SCTP_INP_WUNLOCK(inp);
4626 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
4627 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4628 SCTP_INP_RLOCK(inp);
4629 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4630 SCTP_TCB_LOCK(stcb);
4631 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4632 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4634 SCTP_TCB_UNLOCK(stcb);
4636 SCTP_INP_RUNLOCK(inp);
4641 case SCTP_PEER_ADDR_PARAMS:
4643 struct sctp_paddrparams *paddrp;
4644 struct sctp_nets *net;
4646 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
4647 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
4650 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
4653 * We increment here since
4654 * sctp_findassociation_ep_addr() wil do a
4655 * decrement if it finds the stcb as long as
4656 * the locked tcb (last argument) is NOT a
4659 SCTP_INP_INCR_REF(inp);
4660 stcb = sctp_findassociation_ep_addr(&inp,
4661 (struct sockaddr *)&paddrp->spp_address,
4664 SCTP_INP_DECR_REF(inp);
4667 if (stcb && (net == NULL)) {
4668 struct sockaddr *sa;
4670 sa = (struct sockaddr *)&paddrp->spp_address;
4672 if (sa->sa_family == AF_INET) {
4674 struct sockaddr_in *sin;
4676 sin = (struct sockaddr_in *)sa;
4677 if (sin->sin_addr.s_addr) {
4678 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4679 SCTP_TCB_UNLOCK(stcb);
4686 if (sa->sa_family == AF_INET6) {
4687 struct sockaddr_in6 *sin6;
4689 sin6 = (struct sockaddr_in6 *)sa;
4690 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
4691 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4692 SCTP_TCB_UNLOCK(stcb);
4699 error = EAFNOSUPPORT;
4700 SCTP_TCB_UNLOCK(stcb);
4701 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4706 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
4708 SCTP_TCB_UNLOCK(stcb);
4709 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4712 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
4714 SCTP_TCB_UNLOCK(stcb);
4715 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4719 /************************TCB SPECIFIC SET ******************/
4721 * do we change the timer for HB, we run
4726 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4727 ovh = SCTP_MED_OVERHEAD;
4729 ovh = SCTP_MED_V4_OVERHEAD;
4732 /* network sets ? */
4734 /************************NET SPECIFIC SET ******************/
4735 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4736 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
4737 !(net->dest_state & SCTP_ADDR_NOHB)) {
4738 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4739 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4741 net->dest_state |= SCTP_ADDR_NOHB;
4743 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4744 if (paddrp->spp_hbinterval) {
4745 net->heart_beat_delay = paddrp->spp_hbinterval;
4746 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4747 net->heart_beat_delay = 0;
4749 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4750 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4751 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4752 net->dest_state &= ~SCTP_ADDR_NOHB;
4754 if (paddrp->spp_flags & SPP_HB_DEMAND) {
4756 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4757 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
4758 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4760 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4761 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4762 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4763 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4765 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4766 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4767 net->mtu = paddrp->spp_pathmtu + ovh;
4768 if (net->mtu < stcb->asoc.smallest_mtu) {
4769 sctp_pathmtu_adjustment(stcb, net->mtu);
4773 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4774 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4775 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4777 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4779 if (paddrp->spp_pathmaxrxt) {
4780 if (net->dest_state & SCTP_ADDR_PF) {
4781 if (net->error_count > paddrp->spp_pathmaxrxt) {
4782 net->dest_state &= ~SCTP_ADDR_PF;
4785 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4786 (net->error_count > net->pf_threshold)) {
4787 net->dest_state |= SCTP_ADDR_PF;
4788 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4789 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4790 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4793 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4794 if (net->error_count > paddrp->spp_pathmaxrxt) {
4795 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4796 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
4799 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4800 net->dest_state |= SCTP_ADDR_REACHABLE;
4801 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
4804 net->failure_threshold = paddrp->spp_pathmaxrxt;
4806 if (paddrp->spp_flags & SPP_DSCP) {
4807 net->dscp = paddrp->spp_dscp & 0xfc;
4811 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4812 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4813 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4814 net->flowlabel |= 0x80000000;
4819 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
4820 if (paddrp->spp_pathmaxrxt) {
4821 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
4822 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4823 if (net->dest_state & SCTP_ADDR_PF) {
4824 if (net->error_count > paddrp->spp_pathmaxrxt) {
4825 net->dest_state &= ~SCTP_ADDR_PF;
4828 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4829 (net->error_count > net->pf_threshold)) {
4830 net->dest_state |= SCTP_ADDR_PF;
4831 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4832 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4833 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4836 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4837 if (net->error_count > paddrp->spp_pathmaxrxt) {
4838 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4839 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
4842 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4843 net->dest_state |= SCTP_ADDR_REACHABLE;
4844 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
4847 net->failure_threshold = paddrp->spp_pathmaxrxt;
4850 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4851 if (paddrp->spp_hbinterval) {
4852 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
4853 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4854 stcb->asoc.heart_beat_delay = 0;
4856 /* Turn back on the timer */
4857 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4858 if (paddrp->spp_hbinterval) {
4859 net->heart_beat_delay = paddrp->spp_hbinterval;
4860 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4861 net->heart_beat_delay = 0;
4863 if (net->dest_state & SCTP_ADDR_NOHB) {
4864 net->dest_state &= ~SCTP_ADDR_NOHB;
4866 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4867 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4868 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4870 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4872 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4873 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4874 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
4875 net->dest_state |= SCTP_ADDR_NOHB;
4876 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
4877 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4881 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4883 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4884 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4885 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4886 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4887 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4889 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4890 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4891 net->mtu = paddrp->spp_pathmtu + ovh;
4892 if (net->mtu < stcb->asoc.smallest_mtu) {
4893 sctp_pathmtu_adjustment(stcb, net->mtu);
4897 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4899 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4900 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4901 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4902 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4904 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4906 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4908 if (paddrp->spp_flags & SPP_DSCP) {
4909 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4910 net->dscp = paddrp->spp_dscp & 0xfc;
4913 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
4914 stcb->asoc.default_dscp |= 0x01;
4917 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4918 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4919 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4920 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4921 net->flowlabel |= 0x80000000;
4924 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4925 stcb->asoc.default_flowlabel |= 0x80000000;
4929 SCTP_TCB_UNLOCK(stcb);
4931 /************************NO TCB, SET TO default stuff ******************/
4932 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4933 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4934 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
4935 SCTP_INP_WLOCK(inp);
4937 * For the TOS/FLOWLABEL stuff you
4938 * set it with the options on the
4941 if (paddrp->spp_pathmaxrxt) {
4942 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
4944 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
4945 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4946 else if (paddrp->spp_hbinterval) {
4947 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
4948 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
4949 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4951 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4952 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4953 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4954 } else if (paddrp->spp_hbinterval) {
4955 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4957 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4958 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
4959 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4961 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4962 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4963 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
4964 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4966 if (paddrp->spp_flags & SPP_DSCP) {
4967 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
4968 inp->sctp_ep.default_dscp |= 0x01;
4971 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4972 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4973 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4974 inp->sctp_ep.default_flowlabel |= 0x80000000;
4978 SCTP_INP_WUNLOCK(inp);
4980 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4988 struct sctp_rtoinfo *srto;
4989 uint32_t new_init, new_min, new_max;
4991 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
4992 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
4995 if (srto->srto_initial)
4996 new_init = srto->srto_initial;
4998 new_init = stcb->asoc.initial_rto;
5000 new_max = srto->srto_max;
5002 new_max = stcb->asoc.maxrto;
5004 new_min = srto->srto_min;
5006 new_min = stcb->asoc.minrto;
5007 if ((new_min <= new_init) && (new_init <= new_max)) {
5008 stcb->asoc.initial_rto = new_init;
5009 stcb->asoc.maxrto = new_max;
5010 stcb->asoc.minrto = new_min;
5012 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5015 SCTP_TCB_UNLOCK(stcb);
5017 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5018 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5019 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5020 SCTP_INP_WLOCK(inp);
5021 if (srto->srto_initial)
5022 new_init = srto->srto_initial;
5024 new_init = inp->sctp_ep.initial_rto;
5026 new_max = srto->srto_max;
5028 new_max = inp->sctp_ep.sctp_maxrto;
5030 new_min = srto->srto_min;
5032 new_min = inp->sctp_ep.sctp_minrto;
5033 if ((new_min <= new_init) && (new_init <= new_max)) {
5034 inp->sctp_ep.initial_rto = new_init;
5035 inp->sctp_ep.sctp_maxrto = new_max;
5036 inp->sctp_ep.sctp_minrto = new_min;
5038 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5041 SCTP_INP_WUNLOCK(inp);
5043 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5049 case SCTP_ASSOCINFO:
5051 struct sctp_assocparams *sasoc;
5053 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5054 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5055 if (sasoc->sasoc_cookie_life) {
5056 /* boundary check the cookie life */
5057 if (sasoc->sasoc_cookie_life < 1000)
5058 sasoc->sasoc_cookie_life = 1000;
5059 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5060 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5064 if (sasoc->sasoc_asocmaxrxt)
5065 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5066 if (sasoc->sasoc_cookie_life) {
5067 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5069 SCTP_TCB_UNLOCK(stcb);
5071 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5072 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5073 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5074 SCTP_INP_WLOCK(inp);
5075 if (sasoc->sasoc_asocmaxrxt)
5076 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5077 if (sasoc->sasoc_cookie_life) {
5078 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5080 SCTP_INP_WUNLOCK(inp);
5082 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5090 struct sctp_initmsg *sinit;
5092 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5093 SCTP_INP_WLOCK(inp);
5094 if (sinit->sinit_num_ostreams)
5095 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5097 if (sinit->sinit_max_instreams)
5098 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5100 if (sinit->sinit_max_attempts)
5101 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5103 if (sinit->sinit_max_init_timeo)
5104 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5105 SCTP_INP_WUNLOCK(inp);
5108 case SCTP_PRIMARY_ADDR:
5110 struct sctp_setprim *spa;
5111 struct sctp_nets *net;
5113 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5114 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5118 net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
5121 * We increment here since
5122 * sctp_findassociation_ep_addr() wil do a
5123 * decrement if it finds the stcb as long as
5124 * the locked tcb (last argument) is NOT a
5127 SCTP_INP_INCR_REF(inp);
5128 stcb = sctp_findassociation_ep_addr(&inp,
5129 (struct sockaddr *)&spa->ssp_addr,
5132 SCTP_INP_DECR_REF(inp);
5136 if ((stcb) && (net)) {
5137 if ((net != stcb->asoc.primary_destination) &&
5138 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
5139 /* Ok we need to set it */
5140 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5141 if ((stcb->asoc.alternate) &&
5142 (!(net->dest_state & SCTP_ADDR_PF)) &&
5143 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5144 sctp_free_remote_addr(stcb->asoc.alternate);
5145 stcb->asoc.alternate = NULL;
5150 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5154 SCTP_TCB_UNLOCK(stcb);
5158 case SCTP_SET_DYNAMIC_PRIMARY:
5160 union sctp_sockstore *ss;
5162 error = priv_check(curthread,
5163 PRIV_NETINET_RESERVEDPORT);
5167 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5168 /* SUPER USER CHECK? */
5169 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5172 case SCTP_SET_PEER_PRIMARY_ADDR:
5174 struct sctp_setpeerprim *sspp;
5176 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5177 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5179 struct sctp_ifa *ifa;
5181 ifa = sctp_find_ifa_by_addr((struct sockaddr *)&sspp->sspp_addr,
5182 stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5184 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5188 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5190 * Must validate the ifa found is in
5193 struct sctp_laddr *laddr;
5196 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5197 if (laddr->ifa == NULL) {
5198 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5202 if (laddr->ifa == ifa) {
5208 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5213 if (sctp_set_primary_ip_address_sa(stcb,
5214 (struct sockaddr *)&sspp->sspp_addr) != 0) {
5215 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5219 SCTP_TCB_UNLOCK(stcb);
5221 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5226 case SCTP_BINDX_ADD_ADDR:
5228 struct sctp_getaddresses *addrs;
5231 td = (struct thread *)p;
5232 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5235 if (addrs->addr->sa_family == AF_INET) {
5236 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5237 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5241 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5242 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5248 if (addrs->addr->sa_family == AF_INET6) {
5249 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5250 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5254 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5255 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5256 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5262 error = EAFNOSUPPORT;
5265 sctp_bindx_add_address(so, inp, addrs->addr,
5266 addrs->sget_assoc_id, vrf_id,
5270 case SCTP_BINDX_REM_ADDR:
5272 struct sctp_getaddresses *addrs;
5275 td = (struct thread *)p;
5277 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5279 if (addrs->addr->sa_family == AF_INET) {
5280 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5281 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5285 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5286 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5292 if (addrs->addr->sa_family == AF_INET6) {
5293 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5294 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5299 (error = prison_local_ip6(td->td_ucred,
5300 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5301 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5302 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5308 error = EAFNOSUPPORT;
5311 sctp_bindx_delete_address(inp, addrs->addr,
5312 addrs->sget_assoc_id, vrf_id,
5318 struct sctp_event *event;
5319 uint32_t event_type;
5321 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5322 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5323 switch (event->se_type) {
5324 case SCTP_ASSOC_CHANGE:
5325 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5327 case SCTP_PEER_ADDR_CHANGE:
5328 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5330 case SCTP_REMOTE_ERROR:
5331 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5333 case SCTP_SEND_FAILED:
5334 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5336 case SCTP_SHUTDOWN_EVENT:
5337 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5339 case SCTP_ADAPTATION_INDICATION:
5340 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5342 case SCTP_PARTIAL_DELIVERY_EVENT:
5343 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5345 case SCTP_AUTHENTICATION_EVENT:
5346 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5348 case SCTP_STREAM_RESET_EVENT:
5349 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5351 case SCTP_SENDER_DRY_EVENT:
5352 event_type = SCTP_PCB_FLAGS_DRYEVNT;
5354 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
5356 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5359 case SCTP_ASSOC_RESET_EVENT:
5360 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
5362 case SCTP_STREAM_CHANGE_EVENT:
5363 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
5365 case SCTP_SEND_FAILED_EVENT:
5366 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
5370 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5374 if (event_type > 0) {
5377 sctp_stcb_feature_on(inp, stcb, event_type);
5378 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
5379 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5380 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5381 (stcb->asoc.stream_queue_cnt == 0)) {
5382 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5386 sctp_stcb_feature_off(inp, stcb, event_type);
5388 SCTP_TCB_UNLOCK(stcb);
5391 * We don't want to send up a storm
5392 * of events, so return an error for
5395 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
5396 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
5397 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
5398 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
5399 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
5400 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5404 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5405 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5406 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
5407 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5408 SCTP_INP_WLOCK(inp);
5410 sctp_feature_on(inp, event_type);
5412 sctp_feature_off(inp, event_type);
5414 SCTP_INP_WUNLOCK(inp);
5416 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
5417 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5418 SCTP_INP_RLOCK(inp);
5419 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5420 SCTP_TCB_LOCK(stcb);
5422 sctp_stcb_feature_on(inp, stcb, event_type);
5424 sctp_stcb_feature_off(inp, stcb, event_type);
5426 SCTP_TCB_UNLOCK(stcb);
5428 SCTP_INP_RUNLOCK(inp);
5434 case SCTP_RECVRCVINFO:
5438 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5439 SCTP_INP_WLOCK(inp);
5441 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5443 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5445 SCTP_INP_WUNLOCK(inp);
5448 case SCTP_RECVNXTINFO:
5452 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5453 SCTP_INP_WLOCK(inp);
5455 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5457 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5459 SCTP_INP_WUNLOCK(inp);
5462 case SCTP_DEFAULT_SNDINFO:
5464 struct sctp_sndinfo *info;
5467 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
5468 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
5471 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5472 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5473 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5474 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5475 stcb->asoc.def_send.sinfo_flags |= policy;
5476 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5477 stcb->asoc.def_send.sinfo_context = info->snd_context;
5479 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5482 SCTP_TCB_UNLOCK(stcb);
5484 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5485 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5486 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
5487 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5488 SCTP_INP_WLOCK(inp);
5489 inp->def_send.sinfo_stream = info->snd_sid;
5490 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
5491 inp->def_send.sinfo_flags = info->snd_flags;
5492 inp->def_send.sinfo_flags |= policy;
5493 inp->def_send.sinfo_ppid = info->snd_ppid;
5494 inp->def_send.sinfo_context = info->snd_context;
5495 SCTP_INP_WUNLOCK(inp);
5497 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
5498 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5499 SCTP_INP_RLOCK(inp);
5500 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5501 SCTP_TCB_LOCK(stcb);
5502 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5503 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5504 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5505 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5506 stcb->asoc.def_send.sinfo_flags |= policy;
5507 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5508 stcb->asoc.def_send.sinfo_context = info->snd_context;
5510 SCTP_TCB_UNLOCK(stcb);
5512 SCTP_INP_RUNLOCK(inp);
5517 case SCTP_DEFAULT_PRINFO:
5519 struct sctp_default_prinfo *info;
5521 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
5522 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
5524 if (PR_SCTP_INVALID_POLICY(info->pr_policy)) {
5525 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5530 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5531 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5532 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5533 SCTP_TCB_UNLOCK(stcb);
5535 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5536 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5537 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
5538 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5539 SCTP_INP_WLOCK(inp);
5540 inp->def_send.sinfo_flags &= 0xfff0;
5541 inp->def_send.sinfo_flags |= info->pr_policy;
5542 inp->def_send.sinfo_timetolive = info->pr_value;
5543 SCTP_INP_WUNLOCK(inp);
5545 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
5546 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5547 SCTP_INP_RLOCK(inp);
5548 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5549 SCTP_TCB_LOCK(stcb);
5550 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5551 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5552 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5553 SCTP_TCB_UNLOCK(stcb);
5555 SCTP_INP_RUNLOCK(inp);
5560 case SCTP_PEER_ADDR_THLDS:
5561 /* Applies to the specific association */
5563 struct sctp_paddrthlds *thlds;
5564 struct sctp_nets *net;
5566 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
5567 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
5570 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_assoc_id);
5573 * We increment here since
5574 * sctp_findassociation_ep_addr() wil do a
5575 * decrement if it finds the stcb as long as
5576 * the locked tcb (last argument) is NOT a
5579 SCTP_INP_INCR_REF(inp);
5580 stcb = sctp_findassociation_ep_addr(&inp,
5581 (struct sockaddr *)&thlds->spt_assoc_id,
5584 SCTP_INP_DECR_REF(inp);
5587 if (stcb && (net == NULL)) {
5588 struct sockaddr *sa;
5590 sa = (struct sockaddr *)&thlds->spt_assoc_id;
5592 if (sa->sa_family == AF_INET) {
5594 struct sockaddr_in *sin;
5596 sin = (struct sockaddr_in *)sa;
5597 if (sin->sin_addr.s_addr) {
5598 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5599 SCTP_TCB_UNLOCK(stcb);
5606 if (sa->sa_family == AF_INET6) {
5607 struct sockaddr_in6 *sin6;
5609 sin6 = (struct sockaddr_in6 *)sa;
5610 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5611 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5612 SCTP_TCB_UNLOCK(stcb);
5619 error = EAFNOSUPPORT;
5620 SCTP_TCB_UNLOCK(stcb);
5621 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5627 if (net->dest_state & SCTP_ADDR_PF) {
5628 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5629 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5630 net->dest_state &= ~SCTP_ADDR_PF;
5633 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5634 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5635 net->dest_state |= SCTP_ADDR_PF;
5636 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5637 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5638 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5641 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5642 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5643 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5644 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5647 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5648 net->dest_state |= SCTP_ADDR_REACHABLE;
5649 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5652 net->failure_threshold = thlds->spt_pathmaxrxt;
5653 net->pf_threshold = thlds->spt_pathpfthld;
5655 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5656 if (net->dest_state & SCTP_ADDR_PF) {
5657 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5658 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5659 net->dest_state &= ~SCTP_ADDR_PF;
5662 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5663 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5664 net->dest_state |= SCTP_ADDR_PF;
5665 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5666 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5667 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5670 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5671 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5672 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5673 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5676 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5677 net->dest_state |= SCTP_ADDR_REACHABLE;
5678 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5681 net->failure_threshold = thlds->spt_pathmaxrxt;
5682 net->pf_threshold = thlds->spt_pathpfthld;
5684 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
5685 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
5688 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5689 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5690 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
5691 SCTP_INP_WLOCK(inp);
5692 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
5693 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
5694 SCTP_INP_WUNLOCK(inp);
5696 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5702 case SCTP_REMOTE_UDP_ENCAPS_PORT:
5704 struct sctp_udpencaps *encaps;
5705 struct sctp_nets *net;
5707 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
5708 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
5710 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
5713 * We increment here since
5714 * sctp_findassociation_ep_addr() wil do a
5715 * decrement if it finds the stcb as long as
5716 * the locked tcb (last argument) is NOT a
5720 SCTP_INP_INCR_REF(inp);
5721 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
5723 SCTP_INP_DECR_REF(inp);
5726 if (stcb && (net == NULL)) {
5727 struct sockaddr *sa;
5729 sa = (struct sockaddr *)&encaps->sue_address;
5731 if (sa->sa_family == AF_INET) {
5733 struct sockaddr_in *sin;
5735 sin = (struct sockaddr_in *)sa;
5736 if (sin->sin_addr.s_addr) {
5737 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5738 SCTP_TCB_UNLOCK(stcb);
5745 if (sa->sa_family == AF_INET6) {
5746 struct sockaddr_in6 *sin6;
5748 sin6 = (struct sockaddr_in6 *)sa;
5749 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5750 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5751 SCTP_TCB_UNLOCK(stcb);
5758 error = EAFNOSUPPORT;
5759 SCTP_TCB_UNLOCK(stcb);
5760 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5766 net->port = encaps->sue_port;
5768 stcb->asoc.port = encaps->sue_port;
5770 SCTP_TCB_UNLOCK(stcb);
5772 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5773 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5774 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
5775 SCTP_INP_WLOCK(inp);
5776 inp->sctp_ep.port = encaps->sue_port;
5777 SCTP_INP_WUNLOCK(inp);
5779 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5786 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
5787 error = ENOPROTOOPT;
5789 } /* end switch (opt) */
5794 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
5796 void *optval = NULL;
5801 if (sopt->sopt_level != IPPROTO_SCTP) {
5802 /* wrong proto level... send back up to IP */
5804 if (INP_CHECK_SOCKAF(so, AF_INET6))
5805 error = ip6_ctloutput(so, sopt);
5807 #if defined(INET) && defined(INET6)
5811 error = ip_ctloutput(so, sopt);
5815 optsize = sopt->sopt_valsize;
5817 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
5818 if (optval == NULL) {
5819 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
5822 error = sooptcopyin(sopt, optval, optsize, optsize);
5824 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5828 p = (void *)sopt->sopt_td;
5829 if (sopt->sopt_dir == SOPT_SET) {
5830 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
5831 } else if (sopt->sopt_dir == SOPT_GET) {
5832 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
5834 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5837 if ((error == 0) && (optval != NULL)) {
5838 error = sooptcopyout(sopt, optval, optsize);
5839 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5840 } else if (optval != NULL) {
5841 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5849 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
5852 int create_lock_on = 0;
5854 struct sctp_inpcb *inp;
5855 struct sctp_tcb *stcb = NULL;
5857 inp = (struct sctp_inpcb *)so->so_pcb;
5859 /* I made the same as TCP since we are not setup? */
5860 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5861 return (ECONNRESET);
5864 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5867 switch (addr->sa_family) {
5871 struct sockaddr_in6 *sin6p;
5873 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
5874 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5877 sin6p = (struct sockaddr_in6 *)addr;
5878 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
5879 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5888 struct sockaddr_in *sinp;
5890 if (addr->sa_len != sizeof(struct sockaddr_in)) {
5891 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5894 sinp = (struct sockaddr_in *)addr;
5895 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
5896 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5903 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
5904 return (EAFNOSUPPORT);
5906 SCTP_INP_INCR_REF(inp);
5907 SCTP_ASOC_CREATE_LOCK(inp);
5911 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
5912 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
5913 /* Should I really unlock ? */
5914 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
5919 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
5920 (addr->sa_family == AF_INET6)) {
5921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5926 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
5927 SCTP_PCB_FLAGS_UNBOUND) {
5928 /* Bind a ephemeral port */
5929 error = sctp_inpcb_bind(so, NULL, NULL, p);
5934 /* Now do we connect? */
5935 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
5936 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
5937 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5941 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
5942 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
5943 /* We are already connected AND the TCP model */
5944 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
5948 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
5949 SCTP_INP_RLOCK(inp);
5950 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5951 SCTP_INP_RUNLOCK(inp);
5954 * We increment here since sctp_findassociation_ep_addr()
5955 * will do a decrement if it finds the stcb as long as the
5956 * locked tcb (last argument) is NOT a TCB.. aka NULL.
5958 SCTP_INP_INCR_REF(inp);
5959 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
5961 SCTP_INP_DECR_REF(inp);
5963 SCTP_TCB_UNLOCK(stcb);
5967 /* Already have or am bring up an association */
5968 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
5972 vrf_id = inp->def_vrf_id;
5973 /* We are GOOD to go */
5974 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
5976 /* Gak! no memory */
5979 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
5980 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
5981 /* Set the connected flag so we can queue data */
5984 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
5985 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
5987 /* initialize authentication parameters for the assoc */
5988 sctp_initialize_auth_params(inp, stcb);
5990 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
5991 SCTP_TCB_UNLOCK(stcb);
5993 if (create_lock_on) {
5994 SCTP_ASOC_CREATE_UNLOCK(inp);
5996 SCTP_INP_DECR_REF(inp);
6003 sctp_listen(struct socket *so, int backlog, struct thread *p)
6006 * Note this module depends on the protocol processing being called
6007 * AFTER any socket level flags and backlog are applied to the
6008 * socket. The traditional way that the socket flags are applied is
6009 * AFTER protocol processing. We have made a change to the
6010 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
6011 * place if the socket API for SCTP is to work properly.
6015 struct sctp_inpcb *inp;
6017 inp = (struct sctp_inpcb *)so->so_pcb;
6019 /* I made the same as TCP since we are not setup? */
6020 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6021 return (ECONNRESET);
6023 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
6024 /* See if we have a listener */
6025 struct sctp_inpcb *tinp;
6026 union sctp_sockstore store, *sp;
6029 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
6031 struct sctp_laddr *laddr;
6033 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6034 memcpy(&store, &laddr->ifa->address, sizeof(store));
6035 switch (sp->sa.sa_family) {
6038 sp->sin.sin_port = inp->sctp_lport;
6043 sp->sin6.sin6_port = inp->sctp_lport;
6049 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6050 if (tinp && (tinp != inp) &&
6051 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6052 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6053 (tinp->sctp_socket->so_qlimit)) {
6055 * we have a listener already and
6058 SCTP_INP_DECR_REF(tinp);
6059 return (EADDRINUSE);
6061 SCTP_INP_DECR_REF(tinp);
6065 /* Setup a local addr bound all */
6066 memset(&store, 0, sizeof(store));
6067 switch (sp->sa.sa_family) {
6070 store.sin.sin_port = inp->sctp_lport;
6075 sp->sin6.sin6_port = inp->sctp_lport;
6082 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
6083 store.sa.sa_family = AF_INET6;
6084 store.sa.sa_len = sizeof(struct sockaddr_in6);
6088 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
6089 store.sa.sa_family = AF_INET;
6090 store.sa.sa_len = sizeof(struct sockaddr_in);
6093 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6094 if (tinp && (tinp != inp) &&
6095 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6096 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6097 (tinp->sctp_socket->so_qlimit)) {
6099 * we have a listener already and its not
6102 SCTP_INP_DECR_REF(tinp);
6103 return (EADDRINUSE);
6105 SCTP_INP_DECR_REF(inp);
6109 SCTP_INP_RLOCK(inp);
6110 #ifdef SCTP_LOCK_LOGGING
6111 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
6112 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
6116 error = solisten_proto_check(so);
6119 SCTP_INP_RUNLOCK(inp);
6122 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
6123 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
6125 * The unlucky case - We are in the tcp pool with this guy.
6126 * - Someone else is in the main inp slot. - We must move
6127 * this guy (the listener) to the main slot - We must then
6128 * move the guy that was listener to the TCP Pool.
6130 if (sctp_swap_inpcb_for_listen(inp)) {
6134 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6135 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6136 /* We are already connected AND the TCP model */
6138 SCTP_INP_RUNLOCK(inp);
6140 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6141 return (EADDRINUSE);
6143 SCTP_INP_RUNLOCK(inp);
6144 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
6145 /* We must do a bind. */
6147 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
6148 /* bind error, probably perm */
6153 /* It appears for 7.0 and on, we must always call this. */
6154 solisten_proto(so, backlog);
6155 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6156 /* remove the ACCEPTCONN flag for one-to-many sockets */
6157 so->so_options &= ~SO_ACCEPTCONN;
6160 /* turning off listen */
6161 so->so_options &= ~SO_ACCEPTCONN;
6167 static int sctp_defered_wakeup_cnt = 0;
6170 sctp_accept(struct socket *so, struct sockaddr **addr)
6172 struct sctp_tcb *stcb;
6173 struct sctp_inpcb *inp;
6174 union sctp_sockstore store;
6180 inp = (struct sctp_inpcb *)so->so_pcb;
6183 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6184 return (ECONNRESET);
6186 SCTP_INP_RLOCK(inp);
6187 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6188 SCTP_INP_RUNLOCK(inp);
6189 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
6190 return (EOPNOTSUPP);
6192 if (so->so_state & SS_ISDISCONNECTED) {
6193 SCTP_INP_RUNLOCK(inp);
6194 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
6195 return (ECONNABORTED);
6197 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6199 SCTP_INP_RUNLOCK(inp);
6200 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6201 return (ECONNRESET);
6203 SCTP_TCB_LOCK(stcb);
6204 SCTP_INP_RUNLOCK(inp);
6205 store = stcb->asoc.primary_destination->ro._l_addr;
6206 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
6207 SCTP_TCB_UNLOCK(stcb);
6208 switch (store.sa.sa_family) {
6212 struct sockaddr_in *sin;
6214 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6217 sin->sin_family = AF_INET;
6218 sin->sin_len = sizeof(*sin);
6219 sin->sin_port = ((struct sockaddr_in *)&store)->sin_port;
6220 sin->sin_addr = ((struct sockaddr_in *)&store)->sin_addr;
6221 *addr = (struct sockaddr *)sin;
6228 struct sockaddr_in6 *sin6;
6230 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
6233 sin6->sin6_family = AF_INET6;
6234 sin6->sin6_len = sizeof(*sin6);
6235 sin6->sin6_port = ((struct sockaddr_in6 *)&store)->sin6_port;
6237 sin6->sin6_addr = ((struct sockaddr_in6 *)&store)->sin6_addr;
6238 if ((error = sa6_recoverscope(sin6)) != 0) {
6239 SCTP_FREE_SONAME(sin6);
6242 *addr = (struct sockaddr *)sin6;
6250 /* Wake any delayed sleep action */
6251 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
6252 SCTP_INP_WLOCK(inp);
6253 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
6254 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
6255 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
6256 SCTP_INP_WUNLOCK(inp);
6257 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
6258 if (sowriteable(inp->sctp_socket)) {
6259 sowwakeup_locked(inp->sctp_socket);
6261 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
6263 SCTP_INP_WLOCK(inp);
6265 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
6266 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
6267 SCTP_INP_WUNLOCK(inp);
6268 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
6269 if (soreadable(inp->sctp_socket)) {
6270 sctp_defered_wakeup_cnt++;
6271 sorwakeup_locked(inp->sctp_socket);
6273 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
6275 SCTP_INP_WLOCK(inp);
6277 SCTP_INP_WUNLOCK(inp);
6279 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
6280 SCTP_TCB_LOCK(stcb);
6281 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
6288 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
6290 struct sockaddr_in *sin;
6292 struct sctp_inpcb *inp;
6293 struct sctp_ifa *sctp_ifa;
6296 * Do the malloc first in case it blocks.
6298 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6301 sin->sin_family = AF_INET;
6302 sin->sin_len = sizeof(*sin);
6303 inp = (struct sctp_inpcb *)so->so_pcb;
6305 SCTP_FREE_SONAME(sin);
6306 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6307 return (ECONNRESET);
6309 SCTP_INP_RLOCK(inp);
6310 sin->sin_port = inp->sctp_lport;
6311 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
6312 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6313 struct sctp_tcb *stcb;
6314 struct sockaddr_in *sin_a;
6315 struct sctp_nets *net;
6318 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6324 SCTP_TCB_LOCK(stcb);
6325 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6326 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6328 /* this will make coverity happy */
6331 if (sin_a->sin_family == AF_INET) {
6336 if ((!fnd) || (sin_a == NULL)) {
6338 SCTP_TCB_UNLOCK(stcb);
6341 vrf_id = inp->def_vrf_id;
6342 sctp_ifa = sctp_source_address_selection(inp,
6344 (sctp_route_t *) & net->ro,
6347 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
6348 sctp_free_ifa(sctp_ifa);
6350 SCTP_TCB_UNLOCK(stcb);
6352 /* For the bound all case you get back 0 */
6354 sin->sin_addr.s_addr = 0;
6358 /* Take the first IPv4 address in the list */
6359 struct sctp_laddr *laddr;
6362 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6363 if (laddr->ifa->address.sa.sa_family == AF_INET) {
6364 struct sockaddr_in *sin_a;
6366 sin_a = (struct sockaddr_in *)&laddr->ifa->address.sa;
6367 sin->sin_addr = sin_a->sin_addr;
6373 SCTP_FREE_SONAME(sin);
6374 SCTP_INP_RUNLOCK(inp);
6375 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6379 SCTP_INP_RUNLOCK(inp);
6380 (*addr) = (struct sockaddr *)sin;
6385 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
6387 struct sockaddr_in *sin;
6389 struct sockaddr_in *sin_a;
6390 struct sctp_inpcb *inp;
6391 struct sctp_tcb *stcb;
6392 struct sctp_nets *net;
6394 /* Do the malloc first in case it blocks. */
6395 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6398 sin->sin_family = AF_INET;
6399 sin->sin_len = sizeof(*sin);
6401 inp = (struct sctp_inpcb *)so->so_pcb;
6402 if ((inp == NULL) ||
6403 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
6404 /* UDP type and listeners will drop out here */
6405 SCTP_FREE_SONAME(sin);
6406 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
6409 SCTP_INP_RLOCK(inp);
6410 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6412 SCTP_TCB_LOCK(stcb);
6414 SCTP_INP_RUNLOCK(inp);
6416 SCTP_FREE_SONAME(sin);
6417 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6418 return (ECONNRESET);
6421 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6422 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6423 if (sin_a->sin_family == AF_INET) {
6425 sin->sin_port = stcb->rport;
6426 sin->sin_addr = sin_a->sin_addr;
6430 SCTP_TCB_UNLOCK(stcb);
6432 /* No IPv4 address */
6433 SCTP_FREE_SONAME(sin);
6434 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6437 (*addr) = (struct sockaddr *)sin;
6441 struct pr_usrreqs sctp_usrreqs = {
6442 .pru_abort = sctp_abort,
6443 .pru_accept = sctp_accept,
6444 .pru_attach = sctp_attach,
6445 .pru_bind = sctp_bind,
6446 .pru_connect = sctp_connect,
6447 .pru_control = in_control,
6448 .pru_close = sctp_close,
6449 .pru_detach = sctp_close,
6450 .pru_sopoll = sopoll_generic,
6451 .pru_flush = sctp_flush,
6452 .pru_disconnect = sctp_disconnect,
6453 .pru_listen = sctp_listen,
6454 .pru_peeraddr = sctp_peeraddr,
6455 .pru_send = sctp_sendm,
6456 .pru_shutdown = sctp_shutdown,
6457 .pru_sockaddr = sctp_ingetaddr,
6458 .pru_sosend = sctp_sosend,
6459 .pru_soreceive = sctp_soreceive