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_get_mbuf_for_msg(sizeof(struct sctp_paramhdr),
858 0, M_DONTWAIT, 1, MT_DATA);
864 struct sctp_paramhdr *ph;
866 SCTP_BUF_LEN(op_err) = sizeof(struct sctp_paramhdr);
867 ph = mtod(op_err, struct sctp_paramhdr *);
868 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
869 ph->param_length = htons(SCTP_BUF_LEN(op_err));
871 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
872 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
873 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
874 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
875 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
876 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
878 SCTP_INP_RUNLOCK(inp);
879 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
882 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
885 soisdisconnecting(so);
886 SCTP_TCB_UNLOCK(stcb);
887 SCTP_INP_RUNLOCK(inp);
892 /* UDP model does not support this */
893 SCTP_INP_RUNLOCK(inp);
894 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
900 sctp_flush(struct socket *so, int how)
903 * We will just clear out the values and let subsequent close clear
904 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
905 * they will not be able to read the data, the socket will block
906 * that from happening.
908 struct sctp_inpcb *inp;
910 inp = (struct sctp_inpcb *)so->so_pcb;
912 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
916 /* For the 1 to many model this does nothing */
917 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
918 SCTP_INP_RUNLOCK(inp);
921 SCTP_INP_RUNLOCK(inp);
922 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
924 * First make sure the sb will be happy, we don't use these
925 * except maybe the count
928 SCTP_INP_READ_LOCK(inp);
929 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
930 SCTP_INP_READ_UNLOCK(inp);
931 SCTP_INP_WUNLOCK(inp);
932 so->so_rcv.sb_cc = 0;
933 so->so_rcv.sb_mbcnt = 0;
934 so->so_rcv.sb_mb = NULL;
936 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
938 * First make sure the sb will be happy, we don't use these
939 * except maybe the count
941 so->so_snd.sb_cc = 0;
942 so->so_snd.sb_mbcnt = 0;
943 so->so_snd.sb_mb = NULL;
950 sctp_shutdown(struct socket *so)
952 struct sctp_inpcb *inp;
954 inp = (struct sctp_inpcb *)so->so_pcb;
956 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
960 /* For UDP model this is a invalid call */
961 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
962 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
963 /* Restore the flags that the soshutdown took away. */
964 SOCKBUF_LOCK(&so->so_rcv);
965 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
966 SOCKBUF_UNLOCK(&so->so_rcv);
967 /* This proc will wakeup for read and do nothing (I hope) */
968 SCTP_INP_RUNLOCK(inp);
969 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
973 * Ok if we reach here its the TCP model and it is either a SHUT_WR
974 * or SHUT_RDWR. This means we put the shutdown flag against it.
977 struct sctp_tcb *stcb;
978 struct sctp_association *asoc;
981 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
982 SCTP_INP_RUNLOCK(inp);
987 stcb = LIST_FIRST(&inp->sctp_asoc_list);
990 * Ok we hit the case that the shutdown call was
991 * made after an abort or something. Nothing to do
994 SCTP_INP_RUNLOCK(inp);
999 if (TAILQ_EMPTY(&asoc->send_queue) &&
1000 TAILQ_EMPTY(&asoc->sent_queue) &&
1001 (asoc->stream_queue_cnt == 0)) {
1002 if (asoc->locked_on_sending) {
1005 /* there is nothing queued to send, so I'm done... */
1006 if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) {
1007 /* only send SHUTDOWN the first time through */
1008 struct sctp_nets *netp;
1010 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
1011 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
1012 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1014 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
1015 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
1016 sctp_stop_timers_for_shutdown(stcb);
1017 if (stcb->asoc.alternate) {
1018 netp = stcb->asoc.alternate;
1020 netp = stcb->asoc.primary_destination;
1022 sctp_send_shutdown(stcb, netp);
1023 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1024 stcb->sctp_ep, stcb, netp);
1025 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1026 stcb->sctp_ep, stcb, netp);
1027 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
1031 * we still got (or just got) data to send, so set
1034 struct sctp_nets *netp;
1036 if (stcb->asoc.alternate) {
1037 netp = stcb->asoc.alternate;
1039 netp = stcb->asoc.primary_destination;
1042 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1043 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
1046 if (asoc->locked_on_sending) {
1047 /* Locked to send out the data */
1048 struct sctp_stream_queue_pending *sp;
1050 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
1052 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
1053 asoc->locked_on_sending->stream_no);
1055 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
1056 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
1060 if (TAILQ_EMPTY(&asoc->send_queue) &&
1061 TAILQ_EMPTY(&asoc->sent_queue) &&
1062 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1063 struct mbuf *op_err;
1066 op_err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr),
1067 0, M_DONTWAIT, 1, MT_DATA);
1069 /* Fill in the user initiated abort */
1070 struct sctp_paramhdr *ph;
1072 SCTP_BUF_LEN(op_err) = sizeof(struct sctp_paramhdr);
1073 ph = mtod(op_err, struct sctp_paramhdr *);
1074 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
1075 ph->param_length = htons(SCTP_BUF_LEN(op_err));
1077 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
1078 sctp_abort_an_association(stcb->sctp_ep, stcb,
1079 op_err, SCTP_SO_LOCKED);
1082 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1085 SCTP_TCB_UNLOCK(stcb);
1088 SCTP_INP_RUNLOCK(inp);
1093 * copies a "user" presentable address and removes embedded scope, etc.
1094 * returns 0 on success, 1 on error
1097 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1100 struct sockaddr_in6 lsa6;
1102 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1105 memcpy(ss, sa, sa->sa_len);
1112 * NOTE: assumes addr lock is held
1115 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1116 struct sctp_tcb *stcb,
1118 struct sockaddr_storage *sas,
1121 struct sctp_ifn *sctp_ifn;
1122 struct sctp_ifa *sctp_ifa;
1123 int loopback_scope, ipv4_local_scope, local_scope, site_scope;
1125 int ipv4_addr_legal, ipv6_addr_legal;
1126 struct sctp_vrf *vrf;
1133 /* Turn on all the appropriate scope */
1134 loopback_scope = stcb->asoc.scope.loopback_scope;
1135 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1136 local_scope = stcb->asoc.scope.local_scope;
1137 site_scope = stcb->asoc.scope.site_scope;
1138 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1139 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1141 /* Use generic values for endpoints. */
1143 ipv4_local_scope = 1;
1146 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1147 ipv6_addr_legal = 1;
1148 if (SCTP_IPV6_V6ONLY(inp)) {
1149 ipv4_addr_legal = 0;
1151 ipv4_addr_legal = 1;
1154 ipv6_addr_legal = 0;
1155 ipv4_addr_legal = 1;
1158 vrf = sctp_find_vrf(vrf_id);
1162 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1163 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1164 if ((loopback_scope == 0) &&
1165 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1166 /* Skip loopback if loopback_scope not set */
1169 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1172 * For the BOUND-ALL case, the list
1173 * associated with a TCB is Always
1174 * considered a reverse list.. i.e.
1175 * it lists addresses that are NOT
1176 * part of the association. If this
1177 * is one of those we must skip it.
1179 if (sctp_is_addr_restricted(stcb,
1184 switch (sctp_ifa->address.sa.sa_family) {
1187 if (ipv4_addr_legal) {
1188 struct sockaddr_in *sin;
1190 sin = (struct sockaddr_in *)&sctp_ifa->address.sa;
1191 if (sin->sin_addr.s_addr == 0) {
1199 if ((ipv4_local_scope == 0) &&
1200 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1204 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1205 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1206 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1207 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1208 actual += sizeof(struct sockaddr_in6);
1211 memcpy(sas, sin, sizeof(*sin));
1212 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1213 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1214 actual += sizeof(*sin);
1218 if (actual >= limit) {
1228 if (ipv6_addr_legal) {
1229 struct sockaddr_in6 *sin6;
1231 sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sa;
1232 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1240 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1241 if (local_scope == 0)
1243 if (sin6->sin6_scope_id == 0) {
1244 if (sa6_recoverscope(sin6) != 0)
1262 if ((site_scope == 0) &&
1263 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1266 memcpy(sas, sin6, sizeof(*sin6));
1267 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1268 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1269 actual += sizeof(*sin6);
1270 if (actual >= limit) {
1285 struct sctp_laddr *laddr;
1287 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1289 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1293 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1295 switch (laddr->ifa->address.sa.sa_family) {
1298 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1303 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1310 sas = (struct sockaddr_storage *)((caddr_t)sas +
1311 laddr->ifa->address.sa.sa_len);
1312 actual += laddr->ifa->address.sa.sa_len;
1313 if (actual >= limit) {
1322 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1323 struct sctp_tcb *stcb,
1325 struct sockaddr_storage *sas)
1329 SCTP_IPI_ADDR_RLOCK();
1330 /* fill up addresses for the endpoint's default vrf */
1331 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1333 SCTP_IPI_ADDR_RUNLOCK();
1338 * NOTE: assumes addr lock is held
1341 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1344 struct sctp_vrf *vrf = NULL;
1347 * In both sub-set bound an bound_all cases we return the MAXIMUM
1348 * number of addresses that you COULD get. In reality the sub-set
1349 * bound may have an exclusion list for a given TCB OR in the
1350 * bound-all case a TCB may NOT include the loopback or other
1351 * addresses as well.
1353 vrf = sctp_find_vrf(vrf_id);
1357 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1358 struct sctp_ifn *sctp_ifn;
1359 struct sctp_ifa *sctp_ifa;
1361 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1362 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1363 /* Count them if they are the right type */
1364 switch (sctp_ifa->address.sa.sa_family) {
1367 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1368 cnt += sizeof(struct sockaddr_in6);
1370 cnt += sizeof(struct sockaddr_in);
1375 cnt += sizeof(struct sockaddr_in6);
1384 struct sctp_laddr *laddr;
1386 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1387 switch (laddr->ifa->address.sa.sa_family) {
1390 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1391 cnt += sizeof(struct sockaddr_in6);
1393 cnt += sizeof(struct sockaddr_in);
1398 cnt += sizeof(struct sockaddr_in6);
1410 sctp_count_max_addresses(struct sctp_inpcb *inp)
1414 SCTP_IPI_ADDR_RLOCK();
1415 /* count addresses for the endpoint's default VRF */
1416 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1417 SCTP_IPI_ADDR_RUNLOCK();
1422 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1423 size_t optsize, void *p, int delay)
1426 int creat_lock_on = 0;
1427 struct sctp_tcb *stcb = NULL;
1428 struct sockaddr *sa;
1429 int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1431 int bad_addresses = 0;
1434 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1436 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1437 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1438 /* We are already connected AND the TCP model */
1439 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1440 return (EADDRINUSE);
1442 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1443 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1444 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1447 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1448 SCTP_INP_RLOCK(inp);
1449 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1450 SCTP_INP_RUNLOCK(inp);
1453 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1456 SCTP_INP_INCR_REF(inp);
1457 SCTP_ASOC_CREATE_LOCK(inp);
1459 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1460 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1461 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1465 totaddrp = (int *)optval;
1466 totaddr = *totaddrp;
1467 sa = (struct sockaddr *)(totaddrp + 1);
1468 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (optsize - sizeof(int)), &bad_addresses);
1469 if ((stcb != NULL) || bad_addresses) {
1470 /* Already have or am bring up an association */
1471 SCTP_ASOC_CREATE_UNLOCK(inp);
1474 SCTP_TCB_UNLOCK(stcb);
1475 if (bad_addresses == 0) {
1476 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1482 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1487 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1489 struct in6pcb *inp6;
1491 inp6 = (struct in6pcb *)inp;
1492 if (SCTP_IPV6_V6ONLY(inp6)) {
1494 * if IPV6_V6ONLY flag, ignore connections destined
1495 * to a v4 addr or v4-mapped addr
1497 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1503 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1504 SCTP_PCB_FLAGS_UNBOUND) {
1505 /* Bind a ephemeral port */
1506 error = sctp_inpcb_bind(so, NULL, NULL, p);
1511 /* FIX ME: do we want to pass in a vrf on the connect call? */
1512 vrf_id = inp->def_vrf_id;
1515 /* We are GOOD to go */
1516 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1520 /* Gak! no memory */
1523 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1524 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1525 /* Set the connected flag so we can queue data */
1528 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1529 /* move to second address */
1530 switch (sa->sa_family) {
1533 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1538 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1546 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1547 /* Fill in the return id */
1549 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1552 a_id = (sctp_assoc_t *) optval;
1553 *a_id = sctp_get_associd(stcb);
1555 /* initialize authentication parameters for the assoc */
1556 sctp_initialize_auth_params(inp, stcb);
1559 /* doing delayed connection */
1560 stcb->asoc.delayed_connection = 1;
1561 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1563 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1564 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1566 SCTP_TCB_UNLOCK(stcb);
1567 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1568 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1569 /* Set the connected flag so we can queue data */
1573 if (creat_lock_on) {
1574 SCTP_ASOC_CREATE_UNLOCK(inp);
1576 SCTP_INP_DECR_REF(inp);
1580 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1581 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1582 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1583 SCTP_INP_RLOCK(inp); \
1584 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1586 SCTP_TCB_LOCK(stcb); \
1588 SCTP_INP_RUNLOCK(inp); \
1589 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1590 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1591 if (stcb == NULL) { \
1592 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1602 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1603 if (size < sizeof(type)) { \
1604 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1608 destp = (type *)srcp; \
1613 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1616 struct sctp_inpcb *inp = NULL;
1618 struct sctp_tcb *stcb = NULL;
1620 if (optval == NULL) {
1621 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1624 inp = (struct sctp_inpcb *)so->so_pcb;
1626 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1633 case SCTP_AUTOCLOSE:
1634 case SCTP_EXPLICIT_EOR:
1635 case SCTP_AUTO_ASCONF:
1636 case SCTP_DISABLE_FRAGMENTS:
1637 case SCTP_I_WANT_MAPPED_V4_ADDR:
1638 case SCTP_USE_EXT_RCVINFO:
1639 SCTP_INP_RLOCK(inp);
1641 case SCTP_DISABLE_FRAGMENTS:
1642 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1644 case SCTP_I_WANT_MAPPED_V4_ADDR:
1645 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1647 case SCTP_AUTO_ASCONF:
1648 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1649 /* only valid for bound all sockets */
1650 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1652 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1657 case SCTP_EXPLICIT_EOR:
1658 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1661 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1663 case SCTP_USE_EXT_RCVINFO:
1664 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1666 case SCTP_AUTOCLOSE:
1667 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1668 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1674 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1675 error = ENOPROTOOPT;
1676 } /* end switch (sopt->sopt_name) */
1677 if (*optsize < sizeof(val)) {
1678 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1682 SCTP_INP_RUNLOCK(inp);
1684 /* return the option value */
1685 *(int *)optval = val;
1686 *optsize = sizeof(val);
1689 case SCTP_GET_PACKET_LOG:
1691 #ifdef SCTP_PACKET_LOGGING
1695 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1696 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1699 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1704 case SCTP_REUSE_PORT:
1708 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1709 /* Can't do this for a 1-m socket */
1713 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1714 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1715 *optsize = sizeof(uint32_t);
1718 case SCTP_PARTIAL_DELIVERY_POINT:
1722 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1723 *value = inp->partial_delivery_point;
1724 *optsize = sizeof(uint32_t);
1727 case SCTP_FRAGMENT_INTERLEAVE:
1731 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1732 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1733 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1734 *value = SCTP_FRAG_LEVEL_2;
1736 *value = SCTP_FRAG_LEVEL_1;
1739 *value = SCTP_FRAG_LEVEL_0;
1741 *optsize = sizeof(uint32_t);
1744 case SCTP_CMT_ON_OFF:
1746 struct sctp_assoc_value *av;
1748 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1749 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1751 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1752 SCTP_TCB_UNLOCK(stcb);
1754 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1755 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1756 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1757 SCTP_INP_RLOCK(inp);
1758 av->assoc_value = inp->sctp_cmt_on_off;
1759 SCTP_INP_RUNLOCK(inp);
1761 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1766 *optsize = sizeof(struct sctp_assoc_value);
1770 case SCTP_PLUGGABLE_CC:
1772 struct sctp_assoc_value *av;
1774 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1775 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1777 av->assoc_value = stcb->asoc.congestion_control_module;
1778 SCTP_TCB_UNLOCK(stcb);
1780 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1781 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1782 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1783 SCTP_INP_RLOCK(inp);
1784 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1785 SCTP_INP_RUNLOCK(inp);
1787 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1792 *optsize = sizeof(struct sctp_assoc_value);
1796 case SCTP_CC_OPTION:
1798 struct sctp_cc_option *cc_opt;
1800 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1801 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1805 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1808 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1809 *optsize = sizeof(struct sctp_cc_option);
1811 SCTP_TCB_UNLOCK(stcb);
1815 case SCTP_PLUGGABLE_SS:
1817 struct sctp_assoc_value *av;
1819 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1820 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1822 av->assoc_value = stcb->asoc.stream_scheduling_module;
1823 SCTP_TCB_UNLOCK(stcb);
1825 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1826 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1827 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1828 SCTP_INP_RLOCK(inp);
1829 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1830 SCTP_INP_RUNLOCK(inp);
1832 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1837 *optsize = sizeof(struct sctp_assoc_value);
1843 struct sctp_stream_value *av;
1845 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1846 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1848 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1849 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1850 &av->stream_value) < 0)) {
1851 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1854 *optsize = sizeof(struct sctp_stream_value);
1856 SCTP_TCB_UNLOCK(stcb);
1859 * Can't get stream value without
1862 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1867 case SCTP_GET_ADDR_LEN:
1869 struct sctp_assoc_value *av;
1871 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1874 if (av->assoc_value == AF_INET) {
1875 av->assoc_value = sizeof(struct sockaddr_in);
1880 if (av->assoc_value == AF_INET6) {
1881 av->assoc_value = sizeof(struct sockaddr_in6);
1886 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1888 *optsize = sizeof(struct sctp_assoc_value);
1892 case SCTP_GET_ASSOC_NUMBER:
1894 uint32_t *value, cnt;
1896 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1898 SCTP_INP_RLOCK(inp);
1899 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1902 SCTP_INP_RUNLOCK(inp);
1904 *optsize = sizeof(uint32_t);
1907 case SCTP_GET_ASSOC_ID_LIST:
1909 struct sctp_assoc_ids *ids;
1910 unsigned int at, limit;
1912 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1914 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1915 SCTP_INP_RLOCK(inp);
1916 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1918 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1925 SCTP_INP_RUNLOCK(inp);
1927 ids->gaids_number_of_ids = at;
1928 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1934 struct sctp_assoc_value *av;
1936 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1937 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1940 av->assoc_value = stcb->asoc.context;
1941 SCTP_TCB_UNLOCK(stcb);
1943 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1944 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1945 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1946 SCTP_INP_RLOCK(inp);
1947 av->assoc_value = inp->sctp_context;
1948 SCTP_INP_RUNLOCK(inp);
1950 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1955 *optsize = sizeof(struct sctp_assoc_value);
1961 uint32_t *default_vrfid;
1963 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1964 *default_vrfid = inp->def_vrf_id;
1965 *optsize = sizeof(uint32_t);
1968 case SCTP_GET_ASOC_VRF:
1970 struct sctp_assoc_value *id;
1972 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1973 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1976 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1978 id->assoc_value = stcb->asoc.vrf_id;
1979 *optsize = sizeof(struct sctp_assoc_value);
1983 case SCTP_GET_VRF_IDS:
1985 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1989 case SCTP_GET_NONCE_VALUES:
1991 struct sctp_get_nonce_values *gnv;
1993 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1994 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1997 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1998 gnv->gn_local_tag = stcb->asoc.my_vtag;
1999 SCTP_TCB_UNLOCK(stcb);
2000 *optsize = sizeof(struct sctp_get_nonce_values);
2002 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2007 case SCTP_DELAYED_SACK:
2009 struct sctp_sack_info *sack;
2011 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2012 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2014 sack->sack_delay = stcb->asoc.delayed_ack;
2015 sack->sack_freq = stcb->asoc.sack_freq;
2016 SCTP_TCB_UNLOCK(stcb);
2018 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2019 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2020 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2021 SCTP_INP_RLOCK(inp);
2022 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2023 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2024 SCTP_INP_RUNLOCK(inp);
2026 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2031 *optsize = sizeof(struct sctp_sack_info);
2035 case SCTP_GET_SNDBUF_USE:
2037 struct sctp_sockstat *ss;
2039 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2040 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2043 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2044 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2045 stcb->asoc.size_on_all_streams);
2046 SCTP_TCB_UNLOCK(stcb);
2047 *optsize = sizeof(struct sctp_sockstat);
2049 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2054 case SCTP_MAX_BURST:
2058 SCTP_CHECK_AND_CAST(value, optval, uint8_t, *optsize);
2060 SCTP_INP_RLOCK(inp);
2061 if (inp->sctp_ep.max_burst < 256) {
2062 *value = inp->sctp_ep.max_burst;
2066 SCTP_INP_RUNLOCK(inp);
2067 *optsize = sizeof(uint8_t);
2072 struct sctp_assoc_value *av;
2075 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2076 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2079 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2080 SCTP_TCB_UNLOCK(stcb);
2082 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2083 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2084 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2085 SCTP_INP_RLOCK(inp);
2086 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2087 ovh = SCTP_MED_OVERHEAD;
2089 ovh = SCTP_MED_V4_OVERHEAD;
2091 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2092 av->assoc_value = 0;
2094 av->assoc_value = inp->sctp_frag_point - ovh;
2095 SCTP_INP_RUNLOCK(inp);
2097 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2102 *optsize = sizeof(struct sctp_assoc_value);
2106 case SCTP_GET_STAT_LOG:
2107 error = sctp_fill_stat_log(optval, optsize);
2111 struct sctp_event_subscribe *events;
2113 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2114 memset(events, 0, sizeof(struct sctp_event_subscribe));
2115 SCTP_INP_RLOCK(inp);
2116 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2117 events->sctp_data_io_event = 1;
2119 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2120 events->sctp_association_event = 1;
2122 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2123 events->sctp_address_event = 1;
2125 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2126 events->sctp_send_failure_event = 1;
2128 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2129 events->sctp_peer_error_event = 1;
2131 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2132 events->sctp_shutdown_event = 1;
2134 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2135 events->sctp_partial_delivery_event = 1;
2137 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2138 events->sctp_adaptation_layer_event = 1;
2140 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2141 events->sctp_authentication_event = 1;
2143 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2144 events->sctp_sender_dry_event = 1;
2146 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2147 events->sctp_stream_reset_event = 1;
2148 SCTP_INP_RUNLOCK(inp);
2149 *optsize = sizeof(struct sctp_event_subscribe);
2152 case SCTP_ADAPTATION_LAYER:
2156 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2158 SCTP_INP_RLOCK(inp);
2159 *value = inp->sctp_ep.adaptation_layer_indicator;
2160 SCTP_INP_RUNLOCK(inp);
2161 *optsize = sizeof(uint32_t);
2164 case SCTP_SET_INITIAL_DBG_SEQ:
2168 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2169 SCTP_INP_RLOCK(inp);
2170 *value = inp->sctp_ep.initial_sequence_debug;
2171 SCTP_INP_RUNLOCK(inp);
2172 *optsize = sizeof(uint32_t);
2175 case SCTP_GET_LOCAL_ADDR_SIZE:
2179 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2180 SCTP_INP_RLOCK(inp);
2181 *value = sctp_count_max_addresses(inp);
2182 SCTP_INP_RUNLOCK(inp);
2183 *optsize = sizeof(uint32_t);
2186 case SCTP_GET_REMOTE_ADDR_SIZE:
2190 struct sctp_nets *net;
2192 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2193 /* FIXME MT: change to sctp_assoc_value? */
2194 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2198 /* Count the sizes */
2199 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2200 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2201 size += sizeof(struct sockaddr_in6);
2203 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2206 size += sizeof(struct sockaddr_in);
2211 size += sizeof(struct sockaddr_in6);
2219 SCTP_TCB_UNLOCK(stcb);
2220 *value = (uint32_t) size;
2221 *optsize = sizeof(uint32_t);
2223 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2228 case SCTP_GET_PEER_ADDRESSES:
2230 * Get the address information, an array is passed in to
2231 * fill up we pack it.
2235 struct sockaddr_storage *sas;
2236 struct sctp_nets *net;
2237 struct sctp_getaddresses *saddr;
2239 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2240 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2243 left = (*optsize) - sizeof(struct sctp_getaddresses);
2244 *optsize = sizeof(struct sctp_getaddresses);
2245 sas = (struct sockaddr_storage *)&saddr->addr[0];
2247 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2248 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2249 cpsz = sizeof(struct sockaddr_in6);
2251 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2254 cpsz = sizeof(struct sockaddr_in);
2259 cpsz = sizeof(struct sockaddr_in6);
2271 /* not enough room. */
2274 #if defined(INET) && defined(INET6)
2275 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2276 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
2277 /* Must map the address */
2278 in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
2279 (struct sockaddr_in6 *)sas);
2282 memcpy(sas, &net->ro._l_addr, cpsz);
2283 #if defined(INET) && defined(INET6)
2286 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2288 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2292 SCTP_TCB_UNLOCK(stcb);
2294 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2299 case SCTP_GET_LOCAL_ADDRESSES:
2301 size_t limit, actual;
2302 struct sockaddr_storage *sas;
2303 struct sctp_getaddresses *saddr;
2305 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2306 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2308 sas = (struct sockaddr_storage *)&saddr->addr[0];
2309 limit = *optsize - sizeof(sctp_assoc_t);
2310 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2312 SCTP_TCB_UNLOCK(stcb);
2314 *optsize = sizeof(struct sockaddr_storage) + actual;
2317 case SCTP_PEER_ADDR_PARAMS:
2319 struct sctp_paddrparams *paddrp;
2320 struct sctp_nets *net;
2322 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2323 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2327 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2330 * We increment here since
2331 * sctp_findassociation_ep_addr() wil do a
2332 * decrement if it finds the stcb as long as
2333 * the locked tcb (last argument) is NOT a
2336 SCTP_INP_INCR_REF(inp);
2337 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddrp->spp_address, &net, NULL, NULL);
2339 SCTP_INP_DECR_REF(inp);
2342 if (stcb && (net == NULL)) {
2343 struct sockaddr *sa;
2345 sa = (struct sockaddr *)&paddrp->spp_address;
2347 if (sa->sa_family == AF_INET) {
2348 struct sockaddr_in *sin;
2350 sin = (struct sockaddr_in *)sa;
2351 if (sin->sin_addr.s_addr) {
2353 SCTP_TCB_UNLOCK(stcb);
2354 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2360 if (sa->sa_family == AF_INET6) {
2361 struct sockaddr_in6 *sin6;
2363 sin6 = (struct sockaddr_in6 *)sa;
2364 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2366 SCTP_TCB_UNLOCK(stcb);
2367 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2373 error = EAFNOSUPPORT;
2374 SCTP_TCB_UNLOCK(stcb);
2375 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2380 /* Applies to the specific association */
2381 paddrp->spp_flags = 0;
2385 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2386 ovh = SCTP_MED_OVERHEAD;
2388 ovh = SCTP_MED_V4_OVERHEAD;
2391 paddrp->spp_hbinterval = net->heart_beat_delay;
2392 paddrp->spp_pathmaxrxt = net->failure_threshold;
2393 paddrp->spp_pathmtu = net->mtu - ovh;
2394 /* get flags for HB */
2395 if (net->dest_state & SCTP_ADDR_NOHB) {
2396 paddrp->spp_flags |= SPP_HB_DISABLE;
2398 paddrp->spp_flags |= SPP_HB_ENABLE;
2400 /* get flags for PMTU */
2401 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2402 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2404 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2406 if (net->dscp & 0x01) {
2407 paddrp->spp_dscp = net->dscp & 0xfc;
2408 paddrp->spp_flags |= SPP_DSCP;
2411 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2412 (net->flowlabel & 0x80000000)) {
2413 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2414 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2419 * No destination so return default
2422 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2423 paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
2424 if (stcb->asoc.default_dscp & 0x01) {
2425 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2426 paddrp->spp_flags |= SPP_DSCP;
2429 if (stcb->asoc.default_flowlabel & 0x80000000) {
2430 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2431 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2434 /* default settings should be these */
2435 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2436 paddrp->spp_flags |= SPP_HB_DISABLE;
2438 paddrp->spp_flags |= SPP_HB_ENABLE;
2440 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2441 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2443 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2445 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2447 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2448 SCTP_TCB_UNLOCK(stcb);
2450 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2451 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2452 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2453 /* Use endpoint defaults */
2454 SCTP_INP_RLOCK(inp);
2455 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2456 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2457 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2458 /* get inp's default */
2459 if (inp->sctp_ep.default_dscp & 0x01) {
2460 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2461 paddrp->spp_flags |= SPP_DSCP;
2464 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2465 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2466 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2467 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2470 /* can't return this */
2471 paddrp->spp_pathmtu = 0;
2473 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2474 paddrp->spp_flags |= SPP_HB_ENABLE;
2476 paddrp->spp_flags |= SPP_HB_DISABLE;
2478 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2479 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2481 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2483 SCTP_INP_RUNLOCK(inp);
2485 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2490 *optsize = sizeof(struct sctp_paddrparams);
2494 case SCTP_GET_PEER_ADDR_INFO:
2496 struct sctp_paddrinfo *paddri;
2497 struct sctp_nets *net;
2499 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2500 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2504 net = sctp_findnet(stcb, (struct sockaddr *)&paddri->spinfo_address);
2507 * We increment here since
2508 * sctp_findassociation_ep_addr() wil do a
2509 * decrement if it finds the stcb as long as
2510 * the locked tcb (last argument) is NOT a
2513 SCTP_INP_INCR_REF(inp);
2514 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddri->spinfo_address, &net, NULL, NULL);
2516 SCTP_INP_DECR_REF(inp);
2520 if ((stcb) && (net)) {
2521 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2522 /* It's unconfirmed */
2523 paddri->spinfo_state = SCTP_UNCONFIRMED;
2524 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2526 paddri->spinfo_state = SCTP_ACTIVE;
2529 paddri->spinfo_state = SCTP_INACTIVE;
2531 paddri->spinfo_cwnd = net->cwnd;
2532 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2533 paddri->spinfo_rto = net->RTO;
2534 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2535 paddri->spinfo_mtu = net->mtu;
2536 SCTP_TCB_UNLOCK(stcb);
2537 *optsize = sizeof(struct sctp_paddrinfo);
2540 SCTP_TCB_UNLOCK(stcb);
2542 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2547 case SCTP_PCB_STATUS:
2549 struct sctp_pcbinfo *spcb;
2551 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2552 sctp_fill_pcbinfo(spcb);
2553 *optsize = sizeof(struct sctp_pcbinfo);
2558 struct sctp_nets *net;
2559 struct sctp_status *sstat;
2561 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2562 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2565 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2570 * I think passing the state is fine since
2571 * sctp_constants.h will be available to the user
2574 sstat->sstat_state = stcb->asoc.state;
2575 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2576 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2577 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2579 * We can't include chunks that have been passed to
2580 * the socket layer. Only things in queue.
2582 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2583 stcb->asoc.cnt_on_all_streams);
2586 sstat->sstat_instrms = stcb->asoc.streamincnt;
2587 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2588 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2589 memcpy(&sstat->sstat_primary.spinfo_address,
2590 &stcb->asoc.primary_destination->ro._l_addr,
2591 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2592 net = stcb->asoc.primary_destination;
2593 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2595 * Again the user can get info from sctp_constants.h
2596 * for what the state of the network is.
2598 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2599 /* It's unconfirmed */
2600 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2601 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2603 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2606 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2608 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2609 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2610 sstat->sstat_primary.spinfo_rto = net->RTO;
2611 sstat->sstat_primary.spinfo_mtu = net->mtu;
2612 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2613 SCTP_TCB_UNLOCK(stcb);
2614 *optsize = sizeof(struct sctp_status);
2619 struct sctp_rtoinfo *srto;
2621 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2622 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2625 srto->srto_initial = stcb->asoc.initial_rto;
2626 srto->srto_max = stcb->asoc.maxrto;
2627 srto->srto_min = stcb->asoc.minrto;
2628 SCTP_TCB_UNLOCK(stcb);
2630 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2631 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2632 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2633 SCTP_INP_RLOCK(inp);
2634 srto->srto_initial = inp->sctp_ep.initial_rto;
2635 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2636 srto->srto_min = inp->sctp_ep.sctp_minrto;
2637 SCTP_INP_RUNLOCK(inp);
2639 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2644 *optsize = sizeof(struct sctp_rtoinfo);
2650 struct sctp_timeouts *stimo;
2652 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2653 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2656 stimo->stimo_init = stcb->asoc.timoinit;
2657 stimo->stimo_data = stcb->asoc.timodata;
2658 stimo->stimo_sack = stcb->asoc.timosack;
2659 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2660 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2661 stimo->stimo_cookie = stcb->asoc.timocookie;
2662 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2663 SCTP_TCB_UNLOCK(stcb);
2664 *optsize = sizeof(struct sctp_timeouts);
2666 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2671 case SCTP_ASSOCINFO:
2673 struct sctp_assocparams *sasoc;
2675 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2676 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2679 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2680 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2681 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2682 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2683 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2684 SCTP_TCB_UNLOCK(stcb);
2686 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2687 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2688 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2689 SCTP_INP_RLOCK(inp);
2690 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2691 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2692 sasoc->sasoc_number_peer_destinations = 0;
2693 sasoc->sasoc_peer_rwnd = 0;
2694 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2695 SCTP_INP_RUNLOCK(inp);
2697 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2702 *optsize = sizeof(struct sctp_assocparams);
2706 case SCTP_DEFAULT_SEND_PARAM:
2708 struct sctp_sndrcvinfo *s_info;
2710 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2711 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2714 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2715 SCTP_TCB_UNLOCK(stcb);
2717 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2718 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2719 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2720 SCTP_INP_RLOCK(inp);
2721 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2722 SCTP_INP_RUNLOCK(inp);
2724 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2729 *optsize = sizeof(struct sctp_sndrcvinfo);
2735 struct sctp_initmsg *sinit;
2737 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2738 SCTP_INP_RLOCK(inp);
2739 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2740 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2741 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2742 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2743 SCTP_INP_RUNLOCK(inp);
2744 *optsize = sizeof(struct sctp_initmsg);
2747 case SCTP_PRIMARY_ADDR:
2748 /* we allow a "get" operation on this */
2750 struct sctp_setprim *ssp;
2752 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2753 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2756 /* simply copy out the sockaddr_storage... */
2760 if (len > stcb->asoc.primary_destination->ro._l_addr.sa.sa_len)
2761 len = stcb->asoc.primary_destination->ro._l_addr.sa.sa_len;
2763 memcpy(&ssp->ssp_addr,
2764 &stcb->asoc.primary_destination->ro._l_addr,
2766 SCTP_TCB_UNLOCK(stcb);
2767 *optsize = sizeof(struct sctp_setprim);
2769 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2774 case SCTP_HMAC_IDENT:
2776 struct sctp_hmacalgo *shmac;
2777 sctp_hmaclist_t *hmaclist;
2781 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2783 SCTP_INP_RLOCK(inp);
2784 hmaclist = inp->sctp_ep.local_hmacs;
2785 if (hmaclist == NULL) {
2786 /* no HMACs to return */
2787 *optsize = sizeof(*shmac);
2788 SCTP_INP_RUNLOCK(inp);
2791 /* is there room for all of the hmac ids? */
2792 size = sizeof(*shmac) + (hmaclist->num_algo *
2793 sizeof(shmac->shmac_idents[0]));
2794 if ((size_t)(*optsize) < size) {
2795 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2797 SCTP_INP_RUNLOCK(inp);
2800 /* copy in the list */
2801 shmac->shmac_number_of_idents = hmaclist->num_algo;
2802 for (i = 0; i < hmaclist->num_algo; i++) {
2803 shmac->shmac_idents[i] = hmaclist->hmac[i];
2805 SCTP_INP_RUNLOCK(inp);
2809 case SCTP_AUTH_ACTIVE_KEY:
2811 struct sctp_authkeyid *scact;
2813 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2814 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2817 /* get the active key on the assoc */
2818 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2819 SCTP_TCB_UNLOCK(stcb);
2821 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2822 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2823 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2824 /* get the endpoint active key */
2825 SCTP_INP_RLOCK(inp);
2826 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2827 SCTP_INP_RUNLOCK(inp);
2829 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2834 *optsize = sizeof(struct sctp_authkeyid);
2838 case SCTP_LOCAL_AUTH_CHUNKS:
2840 struct sctp_authchunks *sac;
2841 sctp_auth_chklist_t *chklist = NULL;
2844 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2845 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2848 /* get off the assoc */
2849 chklist = stcb->asoc.local_auth_chunks;
2850 /* is there enough space? */
2851 size = sctp_auth_get_chklist_size(chklist);
2852 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2856 /* copy in the chunks */
2857 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2858 sac->gauth_number_of_chunks = (uint32_t) size;
2859 *optsize = sizeof(struct sctp_authchunks) + size;
2861 SCTP_TCB_UNLOCK(stcb);
2863 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2864 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2865 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2866 /* get off the endpoint */
2867 SCTP_INP_RLOCK(inp);
2868 chklist = inp->sctp_ep.local_auth_chunks;
2869 /* is there enough space? */
2870 size = sctp_auth_get_chklist_size(chklist);
2871 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2873 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2875 /* copy in the chunks */
2876 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2877 sac->gauth_number_of_chunks = (uint32_t) size;
2878 *optsize = sizeof(struct sctp_authchunks) + size;
2880 SCTP_INP_RUNLOCK(inp);
2882 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2888 case SCTP_PEER_AUTH_CHUNKS:
2890 struct sctp_authchunks *sac;
2891 sctp_auth_chklist_t *chklist = NULL;
2894 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2895 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2898 /* get off the assoc */
2899 chklist = stcb->asoc.peer_auth_chunks;
2900 /* is there enough space? */
2901 size = sctp_auth_get_chklist_size(chklist);
2902 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2904 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2906 /* copy in the chunks */
2907 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2908 sac->gauth_number_of_chunks = (uint32_t) size;
2909 *optsize = sizeof(struct sctp_authchunks) + size;
2911 SCTP_TCB_UNLOCK(stcb);
2913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2920 struct sctp_event *event;
2921 uint32_t event_type;
2923 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2924 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
2926 switch (event->se_type) {
2927 case SCTP_ASSOC_CHANGE:
2928 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
2930 case SCTP_PEER_ADDR_CHANGE:
2931 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
2933 case SCTP_REMOTE_ERROR:
2934 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
2936 case SCTP_SEND_FAILED:
2937 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
2939 case SCTP_SHUTDOWN_EVENT:
2940 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
2942 case SCTP_ADAPTATION_INDICATION:
2943 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
2945 case SCTP_PARTIAL_DELIVERY_EVENT:
2946 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
2948 case SCTP_AUTHENTICATION_EVENT:
2949 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
2951 case SCTP_STREAM_RESET_EVENT:
2952 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
2954 case SCTP_SENDER_DRY_EVENT:
2955 event_type = SCTP_PCB_FLAGS_DRYEVNT;
2957 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
2959 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
2962 case SCTP_ASSOC_RESET_EVENT:
2963 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
2965 case SCTP_STREAM_CHANGE_EVENT:
2966 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
2968 case SCTP_SEND_FAILED_EVENT:
2969 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
2973 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2977 if (event_type > 0) {
2979 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
2980 SCTP_TCB_UNLOCK(stcb);
2982 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2983 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2984 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
2985 SCTP_INP_RLOCK(inp);
2986 event->se_on = sctp_is_feature_on(inp, event_type);
2987 SCTP_INP_RUNLOCK(inp);
2989 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2995 *optsize = sizeof(struct sctp_event);
2999 case SCTP_RECVRCVINFO:
3003 if (*optsize < sizeof(int)) {
3004 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3007 SCTP_INP_RLOCK(inp);
3008 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3009 SCTP_INP_RUNLOCK(inp);
3012 /* return the option value */
3013 *(int *)optval = onoff;
3014 *optsize = sizeof(int);
3018 case SCTP_RECVNXTINFO:
3022 if (*optsize < sizeof(int)) {
3023 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3026 SCTP_INP_RLOCK(inp);
3027 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3028 SCTP_INP_RUNLOCK(inp);
3031 /* return the option value */
3032 *(int *)optval = onoff;
3033 *optsize = sizeof(int);
3037 case SCTP_DEFAULT_SNDINFO:
3039 struct sctp_sndinfo *info;
3041 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3042 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3045 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3046 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3047 info->snd_flags &= 0xfff0;
3048 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3049 info->snd_context = stcb->asoc.def_send.sinfo_context;
3050 SCTP_TCB_UNLOCK(stcb);
3052 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3053 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3054 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3055 SCTP_INP_RLOCK(inp);
3056 info->snd_sid = inp->def_send.sinfo_stream;
3057 info->snd_flags = inp->def_send.sinfo_flags;
3058 info->snd_flags &= 0xfff0;
3059 info->snd_ppid = inp->def_send.sinfo_ppid;
3060 info->snd_context = inp->def_send.sinfo_context;
3061 SCTP_INP_RUNLOCK(inp);
3063 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3068 *optsize = sizeof(struct sctp_sndinfo);
3072 case SCTP_DEFAULT_PRINFO:
3074 struct sctp_default_prinfo *info;
3076 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3077 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3080 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3081 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3082 SCTP_TCB_UNLOCK(stcb);
3084 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3085 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3086 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3087 SCTP_INP_RLOCK(inp);
3088 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3089 info->pr_value = inp->def_send.sinfo_timetolive;
3090 SCTP_INP_RUNLOCK(inp);
3092 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3097 *optsize = sizeof(struct sctp_default_prinfo);
3101 case SCTP_PEER_ADDR_THLDS:
3103 struct sctp_paddrthlds *thlds;
3104 struct sctp_nets *net;
3106 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3107 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3111 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_address);
3114 * We increment here since
3115 * sctp_findassociation_ep_addr() wil do a
3116 * decrement if it finds the stcb as long as
3117 * the locked tcb (last argument) is NOT a
3120 SCTP_INP_INCR_REF(inp);
3121 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&thlds->spt_address, &net, NULL, NULL);
3123 SCTP_INP_DECR_REF(inp);
3126 if (stcb && (net == NULL)) {
3127 struct sockaddr *sa;
3129 sa = (struct sockaddr *)&thlds->spt_address;
3131 if (sa->sa_family == AF_INET) {
3132 struct sockaddr_in *sin;
3134 sin = (struct sockaddr_in *)sa;
3135 if (sin->sin_addr.s_addr) {
3137 SCTP_TCB_UNLOCK(stcb);
3138 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3144 if (sa->sa_family == AF_INET6) {
3145 struct sockaddr_in6 *sin6;
3147 sin6 = (struct sockaddr_in6 *)sa;
3148 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3150 SCTP_TCB_UNLOCK(stcb);
3151 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3157 error = EAFNOSUPPORT;
3158 SCTP_TCB_UNLOCK(stcb);
3159 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3165 thlds->spt_pathmaxrxt = net->failure_threshold;
3166 thlds->spt_pathpfthld = net->pf_threshold;
3168 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3169 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3171 thlds->spt_assoc_id = sctp_get_associd(stcb);
3172 SCTP_TCB_UNLOCK(stcb);
3174 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3175 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3176 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3177 /* Use endpoint defaults */
3178 SCTP_INP_RLOCK(inp);
3179 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3180 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3181 SCTP_INP_RUNLOCK(inp);
3183 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3188 *optsize = sizeof(struct sctp_paddrthlds);
3192 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3194 struct sctp_udpencaps *encaps;
3195 struct sctp_nets *net;
3197 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3198 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3201 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
3204 * We increment here since
3205 * sctp_findassociation_ep_addr() wil do a
3206 * decrement if it finds the stcb as long as
3207 * the locked tcb (last argument) is NOT a
3211 SCTP_INP_INCR_REF(inp);
3212 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
3214 SCTP_INP_DECR_REF(inp);
3217 if (stcb && (net == NULL)) {
3218 struct sockaddr *sa;
3220 sa = (struct sockaddr *)&encaps->sue_address;
3222 if (sa->sa_family == AF_INET) {
3223 struct sockaddr_in *sin;
3225 sin = (struct sockaddr_in *)sa;
3226 if (sin->sin_addr.s_addr) {
3228 SCTP_TCB_UNLOCK(stcb);
3229 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3235 if (sa->sa_family == AF_INET6) {
3236 struct sockaddr_in6 *sin6;
3238 sin6 = (struct sockaddr_in6 *)sa;
3239 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3241 SCTP_TCB_UNLOCK(stcb);
3242 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3248 error = EAFNOSUPPORT;
3249 SCTP_TCB_UNLOCK(stcb);
3250 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3256 encaps->sue_port = net->port;
3258 encaps->sue_port = stcb->asoc.port;
3260 SCTP_TCB_UNLOCK(stcb);
3262 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3263 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3264 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3265 SCTP_INP_RLOCK(inp);
3266 encaps->sue_port = inp->sctp_ep.port;
3267 SCTP_INP_RUNLOCK(inp);
3269 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3274 *optsize = sizeof(struct sctp_paddrparams);
3278 case SCTP_ENABLE_STREAM_RESET:
3280 struct sctp_assoc_value *av;
3282 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3283 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3286 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3287 SCTP_TCB_UNLOCK(stcb);
3289 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3290 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3291 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3292 SCTP_INP_RLOCK(inp);
3293 av->assoc_value = (uint32_t) inp->local_strreset_support;
3294 SCTP_INP_RUNLOCK(inp);
3296 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3301 *optsize = sizeof(struct sctp_assoc_value);
3306 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3307 error = ENOPROTOOPT;
3309 } /* end switch (sopt->sopt_name) */
3317 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3322 struct sctp_tcb *stcb = NULL;
3323 struct sctp_inpcb *inp = NULL;
3326 if (optval == NULL) {
3327 SCTP_PRINTF("optval is NULL\n");
3328 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3331 inp = (struct sctp_inpcb *)so->so_pcb;
3333 SCTP_PRINTF("inp is NULL?\n");
3334 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3337 vrf_id = inp->def_vrf_id;
3342 case SCTP_AUTOCLOSE:
3343 case SCTP_AUTO_ASCONF:
3344 case SCTP_EXPLICIT_EOR:
3345 case SCTP_DISABLE_FRAGMENTS:
3346 case SCTP_USE_EXT_RCVINFO:
3347 case SCTP_I_WANT_MAPPED_V4_ADDR:
3348 /* copy in the option value */
3349 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3354 case SCTP_DISABLE_FRAGMENTS:
3355 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3357 case SCTP_AUTO_ASCONF:
3359 * NOTE: we don't really support this flag
3361 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3362 /* only valid for bound all sockets */
3363 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3365 /* forbidden by admin */
3366 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3369 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3371 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3375 case SCTP_EXPLICIT_EOR:
3376 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3378 case SCTP_USE_EXT_RCVINFO:
3379 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3381 case SCTP_I_WANT_MAPPED_V4_ADDR:
3382 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3383 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3385 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3390 set_opt = SCTP_PCB_FLAGS_NODELAY;
3392 case SCTP_AUTOCLOSE:
3393 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3394 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3395 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3398 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3400 * The value is in ticks. Note this does not effect
3401 * old associations, only new ones.
3403 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3406 SCTP_INP_WLOCK(inp);
3408 sctp_feature_on(inp, set_opt);
3410 sctp_feature_off(inp, set_opt);
3412 SCTP_INP_WUNLOCK(inp);
3414 case SCTP_REUSE_PORT:
3416 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3417 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3418 /* Can't set it after we are bound */
3422 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3423 /* Can't do this for a 1-m socket */
3428 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3430 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3433 case SCTP_PARTIAL_DELIVERY_POINT:
3437 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3438 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3439 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3443 inp->partial_delivery_point = *value;
3446 case SCTP_FRAGMENT_INTERLEAVE:
3447 /* not yet until we re-write sctp_recvmsg() */
3451 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3452 if (*level == SCTP_FRAG_LEVEL_2) {
3453 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3454 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3455 } else if (*level == SCTP_FRAG_LEVEL_1) {
3456 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3457 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3458 } else if (*level == SCTP_FRAG_LEVEL_0) {
3459 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3460 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3463 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3468 case SCTP_CMT_ON_OFF:
3469 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3470 struct sctp_assoc_value *av;
3472 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3473 if (av->assoc_value > SCTP_CMT_MAX) {
3474 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3478 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3480 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3481 SCTP_TCB_UNLOCK(stcb);
3483 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3484 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3485 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3486 (av->assoc_id == SCTP_ALL_ASSOC)) {
3487 SCTP_INP_WLOCK(inp);
3488 inp->sctp_cmt_on_off = av->assoc_value;
3489 SCTP_INP_WUNLOCK(inp);
3491 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3492 (av->assoc_id == SCTP_ALL_ASSOC)) {
3493 SCTP_INP_RLOCK(inp);
3494 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3495 SCTP_TCB_LOCK(stcb);
3496 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3497 SCTP_TCB_UNLOCK(stcb);
3499 SCTP_INP_RUNLOCK(inp);
3503 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3504 error = ENOPROTOOPT;
3507 case SCTP_PLUGGABLE_CC:
3509 struct sctp_assoc_value *av;
3510 struct sctp_nets *net;
3512 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3513 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3514 (av->assoc_value != SCTP_CC_HSTCP) &&
3515 (av->assoc_value != SCTP_CC_HTCP) &&
3516 (av->assoc_value != SCTP_CC_RTCC)) {
3517 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3521 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3523 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3524 stcb->asoc.congestion_control_module = av->assoc_value;
3525 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3526 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3527 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3530 SCTP_TCB_UNLOCK(stcb);
3532 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3533 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3534 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3535 (av->assoc_id == SCTP_ALL_ASSOC)) {
3536 SCTP_INP_WLOCK(inp);
3537 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3538 SCTP_INP_WUNLOCK(inp);
3540 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3541 (av->assoc_id == SCTP_ALL_ASSOC)) {
3542 SCTP_INP_RLOCK(inp);
3543 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3544 SCTP_TCB_LOCK(stcb);
3545 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3546 stcb->asoc.congestion_control_module = av->assoc_value;
3547 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3548 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3549 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3552 SCTP_TCB_UNLOCK(stcb);
3554 SCTP_INP_RUNLOCK(inp);
3559 case SCTP_CC_OPTION:
3561 struct sctp_cc_option *cc_opt;
3563 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
3564 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
3566 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
3567 SCTP_INP_RLOCK(inp);
3568 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3569 SCTP_TCB_LOCK(stcb);
3570 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
3571 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
3573 SCTP_TCB_UNLOCK(stcb);
3575 SCTP_INP_RUNLOCK(inp);
3580 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
3583 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
3586 SCTP_TCB_UNLOCK(stcb);
3590 case SCTP_PLUGGABLE_SS:
3592 struct sctp_assoc_value *av;
3594 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3595 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
3596 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
3597 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
3598 (av->assoc_value != SCTP_SS_PRIORITY) &&
3599 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
3600 (av->assoc_value != SCTP_SS_FIRST_COME)) {
3601 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3605 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3607 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3608 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3609 stcb->asoc.stream_scheduling_module = av->assoc_value;
3610 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3611 SCTP_TCB_UNLOCK(stcb);
3613 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3614 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3615 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3616 (av->assoc_id == SCTP_ALL_ASSOC)) {
3617 SCTP_INP_WLOCK(inp);
3618 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
3619 SCTP_INP_WUNLOCK(inp);
3621 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3622 (av->assoc_id == SCTP_ALL_ASSOC)) {
3623 SCTP_INP_RLOCK(inp);
3624 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3625 SCTP_TCB_LOCK(stcb);
3626 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3627 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3628 stcb->asoc.stream_scheduling_module = av->assoc_value;
3629 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3630 SCTP_TCB_UNLOCK(stcb);
3632 SCTP_INP_RUNLOCK(inp);
3639 struct sctp_stream_value *av;
3641 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
3642 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3644 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
3645 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
3646 av->stream_value) < 0)) {
3647 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3650 SCTP_TCB_UNLOCK(stcb);
3652 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
3653 SCTP_INP_RLOCK(inp);
3654 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3655 SCTP_TCB_LOCK(stcb);
3656 if (av->stream_id < stcb->asoc.streamoutcnt) {
3657 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
3659 &stcb->asoc.strmout[av->stream_id],
3662 SCTP_TCB_UNLOCK(stcb);
3664 SCTP_INP_RUNLOCK(inp);
3668 * Can't set stream value without
3671 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3677 case SCTP_CLR_STAT_LOG:
3678 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3683 struct sctp_assoc_value *av;
3685 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3686 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3689 stcb->asoc.context = av->assoc_value;
3690 SCTP_TCB_UNLOCK(stcb);
3692 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3693 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3694 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3695 (av->assoc_id == SCTP_ALL_ASSOC)) {
3696 SCTP_INP_WLOCK(inp);
3697 inp->sctp_context = av->assoc_value;
3698 SCTP_INP_WUNLOCK(inp);
3700 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3701 (av->assoc_id == SCTP_ALL_ASSOC)) {
3702 SCTP_INP_RLOCK(inp);
3703 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3704 SCTP_TCB_LOCK(stcb);
3705 stcb->asoc.context = av->assoc_value;
3706 SCTP_TCB_UNLOCK(stcb);
3708 SCTP_INP_RUNLOCK(inp);
3715 uint32_t *default_vrfid;
3717 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
3718 if (*default_vrfid > SCTP_MAX_VRF_ID) {
3719 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3723 inp->def_vrf_id = *default_vrfid;
3726 case SCTP_DEL_VRF_ID:
3728 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3732 case SCTP_ADD_VRF_ID:
3734 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3738 case SCTP_DELAYED_SACK:
3740 struct sctp_sack_info *sack;
3742 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
3743 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
3744 if (sack->sack_delay) {
3745 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
3746 sack->sack_delay = SCTP_MAX_SACK_DELAY;
3747 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
3748 sack->sack_delay = TICKS_TO_MSEC(1);
3752 if (sack->sack_delay) {
3753 stcb->asoc.delayed_ack = sack->sack_delay;
3755 if (sack->sack_freq) {
3756 stcb->asoc.sack_freq = sack->sack_freq;
3758 SCTP_TCB_UNLOCK(stcb);
3760 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3761 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3762 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
3763 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3764 SCTP_INP_WLOCK(inp);
3765 if (sack->sack_delay) {
3766 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
3768 if (sack->sack_freq) {
3769 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
3771 SCTP_INP_WUNLOCK(inp);
3773 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
3774 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3775 SCTP_INP_RLOCK(inp);
3776 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3777 SCTP_TCB_LOCK(stcb);
3778 if (sack->sack_delay) {
3779 stcb->asoc.delayed_ack = sack->sack_delay;
3781 if (sack->sack_freq) {
3782 stcb->asoc.sack_freq = sack->sack_freq;
3784 SCTP_TCB_UNLOCK(stcb);
3786 SCTP_INP_RUNLOCK(inp);
3791 case SCTP_AUTH_CHUNK:
3793 struct sctp_authchunk *sauth;
3795 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
3797 SCTP_INP_WLOCK(inp);
3798 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
3799 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3802 SCTP_INP_WUNLOCK(inp);
3807 struct sctp_authkey *sca;
3808 struct sctp_keyhead *shared_keys;
3809 sctp_sharedkey_t *shared_key;
3810 sctp_key_t *key = NULL;
3813 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
3814 if (sca->sca_keylength == 0) {
3815 size = optsize - sizeof(struct sctp_authkey);
3817 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
3818 size = sca->sca_keylength;
3820 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3825 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
3828 shared_keys = &stcb->asoc.shared_keys;
3829 /* clear the cached keys for this key id */
3830 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3832 * create the new shared key and
3836 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3838 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3840 SCTP_TCB_UNLOCK(stcb);
3844 shared_key = sctp_alloc_sharedkey();
3845 if (shared_key == NULL) {
3847 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3849 SCTP_TCB_UNLOCK(stcb);
3852 shared_key->key = key;
3853 shared_key->keyid = sca->sca_keynumber;
3854 error = sctp_insert_sharedkey(shared_keys, shared_key);
3855 SCTP_TCB_UNLOCK(stcb);
3857 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3858 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3859 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
3860 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3861 SCTP_INP_WLOCK(inp);
3862 shared_keys = &inp->sctp_ep.shared_keys;
3864 * clear the cached keys on all
3865 * assocs for this key id
3867 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
3869 * create the new shared key and
3873 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3875 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3877 SCTP_INP_WUNLOCK(inp);
3881 shared_key = sctp_alloc_sharedkey();
3882 if (shared_key == NULL) {
3884 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3886 SCTP_INP_WUNLOCK(inp);
3889 shared_key->key = key;
3890 shared_key->keyid = sca->sca_keynumber;
3891 error = sctp_insert_sharedkey(shared_keys, shared_key);
3892 SCTP_INP_WUNLOCK(inp);
3894 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
3895 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3896 SCTP_INP_RLOCK(inp);
3897 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3898 SCTP_TCB_LOCK(stcb);
3899 shared_keys = &stcb->asoc.shared_keys;
3901 * clear the cached keys for
3904 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3906 * create the new shared key
3907 * and insert/replace it
3910 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3912 SCTP_TCB_UNLOCK(stcb);
3916 shared_key = sctp_alloc_sharedkey();
3917 if (shared_key == NULL) {
3919 SCTP_TCB_UNLOCK(stcb);
3922 shared_key->key = key;
3923 shared_key->keyid = sca->sca_keynumber;
3924 error = sctp_insert_sharedkey(shared_keys, shared_key);
3925 SCTP_TCB_UNLOCK(stcb);
3927 SCTP_INP_RUNLOCK(inp);
3932 case SCTP_HMAC_IDENT:
3934 struct sctp_hmacalgo *shmac;
3935 sctp_hmaclist_t *hmaclist;
3940 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
3941 if (optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) {
3942 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3946 hmaclist = sctp_alloc_hmaclist(shmac->shmac_number_of_idents);
3947 if (hmaclist == NULL) {
3948 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3952 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
3953 hmacid = shmac->shmac_idents[i];
3954 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
3955 /* invalid HMACs were found */ ;
3956 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3958 sctp_free_hmaclist(hmaclist);
3959 goto sctp_set_hmac_done;
3963 for (i = 0; i < hmaclist->num_algo; i++) {
3964 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
3965 /* already in list */
3970 sctp_free_hmaclist(hmaclist);
3971 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3975 /* set it on the endpoint */
3976 SCTP_INP_WLOCK(inp);
3977 if (inp->sctp_ep.local_hmacs)
3978 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
3979 inp->sctp_ep.local_hmacs = hmaclist;
3980 SCTP_INP_WUNLOCK(inp);
3984 case SCTP_AUTH_ACTIVE_KEY:
3986 struct sctp_authkeyid *scact;
3988 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
3989 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
3991 /* set the active key on the right place */
3993 /* set the active key on the assoc */
3994 if (sctp_auth_setactivekey(stcb,
3995 scact->scact_keynumber)) {
3996 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
3997 SCTP_FROM_SCTP_USRREQ,
4001 SCTP_TCB_UNLOCK(stcb);
4003 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4004 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4005 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4006 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4007 SCTP_INP_WLOCK(inp);
4008 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4009 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4012 SCTP_INP_WUNLOCK(inp);
4014 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4015 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4016 SCTP_INP_RLOCK(inp);
4017 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4018 SCTP_TCB_LOCK(stcb);
4019 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4020 SCTP_TCB_UNLOCK(stcb);
4022 SCTP_INP_RUNLOCK(inp);
4027 case SCTP_AUTH_DELETE_KEY:
4029 struct sctp_authkeyid *scdel;
4031 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4032 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4034 /* delete the key from the right place */
4036 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4037 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4040 SCTP_TCB_UNLOCK(stcb);
4042 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4043 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4044 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4045 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4046 SCTP_INP_WLOCK(inp);
4047 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4048 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4051 SCTP_INP_WUNLOCK(inp);
4053 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4054 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4055 SCTP_INP_RLOCK(inp);
4056 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4057 SCTP_TCB_LOCK(stcb);
4058 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4059 SCTP_TCB_UNLOCK(stcb);
4061 SCTP_INP_RUNLOCK(inp);
4066 case SCTP_AUTH_DEACTIVATE_KEY:
4068 struct sctp_authkeyid *keyid;
4070 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4071 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4073 /* deactivate the key from the right place */
4075 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4076 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4079 SCTP_TCB_UNLOCK(stcb);
4081 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4082 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4083 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4084 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4085 SCTP_INP_WLOCK(inp);
4086 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4087 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4090 SCTP_INP_WUNLOCK(inp);
4092 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4093 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4094 SCTP_INP_RLOCK(inp);
4095 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4096 SCTP_TCB_LOCK(stcb);
4097 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4098 SCTP_TCB_UNLOCK(stcb);
4100 SCTP_INP_RUNLOCK(inp);
4105 case SCTP_ENABLE_STREAM_RESET:
4107 struct sctp_assoc_value *av;
4109 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4110 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4111 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4115 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4117 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4118 SCTP_TCB_UNLOCK(stcb);
4120 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4121 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4122 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4123 (av->assoc_id == SCTP_ALL_ASSOC)) {
4124 SCTP_INP_WLOCK(inp);
4125 inp->local_strreset_support = (uint8_t) av->assoc_value;
4126 SCTP_INP_WUNLOCK(inp);
4128 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4129 (av->assoc_id == SCTP_ALL_ASSOC)) {
4130 SCTP_INP_RLOCK(inp);
4131 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4132 SCTP_TCB_LOCK(stcb);
4133 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4134 SCTP_TCB_UNLOCK(stcb);
4136 SCTP_INP_RUNLOCK(inp);
4141 case SCTP_RESET_STREAMS:
4143 struct sctp_reset_streams *strrst;
4144 int i, send_out = 0;
4147 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4148 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4150 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4154 if (stcb->asoc.peer_supports_strreset == 0) {
4156 * Peer does not support the chunk type.
4158 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4160 SCTP_TCB_UNLOCK(stcb);
4163 if (stcb->asoc.stream_reset_outstanding) {
4164 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4166 SCTP_TCB_UNLOCK(stcb);
4169 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4172 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4175 if ((send_in == 0) && (send_out == 0)) {
4176 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4178 SCTP_TCB_UNLOCK(stcb);
4181 for (i = 0; i < strrst->srs_number_streams; i++) {
4183 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4184 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4189 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4190 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4196 SCTP_TCB_UNLOCK(stcb);
4199 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4200 strrst->srs_stream_list,
4201 send_out, send_in, 0, 0, 0, 0, 0);
4203 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4204 SCTP_TCB_UNLOCK(stcb);
4207 case SCTP_ADD_STREAMS:
4209 struct sctp_add_streams *stradd;
4210 uint8_t addstream = 0;
4211 uint16_t add_o_strmcnt = 0;
4212 uint16_t add_i_strmcnt = 0;
4214 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4215 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4217 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4221 if (stcb->asoc.peer_supports_strreset == 0) {
4223 * Peer does not support the chunk type.
4225 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4227 SCTP_TCB_UNLOCK(stcb);
4230 if (stcb->asoc.stream_reset_outstanding) {
4231 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4233 SCTP_TCB_UNLOCK(stcb);
4236 if ((stradd->sas_outstrms == 0) &&
4237 (stradd->sas_instrms == 0)) {
4241 if (stradd->sas_outstrms) {
4243 /* We allocate here */
4244 add_o_strmcnt = stradd->sas_outstrms;
4245 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4246 /* You can't have more than 64k */
4251 if (stradd->sas_instrms) {
4256 * We allocate inside
4257 * sctp_send_str_reset_req()
4259 add_i_strmcnt = stradd->sas_instrms;
4260 cnt = add_i_strmcnt;
4261 cnt += stcb->asoc.streamincnt;
4262 if (cnt > 0x0000ffff) {
4263 /* You can't have more than 64k */
4267 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4268 /* More than you are allowed */
4273 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4274 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4276 SCTP_TCB_UNLOCK(stcb);
4279 case SCTP_RESET_ASSOC:
4283 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4284 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4286 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4290 if (stcb->asoc.peer_supports_strreset == 0) {
4292 * Peer does not support the chunk type.
4294 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4296 SCTP_TCB_UNLOCK(stcb);
4299 if (stcb->asoc.stream_reset_outstanding) {
4300 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4302 SCTP_TCB_UNLOCK(stcb);
4305 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 1, 0, 0, 0, 0);
4306 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4307 SCTP_TCB_UNLOCK(stcb);
4310 case SCTP_CONNECT_X:
4311 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4312 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4316 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4318 case SCTP_CONNECT_X_DELAYED:
4319 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4320 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4324 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4326 case SCTP_CONNECT_X_COMPLETE:
4328 struct sockaddr *sa;
4329 struct sctp_nets *net;
4331 /* FIXME MT: check correct? */
4332 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4335 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4336 SCTP_INP_RLOCK(inp);
4337 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4339 SCTP_TCB_LOCK(stcb);
4340 net = sctp_findnet(stcb, sa);
4342 SCTP_INP_RUNLOCK(inp);
4345 * We increment here since
4346 * sctp_findassociation_ep_addr() wil do a
4347 * decrement if it finds the stcb as long as
4348 * the locked tcb (last argument) is NOT a
4351 SCTP_INP_INCR_REF(inp);
4352 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
4354 SCTP_INP_DECR_REF(inp);
4359 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4363 if (stcb->asoc.delayed_connection == 1) {
4364 stcb->asoc.delayed_connection = 0;
4365 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4366 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4367 stcb->asoc.primary_destination,
4368 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
4369 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4372 * already expired or did not use delayed
4375 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4378 SCTP_TCB_UNLOCK(stcb);
4381 case SCTP_MAX_BURST:
4385 SCTP_CHECK_AND_CAST(burst, optval, uint8_t, optsize);
4387 SCTP_INP_WLOCK(inp);
4388 inp->sctp_ep.max_burst = *burst;
4389 SCTP_INP_WUNLOCK(inp);
4394 struct sctp_assoc_value *av;
4397 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4398 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4400 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4401 ovh = SCTP_MED_OVERHEAD;
4403 ovh = SCTP_MED_V4_OVERHEAD;
4406 if (av->assoc_value) {
4407 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4409 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4411 SCTP_TCB_UNLOCK(stcb);
4413 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4414 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4415 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4416 SCTP_INP_WLOCK(inp);
4418 * FIXME MT: I think this is not in
4419 * tune with the API ID
4421 if (av->assoc_value) {
4422 inp->sctp_frag_point = (av->assoc_value + ovh);
4424 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4426 SCTP_INP_WUNLOCK(inp);
4428 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4436 struct sctp_event_subscribe *events;
4438 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4440 SCTP_INP_WLOCK(inp);
4441 if (events->sctp_data_io_event) {
4442 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4444 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4447 if (events->sctp_association_event) {
4448 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4450 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4453 if (events->sctp_address_event) {
4454 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4456 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4459 if (events->sctp_send_failure_event) {
4460 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4462 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4465 if (events->sctp_peer_error_event) {
4466 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4468 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4471 if (events->sctp_shutdown_event) {
4472 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4474 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4477 if (events->sctp_partial_delivery_event) {
4478 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4480 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4483 if (events->sctp_adaptation_layer_event) {
4484 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4486 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4489 if (events->sctp_authentication_event) {
4490 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4492 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4495 if (events->sctp_sender_dry_event) {
4496 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
4498 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
4501 if (events->sctp_stream_reset_event) {
4502 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4504 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4506 SCTP_INP_WUNLOCK(inp);
4508 SCTP_INP_RLOCK(inp);
4509 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4510 SCTP_TCB_LOCK(stcb);
4511 if (events->sctp_association_event) {
4512 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4514 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4516 if (events->sctp_address_event) {
4517 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4519 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4521 if (events->sctp_send_failure_event) {
4522 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4524 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4526 if (events->sctp_peer_error_event) {
4527 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4529 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4531 if (events->sctp_shutdown_event) {
4532 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4534 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4536 if (events->sctp_partial_delivery_event) {
4537 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4539 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4541 if (events->sctp_adaptation_layer_event) {
4542 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4544 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4546 if (events->sctp_authentication_event) {
4547 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4549 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4551 if (events->sctp_sender_dry_event) {
4552 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4554 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4556 if (events->sctp_stream_reset_event) {
4557 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4559 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4561 SCTP_TCB_UNLOCK(stcb);
4564 * Send up the sender dry event only for 1-to-1
4567 if (events->sctp_sender_dry_event) {
4568 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4569 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
4570 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4572 SCTP_TCB_LOCK(stcb);
4573 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
4574 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
4575 (stcb->asoc.stream_queue_cnt == 0)) {
4576 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
4578 SCTP_TCB_UNLOCK(stcb);
4582 SCTP_INP_RUNLOCK(inp);
4585 case SCTP_ADAPTATION_LAYER:
4587 struct sctp_setadaptation *adap_bits;
4589 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
4590 SCTP_INP_WLOCK(inp);
4591 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
4592 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
4593 SCTP_INP_WUNLOCK(inp);
4597 case SCTP_SET_INITIAL_DBG_SEQ:
4601 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
4602 SCTP_INP_WLOCK(inp);
4603 inp->sctp_ep.initial_sequence_debug = *vvv;
4604 SCTP_INP_WUNLOCK(inp);
4608 case SCTP_DEFAULT_SEND_PARAM:
4610 struct sctp_sndrcvinfo *s_info;
4612 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
4613 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
4616 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4617 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4619 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4622 SCTP_TCB_UNLOCK(stcb);
4624 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4625 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4626 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
4627 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4628 SCTP_INP_WLOCK(inp);
4629 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
4630 SCTP_INP_WUNLOCK(inp);
4632 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
4633 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4634 SCTP_INP_RLOCK(inp);
4635 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4636 SCTP_TCB_LOCK(stcb);
4637 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4638 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4640 SCTP_TCB_UNLOCK(stcb);
4642 SCTP_INP_RUNLOCK(inp);
4647 case SCTP_PEER_ADDR_PARAMS:
4649 struct sctp_paddrparams *paddrp;
4650 struct sctp_nets *net;
4652 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
4653 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
4656 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
4659 * We increment here since
4660 * sctp_findassociation_ep_addr() wil do a
4661 * decrement if it finds the stcb as long as
4662 * the locked tcb (last argument) is NOT a
4665 SCTP_INP_INCR_REF(inp);
4666 stcb = sctp_findassociation_ep_addr(&inp,
4667 (struct sockaddr *)&paddrp->spp_address,
4670 SCTP_INP_DECR_REF(inp);
4673 if (stcb && (net == NULL)) {
4674 struct sockaddr *sa;
4676 sa = (struct sockaddr *)&paddrp->spp_address;
4678 if (sa->sa_family == AF_INET) {
4680 struct sockaddr_in *sin;
4682 sin = (struct sockaddr_in *)sa;
4683 if (sin->sin_addr.s_addr) {
4684 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4685 SCTP_TCB_UNLOCK(stcb);
4692 if (sa->sa_family == AF_INET6) {
4693 struct sockaddr_in6 *sin6;
4695 sin6 = (struct sockaddr_in6 *)sa;
4696 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
4697 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4698 SCTP_TCB_UNLOCK(stcb);
4705 error = EAFNOSUPPORT;
4706 SCTP_TCB_UNLOCK(stcb);
4707 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4712 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
4714 SCTP_TCB_UNLOCK(stcb);
4715 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4718 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
4720 SCTP_TCB_UNLOCK(stcb);
4721 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4725 /************************TCB SPECIFIC SET ******************/
4727 * do we change the timer for HB, we run
4732 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4733 ovh = SCTP_MED_OVERHEAD;
4735 ovh = SCTP_MED_V4_OVERHEAD;
4738 /* network sets ? */
4740 /************************NET SPECIFIC SET ******************/
4741 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4742 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
4743 !(net->dest_state & SCTP_ADDR_NOHB)) {
4744 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4745 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4747 net->dest_state |= SCTP_ADDR_NOHB;
4749 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4750 if (paddrp->spp_hbinterval) {
4751 net->heart_beat_delay = paddrp->spp_hbinterval;
4752 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4753 net->heart_beat_delay = 0;
4755 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4756 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4757 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4758 net->dest_state &= ~SCTP_ADDR_NOHB;
4760 if (paddrp->spp_flags & SPP_HB_DEMAND) {
4762 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4763 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
4764 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4766 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4767 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4768 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4769 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4771 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4772 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4773 net->mtu = paddrp->spp_pathmtu + ovh;
4774 if (net->mtu < stcb->asoc.smallest_mtu) {
4775 sctp_pathmtu_adjustment(stcb, net->mtu);
4779 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4780 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4781 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4783 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4785 if (paddrp->spp_pathmaxrxt) {
4786 if (net->dest_state & SCTP_ADDR_PF) {
4787 if (net->error_count > paddrp->spp_pathmaxrxt) {
4788 net->dest_state &= ~SCTP_ADDR_PF;
4791 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4792 (net->error_count > net->pf_threshold)) {
4793 net->dest_state |= SCTP_ADDR_PF;
4794 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4795 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4796 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4799 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4800 if (net->error_count > paddrp->spp_pathmaxrxt) {
4801 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4802 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
4805 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4806 net->dest_state |= SCTP_ADDR_REACHABLE;
4807 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
4810 net->failure_threshold = paddrp->spp_pathmaxrxt;
4812 if (paddrp->spp_flags & SPP_DSCP) {
4813 net->dscp = paddrp->spp_dscp & 0xfc;
4817 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4818 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4819 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4820 net->flowlabel |= 0x80000000;
4825 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
4826 if (paddrp->spp_pathmaxrxt) {
4827 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
4828 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4829 if (net->dest_state & SCTP_ADDR_PF) {
4830 if (net->error_count > paddrp->spp_pathmaxrxt) {
4831 net->dest_state &= ~SCTP_ADDR_PF;
4834 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4835 (net->error_count > net->pf_threshold)) {
4836 net->dest_state |= SCTP_ADDR_PF;
4837 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4838 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4839 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4842 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4843 if (net->error_count > paddrp->spp_pathmaxrxt) {
4844 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4845 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
4848 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4849 net->dest_state |= SCTP_ADDR_REACHABLE;
4850 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
4853 net->failure_threshold = paddrp->spp_pathmaxrxt;
4856 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4857 if (paddrp->spp_hbinterval) {
4858 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
4859 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4860 stcb->asoc.heart_beat_delay = 0;
4862 /* Turn back on the timer */
4863 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4864 if (paddrp->spp_hbinterval) {
4865 net->heart_beat_delay = paddrp->spp_hbinterval;
4866 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4867 net->heart_beat_delay = 0;
4869 if (net->dest_state & SCTP_ADDR_NOHB) {
4870 net->dest_state &= ~SCTP_ADDR_NOHB;
4872 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4873 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4874 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4876 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4878 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4879 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4880 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
4881 net->dest_state |= SCTP_ADDR_NOHB;
4882 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
4883 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4887 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4889 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4890 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4891 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4892 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4893 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4895 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4896 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4897 net->mtu = paddrp->spp_pathmtu + ovh;
4898 if (net->mtu < stcb->asoc.smallest_mtu) {
4899 sctp_pathmtu_adjustment(stcb, net->mtu);
4903 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4905 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4906 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4907 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4908 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4910 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4912 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4914 if (paddrp->spp_flags & SPP_DSCP) {
4915 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4916 net->dscp = paddrp->spp_dscp & 0xfc;
4919 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
4920 stcb->asoc.default_dscp |= 0x01;
4923 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4924 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4925 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4926 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4927 net->flowlabel |= 0x80000000;
4930 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4931 stcb->asoc.default_flowlabel |= 0x80000000;
4935 SCTP_TCB_UNLOCK(stcb);
4937 /************************NO TCB, SET TO default stuff ******************/
4938 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4939 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4940 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
4941 SCTP_INP_WLOCK(inp);
4943 * For the TOS/FLOWLABEL stuff you
4944 * set it with the options on the
4947 if (paddrp->spp_pathmaxrxt) {
4948 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
4950 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
4951 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4952 else if (paddrp->spp_hbinterval) {
4953 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
4954 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
4955 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4957 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4958 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4959 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4960 } else if (paddrp->spp_hbinterval) {
4961 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4963 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4964 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
4965 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4967 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4968 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4969 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
4970 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4972 if (paddrp->spp_flags & SPP_DSCP) {
4973 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
4974 inp->sctp_ep.default_dscp |= 0x01;
4977 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4978 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4979 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4980 inp->sctp_ep.default_flowlabel |= 0x80000000;
4984 SCTP_INP_WUNLOCK(inp);
4986 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4994 struct sctp_rtoinfo *srto;
4995 uint32_t new_init, new_min, new_max;
4997 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
4998 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5001 if (srto->srto_initial)
5002 new_init = srto->srto_initial;
5004 new_init = stcb->asoc.initial_rto;
5006 new_max = srto->srto_max;
5008 new_max = stcb->asoc.maxrto;
5010 new_min = srto->srto_min;
5012 new_min = stcb->asoc.minrto;
5013 if ((new_min <= new_init) && (new_init <= new_max)) {
5014 stcb->asoc.initial_rto = new_init;
5015 stcb->asoc.maxrto = new_max;
5016 stcb->asoc.minrto = new_min;
5018 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5021 SCTP_TCB_UNLOCK(stcb);
5023 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5024 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5025 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5026 SCTP_INP_WLOCK(inp);
5027 if (srto->srto_initial)
5028 new_init = srto->srto_initial;
5030 new_init = inp->sctp_ep.initial_rto;
5032 new_max = srto->srto_max;
5034 new_max = inp->sctp_ep.sctp_maxrto;
5036 new_min = srto->srto_min;
5038 new_min = inp->sctp_ep.sctp_minrto;
5039 if ((new_min <= new_init) && (new_init <= new_max)) {
5040 inp->sctp_ep.initial_rto = new_init;
5041 inp->sctp_ep.sctp_maxrto = new_max;
5042 inp->sctp_ep.sctp_minrto = new_min;
5044 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5047 SCTP_INP_WUNLOCK(inp);
5049 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5055 case SCTP_ASSOCINFO:
5057 struct sctp_assocparams *sasoc;
5059 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5060 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5061 if (sasoc->sasoc_cookie_life) {
5062 /* boundary check the cookie life */
5063 if (sasoc->sasoc_cookie_life < 1000)
5064 sasoc->sasoc_cookie_life = 1000;
5065 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5066 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5070 if (sasoc->sasoc_asocmaxrxt)
5071 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5072 if (sasoc->sasoc_cookie_life) {
5073 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5075 SCTP_TCB_UNLOCK(stcb);
5077 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5078 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5079 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5080 SCTP_INP_WLOCK(inp);
5081 if (sasoc->sasoc_asocmaxrxt)
5082 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5083 if (sasoc->sasoc_cookie_life) {
5084 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5086 SCTP_INP_WUNLOCK(inp);
5088 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5096 struct sctp_initmsg *sinit;
5098 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5099 SCTP_INP_WLOCK(inp);
5100 if (sinit->sinit_num_ostreams)
5101 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5103 if (sinit->sinit_max_instreams)
5104 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5106 if (sinit->sinit_max_attempts)
5107 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5109 if (sinit->sinit_max_init_timeo)
5110 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5111 SCTP_INP_WUNLOCK(inp);
5114 case SCTP_PRIMARY_ADDR:
5116 struct sctp_setprim *spa;
5117 struct sctp_nets *net;
5119 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5120 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5124 net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
5127 * We increment here since
5128 * sctp_findassociation_ep_addr() wil do a
5129 * decrement if it finds the stcb as long as
5130 * the locked tcb (last argument) is NOT a
5133 SCTP_INP_INCR_REF(inp);
5134 stcb = sctp_findassociation_ep_addr(&inp,
5135 (struct sockaddr *)&spa->ssp_addr,
5138 SCTP_INP_DECR_REF(inp);
5142 if ((stcb) && (net)) {
5143 if ((net != stcb->asoc.primary_destination) &&
5144 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
5145 /* Ok we need to set it */
5146 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5147 if ((stcb->asoc.alternate) &&
5148 (!(net->dest_state & SCTP_ADDR_PF)) &&
5149 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5150 sctp_free_remote_addr(stcb->asoc.alternate);
5151 stcb->asoc.alternate = NULL;
5156 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5160 SCTP_TCB_UNLOCK(stcb);
5164 case SCTP_SET_DYNAMIC_PRIMARY:
5166 union sctp_sockstore *ss;
5168 error = priv_check(curthread,
5169 PRIV_NETINET_RESERVEDPORT);
5173 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5174 /* SUPER USER CHECK? */
5175 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5178 case SCTP_SET_PEER_PRIMARY_ADDR:
5180 struct sctp_setpeerprim *sspp;
5182 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5183 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5185 struct sctp_ifa *ifa;
5187 ifa = sctp_find_ifa_by_addr((struct sockaddr *)&sspp->sspp_addr,
5188 stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5190 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5194 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5196 * Must validate the ifa found is in
5199 struct sctp_laddr *laddr;
5202 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5203 if (laddr->ifa == NULL) {
5204 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5208 if (laddr->ifa == ifa) {
5214 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5219 if (sctp_set_primary_ip_address_sa(stcb,
5220 (struct sockaddr *)&sspp->sspp_addr) != 0) {
5221 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5225 SCTP_TCB_UNLOCK(stcb);
5227 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5232 case SCTP_BINDX_ADD_ADDR:
5234 struct sctp_getaddresses *addrs;
5237 td = (struct thread *)p;
5238 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5241 if (addrs->addr->sa_family == AF_INET) {
5242 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5243 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5247 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5248 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5254 if (addrs->addr->sa_family == AF_INET6) {
5255 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5256 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5260 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5261 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5262 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5268 error = EAFNOSUPPORT;
5271 sctp_bindx_add_address(so, inp, addrs->addr,
5272 addrs->sget_assoc_id, vrf_id,
5276 case SCTP_BINDX_REM_ADDR:
5278 struct sctp_getaddresses *addrs;
5281 td = (struct thread *)p;
5283 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5285 if (addrs->addr->sa_family == AF_INET) {
5286 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5287 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5291 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5292 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5298 if (addrs->addr->sa_family == AF_INET6) {
5299 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5300 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5305 (error = prison_local_ip6(td->td_ucred,
5306 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5307 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5308 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5314 error = EAFNOSUPPORT;
5317 sctp_bindx_delete_address(inp, addrs->addr,
5318 addrs->sget_assoc_id, vrf_id,
5324 struct sctp_event *event;
5325 uint32_t event_type;
5327 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5328 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5329 switch (event->se_type) {
5330 case SCTP_ASSOC_CHANGE:
5331 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5333 case SCTP_PEER_ADDR_CHANGE:
5334 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5336 case SCTP_REMOTE_ERROR:
5337 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5339 case SCTP_SEND_FAILED:
5340 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5342 case SCTP_SHUTDOWN_EVENT:
5343 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5345 case SCTP_ADAPTATION_INDICATION:
5346 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5348 case SCTP_PARTIAL_DELIVERY_EVENT:
5349 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5351 case SCTP_AUTHENTICATION_EVENT:
5352 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5354 case SCTP_STREAM_RESET_EVENT:
5355 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5357 case SCTP_SENDER_DRY_EVENT:
5358 event_type = SCTP_PCB_FLAGS_DRYEVNT;
5360 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
5362 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5365 case SCTP_ASSOC_RESET_EVENT:
5366 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
5368 case SCTP_STREAM_CHANGE_EVENT:
5369 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
5371 case SCTP_SEND_FAILED_EVENT:
5372 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
5376 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5380 if (event_type > 0) {
5383 sctp_stcb_feature_on(inp, stcb, event_type);
5384 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
5385 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5386 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5387 (stcb->asoc.stream_queue_cnt == 0)) {
5388 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5392 sctp_stcb_feature_off(inp, stcb, event_type);
5394 SCTP_TCB_UNLOCK(stcb);
5397 * We don't want to send up a storm
5398 * of events, so return an error for
5401 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
5402 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
5403 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
5404 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
5405 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
5406 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5410 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5411 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5412 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
5413 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5414 SCTP_INP_WLOCK(inp);
5416 sctp_feature_on(inp, event_type);
5418 sctp_feature_off(inp, event_type);
5420 SCTP_INP_WUNLOCK(inp);
5422 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
5423 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5424 SCTP_INP_RLOCK(inp);
5425 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5426 SCTP_TCB_LOCK(stcb);
5428 sctp_stcb_feature_on(inp, stcb, event_type);
5430 sctp_stcb_feature_off(inp, stcb, event_type);
5432 SCTP_TCB_UNLOCK(stcb);
5434 SCTP_INP_RUNLOCK(inp);
5440 case SCTP_RECVRCVINFO:
5444 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5445 SCTP_INP_WLOCK(inp);
5447 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5449 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5451 SCTP_INP_WUNLOCK(inp);
5454 case SCTP_RECVNXTINFO:
5458 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5459 SCTP_INP_WLOCK(inp);
5461 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5463 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5465 SCTP_INP_WUNLOCK(inp);
5468 case SCTP_DEFAULT_SNDINFO:
5470 struct sctp_sndinfo *info;
5473 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
5474 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
5477 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5478 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5479 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5480 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5481 stcb->asoc.def_send.sinfo_flags |= policy;
5482 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5483 stcb->asoc.def_send.sinfo_context = info->snd_context;
5485 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5488 SCTP_TCB_UNLOCK(stcb);
5490 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5491 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5492 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
5493 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5494 SCTP_INP_WLOCK(inp);
5495 inp->def_send.sinfo_stream = info->snd_sid;
5496 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
5497 inp->def_send.sinfo_flags = info->snd_flags;
5498 inp->def_send.sinfo_flags |= policy;
5499 inp->def_send.sinfo_ppid = info->snd_ppid;
5500 inp->def_send.sinfo_context = info->snd_context;
5501 SCTP_INP_WUNLOCK(inp);
5503 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
5504 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5505 SCTP_INP_RLOCK(inp);
5506 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5507 SCTP_TCB_LOCK(stcb);
5508 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5509 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5510 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5511 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5512 stcb->asoc.def_send.sinfo_flags |= policy;
5513 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5514 stcb->asoc.def_send.sinfo_context = info->snd_context;
5516 SCTP_TCB_UNLOCK(stcb);
5518 SCTP_INP_RUNLOCK(inp);
5523 case SCTP_DEFAULT_PRINFO:
5525 struct sctp_default_prinfo *info;
5527 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
5528 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
5530 if (PR_SCTP_INVALID_POLICY(info->pr_policy)) {
5531 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5536 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5537 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5538 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5539 SCTP_TCB_UNLOCK(stcb);
5541 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5542 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5543 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
5544 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5545 SCTP_INP_WLOCK(inp);
5546 inp->def_send.sinfo_flags &= 0xfff0;
5547 inp->def_send.sinfo_flags |= info->pr_policy;
5548 inp->def_send.sinfo_timetolive = info->pr_value;
5549 SCTP_INP_WUNLOCK(inp);
5551 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
5552 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5553 SCTP_INP_RLOCK(inp);
5554 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5555 SCTP_TCB_LOCK(stcb);
5556 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5557 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5558 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5559 SCTP_TCB_UNLOCK(stcb);
5561 SCTP_INP_RUNLOCK(inp);
5566 case SCTP_PEER_ADDR_THLDS:
5567 /* Applies to the specific association */
5569 struct sctp_paddrthlds *thlds;
5570 struct sctp_nets *net;
5572 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
5573 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
5576 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_assoc_id);
5579 * We increment here since
5580 * sctp_findassociation_ep_addr() wil do a
5581 * decrement if it finds the stcb as long as
5582 * the locked tcb (last argument) is NOT a
5585 SCTP_INP_INCR_REF(inp);
5586 stcb = sctp_findassociation_ep_addr(&inp,
5587 (struct sockaddr *)&thlds->spt_assoc_id,
5590 SCTP_INP_DECR_REF(inp);
5593 if (stcb && (net == NULL)) {
5594 struct sockaddr *sa;
5596 sa = (struct sockaddr *)&thlds->spt_assoc_id;
5598 if (sa->sa_family == AF_INET) {
5600 struct sockaddr_in *sin;
5602 sin = (struct sockaddr_in *)sa;
5603 if (sin->sin_addr.s_addr) {
5604 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5605 SCTP_TCB_UNLOCK(stcb);
5612 if (sa->sa_family == AF_INET6) {
5613 struct sockaddr_in6 *sin6;
5615 sin6 = (struct sockaddr_in6 *)sa;
5616 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5617 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5618 SCTP_TCB_UNLOCK(stcb);
5625 error = EAFNOSUPPORT;
5626 SCTP_TCB_UNLOCK(stcb);
5627 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5633 if (net->dest_state & SCTP_ADDR_PF) {
5634 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5635 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5636 net->dest_state &= ~SCTP_ADDR_PF;
5639 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5640 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5641 net->dest_state |= SCTP_ADDR_PF;
5642 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5643 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5644 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5647 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5648 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5649 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5650 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5653 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5654 net->dest_state |= SCTP_ADDR_REACHABLE;
5655 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5658 net->failure_threshold = thlds->spt_pathmaxrxt;
5659 net->pf_threshold = thlds->spt_pathpfthld;
5661 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5662 if (net->dest_state & SCTP_ADDR_PF) {
5663 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5664 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5665 net->dest_state &= ~SCTP_ADDR_PF;
5668 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5669 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5670 net->dest_state |= SCTP_ADDR_PF;
5671 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5672 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5673 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5676 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5677 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5678 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5679 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5682 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5683 net->dest_state |= SCTP_ADDR_REACHABLE;
5684 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5687 net->failure_threshold = thlds->spt_pathmaxrxt;
5688 net->pf_threshold = thlds->spt_pathpfthld;
5690 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
5691 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
5694 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5695 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5696 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
5697 SCTP_INP_WLOCK(inp);
5698 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
5699 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
5700 SCTP_INP_WUNLOCK(inp);
5702 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5708 case SCTP_REMOTE_UDP_ENCAPS_PORT:
5710 struct sctp_udpencaps *encaps;
5711 struct sctp_nets *net;
5713 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
5714 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
5716 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
5719 * We increment here since
5720 * sctp_findassociation_ep_addr() wil do a
5721 * decrement if it finds the stcb as long as
5722 * the locked tcb (last argument) is NOT a
5726 SCTP_INP_INCR_REF(inp);
5727 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
5729 SCTP_INP_DECR_REF(inp);
5732 if (stcb && (net == NULL)) {
5733 struct sockaddr *sa;
5735 sa = (struct sockaddr *)&encaps->sue_address;
5737 if (sa->sa_family == AF_INET) {
5739 struct sockaddr_in *sin;
5741 sin = (struct sockaddr_in *)sa;
5742 if (sin->sin_addr.s_addr) {
5743 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5744 SCTP_TCB_UNLOCK(stcb);
5751 if (sa->sa_family == AF_INET6) {
5752 struct sockaddr_in6 *sin6;
5754 sin6 = (struct sockaddr_in6 *)sa;
5755 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5756 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5757 SCTP_TCB_UNLOCK(stcb);
5764 error = EAFNOSUPPORT;
5765 SCTP_TCB_UNLOCK(stcb);
5766 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5772 net->port = encaps->sue_port;
5774 stcb->asoc.port = encaps->sue_port;
5776 SCTP_TCB_UNLOCK(stcb);
5778 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5779 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5780 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
5781 SCTP_INP_WLOCK(inp);
5782 inp->sctp_ep.port = encaps->sue_port;
5783 SCTP_INP_WUNLOCK(inp);
5785 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5792 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
5793 error = ENOPROTOOPT;
5795 } /* end switch (opt) */
5800 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
5802 void *optval = NULL;
5807 if (sopt->sopt_level != IPPROTO_SCTP) {
5808 /* wrong proto level... send back up to IP */
5810 if (INP_CHECK_SOCKAF(so, AF_INET6))
5811 error = ip6_ctloutput(so, sopt);
5813 #if defined(INET) && defined(INET6)
5817 error = ip_ctloutput(so, sopt);
5821 optsize = sopt->sopt_valsize;
5823 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
5824 if (optval == NULL) {
5825 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
5828 error = sooptcopyin(sopt, optval, optsize, optsize);
5830 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5834 p = (void *)sopt->sopt_td;
5835 if (sopt->sopt_dir == SOPT_SET) {
5836 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
5837 } else if (sopt->sopt_dir == SOPT_GET) {
5838 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
5840 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5843 if ((error == 0) && (optval != NULL)) {
5844 error = sooptcopyout(sopt, optval, optsize);
5845 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5846 } else if (optval != NULL) {
5847 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5855 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
5858 int create_lock_on = 0;
5860 struct sctp_inpcb *inp;
5861 struct sctp_tcb *stcb = NULL;
5863 inp = (struct sctp_inpcb *)so->so_pcb;
5865 /* I made the same as TCP since we are not setup? */
5866 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5867 return (ECONNRESET);
5870 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5873 switch (addr->sa_family) {
5877 struct sockaddr_in6 *sin6p;
5879 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
5880 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5883 sin6p = (struct sockaddr_in6 *)addr;
5884 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
5885 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5894 struct sockaddr_in *sinp;
5896 if (addr->sa_len != sizeof(struct sockaddr_in)) {
5897 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5900 sinp = (struct sockaddr_in *)addr;
5901 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
5902 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5909 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
5910 return (EAFNOSUPPORT);
5912 SCTP_INP_INCR_REF(inp);
5913 SCTP_ASOC_CREATE_LOCK(inp);
5917 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
5918 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
5919 /* Should I really unlock ? */
5920 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
5925 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
5926 (addr->sa_family == AF_INET6)) {
5927 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5932 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
5933 SCTP_PCB_FLAGS_UNBOUND) {
5934 /* Bind a ephemeral port */
5935 error = sctp_inpcb_bind(so, NULL, NULL, p);
5940 /* Now do we connect? */
5941 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
5942 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
5943 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5947 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
5948 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
5949 /* We are already connected AND the TCP model */
5950 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
5954 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
5955 SCTP_INP_RLOCK(inp);
5956 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5957 SCTP_INP_RUNLOCK(inp);
5960 * We increment here since sctp_findassociation_ep_addr()
5961 * will do a decrement if it finds the stcb as long as the
5962 * locked tcb (last argument) is NOT a TCB.. aka NULL.
5964 SCTP_INP_INCR_REF(inp);
5965 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
5967 SCTP_INP_DECR_REF(inp);
5969 SCTP_TCB_UNLOCK(stcb);
5973 /* Already have or am bring up an association */
5974 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
5978 vrf_id = inp->def_vrf_id;
5979 /* We are GOOD to go */
5980 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
5982 /* Gak! no memory */
5985 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
5986 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
5987 /* Set the connected flag so we can queue data */
5990 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
5991 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
5993 /* initialize authentication parameters for the assoc */
5994 sctp_initialize_auth_params(inp, stcb);
5996 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
5997 SCTP_TCB_UNLOCK(stcb);
5999 if (create_lock_on) {
6000 SCTP_ASOC_CREATE_UNLOCK(inp);
6002 SCTP_INP_DECR_REF(inp);
6009 sctp_listen(struct socket *so, int backlog, struct thread *p)
6012 * Note this module depends on the protocol processing being called
6013 * AFTER any socket level flags and backlog are applied to the
6014 * socket. The traditional way that the socket flags are applied is
6015 * AFTER protocol processing. We have made a change to the
6016 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
6017 * place if the socket API for SCTP is to work properly.
6021 struct sctp_inpcb *inp;
6023 inp = (struct sctp_inpcb *)so->so_pcb;
6025 /* I made the same as TCP since we are not setup? */
6026 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6027 return (ECONNRESET);
6029 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
6030 /* See if we have a listener */
6031 struct sctp_inpcb *tinp;
6032 union sctp_sockstore store, *sp;
6035 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
6037 struct sctp_laddr *laddr;
6039 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6040 memcpy(&store, &laddr->ifa->address, sizeof(store));
6041 switch (sp->sa.sa_family) {
6044 sp->sin.sin_port = inp->sctp_lport;
6049 sp->sin6.sin6_port = inp->sctp_lport;
6055 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6056 if (tinp && (tinp != inp) &&
6057 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6058 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6059 (tinp->sctp_socket->so_qlimit)) {
6061 * we have a listener already and
6064 SCTP_INP_DECR_REF(tinp);
6065 return (EADDRINUSE);
6067 SCTP_INP_DECR_REF(tinp);
6071 /* Setup a local addr bound all */
6072 memset(&store, 0, sizeof(store));
6073 switch (sp->sa.sa_family) {
6076 store.sin.sin_port = inp->sctp_lport;
6081 sp->sin6.sin6_port = inp->sctp_lport;
6088 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
6089 store.sa.sa_family = AF_INET6;
6090 store.sa.sa_len = sizeof(struct sockaddr_in6);
6094 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
6095 store.sa.sa_family = AF_INET;
6096 store.sa.sa_len = sizeof(struct sockaddr_in);
6099 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6100 if (tinp && (tinp != inp) &&
6101 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6102 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6103 (tinp->sctp_socket->so_qlimit)) {
6105 * we have a listener already and its not
6108 SCTP_INP_DECR_REF(tinp);
6109 return (EADDRINUSE);
6111 SCTP_INP_DECR_REF(inp);
6115 SCTP_INP_RLOCK(inp);
6116 #ifdef SCTP_LOCK_LOGGING
6117 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
6118 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
6122 error = solisten_proto_check(so);
6125 SCTP_INP_RUNLOCK(inp);
6128 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
6129 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
6131 * The unlucky case - We are in the tcp pool with this guy.
6132 * - Someone else is in the main inp slot. - We must move
6133 * this guy (the listener) to the main slot - We must then
6134 * move the guy that was listener to the TCP Pool.
6136 if (sctp_swap_inpcb_for_listen(inp)) {
6140 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6141 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6142 /* We are already connected AND the TCP model */
6144 SCTP_INP_RUNLOCK(inp);
6146 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6147 return (EADDRINUSE);
6149 SCTP_INP_RUNLOCK(inp);
6150 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
6151 /* We must do a bind. */
6153 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
6154 /* bind error, probably perm */
6159 /* It appears for 7.0 and on, we must always call this. */
6160 solisten_proto(so, backlog);
6161 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6162 /* remove the ACCEPTCONN flag for one-to-many sockets */
6163 so->so_options &= ~SO_ACCEPTCONN;
6166 /* turning off listen */
6167 so->so_options &= ~SO_ACCEPTCONN;
6173 static int sctp_defered_wakeup_cnt = 0;
6176 sctp_accept(struct socket *so, struct sockaddr **addr)
6178 struct sctp_tcb *stcb;
6179 struct sctp_inpcb *inp;
6180 union sctp_sockstore store;
6186 inp = (struct sctp_inpcb *)so->so_pcb;
6189 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6190 return (ECONNRESET);
6192 SCTP_INP_RLOCK(inp);
6193 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6194 SCTP_INP_RUNLOCK(inp);
6195 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
6196 return (EOPNOTSUPP);
6198 if (so->so_state & SS_ISDISCONNECTED) {
6199 SCTP_INP_RUNLOCK(inp);
6200 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
6201 return (ECONNABORTED);
6203 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6205 SCTP_INP_RUNLOCK(inp);
6206 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6207 return (ECONNRESET);
6209 SCTP_TCB_LOCK(stcb);
6210 SCTP_INP_RUNLOCK(inp);
6211 store = stcb->asoc.primary_destination->ro._l_addr;
6212 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
6213 SCTP_TCB_UNLOCK(stcb);
6214 switch (store.sa.sa_family) {
6218 struct sockaddr_in *sin;
6220 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6223 sin->sin_family = AF_INET;
6224 sin->sin_len = sizeof(*sin);
6225 sin->sin_port = store.sin.sin_port;
6226 sin->sin_addr = store.sin.sin_addr;
6227 *addr = (struct sockaddr *)sin;
6234 struct sockaddr_in6 *sin6;
6236 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
6239 sin6->sin6_family = AF_INET6;
6240 sin6->sin6_len = sizeof(*sin6);
6241 sin6->sin6_port = store.sin6.sin6_port;
6242 sin6->sin6_addr = store.sin6.sin6_addr;
6243 if ((error = sa6_recoverscope(sin6)) != 0) {
6244 SCTP_FREE_SONAME(sin6);
6247 *addr = (struct sockaddr *)sin6;
6255 /* Wake any delayed sleep action */
6256 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
6257 SCTP_INP_WLOCK(inp);
6258 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
6259 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
6260 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
6261 SCTP_INP_WUNLOCK(inp);
6262 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
6263 if (sowriteable(inp->sctp_socket)) {
6264 sowwakeup_locked(inp->sctp_socket);
6266 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
6268 SCTP_INP_WLOCK(inp);
6270 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
6271 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
6272 SCTP_INP_WUNLOCK(inp);
6273 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
6274 if (soreadable(inp->sctp_socket)) {
6275 sctp_defered_wakeup_cnt++;
6276 sorwakeup_locked(inp->sctp_socket);
6278 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
6280 SCTP_INP_WLOCK(inp);
6282 SCTP_INP_WUNLOCK(inp);
6284 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
6285 SCTP_TCB_LOCK(stcb);
6286 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
6293 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
6295 struct sockaddr_in *sin;
6297 struct sctp_inpcb *inp;
6298 struct sctp_ifa *sctp_ifa;
6301 * Do the malloc first in case it blocks.
6303 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6306 sin->sin_family = AF_INET;
6307 sin->sin_len = sizeof(*sin);
6308 inp = (struct sctp_inpcb *)so->so_pcb;
6310 SCTP_FREE_SONAME(sin);
6311 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6312 return (ECONNRESET);
6314 SCTP_INP_RLOCK(inp);
6315 sin->sin_port = inp->sctp_lport;
6316 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
6317 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6318 struct sctp_tcb *stcb;
6319 struct sockaddr_in *sin_a;
6320 struct sctp_nets *net;
6323 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6329 SCTP_TCB_LOCK(stcb);
6330 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6331 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6333 /* this will make coverity happy */
6336 if (sin_a->sin_family == AF_INET) {
6341 if ((!fnd) || (sin_a == NULL)) {
6343 SCTP_TCB_UNLOCK(stcb);
6346 vrf_id = inp->def_vrf_id;
6347 sctp_ifa = sctp_source_address_selection(inp,
6349 (sctp_route_t *) & net->ro,
6352 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
6353 sctp_free_ifa(sctp_ifa);
6355 SCTP_TCB_UNLOCK(stcb);
6357 /* For the bound all case you get back 0 */
6359 sin->sin_addr.s_addr = 0;
6363 /* Take the first IPv4 address in the list */
6364 struct sctp_laddr *laddr;
6367 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6368 if (laddr->ifa->address.sa.sa_family == AF_INET) {
6369 struct sockaddr_in *sin_a;
6371 sin_a = (struct sockaddr_in *)&laddr->ifa->address.sa;
6372 sin->sin_addr = sin_a->sin_addr;
6378 SCTP_FREE_SONAME(sin);
6379 SCTP_INP_RUNLOCK(inp);
6380 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6384 SCTP_INP_RUNLOCK(inp);
6385 (*addr) = (struct sockaddr *)sin;
6390 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
6392 struct sockaddr_in *sin;
6394 struct sockaddr_in *sin_a;
6395 struct sctp_inpcb *inp;
6396 struct sctp_tcb *stcb;
6397 struct sctp_nets *net;
6399 /* Do the malloc first in case it blocks. */
6400 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6403 sin->sin_family = AF_INET;
6404 sin->sin_len = sizeof(*sin);
6406 inp = (struct sctp_inpcb *)so->so_pcb;
6407 if ((inp == NULL) ||
6408 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
6409 /* UDP type and listeners will drop out here */
6410 SCTP_FREE_SONAME(sin);
6411 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
6414 SCTP_INP_RLOCK(inp);
6415 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6417 SCTP_TCB_LOCK(stcb);
6419 SCTP_INP_RUNLOCK(inp);
6421 SCTP_FREE_SONAME(sin);
6422 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6423 return (ECONNRESET);
6426 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6427 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6428 if (sin_a->sin_family == AF_INET) {
6430 sin->sin_port = stcb->rport;
6431 sin->sin_addr = sin_a->sin_addr;
6435 SCTP_TCB_UNLOCK(stcb);
6437 /* No IPv4 address */
6438 SCTP_FREE_SONAME(sin);
6439 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6442 (*addr) = (struct sockaddr *)sin;
6446 struct pr_usrreqs sctp_usrreqs = {
6447 .pru_abort = sctp_abort,
6448 .pru_accept = sctp_accept,
6449 .pru_attach = sctp_attach,
6450 .pru_bind = sctp_bind,
6451 .pru_connect = sctp_connect,
6452 .pru_control = in_control,
6453 .pru_close = sctp_close,
6454 .pru_detach = sctp_close,
6455 .pru_sopoll = sopoll_generic,
6456 .pru_flush = sctp_flush,
6457 .pru_disconnect = sctp_disconnect,
6458 .pru_listen = sctp_listen,
6459 .pru_peeraddr = sctp_peeraddr,
6460 .pru_send = sctp_sendm,
6461 .pru_shutdown = sctp_shutdown,
6462 .pru_sockaddr = sctp_ingetaddr,
6463 .pru_sosend = sctp_sosend,
6464 .pru_soreceive = sctp_soreceive