2 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2011, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2011, 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 /* $KAME: sctp_usrreq.c,v 1.48 2005/03/07 23:26:08 itojun Exp $ */
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
37 #include <netinet/sctp_os.h>
39 #include <netinet/sctp_pcb.h>
40 #include <netinet/sctp_header.h>
41 #include <netinet/sctp_var.h>
44 #include <netinet/sctp_sysctl.h>
45 #include <netinet/sctp_output.h>
46 #include <netinet/sctp_uio.h>
47 #include <netinet/sctp_asconf.h>
48 #include <netinet/sctputil.h>
49 #include <netinet/sctp_indata.h>
50 #include <netinet/sctp_timer.h>
51 #include <netinet/sctp_auth.h>
52 #include <netinet/sctp_bsd_addr.h>
53 #include <netinet/udp.h>
57 extern struct sctp_cc_functions sctp_cc_functions[];
58 extern struct sctp_ss_functions sctp_ss_functions[];
65 /* Initialize and modify the sysctled variables */
67 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
68 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
70 * Allow a user to take no more than 1/2 the number of clusters or
71 * the SB_MAX whichever is smaller for the send window.
73 sb_max_adj = (u_long)((u_quad_t) (SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
74 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
75 (((uint32_t) nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
77 * Now for the recv window, should we take the same amount? or
78 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
79 * now I will just copy.
81 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
82 SCTP_BASE_VAR(first_time) = 0;
83 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
85 #if defined(SCTP_PACKET_LOGGING)
86 SCTP_BASE_VAR(packet_log_writers) = 0;
87 SCTP_BASE_VAR(packet_log_end) = 0;
88 bzero(&SCTP_BASE_VAR(packet_log_buffer), SCTP_PACKET_LOG_SIZE);
101 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
103 struct sctp_tmit_chunk *chk;
106 /* Adjust that too */
107 stcb->asoc.smallest_mtu = nxtsz;
108 /* now off to subtract IP_DF flag if needed */
109 overhead = IP_HDR_SIZE;
110 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
111 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
113 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
114 if ((chk->send_size + overhead) > nxtsz) {
115 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
118 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
119 if ((chk->send_size + overhead) > nxtsz) {
121 * For this guy we also mark for immediate resend
122 * since we sent to big of chunk
124 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
125 if (chk->sent < SCTP_DATAGRAM_RESEND) {
126 sctp_flight_size_decrease(chk);
127 sctp_total_flight_decrease(stcb, chk);
129 if (chk->sent != SCTP_DATAGRAM_RESEND) {
130 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
132 chk->sent = SCTP_DATAGRAM_RESEND;
133 chk->rec.data.doing_fast_retransmit = 0;
134 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
135 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
136 chk->whoTo->flight_size,
138 (uintptr_t) chk->whoTo,
139 chk->rec.data.TSN_seq);
141 /* Clear any time so NO RTT is being done */
149 sctp_notify_mbuf(struct sctp_inpcb *inp,
150 struct sctp_tcb *stcb,
151 struct sctp_nets *net,
156 int totsz, tmr_stopped = 0;
160 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
161 (ip == NULL) || (sh == NULL)) {
163 SCTP_TCB_UNLOCK(stcb);
167 /* First job is to verify the vtag matches what I would send */
168 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
169 SCTP_TCB_UNLOCK(stcb);
172 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
174 if (icmph->icmp_type != ICMP_UNREACH) {
175 /* We only care about unreachable */
176 SCTP_TCB_UNLOCK(stcb);
179 if (icmph->icmp_code != ICMP_UNREACH_NEEDFRAG) {
180 /* not a unreachable message due to frag. */
181 SCTP_TCB_UNLOCK(stcb);
186 nxtsz = ntohs(icmph->icmp_nextmtu);
189 * old type router that does not tell us what the next size
190 * mtu is. Rats we will have to guess (in a educated fashion
193 nxtsz = sctp_get_prev_mtu(totsz);
195 /* Stop any PMTU timer */
196 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
198 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
199 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
201 /* Adjust destination size limit */
202 if (net->mtu > nxtsz) {
205 net->mtu -= sizeof(struct udphdr);
208 /* now what about the ep? */
209 if (stcb->asoc.smallest_mtu > nxtsz) {
210 sctp_pathmtu_adjustment(stcb, nxtsz);
213 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
215 SCTP_TCB_UNLOCK(stcb);
221 sctp_notify(struct sctp_inpcb *inp,
225 struct sctp_tcb *stcb,
226 struct sctp_nets *net)
228 #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
237 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
238 (sh == NULL) || (to == NULL)) {
240 SCTP_TCB_UNLOCK(stcb);
243 /* First job is to verify the vtag matches what I would send */
244 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
245 SCTP_TCB_UNLOCK(stcb);
248 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
250 if (icmph->icmp_type != ICMP_UNREACH) {
251 /* We only care about unreachable */
252 SCTP_TCB_UNLOCK(stcb);
255 if ((icmph->icmp_code == ICMP_UNREACH_NET) ||
256 (icmph->icmp_code == ICMP_UNREACH_HOST) ||
257 (icmph->icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
258 (icmph->icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
259 (icmph->icmp_code == ICMP_UNREACH_ISOLATED) ||
260 (icmph->icmp_code == ICMP_UNREACH_NET_PROHIB) ||
261 (icmph->icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
262 (icmph->icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
265 * Hmm reachablity problems we must examine closely. If its
266 * not reachable, we may have lost a network. Or if there is
267 * NO protocol at the other end named SCTP. well we consider
270 if (net->dest_state & SCTP_ADDR_REACHABLE) {
271 /* Ok that destination is NOT reachable */
272 net->dest_state &= ~SCTP_ADDR_REACHABLE;
273 net->dest_state &= ~SCTP_ADDR_PF;
274 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
275 stcb, SCTP_FAILED_THRESHOLD,
276 (void *)net, SCTP_SO_NOT_LOCKED);
278 SCTP_TCB_UNLOCK(stcb);
279 } else if ((icmph->icmp_code == ICMP_UNREACH_PROTOCOL) ||
280 (icmph->icmp_code == ICMP_UNREACH_PORT)) {
282 * Here the peer is either playing tricks on us, including
283 * an address that belongs to someone who does not support
284 * SCTP OR was a userland implementation that shutdown and
285 * now is dead. In either case treat it like a OOTB abort
288 reason = SCTP_PEER_FAULTY;
289 sctp_abort_notification(stcb, reason, SCTP_SO_NOT_LOCKED);
290 #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
291 so = SCTP_INP_SO(inp);
292 atomic_add_int(&stcb->asoc.refcnt, 1);
293 SCTP_TCB_UNLOCK(stcb);
294 SCTP_SOCKET_LOCK(so, 1);
296 atomic_subtract_int(&stcb->asoc.refcnt, 1);
298 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
299 #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
300 SCTP_SOCKET_UNLOCK(so, 1);
301 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
303 /* no need to unlock here, since the TCB is gone */
305 SCTP_TCB_UNLOCK(stcb);
311 sctp_ctlinput(cmd, sa, vip)
320 /* FIX, for non-bsd is this right? */
321 vrf_id = SCTP_DEFAULT_VRFID;
322 if (sa->sa_family != AF_INET ||
323 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
326 if (PRC_IS_REDIRECT(cmd)) {
328 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
332 struct sctp_inpcb *inp = NULL;
333 struct sctp_tcb *stcb = NULL;
334 struct sctp_nets *net = NULL;
335 struct sockaddr_in to, from;
337 sh = (struct sctphdr *)((caddr_t)ip + (ip->ip_hl << 2));
338 bzero(&to, sizeof(to));
339 bzero(&from, sizeof(from));
340 from.sin_family = to.sin_family = AF_INET;
341 from.sin_len = to.sin_len = sizeof(to);
342 from.sin_port = sh->src_port;
343 from.sin_addr = ip->ip_src;
344 to.sin_port = sh->dest_port;
345 to.sin_addr = ip->ip_dst;
348 * 'to' holds the dest of the packet that failed to be sent.
349 * 'from' holds our local endpoint address. Thus we reverse
350 * the to and the from in the lookup.
352 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&from,
353 (struct sockaddr *)&to,
354 &inp, &net, 1, vrf_id);
355 if (stcb != NULL && inp && (inp->sctp_socket != NULL)) {
356 if (cmd != PRC_MSGSIZE) {
357 sctp_notify(inp, ip, sh,
358 (struct sockaddr *)&to, stcb,
361 /* handle possible ICMP size messages */
362 sctp_notify_mbuf(inp, stcb, net, ip, sh);
365 if ((stcb == NULL) && (inp != NULL)) {
366 /* reduce ref-count */
368 SCTP_INP_DECR_REF(inp);
369 SCTP_INP_WUNLOCK(inp);
372 SCTP_TCB_UNLOCK(stcb);
382 sctp_getcred(SYSCTL_HANDLER_ARGS)
385 struct sockaddr_in addrs[2];
386 struct sctp_inpcb *inp;
387 struct sctp_nets *net;
388 struct sctp_tcb *stcb;
392 /* FIX, for non-bsd is this right? */
393 vrf_id = SCTP_DEFAULT_VRFID;
395 error = priv_check(req->td, PRIV_NETINET_GETCRED);
400 error = SYSCTL_IN(req, addrs, sizeof(addrs));
404 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[0]),
406 &inp, &net, 1, vrf_id);
407 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
408 if ((inp != NULL) && (stcb == NULL)) {
409 /* reduce ref-count */
411 SCTP_INP_DECR_REF(inp);
414 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
418 SCTP_TCB_UNLOCK(stcb);
420 * We use the write lock here, only since in the error leg we need
421 * it. If we used RLOCK, then we would have to
422 * wlock/decr/unlock/rlock. Which in theory could create a hole.
423 * Better to use higher wlock.
427 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
429 SCTP_INP_WUNLOCK(inp);
432 cru2x(inp->sctp_socket->so_cred, &xuc);
433 SCTP_INP_WUNLOCK(inp);
434 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
439 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
440 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
445 sctp_abort(struct socket *so)
447 struct sctp_inpcb *inp;
450 inp = (struct sctp_inpcb *)so->so_pcb;
455 flags = inp->sctp_flags;
456 #ifdef SCTP_LOG_CLOSING
457 sctp_log_closing(inp, NULL, 17);
459 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
460 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
461 #ifdef SCTP_LOG_CLOSING
462 sctp_log_closing(inp, NULL, 16);
464 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
465 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
467 SCTP_SB_CLEAR(so->so_snd);
469 * same for the rcv ones, they are only here for the
472 SCTP_SB_CLEAR(so->so_rcv);
474 /* Now null out the reference, we are completely detached. */
478 flags = inp->sctp_flags;
479 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
480 goto sctp_must_try_again;
487 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
489 struct sctp_inpcb *inp;
490 struct inpcb *ip_inp;
492 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
499 inp = (struct sctp_inpcb *)so->so_pcb;
501 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
504 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
505 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
510 error = sctp_inpcb_alloc(so, vrf_id);
514 inp = (struct sctp_inpcb *)so->so_pcb;
516 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
517 ip_inp = &inp->ip_inp.inp;
518 ip_inp->inp_vflag |= INP_IPV4;
519 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
521 error = ipsec_init_policy(so, &ip_inp->inp_sp);
522 #ifdef SCTP_LOG_CLOSING
523 sctp_log_closing(inp, NULL, 17);
527 flags = inp->sctp_flags;
528 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
529 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
530 #ifdef SCTP_LOG_CLOSING
531 sctp_log_closing(inp, NULL, 15);
533 SCTP_INP_WUNLOCK(inp);
534 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
535 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
537 flags = inp->sctp_flags;
538 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
541 SCTP_INP_WUNLOCK(inp);
547 SCTP_INP_WUNLOCK(inp);
552 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
554 struct sctp_inpcb *inp = NULL;
558 if (addr && addr->sa_family != AF_INET) {
559 /* must be a v4 address! */
560 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
564 if (addr && (addr->sa_len != sizeof(struct sockaddr_in))) {
565 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
568 inp = (struct sctp_inpcb *)so->so_pcb;
570 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
573 error = sctp_inpcb_bind(so, addr, NULL, p);
579 sctp_close(struct socket *so)
581 struct sctp_inpcb *inp;
584 inp = (struct sctp_inpcb *)so->so_pcb;
589 * Inform all the lower layer assoc that we are done.
592 flags = inp->sctp_flags;
593 #ifdef SCTP_LOG_CLOSING
594 sctp_log_closing(inp, NULL, 17);
596 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
597 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
598 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
599 (so->so_rcv.sb_cc > 0)) {
600 #ifdef SCTP_LOG_CLOSING
601 sctp_log_closing(inp, NULL, 13);
603 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
604 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
606 #ifdef SCTP_LOG_CLOSING
607 sctp_log_closing(inp, NULL, 14);
609 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
610 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
613 * The socket is now detached, no matter what the state of
614 * the SCTP association.
617 SCTP_SB_CLEAR(so->so_snd);
619 * same for the rcv ones, they are only here for the
622 SCTP_SB_CLEAR(so->so_rcv);
624 /* Now null out the reference, we are completely detached. */
628 flags = inp->sctp_flags;
629 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
630 goto sctp_must_try_again;
638 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
639 struct mbuf *control, struct thread *p);
643 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
644 struct mbuf *control, struct thread *p)
646 struct sctp_inpcb *inp;
649 inp = (struct sctp_inpcb *)so->so_pcb;
652 sctp_m_freem(control);
655 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
659 /* Got to have an to address if we are NOT a connected socket */
660 if ((addr == NULL) &&
661 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
662 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
664 } else if (addr == NULL) {
665 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
666 error = EDESTADDRREQ;
669 sctp_m_freem(control);
675 if (addr->sa_family != AF_INET) {
676 /* must be a v4 address! */
677 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
680 sctp_m_freem(control);
683 error = EDESTADDRREQ;
688 /* now what about control */
691 SCTP_PRINTF("huh? control set?\n");
692 sctp_m_freem(inp->control);
695 inp->control = control;
699 SCTP_BUF_NEXT(inp->pkt_last) = m;
702 inp->pkt_last = inp->pkt = m;
705 /* FreeBSD uses a flag passed */
706 ((flags & PRUS_MORETOCOME) == 0)
709 * note with the current version this code will only be used
710 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
711 * re-defining sosend to use the sctp_sosend. One can
712 * optionally switch back to this code (by changing back the
713 * definitions) but this is not advisable. This code is used
714 * by FreeBSD when sending a file with sendfile() though.
718 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
728 sctp_disconnect(struct socket *so)
730 struct sctp_inpcb *inp;
732 inp = (struct sctp_inpcb *)so->so_pcb;
734 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
738 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
739 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
740 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
742 SCTP_INP_RUNLOCK(inp);
745 struct sctp_association *asoc;
746 struct sctp_tcb *stcb;
748 stcb = LIST_FIRST(&inp->sctp_asoc_list);
750 SCTP_INP_RUNLOCK(inp);
751 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
756 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
757 /* We are about to be freed, out of here */
758 SCTP_TCB_UNLOCK(stcb);
759 SCTP_INP_RUNLOCK(inp);
762 if (((so->so_options & SO_LINGER) &&
763 (so->so_linger == 0)) ||
764 (so->so_rcv.sb_cc > 0)) {
765 if (SCTP_GET_STATE(asoc) !=
766 SCTP_STATE_COOKIE_WAIT) {
767 /* Left with Data unread */
770 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_DONTWAIT, 1, MT_DATA);
776 struct sctp_paramhdr *ph;
778 ph = mtod(err, struct sctp_paramhdr *);
779 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
780 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
781 ph->param_length = htons(SCTP_BUF_LEN(err));
783 #if defined(SCTP_PANIC_ON_ABORT)
784 panic("disconnect does an abort");
786 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
787 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
789 SCTP_INP_RUNLOCK(inp);
790 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
791 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
792 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
794 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
795 /* No unlock tcb assoc is gone */
798 if (TAILQ_EMPTY(&asoc->send_queue) &&
799 TAILQ_EMPTY(&asoc->sent_queue) &&
800 (asoc->stream_queue_cnt == 0)) {
801 /* there is nothing queued to send, so done */
802 if (asoc->locked_on_sending) {
805 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
806 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
807 /* only send SHUTDOWN 1st time thru */
808 struct sctp_nets *netp;
810 if (stcb->asoc.alternate) {
811 netp = stcb->asoc.alternate;
813 netp = stcb->asoc.primary_destination;
815 sctp_stop_timers_for_shutdown(stcb);
816 sctp_send_shutdown(stcb, netp);
817 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
818 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
819 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
820 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
822 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
823 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
824 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
825 stcb->sctp_ep, stcb, netp);
826 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
827 stcb->sctp_ep, stcb, netp);
832 * we still got (or just got) data to send,
833 * so set SHUTDOWN_PENDING
836 * XXX sockets draft says that SCTP_EOF
837 * should be sent with no data. currently,
838 * we will allow user data to be sent first
839 * and move to SHUTDOWN-PENDING
841 struct sctp_nets *netp;
843 if (stcb->asoc.alternate) {
844 netp = stcb->asoc.alternate;
846 netp = stcb->asoc.primary_destination;
849 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
850 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
852 if (asoc->locked_on_sending) {
853 /* Locked to send out the data */
854 struct sctp_stream_queue_pending *sp;
856 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
858 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
859 asoc->locked_on_sending->stream_no);
861 if ((sp->length == 0) && (sp->msg_is_complete == 0))
862 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
865 if (TAILQ_EMPTY(&asoc->send_queue) &&
866 TAILQ_EMPTY(&asoc->sent_queue) &&
867 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
871 op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
872 0, M_DONTWAIT, 1, MT_DATA);
878 struct sctp_paramhdr *ph;
881 SCTP_BUF_LEN(op_err) =
882 (sizeof(struct sctp_paramhdr) + sizeof(uint32_t));
884 struct sctp_paramhdr *);
885 ph->param_type = htons(
886 SCTP_CAUSE_USER_INITIATED_ABT);
887 ph->param_length = htons(SCTP_BUF_LEN(op_err));
888 ippp = (uint32_t *) (ph + 1);
889 *ippp = htonl(SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4);
891 #if defined(SCTP_PANIC_ON_ABORT)
892 panic("disconnect does an abort");
895 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
896 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
897 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
898 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
899 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
900 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
902 SCTP_INP_RUNLOCK(inp);
903 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
906 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
909 soisdisconnecting(so);
910 SCTP_TCB_UNLOCK(stcb);
911 SCTP_INP_RUNLOCK(inp);
916 /* UDP model does not support this */
917 SCTP_INP_RUNLOCK(inp);
918 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
924 sctp_flush(struct socket *so, int how)
927 * We will just clear out the values and let subsequent close clear
928 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
929 * they will not be able to read the data, the socket will block
930 * that from happening.
932 struct sctp_inpcb *inp;
934 inp = (struct sctp_inpcb *)so->so_pcb;
936 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
940 /* For the 1 to many model this does nothing */
941 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
942 SCTP_INP_RUNLOCK(inp);
945 SCTP_INP_RUNLOCK(inp);
946 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
948 * First make sure the sb will be happy, we don't use these
949 * except maybe the count
952 SCTP_INP_READ_LOCK(inp);
953 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
954 SCTP_INP_READ_UNLOCK(inp);
955 SCTP_INP_WUNLOCK(inp);
956 so->so_rcv.sb_cc = 0;
957 so->so_rcv.sb_mbcnt = 0;
958 so->so_rcv.sb_mb = NULL;
960 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
962 * First make sure the sb will be happy, we don't use these
963 * except maybe the count
965 so->so_snd.sb_cc = 0;
966 so->so_snd.sb_mbcnt = 0;
967 so->so_snd.sb_mb = NULL;
974 sctp_shutdown(struct socket *so)
976 struct sctp_inpcb *inp;
978 inp = (struct sctp_inpcb *)so->so_pcb;
980 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
984 /* For UDP model this is a invalid call */
985 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
986 /* Restore the flags that the soshutdown took away. */
987 SOCKBUF_LOCK(&so->so_rcv);
988 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
989 SOCKBUF_UNLOCK(&so->so_rcv);
990 /* This proc will wakeup for read and do nothing (I hope) */
991 SCTP_INP_RUNLOCK(inp);
992 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
996 * Ok if we reach here its the TCP model and it is either a SHUT_WR
997 * or SHUT_RDWR. This means we put the shutdown flag against it.
1000 struct sctp_tcb *stcb;
1001 struct sctp_association *asoc;
1004 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
1005 SCTP_INP_RUNLOCK(inp);
1010 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1013 * Ok we hit the case that the shutdown call was
1014 * made after an abort or something. Nothing to do
1017 SCTP_INP_RUNLOCK(inp);
1020 SCTP_TCB_LOCK(stcb);
1022 if (TAILQ_EMPTY(&asoc->send_queue) &&
1023 TAILQ_EMPTY(&asoc->sent_queue) &&
1024 (asoc->stream_queue_cnt == 0)) {
1025 if (asoc->locked_on_sending) {
1028 /* there is nothing queued to send, so I'm done... */
1029 if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) {
1030 /* only send SHUTDOWN the first time through */
1031 struct sctp_nets *netp;
1033 if (stcb->asoc.alternate) {
1034 netp = stcb->asoc.alternate;
1036 netp = stcb->asoc.primary_destination;
1038 sctp_stop_timers_for_shutdown(stcb);
1039 sctp_send_shutdown(stcb, netp);
1040 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
1041 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
1042 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
1043 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1045 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
1046 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
1047 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1048 stcb->sctp_ep, stcb, netp);
1049 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1050 stcb->sctp_ep, stcb, netp);
1054 * we still got (or just got) data to send, so set
1057 struct sctp_nets *netp;
1059 if (stcb->asoc.alternate) {
1060 netp = stcb->asoc.alternate;
1062 netp = stcb->asoc.primary_destination;
1065 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1066 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
1069 if (asoc->locked_on_sending) {
1070 /* Locked to send out the data */
1071 struct sctp_stream_queue_pending *sp;
1073 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
1075 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
1076 asoc->locked_on_sending->stream_no);
1078 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
1079 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
1083 if (TAILQ_EMPTY(&asoc->send_queue) &&
1084 TAILQ_EMPTY(&asoc->sent_queue) &&
1085 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1086 struct mbuf *op_err;
1089 op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
1090 0, M_DONTWAIT, 1, MT_DATA);
1092 /* Fill in the user initiated abort */
1093 struct sctp_paramhdr *ph;
1096 SCTP_BUF_LEN(op_err) =
1097 sizeof(struct sctp_paramhdr) + sizeof(uint32_t);
1099 struct sctp_paramhdr *);
1100 ph->param_type = htons(
1101 SCTP_CAUSE_USER_INITIATED_ABT);
1102 ph->param_length = htons(SCTP_BUF_LEN(op_err));
1103 ippp = (uint32_t *) (ph + 1);
1104 *ippp = htonl(SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1106 #if defined(SCTP_PANIC_ON_ABORT)
1107 panic("shutdown does an abort");
1109 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
1110 sctp_abort_an_association(stcb->sctp_ep, stcb,
1111 SCTP_RESPONSE_TO_USER_REQ,
1112 op_err, SCTP_SO_LOCKED);
1115 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1118 SCTP_TCB_UNLOCK(stcb);
1121 SCTP_INP_RUNLOCK(inp);
1126 * copies a "user" presentable address and removes embedded scope, etc.
1127 * returns 0 on success, 1 on error
1130 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1133 struct sockaddr_in6 lsa6;
1135 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1138 memcpy(ss, sa, sa->sa_len);
1145 * NOTE: assumes addr lock is held
1148 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1149 struct sctp_tcb *stcb,
1151 struct sockaddr_storage *sas,
1154 struct sctp_ifn *sctp_ifn;
1155 struct sctp_ifa *sctp_ifa;
1156 int loopback_scope, ipv4_local_scope, local_scope, site_scope;
1158 int ipv4_addr_legal, ipv6_addr_legal;
1159 struct sctp_vrf *vrf;
1166 /* Turn on all the appropriate scope */
1167 loopback_scope = stcb->asoc.loopback_scope;
1168 ipv4_local_scope = stcb->asoc.ipv4_local_scope;
1169 local_scope = stcb->asoc.local_scope;
1170 site_scope = stcb->asoc.site_scope;
1172 /* Turn on ALL scope, since we look at the EP */
1173 loopback_scope = ipv4_local_scope = local_scope =
1176 ipv4_addr_legal = ipv6_addr_legal = 0;
1177 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1178 ipv6_addr_legal = 1;
1179 if (SCTP_IPV6_V6ONLY(inp) == 0) {
1180 ipv4_addr_legal = 1;
1183 ipv4_addr_legal = 1;
1185 vrf = sctp_find_vrf(vrf_id);
1189 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1190 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1191 if ((loopback_scope == 0) &&
1192 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1193 /* Skip loopback if loopback_scope not set */
1196 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1199 * For the BOUND-ALL case, the list
1200 * associated with a TCB is Always
1201 * considered a reverse list.. i.e.
1202 * it lists addresses that are NOT
1203 * part of the association. If this
1204 * is one of those we must skip it.
1206 if (sctp_is_addr_restricted(stcb,
1211 switch (sctp_ifa->address.sa.sa_family) {
1214 if (ipv4_addr_legal) {
1215 struct sockaddr_in *sin;
1217 sin = (struct sockaddr_in *)&sctp_ifa->address.sa;
1218 if (sin->sin_addr.s_addr == 0) {
1226 if ((ipv4_local_scope == 0) &&
1227 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1231 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1232 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1233 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1234 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1235 actual += sizeof(struct sockaddr_in6);
1238 memcpy(sas, sin, sizeof(*sin));
1239 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1240 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1241 actual += sizeof(*sin);
1245 if (actual >= limit) {
1255 if (ipv6_addr_legal) {
1256 struct sockaddr_in6 *sin6;
1258 sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sa;
1259 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1267 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1268 if (local_scope == 0)
1270 if (sin6->sin6_scope_id == 0) {
1271 if (sa6_recoverscope(sin6) != 0)
1289 if ((site_scope == 0) &&
1290 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1293 memcpy(sas, sin6, sizeof(*sin6));
1294 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1295 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1296 actual += sizeof(*sin6);
1297 if (actual >= limit) {
1312 struct sctp_laddr *laddr;
1314 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1316 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1320 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1323 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1324 sas = (struct sockaddr_storage *)((caddr_t)sas +
1325 laddr->ifa->address.sa.sa_len);
1326 actual += laddr->ifa->address.sa.sa_len;
1327 if (actual >= limit) {
1336 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1337 struct sctp_tcb *stcb,
1339 struct sockaddr_storage *sas)
1343 SCTP_IPI_ADDR_RLOCK();
1344 /* fill up addresses for the endpoint's default vrf */
1345 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1347 SCTP_IPI_ADDR_RUNLOCK();
1352 * NOTE: assumes addr lock is held
1355 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1358 struct sctp_vrf *vrf = NULL;
1361 * In both sub-set bound an bound_all cases we return the MAXIMUM
1362 * number of addresses that you COULD get. In reality the sub-set
1363 * bound may have an exclusion list for a given TCB OR in the
1364 * bound-all case a TCB may NOT include the loopback or other
1365 * addresses as well.
1367 vrf = sctp_find_vrf(vrf_id);
1371 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1372 struct sctp_ifn *sctp_ifn;
1373 struct sctp_ifa *sctp_ifa;
1375 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1376 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1377 /* Count them if they are the right type */
1378 switch (sctp_ifa->address.sa.sa_family) {
1381 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1382 cnt += sizeof(struct sockaddr_in6);
1384 cnt += sizeof(struct sockaddr_in);
1389 cnt += sizeof(struct sockaddr_in6);
1398 struct sctp_laddr *laddr;
1400 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1401 switch (laddr->ifa->address.sa.sa_family) {
1404 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1405 cnt += sizeof(struct sockaddr_in6);
1407 cnt += sizeof(struct sockaddr_in);
1412 cnt += sizeof(struct sockaddr_in6);
1424 sctp_count_max_addresses(struct sctp_inpcb *inp)
1428 SCTP_IPI_ADDR_RLOCK();
1429 /* count addresses for the endpoint's default VRF */
1430 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1431 SCTP_IPI_ADDR_RUNLOCK();
1436 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1437 size_t optsize, void *p, int delay)
1440 int creat_lock_on = 0;
1441 struct sctp_tcb *stcb = NULL;
1442 struct sockaddr *sa;
1443 int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1445 int bad_addresses = 0;
1448 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1450 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1451 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1452 /* We are already connected AND the TCP model */
1453 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1454 return (EADDRINUSE);
1456 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1457 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1458 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1461 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1462 SCTP_INP_RLOCK(inp);
1463 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1464 SCTP_INP_RUNLOCK(inp);
1467 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1470 SCTP_INP_INCR_REF(inp);
1471 SCTP_ASOC_CREATE_LOCK(inp);
1473 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1474 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1475 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1479 totaddrp = (int *)optval;
1480 totaddr = *totaddrp;
1481 sa = (struct sockaddr *)(totaddrp + 1);
1482 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (optsize - sizeof(int)), &bad_addresses);
1483 if ((stcb != NULL) || bad_addresses) {
1484 /* Already have or am bring up an association */
1485 SCTP_ASOC_CREATE_UNLOCK(inp);
1488 SCTP_TCB_UNLOCK(stcb);
1489 if (bad_addresses == 0) {
1490 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1496 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1501 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1503 struct in6pcb *inp6;
1505 inp6 = (struct in6pcb *)inp;
1506 if (SCTP_IPV6_V6ONLY(inp6)) {
1508 * if IPV6_V6ONLY flag, ignore connections destined
1509 * to a v4 addr or v4-mapped addr
1511 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1517 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1518 SCTP_PCB_FLAGS_UNBOUND) {
1519 /* Bind a ephemeral port */
1520 error = sctp_inpcb_bind(so, NULL, NULL, p);
1525 /* FIX ME: do we want to pass in a vrf on the connect call? */
1526 vrf_id = inp->def_vrf_id;
1529 /* We are GOOD to go */
1530 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1534 /* Gak! no memory */
1537 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1538 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1539 /* Set the connected flag so we can queue data */
1542 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1543 /* move to second address */
1544 switch (sa->sa_family) {
1547 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1552 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1560 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1561 /* Fill in the return id */
1563 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1566 a_id = (sctp_assoc_t *) optval;
1567 *a_id = sctp_get_associd(stcb);
1569 /* initialize authentication parameters for the assoc */
1570 sctp_initialize_auth_params(inp, stcb);
1573 /* doing delayed connection */
1574 stcb->asoc.delayed_connection = 1;
1575 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1577 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1578 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1580 SCTP_TCB_UNLOCK(stcb);
1581 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1582 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1583 /* Set the connected flag so we can queue data */
1587 if (creat_lock_on) {
1588 SCTP_ASOC_CREATE_UNLOCK(inp);
1590 SCTP_INP_DECR_REF(inp);
1594 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1595 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1596 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1597 SCTP_INP_RLOCK(inp); \
1598 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1600 SCTP_TCB_LOCK(stcb); \
1602 SCTP_INP_RUNLOCK(inp); \
1603 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1604 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1605 if (stcb == NULL) { \
1606 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1616 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1617 if (size < sizeof(type)) { \
1618 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1622 destp = (type *)srcp; \
1627 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1630 struct sctp_inpcb *inp = NULL;
1632 struct sctp_tcb *stcb = NULL;
1634 if (optval == NULL) {
1635 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1638 inp = (struct sctp_inpcb *)so->so_pcb;
1640 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1647 case SCTP_AUTOCLOSE:
1648 case SCTP_EXPLICIT_EOR:
1649 case SCTP_AUTO_ASCONF:
1650 case SCTP_DISABLE_FRAGMENTS:
1651 case SCTP_I_WANT_MAPPED_V4_ADDR:
1652 case SCTP_USE_EXT_RCVINFO:
1653 SCTP_INP_RLOCK(inp);
1655 case SCTP_DISABLE_FRAGMENTS:
1656 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1658 case SCTP_I_WANT_MAPPED_V4_ADDR:
1659 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1661 case SCTP_AUTO_ASCONF:
1662 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1663 /* only valid for bound all sockets */
1664 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1666 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1671 case SCTP_EXPLICIT_EOR:
1672 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1675 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1677 case SCTP_USE_EXT_RCVINFO:
1678 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1680 case SCTP_AUTOCLOSE:
1681 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1682 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1688 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1689 error = ENOPROTOOPT;
1690 } /* end switch (sopt->sopt_name) */
1691 if (*optsize < sizeof(val)) {
1692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1696 SCTP_INP_RUNLOCK(inp);
1698 /* return the option value */
1699 *(int *)optval = val;
1700 *optsize = sizeof(val);
1703 case SCTP_GET_PACKET_LOG:
1705 #ifdef SCTP_PACKET_LOGGING
1709 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1710 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1713 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1718 case SCTP_REUSE_PORT:
1722 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1723 /* Can't do this for a 1-m socket */
1727 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1728 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1729 *optsize = sizeof(uint32_t);
1732 case SCTP_PARTIAL_DELIVERY_POINT:
1736 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1737 *value = inp->partial_delivery_point;
1738 *optsize = sizeof(uint32_t);
1741 case SCTP_FRAGMENT_INTERLEAVE:
1745 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1746 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1747 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1748 *value = SCTP_FRAG_LEVEL_2;
1750 *value = SCTP_FRAG_LEVEL_1;
1753 *value = SCTP_FRAG_LEVEL_0;
1755 *optsize = sizeof(uint32_t);
1758 case SCTP_CMT_ON_OFF:
1760 struct sctp_assoc_value *av;
1762 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1763 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1765 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1766 SCTP_TCB_UNLOCK(stcb);
1768 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1769 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1770 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1771 SCTP_INP_RLOCK(inp);
1772 av->assoc_value = inp->sctp_cmt_on_off;
1773 SCTP_INP_RUNLOCK(inp);
1775 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1780 *optsize = sizeof(struct sctp_assoc_value);
1784 case SCTP_PLUGGABLE_CC:
1786 struct sctp_assoc_value *av;
1788 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1789 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1791 av->assoc_value = stcb->asoc.congestion_control_module;
1792 SCTP_TCB_UNLOCK(stcb);
1794 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1795 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1796 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1797 SCTP_INP_RLOCK(inp);
1798 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1799 SCTP_INP_RUNLOCK(inp);
1801 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1806 *optsize = sizeof(struct sctp_assoc_value);
1810 case SCTP_CC_OPTION:
1812 struct sctp_cc_option *cc_opt;
1814 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1815 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1819 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1822 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1823 *optsize = sizeof(struct sctp_cc_option);
1825 SCTP_TCB_UNLOCK(stcb);
1829 case SCTP_PLUGGABLE_SS:
1831 struct sctp_assoc_value *av;
1833 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1834 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1836 av->assoc_value = stcb->asoc.stream_scheduling_module;
1837 SCTP_TCB_UNLOCK(stcb);
1839 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1840 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1841 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1842 SCTP_INP_RLOCK(inp);
1843 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1844 SCTP_INP_RUNLOCK(inp);
1846 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1851 *optsize = sizeof(struct sctp_assoc_value);
1857 struct sctp_stream_value *av;
1859 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1860 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1862 if (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1863 &av->stream_value) < 0) {
1864 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1867 *optsize = sizeof(struct sctp_stream_value);
1869 SCTP_TCB_UNLOCK(stcb);
1872 * Can't get stream value without
1875 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1880 case SCTP_GET_ADDR_LEN:
1882 struct sctp_assoc_value *av;
1884 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1887 if (av->assoc_value == AF_INET) {
1888 av->assoc_value = sizeof(struct sockaddr_in);
1893 if (av->assoc_value == AF_INET6) {
1894 av->assoc_value = sizeof(struct sockaddr_in6);
1899 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1901 *optsize = sizeof(struct sctp_assoc_value);
1905 case SCTP_GET_ASSOC_NUMBER:
1907 uint32_t *value, cnt;
1909 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1911 SCTP_INP_RLOCK(inp);
1912 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1915 SCTP_INP_RUNLOCK(inp);
1917 *optsize = sizeof(uint32_t);
1920 case SCTP_GET_ASSOC_ID_LIST:
1922 struct sctp_assoc_ids *ids;
1923 unsigned int at, limit;
1925 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1927 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1928 SCTP_INP_RLOCK(inp);
1929 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1931 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1934 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1938 SCTP_INP_RUNLOCK(inp);
1940 ids->gaids_number_of_ids = at;
1941 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1947 struct sctp_assoc_value *av;
1949 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1950 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1953 av->assoc_value = stcb->asoc.context;
1954 SCTP_TCB_UNLOCK(stcb);
1956 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1957 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1958 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1959 SCTP_INP_RLOCK(inp);
1960 av->assoc_value = inp->sctp_context;
1961 SCTP_INP_RUNLOCK(inp);
1963 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1968 *optsize = sizeof(struct sctp_assoc_value);
1974 uint32_t *default_vrfid;
1976 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1977 *default_vrfid = inp->def_vrf_id;
1978 *optsize = sizeof(uint32_t);
1981 case SCTP_GET_ASOC_VRF:
1983 struct sctp_assoc_value *id;
1985 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1986 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1989 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1991 id->assoc_value = stcb->asoc.vrf_id;
1992 *optsize = sizeof(struct sctp_assoc_value);
1996 case SCTP_GET_VRF_IDS:
1998 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
2002 case SCTP_GET_NONCE_VALUES:
2004 struct sctp_get_nonce_values *gnv;
2006 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
2007 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
2010 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
2011 gnv->gn_local_tag = stcb->asoc.my_vtag;
2012 SCTP_TCB_UNLOCK(stcb);
2013 *optsize = sizeof(struct sctp_get_nonce_values);
2015 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2020 case SCTP_DELAYED_SACK:
2022 struct sctp_sack_info *sack;
2024 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2025 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2027 sack->sack_delay = stcb->asoc.delayed_ack;
2028 sack->sack_freq = stcb->asoc.sack_freq;
2029 SCTP_TCB_UNLOCK(stcb);
2031 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2032 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2033 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2034 SCTP_INP_RLOCK(inp);
2035 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2036 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2037 SCTP_INP_RUNLOCK(inp);
2039 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2044 *optsize = sizeof(struct sctp_sack_info);
2048 case SCTP_GET_SNDBUF_USE:
2050 struct sctp_sockstat *ss;
2052 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2053 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2056 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2057 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2058 stcb->asoc.size_on_all_streams);
2059 SCTP_TCB_UNLOCK(stcb);
2060 *optsize = sizeof(struct sctp_sockstat);
2062 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2067 case SCTP_MAX_BURST:
2069 struct sctp_assoc_value *av;
2071 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2072 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2075 av->assoc_value = stcb->asoc.max_burst;
2076 SCTP_TCB_UNLOCK(stcb);
2078 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2079 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2080 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2081 SCTP_INP_RLOCK(inp);
2082 av->assoc_value = inp->sctp_ep.max_burst;
2083 SCTP_INP_RUNLOCK(inp);
2085 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2090 *optsize = sizeof(struct sctp_assoc_value);
2096 struct sctp_assoc_value *av;
2099 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2100 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2103 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2104 SCTP_TCB_UNLOCK(stcb);
2106 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2107 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2108 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2109 SCTP_INP_RLOCK(inp);
2110 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2111 ovh = SCTP_MED_OVERHEAD;
2113 ovh = SCTP_MED_V4_OVERHEAD;
2115 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2116 av->assoc_value = 0;
2118 av->assoc_value = inp->sctp_frag_point - ovh;
2119 SCTP_INP_RUNLOCK(inp);
2121 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2126 *optsize = sizeof(struct sctp_assoc_value);
2130 case SCTP_GET_STAT_LOG:
2131 error = sctp_fill_stat_log(optval, optsize);
2135 struct sctp_event_subscribe *events;
2137 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2138 memset(events, 0, sizeof(struct sctp_event_subscribe));
2139 SCTP_INP_RLOCK(inp);
2140 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2141 events->sctp_data_io_event = 1;
2143 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2144 events->sctp_association_event = 1;
2146 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2147 events->sctp_address_event = 1;
2149 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2150 events->sctp_send_failure_event = 1;
2152 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2153 events->sctp_peer_error_event = 1;
2155 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2156 events->sctp_shutdown_event = 1;
2158 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2159 events->sctp_partial_delivery_event = 1;
2161 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2162 events->sctp_adaptation_layer_event = 1;
2164 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2165 events->sctp_authentication_event = 1;
2167 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2168 events->sctp_sender_dry_event = 1;
2170 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2171 events->sctp_stream_reset_event = 1;
2172 SCTP_INP_RUNLOCK(inp);
2173 *optsize = sizeof(struct sctp_event_subscribe);
2176 case SCTP_ADAPTATION_LAYER:
2180 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2182 SCTP_INP_RLOCK(inp);
2183 *value = inp->sctp_ep.adaptation_layer_indicator;
2184 SCTP_INP_RUNLOCK(inp);
2185 *optsize = sizeof(uint32_t);
2188 case SCTP_SET_INITIAL_DBG_SEQ:
2192 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2193 SCTP_INP_RLOCK(inp);
2194 *value = inp->sctp_ep.initial_sequence_debug;
2195 SCTP_INP_RUNLOCK(inp);
2196 *optsize = sizeof(uint32_t);
2199 case SCTP_GET_LOCAL_ADDR_SIZE:
2203 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2204 SCTP_INP_RLOCK(inp);
2205 *value = sctp_count_max_addresses(inp);
2206 SCTP_INP_RUNLOCK(inp);
2207 *optsize = sizeof(uint32_t);
2210 case SCTP_GET_REMOTE_ADDR_SIZE:
2214 struct sctp_nets *net;
2216 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2217 /* FIXME MT: change to sctp_assoc_value? */
2218 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2222 /* Count the sizes */
2223 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2224 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2225 size += sizeof(struct sockaddr_in6);
2227 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2230 size += sizeof(struct sockaddr_in);
2235 size += sizeof(struct sockaddr_in6);
2243 SCTP_TCB_UNLOCK(stcb);
2244 *value = (uint32_t) size;
2245 *optsize = sizeof(uint32_t);
2247 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2252 case SCTP_GET_PEER_ADDRESSES:
2254 * Get the address information, an array is passed in to
2255 * fill up we pack it.
2259 struct sockaddr_storage *sas;
2260 struct sctp_nets *net;
2261 struct sctp_getaddresses *saddr;
2263 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2264 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2267 left = (*optsize) - sizeof(struct sctp_getaddresses);
2268 *optsize = sizeof(struct sctp_getaddresses);
2269 sas = (struct sockaddr_storage *)&saddr->addr[0];
2271 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2272 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2273 cpsz = sizeof(struct sockaddr_in6);
2275 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2278 cpsz = sizeof(struct sockaddr_in);
2283 cpsz = sizeof(struct sockaddr_in6);
2295 /* not enough room. */
2298 #if defined(INET) && defined(INET6)
2299 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2300 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
2301 /* Must map the address */
2302 in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
2303 (struct sockaddr_in6 *)sas);
2306 memcpy(sas, &net->ro._l_addr, cpsz);
2307 #if defined(INET) && defined(INET6)
2310 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2312 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2316 SCTP_TCB_UNLOCK(stcb);
2318 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2323 case SCTP_GET_LOCAL_ADDRESSES:
2325 size_t limit, actual;
2326 struct sockaddr_storage *sas;
2327 struct sctp_getaddresses *saddr;
2329 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2330 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2332 sas = (struct sockaddr_storage *)&saddr->addr[0];
2333 limit = *optsize - sizeof(sctp_assoc_t);
2334 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2336 SCTP_TCB_UNLOCK(stcb);
2338 *optsize = sizeof(struct sockaddr_storage) + actual;
2341 case SCTP_PEER_ADDR_PARAMS:
2343 struct sctp_paddrparams *paddrp;
2344 struct sctp_nets *net;
2346 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2347 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2351 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2354 * We increment here since
2355 * sctp_findassociation_ep_addr() wil do a
2356 * decrement if it finds the stcb as long as
2357 * the locked tcb (last argument) is NOT a
2360 SCTP_INP_INCR_REF(inp);
2361 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddrp->spp_address, &net, NULL, NULL);
2363 SCTP_INP_DECR_REF(inp);
2366 if (stcb && (net == NULL)) {
2367 struct sockaddr *sa;
2369 sa = (struct sockaddr *)&paddrp->spp_address;
2371 if (sa->sa_family == AF_INET) {
2372 struct sockaddr_in *sin;
2374 sin = (struct sockaddr_in *)sa;
2375 if (sin->sin_addr.s_addr) {
2377 SCTP_TCB_UNLOCK(stcb);
2378 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2384 if (sa->sa_family == AF_INET6) {
2385 struct sockaddr_in6 *sin6;
2387 sin6 = (struct sockaddr_in6 *)sa;
2388 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2390 SCTP_TCB_UNLOCK(stcb);
2391 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2397 error = EAFNOSUPPORT;
2398 SCTP_TCB_UNLOCK(stcb);
2399 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2404 /* Applies to the specific association */
2405 paddrp->spp_flags = 0;
2409 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2410 ovh = SCTP_MED_OVERHEAD;
2412 ovh = SCTP_MED_V4_OVERHEAD;
2415 paddrp->spp_hbinterval = net->heart_beat_delay;
2416 paddrp->spp_pathmaxrxt = net->failure_threshold;
2417 paddrp->spp_pathmtu = net->mtu - ovh;
2418 /* get flags for HB */
2419 if (net->dest_state & SCTP_ADDR_NOHB) {
2420 paddrp->spp_flags |= SPP_HB_DISABLE;
2422 paddrp->spp_flags |= SPP_HB_ENABLE;
2424 /* get flags for PMTU */
2425 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2426 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2428 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2430 if (net->dscp & 0x01) {
2431 paddrp->spp_dscp = net->dscp & 0xfc;
2432 paddrp->spp_flags |= SPP_DSCP;
2435 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2436 (net->flowlabel & 0x80000000)) {
2437 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2438 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2443 * No destination so return default
2446 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2447 paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
2448 if (stcb->asoc.default_dscp & 0x01) {
2449 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2450 paddrp->spp_flags |= SPP_DSCP;
2453 if (stcb->asoc.default_flowlabel & 0x80000000) {
2454 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2455 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2458 /* default settings should be these */
2459 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2460 paddrp->spp_flags |= SPP_HB_DISABLE;
2462 paddrp->spp_flags |= SPP_HB_ENABLE;
2464 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2465 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2467 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2469 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2471 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2472 SCTP_TCB_UNLOCK(stcb);
2474 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2475 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2476 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2477 /* Use endpoint defaults */
2478 SCTP_INP_RLOCK(inp);
2479 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2480 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2481 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2482 /* get inp's default */
2483 if (inp->sctp_ep.default_dscp & 0x01) {
2484 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2485 paddrp->spp_flags |= SPP_DSCP;
2488 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2489 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2490 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2491 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2494 /* can't return this */
2495 paddrp->spp_pathmtu = 0;
2497 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2498 paddrp->spp_flags |= SPP_HB_ENABLE;
2500 paddrp->spp_flags |= SPP_HB_DISABLE;
2502 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2503 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2505 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2507 SCTP_INP_RUNLOCK(inp);
2509 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2514 *optsize = sizeof(struct sctp_paddrparams);
2518 case SCTP_GET_PEER_ADDR_INFO:
2520 struct sctp_paddrinfo *paddri;
2521 struct sctp_nets *net;
2523 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2524 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2528 net = sctp_findnet(stcb, (struct sockaddr *)&paddri->spinfo_address);
2531 * We increment here since
2532 * sctp_findassociation_ep_addr() wil do a
2533 * decrement if it finds the stcb as long as
2534 * the locked tcb (last argument) is NOT a
2537 SCTP_INP_INCR_REF(inp);
2538 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddri->spinfo_address, &net, NULL, NULL);
2540 SCTP_INP_DECR_REF(inp);
2544 if ((stcb) && (net)) {
2545 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2546 /* It's unconfirmed */
2547 paddri->spinfo_state = SCTP_UNCONFIRMED;
2548 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2550 paddri->spinfo_state = SCTP_ACTIVE;
2553 paddri->spinfo_state = SCTP_INACTIVE;
2555 paddri->spinfo_cwnd = net->cwnd;
2556 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2557 paddri->spinfo_rto = net->RTO;
2558 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2559 paddri->spinfo_mtu = net->mtu;
2560 SCTP_TCB_UNLOCK(stcb);
2561 *optsize = sizeof(struct sctp_paddrinfo);
2564 SCTP_TCB_UNLOCK(stcb);
2566 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2571 case SCTP_PCB_STATUS:
2573 struct sctp_pcbinfo *spcb;
2575 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2576 sctp_fill_pcbinfo(spcb);
2577 *optsize = sizeof(struct sctp_pcbinfo);
2582 struct sctp_nets *net;
2583 struct sctp_status *sstat;
2585 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2586 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2589 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2594 * I think passing the state is fine since
2595 * sctp_constants.h will be available to the user
2598 sstat->sstat_state = stcb->asoc.state;
2599 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2600 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2601 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2603 * We can't include chunks that have been passed to
2604 * the socket layer. Only things in queue.
2606 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2607 stcb->asoc.cnt_on_all_streams);
2610 sstat->sstat_instrms = stcb->asoc.streamincnt;
2611 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2612 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2613 memcpy(&sstat->sstat_primary.spinfo_address,
2614 &stcb->asoc.primary_destination->ro._l_addr,
2615 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2616 net = stcb->asoc.primary_destination;
2617 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2619 * Again the user can get info from sctp_constants.h
2620 * for what the state of the network is.
2622 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2623 /* It's unconfirmed */
2624 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2625 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2627 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2630 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2632 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2633 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2634 sstat->sstat_primary.spinfo_rto = net->RTO;
2635 sstat->sstat_primary.spinfo_mtu = net->mtu;
2636 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2637 SCTP_TCB_UNLOCK(stcb);
2638 *optsize = sizeof(struct sctp_status);
2643 struct sctp_rtoinfo *srto;
2645 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2646 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2649 srto->srto_initial = stcb->asoc.initial_rto;
2650 srto->srto_max = stcb->asoc.maxrto;
2651 srto->srto_min = stcb->asoc.minrto;
2652 SCTP_TCB_UNLOCK(stcb);
2654 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2655 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2656 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2657 SCTP_INP_RLOCK(inp);
2658 srto->srto_initial = inp->sctp_ep.initial_rto;
2659 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2660 srto->srto_min = inp->sctp_ep.sctp_minrto;
2661 SCTP_INP_RUNLOCK(inp);
2663 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2668 *optsize = sizeof(struct sctp_rtoinfo);
2674 struct sctp_timeouts *stimo;
2676 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2677 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2680 stimo->stimo_init = stcb->asoc.timoinit;
2681 stimo->stimo_data = stcb->asoc.timodata;
2682 stimo->stimo_sack = stcb->asoc.timosack;
2683 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2684 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2685 stimo->stimo_cookie = stcb->asoc.timocookie;
2686 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2687 SCTP_TCB_UNLOCK(stcb);
2688 *optsize = sizeof(struct sctp_timeouts);
2690 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2695 case SCTP_ASSOCINFO:
2697 struct sctp_assocparams *sasoc;
2699 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2700 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2703 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2704 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2705 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2706 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2707 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2708 SCTP_TCB_UNLOCK(stcb);
2710 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2711 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2712 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2713 SCTP_INP_RLOCK(inp);
2714 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2715 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2716 sasoc->sasoc_number_peer_destinations = 0;
2717 sasoc->sasoc_peer_rwnd = 0;
2718 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2719 SCTP_INP_RUNLOCK(inp);
2721 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2726 *optsize = sizeof(struct sctp_assocparams);
2730 case SCTP_DEFAULT_SEND_PARAM:
2732 struct sctp_sndrcvinfo *s_info;
2734 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2735 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2738 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2739 SCTP_TCB_UNLOCK(stcb);
2741 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2742 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2743 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2744 SCTP_INP_RLOCK(inp);
2745 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2746 SCTP_INP_RUNLOCK(inp);
2748 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2753 *optsize = sizeof(struct sctp_sndrcvinfo);
2759 struct sctp_initmsg *sinit;
2761 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2762 SCTP_INP_RLOCK(inp);
2763 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2764 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2765 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2766 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2767 SCTP_INP_RUNLOCK(inp);
2768 *optsize = sizeof(struct sctp_initmsg);
2771 case SCTP_PRIMARY_ADDR:
2772 /* we allow a "get" operation on this */
2774 struct sctp_setprim *ssp;
2776 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2777 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2780 /* simply copy out the sockaddr_storage... */
2784 if (len > stcb->asoc.primary_destination->ro._l_addr.sa.sa_len)
2785 len = stcb->asoc.primary_destination->ro._l_addr.sa.sa_len;
2787 memcpy(&ssp->ssp_addr,
2788 &stcb->asoc.primary_destination->ro._l_addr,
2790 SCTP_TCB_UNLOCK(stcb);
2791 *optsize = sizeof(struct sctp_setprim);
2793 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2798 case SCTP_HMAC_IDENT:
2800 struct sctp_hmacalgo *shmac;
2801 sctp_hmaclist_t *hmaclist;
2805 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2807 SCTP_INP_RLOCK(inp);
2808 hmaclist = inp->sctp_ep.local_hmacs;
2809 if (hmaclist == NULL) {
2810 /* no HMACs to return */
2811 *optsize = sizeof(*shmac);
2812 SCTP_INP_RUNLOCK(inp);
2815 /* is there room for all of the hmac ids? */
2816 size = sizeof(*shmac) + (hmaclist->num_algo *
2817 sizeof(shmac->shmac_idents[0]));
2818 if ((size_t)(*optsize) < size) {
2819 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2821 SCTP_INP_RUNLOCK(inp);
2824 /* copy in the list */
2825 shmac->shmac_number_of_idents = hmaclist->num_algo;
2826 for (i = 0; i < hmaclist->num_algo; i++) {
2827 shmac->shmac_idents[i] = hmaclist->hmac[i];
2829 SCTP_INP_RUNLOCK(inp);
2833 case SCTP_AUTH_ACTIVE_KEY:
2835 struct sctp_authkeyid *scact;
2837 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2838 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2841 /* get the active key on the assoc */
2842 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2843 SCTP_TCB_UNLOCK(stcb);
2845 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2846 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2847 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2848 /* get the endpoint active key */
2849 SCTP_INP_RLOCK(inp);
2850 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2851 SCTP_INP_RUNLOCK(inp);
2853 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2858 *optsize = sizeof(struct sctp_authkeyid);
2862 case SCTP_LOCAL_AUTH_CHUNKS:
2864 struct sctp_authchunks *sac;
2865 sctp_auth_chklist_t *chklist = NULL;
2868 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2869 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2872 /* get off the assoc */
2873 chklist = stcb->asoc.local_auth_chunks;
2874 /* is there enough space? */
2875 size = sctp_auth_get_chklist_size(chklist);
2876 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2878 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2880 /* copy in the chunks */
2881 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2882 *optsize = sizeof(struct sctp_authchunks) + size;
2884 SCTP_TCB_UNLOCK(stcb);
2886 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2887 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2888 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2889 /* get off the endpoint */
2890 SCTP_INP_RLOCK(inp);
2891 chklist = inp->sctp_ep.local_auth_chunks;
2892 /* is there enough space? */
2893 size = sctp_auth_get_chklist_size(chklist);
2894 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2896 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2898 /* copy in the chunks */
2899 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2900 *optsize = sizeof(struct sctp_authchunks) + size;
2902 SCTP_INP_RUNLOCK(inp);
2904 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2910 case SCTP_PEER_AUTH_CHUNKS:
2912 struct sctp_authchunks *sac;
2913 sctp_auth_chklist_t *chklist = NULL;
2916 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2917 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2920 /* get off the assoc */
2921 chklist = stcb->asoc.peer_auth_chunks;
2922 /* is there enough space? */
2923 size = sctp_auth_get_chklist_size(chklist);
2924 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2926 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2928 /* copy in the chunks */
2929 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2930 *optsize = sizeof(struct sctp_authchunks) + size;
2932 SCTP_TCB_UNLOCK(stcb);
2934 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2941 struct sctp_event *event;
2942 uint32_t event_type;
2944 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2945 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
2947 switch (event->se_type) {
2948 case SCTP_ASSOC_CHANGE:
2949 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
2951 case SCTP_PEER_ADDR_CHANGE:
2952 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
2954 case SCTP_REMOTE_ERROR:
2955 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
2957 case SCTP_SEND_FAILED:
2958 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
2960 case SCTP_SHUTDOWN_EVENT:
2961 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
2963 case SCTP_ADAPTATION_INDICATION:
2964 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
2966 case SCTP_PARTIAL_DELIVERY_EVENT:
2967 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
2969 case SCTP_AUTHENTICATION_EVENT:
2970 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
2972 case SCTP_STREAM_RESET_EVENT:
2973 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
2975 case SCTP_SENDER_DRY_EVENT:
2976 event_type = SCTP_PCB_FLAGS_DRYEVNT;
2978 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
2980 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
2985 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2989 if (event_type > 0) {
2991 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
2992 SCTP_TCB_UNLOCK(stcb);
2994 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2995 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2996 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
2997 SCTP_INP_RLOCK(inp);
2998 event->se_on = sctp_is_feature_on(inp, event_type);
2999 SCTP_INP_RUNLOCK(inp);
3001 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3007 *optsize = sizeof(struct sctp_event);
3011 case SCTP_RECVRCVINFO:
3015 if (*optsize < sizeof(int)) {
3016 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3019 SCTP_INP_RLOCK(inp);
3020 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3021 SCTP_INP_RUNLOCK(inp);
3024 /* return the option value */
3025 *(int *)optval = onoff;
3026 *optsize = sizeof(int);
3030 case SCTP_RECVNXTINFO:
3034 if (*optsize < sizeof(int)) {
3035 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3038 SCTP_INP_RLOCK(inp);
3039 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3040 SCTP_INP_RUNLOCK(inp);
3043 /* return the option value */
3044 *(int *)optval = onoff;
3045 *optsize = sizeof(int);
3049 case SCTP_DEFAULT_SNDINFO:
3051 struct sctp_sndinfo *info;
3053 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3054 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3057 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3058 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3059 info->snd_flags &= 0xfff0;
3060 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3061 info->snd_context = stcb->asoc.def_send.sinfo_context;
3062 SCTP_TCB_UNLOCK(stcb);
3064 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3065 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3066 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3067 SCTP_INP_RLOCK(inp);
3068 info->snd_sid = inp->def_send.sinfo_stream;
3069 info->snd_flags = inp->def_send.sinfo_flags;
3070 info->snd_flags &= 0xfff0;
3071 info->snd_ppid = inp->def_send.sinfo_ppid;
3072 info->snd_context = inp->def_send.sinfo_context;
3073 SCTP_INP_RUNLOCK(inp);
3075 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3080 *optsize = sizeof(struct sctp_sndinfo);
3084 case SCTP_DEFAULT_PRINFO:
3086 struct sctp_default_prinfo *info;
3088 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3089 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3092 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3093 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3094 SCTP_TCB_UNLOCK(stcb);
3096 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3097 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3098 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3099 SCTP_INP_RLOCK(inp);
3100 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3101 info->pr_value = inp->def_send.sinfo_timetolive;
3102 SCTP_INP_RUNLOCK(inp);
3104 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3109 *optsize = sizeof(struct sctp_default_prinfo);
3113 case SCTP_PEER_ADDR_THLDS:
3115 struct sctp_paddrthlds *thlds;
3116 struct sctp_nets *net;
3118 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3119 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3123 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_address);
3126 * We increment here since
3127 * sctp_findassociation_ep_addr() wil do a
3128 * decrement if it finds the stcb as long as
3129 * the locked tcb (last argument) is NOT a
3132 SCTP_INP_INCR_REF(inp);
3133 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&thlds->spt_address, &net, NULL, NULL);
3135 SCTP_INP_DECR_REF(inp);
3138 if (stcb && (net == NULL)) {
3139 struct sockaddr *sa;
3141 sa = (struct sockaddr *)&thlds->spt_address;
3143 if (sa->sa_family == AF_INET) {
3144 struct sockaddr_in *sin;
3146 sin = (struct sockaddr_in *)sa;
3147 if (sin->sin_addr.s_addr) {
3149 SCTP_TCB_UNLOCK(stcb);
3150 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3156 if (sa->sa_family == AF_INET6) {
3157 struct sockaddr_in6 *sin6;
3159 sin6 = (struct sockaddr_in6 *)sa;
3160 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3162 SCTP_TCB_UNLOCK(stcb);
3163 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3169 error = EAFNOSUPPORT;
3170 SCTP_TCB_UNLOCK(stcb);
3171 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3177 thlds->spt_pathmaxrxt = net->failure_threshold;
3178 thlds->spt_pathpfthld = net->pf_threshold;
3180 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3181 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3183 thlds->spt_assoc_id = sctp_get_associd(stcb);
3184 SCTP_TCB_UNLOCK(stcb);
3186 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3187 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3188 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3189 /* Use endpoint defaults */
3190 SCTP_INP_RLOCK(inp);
3191 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3192 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3193 SCTP_INP_RUNLOCK(inp);
3195 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3200 *optsize = sizeof(struct sctp_paddrthlds);
3204 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3206 struct sctp_udpencaps *encaps;
3207 struct sctp_nets *net;
3209 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3210 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3213 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
3216 * We increment here since
3217 * sctp_findassociation_ep_addr() wil do a
3218 * decrement if it finds the stcb as long as
3219 * the locked tcb (last argument) is NOT a
3223 SCTP_INP_INCR_REF(inp);
3224 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
3226 SCTP_INP_DECR_REF(inp);
3229 if (stcb && (net == NULL)) {
3230 struct sockaddr *sa;
3232 sa = (struct sockaddr *)&encaps->sue_address;
3234 if (sa->sa_family == AF_INET) {
3235 struct sockaddr_in *sin;
3237 sin = (struct sockaddr_in *)sa;
3238 if (sin->sin_addr.s_addr) {
3240 SCTP_TCB_UNLOCK(stcb);
3241 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3247 if (sa->sa_family == AF_INET6) {
3248 struct sockaddr_in6 *sin6;
3250 sin6 = (struct sockaddr_in6 *)sa;
3251 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3253 SCTP_TCB_UNLOCK(stcb);
3254 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3260 error = EAFNOSUPPORT;
3261 SCTP_TCB_UNLOCK(stcb);
3262 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3268 encaps->sue_port = net->port;
3270 encaps->sue_port = stcb->asoc.port;
3272 SCTP_TCB_UNLOCK(stcb);
3274 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3275 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3276 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3277 SCTP_INP_RLOCK(inp);
3278 encaps->sue_port = inp->sctp_ep.port;
3279 SCTP_INP_RUNLOCK(inp);
3281 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3286 *optsize = sizeof(struct sctp_paddrparams);
3291 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3292 error = ENOPROTOOPT;
3294 } /* end switch (sopt->sopt_name) */
3302 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3307 struct sctp_tcb *stcb = NULL;
3308 struct sctp_inpcb *inp = NULL;
3311 if (optval == NULL) {
3312 SCTP_PRINTF("optval is NULL\n");
3313 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3316 inp = (struct sctp_inpcb *)so->so_pcb;
3318 SCTP_PRINTF("inp is NULL?\n");
3319 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3322 vrf_id = inp->def_vrf_id;
3327 case SCTP_AUTOCLOSE:
3328 case SCTP_AUTO_ASCONF:
3329 case SCTP_EXPLICIT_EOR:
3330 case SCTP_DISABLE_FRAGMENTS:
3331 case SCTP_USE_EXT_RCVINFO:
3332 case SCTP_I_WANT_MAPPED_V4_ADDR:
3333 /* copy in the option value */
3334 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3339 case SCTP_DISABLE_FRAGMENTS:
3340 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3342 case SCTP_AUTO_ASCONF:
3344 * NOTE: we don't really support this flag
3346 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3347 /* only valid for bound all sockets */
3348 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3350 /* forbidden by admin */
3351 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3354 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3356 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3360 case SCTP_EXPLICIT_EOR:
3361 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3363 case SCTP_USE_EXT_RCVINFO:
3364 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3366 case SCTP_I_WANT_MAPPED_V4_ADDR:
3367 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3368 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3370 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3375 set_opt = SCTP_PCB_FLAGS_NODELAY;
3377 case SCTP_AUTOCLOSE:
3378 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3379 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3380 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3383 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3385 * The value is in ticks. Note this does not effect
3386 * old associations, only new ones.
3388 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3391 SCTP_INP_WLOCK(inp);
3393 sctp_feature_on(inp, set_opt);
3395 sctp_feature_off(inp, set_opt);
3397 SCTP_INP_WUNLOCK(inp);
3399 case SCTP_REUSE_PORT:
3401 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3402 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3403 /* Can't set it after we are bound */
3407 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3408 /* Can't do this for a 1-m socket */
3413 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3415 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3418 case SCTP_PARTIAL_DELIVERY_POINT:
3422 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3423 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3424 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3428 inp->partial_delivery_point = *value;
3431 case SCTP_FRAGMENT_INTERLEAVE:
3432 /* not yet until we re-write sctp_recvmsg() */
3436 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3437 if (*level == SCTP_FRAG_LEVEL_2) {
3438 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3439 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3440 } else if (*level == SCTP_FRAG_LEVEL_1) {
3441 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3442 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3443 } else if (*level == SCTP_FRAG_LEVEL_0) {
3444 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3445 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3448 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3453 case SCTP_CMT_ON_OFF:
3454 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3455 struct sctp_assoc_value *av;
3457 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3458 if (av->assoc_value > SCTP_CMT_MAX) {
3459 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3463 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3465 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3466 SCTP_TCB_UNLOCK(stcb);
3468 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3469 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3470 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3471 (av->assoc_id == SCTP_ALL_ASSOC)) {
3472 SCTP_INP_WLOCK(inp);
3473 inp->sctp_cmt_on_off = av->assoc_value;
3474 SCTP_INP_WUNLOCK(inp);
3476 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3477 (av->assoc_id == SCTP_ALL_ASSOC)) {
3478 SCTP_INP_RLOCK(inp);
3479 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3480 SCTP_TCB_LOCK(stcb);
3481 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3482 SCTP_TCB_UNLOCK(stcb);
3484 SCTP_INP_RUNLOCK(inp);
3488 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3489 error = ENOPROTOOPT;
3492 case SCTP_PLUGGABLE_CC:
3494 struct sctp_assoc_value *av;
3495 struct sctp_nets *net;
3497 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3498 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3499 (av->assoc_value != SCTP_CC_HSTCP) &&
3500 (av->assoc_value != SCTP_CC_HTCP) &&
3501 (av->assoc_value != SCTP_CC_RTCC)) {
3502 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3506 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3508 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3509 stcb->asoc.congestion_control_module = av->assoc_value;
3510 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3511 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3512 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3515 SCTP_TCB_UNLOCK(stcb);
3517 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3518 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3519 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3520 (av->assoc_id == SCTP_ALL_ASSOC)) {
3521 SCTP_INP_WLOCK(inp);
3522 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3523 SCTP_INP_WUNLOCK(inp);
3525 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3526 (av->assoc_id == SCTP_ALL_ASSOC)) {
3527 SCTP_INP_RLOCK(inp);
3528 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3529 SCTP_TCB_LOCK(stcb);
3530 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3531 stcb->asoc.congestion_control_module = av->assoc_value;
3532 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3533 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3534 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3537 SCTP_TCB_UNLOCK(stcb);
3539 SCTP_INP_RUNLOCK(inp);
3544 case SCTP_CC_OPTION:
3546 struct sctp_cc_option *cc_opt;
3548 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
3549 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
3551 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
3552 SCTP_INP_RLOCK(inp);
3553 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3554 SCTP_TCB_LOCK(stcb);
3555 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
3556 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
3558 SCTP_TCB_UNLOCK(stcb);
3560 SCTP_INP_RUNLOCK(inp);
3565 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
3568 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
3571 SCTP_TCB_UNLOCK(stcb);
3575 case SCTP_PLUGGABLE_SS:
3577 struct sctp_assoc_value *av;
3579 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3580 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
3581 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
3582 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
3583 (av->assoc_value != SCTP_SS_PRIORITY) &&
3584 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
3585 (av->assoc_value != SCTP_SS_FIRST_COME)) {
3586 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3590 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3592 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3593 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3594 stcb->asoc.stream_scheduling_module = av->assoc_value;
3595 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3596 SCTP_TCB_UNLOCK(stcb);
3598 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3599 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3600 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3601 (av->assoc_id == SCTP_ALL_ASSOC)) {
3602 SCTP_INP_WLOCK(inp);
3603 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
3604 SCTP_INP_WUNLOCK(inp);
3606 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3607 (av->assoc_id == SCTP_ALL_ASSOC)) {
3608 SCTP_INP_RLOCK(inp);
3609 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3610 SCTP_TCB_LOCK(stcb);
3611 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3612 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3613 stcb->asoc.stream_scheduling_module = av->assoc_value;
3614 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3615 SCTP_TCB_UNLOCK(stcb);
3617 SCTP_INP_RUNLOCK(inp);
3624 struct sctp_stream_value *av;
3626 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
3627 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3629 if (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
3630 av->stream_value) < 0) {
3631 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3634 SCTP_TCB_UNLOCK(stcb);
3636 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
3637 SCTP_INP_RLOCK(inp);
3638 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3639 SCTP_TCB_LOCK(stcb);
3640 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
3642 &stcb->asoc.strmout[av->stream_id],
3644 SCTP_TCB_UNLOCK(stcb);
3646 SCTP_INP_RUNLOCK(inp);
3650 * Can't set stream value without
3653 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3659 case SCTP_CLR_STAT_LOG:
3660 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3665 struct sctp_assoc_value *av;
3667 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3668 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3671 stcb->asoc.context = av->assoc_value;
3672 SCTP_TCB_UNLOCK(stcb);
3674 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3675 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3676 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3677 (av->assoc_id == SCTP_ALL_ASSOC)) {
3678 SCTP_INP_WLOCK(inp);
3679 inp->sctp_context = av->assoc_value;
3680 SCTP_INP_WUNLOCK(inp);
3682 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3683 (av->assoc_id == SCTP_ALL_ASSOC)) {
3684 SCTP_INP_RLOCK(inp);
3685 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3686 SCTP_TCB_LOCK(stcb);
3687 stcb->asoc.context = av->assoc_value;
3688 SCTP_TCB_UNLOCK(stcb);
3690 SCTP_INP_RUNLOCK(inp);
3697 uint32_t *default_vrfid;
3699 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
3700 if (*default_vrfid > SCTP_MAX_VRF_ID) {
3701 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3705 inp->def_vrf_id = *default_vrfid;
3708 case SCTP_DEL_VRF_ID:
3710 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3714 case SCTP_ADD_VRF_ID:
3716 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3720 case SCTP_DELAYED_SACK:
3722 struct sctp_sack_info *sack;
3724 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
3725 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
3726 if (sack->sack_delay) {
3727 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
3728 sack->sack_delay = SCTP_MAX_SACK_DELAY;
3729 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
3730 sack->sack_delay = TICKS_TO_MSEC(1);
3734 if (sack->sack_delay) {
3735 stcb->asoc.delayed_ack = sack->sack_delay;
3737 if (sack->sack_freq) {
3738 stcb->asoc.sack_freq = sack->sack_freq;
3740 SCTP_TCB_UNLOCK(stcb);
3742 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3743 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3744 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
3745 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3746 SCTP_INP_WLOCK(inp);
3747 if (sack->sack_delay) {
3748 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
3750 if (sack->sack_freq) {
3751 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
3753 SCTP_INP_WUNLOCK(inp);
3755 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
3756 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3757 SCTP_INP_RLOCK(inp);
3758 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3759 SCTP_TCB_LOCK(stcb);
3760 if (sack->sack_delay) {
3761 stcb->asoc.delayed_ack = sack->sack_delay;
3763 if (sack->sack_freq) {
3764 stcb->asoc.sack_freq = sack->sack_freq;
3766 SCTP_TCB_UNLOCK(stcb);
3768 SCTP_INP_RUNLOCK(inp);
3773 case SCTP_AUTH_CHUNK:
3775 struct sctp_authchunk *sauth;
3777 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
3779 SCTP_INP_WLOCK(inp);
3780 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
3781 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3784 SCTP_INP_WUNLOCK(inp);
3789 struct sctp_authkey *sca;
3790 struct sctp_keyhead *shared_keys;
3791 sctp_sharedkey_t *shared_key;
3792 sctp_key_t *key = NULL;
3795 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
3796 if (sca->sca_keylength == 0) {
3797 size = optsize - sizeof(struct sctp_authkey);
3799 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
3800 size = sca->sca_keylength;
3802 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3807 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
3810 shared_keys = &stcb->asoc.shared_keys;
3811 /* clear the cached keys for this key id */
3812 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3814 * create the new shared key and
3818 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3820 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3822 SCTP_TCB_UNLOCK(stcb);
3826 shared_key = sctp_alloc_sharedkey();
3827 if (shared_key == NULL) {
3829 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3831 SCTP_TCB_UNLOCK(stcb);
3834 shared_key->key = key;
3835 shared_key->keyid = sca->sca_keynumber;
3836 error = sctp_insert_sharedkey(shared_keys, shared_key);
3837 SCTP_TCB_UNLOCK(stcb);
3839 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3840 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3841 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
3842 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3843 SCTP_INP_WLOCK(inp);
3844 shared_keys = &inp->sctp_ep.shared_keys;
3846 * clear the cached keys on all
3847 * assocs for this key id
3849 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
3851 * create the new shared key and
3855 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3857 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3859 SCTP_INP_WUNLOCK(inp);
3863 shared_key = sctp_alloc_sharedkey();
3864 if (shared_key == NULL) {
3866 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3868 SCTP_INP_WUNLOCK(inp);
3871 shared_key->key = key;
3872 shared_key->keyid = sca->sca_keynumber;
3873 error = sctp_insert_sharedkey(shared_keys, shared_key);
3874 SCTP_INP_WUNLOCK(inp);
3876 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
3877 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3878 SCTP_INP_RLOCK(inp);
3879 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3880 SCTP_TCB_LOCK(stcb);
3881 shared_keys = &stcb->asoc.shared_keys;
3883 * clear the cached keys for
3886 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3888 * create the new shared key
3889 * and insert/replace it
3892 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3894 SCTP_TCB_UNLOCK(stcb);
3898 shared_key = sctp_alloc_sharedkey();
3899 if (shared_key == NULL) {
3901 SCTP_TCB_UNLOCK(stcb);
3904 shared_key->key = key;
3905 shared_key->keyid = sca->sca_keynumber;
3906 error = sctp_insert_sharedkey(shared_keys, shared_key);
3907 SCTP_TCB_UNLOCK(stcb);
3909 SCTP_INP_RUNLOCK(inp);
3914 case SCTP_HMAC_IDENT:
3916 struct sctp_hmacalgo *shmac;
3917 sctp_hmaclist_t *hmaclist;
3922 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
3923 if (optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) {
3924 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3928 hmaclist = sctp_alloc_hmaclist(shmac->shmac_number_of_idents);
3929 if (hmaclist == NULL) {
3930 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3934 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
3935 hmacid = shmac->shmac_idents[i];
3936 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
3937 /* invalid HMACs were found */ ;
3938 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3940 sctp_free_hmaclist(hmaclist);
3941 goto sctp_set_hmac_done;
3945 for (i = 0; i < hmaclist->num_algo; i++) {
3946 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
3947 /* already in list */
3952 sctp_free_hmaclist(hmaclist);
3953 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3957 /* set it on the endpoint */
3958 SCTP_INP_WLOCK(inp);
3959 if (inp->sctp_ep.local_hmacs)
3960 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
3961 inp->sctp_ep.local_hmacs = hmaclist;
3962 SCTP_INP_WUNLOCK(inp);
3966 case SCTP_AUTH_ACTIVE_KEY:
3968 struct sctp_authkeyid *scact;
3970 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
3971 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
3973 /* set the active key on the right place */
3975 /* set the active key on the assoc */
3976 if (sctp_auth_setactivekey(stcb,
3977 scact->scact_keynumber)) {
3978 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
3979 SCTP_FROM_SCTP_USRREQ,
3983 SCTP_TCB_UNLOCK(stcb);
3985 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3986 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3987 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
3988 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
3989 SCTP_INP_WLOCK(inp);
3990 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
3991 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3994 SCTP_INP_WUNLOCK(inp);
3996 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
3997 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
3998 SCTP_INP_RLOCK(inp);
3999 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4000 SCTP_TCB_LOCK(stcb);
4001 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4002 SCTP_TCB_UNLOCK(stcb);
4004 SCTP_INP_RUNLOCK(inp);
4009 case SCTP_AUTH_DELETE_KEY:
4011 struct sctp_authkeyid *scdel;
4013 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4014 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4016 /* delete the key from the right place */
4018 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4019 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4022 SCTP_TCB_UNLOCK(stcb);
4024 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4025 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4026 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4027 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4028 SCTP_INP_WLOCK(inp);
4029 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4030 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4033 SCTP_INP_WUNLOCK(inp);
4035 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4036 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4037 SCTP_INP_RLOCK(inp);
4038 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4039 SCTP_TCB_LOCK(stcb);
4040 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4041 SCTP_TCB_UNLOCK(stcb);
4043 SCTP_INP_RUNLOCK(inp);
4048 case SCTP_AUTH_DEACTIVATE_KEY:
4050 struct sctp_authkeyid *keyid;
4052 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4053 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4055 /* deactivate the key from the right place */
4057 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4058 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4061 SCTP_TCB_UNLOCK(stcb);
4063 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4064 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4065 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4066 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4067 SCTP_INP_WLOCK(inp);
4068 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4069 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4072 SCTP_INP_WUNLOCK(inp);
4074 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4075 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4076 SCTP_INP_RLOCK(inp);
4077 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4078 SCTP_TCB_LOCK(stcb);
4079 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4080 SCTP_TCB_UNLOCK(stcb);
4082 SCTP_INP_RUNLOCK(inp);
4087 case SCTP_ENABLE_STREAM_RESET:
4089 struct sctp_assoc_value *av;
4090 uint8_t set_value = 0;
4092 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4093 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4094 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4098 set_value = av->assoc_value & SCTP_ENABLE_VALUE_MASK;
4099 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4101 stcb->asoc.local_strreset_support = set_value;
4102 SCTP_TCB_UNLOCK(stcb);
4104 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4105 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4106 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4107 (av->assoc_id == SCTP_ALL_ASSOC)) {
4108 SCTP_INP_WLOCK(inp);
4109 inp->local_strreset_support = set_value;
4110 SCTP_INP_WUNLOCK(inp);
4112 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4113 (av->assoc_id == SCTP_ALL_ASSOC)) {
4114 SCTP_INP_RLOCK(inp);
4115 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4116 SCTP_TCB_LOCK(stcb);
4117 stcb->asoc.local_strreset_support = set_value;
4118 SCTP_TCB_UNLOCK(stcb);
4120 SCTP_INP_RUNLOCK(inp);
4125 case SCTP_RESET_STREAMS:
4127 struct sctp_reset_streams *strrst;
4128 int i, send_out = 0;
4131 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4132 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4135 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4139 if (stcb->asoc.peer_supports_strreset == 0) {
4141 * Peer does not support the chunk type.
4143 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4145 SCTP_TCB_UNLOCK(stcb);
4148 if (!(stcb->asoc.local_strreset_support & SCTP_ENABLE_RESET_STREAM_REQ)) {
4150 * User did not enable the operation.
4152 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
4154 SCTP_TCB_UNLOCK(stcb);
4157 if (stcb->asoc.stream_reset_outstanding) {
4158 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4160 SCTP_TCB_UNLOCK(stcb);
4163 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4166 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4169 if ((send_in == 0) && (send_out == 0)) {
4170 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4172 SCTP_TCB_UNLOCK(stcb);
4175 for (i = 0; i < strrst->srs_number_streams; i++) {
4177 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4178 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4183 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4184 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4190 SCTP_TCB_UNLOCK(stcb);
4193 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4194 strrst->srs_stream_list,
4195 send_out, send_in, 0, 0, 0, 0, 0);
4197 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4198 SCTP_TCB_UNLOCK(stcb);
4201 case SCTP_ADD_STREAMS:
4203 struct sctp_add_streams *stradd;
4204 uint8_t addstream = 0;
4205 uint16_t add_o_strmcnt = 0;
4206 uint16_t add_i_strmcnt = 0;
4208 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4209 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4211 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4215 if ((stradd->sas_outstrms == 0) &&
4216 (stradd->sas_instrms == 0)) {
4220 if (stradd->sas_outstrms) {
4222 /* We allocate here */
4223 add_o_strmcnt = stradd->sas_outstrms;
4224 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4225 /* You can't have more than 64k */
4230 if (stradd->sas_instrms) {
4235 * We allocate inside
4236 * sctp_send_str_reset_req()
4238 add_i_strmcnt = stradd->sas_instrms;
4239 cnt = add_i_strmcnt;
4240 cnt += stcb->asoc.streamincnt;
4241 if (cnt > 0x0000ffff) {
4242 /* You can't have more than 64k */
4246 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4247 /* More than you are allowed */
4252 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4253 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4255 SCTP_TCB_UNLOCK(stcb);
4258 case SCTP_RESET_ASSOC:
4262 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4263 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4265 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4269 if (stcb->asoc.peer_supports_strreset == 0) {
4271 * Peer does not support the chunk type.
4273 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4275 SCTP_TCB_UNLOCK(stcb);
4278 if (!(stcb->asoc.local_strreset_support & SCTP_ENABLE_RESET_ASSOC_REQ)) {
4280 * User did not enable the operation.
4282 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
4284 SCTP_TCB_UNLOCK(stcb);
4287 if (stcb->asoc.stream_reset_outstanding) {
4288 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4290 SCTP_TCB_UNLOCK(stcb);
4293 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 1, 0, 0, 0, 0);
4294 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4295 SCTP_TCB_UNLOCK(stcb);
4298 case SCTP_CONNECT_X:
4299 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4300 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4304 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4306 case SCTP_CONNECT_X_DELAYED:
4307 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4308 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4312 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4314 case SCTP_CONNECT_X_COMPLETE:
4316 struct sockaddr *sa;
4317 struct sctp_nets *net;
4319 /* FIXME MT: check correct? */
4320 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4323 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4324 SCTP_INP_RLOCK(inp);
4325 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4327 SCTP_TCB_LOCK(stcb);
4328 net = sctp_findnet(stcb, sa);
4330 SCTP_INP_RUNLOCK(inp);
4333 * We increment here since
4334 * sctp_findassociation_ep_addr() wil do a
4335 * decrement if it finds the stcb as long as
4336 * the locked tcb (last argument) is NOT a
4339 SCTP_INP_INCR_REF(inp);
4340 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
4342 SCTP_INP_DECR_REF(inp);
4347 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4351 if (stcb->asoc.delayed_connection == 1) {
4352 stcb->asoc.delayed_connection = 0;
4353 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4354 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4355 stcb->asoc.primary_destination,
4356 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
4357 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4360 * already expired or did not use delayed
4363 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4366 SCTP_TCB_UNLOCK(stcb);
4369 case SCTP_MAX_BURST:
4371 struct sctp_assoc_value *av;
4373 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4374 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4377 stcb->asoc.max_burst = av->assoc_value;
4378 SCTP_TCB_UNLOCK(stcb);
4380 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4381 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4382 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4383 (av->assoc_id == SCTP_ALL_ASSOC)) {
4384 SCTP_INP_WLOCK(inp);
4385 inp->sctp_ep.max_burst = av->assoc_value;
4386 SCTP_INP_WUNLOCK(inp);
4388 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4389 (av->assoc_id == SCTP_ALL_ASSOC)) {
4390 SCTP_INP_RLOCK(inp);
4391 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4392 SCTP_TCB_LOCK(stcb);
4393 stcb->asoc.max_burst = av->assoc_value;
4394 SCTP_TCB_UNLOCK(stcb);
4396 SCTP_INP_RUNLOCK(inp);
4403 struct sctp_assoc_value *av;
4406 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4407 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4409 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4410 ovh = SCTP_MED_OVERHEAD;
4412 ovh = SCTP_MED_V4_OVERHEAD;
4415 if (av->assoc_value) {
4416 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4418 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4420 SCTP_TCB_UNLOCK(stcb);
4422 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4423 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4424 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4425 SCTP_INP_WLOCK(inp);
4427 * FIXME MT: I think this is not in
4428 * tune with the API ID
4430 if (av->assoc_value) {
4431 inp->sctp_frag_point = (av->assoc_value + ovh);
4433 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4435 SCTP_INP_WUNLOCK(inp);
4437 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4445 struct sctp_event_subscribe *events;
4447 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4449 SCTP_INP_WLOCK(inp);
4450 if (events->sctp_data_io_event) {
4451 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4453 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4456 if (events->sctp_association_event) {
4457 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4459 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4462 if (events->sctp_address_event) {
4463 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4465 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4468 if (events->sctp_send_failure_event) {
4469 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4471 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4474 if (events->sctp_peer_error_event) {
4475 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4477 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4480 if (events->sctp_shutdown_event) {
4481 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4483 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4486 if (events->sctp_partial_delivery_event) {
4487 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4489 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4492 if (events->sctp_adaptation_layer_event) {
4493 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4495 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4498 if (events->sctp_authentication_event) {
4499 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4501 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4504 if (events->sctp_sender_dry_event) {
4505 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
4507 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
4510 if (events->sctp_stream_reset_event) {
4511 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4513 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4515 SCTP_INP_WUNLOCK(inp);
4517 SCTP_INP_RLOCK(inp);
4518 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4519 SCTP_TCB_LOCK(stcb);
4520 if (events->sctp_association_event) {
4521 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4523 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4525 if (events->sctp_address_event) {
4526 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4528 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4530 if (events->sctp_send_failure_event) {
4531 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4533 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4535 if (events->sctp_peer_error_event) {
4536 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4538 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4540 if (events->sctp_shutdown_event) {
4541 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4543 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4545 if (events->sctp_partial_delivery_event) {
4546 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4548 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4550 if (events->sctp_adaptation_layer_event) {
4551 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4553 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4555 if (events->sctp_authentication_event) {
4556 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4558 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4560 if (events->sctp_sender_dry_event) {
4561 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4563 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4565 if (events->sctp_stream_reset_event) {
4566 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4568 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4570 SCTP_TCB_UNLOCK(stcb);
4573 * Send up the sender dry event only for 1-to-1
4576 if (events->sctp_sender_dry_event) {
4577 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4578 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
4579 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4581 SCTP_TCB_LOCK(stcb);
4582 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
4583 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
4584 (stcb->asoc.stream_queue_cnt == 0)) {
4585 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
4587 SCTP_TCB_UNLOCK(stcb);
4591 SCTP_INP_RUNLOCK(inp);
4594 case SCTP_ADAPTATION_LAYER:
4596 struct sctp_setadaptation *adap_bits;
4598 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
4599 SCTP_INP_WLOCK(inp);
4600 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
4601 SCTP_INP_WUNLOCK(inp);
4605 case SCTP_SET_INITIAL_DBG_SEQ:
4609 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
4610 SCTP_INP_WLOCK(inp);
4611 inp->sctp_ep.initial_sequence_debug = *vvv;
4612 SCTP_INP_WUNLOCK(inp);
4616 case SCTP_DEFAULT_SEND_PARAM:
4618 struct sctp_sndrcvinfo *s_info;
4620 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
4621 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
4624 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4625 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4627 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4630 SCTP_TCB_UNLOCK(stcb);
4632 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4633 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4634 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
4635 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4636 SCTP_INP_WLOCK(inp);
4637 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
4638 SCTP_INP_WUNLOCK(inp);
4640 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
4641 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4642 SCTP_INP_RLOCK(inp);
4643 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4644 SCTP_TCB_LOCK(stcb);
4645 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4646 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4648 SCTP_TCB_UNLOCK(stcb);
4650 SCTP_INP_RUNLOCK(inp);
4655 case SCTP_PEER_ADDR_PARAMS:
4657 struct sctp_paddrparams *paddrp;
4658 struct sctp_nets *net;
4660 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
4661 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
4664 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
4667 * We increment here since
4668 * sctp_findassociation_ep_addr() wil do a
4669 * decrement if it finds the stcb as long as
4670 * the locked tcb (last argument) is NOT a
4673 SCTP_INP_INCR_REF(inp);
4674 stcb = sctp_findassociation_ep_addr(&inp,
4675 (struct sockaddr *)&paddrp->spp_address,
4678 SCTP_INP_DECR_REF(inp);
4681 if (stcb && (net == NULL)) {
4682 struct sockaddr *sa;
4684 sa = (struct sockaddr *)&paddrp->spp_address;
4686 if (sa->sa_family == AF_INET) {
4688 struct sockaddr_in *sin;
4690 sin = (struct sockaddr_in *)sa;
4691 if (sin->sin_addr.s_addr) {
4692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4693 SCTP_TCB_UNLOCK(stcb);
4700 if (sa->sa_family == AF_INET6) {
4701 struct sockaddr_in6 *sin6;
4703 sin6 = (struct sockaddr_in6 *)sa;
4704 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
4705 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4706 SCTP_TCB_UNLOCK(stcb);
4713 error = EAFNOSUPPORT;
4714 SCTP_TCB_UNLOCK(stcb);
4715 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4720 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
4722 SCTP_TCB_UNLOCK(stcb);
4723 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4726 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
4728 SCTP_TCB_UNLOCK(stcb);
4729 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4733 /************************TCB SPECIFIC SET ******************/
4735 * do we change the timer for HB, we run
4740 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4741 ovh = SCTP_MED_OVERHEAD;
4743 ovh = SCTP_MED_V4_OVERHEAD;
4746 /* network sets ? */
4748 /************************NET SPECIFIC SET ******************/
4749 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4750 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
4751 !(net->dest_state & SCTP_ADDR_NOHB)) {
4752 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4753 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4755 net->dest_state |= SCTP_ADDR_NOHB;
4757 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4758 if (paddrp->spp_hbinterval) {
4759 net->heart_beat_delay = paddrp->spp_hbinterval;
4760 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4761 net->heart_beat_delay = 0;
4763 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4764 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4765 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4766 net->dest_state &= ~SCTP_ADDR_NOHB;
4768 if (paddrp->spp_flags & SPP_HB_DEMAND) {
4770 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4771 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
4772 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4774 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4775 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4776 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4777 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4779 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4780 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4781 net->mtu = paddrp->spp_pathmtu + ovh;
4782 if (net->mtu < stcb->asoc.smallest_mtu) {
4783 sctp_pathmtu_adjustment(stcb, net->mtu);
4787 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4788 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4789 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4791 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4793 if (paddrp->spp_pathmaxrxt) {
4794 if (net->dest_state & SCTP_ADDR_PF) {
4795 if (net->error_count > paddrp->spp_pathmaxrxt) {
4796 net->dest_state &= ~SCTP_ADDR_PF;
4799 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4800 (net->error_count > net->pf_threshold)) {
4801 net->dest_state |= SCTP_ADDR_PF;
4802 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4803 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4804 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4807 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4808 if (net->error_count > paddrp->spp_pathmaxrxt) {
4809 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4810 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4813 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4814 net->dest_state |= SCTP_ADDR_REACHABLE;
4815 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4818 net->failure_threshold = paddrp->spp_pathmaxrxt;
4820 if (paddrp->spp_flags & SPP_DSCP) {
4821 net->dscp = paddrp->spp_dscp & 0xfc;
4825 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4826 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4827 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4828 net->flowlabel |= 0x80000000;
4833 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
4834 if (paddrp->spp_pathmaxrxt) {
4835 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
4836 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4837 if (net->dest_state & SCTP_ADDR_PF) {
4838 if (net->error_count > paddrp->spp_pathmaxrxt) {
4839 net->dest_state &= ~SCTP_ADDR_PF;
4842 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4843 (net->error_count > net->pf_threshold)) {
4844 net->dest_state |= SCTP_ADDR_PF;
4845 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4846 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4847 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4850 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4851 if (net->error_count > paddrp->spp_pathmaxrxt) {
4852 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4853 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4856 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4857 net->dest_state |= SCTP_ADDR_REACHABLE;
4858 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4861 net->failure_threshold = paddrp->spp_pathmaxrxt;
4864 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4865 if (paddrp->spp_hbinterval) {
4866 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
4867 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4868 stcb->asoc.heart_beat_delay = 0;
4870 /* Turn back on the timer */
4871 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4872 if (paddrp->spp_hbinterval) {
4873 net->heart_beat_delay = paddrp->spp_hbinterval;
4874 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4875 net->heart_beat_delay = 0;
4877 if (net->dest_state & SCTP_ADDR_NOHB) {
4878 net->dest_state &= ~SCTP_ADDR_NOHB;
4880 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4881 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4882 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4884 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4886 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4887 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4888 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
4889 net->dest_state |= SCTP_ADDR_NOHB;
4890 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
4891 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4895 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4897 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4898 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4899 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4900 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4901 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4903 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4904 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4905 net->mtu = paddrp->spp_pathmtu + ovh;
4906 if (net->mtu < stcb->asoc.smallest_mtu) {
4907 sctp_pathmtu_adjustment(stcb, net->mtu);
4911 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4913 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4914 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4915 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4916 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4918 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4920 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4922 if (paddrp->spp_flags & SPP_DSCP) {
4923 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4924 net->dscp = paddrp->spp_dscp & 0xfc;
4927 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
4928 stcb->asoc.default_dscp |= 0x01;
4931 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4932 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4933 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4934 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4935 net->flowlabel |= 0x80000000;
4938 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4939 stcb->asoc.default_flowlabel |= 0x80000000;
4943 SCTP_TCB_UNLOCK(stcb);
4945 /************************NO TCB, SET TO default stuff ******************/
4946 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4947 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4948 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
4949 SCTP_INP_WLOCK(inp);
4951 * For the TOS/FLOWLABEL stuff you
4952 * set it with the options on the
4955 if (paddrp->spp_pathmaxrxt) {
4956 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
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 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
4962 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
4963 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4965 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4966 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4967 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4968 } else if (paddrp->spp_hbinterval) {
4969 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4971 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4972 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
4973 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4975 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4976 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4977 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
4978 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4980 if (paddrp->spp_flags & SPP_DSCP) {
4981 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
4982 inp->sctp_ep.default_dscp |= 0x01;
4985 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4986 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4987 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4988 inp->sctp_ep.default_flowlabel |= 0x80000000;
4992 SCTP_INP_WUNLOCK(inp);
4994 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5002 struct sctp_rtoinfo *srto;
5003 uint32_t new_init, new_min, new_max;
5005 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5006 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5009 if (srto->srto_initial)
5010 new_init = srto->srto_initial;
5012 new_init = stcb->asoc.initial_rto;
5014 new_max = srto->srto_max;
5016 new_max = stcb->asoc.maxrto;
5018 new_min = srto->srto_min;
5020 new_min = stcb->asoc.minrto;
5021 if ((new_min <= new_init) && (new_init <= new_max)) {
5022 stcb->asoc.initial_rto = new_init;
5023 stcb->asoc.maxrto = new_max;
5024 stcb->asoc.minrto = new_min;
5026 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5029 SCTP_TCB_UNLOCK(stcb);
5031 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5032 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5033 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5034 SCTP_INP_WLOCK(inp);
5035 if (srto->srto_initial)
5036 new_init = srto->srto_initial;
5038 new_init = inp->sctp_ep.initial_rto;
5040 new_max = srto->srto_max;
5042 new_max = inp->sctp_ep.sctp_maxrto;
5044 new_min = srto->srto_min;
5046 new_min = inp->sctp_ep.sctp_minrto;
5047 if ((new_min <= new_init) && (new_init <= new_max)) {
5048 inp->sctp_ep.initial_rto = new_init;
5049 inp->sctp_ep.sctp_maxrto = new_max;
5050 inp->sctp_ep.sctp_minrto = new_min;
5052 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5055 SCTP_INP_WUNLOCK(inp);
5057 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5063 case SCTP_ASSOCINFO:
5065 struct sctp_assocparams *sasoc;
5067 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5068 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5069 if (sasoc->sasoc_cookie_life) {
5070 /* boundary check the cookie life */
5071 if (sasoc->sasoc_cookie_life < 1000)
5072 sasoc->sasoc_cookie_life = 1000;
5073 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5074 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5078 if (sasoc->sasoc_asocmaxrxt)
5079 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5080 if (sasoc->sasoc_cookie_life) {
5081 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5083 SCTP_TCB_UNLOCK(stcb);
5085 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5086 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5087 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5088 SCTP_INP_WLOCK(inp);
5089 if (sasoc->sasoc_asocmaxrxt)
5090 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5091 if (sasoc->sasoc_cookie_life) {
5092 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5094 SCTP_INP_WUNLOCK(inp);
5096 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5104 struct sctp_initmsg *sinit;
5106 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5107 SCTP_INP_WLOCK(inp);
5108 if (sinit->sinit_num_ostreams)
5109 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5111 if (sinit->sinit_max_instreams)
5112 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5114 if (sinit->sinit_max_attempts)
5115 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5117 if (sinit->sinit_max_init_timeo)
5118 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5119 SCTP_INP_WUNLOCK(inp);
5122 case SCTP_PRIMARY_ADDR:
5124 struct sctp_setprim *spa;
5125 struct sctp_nets *net;
5127 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5128 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5132 net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
5135 * We increment here since
5136 * sctp_findassociation_ep_addr() wil do a
5137 * decrement if it finds the stcb as long as
5138 * the locked tcb (last argument) is NOT a
5141 SCTP_INP_INCR_REF(inp);
5142 stcb = sctp_findassociation_ep_addr(&inp,
5143 (struct sockaddr *)&spa->ssp_addr,
5146 SCTP_INP_DECR_REF(inp);
5150 if ((stcb) && (net)) {
5151 if ((net != stcb->asoc.primary_destination) &&
5152 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
5153 /* Ok we need to set it */
5154 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5155 if ((stcb->asoc.alternate) &&
5156 (!(net->dest_state & SCTP_ADDR_PF)) &&
5157 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5158 sctp_free_remote_addr(stcb->asoc.alternate);
5159 stcb->asoc.alternate = NULL;
5164 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5168 SCTP_TCB_UNLOCK(stcb);
5172 case SCTP_SET_DYNAMIC_PRIMARY:
5174 union sctp_sockstore *ss;
5176 error = priv_check(curthread,
5177 PRIV_NETINET_RESERVEDPORT);
5181 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5182 /* SUPER USER CHECK? */
5183 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5186 case SCTP_SET_PEER_PRIMARY_ADDR:
5188 struct sctp_setpeerprim *sspp;
5190 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5191 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5193 struct sctp_ifa *ifa;
5195 ifa = sctp_find_ifa_by_addr((struct sockaddr *)&sspp->sspp_addr,
5196 stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5198 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5202 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5204 * Must validate the ifa found is in
5207 struct sctp_laddr *laddr;
5210 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5211 if (laddr->ifa == NULL) {
5212 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5216 if (laddr->ifa == ifa) {
5222 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5227 if (sctp_set_primary_ip_address_sa(stcb,
5228 (struct sockaddr *)&sspp->sspp_addr) != 0) {
5229 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5233 SCTP_TCB_UNLOCK(stcb);
5235 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5240 case SCTP_BINDX_ADD_ADDR:
5242 struct sctp_getaddresses *addrs;
5246 td = (struct thread *)p;
5247 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5250 if (addrs->addr->sa_family == AF_INET) {
5251 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in);
5253 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5257 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5258 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5264 if (addrs->addr->sa_family == AF_INET6) {
5265 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6);
5267 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5271 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5272 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5273 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5279 error = EAFNOSUPPORT;
5282 sctp_bindx_add_address(so, inp, addrs->addr,
5283 addrs->sget_assoc_id, vrf_id,
5287 case SCTP_BINDX_REM_ADDR:
5289 struct sctp_getaddresses *addrs;
5293 td = (struct thread *)p;
5295 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5297 if (addrs->addr->sa_family == AF_INET) {
5298 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in);
5300 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5304 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5305 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5311 if (addrs->addr->sa_family == AF_INET6) {
5312 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6);
5314 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5319 (error = prison_local_ip6(td->td_ucred,
5320 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5321 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5322 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5328 error = EAFNOSUPPORT;
5331 sctp_bindx_delete_address(inp, addrs->addr,
5332 addrs->sget_assoc_id, vrf_id,
5338 struct sctp_event *event;
5339 uint32_t event_type;
5341 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5342 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5343 switch (event->se_type) {
5344 case SCTP_ASSOC_CHANGE:
5345 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5347 case SCTP_PEER_ADDR_CHANGE:
5348 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5350 case SCTP_REMOTE_ERROR:
5351 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5353 case SCTP_SEND_FAILED:
5354 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5356 case SCTP_SHUTDOWN_EVENT:
5357 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5359 case SCTP_ADAPTATION_INDICATION:
5360 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5362 case SCTP_PARTIAL_DELIVERY_EVENT:
5363 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5365 case SCTP_AUTHENTICATION_EVENT:
5366 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5368 case SCTP_STREAM_RESET_EVENT:
5369 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5371 case SCTP_SENDER_DRY_EVENT:
5372 event_type = SCTP_PCB_FLAGS_DRYEVNT;
5374 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
5376 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5381 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5385 if (event_type > 0) {
5388 sctp_stcb_feature_on(inp, stcb, event_type);
5389 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
5390 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5391 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5392 (stcb->asoc.stream_queue_cnt == 0)) {
5393 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5397 sctp_stcb_feature_off(inp, stcb, event_type);
5399 SCTP_TCB_UNLOCK(stcb);
5402 * We don't want to send up a storm
5403 * of events, so return an error for
5406 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
5407 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
5408 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
5409 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
5410 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
5411 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5415 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5416 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5417 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
5418 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5419 SCTP_INP_WLOCK(inp);
5421 sctp_feature_on(inp, event_type);
5423 sctp_feature_off(inp, event_type);
5425 SCTP_INP_WUNLOCK(inp);
5427 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
5428 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5429 SCTP_INP_RLOCK(inp);
5430 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5431 SCTP_TCB_LOCK(stcb);
5433 sctp_stcb_feature_on(inp, stcb, event_type);
5435 sctp_stcb_feature_off(inp, stcb, event_type);
5437 SCTP_TCB_UNLOCK(stcb);
5439 SCTP_INP_RUNLOCK(inp);
5445 case SCTP_RECVRCVINFO:
5449 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5450 SCTP_INP_WLOCK(inp);
5452 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5454 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5456 SCTP_INP_WUNLOCK(inp);
5459 case SCTP_RECVNXTINFO:
5463 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5464 SCTP_INP_WLOCK(inp);
5466 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5468 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5470 SCTP_INP_WUNLOCK(inp);
5473 case SCTP_DEFAULT_SNDINFO:
5475 struct sctp_sndinfo *info;
5478 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
5479 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
5482 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5483 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5484 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5485 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5486 stcb->asoc.def_send.sinfo_flags |= policy;
5487 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5488 stcb->asoc.def_send.sinfo_context = info->snd_context;
5490 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5493 SCTP_TCB_UNLOCK(stcb);
5495 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5496 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5497 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
5498 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5499 SCTP_INP_WLOCK(inp);
5500 inp->def_send.sinfo_stream = info->snd_sid;
5501 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
5502 inp->def_send.sinfo_flags = info->snd_flags;
5503 inp->def_send.sinfo_flags |= policy;
5504 inp->def_send.sinfo_ppid = info->snd_ppid;
5505 inp->def_send.sinfo_context = info->snd_context;
5506 SCTP_INP_WUNLOCK(inp);
5508 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
5509 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5510 SCTP_INP_RLOCK(inp);
5511 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5512 SCTP_TCB_LOCK(stcb);
5513 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5514 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5515 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5516 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5517 stcb->asoc.def_send.sinfo_flags |= policy;
5518 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5519 stcb->asoc.def_send.sinfo_context = info->snd_context;
5521 SCTP_TCB_UNLOCK(stcb);
5523 SCTP_INP_RUNLOCK(inp);
5528 case SCTP_DEFAULT_PRINFO:
5530 struct sctp_default_prinfo *info;
5532 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
5533 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
5535 if (PR_SCTP_INVALID_POLICY(info->pr_policy)) {
5536 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5541 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5542 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5543 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5544 SCTP_TCB_UNLOCK(stcb);
5546 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5547 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5548 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
5549 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5550 SCTP_INP_WLOCK(inp);
5551 inp->def_send.sinfo_flags &= 0xfff0;
5552 inp->def_send.sinfo_flags |= info->pr_policy;
5553 inp->def_send.sinfo_timetolive = info->pr_value;
5554 SCTP_INP_WUNLOCK(inp);
5556 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
5557 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5558 SCTP_INP_RLOCK(inp);
5559 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5560 SCTP_TCB_LOCK(stcb);
5561 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5562 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5563 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5564 SCTP_TCB_UNLOCK(stcb);
5566 SCTP_INP_RUNLOCK(inp);
5571 case SCTP_PEER_ADDR_THLDS:
5572 /* Applies to the specific association */
5574 struct sctp_paddrthlds *thlds;
5575 struct sctp_nets *net;
5577 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
5578 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
5581 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_assoc_id);
5584 * We increment here since
5585 * sctp_findassociation_ep_addr() wil do a
5586 * decrement if it finds the stcb as long as
5587 * the locked tcb (last argument) is NOT a
5590 SCTP_INP_INCR_REF(inp);
5591 stcb = sctp_findassociation_ep_addr(&inp,
5592 (struct sockaddr *)&thlds->spt_assoc_id,
5595 SCTP_INP_DECR_REF(inp);
5598 if (stcb && (net == NULL)) {
5599 struct sockaddr *sa;
5601 sa = (struct sockaddr *)&thlds->spt_assoc_id;
5603 if (sa->sa_family == AF_INET) {
5605 struct sockaddr_in *sin;
5607 sin = (struct sockaddr_in *)sa;
5608 if (sin->sin_addr.s_addr) {
5609 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5610 SCTP_TCB_UNLOCK(stcb);
5617 if (sa->sa_family == AF_INET6) {
5618 struct sockaddr_in6 *sin6;
5620 sin6 = (struct sockaddr_in6 *)sa;
5621 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5622 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5623 SCTP_TCB_UNLOCK(stcb);
5630 error = EAFNOSUPPORT;
5631 SCTP_TCB_UNLOCK(stcb);
5632 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5638 if (net->dest_state & SCTP_ADDR_PF) {
5639 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5640 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5641 net->dest_state &= ~SCTP_ADDR_PF;
5644 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5645 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5646 net->dest_state |= SCTP_ADDR_PF;
5647 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5648 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5649 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5652 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5653 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5654 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5655 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5658 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5659 net->dest_state |= SCTP_ADDR_REACHABLE;
5660 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5663 net->failure_threshold = thlds->spt_pathmaxrxt;
5664 net->pf_threshold = thlds->spt_pathpfthld;
5666 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5667 if (net->dest_state & SCTP_ADDR_PF) {
5668 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5669 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5670 net->dest_state &= ~SCTP_ADDR_PF;
5673 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5674 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5675 net->dest_state |= SCTP_ADDR_PF;
5676 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5677 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5678 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5681 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5682 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5683 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5684 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5687 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5688 net->dest_state |= SCTP_ADDR_REACHABLE;
5689 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5692 net->failure_threshold = thlds->spt_pathmaxrxt;
5693 net->pf_threshold = thlds->spt_pathpfthld;
5695 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
5696 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
5699 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5700 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5701 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
5702 SCTP_INP_WLOCK(inp);
5703 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
5704 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
5705 SCTP_INP_WUNLOCK(inp);
5707 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5713 case SCTP_REMOTE_UDP_ENCAPS_PORT:
5715 struct sctp_udpencaps *encaps;
5716 struct sctp_nets *net;
5718 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
5719 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
5721 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
5724 * We increment here since
5725 * sctp_findassociation_ep_addr() wil do a
5726 * decrement if it finds the stcb as long as
5727 * the locked tcb (last argument) is NOT a
5731 SCTP_INP_INCR_REF(inp);
5732 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
5734 SCTP_INP_DECR_REF(inp);
5737 if (stcb && (net == NULL)) {
5738 struct sockaddr *sa;
5740 sa = (struct sockaddr *)&encaps->sue_address;
5742 if (sa->sa_family == AF_INET) {
5744 struct sockaddr_in *sin;
5746 sin = (struct sockaddr_in *)sa;
5747 if (sin->sin_addr.s_addr) {
5748 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5749 SCTP_TCB_UNLOCK(stcb);
5756 if (sa->sa_family == AF_INET6) {
5757 struct sockaddr_in6 *sin6;
5759 sin6 = (struct sockaddr_in6 *)sa;
5760 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5761 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5762 SCTP_TCB_UNLOCK(stcb);
5769 error = EAFNOSUPPORT;
5770 SCTP_TCB_UNLOCK(stcb);
5771 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5777 net->port = encaps->sue_port;
5779 stcb->asoc.port = encaps->sue_port;
5781 SCTP_TCB_UNLOCK(stcb);
5783 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5784 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5785 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
5786 SCTP_INP_WLOCK(inp);
5787 inp->sctp_ep.port = encaps->sue_port;
5788 SCTP_INP_WUNLOCK(inp);
5790 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5797 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
5798 error = ENOPROTOOPT;
5800 } /* end switch (opt) */
5805 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
5807 void *optval = NULL;
5809 struct sctp_inpcb *inp;
5813 if (sopt->sopt_level != IPPROTO_SCTP) {
5814 /* wrong proto level... send back up to IP */
5816 if (INP_CHECK_SOCKAF(so, AF_INET6))
5817 error = ip6_ctloutput(so, sopt);
5819 #if defined(INET) && defined (INET6)
5823 error = ip_ctloutput(so, sopt);
5827 inp = (struct sctp_inpcb *)so->so_pcb;
5828 optsize = sopt->sopt_valsize;
5830 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
5831 if (optval == NULL) {
5832 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
5835 error = sooptcopyin(sopt, optval, optsize, optsize);
5837 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5841 p = (void *)sopt->sopt_td;
5842 if (sopt->sopt_dir == SOPT_SET) {
5843 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
5844 } else if (sopt->sopt_dir == SOPT_GET) {
5845 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
5847 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5850 if ((error == 0) && (optval != NULL)) {
5851 error = sooptcopyout(sopt, optval, optsize);
5852 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5853 } else if (optval != NULL) {
5854 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5862 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
5865 int create_lock_on = 0;
5867 struct sctp_inpcb *inp;
5868 struct sctp_tcb *stcb = NULL;
5870 inp = (struct sctp_inpcb *)so->so_pcb;
5872 /* I made the same as TCP since we are not setup? */
5873 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5874 return (ECONNRESET);
5877 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5880 switch (addr->sa_family) {
5884 struct sockaddr_in6 *sin6p;
5886 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
5887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5890 sin6p = (struct sockaddr_in6 *)addr;
5891 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
5892 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5901 struct sockaddr_in *sinp;
5903 if (addr->sa_len != sizeof(struct sockaddr_in)) {
5904 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5907 sinp = (struct sockaddr_in *)addr;
5908 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
5909 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5916 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
5917 return (EAFNOSUPPORT);
5919 SCTP_INP_INCR_REF(inp);
5920 SCTP_ASOC_CREATE_LOCK(inp);
5924 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
5925 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
5926 /* Should I really unlock ? */
5927 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
5932 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
5933 (addr->sa_family == AF_INET6)) {
5934 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5939 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
5940 SCTP_PCB_FLAGS_UNBOUND) {
5941 /* Bind a ephemeral port */
5942 error = sctp_inpcb_bind(so, NULL, NULL, p);
5947 /* Now do we connect? */
5948 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
5949 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
5950 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5954 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
5955 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
5956 /* We are already connected AND the TCP model */
5957 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
5961 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
5962 SCTP_INP_RLOCK(inp);
5963 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5964 SCTP_INP_RUNLOCK(inp);
5967 * We increment here since sctp_findassociation_ep_addr()
5968 * will do a decrement if it finds the stcb as long as the
5969 * locked tcb (last argument) is NOT a TCB.. aka NULL.
5971 SCTP_INP_INCR_REF(inp);
5972 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
5974 SCTP_INP_DECR_REF(inp);
5976 SCTP_TCB_UNLOCK(stcb);
5980 /* Already have or am bring up an association */
5981 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
5985 vrf_id = inp->def_vrf_id;
5986 /* We are GOOD to go */
5987 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
5989 /* Gak! no memory */
5992 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
5993 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
5994 /* Set the connected flag so we can queue data */
5997 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
5998 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
6000 /* initialize authentication parameters for the assoc */
6001 sctp_initialize_auth_params(inp, stcb);
6003 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
6004 SCTP_TCB_UNLOCK(stcb);
6006 if (create_lock_on) {
6007 SCTP_ASOC_CREATE_UNLOCK(inp);
6009 SCTP_INP_DECR_REF(inp);
6016 sctp_listen(struct socket *so, int backlog, struct thread *p)
6019 * Note this module depends on the protocol processing being called
6020 * AFTER any socket level flags and backlog are applied to the
6021 * socket. The traditional way that the socket flags are applied is
6022 * AFTER protocol processing. We have made a change to the
6023 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
6024 * place if the socket API for SCTP is to work properly.
6028 struct sctp_inpcb *inp;
6030 inp = (struct sctp_inpcb *)so->so_pcb;
6032 /* I made the same as TCP since we are not setup? */
6033 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6034 return (ECONNRESET);
6036 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
6037 /* See if we have a listener */
6038 struct sctp_inpcb *tinp;
6039 union sctp_sockstore store, *sp;
6042 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
6044 struct sctp_laddr *laddr;
6046 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6047 memcpy(&store, &laddr->ifa->address, sizeof(store));
6048 switch (sp->sa.sa_family) {
6051 sp->sin.sin_port = inp->sctp_lport;
6056 sp->sin6.sin6_port = inp->sctp_lport;
6062 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6063 if (tinp && (tinp != inp) &&
6064 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6065 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6066 (tinp->sctp_socket->so_qlimit)) {
6068 * we have a listener already and
6071 SCTP_INP_DECR_REF(tinp);
6072 return (EADDRINUSE);
6074 SCTP_INP_DECR_REF(tinp);
6078 /* Setup a local addr bound all */
6079 memset(&store, 0, sizeof(store));
6080 switch (sp->sa.sa_family) {
6083 store.sin.sin_port = inp->sctp_lport;
6088 sp->sin6.sin6_port = inp->sctp_lport;
6095 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
6096 store.sa.sa_family = AF_INET6;
6097 store.sa.sa_len = sizeof(struct sockaddr_in6);
6101 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
6102 store.sa.sa_family = AF_INET;
6103 store.sa.sa_len = sizeof(struct sockaddr_in);
6106 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6107 if (tinp && (tinp != inp) &&
6108 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6109 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6110 (tinp->sctp_socket->so_qlimit)) {
6112 * we have a listener already and its not
6115 SCTP_INP_DECR_REF(tinp);
6116 return (EADDRINUSE);
6118 SCTP_INP_DECR_REF(inp);
6122 SCTP_INP_RLOCK(inp);
6123 #ifdef SCTP_LOCK_LOGGING
6124 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
6125 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
6129 error = solisten_proto_check(so);
6132 SCTP_INP_RUNLOCK(inp);
6135 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
6136 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
6138 * The unlucky case - We are in the tcp pool with this guy.
6139 * - Someone else is in the main inp slot. - We must move
6140 * this guy (the listener) to the main slot - We must then
6141 * move the guy that was listener to the TCP Pool.
6143 if (sctp_swap_inpcb_for_listen(inp)) {
6147 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6148 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6149 /* We are already connected AND the TCP model */
6151 SCTP_INP_RUNLOCK(inp);
6153 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6154 return (EADDRINUSE);
6156 SCTP_INP_RUNLOCK(inp);
6157 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
6158 /* We must do a bind. */
6160 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
6161 /* bind error, probably perm */
6166 /* It appears for 7.0 and on, we must always call this. */
6167 solisten_proto(so, backlog);
6168 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6169 /* remove the ACCEPTCONN flag for one-to-many sockets */
6170 so->so_options &= ~SO_ACCEPTCONN;
6173 /* turning off listen */
6174 so->so_options &= ~SO_ACCEPTCONN;
6180 static int sctp_defered_wakeup_cnt = 0;
6183 sctp_accept(struct socket *so, struct sockaddr **addr)
6185 struct sctp_tcb *stcb;
6186 struct sctp_inpcb *inp;
6187 union sctp_sockstore store;
6193 inp = (struct sctp_inpcb *)so->so_pcb;
6196 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6197 return (ECONNRESET);
6199 SCTP_INP_RLOCK(inp);
6200 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6201 SCTP_INP_RUNLOCK(inp);
6202 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
6203 return (EOPNOTSUPP);
6205 if (so->so_state & SS_ISDISCONNECTED) {
6206 SCTP_INP_RUNLOCK(inp);
6207 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
6208 return (ECONNABORTED);
6210 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6212 SCTP_INP_RUNLOCK(inp);
6213 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6214 return (ECONNRESET);
6216 SCTP_TCB_LOCK(stcb);
6217 SCTP_INP_RUNLOCK(inp);
6218 store = stcb->asoc.primary_destination->ro._l_addr;
6219 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
6220 SCTP_TCB_UNLOCK(stcb);
6221 switch (store.sa.sa_family) {
6225 struct sockaddr_in *sin;
6227 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6230 sin->sin_family = AF_INET;
6231 sin->sin_len = sizeof(*sin);
6232 sin->sin_port = ((struct sockaddr_in *)&store)->sin_port;
6233 sin->sin_addr = ((struct sockaddr_in *)&store)->sin_addr;
6234 *addr = (struct sockaddr *)sin;
6241 struct sockaddr_in6 *sin6;
6243 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
6246 sin6->sin6_family = AF_INET6;
6247 sin6->sin6_len = sizeof(*sin6);
6248 sin6->sin6_port = ((struct sockaddr_in6 *)&store)->sin6_port;
6250 sin6->sin6_addr = ((struct sockaddr_in6 *)&store)->sin6_addr;
6251 if ((error = sa6_recoverscope(sin6)) != 0) {
6252 SCTP_FREE_SONAME(sin6);
6255 *addr = (struct sockaddr *)sin6;
6263 /* Wake any delayed sleep action */
6264 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
6265 SCTP_INP_WLOCK(inp);
6266 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
6267 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
6268 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
6269 SCTP_INP_WUNLOCK(inp);
6270 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
6271 if (sowriteable(inp->sctp_socket)) {
6272 sowwakeup_locked(inp->sctp_socket);
6274 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
6276 SCTP_INP_WLOCK(inp);
6278 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
6279 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
6280 SCTP_INP_WUNLOCK(inp);
6281 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
6282 if (soreadable(inp->sctp_socket)) {
6283 sctp_defered_wakeup_cnt++;
6284 sorwakeup_locked(inp->sctp_socket);
6286 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
6288 SCTP_INP_WLOCK(inp);
6290 SCTP_INP_WUNLOCK(inp);
6292 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
6293 SCTP_TCB_LOCK(stcb);
6294 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
6301 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
6303 struct sockaddr_in *sin;
6305 struct sctp_inpcb *inp;
6306 struct sctp_ifa *sctp_ifa;
6309 * Do the malloc first in case it blocks.
6311 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6314 sin->sin_family = AF_INET;
6315 sin->sin_len = sizeof(*sin);
6316 inp = (struct sctp_inpcb *)so->so_pcb;
6318 SCTP_FREE_SONAME(sin);
6319 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6320 return (ECONNRESET);
6322 SCTP_INP_RLOCK(inp);
6323 sin->sin_port = inp->sctp_lport;
6324 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
6325 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6326 struct sctp_tcb *stcb;
6327 struct sockaddr_in *sin_a;
6328 struct sctp_nets *net;
6331 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6337 SCTP_TCB_LOCK(stcb);
6338 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6339 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6341 /* this will make coverity happy */
6344 if (sin_a->sin_family == AF_INET) {
6349 if ((!fnd) || (sin_a == NULL)) {
6351 SCTP_TCB_UNLOCK(stcb);
6354 vrf_id = inp->def_vrf_id;
6355 sctp_ifa = sctp_source_address_selection(inp,
6357 (sctp_route_t *) & net->ro,
6360 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
6361 sctp_free_ifa(sctp_ifa);
6363 SCTP_TCB_UNLOCK(stcb);
6365 /* For the bound all case you get back 0 */
6367 sin->sin_addr.s_addr = 0;
6371 /* Take the first IPv4 address in the list */
6372 struct sctp_laddr *laddr;
6375 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6376 if (laddr->ifa->address.sa.sa_family == AF_INET) {
6377 struct sockaddr_in *sin_a;
6379 sin_a = (struct sockaddr_in *)&laddr->ifa->address.sa;
6380 sin->sin_addr = sin_a->sin_addr;
6386 SCTP_FREE_SONAME(sin);
6387 SCTP_INP_RUNLOCK(inp);
6388 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6392 SCTP_INP_RUNLOCK(inp);
6393 (*addr) = (struct sockaddr *)sin;
6398 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
6400 struct sockaddr_in *sin;
6402 struct sockaddr_in *sin_a;
6403 struct sctp_inpcb *inp;
6404 struct sctp_tcb *stcb;
6405 struct sctp_nets *net;
6407 /* Do the malloc first in case it blocks. */
6408 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6411 sin->sin_family = AF_INET;
6412 sin->sin_len = sizeof(*sin);
6414 inp = (struct sctp_inpcb *)so->so_pcb;
6415 if ((inp == NULL) ||
6416 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
6417 /* UDP type and listeners will drop out here */
6418 SCTP_FREE_SONAME(sin);
6419 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
6422 SCTP_INP_RLOCK(inp);
6423 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6425 SCTP_TCB_LOCK(stcb);
6427 SCTP_INP_RUNLOCK(inp);
6429 SCTP_FREE_SONAME(sin);
6430 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6431 return (ECONNRESET);
6434 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6435 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6436 if (sin_a->sin_family == AF_INET) {
6438 sin->sin_port = stcb->rport;
6439 sin->sin_addr = sin_a->sin_addr;
6443 SCTP_TCB_UNLOCK(stcb);
6445 /* No IPv4 address */
6446 SCTP_FREE_SONAME(sin);
6447 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6450 (*addr) = (struct sockaddr *)sin;
6455 struct pr_usrreqs sctp_usrreqs = {
6456 .pru_abort = sctp_abort,
6457 .pru_accept = sctp_accept,
6458 .pru_attach = sctp_attach,
6459 .pru_bind = sctp_bind,
6460 .pru_connect = sctp_connect,
6461 .pru_control = in_control,
6462 .pru_close = sctp_close,
6463 .pru_detach = sctp_close,
6464 .pru_sopoll = sopoll_generic,
6465 .pru_flush = sctp_flush,
6466 .pru_disconnect = sctp_disconnect,
6467 .pru_listen = sctp_listen,
6468 .pru_peeraddr = sctp_peeraddr,
6469 .pru_send = sctp_sendm,
6470 .pru_shutdown = sctp_shutdown,
6471 .pru_sockaddr = sctp_ingetaddr,
6472 .pru_sosend = sctp_sosend,
6473 .pru_soreceive = sctp_soreceive