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;
552 inp = (struct sctp_inpcb *)so->so_pcb;
554 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
558 if ((addr->sa_family != AF_INET) ||
559 (addr->sa_len != sizeof(struct sockaddr_in))) {
560 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
564 return (sctp_inpcb_bind(so, addr, NULL, p));
569 sctp_close(struct socket *so)
571 struct sctp_inpcb *inp;
574 inp = (struct sctp_inpcb *)so->so_pcb;
579 * Inform all the lower layer assoc that we are done.
582 flags = inp->sctp_flags;
583 #ifdef SCTP_LOG_CLOSING
584 sctp_log_closing(inp, NULL, 17);
586 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
587 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
588 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
589 (so->so_rcv.sb_cc > 0)) {
590 #ifdef SCTP_LOG_CLOSING
591 sctp_log_closing(inp, NULL, 13);
593 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
594 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
596 #ifdef SCTP_LOG_CLOSING
597 sctp_log_closing(inp, NULL, 14);
599 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
600 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
603 * The socket is now detached, no matter what the state of
604 * the SCTP association.
607 SCTP_SB_CLEAR(so->so_snd);
609 * same for the rcv ones, they are only here for the
612 SCTP_SB_CLEAR(so->so_rcv);
614 /* Now null out the reference, we are completely detached. */
618 flags = inp->sctp_flags;
619 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
620 goto sctp_must_try_again;
628 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
629 struct mbuf *control, struct thread *p);
633 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
634 struct mbuf *control, struct thread *p)
636 struct sctp_inpcb *inp;
639 inp = (struct sctp_inpcb *)so->so_pcb;
642 sctp_m_freem(control);
645 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
649 /* Got to have an to address if we are NOT a connected socket */
650 if ((addr == NULL) &&
651 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
652 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
654 } else if (addr == NULL) {
655 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
656 error = EDESTADDRREQ;
659 sctp_m_freem(control);
665 if (addr->sa_family != AF_INET) {
666 /* must be a v4 address! */
667 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
670 sctp_m_freem(control);
673 error = EDESTADDRREQ;
678 /* now what about control */
681 SCTP_PRINTF("huh? control set?\n");
682 sctp_m_freem(inp->control);
685 inp->control = control;
689 SCTP_BUF_NEXT(inp->pkt_last) = m;
692 inp->pkt_last = inp->pkt = m;
695 /* FreeBSD uses a flag passed */
696 ((flags & PRUS_MORETOCOME) == 0)
699 * note with the current version this code will only be used
700 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
701 * re-defining sosend to use the sctp_sosend. One can
702 * optionally switch back to this code (by changing back the
703 * definitions) but this is not advisable. This code is used
704 * by FreeBSD when sending a file with sendfile() though.
708 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
718 sctp_disconnect(struct socket *so)
720 struct sctp_inpcb *inp;
722 inp = (struct sctp_inpcb *)so->so_pcb;
724 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
728 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
729 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
730 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
732 SCTP_INP_RUNLOCK(inp);
735 struct sctp_association *asoc;
736 struct sctp_tcb *stcb;
738 stcb = LIST_FIRST(&inp->sctp_asoc_list);
740 SCTP_INP_RUNLOCK(inp);
741 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
746 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
747 /* We are about to be freed, out of here */
748 SCTP_TCB_UNLOCK(stcb);
749 SCTP_INP_RUNLOCK(inp);
752 if (((so->so_options & SO_LINGER) &&
753 (so->so_linger == 0)) ||
754 (so->so_rcv.sb_cc > 0)) {
755 if (SCTP_GET_STATE(asoc) !=
756 SCTP_STATE_COOKIE_WAIT) {
757 /* Left with Data unread */
760 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_DONTWAIT, 1, MT_DATA);
766 struct sctp_paramhdr *ph;
768 ph = mtod(err, struct sctp_paramhdr *);
769 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
770 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
771 ph->param_length = htons(SCTP_BUF_LEN(err));
773 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
774 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
776 SCTP_INP_RUNLOCK(inp);
777 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
778 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
779 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
781 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
782 /* No unlock tcb assoc is gone */
785 if (TAILQ_EMPTY(&asoc->send_queue) &&
786 TAILQ_EMPTY(&asoc->sent_queue) &&
787 (asoc->stream_queue_cnt == 0)) {
788 /* there is nothing queued to send, so done */
789 if (asoc->locked_on_sending) {
792 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
793 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
794 /* only send SHUTDOWN 1st time thru */
795 struct sctp_nets *netp;
797 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
798 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
799 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
801 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
802 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
803 sctp_stop_timers_for_shutdown(stcb);
804 if (stcb->asoc.alternate) {
805 netp = stcb->asoc.alternate;
807 netp = stcb->asoc.primary_destination;
809 sctp_send_shutdown(stcb, netp);
810 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
811 stcb->sctp_ep, stcb, netp);
812 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
813 stcb->sctp_ep, stcb, netp);
814 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
818 * we still got (or just got) data to send,
819 * so set SHUTDOWN_PENDING
822 * XXX sockets draft says that SCTP_EOF
823 * should be sent with no data. currently,
824 * we will allow user data to be sent first
825 * and move to SHUTDOWN-PENDING
827 struct sctp_nets *netp;
829 if (stcb->asoc.alternate) {
830 netp = stcb->asoc.alternate;
832 netp = stcb->asoc.primary_destination;
835 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
836 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
838 if (asoc->locked_on_sending) {
839 /* Locked to send out the data */
840 struct sctp_stream_queue_pending *sp;
842 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
844 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
845 asoc->locked_on_sending->stream_no);
847 if ((sp->length == 0) && (sp->msg_is_complete == 0))
848 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
851 if (TAILQ_EMPTY(&asoc->send_queue) &&
852 TAILQ_EMPTY(&asoc->sent_queue) &&
853 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
857 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
858 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
859 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
860 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
861 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
862 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
863 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
865 SCTP_INP_RUNLOCK(inp);
866 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
869 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
872 soisdisconnecting(so);
873 SCTP_TCB_UNLOCK(stcb);
874 SCTP_INP_RUNLOCK(inp);
879 /* UDP model does not support this */
880 SCTP_INP_RUNLOCK(inp);
881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
887 sctp_flush(struct socket *so, int how)
890 * We will just clear out the values and let subsequent close clear
891 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
892 * they will not be able to read the data, the socket will block
893 * that from happening.
895 struct sctp_inpcb *inp;
897 inp = (struct sctp_inpcb *)so->so_pcb;
899 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
903 /* For the 1 to many model this does nothing */
904 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
905 SCTP_INP_RUNLOCK(inp);
908 SCTP_INP_RUNLOCK(inp);
909 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
911 * First make sure the sb will be happy, we don't use these
912 * except maybe the count
915 SCTP_INP_READ_LOCK(inp);
916 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
917 SCTP_INP_READ_UNLOCK(inp);
918 SCTP_INP_WUNLOCK(inp);
919 so->so_rcv.sb_cc = 0;
920 so->so_rcv.sb_mbcnt = 0;
921 so->so_rcv.sb_mb = NULL;
923 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
925 * First make sure the sb will be happy, we don't use these
926 * except maybe the count
928 so->so_snd.sb_cc = 0;
929 so->so_snd.sb_mbcnt = 0;
930 so->so_snd.sb_mb = NULL;
937 sctp_shutdown(struct socket *so)
939 struct sctp_inpcb *inp;
941 inp = (struct sctp_inpcb *)so->so_pcb;
943 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
947 /* For UDP model this is a invalid call */
948 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
949 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
950 /* Restore the flags that the soshutdown took away. */
951 SOCKBUF_LOCK(&so->so_rcv);
952 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
953 SOCKBUF_UNLOCK(&so->so_rcv);
954 /* This proc will wakeup for read and do nothing (I hope) */
955 SCTP_INP_RUNLOCK(inp);
956 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
960 * Ok if we reach here its the TCP model and it is either a SHUT_WR
961 * or SHUT_RDWR. This means we put the shutdown flag against it.
964 struct sctp_tcb *stcb;
965 struct sctp_association *asoc;
968 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
969 SCTP_INP_RUNLOCK(inp);
974 stcb = LIST_FIRST(&inp->sctp_asoc_list);
977 * Ok we hit the case that the shutdown call was
978 * made after an abort or something. Nothing to do
981 SCTP_INP_RUNLOCK(inp);
986 if (TAILQ_EMPTY(&asoc->send_queue) &&
987 TAILQ_EMPTY(&asoc->sent_queue) &&
988 (asoc->stream_queue_cnt == 0)) {
989 if (asoc->locked_on_sending) {
992 /* there is nothing queued to send, so I'm done... */
993 if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) {
994 /* only send SHUTDOWN the first time through */
995 struct sctp_nets *netp;
997 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
998 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
999 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1001 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
1002 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
1003 sctp_stop_timers_for_shutdown(stcb);
1004 if (stcb->asoc.alternate) {
1005 netp = stcb->asoc.alternate;
1007 netp = stcb->asoc.primary_destination;
1009 sctp_send_shutdown(stcb, netp);
1010 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1011 stcb->sctp_ep, stcb, netp);
1012 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1013 stcb->sctp_ep, stcb, netp);
1014 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
1018 * we still got (or just got) data to send, so set
1021 struct sctp_nets *netp;
1023 if (stcb->asoc.alternate) {
1024 netp = stcb->asoc.alternate;
1026 netp = stcb->asoc.primary_destination;
1029 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1030 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
1033 if (asoc->locked_on_sending) {
1034 /* Locked to send out the data */
1035 struct sctp_stream_queue_pending *sp;
1037 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
1039 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
1040 asoc->locked_on_sending->stream_no);
1042 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
1043 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
1047 if (TAILQ_EMPTY(&asoc->send_queue) &&
1048 TAILQ_EMPTY(&asoc->sent_queue) &&
1049 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1050 struct mbuf *op_err;
1053 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
1054 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
1055 sctp_abort_an_association(stcb->sctp_ep, stcb,
1056 op_err, SCTP_SO_LOCKED);
1059 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1062 SCTP_TCB_UNLOCK(stcb);
1065 SCTP_INP_RUNLOCK(inp);
1070 * copies a "user" presentable address and removes embedded scope, etc.
1071 * returns 0 on success, 1 on error
1074 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1077 struct sockaddr_in6 lsa6;
1079 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1082 memcpy(ss, sa, sa->sa_len);
1089 * NOTE: assumes addr lock is held
1092 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1093 struct sctp_tcb *stcb,
1095 struct sockaddr_storage *sas,
1098 struct sctp_ifn *sctp_ifn;
1099 struct sctp_ifa *sctp_ifa;
1104 int ipv4_local_scope, ipv4_addr_legal;
1108 int local_scope, site_scope, ipv6_addr_legal;
1111 struct sctp_vrf *vrf;
1118 /* Turn on all the appropriate scope */
1119 loopback_scope = stcb->asoc.scope.loopback_scope;
1121 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1122 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1125 local_scope = stcb->asoc.scope.local_scope;
1126 site_scope = stcb->asoc.scope.site_scope;
1127 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1130 /* Use generic values for endpoints. */
1133 ipv4_local_scope = 1;
1139 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1141 ipv6_addr_legal = 1;
1144 if (SCTP_IPV6_V6ONLY(inp)) {
1145 ipv4_addr_legal = 0;
1147 ipv4_addr_legal = 1;
1152 ipv6_addr_legal = 0;
1155 ipv4_addr_legal = 1;
1159 vrf = sctp_find_vrf(vrf_id);
1163 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1164 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1165 if ((loopback_scope == 0) &&
1166 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1167 /* Skip loopback if loopback_scope not set */
1170 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1173 * For the BOUND-ALL case, the list
1174 * associated with a TCB is Always
1175 * considered a reverse list.. i.e.
1176 * it lists addresses that are NOT
1177 * part of the association. If this
1178 * is one of those we must skip it.
1180 if (sctp_is_addr_restricted(stcb,
1185 switch (sctp_ifa->address.sa.sa_family) {
1188 if (ipv4_addr_legal) {
1189 struct sockaddr_in *sin;
1191 sin = (struct sockaddr_in *)&sctp_ifa->address.sa;
1192 if (sin->sin_addr.s_addr == 0) {
1200 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1201 &sin->sin_addr) != 0) {
1204 if ((ipv4_local_scope == 0) &&
1205 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1209 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1210 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1211 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1212 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1213 actual += sizeof(struct sockaddr_in6);
1216 memcpy(sas, sin, sizeof(*sin));
1217 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1218 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1219 actual += sizeof(*sin);
1223 if (actual >= limit) {
1233 if (ipv6_addr_legal) {
1234 struct sockaddr_in6 *sin6;
1236 sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sa;
1237 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1245 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1246 &sin6->sin6_addr) != 0) {
1249 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1250 if (local_scope == 0)
1252 if (sin6->sin6_scope_id == 0) {
1253 if (sa6_recoverscope(sin6) != 0)
1271 if ((site_scope == 0) &&
1272 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1275 memcpy(sas, sin6, sizeof(*sin6));
1276 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1277 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1278 actual += sizeof(*sin6);
1279 if (actual >= limit) {
1294 struct sctp_laddr *laddr;
1296 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1298 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1302 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1304 switch (laddr->ifa->address.sa.sa_family) {
1307 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1312 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1319 sas = (struct sockaddr_storage *)((caddr_t)sas +
1320 laddr->ifa->address.sa.sa_len);
1321 actual += laddr->ifa->address.sa.sa_len;
1322 if (actual >= limit) {
1331 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1332 struct sctp_tcb *stcb,
1334 struct sockaddr_storage *sas)
1338 SCTP_IPI_ADDR_RLOCK();
1339 /* fill up addresses for the endpoint's default vrf */
1340 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1342 SCTP_IPI_ADDR_RUNLOCK();
1347 * NOTE: assumes addr lock is held
1350 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1353 struct sctp_vrf *vrf = NULL;
1356 * In both sub-set bound an bound_all cases we return the MAXIMUM
1357 * number of addresses that you COULD get. In reality the sub-set
1358 * bound may have an exclusion list for a given TCB OR in the
1359 * bound-all case a TCB may NOT include the loopback or other
1360 * addresses as well.
1362 vrf = sctp_find_vrf(vrf_id);
1366 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1367 struct sctp_ifn *sctp_ifn;
1368 struct sctp_ifa *sctp_ifa;
1370 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1371 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1372 /* Count them if they are the right type */
1373 switch (sctp_ifa->address.sa.sa_family) {
1376 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1377 cnt += sizeof(struct sockaddr_in6);
1379 cnt += sizeof(struct sockaddr_in);
1384 cnt += sizeof(struct sockaddr_in6);
1393 struct sctp_laddr *laddr;
1395 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1396 switch (laddr->ifa->address.sa.sa_family) {
1399 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1400 cnt += sizeof(struct sockaddr_in6);
1402 cnt += sizeof(struct sockaddr_in);
1407 cnt += sizeof(struct sockaddr_in6);
1419 sctp_count_max_addresses(struct sctp_inpcb *inp)
1423 SCTP_IPI_ADDR_RLOCK();
1424 /* count addresses for the endpoint's default VRF */
1425 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1426 SCTP_IPI_ADDR_RUNLOCK();
1431 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1432 size_t optsize, void *p, int delay)
1435 int creat_lock_on = 0;
1436 struct sctp_tcb *stcb = NULL;
1437 struct sockaddr *sa;
1438 int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1440 int bad_addresses = 0;
1443 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1445 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1446 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1447 /* We are already connected AND the TCP model */
1448 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1449 return (EADDRINUSE);
1451 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1452 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1453 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1456 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1457 SCTP_INP_RLOCK(inp);
1458 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1459 SCTP_INP_RUNLOCK(inp);
1462 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1465 SCTP_INP_INCR_REF(inp);
1466 SCTP_ASOC_CREATE_LOCK(inp);
1468 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1469 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1470 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1474 totaddrp = (int *)optval;
1475 totaddr = *totaddrp;
1476 sa = (struct sockaddr *)(totaddrp + 1);
1477 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (optsize - sizeof(int)), &bad_addresses);
1478 if ((stcb != NULL) || bad_addresses) {
1479 /* Already have or am bring up an association */
1480 SCTP_ASOC_CREATE_UNLOCK(inp);
1483 SCTP_TCB_UNLOCK(stcb);
1484 if (bad_addresses == 0) {
1485 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1491 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1496 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1498 struct in6pcb *inp6;
1500 inp6 = (struct in6pcb *)inp;
1501 if (SCTP_IPV6_V6ONLY(inp6)) {
1503 * if IPV6_V6ONLY flag, ignore connections destined
1504 * to a v4 addr or v4-mapped addr
1506 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1512 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1513 SCTP_PCB_FLAGS_UNBOUND) {
1514 /* Bind a ephemeral port */
1515 error = sctp_inpcb_bind(so, NULL, NULL, p);
1520 /* FIX ME: do we want to pass in a vrf on the connect call? */
1521 vrf_id = inp->def_vrf_id;
1524 /* We are GOOD to go */
1525 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1529 /* Gak! no memory */
1532 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1533 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1534 /* Set the connected flag so we can queue data */
1537 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1538 /* move to second address */
1539 switch (sa->sa_family) {
1542 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1547 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1555 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1556 /* Fill in the return id */
1558 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1561 a_id = (sctp_assoc_t *) optval;
1562 *a_id = sctp_get_associd(stcb);
1564 /* initialize authentication parameters for the assoc */
1565 sctp_initialize_auth_params(inp, stcb);
1568 /* doing delayed connection */
1569 stcb->asoc.delayed_connection = 1;
1570 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1572 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1573 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1575 SCTP_TCB_UNLOCK(stcb);
1576 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1577 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1578 /* Set the connected flag so we can queue data */
1582 if (creat_lock_on) {
1583 SCTP_ASOC_CREATE_UNLOCK(inp);
1585 SCTP_INP_DECR_REF(inp);
1589 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1590 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1591 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1592 SCTP_INP_RLOCK(inp); \
1593 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1595 SCTP_TCB_LOCK(stcb); \
1597 SCTP_INP_RUNLOCK(inp); \
1598 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1599 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1600 if (stcb == NULL) { \
1601 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1611 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1612 if (size < sizeof(type)) { \
1613 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1617 destp = (type *)srcp; \
1622 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1625 struct sctp_inpcb *inp = NULL;
1627 struct sctp_tcb *stcb = NULL;
1629 if (optval == NULL) {
1630 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1633 inp = (struct sctp_inpcb *)so->so_pcb;
1635 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1642 case SCTP_AUTOCLOSE:
1643 case SCTP_EXPLICIT_EOR:
1644 case SCTP_AUTO_ASCONF:
1645 case SCTP_DISABLE_FRAGMENTS:
1646 case SCTP_I_WANT_MAPPED_V4_ADDR:
1647 case SCTP_USE_EXT_RCVINFO:
1648 SCTP_INP_RLOCK(inp);
1650 case SCTP_DISABLE_FRAGMENTS:
1651 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1653 case SCTP_I_WANT_MAPPED_V4_ADDR:
1654 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1656 case SCTP_AUTO_ASCONF:
1657 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1658 /* only valid for bound all sockets */
1659 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1661 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1666 case SCTP_EXPLICIT_EOR:
1667 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1670 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1672 case SCTP_USE_EXT_RCVINFO:
1673 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1675 case SCTP_AUTOCLOSE:
1676 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1677 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1683 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1684 error = ENOPROTOOPT;
1685 } /* end switch (sopt->sopt_name) */
1686 if (*optsize < sizeof(val)) {
1687 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1691 SCTP_INP_RUNLOCK(inp);
1693 /* return the option value */
1694 *(int *)optval = val;
1695 *optsize = sizeof(val);
1698 case SCTP_GET_PACKET_LOG:
1700 #ifdef SCTP_PACKET_LOGGING
1704 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1705 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1708 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1713 case SCTP_REUSE_PORT:
1717 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1718 /* Can't do this for a 1-m socket */
1722 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1723 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1724 *optsize = sizeof(uint32_t);
1727 case SCTP_PARTIAL_DELIVERY_POINT:
1731 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1732 *value = inp->partial_delivery_point;
1733 *optsize = sizeof(uint32_t);
1736 case SCTP_FRAGMENT_INTERLEAVE:
1740 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1741 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1742 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1743 *value = SCTP_FRAG_LEVEL_2;
1745 *value = SCTP_FRAG_LEVEL_1;
1748 *value = SCTP_FRAG_LEVEL_0;
1750 *optsize = sizeof(uint32_t);
1753 case SCTP_CMT_ON_OFF:
1755 struct sctp_assoc_value *av;
1757 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1758 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1760 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1761 SCTP_TCB_UNLOCK(stcb);
1763 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1764 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1765 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1766 SCTP_INP_RLOCK(inp);
1767 av->assoc_value = inp->sctp_cmt_on_off;
1768 SCTP_INP_RUNLOCK(inp);
1770 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1775 *optsize = sizeof(struct sctp_assoc_value);
1779 case SCTP_PLUGGABLE_CC:
1781 struct sctp_assoc_value *av;
1783 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1784 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1786 av->assoc_value = stcb->asoc.congestion_control_module;
1787 SCTP_TCB_UNLOCK(stcb);
1789 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1790 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1791 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1792 SCTP_INP_RLOCK(inp);
1793 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1794 SCTP_INP_RUNLOCK(inp);
1796 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1801 *optsize = sizeof(struct sctp_assoc_value);
1805 case SCTP_CC_OPTION:
1807 struct sctp_cc_option *cc_opt;
1809 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1810 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1814 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1817 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1818 *optsize = sizeof(struct sctp_cc_option);
1820 SCTP_TCB_UNLOCK(stcb);
1824 case SCTP_PLUGGABLE_SS:
1826 struct sctp_assoc_value *av;
1828 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1829 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1831 av->assoc_value = stcb->asoc.stream_scheduling_module;
1832 SCTP_TCB_UNLOCK(stcb);
1834 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1835 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1836 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1837 SCTP_INP_RLOCK(inp);
1838 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1839 SCTP_INP_RUNLOCK(inp);
1841 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1846 *optsize = sizeof(struct sctp_assoc_value);
1852 struct sctp_stream_value *av;
1854 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1855 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1857 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1858 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1859 &av->stream_value) < 0)) {
1860 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1863 *optsize = sizeof(struct sctp_stream_value);
1865 SCTP_TCB_UNLOCK(stcb);
1868 * Can't get stream value without
1871 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1876 case SCTP_GET_ADDR_LEN:
1878 struct sctp_assoc_value *av;
1880 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1883 if (av->assoc_value == AF_INET) {
1884 av->assoc_value = sizeof(struct sockaddr_in);
1889 if (av->assoc_value == AF_INET6) {
1890 av->assoc_value = sizeof(struct sockaddr_in6);
1895 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1897 *optsize = sizeof(struct sctp_assoc_value);
1901 case SCTP_GET_ASSOC_NUMBER:
1903 uint32_t *value, cnt;
1905 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1907 SCTP_INP_RLOCK(inp);
1908 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1911 SCTP_INP_RUNLOCK(inp);
1913 *optsize = sizeof(uint32_t);
1916 case SCTP_GET_ASSOC_ID_LIST:
1918 struct sctp_assoc_ids *ids;
1919 unsigned int at, limit;
1921 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1923 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1924 SCTP_INP_RLOCK(inp);
1925 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1927 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1930 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1934 SCTP_INP_RUNLOCK(inp);
1936 ids->gaids_number_of_ids = at;
1937 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1943 struct sctp_assoc_value *av;
1945 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1946 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1949 av->assoc_value = stcb->asoc.context;
1950 SCTP_TCB_UNLOCK(stcb);
1952 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1953 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1954 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1955 SCTP_INP_RLOCK(inp);
1956 av->assoc_value = inp->sctp_context;
1957 SCTP_INP_RUNLOCK(inp);
1959 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1964 *optsize = sizeof(struct sctp_assoc_value);
1970 uint32_t *default_vrfid;
1972 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1973 *default_vrfid = inp->def_vrf_id;
1974 *optsize = sizeof(uint32_t);
1977 case SCTP_GET_ASOC_VRF:
1979 struct sctp_assoc_value *id;
1981 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1982 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1985 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1987 id->assoc_value = stcb->asoc.vrf_id;
1988 *optsize = sizeof(struct sctp_assoc_value);
1992 case SCTP_GET_VRF_IDS:
1994 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1998 case SCTP_GET_NONCE_VALUES:
2000 struct sctp_get_nonce_values *gnv;
2002 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
2003 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
2006 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
2007 gnv->gn_local_tag = stcb->asoc.my_vtag;
2008 SCTP_TCB_UNLOCK(stcb);
2009 *optsize = sizeof(struct sctp_get_nonce_values);
2011 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2016 case SCTP_DELAYED_SACK:
2018 struct sctp_sack_info *sack;
2020 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2021 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2023 sack->sack_delay = stcb->asoc.delayed_ack;
2024 sack->sack_freq = stcb->asoc.sack_freq;
2025 SCTP_TCB_UNLOCK(stcb);
2027 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2028 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2029 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2030 SCTP_INP_RLOCK(inp);
2031 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2032 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2033 SCTP_INP_RUNLOCK(inp);
2035 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2040 *optsize = sizeof(struct sctp_sack_info);
2044 case SCTP_GET_SNDBUF_USE:
2046 struct sctp_sockstat *ss;
2048 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2049 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2052 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2053 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2054 stcb->asoc.size_on_all_streams);
2055 SCTP_TCB_UNLOCK(stcb);
2056 *optsize = sizeof(struct sctp_sockstat);
2058 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2063 case SCTP_MAX_BURST:
2065 struct sctp_assoc_value *av;
2067 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2068 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2071 av->assoc_value = stcb->asoc.max_burst;
2072 SCTP_TCB_UNLOCK(stcb);
2074 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2075 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2076 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2077 SCTP_INP_RLOCK(inp);
2078 av->assoc_value = inp->sctp_ep.max_burst;
2079 SCTP_INP_RUNLOCK(inp);
2081 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2086 *optsize = sizeof(struct sctp_assoc_value);
2092 struct sctp_assoc_value *av;
2095 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2096 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2099 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2100 SCTP_TCB_UNLOCK(stcb);
2102 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2103 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2104 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2105 SCTP_INP_RLOCK(inp);
2106 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2107 ovh = SCTP_MED_OVERHEAD;
2109 ovh = SCTP_MED_V4_OVERHEAD;
2111 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2112 av->assoc_value = 0;
2114 av->assoc_value = inp->sctp_frag_point - ovh;
2115 SCTP_INP_RUNLOCK(inp);
2117 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2122 *optsize = sizeof(struct sctp_assoc_value);
2126 case SCTP_GET_STAT_LOG:
2127 error = sctp_fill_stat_log(optval, optsize);
2131 struct sctp_event_subscribe *events;
2133 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2134 memset(events, 0, sizeof(struct sctp_event_subscribe));
2135 SCTP_INP_RLOCK(inp);
2136 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2137 events->sctp_data_io_event = 1;
2139 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2140 events->sctp_association_event = 1;
2142 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2143 events->sctp_address_event = 1;
2145 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2146 events->sctp_send_failure_event = 1;
2148 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2149 events->sctp_peer_error_event = 1;
2151 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2152 events->sctp_shutdown_event = 1;
2154 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2155 events->sctp_partial_delivery_event = 1;
2157 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2158 events->sctp_adaptation_layer_event = 1;
2160 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2161 events->sctp_authentication_event = 1;
2163 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2164 events->sctp_sender_dry_event = 1;
2166 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2167 events->sctp_stream_reset_event = 1;
2168 SCTP_INP_RUNLOCK(inp);
2169 *optsize = sizeof(struct sctp_event_subscribe);
2172 case SCTP_ADAPTATION_LAYER:
2176 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2178 SCTP_INP_RLOCK(inp);
2179 *value = inp->sctp_ep.adaptation_layer_indicator;
2180 SCTP_INP_RUNLOCK(inp);
2181 *optsize = sizeof(uint32_t);
2184 case SCTP_SET_INITIAL_DBG_SEQ:
2188 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2189 SCTP_INP_RLOCK(inp);
2190 *value = inp->sctp_ep.initial_sequence_debug;
2191 SCTP_INP_RUNLOCK(inp);
2192 *optsize = sizeof(uint32_t);
2195 case SCTP_GET_LOCAL_ADDR_SIZE:
2199 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2200 SCTP_INP_RLOCK(inp);
2201 *value = sctp_count_max_addresses(inp);
2202 SCTP_INP_RUNLOCK(inp);
2203 *optsize = sizeof(uint32_t);
2206 case SCTP_GET_REMOTE_ADDR_SIZE:
2210 struct sctp_nets *net;
2212 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2213 /* FIXME MT: change to sctp_assoc_value? */
2214 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2218 /* Count the sizes */
2219 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2220 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2221 size += sizeof(struct sockaddr_in6);
2223 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2226 size += sizeof(struct sockaddr_in);
2231 size += sizeof(struct sockaddr_in6);
2239 SCTP_TCB_UNLOCK(stcb);
2240 *value = (uint32_t) size;
2241 *optsize = sizeof(uint32_t);
2243 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2248 case SCTP_GET_PEER_ADDRESSES:
2250 * Get the address information, an array is passed in to
2251 * fill up we pack it.
2255 struct sockaddr_storage *sas;
2256 struct sctp_nets *net;
2257 struct sctp_getaddresses *saddr;
2259 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2260 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2263 left = (*optsize) - sizeof(struct sctp_getaddresses);
2264 *optsize = sizeof(struct sctp_getaddresses);
2265 sas = (struct sockaddr_storage *)&saddr->addr[0];
2267 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2268 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2269 cpsz = sizeof(struct sockaddr_in6);
2271 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2274 cpsz = sizeof(struct sockaddr_in);
2279 cpsz = sizeof(struct sockaddr_in6);
2291 /* not enough room. */
2294 #if defined(INET) && defined(INET6)
2295 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2296 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
2297 /* Must map the address */
2298 in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
2299 (struct sockaddr_in6 *)sas);
2302 memcpy(sas, &net->ro._l_addr, cpsz);
2303 #if defined(INET) && defined(INET6)
2306 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2308 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2312 SCTP_TCB_UNLOCK(stcb);
2314 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2319 case SCTP_GET_LOCAL_ADDRESSES:
2321 size_t limit, actual;
2322 struct sockaddr_storage *sas;
2323 struct sctp_getaddresses *saddr;
2325 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2326 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2328 sas = (struct sockaddr_storage *)&saddr->addr[0];
2329 limit = *optsize - sizeof(sctp_assoc_t);
2330 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2332 SCTP_TCB_UNLOCK(stcb);
2334 *optsize = sizeof(struct sockaddr_storage) + actual;
2337 case SCTP_PEER_ADDR_PARAMS:
2339 struct sctp_paddrparams *paddrp;
2340 struct sctp_nets *net;
2342 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2343 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2347 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2350 * We increment here since
2351 * sctp_findassociation_ep_addr() wil do a
2352 * decrement if it finds the stcb as long as
2353 * the locked tcb (last argument) is NOT a
2356 SCTP_INP_INCR_REF(inp);
2357 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddrp->spp_address, &net, NULL, NULL);
2359 SCTP_INP_DECR_REF(inp);
2362 if (stcb && (net == NULL)) {
2363 struct sockaddr *sa;
2365 sa = (struct sockaddr *)&paddrp->spp_address;
2367 if (sa->sa_family == AF_INET) {
2368 struct sockaddr_in *sin;
2370 sin = (struct sockaddr_in *)sa;
2371 if (sin->sin_addr.s_addr) {
2373 SCTP_TCB_UNLOCK(stcb);
2374 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2380 if (sa->sa_family == AF_INET6) {
2381 struct sockaddr_in6 *sin6;
2383 sin6 = (struct sockaddr_in6 *)sa;
2384 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2386 SCTP_TCB_UNLOCK(stcb);
2387 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2393 error = EAFNOSUPPORT;
2394 SCTP_TCB_UNLOCK(stcb);
2395 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2400 /* Applies to the specific association */
2401 paddrp->spp_flags = 0;
2405 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2406 ovh = SCTP_MED_OVERHEAD;
2408 ovh = SCTP_MED_V4_OVERHEAD;
2411 paddrp->spp_hbinterval = net->heart_beat_delay;
2412 paddrp->spp_pathmaxrxt = net->failure_threshold;
2413 paddrp->spp_pathmtu = net->mtu - ovh;
2414 /* get flags for HB */
2415 if (net->dest_state & SCTP_ADDR_NOHB) {
2416 paddrp->spp_flags |= SPP_HB_DISABLE;
2418 paddrp->spp_flags |= SPP_HB_ENABLE;
2420 /* get flags for PMTU */
2421 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2422 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2424 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2426 if (net->dscp & 0x01) {
2427 paddrp->spp_dscp = net->dscp & 0xfc;
2428 paddrp->spp_flags |= SPP_DSCP;
2431 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2432 (net->flowlabel & 0x80000000)) {
2433 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2434 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2439 * No destination so return default
2442 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2443 paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
2444 if (stcb->asoc.default_dscp & 0x01) {
2445 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2446 paddrp->spp_flags |= SPP_DSCP;
2449 if (stcb->asoc.default_flowlabel & 0x80000000) {
2450 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2451 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2454 /* default settings should be these */
2455 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2456 paddrp->spp_flags |= SPP_HB_DISABLE;
2458 paddrp->spp_flags |= SPP_HB_ENABLE;
2460 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2461 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2463 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2465 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2467 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2468 SCTP_TCB_UNLOCK(stcb);
2470 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2471 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2472 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2473 /* Use endpoint defaults */
2474 SCTP_INP_RLOCK(inp);
2475 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2476 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2477 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2478 /* get inp's default */
2479 if (inp->sctp_ep.default_dscp & 0x01) {
2480 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2481 paddrp->spp_flags |= SPP_DSCP;
2484 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2485 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2486 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2487 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2490 /* can't return this */
2491 paddrp->spp_pathmtu = 0;
2493 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2494 paddrp->spp_flags |= SPP_HB_ENABLE;
2496 paddrp->spp_flags |= SPP_HB_DISABLE;
2498 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2499 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2501 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2503 SCTP_INP_RUNLOCK(inp);
2505 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2510 *optsize = sizeof(struct sctp_paddrparams);
2514 case SCTP_GET_PEER_ADDR_INFO:
2516 struct sctp_paddrinfo *paddri;
2517 struct sctp_nets *net;
2519 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2520 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2524 net = sctp_findnet(stcb, (struct sockaddr *)&paddri->spinfo_address);
2527 * We increment here since
2528 * sctp_findassociation_ep_addr() wil do a
2529 * decrement if it finds the stcb as long as
2530 * the locked tcb (last argument) is NOT a
2533 SCTP_INP_INCR_REF(inp);
2534 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddri->spinfo_address, &net, NULL, NULL);
2536 SCTP_INP_DECR_REF(inp);
2540 if ((stcb) && (net)) {
2541 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2542 /* It's unconfirmed */
2543 paddri->spinfo_state = SCTP_UNCONFIRMED;
2544 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2546 paddri->spinfo_state = SCTP_ACTIVE;
2549 paddri->spinfo_state = SCTP_INACTIVE;
2551 paddri->spinfo_cwnd = net->cwnd;
2552 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2553 paddri->spinfo_rto = net->RTO;
2554 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2555 paddri->spinfo_mtu = net->mtu;
2556 SCTP_TCB_UNLOCK(stcb);
2557 *optsize = sizeof(struct sctp_paddrinfo);
2560 SCTP_TCB_UNLOCK(stcb);
2562 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2567 case SCTP_PCB_STATUS:
2569 struct sctp_pcbinfo *spcb;
2571 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2572 sctp_fill_pcbinfo(spcb);
2573 *optsize = sizeof(struct sctp_pcbinfo);
2578 struct sctp_nets *net;
2579 struct sctp_status *sstat;
2581 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2582 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2585 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2590 * I think passing the state is fine since
2591 * sctp_constants.h will be available to the user
2594 sstat->sstat_state = stcb->asoc.state;
2595 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2596 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2597 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2599 * We can't include chunks that have been passed to
2600 * the socket layer. Only things in queue.
2602 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2603 stcb->asoc.cnt_on_all_streams);
2606 sstat->sstat_instrms = stcb->asoc.streamincnt;
2607 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2608 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2609 memcpy(&sstat->sstat_primary.spinfo_address,
2610 &stcb->asoc.primary_destination->ro._l_addr,
2611 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2612 net = stcb->asoc.primary_destination;
2613 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2615 * Again the user can get info from sctp_constants.h
2616 * for what the state of the network is.
2618 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2619 /* It's unconfirmed */
2620 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2621 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2623 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2626 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2628 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2629 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2630 sstat->sstat_primary.spinfo_rto = net->RTO;
2631 sstat->sstat_primary.spinfo_mtu = net->mtu;
2632 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2633 SCTP_TCB_UNLOCK(stcb);
2634 *optsize = sizeof(struct sctp_status);
2639 struct sctp_rtoinfo *srto;
2641 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2642 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2645 srto->srto_initial = stcb->asoc.initial_rto;
2646 srto->srto_max = stcb->asoc.maxrto;
2647 srto->srto_min = stcb->asoc.minrto;
2648 SCTP_TCB_UNLOCK(stcb);
2650 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2651 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2652 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2653 SCTP_INP_RLOCK(inp);
2654 srto->srto_initial = inp->sctp_ep.initial_rto;
2655 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2656 srto->srto_min = inp->sctp_ep.sctp_minrto;
2657 SCTP_INP_RUNLOCK(inp);
2659 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2664 *optsize = sizeof(struct sctp_rtoinfo);
2670 struct sctp_timeouts *stimo;
2672 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2673 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2676 stimo->stimo_init = stcb->asoc.timoinit;
2677 stimo->stimo_data = stcb->asoc.timodata;
2678 stimo->stimo_sack = stcb->asoc.timosack;
2679 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2680 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2681 stimo->stimo_cookie = stcb->asoc.timocookie;
2682 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2683 SCTP_TCB_UNLOCK(stcb);
2684 *optsize = sizeof(struct sctp_timeouts);
2686 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2691 case SCTP_ASSOCINFO:
2693 struct sctp_assocparams *sasoc;
2695 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2696 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2699 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2700 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2701 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2702 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2703 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2704 SCTP_TCB_UNLOCK(stcb);
2706 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2707 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2708 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2709 SCTP_INP_RLOCK(inp);
2710 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2711 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2712 sasoc->sasoc_number_peer_destinations = 0;
2713 sasoc->sasoc_peer_rwnd = 0;
2714 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2715 SCTP_INP_RUNLOCK(inp);
2717 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2722 *optsize = sizeof(struct sctp_assocparams);
2726 case SCTP_DEFAULT_SEND_PARAM:
2728 struct sctp_sndrcvinfo *s_info;
2730 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2731 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2734 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2735 SCTP_TCB_UNLOCK(stcb);
2737 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2738 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2739 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2740 SCTP_INP_RLOCK(inp);
2741 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2742 SCTP_INP_RUNLOCK(inp);
2744 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2749 *optsize = sizeof(struct sctp_sndrcvinfo);
2755 struct sctp_initmsg *sinit;
2757 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2758 SCTP_INP_RLOCK(inp);
2759 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2760 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2761 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2762 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2763 SCTP_INP_RUNLOCK(inp);
2764 *optsize = sizeof(struct sctp_initmsg);
2767 case SCTP_PRIMARY_ADDR:
2768 /* we allow a "get" operation on this */
2770 struct sctp_setprim *ssp;
2772 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2773 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2776 /* simply copy out the sockaddr_storage... */
2780 if (len > stcb->asoc.primary_destination->ro._l_addr.sa.sa_len)
2781 len = stcb->asoc.primary_destination->ro._l_addr.sa.sa_len;
2783 memcpy(&ssp->ssp_addr,
2784 &stcb->asoc.primary_destination->ro._l_addr,
2786 SCTP_TCB_UNLOCK(stcb);
2787 *optsize = sizeof(struct sctp_setprim);
2789 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2794 case SCTP_HMAC_IDENT:
2796 struct sctp_hmacalgo *shmac;
2797 sctp_hmaclist_t *hmaclist;
2801 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2803 SCTP_INP_RLOCK(inp);
2804 hmaclist = inp->sctp_ep.local_hmacs;
2805 if (hmaclist == NULL) {
2806 /* no HMACs to return */
2807 *optsize = sizeof(*shmac);
2808 SCTP_INP_RUNLOCK(inp);
2811 /* is there room for all of the hmac ids? */
2812 size = sizeof(*shmac) + (hmaclist->num_algo *
2813 sizeof(shmac->shmac_idents[0]));
2814 if ((size_t)(*optsize) < size) {
2815 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2817 SCTP_INP_RUNLOCK(inp);
2820 /* copy in the list */
2821 shmac->shmac_number_of_idents = hmaclist->num_algo;
2822 for (i = 0; i < hmaclist->num_algo; i++) {
2823 shmac->shmac_idents[i] = hmaclist->hmac[i];
2825 SCTP_INP_RUNLOCK(inp);
2829 case SCTP_AUTH_ACTIVE_KEY:
2831 struct sctp_authkeyid *scact;
2833 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2834 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2837 /* get the active key on the assoc */
2838 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2839 SCTP_TCB_UNLOCK(stcb);
2841 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2842 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2843 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2844 /* get the endpoint active key */
2845 SCTP_INP_RLOCK(inp);
2846 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2847 SCTP_INP_RUNLOCK(inp);
2849 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2854 *optsize = sizeof(struct sctp_authkeyid);
2858 case SCTP_LOCAL_AUTH_CHUNKS:
2860 struct sctp_authchunks *sac;
2861 sctp_auth_chklist_t *chklist = NULL;
2864 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2865 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2868 /* get off the assoc */
2869 chklist = stcb->asoc.local_auth_chunks;
2870 /* is there enough space? */
2871 size = sctp_auth_get_chklist_size(chklist);
2872 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2874 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2876 /* copy in the chunks */
2877 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2878 sac->gauth_number_of_chunks = (uint32_t) size;
2879 *optsize = sizeof(struct sctp_authchunks) + size;
2881 SCTP_TCB_UNLOCK(stcb);
2883 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2884 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2885 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2886 /* get off the endpoint */
2887 SCTP_INP_RLOCK(inp);
2888 chklist = inp->sctp_ep.local_auth_chunks;
2889 /* is there enough space? */
2890 size = sctp_auth_get_chklist_size(chklist);
2891 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2893 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2895 /* copy in the chunks */
2896 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2897 sac->gauth_number_of_chunks = (uint32_t) size;
2898 *optsize = sizeof(struct sctp_authchunks) + size;
2900 SCTP_INP_RUNLOCK(inp);
2902 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2908 case SCTP_PEER_AUTH_CHUNKS:
2910 struct sctp_authchunks *sac;
2911 sctp_auth_chklist_t *chklist = NULL;
2914 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2915 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2918 /* get off the assoc */
2919 chklist = stcb->asoc.peer_auth_chunks;
2920 /* is there enough space? */
2921 size = sctp_auth_get_chklist_size(chklist);
2922 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2924 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2926 /* copy in the chunks */
2927 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2928 sac->gauth_number_of_chunks = (uint32_t) size;
2929 *optsize = sizeof(struct sctp_authchunks) + size;
2931 SCTP_TCB_UNLOCK(stcb);
2933 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2940 struct sctp_event *event;
2941 uint32_t event_type;
2943 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2944 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
2946 switch (event->se_type) {
2947 case SCTP_ASSOC_CHANGE:
2948 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
2950 case SCTP_PEER_ADDR_CHANGE:
2951 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
2953 case SCTP_REMOTE_ERROR:
2954 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
2956 case SCTP_SEND_FAILED:
2957 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
2959 case SCTP_SHUTDOWN_EVENT:
2960 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
2962 case SCTP_ADAPTATION_INDICATION:
2963 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
2965 case SCTP_PARTIAL_DELIVERY_EVENT:
2966 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
2968 case SCTP_AUTHENTICATION_EVENT:
2969 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
2971 case SCTP_STREAM_RESET_EVENT:
2972 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
2974 case SCTP_SENDER_DRY_EVENT:
2975 event_type = SCTP_PCB_FLAGS_DRYEVNT;
2977 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
2979 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
2982 case SCTP_ASSOC_RESET_EVENT:
2983 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
2985 case SCTP_STREAM_CHANGE_EVENT:
2986 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
2988 case SCTP_SEND_FAILED_EVENT:
2989 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
2993 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2997 if (event_type > 0) {
2999 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3000 SCTP_TCB_UNLOCK(stcb);
3002 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3003 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3004 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3005 SCTP_INP_RLOCK(inp);
3006 event->se_on = sctp_is_feature_on(inp, event_type);
3007 SCTP_INP_RUNLOCK(inp);
3009 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3015 *optsize = sizeof(struct sctp_event);
3019 case SCTP_RECVRCVINFO:
3023 if (*optsize < sizeof(int)) {
3024 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3027 SCTP_INP_RLOCK(inp);
3028 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3029 SCTP_INP_RUNLOCK(inp);
3032 /* return the option value */
3033 *(int *)optval = onoff;
3034 *optsize = sizeof(int);
3038 case SCTP_RECVNXTINFO:
3042 if (*optsize < sizeof(int)) {
3043 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3046 SCTP_INP_RLOCK(inp);
3047 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3048 SCTP_INP_RUNLOCK(inp);
3051 /* return the option value */
3052 *(int *)optval = onoff;
3053 *optsize = sizeof(int);
3057 case SCTP_DEFAULT_SNDINFO:
3059 struct sctp_sndinfo *info;
3061 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3062 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3065 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3066 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3067 info->snd_flags &= 0xfff0;
3068 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3069 info->snd_context = stcb->asoc.def_send.sinfo_context;
3070 SCTP_TCB_UNLOCK(stcb);
3072 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3073 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3074 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3075 SCTP_INP_RLOCK(inp);
3076 info->snd_sid = inp->def_send.sinfo_stream;
3077 info->snd_flags = inp->def_send.sinfo_flags;
3078 info->snd_flags &= 0xfff0;
3079 info->snd_ppid = inp->def_send.sinfo_ppid;
3080 info->snd_context = inp->def_send.sinfo_context;
3081 SCTP_INP_RUNLOCK(inp);
3083 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3088 *optsize = sizeof(struct sctp_sndinfo);
3092 case SCTP_DEFAULT_PRINFO:
3094 struct sctp_default_prinfo *info;
3096 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3097 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3100 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3101 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3102 SCTP_TCB_UNLOCK(stcb);
3104 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3105 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3106 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3107 SCTP_INP_RLOCK(inp);
3108 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3109 info->pr_value = inp->def_send.sinfo_timetolive;
3110 SCTP_INP_RUNLOCK(inp);
3112 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3117 *optsize = sizeof(struct sctp_default_prinfo);
3121 case SCTP_PEER_ADDR_THLDS:
3123 struct sctp_paddrthlds *thlds;
3124 struct sctp_nets *net;
3126 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3127 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3131 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_address);
3134 * We increment here since
3135 * sctp_findassociation_ep_addr() wil do a
3136 * decrement if it finds the stcb as long as
3137 * the locked tcb (last argument) is NOT a
3140 SCTP_INP_INCR_REF(inp);
3141 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&thlds->spt_address, &net, NULL, NULL);
3143 SCTP_INP_DECR_REF(inp);
3146 if (stcb && (net == NULL)) {
3147 struct sockaddr *sa;
3149 sa = (struct sockaddr *)&thlds->spt_address;
3151 if (sa->sa_family == AF_INET) {
3152 struct sockaddr_in *sin;
3154 sin = (struct sockaddr_in *)sa;
3155 if (sin->sin_addr.s_addr) {
3157 SCTP_TCB_UNLOCK(stcb);
3158 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3164 if (sa->sa_family == AF_INET6) {
3165 struct sockaddr_in6 *sin6;
3167 sin6 = (struct sockaddr_in6 *)sa;
3168 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3170 SCTP_TCB_UNLOCK(stcb);
3171 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3177 error = EAFNOSUPPORT;
3178 SCTP_TCB_UNLOCK(stcb);
3179 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3185 thlds->spt_pathmaxrxt = net->failure_threshold;
3186 thlds->spt_pathpfthld = net->pf_threshold;
3188 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3189 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3191 thlds->spt_assoc_id = sctp_get_associd(stcb);
3192 SCTP_TCB_UNLOCK(stcb);
3194 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3195 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3196 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3197 /* Use endpoint defaults */
3198 SCTP_INP_RLOCK(inp);
3199 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3200 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3201 SCTP_INP_RUNLOCK(inp);
3203 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3208 *optsize = sizeof(struct sctp_paddrthlds);
3212 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3214 struct sctp_udpencaps *encaps;
3215 struct sctp_nets *net;
3217 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3218 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3221 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
3224 * We increment here since
3225 * sctp_findassociation_ep_addr() wil do a
3226 * decrement if it finds the stcb as long as
3227 * the locked tcb (last argument) is NOT a
3231 SCTP_INP_INCR_REF(inp);
3232 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
3234 SCTP_INP_DECR_REF(inp);
3237 if (stcb && (net == NULL)) {
3238 struct sockaddr *sa;
3240 sa = (struct sockaddr *)&encaps->sue_address;
3242 if (sa->sa_family == AF_INET) {
3243 struct sockaddr_in *sin;
3245 sin = (struct sockaddr_in *)sa;
3246 if (sin->sin_addr.s_addr) {
3248 SCTP_TCB_UNLOCK(stcb);
3249 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3255 if (sa->sa_family == AF_INET6) {
3256 struct sockaddr_in6 *sin6;
3258 sin6 = (struct sockaddr_in6 *)sa;
3259 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3261 SCTP_TCB_UNLOCK(stcb);
3262 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3268 error = EAFNOSUPPORT;
3269 SCTP_TCB_UNLOCK(stcb);
3270 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3276 encaps->sue_port = net->port;
3278 encaps->sue_port = stcb->asoc.port;
3280 SCTP_TCB_UNLOCK(stcb);
3282 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3283 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3284 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3285 SCTP_INP_RLOCK(inp);
3286 encaps->sue_port = inp->sctp_ep.port;
3287 SCTP_INP_RUNLOCK(inp);
3289 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3294 *optsize = sizeof(struct sctp_udpencaps);
3298 case SCTP_ENABLE_STREAM_RESET:
3300 struct sctp_assoc_value *av;
3302 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3303 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3306 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3307 SCTP_TCB_UNLOCK(stcb);
3309 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3310 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3311 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3312 SCTP_INP_RLOCK(inp);
3313 av->assoc_value = (uint32_t) inp->local_strreset_support;
3314 SCTP_INP_RUNLOCK(inp);
3316 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3321 *optsize = sizeof(struct sctp_assoc_value);
3326 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3327 error = ENOPROTOOPT;
3329 } /* end switch (sopt->sopt_name) */
3337 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3342 struct sctp_tcb *stcb = NULL;
3343 struct sctp_inpcb *inp = NULL;
3346 if (optval == NULL) {
3347 SCTP_PRINTF("optval is NULL\n");
3348 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3351 inp = (struct sctp_inpcb *)so->so_pcb;
3353 SCTP_PRINTF("inp is NULL?\n");
3354 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3357 vrf_id = inp->def_vrf_id;
3362 case SCTP_AUTOCLOSE:
3363 case SCTP_AUTO_ASCONF:
3364 case SCTP_EXPLICIT_EOR:
3365 case SCTP_DISABLE_FRAGMENTS:
3366 case SCTP_USE_EXT_RCVINFO:
3367 case SCTP_I_WANT_MAPPED_V4_ADDR:
3368 /* copy in the option value */
3369 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3374 case SCTP_DISABLE_FRAGMENTS:
3375 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3377 case SCTP_AUTO_ASCONF:
3379 * NOTE: we don't really support this flag
3381 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3382 /* only valid for bound all sockets */
3383 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3385 /* forbidden by admin */
3386 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3389 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3391 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3395 case SCTP_EXPLICIT_EOR:
3396 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3398 case SCTP_USE_EXT_RCVINFO:
3399 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3401 case SCTP_I_WANT_MAPPED_V4_ADDR:
3402 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3403 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3405 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3410 set_opt = SCTP_PCB_FLAGS_NODELAY;
3412 case SCTP_AUTOCLOSE:
3413 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3414 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3415 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3418 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3420 * The value is in ticks. Note this does not effect
3421 * old associations, only new ones.
3423 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3426 SCTP_INP_WLOCK(inp);
3428 sctp_feature_on(inp, set_opt);
3430 sctp_feature_off(inp, set_opt);
3432 SCTP_INP_WUNLOCK(inp);
3434 case SCTP_REUSE_PORT:
3436 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3437 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3438 /* Can't set it after we are bound */
3442 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3443 /* Can't do this for a 1-m socket */
3448 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3450 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3453 case SCTP_PARTIAL_DELIVERY_POINT:
3457 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3458 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3459 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3463 inp->partial_delivery_point = *value;
3466 case SCTP_FRAGMENT_INTERLEAVE:
3467 /* not yet until we re-write sctp_recvmsg() */
3471 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3472 if (*level == SCTP_FRAG_LEVEL_2) {
3473 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3474 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3475 } else if (*level == SCTP_FRAG_LEVEL_1) {
3476 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3477 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3478 } else if (*level == SCTP_FRAG_LEVEL_0) {
3479 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3480 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3483 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3488 case SCTP_CMT_ON_OFF:
3489 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3490 struct sctp_assoc_value *av;
3492 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3493 if (av->assoc_value > SCTP_CMT_MAX) {
3494 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3498 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3500 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3501 SCTP_TCB_UNLOCK(stcb);
3503 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3504 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3505 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3506 (av->assoc_id == SCTP_ALL_ASSOC)) {
3507 SCTP_INP_WLOCK(inp);
3508 inp->sctp_cmt_on_off = av->assoc_value;
3509 SCTP_INP_WUNLOCK(inp);
3511 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3512 (av->assoc_id == SCTP_ALL_ASSOC)) {
3513 SCTP_INP_RLOCK(inp);
3514 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3515 SCTP_TCB_LOCK(stcb);
3516 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3517 SCTP_TCB_UNLOCK(stcb);
3519 SCTP_INP_RUNLOCK(inp);
3523 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3524 error = ENOPROTOOPT;
3527 case SCTP_PLUGGABLE_CC:
3529 struct sctp_assoc_value *av;
3530 struct sctp_nets *net;
3532 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3533 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3534 (av->assoc_value != SCTP_CC_HSTCP) &&
3535 (av->assoc_value != SCTP_CC_HTCP) &&
3536 (av->assoc_value != SCTP_CC_RTCC)) {
3537 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3541 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
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 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3553 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3554 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3555 (av->assoc_id == SCTP_ALL_ASSOC)) {
3556 SCTP_INP_WLOCK(inp);
3557 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3558 SCTP_INP_WUNLOCK(inp);
3560 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3561 (av->assoc_id == SCTP_ALL_ASSOC)) {
3562 SCTP_INP_RLOCK(inp);
3563 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3564 SCTP_TCB_LOCK(stcb);
3565 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3566 stcb->asoc.congestion_control_module = av->assoc_value;
3567 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3568 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3569 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3572 SCTP_TCB_UNLOCK(stcb);
3574 SCTP_INP_RUNLOCK(inp);
3579 case SCTP_CC_OPTION:
3581 struct sctp_cc_option *cc_opt;
3583 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
3584 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
3586 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
3587 SCTP_INP_RLOCK(inp);
3588 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3589 SCTP_TCB_LOCK(stcb);
3590 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
3591 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
3593 SCTP_TCB_UNLOCK(stcb);
3595 SCTP_INP_RUNLOCK(inp);
3600 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
3603 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
3606 SCTP_TCB_UNLOCK(stcb);
3610 case SCTP_PLUGGABLE_SS:
3612 struct sctp_assoc_value *av;
3614 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3615 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
3616 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
3617 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
3618 (av->assoc_value != SCTP_SS_PRIORITY) &&
3619 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
3620 (av->assoc_value != SCTP_SS_FIRST_COME)) {
3621 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3625 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3627 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3628 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3629 stcb->asoc.stream_scheduling_module = av->assoc_value;
3630 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3631 SCTP_TCB_UNLOCK(stcb);
3633 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3634 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3635 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3636 (av->assoc_id == SCTP_ALL_ASSOC)) {
3637 SCTP_INP_WLOCK(inp);
3638 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
3639 SCTP_INP_WUNLOCK(inp);
3641 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3642 (av->assoc_id == SCTP_ALL_ASSOC)) {
3643 SCTP_INP_RLOCK(inp);
3644 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3645 SCTP_TCB_LOCK(stcb);
3646 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3647 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3648 stcb->asoc.stream_scheduling_module = av->assoc_value;
3649 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3650 SCTP_TCB_UNLOCK(stcb);
3652 SCTP_INP_RUNLOCK(inp);
3659 struct sctp_stream_value *av;
3661 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
3662 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3664 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
3665 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
3666 av->stream_value) < 0)) {
3667 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3670 SCTP_TCB_UNLOCK(stcb);
3672 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
3673 SCTP_INP_RLOCK(inp);
3674 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3675 SCTP_TCB_LOCK(stcb);
3676 if (av->stream_id < stcb->asoc.streamoutcnt) {
3677 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
3679 &stcb->asoc.strmout[av->stream_id],
3682 SCTP_TCB_UNLOCK(stcb);
3684 SCTP_INP_RUNLOCK(inp);
3688 * Can't set stream value without
3691 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3697 case SCTP_CLR_STAT_LOG:
3698 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3703 struct sctp_assoc_value *av;
3705 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3706 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3709 stcb->asoc.context = av->assoc_value;
3710 SCTP_TCB_UNLOCK(stcb);
3712 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3713 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3714 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3715 (av->assoc_id == SCTP_ALL_ASSOC)) {
3716 SCTP_INP_WLOCK(inp);
3717 inp->sctp_context = av->assoc_value;
3718 SCTP_INP_WUNLOCK(inp);
3720 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3721 (av->assoc_id == SCTP_ALL_ASSOC)) {
3722 SCTP_INP_RLOCK(inp);
3723 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3724 SCTP_TCB_LOCK(stcb);
3725 stcb->asoc.context = av->assoc_value;
3726 SCTP_TCB_UNLOCK(stcb);
3728 SCTP_INP_RUNLOCK(inp);
3735 uint32_t *default_vrfid;
3737 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
3738 if (*default_vrfid > SCTP_MAX_VRF_ID) {
3739 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3743 inp->def_vrf_id = *default_vrfid;
3746 case SCTP_DEL_VRF_ID:
3748 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3752 case SCTP_ADD_VRF_ID:
3754 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3758 case SCTP_DELAYED_SACK:
3760 struct sctp_sack_info *sack;
3762 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
3763 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
3764 if (sack->sack_delay) {
3765 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
3766 sack->sack_delay = SCTP_MAX_SACK_DELAY;
3767 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
3768 sack->sack_delay = TICKS_TO_MSEC(1);
3772 if (sack->sack_delay) {
3773 stcb->asoc.delayed_ack = sack->sack_delay;
3775 if (sack->sack_freq) {
3776 stcb->asoc.sack_freq = sack->sack_freq;
3778 SCTP_TCB_UNLOCK(stcb);
3780 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3781 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3782 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
3783 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3784 SCTP_INP_WLOCK(inp);
3785 if (sack->sack_delay) {
3786 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
3788 if (sack->sack_freq) {
3789 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
3791 SCTP_INP_WUNLOCK(inp);
3793 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
3794 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3795 SCTP_INP_RLOCK(inp);
3796 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3797 SCTP_TCB_LOCK(stcb);
3798 if (sack->sack_delay) {
3799 stcb->asoc.delayed_ack = sack->sack_delay;
3801 if (sack->sack_freq) {
3802 stcb->asoc.sack_freq = sack->sack_freq;
3804 SCTP_TCB_UNLOCK(stcb);
3806 SCTP_INP_RUNLOCK(inp);
3811 case SCTP_AUTH_CHUNK:
3813 struct sctp_authchunk *sauth;
3815 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
3817 SCTP_INP_WLOCK(inp);
3818 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
3819 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3822 SCTP_INP_WUNLOCK(inp);
3827 struct sctp_authkey *sca;
3828 struct sctp_keyhead *shared_keys;
3829 sctp_sharedkey_t *shared_key;
3830 sctp_key_t *key = NULL;
3833 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
3834 if (sca->sca_keylength == 0) {
3835 size = optsize - sizeof(struct sctp_authkey);
3837 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
3838 size = sca->sca_keylength;
3840 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3845 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
3848 shared_keys = &stcb->asoc.shared_keys;
3849 /* clear the cached keys for this key id */
3850 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3852 * create the new shared key and
3856 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3858 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3860 SCTP_TCB_UNLOCK(stcb);
3864 shared_key = sctp_alloc_sharedkey();
3865 if (shared_key == NULL) {
3867 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3869 SCTP_TCB_UNLOCK(stcb);
3872 shared_key->key = key;
3873 shared_key->keyid = sca->sca_keynumber;
3874 error = sctp_insert_sharedkey(shared_keys, shared_key);
3875 SCTP_TCB_UNLOCK(stcb);
3877 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3878 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3879 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
3880 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3881 SCTP_INP_WLOCK(inp);
3882 shared_keys = &inp->sctp_ep.shared_keys;
3884 * clear the cached keys on all
3885 * assocs for this key id
3887 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
3889 * create the new shared key and
3893 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3895 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3897 SCTP_INP_WUNLOCK(inp);
3901 shared_key = sctp_alloc_sharedkey();
3902 if (shared_key == NULL) {
3904 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3906 SCTP_INP_WUNLOCK(inp);
3909 shared_key->key = key;
3910 shared_key->keyid = sca->sca_keynumber;
3911 error = sctp_insert_sharedkey(shared_keys, shared_key);
3912 SCTP_INP_WUNLOCK(inp);
3914 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
3915 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3916 SCTP_INP_RLOCK(inp);
3917 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3918 SCTP_TCB_LOCK(stcb);
3919 shared_keys = &stcb->asoc.shared_keys;
3921 * clear the cached keys for
3924 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3926 * create the new shared key
3927 * and insert/replace it
3930 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3932 SCTP_TCB_UNLOCK(stcb);
3936 shared_key = sctp_alloc_sharedkey();
3937 if (shared_key == NULL) {
3939 SCTP_TCB_UNLOCK(stcb);
3942 shared_key->key = key;
3943 shared_key->keyid = sca->sca_keynumber;
3944 error = sctp_insert_sharedkey(shared_keys, shared_key);
3945 SCTP_TCB_UNLOCK(stcb);
3947 SCTP_INP_RUNLOCK(inp);
3952 case SCTP_HMAC_IDENT:
3954 struct sctp_hmacalgo *shmac;
3955 sctp_hmaclist_t *hmaclist;
3959 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
3960 if (optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) {
3961 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3965 hmaclist = sctp_alloc_hmaclist(shmac->shmac_number_of_idents);
3966 if (hmaclist == NULL) {
3967 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3971 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
3972 hmacid = shmac->shmac_idents[i];
3973 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
3974 /* invalid HMACs were found */ ;
3975 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3977 sctp_free_hmaclist(hmaclist);
3978 goto sctp_set_hmac_done;
3981 for (i = 0; i < hmaclist->num_algo; i++) {
3982 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
3983 /* already in list */
3987 if (i == hmaclist->num_algo) {
3988 /* not found in list */
3989 sctp_free_hmaclist(hmaclist);
3990 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3994 /* set it on the endpoint */
3995 SCTP_INP_WLOCK(inp);
3996 if (inp->sctp_ep.local_hmacs)
3997 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
3998 inp->sctp_ep.local_hmacs = hmaclist;
3999 SCTP_INP_WUNLOCK(inp);
4003 case SCTP_AUTH_ACTIVE_KEY:
4005 struct sctp_authkeyid *scact;
4007 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4008 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4010 /* set the active key on the right place */
4012 /* set the active key on the assoc */
4013 if (sctp_auth_setactivekey(stcb,
4014 scact->scact_keynumber)) {
4015 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4016 SCTP_FROM_SCTP_USRREQ,
4020 SCTP_TCB_UNLOCK(stcb);
4022 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4023 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4024 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4025 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4026 SCTP_INP_WLOCK(inp);
4027 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4028 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4031 SCTP_INP_WUNLOCK(inp);
4033 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4034 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4035 SCTP_INP_RLOCK(inp);
4036 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4037 SCTP_TCB_LOCK(stcb);
4038 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4039 SCTP_TCB_UNLOCK(stcb);
4041 SCTP_INP_RUNLOCK(inp);
4046 case SCTP_AUTH_DELETE_KEY:
4048 struct sctp_authkeyid *scdel;
4050 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4051 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4053 /* delete the key from the right place */
4055 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4056 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4059 SCTP_TCB_UNLOCK(stcb);
4061 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4062 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4063 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4064 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4065 SCTP_INP_WLOCK(inp);
4066 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4067 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4070 SCTP_INP_WUNLOCK(inp);
4072 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4073 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4074 SCTP_INP_RLOCK(inp);
4075 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4076 SCTP_TCB_LOCK(stcb);
4077 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4078 SCTP_TCB_UNLOCK(stcb);
4080 SCTP_INP_RUNLOCK(inp);
4085 case SCTP_AUTH_DEACTIVATE_KEY:
4087 struct sctp_authkeyid *keyid;
4089 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4090 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4092 /* deactivate the key from the right place */
4094 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4095 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4098 SCTP_TCB_UNLOCK(stcb);
4100 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4101 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4102 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4103 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4104 SCTP_INP_WLOCK(inp);
4105 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4106 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4109 SCTP_INP_WUNLOCK(inp);
4111 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4112 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4113 SCTP_INP_RLOCK(inp);
4114 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4115 SCTP_TCB_LOCK(stcb);
4116 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4117 SCTP_TCB_UNLOCK(stcb);
4119 SCTP_INP_RUNLOCK(inp);
4124 case SCTP_ENABLE_STREAM_RESET:
4126 struct sctp_assoc_value *av;
4128 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4129 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4130 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4134 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4136 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4137 SCTP_TCB_UNLOCK(stcb);
4139 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4140 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4141 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4142 (av->assoc_id == SCTP_ALL_ASSOC)) {
4143 SCTP_INP_WLOCK(inp);
4144 inp->local_strreset_support = (uint8_t) av->assoc_value;
4145 SCTP_INP_WUNLOCK(inp);
4147 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4148 (av->assoc_id == SCTP_ALL_ASSOC)) {
4149 SCTP_INP_RLOCK(inp);
4150 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4151 SCTP_TCB_LOCK(stcb);
4152 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4153 SCTP_TCB_UNLOCK(stcb);
4155 SCTP_INP_RUNLOCK(inp);
4160 case SCTP_RESET_STREAMS:
4162 struct sctp_reset_streams *strrst;
4163 int i, send_out = 0;
4166 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4167 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4169 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4173 if (stcb->asoc.peer_supports_strreset == 0) {
4175 * Peer does not support the chunk type.
4177 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4179 SCTP_TCB_UNLOCK(stcb);
4182 if (stcb->asoc.stream_reset_outstanding) {
4183 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4185 SCTP_TCB_UNLOCK(stcb);
4188 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4191 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4194 if ((send_in == 0) && (send_out == 0)) {
4195 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4197 SCTP_TCB_UNLOCK(stcb);
4200 for (i = 0; i < strrst->srs_number_streams; i++) {
4202 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4203 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4208 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4209 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4215 SCTP_TCB_UNLOCK(stcb);
4218 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4219 strrst->srs_stream_list,
4220 send_out, send_in, 0, 0, 0, 0, 0);
4222 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4223 SCTP_TCB_UNLOCK(stcb);
4226 case SCTP_ADD_STREAMS:
4228 struct sctp_add_streams *stradd;
4229 uint8_t addstream = 0;
4230 uint16_t add_o_strmcnt = 0;
4231 uint16_t add_i_strmcnt = 0;
4233 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4234 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4236 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4240 if (stcb->asoc.peer_supports_strreset == 0) {
4242 * Peer does not support the chunk type.
4244 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4246 SCTP_TCB_UNLOCK(stcb);
4249 if (stcb->asoc.stream_reset_outstanding) {
4250 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4252 SCTP_TCB_UNLOCK(stcb);
4255 if ((stradd->sas_outstrms == 0) &&
4256 (stradd->sas_instrms == 0)) {
4260 if (stradd->sas_outstrms) {
4262 /* We allocate here */
4263 add_o_strmcnt = stradd->sas_outstrms;
4264 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4265 /* You can't have more than 64k */
4270 if (stradd->sas_instrms) {
4275 * We allocate inside
4276 * sctp_send_str_reset_req()
4278 add_i_strmcnt = stradd->sas_instrms;
4279 cnt = add_i_strmcnt;
4280 cnt += stcb->asoc.streamincnt;
4281 if (cnt > 0x0000ffff) {
4282 /* You can't have more than 64k */
4286 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4287 /* More than you are allowed */
4292 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4293 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4295 SCTP_TCB_UNLOCK(stcb);
4298 case SCTP_RESET_ASSOC:
4302 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4303 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4305 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4309 if (stcb->asoc.peer_supports_strreset == 0) {
4311 * Peer does not support the chunk type.
4313 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4315 SCTP_TCB_UNLOCK(stcb);
4318 if (stcb->asoc.stream_reset_outstanding) {
4319 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4321 SCTP_TCB_UNLOCK(stcb);
4324 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 1, 0, 0, 0, 0);
4325 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4326 SCTP_TCB_UNLOCK(stcb);
4329 case SCTP_CONNECT_X:
4330 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4331 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4335 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4337 case SCTP_CONNECT_X_DELAYED:
4338 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4339 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4343 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4345 case SCTP_CONNECT_X_COMPLETE:
4347 struct sockaddr *sa;
4348 struct sctp_nets *net;
4350 /* FIXME MT: check correct? */
4351 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4354 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4355 SCTP_INP_RLOCK(inp);
4356 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4358 SCTP_TCB_LOCK(stcb);
4359 net = sctp_findnet(stcb, sa);
4361 SCTP_INP_RUNLOCK(inp);
4364 * We increment here since
4365 * sctp_findassociation_ep_addr() wil do a
4366 * decrement if it finds the stcb as long as
4367 * the locked tcb (last argument) is NOT a
4370 SCTP_INP_INCR_REF(inp);
4371 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
4373 SCTP_INP_DECR_REF(inp);
4378 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4382 if (stcb->asoc.delayed_connection == 1) {
4383 stcb->asoc.delayed_connection = 0;
4384 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4385 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4386 stcb->asoc.primary_destination,
4387 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
4388 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4391 * already expired or did not use delayed
4394 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4397 SCTP_TCB_UNLOCK(stcb);
4400 case SCTP_MAX_BURST:
4402 struct sctp_assoc_value *av;
4404 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4405 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4408 stcb->asoc.max_burst = av->assoc_value;
4409 SCTP_TCB_UNLOCK(stcb);
4411 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4412 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4413 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4414 (av->assoc_id == SCTP_ALL_ASSOC)) {
4415 SCTP_INP_WLOCK(inp);
4416 inp->sctp_ep.max_burst = av->assoc_value;
4417 SCTP_INP_WUNLOCK(inp);
4419 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4420 (av->assoc_id == SCTP_ALL_ASSOC)) {
4421 SCTP_INP_RLOCK(inp);
4422 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4423 SCTP_TCB_LOCK(stcb);
4424 stcb->asoc.max_burst = av->assoc_value;
4425 SCTP_TCB_UNLOCK(stcb);
4427 SCTP_INP_RUNLOCK(inp);
4434 struct sctp_assoc_value *av;
4437 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4438 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4440 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4441 ovh = SCTP_MED_OVERHEAD;
4443 ovh = SCTP_MED_V4_OVERHEAD;
4446 if (av->assoc_value) {
4447 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4449 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4451 SCTP_TCB_UNLOCK(stcb);
4453 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4454 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4455 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4456 SCTP_INP_WLOCK(inp);
4458 * FIXME MT: I think this is not in
4459 * tune with the API ID
4461 if (av->assoc_value) {
4462 inp->sctp_frag_point = (av->assoc_value + ovh);
4464 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4466 SCTP_INP_WUNLOCK(inp);
4468 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4476 struct sctp_event_subscribe *events;
4478 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4480 SCTP_INP_WLOCK(inp);
4481 if (events->sctp_data_io_event) {
4482 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4484 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4487 if (events->sctp_association_event) {
4488 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4490 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4493 if (events->sctp_address_event) {
4494 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4496 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4499 if (events->sctp_send_failure_event) {
4500 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4502 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4505 if (events->sctp_peer_error_event) {
4506 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4508 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4511 if (events->sctp_shutdown_event) {
4512 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4514 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4517 if (events->sctp_partial_delivery_event) {
4518 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4520 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4523 if (events->sctp_adaptation_layer_event) {
4524 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4526 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4529 if (events->sctp_authentication_event) {
4530 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4532 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4535 if (events->sctp_sender_dry_event) {
4536 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
4538 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
4541 if (events->sctp_stream_reset_event) {
4542 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4544 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4546 SCTP_INP_WUNLOCK(inp);
4548 SCTP_INP_RLOCK(inp);
4549 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4550 SCTP_TCB_LOCK(stcb);
4551 if (events->sctp_association_event) {
4552 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4554 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4556 if (events->sctp_address_event) {
4557 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4559 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4561 if (events->sctp_send_failure_event) {
4562 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4564 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4566 if (events->sctp_peer_error_event) {
4567 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4569 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4571 if (events->sctp_shutdown_event) {
4572 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4574 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4576 if (events->sctp_partial_delivery_event) {
4577 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4579 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4581 if (events->sctp_adaptation_layer_event) {
4582 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4584 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4586 if (events->sctp_authentication_event) {
4587 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4589 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4591 if (events->sctp_sender_dry_event) {
4592 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4594 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4596 if (events->sctp_stream_reset_event) {
4597 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4599 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4601 SCTP_TCB_UNLOCK(stcb);
4604 * Send up the sender dry event only for 1-to-1
4607 if (events->sctp_sender_dry_event) {
4608 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4609 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
4610 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4612 SCTP_TCB_LOCK(stcb);
4613 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
4614 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
4615 (stcb->asoc.stream_queue_cnt == 0)) {
4616 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
4618 SCTP_TCB_UNLOCK(stcb);
4622 SCTP_INP_RUNLOCK(inp);
4625 case SCTP_ADAPTATION_LAYER:
4627 struct sctp_setadaptation *adap_bits;
4629 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
4630 SCTP_INP_WLOCK(inp);
4631 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
4632 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
4633 SCTP_INP_WUNLOCK(inp);
4637 case SCTP_SET_INITIAL_DBG_SEQ:
4641 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
4642 SCTP_INP_WLOCK(inp);
4643 inp->sctp_ep.initial_sequence_debug = *vvv;
4644 SCTP_INP_WUNLOCK(inp);
4648 case SCTP_DEFAULT_SEND_PARAM:
4650 struct sctp_sndrcvinfo *s_info;
4652 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
4653 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
4656 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4657 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4659 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4662 SCTP_TCB_UNLOCK(stcb);
4664 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4665 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4666 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
4667 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4668 SCTP_INP_WLOCK(inp);
4669 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
4670 SCTP_INP_WUNLOCK(inp);
4672 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
4673 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4674 SCTP_INP_RLOCK(inp);
4675 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4676 SCTP_TCB_LOCK(stcb);
4677 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4678 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4680 SCTP_TCB_UNLOCK(stcb);
4682 SCTP_INP_RUNLOCK(inp);
4687 case SCTP_PEER_ADDR_PARAMS:
4689 struct sctp_paddrparams *paddrp;
4690 struct sctp_nets *net;
4692 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
4693 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
4696 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
4699 * We increment here since
4700 * sctp_findassociation_ep_addr() wil do a
4701 * decrement if it finds the stcb as long as
4702 * the locked tcb (last argument) is NOT a
4705 SCTP_INP_INCR_REF(inp);
4706 stcb = sctp_findassociation_ep_addr(&inp,
4707 (struct sockaddr *)&paddrp->spp_address,
4710 SCTP_INP_DECR_REF(inp);
4713 if (stcb && (net == NULL)) {
4714 struct sockaddr *sa;
4716 sa = (struct sockaddr *)&paddrp->spp_address;
4718 if (sa->sa_family == AF_INET) {
4720 struct sockaddr_in *sin;
4722 sin = (struct sockaddr_in *)sa;
4723 if (sin->sin_addr.s_addr) {
4724 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4725 SCTP_TCB_UNLOCK(stcb);
4732 if (sa->sa_family == AF_INET6) {
4733 struct sockaddr_in6 *sin6;
4735 sin6 = (struct sockaddr_in6 *)sa;
4736 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
4737 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4738 SCTP_TCB_UNLOCK(stcb);
4745 error = EAFNOSUPPORT;
4746 SCTP_TCB_UNLOCK(stcb);
4747 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4752 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
4754 SCTP_TCB_UNLOCK(stcb);
4755 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4758 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
4760 SCTP_TCB_UNLOCK(stcb);
4761 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4765 /************************TCB SPECIFIC SET ******************/
4767 * do we change the timer for HB, we run
4772 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4773 ovh = SCTP_MED_OVERHEAD;
4775 ovh = SCTP_MED_V4_OVERHEAD;
4778 /* network sets ? */
4780 /************************NET SPECIFIC SET ******************/
4781 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4782 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
4783 !(net->dest_state & SCTP_ADDR_NOHB)) {
4784 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4785 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4787 net->dest_state |= SCTP_ADDR_NOHB;
4789 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4790 if (paddrp->spp_hbinterval) {
4791 net->heart_beat_delay = paddrp->spp_hbinterval;
4792 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4793 net->heart_beat_delay = 0;
4795 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4796 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4797 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4798 net->dest_state &= ~SCTP_ADDR_NOHB;
4800 if (paddrp->spp_flags & SPP_HB_DEMAND) {
4802 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4803 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
4804 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4806 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4807 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4808 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4809 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4811 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4812 net->mtu = paddrp->spp_pathmtu + ovh;
4813 if (net->mtu < stcb->asoc.smallest_mtu) {
4814 sctp_pathmtu_adjustment(stcb, net->mtu);
4817 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4818 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4819 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4821 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4823 if (paddrp->spp_pathmaxrxt) {
4824 if (net->dest_state & SCTP_ADDR_PF) {
4825 if (net->error_count > paddrp->spp_pathmaxrxt) {
4826 net->dest_state &= ~SCTP_ADDR_PF;
4829 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4830 (net->error_count > net->pf_threshold)) {
4831 net->dest_state |= SCTP_ADDR_PF;
4832 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4833 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4834 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4837 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4838 if (net->error_count > paddrp->spp_pathmaxrxt) {
4839 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4840 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
4843 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4844 net->dest_state |= SCTP_ADDR_REACHABLE;
4845 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
4848 net->failure_threshold = paddrp->spp_pathmaxrxt;
4850 if (paddrp->spp_flags & SPP_DSCP) {
4851 net->dscp = paddrp->spp_dscp & 0xfc;
4855 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4856 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4857 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4858 net->flowlabel |= 0x80000000;
4863 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
4864 if (paddrp->spp_pathmaxrxt) {
4865 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
4866 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4867 if (net->dest_state & SCTP_ADDR_PF) {
4868 if (net->error_count > paddrp->spp_pathmaxrxt) {
4869 net->dest_state &= ~SCTP_ADDR_PF;
4872 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4873 (net->error_count > net->pf_threshold)) {
4874 net->dest_state |= SCTP_ADDR_PF;
4875 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4876 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4877 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4880 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4881 if (net->error_count > paddrp->spp_pathmaxrxt) {
4882 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4883 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
4886 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4887 net->dest_state |= SCTP_ADDR_REACHABLE;
4888 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
4891 net->failure_threshold = paddrp->spp_pathmaxrxt;
4894 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4895 if (paddrp->spp_hbinterval) {
4896 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
4897 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4898 stcb->asoc.heart_beat_delay = 0;
4900 /* Turn back on the timer */
4901 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4902 if (paddrp->spp_hbinterval) {
4903 net->heart_beat_delay = paddrp->spp_hbinterval;
4904 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4905 net->heart_beat_delay = 0;
4907 if (net->dest_state & SCTP_ADDR_NOHB) {
4908 net->dest_state &= ~SCTP_ADDR_NOHB;
4910 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4911 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4912 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4914 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4916 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4917 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4918 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
4919 net->dest_state |= SCTP_ADDR_NOHB;
4920 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
4921 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4925 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4927 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4928 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4929 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4930 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4931 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4933 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4934 net->mtu = paddrp->spp_pathmtu + ovh;
4935 if (net->mtu < stcb->asoc.smallest_mtu) {
4936 sctp_pathmtu_adjustment(stcb, net->mtu);
4939 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4941 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4942 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4943 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4944 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4946 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4948 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4950 if (paddrp->spp_flags & SPP_DSCP) {
4951 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4952 net->dscp = paddrp->spp_dscp & 0xfc;
4955 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
4956 stcb->asoc.default_dscp |= 0x01;
4959 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4960 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4961 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4962 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4963 net->flowlabel |= 0x80000000;
4966 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4967 stcb->asoc.default_flowlabel |= 0x80000000;
4971 SCTP_TCB_UNLOCK(stcb);
4973 /************************NO TCB, SET TO default stuff ******************/
4974 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4975 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4976 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
4977 SCTP_INP_WLOCK(inp);
4979 * For the TOS/FLOWLABEL stuff you
4980 * set it with the options on the
4983 if (paddrp->spp_pathmaxrxt) {
4984 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
4986 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
4987 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4988 else if (paddrp->spp_hbinterval) {
4989 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
4990 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
4991 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4993 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4994 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4995 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4996 } else if (paddrp->spp_hbinterval) {
4997 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4999 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5000 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5001 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5003 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5004 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5005 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5006 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5008 if (paddrp->spp_flags & SPP_DSCP) {
5009 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5010 inp->sctp_ep.default_dscp |= 0x01;
5013 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5014 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5015 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5016 inp->sctp_ep.default_flowlabel |= 0x80000000;
5020 SCTP_INP_WUNLOCK(inp);
5022 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5030 struct sctp_rtoinfo *srto;
5031 uint32_t new_init, new_min, new_max;
5033 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5034 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5037 if (srto->srto_initial)
5038 new_init = srto->srto_initial;
5040 new_init = stcb->asoc.initial_rto;
5042 new_max = srto->srto_max;
5044 new_max = stcb->asoc.maxrto;
5046 new_min = srto->srto_min;
5048 new_min = stcb->asoc.minrto;
5049 if ((new_min <= new_init) && (new_init <= new_max)) {
5050 stcb->asoc.initial_rto = new_init;
5051 stcb->asoc.maxrto = new_max;
5052 stcb->asoc.minrto = new_min;
5054 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5057 SCTP_TCB_UNLOCK(stcb);
5059 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5060 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5061 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5062 SCTP_INP_WLOCK(inp);
5063 if (srto->srto_initial)
5064 new_init = srto->srto_initial;
5066 new_init = inp->sctp_ep.initial_rto;
5068 new_max = srto->srto_max;
5070 new_max = inp->sctp_ep.sctp_maxrto;
5072 new_min = srto->srto_min;
5074 new_min = inp->sctp_ep.sctp_minrto;
5075 if ((new_min <= new_init) && (new_init <= new_max)) {
5076 inp->sctp_ep.initial_rto = new_init;
5077 inp->sctp_ep.sctp_maxrto = new_max;
5078 inp->sctp_ep.sctp_minrto = new_min;
5080 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5083 SCTP_INP_WUNLOCK(inp);
5085 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5091 case SCTP_ASSOCINFO:
5093 struct sctp_assocparams *sasoc;
5095 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5096 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5097 if (sasoc->sasoc_cookie_life) {
5098 /* boundary check the cookie life */
5099 if (sasoc->sasoc_cookie_life < 1000)
5100 sasoc->sasoc_cookie_life = 1000;
5101 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5102 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5106 if (sasoc->sasoc_asocmaxrxt)
5107 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5108 if (sasoc->sasoc_cookie_life) {
5109 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5111 SCTP_TCB_UNLOCK(stcb);
5113 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5114 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5115 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5116 SCTP_INP_WLOCK(inp);
5117 if (sasoc->sasoc_asocmaxrxt)
5118 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5119 if (sasoc->sasoc_cookie_life) {
5120 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5122 SCTP_INP_WUNLOCK(inp);
5124 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5132 struct sctp_initmsg *sinit;
5134 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5135 SCTP_INP_WLOCK(inp);
5136 if (sinit->sinit_num_ostreams)
5137 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5139 if (sinit->sinit_max_instreams)
5140 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5142 if (sinit->sinit_max_attempts)
5143 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5145 if (sinit->sinit_max_init_timeo)
5146 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5147 SCTP_INP_WUNLOCK(inp);
5150 case SCTP_PRIMARY_ADDR:
5152 struct sctp_setprim *spa;
5153 struct sctp_nets *net;
5155 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5156 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5160 net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
5163 * We increment here since
5164 * sctp_findassociation_ep_addr() wil do a
5165 * decrement if it finds the stcb as long as
5166 * the locked tcb (last argument) is NOT a
5169 SCTP_INP_INCR_REF(inp);
5170 stcb = sctp_findassociation_ep_addr(&inp,
5171 (struct sockaddr *)&spa->ssp_addr,
5174 SCTP_INP_DECR_REF(inp);
5178 if ((stcb) && (net)) {
5179 if ((net != stcb->asoc.primary_destination) &&
5180 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
5181 /* Ok we need to set it */
5182 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5183 if ((stcb->asoc.alternate) &&
5184 (!(net->dest_state & SCTP_ADDR_PF)) &&
5185 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5186 sctp_free_remote_addr(stcb->asoc.alternate);
5187 stcb->asoc.alternate = NULL;
5192 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5196 SCTP_TCB_UNLOCK(stcb);
5200 case SCTP_SET_DYNAMIC_PRIMARY:
5202 union sctp_sockstore *ss;
5204 error = priv_check(curthread,
5205 PRIV_NETINET_RESERVEDPORT);
5209 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5210 /* SUPER USER CHECK? */
5211 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5214 case SCTP_SET_PEER_PRIMARY_ADDR:
5216 struct sctp_setpeerprim *sspp;
5218 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5219 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5221 struct sctp_ifa *ifa;
5223 ifa = sctp_find_ifa_by_addr((struct sockaddr *)&sspp->sspp_addr,
5224 stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5226 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5230 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5232 * Must validate the ifa found is in
5235 struct sctp_laddr *laddr;
5238 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5239 if (laddr->ifa == NULL) {
5240 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5244 if (laddr->ifa == ifa) {
5250 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5255 switch (sspp->sspp_addr.ss_family) {
5259 struct sockaddr_in *sin;
5261 sin = (struct sockaddr_in *)&sspp->sspp_addr;
5262 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5263 &sin->sin_addr) != 0) {
5264 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5274 struct sockaddr_in6 *sin6;
5276 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5277 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5278 &sin6->sin6_addr) != 0) {
5279 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5287 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5292 if (sctp_set_primary_ip_address_sa(stcb,
5293 (struct sockaddr *)&sspp->sspp_addr) != 0) {
5294 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5298 SCTP_TCB_UNLOCK(stcb);
5300 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5305 case SCTP_BINDX_ADD_ADDR:
5307 struct sctp_getaddresses *addrs;
5310 td = (struct thread *)p;
5311 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5314 if (addrs->addr->sa_family == AF_INET) {
5315 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5316 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5320 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5321 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5327 if (addrs->addr->sa_family == AF_INET6) {
5328 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5329 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5333 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5334 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5335 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5341 error = EAFNOSUPPORT;
5344 sctp_bindx_add_address(so, inp, addrs->addr,
5345 addrs->sget_assoc_id, vrf_id,
5349 case SCTP_BINDX_REM_ADDR:
5351 struct sctp_getaddresses *addrs;
5354 td = (struct thread *)p;
5356 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5358 if (addrs->addr->sa_family == AF_INET) {
5359 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5360 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5364 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5365 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5371 if (addrs->addr->sa_family == AF_INET6) {
5372 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5373 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5378 (error = prison_local_ip6(td->td_ucred,
5379 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5380 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5381 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5387 error = EAFNOSUPPORT;
5390 sctp_bindx_delete_address(inp, addrs->addr,
5391 addrs->sget_assoc_id, vrf_id,
5397 struct sctp_event *event;
5398 uint32_t event_type;
5400 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5401 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5402 switch (event->se_type) {
5403 case SCTP_ASSOC_CHANGE:
5404 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5406 case SCTP_PEER_ADDR_CHANGE:
5407 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5409 case SCTP_REMOTE_ERROR:
5410 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5412 case SCTP_SEND_FAILED:
5413 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5415 case SCTP_SHUTDOWN_EVENT:
5416 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5418 case SCTP_ADAPTATION_INDICATION:
5419 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5421 case SCTP_PARTIAL_DELIVERY_EVENT:
5422 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5424 case SCTP_AUTHENTICATION_EVENT:
5425 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5427 case SCTP_STREAM_RESET_EVENT:
5428 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5430 case SCTP_SENDER_DRY_EVENT:
5431 event_type = SCTP_PCB_FLAGS_DRYEVNT;
5433 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
5435 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5438 case SCTP_ASSOC_RESET_EVENT:
5439 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
5441 case SCTP_STREAM_CHANGE_EVENT:
5442 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
5444 case SCTP_SEND_FAILED_EVENT:
5445 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
5449 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5453 if (event_type > 0) {
5456 sctp_stcb_feature_on(inp, stcb, event_type);
5457 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
5458 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5459 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5460 (stcb->asoc.stream_queue_cnt == 0)) {
5461 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5465 sctp_stcb_feature_off(inp, stcb, event_type);
5467 SCTP_TCB_UNLOCK(stcb);
5470 * We don't want to send up a storm
5471 * of events, so return an error for
5474 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
5475 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
5476 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
5477 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
5478 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
5479 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5483 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5484 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5485 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
5486 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5487 SCTP_INP_WLOCK(inp);
5489 sctp_feature_on(inp, event_type);
5491 sctp_feature_off(inp, event_type);
5493 SCTP_INP_WUNLOCK(inp);
5495 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
5496 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5497 SCTP_INP_RLOCK(inp);
5498 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5499 SCTP_TCB_LOCK(stcb);
5501 sctp_stcb_feature_on(inp, stcb, event_type);
5503 sctp_stcb_feature_off(inp, stcb, event_type);
5505 SCTP_TCB_UNLOCK(stcb);
5507 SCTP_INP_RUNLOCK(inp);
5513 case SCTP_RECVRCVINFO:
5517 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5518 SCTP_INP_WLOCK(inp);
5520 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5522 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5524 SCTP_INP_WUNLOCK(inp);
5527 case SCTP_RECVNXTINFO:
5531 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5532 SCTP_INP_WLOCK(inp);
5534 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5536 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5538 SCTP_INP_WUNLOCK(inp);
5541 case SCTP_DEFAULT_SNDINFO:
5543 struct sctp_sndinfo *info;
5546 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
5547 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
5550 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5551 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5552 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5553 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5554 stcb->asoc.def_send.sinfo_flags |= policy;
5555 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5556 stcb->asoc.def_send.sinfo_context = info->snd_context;
5558 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5561 SCTP_TCB_UNLOCK(stcb);
5563 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5564 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5565 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
5566 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5567 SCTP_INP_WLOCK(inp);
5568 inp->def_send.sinfo_stream = info->snd_sid;
5569 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
5570 inp->def_send.sinfo_flags = info->snd_flags;
5571 inp->def_send.sinfo_flags |= policy;
5572 inp->def_send.sinfo_ppid = info->snd_ppid;
5573 inp->def_send.sinfo_context = info->snd_context;
5574 SCTP_INP_WUNLOCK(inp);
5576 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
5577 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5578 SCTP_INP_RLOCK(inp);
5579 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5580 SCTP_TCB_LOCK(stcb);
5581 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5582 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5583 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5584 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5585 stcb->asoc.def_send.sinfo_flags |= policy;
5586 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5587 stcb->asoc.def_send.sinfo_context = info->snd_context;
5589 SCTP_TCB_UNLOCK(stcb);
5591 SCTP_INP_RUNLOCK(inp);
5596 case SCTP_DEFAULT_PRINFO:
5598 struct sctp_default_prinfo *info;
5600 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
5601 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
5603 if (PR_SCTP_INVALID_POLICY(info->pr_policy)) {
5604 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5609 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5610 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5611 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5612 SCTP_TCB_UNLOCK(stcb);
5614 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5615 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5616 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
5617 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5618 SCTP_INP_WLOCK(inp);
5619 inp->def_send.sinfo_flags &= 0xfff0;
5620 inp->def_send.sinfo_flags |= info->pr_policy;
5621 inp->def_send.sinfo_timetolive = info->pr_value;
5622 SCTP_INP_WUNLOCK(inp);
5624 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
5625 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5626 SCTP_INP_RLOCK(inp);
5627 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5628 SCTP_TCB_LOCK(stcb);
5629 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5630 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5631 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5632 SCTP_TCB_UNLOCK(stcb);
5634 SCTP_INP_RUNLOCK(inp);
5639 case SCTP_PEER_ADDR_THLDS:
5640 /* Applies to the specific association */
5642 struct sctp_paddrthlds *thlds;
5643 struct sctp_nets *net;
5645 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
5646 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
5649 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_address);
5652 * We increment here since
5653 * sctp_findassociation_ep_addr() wil do a
5654 * decrement if it finds the stcb as long as
5655 * the locked tcb (last argument) is NOT a
5658 SCTP_INP_INCR_REF(inp);
5659 stcb = sctp_findassociation_ep_addr(&inp,
5660 (struct sockaddr *)&thlds->spt_address,
5663 SCTP_INP_DECR_REF(inp);
5666 if (stcb && (net == NULL)) {
5667 struct sockaddr *sa;
5669 sa = (struct sockaddr *)&thlds->spt_address;
5671 if (sa->sa_family == AF_INET) {
5673 struct sockaddr_in *sin;
5675 sin = (struct sockaddr_in *)sa;
5676 if (sin->sin_addr.s_addr) {
5677 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5678 SCTP_TCB_UNLOCK(stcb);
5685 if (sa->sa_family == AF_INET6) {
5686 struct sockaddr_in6 *sin6;
5688 sin6 = (struct sockaddr_in6 *)sa;
5689 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5690 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5691 SCTP_TCB_UNLOCK(stcb);
5698 error = EAFNOSUPPORT;
5699 SCTP_TCB_UNLOCK(stcb);
5700 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5706 if (net->dest_state & SCTP_ADDR_PF) {
5707 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5708 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5709 net->dest_state &= ~SCTP_ADDR_PF;
5712 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5713 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5714 net->dest_state |= SCTP_ADDR_PF;
5715 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5716 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5717 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5720 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5721 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5722 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5723 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5726 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5727 net->dest_state |= SCTP_ADDR_REACHABLE;
5728 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5731 net->failure_threshold = thlds->spt_pathmaxrxt;
5732 net->pf_threshold = thlds->spt_pathpfthld;
5734 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5735 if (net->dest_state & SCTP_ADDR_PF) {
5736 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5737 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5738 net->dest_state &= ~SCTP_ADDR_PF;
5741 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5742 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5743 net->dest_state |= SCTP_ADDR_PF;
5744 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5745 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5746 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5749 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5750 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5751 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5752 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5755 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5756 net->dest_state |= SCTP_ADDR_REACHABLE;
5757 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5760 net->failure_threshold = thlds->spt_pathmaxrxt;
5761 net->pf_threshold = thlds->spt_pathpfthld;
5763 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
5764 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
5767 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5768 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5769 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
5770 SCTP_INP_WLOCK(inp);
5771 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
5772 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
5773 SCTP_INP_WUNLOCK(inp);
5775 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5781 case SCTP_REMOTE_UDP_ENCAPS_PORT:
5783 struct sctp_udpencaps *encaps;
5784 struct sctp_nets *net;
5786 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
5787 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
5789 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
5792 * We increment here since
5793 * sctp_findassociation_ep_addr() wil do a
5794 * decrement if it finds the stcb as long as
5795 * the locked tcb (last argument) is NOT a
5799 SCTP_INP_INCR_REF(inp);
5800 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
5802 SCTP_INP_DECR_REF(inp);
5805 if (stcb && (net == NULL)) {
5806 struct sockaddr *sa;
5808 sa = (struct sockaddr *)&encaps->sue_address;
5810 if (sa->sa_family == AF_INET) {
5812 struct sockaddr_in *sin;
5814 sin = (struct sockaddr_in *)sa;
5815 if (sin->sin_addr.s_addr) {
5816 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5817 SCTP_TCB_UNLOCK(stcb);
5824 if (sa->sa_family == AF_INET6) {
5825 struct sockaddr_in6 *sin6;
5827 sin6 = (struct sockaddr_in6 *)sa;
5828 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5829 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5830 SCTP_TCB_UNLOCK(stcb);
5837 error = EAFNOSUPPORT;
5838 SCTP_TCB_UNLOCK(stcb);
5839 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5845 net->port = encaps->sue_port;
5847 stcb->asoc.port = encaps->sue_port;
5849 SCTP_TCB_UNLOCK(stcb);
5851 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5852 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5853 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
5854 SCTP_INP_WLOCK(inp);
5855 inp->sctp_ep.port = encaps->sue_port;
5856 SCTP_INP_WUNLOCK(inp);
5858 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5865 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
5866 error = ENOPROTOOPT;
5868 } /* end switch (opt) */
5873 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
5875 void *optval = NULL;
5880 if (sopt->sopt_level != IPPROTO_SCTP) {
5881 /* wrong proto level... send back up to IP */
5883 if (INP_CHECK_SOCKAF(so, AF_INET6))
5884 error = ip6_ctloutput(so, sopt);
5886 #if defined(INET) && defined(INET6)
5890 error = ip_ctloutput(so, sopt);
5894 optsize = sopt->sopt_valsize;
5896 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
5897 if (optval == NULL) {
5898 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
5901 error = sooptcopyin(sopt, optval, optsize, optsize);
5903 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5907 p = (void *)sopt->sopt_td;
5908 if (sopt->sopt_dir == SOPT_SET) {
5909 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
5910 } else if (sopt->sopt_dir == SOPT_GET) {
5911 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
5913 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5916 if ((error == 0) && (optval != NULL)) {
5917 error = sooptcopyout(sopt, optval, optsize);
5918 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5919 } else if (optval != NULL) {
5920 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5928 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
5931 int create_lock_on = 0;
5933 struct sctp_inpcb *inp;
5934 struct sctp_tcb *stcb = NULL;
5936 inp = (struct sctp_inpcb *)so->so_pcb;
5938 /* I made the same as TCP since we are not setup? */
5939 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5940 return (ECONNRESET);
5943 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5946 switch (addr->sa_family) {
5950 struct sockaddr_in6 *sin6p;
5952 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
5953 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5956 sin6p = (struct sockaddr_in6 *)addr;
5957 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
5958 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5967 struct sockaddr_in *sinp;
5969 if (addr->sa_len != sizeof(struct sockaddr_in)) {
5970 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5973 sinp = (struct sockaddr_in *)addr;
5974 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
5975 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5982 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
5983 return (EAFNOSUPPORT);
5985 SCTP_INP_INCR_REF(inp);
5986 SCTP_ASOC_CREATE_LOCK(inp);
5990 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
5991 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
5992 /* Should I really unlock ? */
5993 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
5998 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
5999 (addr->sa_family == AF_INET6)) {
6000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6005 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6006 SCTP_PCB_FLAGS_UNBOUND) {
6007 /* Bind a ephemeral port */
6008 error = sctp_inpcb_bind(so, NULL, NULL, p);
6013 /* Now do we connect? */
6014 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6015 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6016 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6020 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6021 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6022 /* We are already connected AND the TCP model */
6023 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6027 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6028 SCTP_INP_RLOCK(inp);
6029 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6030 SCTP_INP_RUNLOCK(inp);
6033 * We increment here since sctp_findassociation_ep_addr()
6034 * will do a decrement if it finds the stcb as long as the
6035 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6037 SCTP_INP_INCR_REF(inp);
6038 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6040 SCTP_INP_DECR_REF(inp);
6042 SCTP_TCB_UNLOCK(stcb);
6046 /* Already have or am bring up an association */
6047 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
6051 vrf_id = inp->def_vrf_id;
6052 /* We are GOOD to go */
6053 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
6055 /* Gak! no memory */
6058 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
6059 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
6060 /* Set the connected flag so we can queue data */
6063 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
6064 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
6066 /* initialize authentication parameters for the assoc */
6067 sctp_initialize_auth_params(inp, stcb);
6069 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
6070 SCTP_TCB_UNLOCK(stcb);
6072 if (create_lock_on) {
6073 SCTP_ASOC_CREATE_UNLOCK(inp);
6075 SCTP_INP_DECR_REF(inp);
6082 sctp_listen(struct socket *so, int backlog, struct thread *p)
6085 * Note this module depends on the protocol processing being called
6086 * AFTER any socket level flags and backlog are applied to the
6087 * socket. The traditional way that the socket flags are applied is
6088 * AFTER protocol processing. We have made a change to the
6089 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
6090 * place if the socket API for SCTP is to work properly.
6094 struct sctp_inpcb *inp;
6096 inp = (struct sctp_inpcb *)so->so_pcb;
6098 /* I made the same as TCP since we are not setup? */
6099 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6100 return (ECONNRESET);
6102 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
6103 /* See if we have a listener */
6104 struct sctp_inpcb *tinp;
6105 union sctp_sockstore store;
6107 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
6109 struct sctp_laddr *laddr;
6111 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6112 memcpy(&store, &laddr->ifa->address, sizeof(store));
6113 switch (store.sa.sa_family) {
6116 store.sin.sin_port = inp->sctp_lport;
6121 store.sin6.sin6_port = inp->sctp_lport;
6127 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
6128 if (tinp && (tinp != inp) &&
6129 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6130 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6131 (tinp->sctp_socket->so_qlimit)) {
6133 * we have a listener already and
6136 SCTP_INP_DECR_REF(tinp);
6137 return (EADDRINUSE);
6139 SCTP_INP_DECR_REF(tinp);
6143 /* Setup a local addr bound all */
6144 memset(&store, 0, sizeof(store));
6146 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
6147 store.sa.sa_family = AF_INET6;
6148 store.sa.sa_len = sizeof(struct sockaddr_in6);
6152 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
6153 store.sa.sa_family = AF_INET;
6154 store.sa.sa_len = sizeof(struct sockaddr_in);
6157 switch (store.sa.sa_family) {
6160 store.sin.sin_port = inp->sctp_lport;
6165 store.sin6.sin6_port = inp->sctp_lport;
6171 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
6172 if (tinp && (tinp != inp) &&
6173 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6174 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6175 (tinp->sctp_socket->so_qlimit)) {
6177 * we have a listener already and its not
6180 SCTP_INP_DECR_REF(tinp);
6181 return (EADDRINUSE);
6183 SCTP_INP_DECR_REF(inp);
6187 SCTP_INP_RLOCK(inp);
6188 #ifdef SCTP_LOCK_LOGGING
6189 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
6190 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
6194 error = solisten_proto_check(so);
6197 SCTP_INP_RUNLOCK(inp);
6200 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
6201 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
6203 * The unlucky case - We are in the tcp pool with this guy.
6204 * - Someone else is in the main inp slot. - We must move
6205 * this guy (the listener) to the main slot - We must then
6206 * move the guy that was listener to the TCP Pool.
6208 if (sctp_swap_inpcb_for_listen(inp)) {
6212 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6213 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6214 /* We are already connected AND the TCP model */
6216 SCTP_INP_RUNLOCK(inp);
6218 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6219 return (EADDRINUSE);
6221 SCTP_INP_RUNLOCK(inp);
6222 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
6223 /* We must do a bind. */
6225 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
6226 /* bind error, probably perm */
6231 /* It appears for 7.0 and on, we must always call this. */
6232 solisten_proto(so, backlog);
6233 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6234 /* remove the ACCEPTCONN flag for one-to-many sockets */
6235 so->so_options &= ~SO_ACCEPTCONN;
6238 /* turning off listen */
6239 so->so_options &= ~SO_ACCEPTCONN;
6245 static int sctp_defered_wakeup_cnt = 0;
6248 sctp_accept(struct socket *so, struct sockaddr **addr)
6250 struct sctp_tcb *stcb;
6251 struct sctp_inpcb *inp;
6252 union sctp_sockstore store;
6258 inp = (struct sctp_inpcb *)so->so_pcb;
6261 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6262 return (ECONNRESET);
6264 SCTP_INP_RLOCK(inp);
6265 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6266 SCTP_INP_RUNLOCK(inp);
6267 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
6268 return (EOPNOTSUPP);
6270 if (so->so_state & SS_ISDISCONNECTED) {
6271 SCTP_INP_RUNLOCK(inp);
6272 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
6273 return (ECONNABORTED);
6275 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6277 SCTP_INP_RUNLOCK(inp);
6278 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6279 return (ECONNRESET);
6281 SCTP_TCB_LOCK(stcb);
6282 SCTP_INP_RUNLOCK(inp);
6283 store = stcb->asoc.primary_destination->ro._l_addr;
6284 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
6285 SCTP_TCB_UNLOCK(stcb);
6286 switch (store.sa.sa_family) {
6290 struct sockaddr_in *sin;
6292 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6295 sin->sin_family = AF_INET;
6296 sin->sin_len = sizeof(*sin);
6297 sin->sin_port = store.sin.sin_port;
6298 sin->sin_addr = store.sin.sin_addr;
6299 *addr = (struct sockaddr *)sin;
6306 struct sockaddr_in6 *sin6;
6308 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
6311 sin6->sin6_family = AF_INET6;
6312 sin6->sin6_len = sizeof(*sin6);
6313 sin6->sin6_port = store.sin6.sin6_port;
6314 sin6->sin6_addr = store.sin6.sin6_addr;
6315 if ((error = sa6_recoverscope(sin6)) != 0) {
6316 SCTP_FREE_SONAME(sin6);
6319 *addr = (struct sockaddr *)sin6;
6327 /* Wake any delayed sleep action */
6328 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
6329 SCTP_INP_WLOCK(inp);
6330 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
6331 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
6332 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
6333 SCTP_INP_WUNLOCK(inp);
6334 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
6335 if (sowriteable(inp->sctp_socket)) {
6336 sowwakeup_locked(inp->sctp_socket);
6338 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
6340 SCTP_INP_WLOCK(inp);
6342 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
6343 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
6344 SCTP_INP_WUNLOCK(inp);
6345 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
6346 if (soreadable(inp->sctp_socket)) {
6347 sctp_defered_wakeup_cnt++;
6348 sorwakeup_locked(inp->sctp_socket);
6350 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
6352 SCTP_INP_WLOCK(inp);
6354 SCTP_INP_WUNLOCK(inp);
6356 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
6357 SCTP_TCB_LOCK(stcb);
6358 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
6365 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
6367 struct sockaddr_in *sin;
6369 struct sctp_inpcb *inp;
6370 struct sctp_ifa *sctp_ifa;
6373 * Do the malloc first in case it blocks.
6375 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6378 sin->sin_family = AF_INET;
6379 sin->sin_len = sizeof(*sin);
6380 inp = (struct sctp_inpcb *)so->so_pcb;
6382 SCTP_FREE_SONAME(sin);
6383 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6384 return (ECONNRESET);
6386 SCTP_INP_RLOCK(inp);
6387 sin->sin_port = inp->sctp_lport;
6388 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
6389 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6390 struct sctp_tcb *stcb;
6391 struct sockaddr_in *sin_a;
6392 struct sctp_nets *net;
6395 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6401 SCTP_TCB_LOCK(stcb);
6402 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6403 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6405 /* this will make coverity happy */
6408 if (sin_a->sin_family == AF_INET) {
6413 if ((!fnd) || (sin_a == NULL)) {
6415 SCTP_TCB_UNLOCK(stcb);
6418 vrf_id = inp->def_vrf_id;
6419 sctp_ifa = sctp_source_address_selection(inp,
6421 (sctp_route_t *) & net->ro,
6424 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
6425 sctp_free_ifa(sctp_ifa);
6427 SCTP_TCB_UNLOCK(stcb);
6429 /* For the bound all case you get back 0 */
6431 sin->sin_addr.s_addr = 0;
6435 /* Take the first IPv4 address in the list */
6436 struct sctp_laddr *laddr;
6439 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6440 if (laddr->ifa->address.sa.sa_family == AF_INET) {
6441 struct sockaddr_in *sin_a;
6443 sin_a = (struct sockaddr_in *)&laddr->ifa->address.sa;
6444 sin->sin_addr = sin_a->sin_addr;
6450 SCTP_FREE_SONAME(sin);
6451 SCTP_INP_RUNLOCK(inp);
6452 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6456 SCTP_INP_RUNLOCK(inp);
6457 (*addr) = (struct sockaddr *)sin;
6462 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
6464 struct sockaddr_in *sin;
6466 struct sockaddr_in *sin_a;
6467 struct sctp_inpcb *inp;
6468 struct sctp_tcb *stcb;
6469 struct sctp_nets *net;
6471 /* Do the malloc first in case it blocks. */
6472 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6475 sin->sin_family = AF_INET;
6476 sin->sin_len = sizeof(*sin);
6478 inp = (struct sctp_inpcb *)so->so_pcb;
6479 if ((inp == NULL) ||
6480 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
6481 /* UDP type and listeners will drop out here */
6482 SCTP_FREE_SONAME(sin);
6483 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
6486 SCTP_INP_RLOCK(inp);
6487 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6489 SCTP_TCB_LOCK(stcb);
6491 SCTP_INP_RUNLOCK(inp);
6493 SCTP_FREE_SONAME(sin);
6494 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6495 return (ECONNRESET);
6498 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6499 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6500 if (sin_a->sin_family == AF_INET) {
6502 sin->sin_port = stcb->rport;
6503 sin->sin_addr = sin_a->sin_addr;
6507 SCTP_TCB_UNLOCK(stcb);
6509 /* No IPv4 address */
6510 SCTP_FREE_SONAME(sin);
6511 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6514 (*addr) = (struct sockaddr *)sin;
6518 struct pr_usrreqs sctp_usrreqs = {
6519 .pru_abort = sctp_abort,
6520 .pru_accept = sctp_accept,
6521 .pru_attach = sctp_attach,
6522 .pru_bind = sctp_bind,
6523 .pru_connect = sctp_connect,
6524 .pru_control = in_control,
6525 .pru_close = sctp_close,
6526 .pru_detach = sctp_close,
6527 .pru_sopoll = sopoll_generic,
6528 .pru_flush = sctp_flush,
6529 .pru_disconnect = sctp_disconnect,
6530 .pru_listen = sctp_listen,
6531 .pru_peeraddr = sctp_peeraddr,
6532 .pru_send = sctp_sendm,
6533 .pru_shutdown = sctp_shutdown,
6534 .pru_sockaddr = sctp_ingetaddr,
6535 .pru_sosend = sctp_sosend,
6536 .pru_soreceive = sctp_soreceive