2 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * a) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
12 * b) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the distribution.
16 * c) Neither the name of Cisco Systems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <netinet/sctp_os.h>
38 #include <netinet/sctp_pcb.h>
39 #include <netinet/sctp_header.h>
40 #include <netinet/sctp_var.h>
43 #include <netinet/sctp_sysctl.h>
44 #include <netinet/sctp_output.h>
45 #include <netinet/sctp_uio.h>
46 #include <netinet/sctp_asconf.h>
47 #include <netinet/sctputil.h>
48 #include <netinet/sctp_indata.h>
49 #include <netinet/sctp_timer.h>
50 #include <netinet/sctp_auth.h>
51 #include <netinet/sctp_bsd_addr.h>
52 #include <netinet/udp.h>
56 extern struct sctp_cc_functions sctp_cc_functions[];
57 extern struct sctp_ss_functions sctp_ss_functions[];
64 /* Initialize and modify the sysctled variables */
66 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
67 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
69 * Allow a user to take no more than 1/2 the number of clusters or
70 * the SB_MAX whichever is smaller for the send window.
72 sb_max_adj = (u_long)((u_quad_t) (SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
73 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
74 (((uint32_t) nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
76 * Now for the recv window, should we take the same amount? or
77 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
78 * now I will just copy.
80 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
81 SCTP_BASE_VAR(first_time) = 0;
82 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
84 #if defined(SCTP_PACKET_LOGGING)
85 SCTP_BASE_VAR(packet_log_writers) = 0;
86 SCTP_BASE_VAR(packet_log_end) = 0;
87 bzero(&SCTP_BASE_VAR(packet_log_buffer), SCTP_PACKET_LOG_SIZE);
100 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
102 struct sctp_tmit_chunk *chk;
105 /* Adjust that too */
106 stcb->asoc.smallest_mtu = nxtsz;
107 /* now off to subtract IP_DF flag if needed */
108 overhead = IP_HDR_SIZE;
109 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
110 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
112 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
113 if ((chk->send_size + overhead) > nxtsz) {
114 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
117 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
118 if ((chk->send_size + overhead) > nxtsz) {
120 * For this guy we also mark for immediate resend
121 * since we sent to big of chunk
123 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
124 if (chk->sent < SCTP_DATAGRAM_RESEND) {
125 sctp_flight_size_decrease(chk);
126 sctp_total_flight_decrease(stcb, chk);
128 if (chk->sent != SCTP_DATAGRAM_RESEND) {
129 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
131 chk->sent = SCTP_DATAGRAM_RESEND;
132 chk->rec.data.doing_fast_retransmit = 0;
133 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
134 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
135 chk->whoTo->flight_size,
137 (uintptr_t) chk->whoTo,
138 chk->rec.data.TSN_seq);
140 /* Clear any time so NO RTT is being done */
148 sctp_notify_mbuf(struct sctp_inpcb *inp,
149 struct sctp_tcb *stcb,
150 struct sctp_nets *net,
155 int totsz, tmr_stopped = 0;
159 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
160 (ip == NULL) || (sh == NULL)) {
162 SCTP_TCB_UNLOCK(stcb);
166 /* First job is to verify the vtag matches what I would send */
167 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
168 SCTP_TCB_UNLOCK(stcb);
171 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
173 if (icmph->icmp_type != ICMP_UNREACH) {
174 /* We only care about unreachable */
175 SCTP_TCB_UNLOCK(stcb);
178 if (icmph->icmp_code != ICMP_UNREACH_NEEDFRAG) {
179 /* not a unreachable message due to frag. */
180 SCTP_TCB_UNLOCK(stcb);
185 nxtsz = ntohs(icmph->icmp_nextmtu);
188 * old type router that does not tell us what the next size
189 * mtu is. Rats we will have to guess (in a educated fashion
192 nxtsz = sctp_get_prev_mtu(totsz);
194 /* Stop any PMTU timer */
195 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
197 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
198 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
200 /* Adjust destination size limit */
201 if (net->mtu > nxtsz) {
204 net->mtu -= sizeof(struct udphdr);
207 /* now what about the ep? */
208 if (stcb->asoc.smallest_mtu > nxtsz) {
209 sctp_pathmtu_adjustment(stcb, nxtsz);
212 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
214 SCTP_TCB_UNLOCK(stcb);
220 sctp_notify(struct sctp_inpcb *inp,
224 struct sctp_tcb *stcb,
225 struct sctp_nets *net)
227 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
234 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
235 (sh == NULL) || (to == NULL)) {
237 SCTP_TCB_UNLOCK(stcb);
240 /* First job is to verify the vtag matches what I would send */
241 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
242 SCTP_TCB_UNLOCK(stcb);
245 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
247 if (icmph->icmp_type != ICMP_UNREACH) {
248 /* We only care about unreachable */
249 SCTP_TCB_UNLOCK(stcb);
252 if ((icmph->icmp_code == ICMP_UNREACH_NET) ||
253 (icmph->icmp_code == ICMP_UNREACH_HOST) ||
254 (icmph->icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
255 (icmph->icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
256 (icmph->icmp_code == ICMP_UNREACH_ISOLATED) ||
257 (icmph->icmp_code == ICMP_UNREACH_NET_PROHIB) ||
258 (icmph->icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
259 (icmph->icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
262 * Hmm reachablity problems we must examine closely. If its
263 * not reachable, we may have lost a network. Or if there is
264 * NO protocol at the other end named SCTP. well we consider
267 if (net->dest_state & SCTP_ADDR_REACHABLE) {
268 /* Ok that destination is NOT reachable */
269 net->dest_state &= ~SCTP_ADDR_REACHABLE;
270 net->dest_state &= ~SCTP_ADDR_PF;
271 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
273 (void *)net, SCTP_SO_NOT_LOCKED);
275 SCTP_TCB_UNLOCK(stcb);
276 } else if ((icmph->icmp_code == ICMP_UNREACH_PROTOCOL) ||
277 (icmph->icmp_code == ICMP_UNREACH_PORT)) {
279 * Here the peer is either playing tricks on us, including
280 * an address that belongs to someone who does not support
281 * SCTP OR was a userland implementation that shutdown and
282 * now is dead. In either case treat it like a OOTB abort
285 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
286 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
287 so = SCTP_INP_SO(inp);
288 atomic_add_int(&stcb->asoc.refcnt, 1);
289 SCTP_TCB_UNLOCK(stcb);
290 SCTP_SOCKET_LOCK(so, 1);
292 atomic_subtract_int(&stcb->asoc.refcnt, 1);
294 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
295 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
296 SCTP_SOCKET_UNLOCK(so, 1);
297 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
299 /* no need to unlock here, since the TCB is gone */
301 SCTP_TCB_UNLOCK(stcb);
307 sctp_ctlinput(cmd, sa, vip)
316 /* FIX, for non-bsd is this right? */
317 vrf_id = SCTP_DEFAULT_VRFID;
318 if (sa->sa_family != AF_INET ||
319 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
322 if (PRC_IS_REDIRECT(cmd)) {
324 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
328 struct sctp_inpcb *inp = NULL;
329 struct sctp_tcb *stcb = NULL;
330 struct sctp_nets *net = NULL;
331 struct sockaddr_in to, from;
333 sh = (struct sctphdr *)((caddr_t)ip + (ip->ip_hl << 2));
334 bzero(&to, sizeof(to));
335 bzero(&from, sizeof(from));
336 from.sin_family = to.sin_family = AF_INET;
337 from.sin_len = to.sin_len = sizeof(to);
338 from.sin_port = sh->src_port;
339 from.sin_addr = ip->ip_src;
340 to.sin_port = sh->dest_port;
341 to.sin_addr = ip->ip_dst;
344 * 'to' holds the dest of the packet that failed to be sent.
345 * 'from' holds our local endpoint address. Thus we reverse
346 * the to and the from in the lookup.
348 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&to,
349 (struct sockaddr *)&from,
350 &inp, &net, 1, vrf_id);
351 if (stcb != NULL && inp && (inp->sctp_socket != NULL)) {
352 if (cmd != PRC_MSGSIZE) {
353 sctp_notify(inp, ip, sh,
354 (struct sockaddr *)&to, stcb,
357 /* handle possible ICMP size messages */
358 sctp_notify_mbuf(inp, stcb, net, ip, sh);
361 if ((stcb == NULL) && (inp != NULL)) {
362 /* reduce ref-count */
364 SCTP_INP_DECR_REF(inp);
365 SCTP_INP_WUNLOCK(inp);
368 SCTP_TCB_UNLOCK(stcb);
378 sctp_getcred(SYSCTL_HANDLER_ARGS)
381 struct sockaddr_in addrs[2];
382 struct sctp_inpcb *inp;
383 struct sctp_nets *net;
384 struct sctp_tcb *stcb;
388 /* FIX, for non-bsd is this right? */
389 vrf_id = SCTP_DEFAULT_VRFID;
391 error = priv_check(req->td, PRIV_NETINET_GETCRED);
396 error = SYSCTL_IN(req, addrs, sizeof(addrs));
400 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
402 &inp, &net, 1, vrf_id);
403 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
404 if ((inp != NULL) && (stcb == NULL)) {
405 /* reduce ref-count */
407 SCTP_INP_DECR_REF(inp);
410 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
414 SCTP_TCB_UNLOCK(stcb);
416 * We use the write lock here, only since in the error leg we need
417 * it. If we used RLOCK, then we would have to
418 * wlock/decr/unlock/rlock. Which in theory could create a hole.
419 * Better to use higher wlock.
423 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
425 SCTP_INP_WUNLOCK(inp);
428 cru2x(inp->sctp_socket->so_cred, &xuc);
429 SCTP_INP_WUNLOCK(inp);
430 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
435 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
436 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
441 sctp_abort(struct socket *so)
443 struct sctp_inpcb *inp;
446 inp = (struct sctp_inpcb *)so->so_pcb;
451 flags = inp->sctp_flags;
452 #ifdef SCTP_LOG_CLOSING
453 sctp_log_closing(inp, NULL, 17);
455 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
456 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
457 #ifdef SCTP_LOG_CLOSING
458 sctp_log_closing(inp, NULL, 16);
460 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
461 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
463 SCTP_SB_CLEAR(so->so_snd);
465 * same for the rcv ones, they are only here for the
468 SCTP_SB_CLEAR(so->so_rcv);
470 /* Now null out the reference, we are completely detached. */
474 flags = inp->sctp_flags;
475 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
476 goto sctp_must_try_again;
483 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
485 struct sctp_inpcb *inp;
486 struct inpcb *ip_inp;
488 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
495 inp = (struct sctp_inpcb *)so->so_pcb;
497 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
500 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
501 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
506 error = sctp_inpcb_alloc(so, vrf_id);
510 inp = (struct sctp_inpcb *)so->so_pcb;
512 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
513 ip_inp = &inp->ip_inp.inp;
514 ip_inp->inp_vflag |= INP_IPV4;
515 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
517 error = ipsec_init_policy(so, &ip_inp->inp_sp);
518 #ifdef SCTP_LOG_CLOSING
519 sctp_log_closing(inp, NULL, 17);
523 flags = inp->sctp_flags;
524 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
525 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
526 #ifdef SCTP_LOG_CLOSING
527 sctp_log_closing(inp, NULL, 15);
529 SCTP_INP_WUNLOCK(inp);
530 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
531 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
533 flags = inp->sctp_flags;
534 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
537 SCTP_INP_WUNLOCK(inp);
543 SCTP_INP_WUNLOCK(inp);
548 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
550 struct sctp_inpcb *inp;
552 inp = (struct sctp_inpcb *)so->so_pcb;
554 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
558 if ((addr->sa_family != AF_INET) ||
559 (addr->sa_len != sizeof(struct sockaddr_in))) {
560 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
564 return (sctp_inpcb_bind(so, addr, NULL, p));
569 sctp_close(struct socket *so)
571 struct sctp_inpcb *inp;
574 inp = (struct sctp_inpcb *)so->so_pcb;
579 * Inform all the lower layer assoc that we are done.
582 flags = inp->sctp_flags;
583 #ifdef SCTP_LOG_CLOSING
584 sctp_log_closing(inp, NULL, 17);
586 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
587 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
588 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
589 (so->so_rcv.sb_cc > 0)) {
590 #ifdef SCTP_LOG_CLOSING
591 sctp_log_closing(inp, NULL, 13);
593 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
594 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
596 #ifdef SCTP_LOG_CLOSING
597 sctp_log_closing(inp, NULL, 14);
599 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
600 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
603 * The socket is now detached, no matter what the state of
604 * the SCTP association.
607 SCTP_SB_CLEAR(so->so_snd);
609 * same for the rcv ones, they are only here for the
612 SCTP_SB_CLEAR(so->so_rcv);
614 /* Now null out the reference, we are completely detached. */
618 flags = inp->sctp_flags;
619 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
620 goto sctp_must_try_again;
628 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
629 struct mbuf *control, struct thread *p);
633 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
634 struct mbuf *control, struct thread *p)
636 struct sctp_inpcb *inp;
639 inp = (struct sctp_inpcb *)so->so_pcb;
642 sctp_m_freem(control);
645 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
649 /* Got to have an to address if we are NOT a connected socket */
650 if ((addr == NULL) &&
651 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
652 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
654 } else if (addr == NULL) {
655 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
656 error = EDESTADDRREQ;
659 sctp_m_freem(control);
665 if (addr->sa_family != AF_INET) {
666 /* must be a v4 address! */
667 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
670 sctp_m_freem(control);
673 error = EDESTADDRREQ;
678 /* now what about control */
681 SCTP_PRINTF("huh? control set?\n");
682 sctp_m_freem(inp->control);
685 inp->control = control;
689 SCTP_BUF_NEXT(inp->pkt_last) = m;
692 inp->pkt_last = inp->pkt = m;
695 /* FreeBSD uses a flag passed */
696 ((flags & PRUS_MORETOCOME) == 0)
699 * note with the current version this code will only be used
700 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
701 * re-defining sosend to use the sctp_sosend. One can
702 * optionally switch back to this code (by changing back the
703 * definitions) but this is not advisable. This code is used
704 * by FreeBSD when sending a file with sendfile() though.
708 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
718 sctp_disconnect(struct socket *so)
720 struct sctp_inpcb *inp;
722 inp = (struct sctp_inpcb *)so->so_pcb;
724 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
728 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
729 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
730 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
732 SCTP_INP_RUNLOCK(inp);
735 struct sctp_association *asoc;
736 struct sctp_tcb *stcb;
738 stcb = LIST_FIRST(&inp->sctp_asoc_list);
740 SCTP_INP_RUNLOCK(inp);
741 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
746 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
747 /* We are about to be freed, out of here */
748 SCTP_TCB_UNLOCK(stcb);
749 SCTP_INP_RUNLOCK(inp);
752 if (((so->so_options & SO_LINGER) &&
753 (so->so_linger == 0)) ||
754 (so->so_rcv.sb_cc > 0)) {
755 if (SCTP_GET_STATE(asoc) !=
756 SCTP_STATE_COOKIE_WAIT) {
757 /* Left with Data unread */
760 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_DONTWAIT, 1, MT_DATA);
766 struct sctp_paramhdr *ph;
768 ph = mtod(err, struct sctp_paramhdr *);
769 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
770 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
771 ph->param_length = htons(SCTP_BUF_LEN(err));
773 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
774 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
776 SCTP_INP_RUNLOCK(inp);
777 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
778 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
779 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
781 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
782 /* No unlock tcb assoc is gone */
785 if (TAILQ_EMPTY(&asoc->send_queue) &&
786 TAILQ_EMPTY(&asoc->sent_queue) &&
787 (asoc->stream_queue_cnt == 0)) {
788 /* there is nothing queued to send, so done */
789 if (asoc->locked_on_sending) {
792 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
793 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
794 /* only send SHUTDOWN 1st time thru */
795 struct sctp_nets *netp;
797 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
798 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
799 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
801 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
802 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
803 sctp_stop_timers_for_shutdown(stcb);
804 if (stcb->asoc.alternate) {
805 netp = stcb->asoc.alternate;
807 netp = stcb->asoc.primary_destination;
809 sctp_send_shutdown(stcb, netp);
810 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
811 stcb->sctp_ep, stcb, netp);
812 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
813 stcb->sctp_ep, stcb, netp);
814 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
818 * we still got (or just got) data to send,
819 * so set SHUTDOWN_PENDING
822 * XXX sockets draft says that SCTP_EOF
823 * should be sent with no data. currently,
824 * we will allow user data to be sent first
825 * and move to SHUTDOWN-PENDING
827 struct sctp_nets *netp;
829 if (stcb->asoc.alternate) {
830 netp = stcb->asoc.alternate;
832 netp = stcb->asoc.primary_destination;
835 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
836 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
838 if (asoc->locked_on_sending) {
839 /* Locked to send out the data */
840 struct sctp_stream_queue_pending *sp;
842 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
844 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
845 asoc->locked_on_sending->stream_no);
847 if ((sp->length == 0) && (sp->msg_is_complete == 0))
848 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
851 if (TAILQ_EMPTY(&asoc->send_queue) &&
852 TAILQ_EMPTY(&asoc->sent_queue) &&
853 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
857 op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
858 0, M_DONTWAIT, 1, MT_DATA);
864 struct sctp_paramhdr *ph;
867 SCTP_BUF_LEN(op_err) =
868 (sizeof(struct sctp_paramhdr) + sizeof(uint32_t));
870 struct sctp_paramhdr *);
871 ph->param_type = htons(
872 SCTP_CAUSE_USER_INITIATED_ABT);
873 ph->param_length = htons(SCTP_BUF_LEN(op_err));
874 ippp = (uint32_t *) (ph + 1);
875 *ippp = htonl(SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4);
877 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
878 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
879 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
880 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
881 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
882 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
884 SCTP_INP_RUNLOCK(inp);
885 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
888 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
891 soisdisconnecting(so);
892 SCTP_TCB_UNLOCK(stcb);
893 SCTP_INP_RUNLOCK(inp);
898 /* UDP model does not support this */
899 SCTP_INP_RUNLOCK(inp);
900 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
906 sctp_flush(struct socket *so, int how)
909 * We will just clear out the values and let subsequent close clear
910 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
911 * they will not be able to read the data, the socket will block
912 * that from happening.
914 struct sctp_inpcb *inp;
916 inp = (struct sctp_inpcb *)so->so_pcb;
918 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
922 /* For the 1 to many model this does nothing */
923 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
924 SCTP_INP_RUNLOCK(inp);
927 SCTP_INP_RUNLOCK(inp);
928 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
930 * First make sure the sb will be happy, we don't use these
931 * except maybe the count
934 SCTP_INP_READ_LOCK(inp);
935 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
936 SCTP_INP_READ_UNLOCK(inp);
937 SCTP_INP_WUNLOCK(inp);
938 so->so_rcv.sb_cc = 0;
939 so->so_rcv.sb_mbcnt = 0;
940 so->so_rcv.sb_mb = NULL;
942 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
944 * First make sure the sb will be happy, we don't use these
945 * except maybe the count
947 so->so_snd.sb_cc = 0;
948 so->so_snd.sb_mbcnt = 0;
949 so->so_snd.sb_mb = NULL;
956 sctp_shutdown(struct socket *so)
958 struct sctp_inpcb *inp;
960 inp = (struct sctp_inpcb *)so->so_pcb;
962 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
966 /* For UDP model this is a invalid call */
967 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
968 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
969 /* Restore the flags that the soshutdown took away. */
970 SOCKBUF_LOCK(&so->so_rcv);
971 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
972 SOCKBUF_UNLOCK(&so->so_rcv);
973 /* This proc will wakeup for read and do nothing (I hope) */
974 SCTP_INP_RUNLOCK(inp);
975 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
979 * Ok if we reach here its the TCP model and it is either a SHUT_WR
980 * or SHUT_RDWR. This means we put the shutdown flag against it.
983 struct sctp_tcb *stcb;
984 struct sctp_association *asoc;
987 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
988 SCTP_INP_RUNLOCK(inp);
993 stcb = LIST_FIRST(&inp->sctp_asoc_list);
996 * Ok we hit the case that the shutdown call was
997 * made after an abort or something. Nothing to do
1000 SCTP_INP_RUNLOCK(inp);
1003 SCTP_TCB_LOCK(stcb);
1005 if (TAILQ_EMPTY(&asoc->send_queue) &&
1006 TAILQ_EMPTY(&asoc->sent_queue) &&
1007 (asoc->stream_queue_cnt == 0)) {
1008 if (asoc->locked_on_sending) {
1011 /* there is nothing queued to send, so I'm done... */
1012 if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) {
1013 /* only send SHUTDOWN the first time through */
1014 struct sctp_nets *netp;
1016 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
1017 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
1018 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1020 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
1021 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
1022 sctp_stop_timers_for_shutdown(stcb);
1023 if (stcb->asoc.alternate) {
1024 netp = stcb->asoc.alternate;
1026 netp = stcb->asoc.primary_destination;
1028 sctp_send_shutdown(stcb, netp);
1029 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1030 stcb->sctp_ep, stcb, netp);
1031 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1032 stcb->sctp_ep, stcb, netp);
1033 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
1037 * we still got (or just got) data to send, so set
1040 struct sctp_nets *netp;
1042 if (stcb->asoc.alternate) {
1043 netp = stcb->asoc.alternate;
1045 netp = stcb->asoc.primary_destination;
1048 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1049 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
1052 if (asoc->locked_on_sending) {
1053 /* Locked to send out the data */
1054 struct sctp_stream_queue_pending *sp;
1056 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
1058 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
1059 asoc->locked_on_sending->stream_no);
1061 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
1062 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
1066 if (TAILQ_EMPTY(&asoc->send_queue) &&
1067 TAILQ_EMPTY(&asoc->sent_queue) &&
1068 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1069 struct mbuf *op_err;
1072 op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
1073 0, M_DONTWAIT, 1, MT_DATA);
1075 /* Fill in the user initiated abort */
1076 struct sctp_paramhdr *ph;
1079 SCTP_BUF_LEN(op_err) =
1080 sizeof(struct sctp_paramhdr) + sizeof(uint32_t);
1082 struct sctp_paramhdr *);
1083 ph->param_type = htons(
1084 SCTP_CAUSE_USER_INITIATED_ABT);
1085 ph->param_length = htons(SCTP_BUF_LEN(op_err));
1086 ippp = (uint32_t *) (ph + 1);
1087 *ippp = htonl(SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1089 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
1090 sctp_abort_an_association(stcb->sctp_ep, stcb,
1091 op_err, SCTP_SO_LOCKED);
1094 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1097 SCTP_TCB_UNLOCK(stcb);
1100 SCTP_INP_RUNLOCK(inp);
1105 * copies a "user" presentable address and removes embedded scope, etc.
1106 * returns 0 on success, 1 on error
1109 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1112 struct sockaddr_in6 lsa6;
1114 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1117 memcpy(ss, sa, sa->sa_len);
1124 * NOTE: assumes addr lock is held
1127 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1128 struct sctp_tcb *stcb,
1130 struct sockaddr_storage *sas,
1133 struct sctp_ifn *sctp_ifn;
1134 struct sctp_ifa *sctp_ifa;
1135 int loopback_scope, ipv4_local_scope, local_scope, site_scope;
1137 int ipv4_addr_legal, ipv6_addr_legal;
1138 struct sctp_vrf *vrf;
1145 /* Turn on all the appropriate scope */
1146 loopback_scope = stcb->asoc.loopback_scope;
1147 ipv4_local_scope = stcb->asoc.ipv4_local_scope;
1148 local_scope = stcb->asoc.local_scope;
1149 site_scope = stcb->asoc.site_scope;
1151 /* Turn on ALL scope, since we look at the EP */
1152 loopback_scope = ipv4_local_scope = local_scope =
1155 ipv4_addr_legal = ipv6_addr_legal = 0;
1156 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1157 ipv6_addr_legal = 1;
1158 if (SCTP_IPV6_V6ONLY(inp) == 0) {
1159 ipv4_addr_legal = 1;
1162 ipv4_addr_legal = 1;
1164 vrf = sctp_find_vrf(vrf_id);
1168 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1169 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1170 if ((loopback_scope == 0) &&
1171 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1172 /* Skip loopback if loopback_scope not set */
1175 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1178 * For the BOUND-ALL case, the list
1179 * associated with a TCB is Always
1180 * considered a reverse list.. i.e.
1181 * it lists addresses that are NOT
1182 * part of the association. If this
1183 * is one of those we must skip it.
1185 if (sctp_is_addr_restricted(stcb,
1190 switch (sctp_ifa->address.sa.sa_family) {
1193 if (ipv4_addr_legal) {
1194 struct sockaddr_in *sin;
1196 sin = (struct sockaddr_in *)&sctp_ifa->address.sa;
1197 if (sin->sin_addr.s_addr == 0) {
1205 if ((ipv4_local_scope == 0) &&
1206 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1210 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1211 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1212 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1213 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1214 actual += sizeof(struct sockaddr_in6);
1217 memcpy(sas, sin, sizeof(*sin));
1218 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1219 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1220 actual += sizeof(*sin);
1224 if (actual >= limit) {
1234 if (ipv6_addr_legal) {
1235 struct sockaddr_in6 *sin6;
1237 sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sa;
1238 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1246 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1247 if (local_scope == 0)
1249 if (sin6->sin6_scope_id == 0) {
1250 if (sa6_recoverscope(sin6) != 0)
1268 if ((site_scope == 0) &&
1269 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1272 memcpy(sas, sin6, sizeof(*sin6));
1273 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1274 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1275 actual += sizeof(*sin6);
1276 if (actual >= limit) {
1291 struct sctp_laddr *laddr;
1293 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1295 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1299 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1302 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1303 sas = (struct sockaddr_storage *)((caddr_t)sas +
1304 laddr->ifa->address.sa.sa_len);
1305 actual += laddr->ifa->address.sa.sa_len;
1306 if (actual >= limit) {
1315 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1316 struct sctp_tcb *stcb,
1318 struct sockaddr_storage *sas)
1322 SCTP_IPI_ADDR_RLOCK();
1323 /* fill up addresses for the endpoint's default vrf */
1324 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1326 SCTP_IPI_ADDR_RUNLOCK();
1331 * NOTE: assumes addr lock is held
1334 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1337 struct sctp_vrf *vrf = NULL;
1340 * In both sub-set bound an bound_all cases we return the MAXIMUM
1341 * number of addresses that you COULD get. In reality the sub-set
1342 * bound may have an exclusion list for a given TCB OR in the
1343 * bound-all case a TCB may NOT include the loopback or other
1344 * addresses as well.
1346 vrf = sctp_find_vrf(vrf_id);
1350 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1351 struct sctp_ifn *sctp_ifn;
1352 struct sctp_ifa *sctp_ifa;
1354 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1355 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1356 /* Count them if they are the right type */
1357 switch (sctp_ifa->address.sa.sa_family) {
1360 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1361 cnt += sizeof(struct sockaddr_in6);
1363 cnt += sizeof(struct sockaddr_in);
1368 cnt += sizeof(struct sockaddr_in6);
1377 struct sctp_laddr *laddr;
1379 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1380 switch (laddr->ifa->address.sa.sa_family) {
1383 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1384 cnt += sizeof(struct sockaddr_in6);
1386 cnt += sizeof(struct sockaddr_in);
1391 cnt += sizeof(struct sockaddr_in6);
1403 sctp_count_max_addresses(struct sctp_inpcb *inp)
1407 SCTP_IPI_ADDR_RLOCK();
1408 /* count addresses for the endpoint's default VRF */
1409 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1410 SCTP_IPI_ADDR_RUNLOCK();
1415 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1416 size_t optsize, void *p, int delay)
1419 int creat_lock_on = 0;
1420 struct sctp_tcb *stcb = NULL;
1421 struct sockaddr *sa;
1422 int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1424 int bad_addresses = 0;
1427 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1429 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1430 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1431 /* We are already connected AND the TCP model */
1432 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1433 return (EADDRINUSE);
1435 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1436 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1437 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1440 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1441 SCTP_INP_RLOCK(inp);
1442 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1443 SCTP_INP_RUNLOCK(inp);
1446 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1449 SCTP_INP_INCR_REF(inp);
1450 SCTP_ASOC_CREATE_LOCK(inp);
1452 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1453 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1454 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1458 totaddrp = (int *)optval;
1459 totaddr = *totaddrp;
1460 sa = (struct sockaddr *)(totaddrp + 1);
1461 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (optsize - sizeof(int)), &bad_addresses);
1462 if ((stcb != NULL) || bad_addresses) {
1463 /* Already have or am bring up an association */
1464 SCTP_ASOC_CREATE_UNLOCK(inp);
1467 SCTP_TCB_UNLOCK(stcb);
1468 if (bad_addresses == 0) {
1469 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1475 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1480 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1482 struct in6pcb *inp6;
1484 inp6 = (struct in6pcb *)inp;
1485 if (SCTP_IPV6_V6ONLY(inp6)) {
1487 * if IPV6_V6ONLY flag, ignore connections destined
1488 * to a v4 addr or v4-mapped addr
1490 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1496 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1497 SCTP_PCB_FLAGS_UNBOUND) {
1498 /* Bind a ephemeral port */
1499 error = sctp_inpcb_bind(so, NULL, NULL, p);
1504 /* FIX ME: do we want to pass in a vrf on the connect call? */
1505 vrf_id = inp->def_vrf_id;
1508 /* We are GOOD to go */
1509 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1513 /* Gak! no memory */
1516 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1517 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1518 /* Set the connected flag so we can queue data */
1521 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1522 /* move to second address */
1523 switch (sa->sa_family) {
1526 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1531 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1539 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1540 /* Fill in the return id */
1542 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1545 a_id = (sctp_assoc_t *) optval;
1546 *a_id = sctp_get_associd(stcb);
1548 /* initialize authentication parameters for the assoc */
1549 sctp_initialize_auth_params(inp, stcb);
1552 /* doing delayed connection */
1553 stcb->asoc.delayed_connection = 1;
1554 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1556 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1557 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1559 SCTP_TCB_UNLOCK(stcb);
1560 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1561 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1562 /* Set the connected flag so we can queue data */
1566 if (creat_lock_on) {
1567 SCTP_ASOC_CREATE_UNLOCK(inp);
1569 SCTP_INP_DECR_REF(inp);
1573 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1574 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1575 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1576 SCTP_INP_RLOCK(inp); \
1577 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1579 SCTP_TCB_LOCK(stcb); \
1581 SCTP_INP_RUNLOCK(inp); \
1582 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1583 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1584 if (stcb == NULL) { \
1585 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1595 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1596 if (size < sizeof(type)) { \
1597 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1601 destp = (type *)srcp; \
1606 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1609 struct sctp_inpcb *inp = NULL;
1611 struct sctp_tcb *stcb = NULL;
1613 if (optval == NULL) {
1614 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1617 inp = (struct sctp_inpcb *)so->so_pcb;
1619 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1626 case SCTP_AUTOCLOSE:
1627 case SCTP_EXPLICIT_EOR:
1628 case SCTP_AUTO_ASCONF:
1629 case SCTP_DISABLE_FRAGMENTS:
1630 case SCTP_I_WANT_MAPPED_V4_ADDR:
1631 case SCTP_USE_EXT_RCVINFO:
1632 SCTP_INP_RLOCK(inp);
1634 case SCTP_DISABLE_FRAGMENTS:
1635 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1637 case SCTP_I_WANT_MAPPED_V4_ADDR:
1638 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1640 case SCTP_AUTO_ASCONF:
1641 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1642 /* only valid for bound all sockets */
1643 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1645 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1650 case SCTP_EXPLICIT_EOR:
1651 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1654 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1656 case SCTP_USE_EXT_RCVINFO:
1657 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1659 case SCTP_AUTOCLOSE:
1660 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1661 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1667 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1668 error = ENOPROTOOPT;
1669 } /* end switch (sopt->sopt_name) */
1670 if (*optsize < sizeof(val)) {
1671 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1675 SCTP_INP_RUNLOCK(inp);
1677 /* return the option value */
1678 *(int *)optval = val;
1679 *optsize = sizeof(val);
1682 case SCTP_GET_PACKET_LOG:
1684 #ifdef SCTP_PACKET_LOGGING
1688 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1689 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1697 case SCTP_REUSE_PORT:
1701 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1702 /* Can't do this for a 1-m socket */
1706 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1707 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1708 *optsize = sizeof(uint32_t);
1711 case SCTP_PARTIAL_DELIVERY_POINT:
1715 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1716 *value = inp->partial_delivery_point;
1717 *optsize = sizeof(uint32_t);
1720 case SCTP_FRAGMENT_INTERLEAVE:
1724 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1725 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1726 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1727 *value = SCTP_FRAG_LEVEL_2;
1729 *value = SCTP_FRAG_LEVEL_1;
1732 *value = SCTP_FRAG_LEVEL_0;
1734 *optsize = sizeof(uint32_t);
1737 case SCTP_CMT_ON_OFF:
1739 struct sctp_assoc_value *av;
1741 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1742 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1744 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1745 SCTP_TCB_UNLOCK(stcb);
1747 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1748 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1749 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1750 SCTP_INP_RLOCK(inp);
1751 av->assoc_value = inp->sctp_cmt_on_off;
1752 SCTP_INP_RUNLOCK(inp);
1754 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1759 *optsize = sizeof(struct sctp_assoc_value);
1763 case SCTP_PLUGGABLE_CC:
1765 struct sctp_assoc_value *av;
1767 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1768 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1770 av->assoc_value = stcb->asoc.congestion_control_module;
1771 SCTP_TCB_UNLOCK(stcb);
1773 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1774 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1775 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1776 SCTP_INP_RLOCK(inp);
1777 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1778 SCTP_INP_RUNLOCK(inp);
1780 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1785 *optsize = sizeof(struct sctp_assoc_value);
1789 case SCTP_CC_OPTION:
1791 struct sctp_cc_option *cc_opt;
1793 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1794 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1798 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1801 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1802 *optsize = sizeof(struct sctp_cc_option);
1804 SCTP_TCB_UNLOCK(stcb);
1808 case SCTP_PLUGGABLE_SS:
1810 struct sctp_assoc_value *av;
1812 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1813 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1815 av->assoc_value = stcb->asoc.stream_scheduling_module;
1816 SCTP_TCB_UNLOCK(stcb);
1818 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1819 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1820 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1821 SCTP_INP_RLOCK(inp);
1822 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1823 SCTP_INP_RUNLOCK(inp);
1825 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1830 *optsize = sizeof(struct sctp_assoc_value);
1836 struct sctp_stream_value *av;
1838 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1839 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1841 if (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1842 &av->stream_value) < 0) {
1843 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1846 *optsize = sizeof(struct sctp_stream_value);
1848 SCTP_TCB_UNLOCK(stcb);
1851 * Can't get stream value without
1854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1859 case SCTP_GET_ADDR_LEN:
1861 struct sctp_assoc_value *av;
1863 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1866 if (av->assoc_value == AF_INET) {
1867 av->assoc_value = sizeof(struct sockaddr_in);
1872 if (av->assoc_value == AF_INET6) {
1873 av->assoc_value = sizeof(struct sockaddr_in6);
1878 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1880 *optsize = sizeof(struct sctp_assoc_value);
1884 case SCTP_GET_ASSOC_NUMBER:
1886 uint32_t *value, cnt;
1888 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1890 SCTP_INP_RLOCK(inp);
1891 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1894 SCTP_INP_RUNLOCK(inp);
1896 *optsize = sizeof(uint32_t);
1899 case SCTP_GET_ASSOC_ID_LIST:
1901 struct sctp_assoc_ids *ids;
1902 unsigned int at, limit;
1904 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1906 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1907 SCTP_INP_RLOCK(inp);
1908 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1910 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1917 SCTP_INP_RUNLOCK(inp);
1919 ids->gaids_number_of_ids = at;
1920 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1926 struct sctp_assoc_value *av;
1928 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1929 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1932 av->assoc_value = stcb->asoc.context;
1933 SCTP_TCB_UNLOCK(stcb);
1935 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1936 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1937 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1938 SCTP_INP_RLOCK(inp);
1939 av->assoc_value = inp->sctp_context;
1940 SCTP_INP_RUNLOCK(inp);
1942 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1947 *optsize = sizeof(struct sctp_assoc_value);
1953 uint32_t *default_vrfid;
1955 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1956 *default_vrfid = inp->def_vrf_id;
1957 *optsize = sizeof(uint32_t);
1960 case SCTP_GET_ASOC_VRF:
1962 struct sctp_assoc_value *id;
1964 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1965 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1968 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1970 id->assoc_value = stcb->asoc.vrf_id;
1971 *optsize = sizeof(struct sctp_assoc_value);
1975 case SCTP_GET_VRF_IDS:
1977 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1981 case SCTP_GET_NONCE_VALUES:
1983 struct sctp_get_nonce_values *gnv;
1985 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1986 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1989 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1990 gnv->gn_local_tag = stcb->asoc.my_vtag;
1991 SCTP_TCB_UNLOCK(stcb);
1992 *optsize = sizeof(struct sctp_get_nonce_values);
1994 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1999 case SCTP_DELAYED_SACK:
2001 struct sctp_sack_info *sack;
2003 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2004 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2006 sack->sack_delay = stcb->asoc.delayed_ack;
2007 sack->sack_freq = stcb->asoc.sack_freq;
2008 SCTP_TCB_UNLOCK(stcb);
2010 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2011 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2012 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2013 SCTP_INP_RLOCK(inp);
2014 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2015 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2016 SCTP_INP_RUNLOCK(inp);
2018 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2023 *optsize = sizeof(struct sctp_sack_info);
2027 case SCTP_GET_SNDBUF_USE:
2029 struct sctp_sockstat *ss;
2031 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2032 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2035 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2036 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2037 stcb->asoc.size_on_all_streams);
2038 SCTP_TCB_UNLOCK(stcb);
2039 *optsize = sizeof(struct sctp_sockstat);
2041 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2046 case SCTP_MAX_BURST:
2050 SCTP_CHECK_AND_CAST(value, optval, uint8_t, *optsize);
2052 SCTP_INP_RLOCK(inp);
2053 if (inp->sctp_ep.max_burst < 256) {
2054 *value = inp->sctp_ep.max_burst;
2058 SCTP_INP_RUNLOCK(inp);
2059 *optsize = sizeof(uint8_t);
2064 struct sctp_assoc_value *av;
2067 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2068 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2071 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2072 SCTP_TCB_UNLOCK(stcb);
2074 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2075 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2076 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2077 SCTP_INP_RLOCK(inp);
2078 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2079 ovh = SCTP_MED_OVERHEAD;
2081 ovh = SCTP_MED_V4_OVERHEAD;
2083 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2084 av->assoc_value = 0;
2086 av->assoc_value = inp->sctp_frag_point - ovh;
2087 SCTP_INP_RUNLOCK(inp);
2089 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2094 *optsize = sizeof(struct sctp_assoc_value);
2098 case SCTP_GET_STAT_LOG:
2099 error = sctp_fill_stat_log(optval, optsize);
2103 struct sctp_event_subscribe *events;
2105 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2106 memset(events, 0, sizeof(struct sctp_event_subscribe));
2107 SCTP_INP_RLOCK(inp);
2108 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2109 events->sctp_data_io_event = 1;
2111 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2112 events->sctp_association_event = 1;
2114 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2115 events->sctp_address_event = 1;
2117 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2118 events->sctp_send_failure_event = 1;
2120 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2121 events->sctp_peer_error_event = 1;
2123 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2124 events->sctp_shutdown_event = 1;
2126 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2127 events->sctp_partial_delivery_event = 1;
2129 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2130 events->sctp_adaptation_layer_event = 1;
2132 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2133 events->sctp_authentication_event = 1;
2135 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2136 events->sctp_sender_dry_event = 1;
2138 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2139 events->sctp_stream_reset_event = 1;
2140 SCTP_INP_RUNLOCK(inp);
2141 *optsize = sizeof(struct sctp_event_subscribe);
2144 case SCTP_ADAPTATION_LAYER:
2148 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2150 SCTP_INP_RLOCK(inp);
2151 *value = inp->sctp_ep.adaptation_layer_indicator;
2152 SCTP_INP_RUNLOCK(inp);
2153 *optsize = sizeof(uint32_t);
2156 case SCTP_SET_INITIAL_DBG_SEQ:
2160 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2161 SCTP_INP_RLOCK(inp);
2162 *value = inp->sctp_ep.initial_sequence_debug;
2163 SCTP_INP_RUNLOCK(inp);
2164 *optsize = sizeof(uint32_t);
2167 case SCTP_GET_LOCAL_ADDR_SIZE:
2171 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2172 SCTP_INP_RLOCK(inp);
2173 *value = sctp_count_max_addresses(inp);
2174 SCTP_INP_RUNLOCK(inp);
2175 *optsize = sizeof(uint32_t);
2178 case SCTP_GET_REMOTE_ADDR_SIZE:
2182 struct sctp_nets *net;
2184 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2185 /* FIXME MT: change to sctp_assoc_value? */
2186 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2190 /* Count the sizes */
2191 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2192 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2193 size += sizeof(struct sockaddr_in6);
2195 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2198 size += sizeof(struct sockaddr_in);
2203 size += sizeof(struct sockaddr_in6);
2211 SCTP_TCB_UNLOCK(stcb);
2212 *value = (uint32_t) size;
2213 *optsize = sizeof(uint32_t);
2215 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2220 case SCTP_GET_PEER_ADDRESSES:
2222 * Get the address information, an array is passed in to
2223 * fill up we pack it.
2227 struct sockaddr_storage *sas;
2228 struct sctp_nets *net;
2229 struct sctp_getaddresses *saddr;
2231 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2232 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2235 left = (*optsize) - sizeof(struct sctp_getaddresses);
2236 *optsize = sizeof(struct sctp_getaddresses);
2237 sas = (struct sockaddr_storage *)&saddr->addr[0];
2239 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2240 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2241 cpsz = sizeof(struct sockaddr_in6);
2243 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2246 cpsz = sizeof(struct sockaddr_in);
2251 cpsz = sizeof(struct sockaddr_in6);
2263 /* not enough room. */
2266 #if defined(INET) && defined(INET6)
2267 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2268 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
2269 /* Must map the address */
2270 in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
2271 (struct sockaddr_in6 *)sas);
2274 memcpy(sas, &net->ro._l_addr, cpsz);
2275 #if defined(INET) && defined(INET6)
2278 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2280 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2284 SCTP_TCB_UNLOCK(stcb);
2286 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2291 case SCTP_GET_LOCAL_ADDRESSES:
2293 size_t limit, actual;
2294 struct sockaddr_storage *sas;
2295 struct sctp_getaddresses *saddr;
2297 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2298 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2300 sas = (struct sockaddr_storage *)&saddr->addr[0];
2301 limit = *optsize - sizeof(sctp_assoc_t);
2302 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2304 SCTP_TCB_UNLOCK(stcb);
2306 *optsize = sizeof(struct sockaddr_storage) + actual;
2309 case SCTP_PEER_ADDR_PARAMS:
2311 struct sctp_paddrparams *paddrp;
2312 struct sctp_nets *net;
2314 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2315 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2319 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2322 * We increment here since
2323 * sctp_findassociation_ep_addr() wil do a
2324 * decrement if it finds the stcb as long as
2325 * the locked tcb (last argument) is NOT a
2328 SCTP_INP_INCR_REF(inp);
2329 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddrp->spp_address, &net, NULL, NULL);
2331 SCTP_INP_DECR_REF(inp);
2334 if (stcb && (net == NULL)) {
2335 struct sockaddr *sa;
2337 sa = (struct sockaddr *)&paddrp->spp_address;
2339 if (sa->sa_family == AF_INET) {
2340 struct sockaddr_in *sin;
2342 sin = (struct sockaddr_in *)sa;
2343 if (sin->sin_addr.s_addr) {
2345 SCTP_TCB_UNLOCK(stcb);
2346 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2352 if (sa->sa_family == AF_INET6) {
2353 struct sockaddr_in6 *sin6;
2355 sin6 = (struct sockaddr_in6 *)sa;
2356 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2358 SCTP_TCB_UNLOCK(stcb);
2359 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2365 error = EAFNOSUPPORT;
2366 SCTP_TCB_UNLOCK(stcb);
2367 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2372 /* Applies to the specific association */
2373 paddrp->spp_flags = 0;
2377 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2378 ovh = SCTP_MED_OVERHEAD;
2380 ovh = SCTP_MED_V4_OVERHEAD;
2383 paddrp->spp_hbinterval = net->heart_beat_delay;
2384 paddrp->spp_pathmaxrxt = net->failure_threshold;
2385 paddrp->spp_pathmtu = net->mtu - ovh;
2386 /* get flags for HB */
2387 if (net->dest_state & SCTP_ADDR_NOHB) {
2388 paddrp->spp_flags |= SPP_HB_DISABLE;
2390 paddrp->spp_flags |= SPP_HB_ENABLE;
2392 /* get flags for PMTU */
2393 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2394 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2396 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2398 if (net->dscp & 0x01) {
2399 paddrp->spp_dscp = net->dscp & 0xfc;
2400 paddrp->spp_flags |= SPP_DSCP;
2403 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2404 (net->flowlabel & 0x80000000)) {
2405 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2406 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2411 * No destination so return default
2414 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2415 paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
2416 if (stcb->asoc.default_dscp & 0x01) {
2417 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2418 paddrp->spp_flags |= SPP_DSCP;
2421 if (stcb->asoc.default_flowlabel & 0x80000000) {
2422 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2423 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2426 /* default settings should be these */
2427 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2428 paddrp->spp_flags |= SPP_HB_DISABLE;
2430 paddrp->spp_flags |= SPP_HB_ENABLE;
2432 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2433 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2435 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2437 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2439 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2440 SCTP_TCB_UNLOCK(stcb);
2442 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2443 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2444 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2445 /* Use endpoint defaults */
2446 SCTP_INP_RLOCK(inp);
2447 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2448 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2449 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2450 /* get inp's default */
2451 if (inp->sctp_ep.default_dscp & 0x01) {
2452 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2453 paddrp->spp_flags |= SPP_DSCP;
2456 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2457 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2458 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2459 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2462 /* can't return this */
2463 paddrp->spp_pathmtu = 0;
2465 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2466 paddrp->spp_flags |= SPP_HB_ENABLE;
2468 paddrp->spp_flags |= SPP_HB_DISABLE;
2470 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2471 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2473 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2475 SCTP_INP_RUNLOCK(inp);
2477 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2482 *optsize = sizeof(struct sctp_paddrparams);
2486 case SCTP_GET_PEER_ADDR_INFO:
2488 struct sctp_paddrinfo *paddri;
2489 struct sctp_nets *net;
2491 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2492 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2496 net = sctp_findnet(stcb, (struct sockaddr *)&paddri->spinfo_address);
2499 * We increment here since
2500 * sctp_findassociation_ep_addr() wil do a
2501 * decrement if it finds the stcb as long as
2502 * the locked tcb (last argument) is NOT a
2505 SCTP_INP_INCR_REF(inp);
2506 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddri->spinfo_address, &net, NULL, NULL);
2508 SCTP_INP_DECR_REF(inp);
2512 if ((stcb) && (net)) {
2513 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2514 /* It's unconfirmed */
2515 paddri->spinfo_state = SCTP_UNCONFIRMED;
2516 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2518 paddri->spinfo_state = SCTP_ACTIVE;
2521 paddri->spinfo_state = SCTP_INACTIVE;
2523 paddri->spinfo_cwnd = net->cwnd;
2524 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2525 paddri->spinfo_rto = net->RTO;
2526 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2527 paddri->spinfo_mtu = net->mtu;
2528 SCTP_TCB_UNLOCK(stcb);
2529 *optsize = sizeof(struct sctp_paddrinfo);
2532 SCTP_TCB_UNLOCK(stcb);
2534 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2539 case SCTP_PCB_STATUS:
2541 struct sctp_pcbinfo *spcb;
2543 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2544 sctp_fill_pcbinfo(spcb);
2545 *optsize = sizeof(struct sctp_pcbinfo);
2550 struct sctp_nets *net;
2551 struct sctp_status *sstat;
2553 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2554 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2557 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2562 * I think passing the state is fine since
2563 * sctp_constants.h will be available to the user
2566 sstat->sstat_state = stcb->asoc.state;
2567 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2568 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2569 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2571 * We can't include chunks that have been passed to
2572 * the socket layer. Only things in queue.
2574 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2575 stcb->asoc.cnt_on_all_streams);
2578 sstat->sstat_instrms = stcb->asoc.streamincnt;
2579 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2580 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2581 memcpy(&sstat->sstat_primary.spinfo_address,
2582 &stcb->asoc.primary_destination->ro._l_addr,
2583 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2584 net = stcb->asoc.primary_destination;
2585 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2587 * Again the user can get info from sctp_constants.h
2588 * for what the state of the network is.
2590 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2591 /* It's unconfirmed */
2592 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2593 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2595 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2598 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2600 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2601 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2602 sstat->sstat_primary.spinfo_rto = net->RTO;
2603 sstat->sstat_primary.spinfo_mtu = net->mtu;
2604 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2605 SCTP_TCB_UNLOCK(stcb);
2606 *optsize = sizeof(struct sctp_status);
2611 struct sctp_rtoinfo *srto;
2613 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2614 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2617 srto->srto_initial = stcb->asoc.initial_rto;
2618 srto->srto_max = stcb->asoc.maxrto;
2619 srto->srto_min = stcb->asoc.minrto;
2620 SCTP_TCB_UNLOCK(stcb);
2622 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2623 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2624 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2625 SCTP_INP_RLOCK(inp);
2626 srto->srto_initial = inp->sctp_ep.initial_rto;
2627 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2628 srto->srto_min = inp->sctp_ep.sctp_minrto;
2629 SCTP_INP_RUNLOCK(inp);
2631 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2636 *optsize = sizeof(struct sctp_rtoinfo);
2642 struct sctp_timeouts *stimo;
2644 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2645 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2648 stimo->stimo_init = stcb->asoc.timoinit;
2649 stimo->stimo_data = stcb->asoc.timodata;
2650 stimo->stimo_sack = stcb->asoc.timosack;
2651 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2652 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2653 stimo->stimo_cookie = stcb->asoc.timocookie;
2654 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2655 SCTP_TCB_UNLOCK(stcb);
2656 *optsize = sizeof(struct sctp_timeouts);
2658 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2663 case SCTP_ASSOCINFO:
2665 struct sctp_assocparams *sasoc;
2667 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2668 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2671 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2672 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2673 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2674 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2675 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2676 SCTP_TCB_UNLOCK(stcb);
2678 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2679 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2680 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2681 SCTP_INP_RLOCK(inp);
2682 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2683 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2684 sasoc->sasoc_number_peer_destinations = 0;
2685 sasoc->sasoc_peer_rwnd = 0;
2686 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2687 SCTP_INP_RUNLOCK(inp);
2689 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2694 *optsize = sizeof(struct sctp_assocparams);
2698 case SCTP_DEFAULT_SEND_PARAM:
2700 struct sctp_sndrcvinfo *s_info;
2702 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2703 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2706 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2707 SCTP_TCB_UNLOCK(stcb);
2709 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2710 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2711 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2712 SCTP_INP_RLOCK(inp);
2713 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2714 SCTP_INP_RUNLOCK(inp);
2716 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2721 *optsize = sizeof(struct sctp_sndrcvinfo);
2727 struct sctp_initmsg *sinit;
2729 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2730 SCTP_INP_RLOCK(inp);
2731 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2732 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2733 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2734 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2735 SCTP_INP_RUNLOCK(inp);
2736 *optsize = sizeof(struct sctp_initmsg);
2739 case SCTP_PRIMARY_ADDR:
2740 /* we allow a "get" operation on this */
2742 struct sctp_setprim *ssp;
2744 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2745 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2748 /* simply copy out the sockaddr_storage... */
2752 if (len > stcb->asoc.primary_destination->ro._l_addr.sa.sa_len)
2753 len = stcb->asoc.primary_destination->ro._l_addr.sa.sa_len;
2755 memcpy(&ssp->ssp_addr,
2756 &stcb->asoc.primary_destination->ro._l_addr,
2758 SCTP_TCB_UNLOCK(stcb);
2759 *optsize = sizeof(struct sctp_setprim);
2761 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2766 case SCTP_HMAC_IDENT:
2768 struct sctp_hmacalgo *shmac;
2769 sctp_hmaclist_t *hmaclist;
2773 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2775 SCTP_INP_RLOCK(inp);
2776 hmaclist = inp->sctp_ep.local_hmacs;
2777 if (hmaclist == NULL) {
2778 /* no HMACs to return */
2779 *optsize = sizeof(*shmac);
2780 SCTP_INP_RUNLOCK(inp);
2783 /* is there room for all of the hmac ids? */
2784 size = sizeof(*shmac) + (hmaclist->num_algo *
2785 sizeof(shmac->shmac_idents[0]));
2786 if ((size_t)(*optsize) < size) {
2787 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2789 SCTP_INP_RUNLOCK(inp);
2792 /* copy in the list */
2793 shmac->shmac_number_of_idents = hmaclist->num_algo;
2794 for (i = 0; i < hmaclist->num_algo; i++) {
2795 shmac->shmac_idents[i] = hmaclist->hmac[i];
2797 SCTP_INP_RUNLOCK(inp);
2801 case SCTP_AUTH_ACTIVE_KEY:
2803 struct sctp_authkeyid *scact;
2805 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2806 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2809 /* get the active key on the assoc */
2810 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2811 SCTP_TCB_UNLOCK(stcb);
2813 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2814 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2815 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2816 /* get the endpoint active key */
2817 SCTP_INP_RLOCK(inp);
2818 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2819 SCTP_INP_RUNLOCK(inp);
2821 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2826 *optsize = sizeof(struct sctp_authkeyid);
2830 case SCTP_LOCAL_AUTH_CHUNKS:
2832 struct sctp_authchunks *sac;
2833 sctp_auth_chklist_t *chklist = NULL;
2836 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2837 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2840 /* get off the assoc */
2841 chklist = stcb->asoc.local_auth_chunks;
2842 /* is there enough space? */
2843 size = sctp_auth_get_chklist_size(chklist);
2844 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2846 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2848 /* copy in the chunks */
2849 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2850 sac->gauth_number_of_chunks = (uint32_t) size;
2851 *optsize = sizeof(struct sctp_authchunks) + size;
2853 SCTP_TCB_UNLOCK(stcb);
2855 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2856 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2857 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2858 /* get off the endpoint */
2859 SCTP_INP_RLOCK(inp);
2860 chklist = inp->sctp_ep.local_auth_chunks;
2861 /* is there enough space? */
2862 size = sctp_auth_get_chklist_size(chklist);
2863 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2865 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2867 /* copy in the chunks */
2868 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2869 sac->gauth_number_of_chunks = (uint32_t) size;
2870 *optsize = sizeof(struct sctp_authchunks) + size;
2872 SCTP_INP_RUNLOCK(inp);
2874 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2880 case SCTP_PEER_AUTH_CHUNKS:
2882 struct sctp_authchunks *sac;
2883 sctp_auth_chklist_t *chklist = NULL;
2886 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2887 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2890 /* get off the assoc */
2891 chklist = stcb->asoc.peer_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 sac->gauth_number_of_chunks = (uint32_t) size;
2901 *optsize = sizeof(struct sctp_authchunks) + size;
2903 SCTP_TCB_UNLOCK(stcb);
2905 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2912 struct sctp_event *event;
2913 uint32_t event_type;
2915 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2916 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
2918 switch (event->se_type) {
2919 case SCTP_ASSOC_CHANGE:
2920 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
2922 case SCTP_PEER_ADDR_CHANGE:
2923 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
2925 case SCTP_REMOTE_ERROR:
2926 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
2928 case SCTP_SEND_FAILED:
2929 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
2931 case SCTP_SHUTDOWN_EVENT:
2932 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
2934 case SCTP_ADAPTATION_INDICATION:
2935 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
2937 case SCTP_PARTIAL_DELIVERY_EVENT:
2938 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
2940 case SCTP_AUTHENTICATION_EVENT:
2941 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
2943 case SCTP_STREAM_RESET_EVENT:
2944 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
2946 case SCTP_SENDER_DRY_EVENT:
2947 event_type = SCTP_PCB_FLAGS_DRYEVNT;
2949 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
2951 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
2954 case SCTP_ASSOC_RESET_EVENT:
2955 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
2957 case SCTP_STREAM_CHANGE_EVENT:
2958 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
2960 case SCTP_SEND_FAILED_EVENT:
2961 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
2965 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2969 if (event_type > 0) {
2971 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
2972 SCTP_TCB_UNLOCK(stcb);
2974 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2975 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2976 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
2977 SCTP_INP_RLOCK(inp);
2978 event->se_on = sctp_is_feature_on(inp, event_type);
2979 SCTP_INP_RUNLOCK(inp);
2981 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2987 *optsize = sizeof(struct sctp_event);
2991 case SCTP_RECVRCVINFO:
2995 if (*optsize < sizeof(int)) {
2996 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2999 SCTP_INP_RLOCK(inp);
3000 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3001 SCTP_INP_RUNLOCK(inp);
3004 /* return the option value */
3005 *(int *)optval = onoff;
3006 *optsize = sizeof(int);
3010 case SCTP_RECVNXTINFO:
3014 if (*optsize < sizeof(int)) {
3015 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3018 SCTP_INP_RLOCK(inp);
3019 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3020 SCTP_INP_RUNLOCK(inp);
3023 /* return the option value */
3024 *(int *)optval = onoff;
3025 *optsize = sizeof(int);
3029 case SCTP_DEFAULT_SNDINFO:
3031 struct sctp_sndinfo *info;
3033 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3034 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3037 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3038 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3039 info->snd_flags &= 0xfff0;
3040 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3041 info->snd_context = stcb->asoc.def_send.sinfo_context;
3042 SCTP_TCB_UNLOCK(stcb);
3044 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3045 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3046 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3047 SCTP_INP_RLOCK(inp);
3048 info->snd_sid = inp->def_send.sinfo_stream;
3049 info->snd_flags = inp->def_send.sinfo_flags;
3050 info->snd_flags &= 0xfff0;
3051 info->snd_ppid = inp->def_send.sinfo_ppid;
3052 info->snd_context = inp->def_send.sinfo_context;
3053 SCTP_INP_RUNLOCK(inp);
3055 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3060 *optsize = sizeof(struct sctp_sndinfo);
3064 case SCTP_DEFAULT_PRINFO:
3066 struct sctp_default_prinfo *info;
3068 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3069 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3072 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3073 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3074 SCTP_TCB_UNLOCK(stcb);
3076 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3077 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3078 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3079 SCTP_INP_RLOCK(inp);
3080 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3081 info->pr_value = inp->def_send.sinfo_timetolive;
3082 SCTP_INP_RUNLOCK(inp);
3084 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3089 *optsize = sizeof(struct sctp_default_prinfo);
3093 case SCTP_PEER_ADDR_THLDS:
3095 struct sctp_paddrthlds *thlds;
3096 struct sctp_nets *net;
3098 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3099 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3103 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_address);
3106 * We increment here since
3107 * sctp_findassociation_ep_addr() wil do a
3108 * decrement if it finds the stcb as long as
3109 * the locked tcb (last argument) is NOT a
3112 SCTP_INP_INCR_REF(inp);
3113 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&thlds->spt_address, &net, NULL, NULL);
3115 SCTP_INP_DECR_REF(inp);
3118 if (stcb && (net == NULL)) {
3119 struct sockaddr *sa;
3121 sa = (struct sockaddr *)&thlds->spt_address;
3123 if (sa->sa_family == AF_INET) {
3124 struct sockaddr_in *sin;
3126 sin = (struct sockaddr_in *)sa;
3127 if (sin->sin_addr.s_addr) {
3129 SCTP_TCB_UNLOCK(stcb);
3130 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3136 if (sa->sa_family == AF_INET6) {
3137 struct sockaddr_in6 *sin6;
3139 sin6 = (struct sockaddr_in6 *)sa;
3140 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3142 SCTP_TCB_UNLOCK(stcb);
3143 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3149 error = EAFNOSUPPORT;
3150 SCTP_TCB_UNLOCK(stcb);
3151 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3157 thlds->spt_pathmaxrxt = net->failure_threshold;
3158 thlds->spt_pathpfthld = net->pf_threshold;
3160 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3161 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3163 thlds->spt_assoc_id = sctp_get_associd(stcb);
3164 SCTP_TCB_UNLOCK(stcb);
3166 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3167 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3168 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3169 /* Use endpoint defaults */
3170 SCTP_INP_RLOCK(inp);
3171 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3172 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3173 SCTP_INP_RUNLOCK(inp);
3175 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3180 *optsize = sizeof(struct sctp_paddrthlds);
3184 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3186 struct sctp_udpencaps *encaps;
3187 struct sctp_nets *net;
3189 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3190 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3193 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
3196 * We increment here since
3197 * sctp_findassociation_ep_addr() wil do a
3198 * decrement if it finds the stcb as long as
3199 * the locked tcb (last argument) is NOT a
3203 SCTP_INP_INCR_REF(inp);
3204 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
3206 SCTP_INP_DECR_REF(inp);
3209 if (stcb && (net == NULL)) {
3210 struct sockaddr *sa;
3212 sa = (struct sockaddr *)&encaps->sue_address;
3214 if (sa->sa_family == AF_INET) {
3215 struct sockaddr_in *sin;
3217 sin = (struct sockaddr_in *)sa;
3218 if (sin->sin_addr.s_addr) {
3220 SCTP_TCB_UNLOCK(stcb);
3221 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3227 if (sa->sa_family == AF_INET6) {
3228 struct sockaddr_in6 *sin6;
3230 sin6 = (struct sockaddr_in6 *)sa;
3231 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3233 SCTP_TCB_UNLOCK(stcb);
3234 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3240 error = EAFNOSUPPORT;
3241 SCTP_TCB_UNLOCK(stcb);
3242 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3248 encaps->sue_port = net->port;
3250 encaps->sue_port = stcb->asoc.port;
3252 SCTP_TCB_UNLOCK(stcb);
3254 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3255 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3256 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3257 SCTP_INP_RLOCK(inp);
3258 encaps->sue_port = inp->sctp_ep.port;
3259 SCTP_INP_RUNLOCK(inp);
3261 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3266 *optsize = sizeof(struct sctp_paddrparams);
3270 case SCTP_ENABLE_STREAM_RESET:
3272 struct sctp_assoc_value *av;
3274 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3275 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3278 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3279 SCTP_TCB_UNLOCK(stcb);
3281 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3282 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3283 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3284 SCTP_INP_RLOCK(inp);
3285 av->assoc_value = (uint32_t) inp->local_strreset_support;
3286 SCTP_INP_RUNLOCK(inp);
3288 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3293 *optsize = sizeof(struct sctp_assoc_value);
3298 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3299 error = ENOPROTOOPT;
3301 } /* end switch (sopt->sopt_name) */
3309 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3314 struct sctp_tcb *stcb = NULL;
3315 struct sctp_inpcb *inp = NULL;
3318 if (optval == NULL) {
3319 SCTP_PRINTF("optval is NULL\n");
3320 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3323 inp = (struct sctp_inpcb *)so->so_pcb;
3325 SCTP_PRINTF("inp is NULL?\n");
3326 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3329 vrf_id = inp->def_vrf_id;
3334 case SCTP_AUTOCLOSE:
3335 case SCTP_AUTO_ASCONF:
3336 case SCTP_EXPLICIT_EOR:
3337 case SCTP_DISABLE_FRAGMENTS:
3338 case SCTP_USE_EXT_RCVINFO:
3339 case SCTP_I_WANT_MAPPED_V4_ADDR:
3340 /* copy in the option value */
3341 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3346 case SCTP_DISABLE_FRAGMENTS:
3347 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3349 case SCTP_AUTO_ASCONF:
3351 * NOTE: we don't really support this flag
3353 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3354 /* only valid for bound all sockets */
3355 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3357 /* forbidden by admin */
3358 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3361 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3363 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3367 case SCTP_EXPLICIT_EOR:
3368 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3370 case SCTP_USE_EXT_RCVINFO:
3371 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3373 case SCTP_I_WANT_MAPPED_V4_ADDR:
3374 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3375 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3377 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3382 set_opt = SCTP_PCB_FLAGS_NODELAY;
3384 case SCTP_AUTOCLOSE:
3385 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3386 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3387 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3390 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3392 * The value is in ticks. Note this does not effect
3393 * old associations, only new ones.
3395 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3398 SCTP_INP_WLOCK(inp);
3400 sctp_feature_on(inp, set_opt);
3402 sctp_feature_off(inp, set_opt);
3404 SCTP_INP_WUNLOCK(inp);
3406 case SCTP_REUSE_PORT:
3408 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3409 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3410 /* Can't set it after we are bound */
3414 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3415 /* Can't do this for a 1-m socket */
3420 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3422 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3425 case SCTP_PARTIAL_DELIVERY_POINT:
3429 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3430 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3431 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3435 inp->partial_delivery_point = *value;
3438 case SCTP_FRAGMENT_INTERLEAVE:
3439 /* not yet until we re-write sctp_recvmsg() */
3443 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3444 if (*level == SCTP_FRAG_LEVEL_2) {
3445 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3446 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3447 } else if (*level == SCTP_FRAG_LEVEL_1) {
3448 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3449 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3450 } else if (*level == SCTP_FRAG_LEVEL_0) {
3451 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3452 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3455 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3460 case SCTP_CMT_ON_OFF:
3461 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3462 struct sctp_assoc_value *av;
3464 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3465 if (av->assoc_value > SCTP_CMT_MAX) {
3466 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3470 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3472 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3473 SCTP_TCB_UNLOCK(stcb);
3475 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3476 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3477 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3478 (av->assoc_id == SCTP_ALL_ASSOC)) {
3479 SCTP_INP_WLOCK(inp);
3480 inp->sctp_cmt_on_off = av->assoc_value;
3481 SCTP_INP_WUNLOCK(inp);
3483 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3484 (av->assoc_id == SCTP_ALL_ASSOC)) {
3485 SCTP_INP_RLOCK(inp);
3486 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3487 SCTP_TCB_LOCK(stcb);
3488 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3489 SCTP_TCB_UNLOCK(stcb);
3491 SCTP_INP_RUNLOCK(inp);
3495 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3496 error = ENOPROTOOPT;
3499 case SCTP_PLUGGABLE_CC:
3501 struct sctp_assoc_value *av;
3502 struct sctp_nets *net;
3504 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3505 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3506 (av->assoc_value != SCTP_CC_HSTCP) &&
3507 (av->assoc_value != SCTP_CC_HTCP) &&
3508 (av->assoc_value != SCTP_CC_RTCC)) {
3509 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3513 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3515 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3516 stcb->asoc.congestion_control_module = av->assoc_value;
3517 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3518 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3519 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3522 SCTP_TCB_UNLOCK(stcb);
3524 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3525 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3526 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3527 (av->assoc_id == SCTP_ALL_ASSOC)) {
3528 SCTP_INP_WLOCK(inp);
3529 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3530 SCTP_INP_WUNLOCK(inp);
3532 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3533 (av->assoc_id == SCTP_ALL_ASSOC)) {
3534 SCTP_INP_RLOCK(inp);
3535 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3536 SCTP_TCB_LOCK(stcb);
3537 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3538 stcb->asoc.congestion_control_module = av->assoc_value;
3539 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3540 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3541 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3544 SCTP_TCB_UNLOCK(stcb);
3546 SCTP_INP_RUNLOCK(inp);
3551 case SCTP_CC_OPTION:
3553 struct sctp_cc_option *cc_opt;
3555 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
3556 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
3558 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
3559 SCTP_INP_RLOCK(inp);
3560 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3561 SCTP_TCB_LOCK(stcb);
3562 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
3563 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
3565 SCTP_TCB_UNLOCK(stcb);
3567 SCTP_INP_RUNLOCK(inp);
3572 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
3575 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
3578 SCTP_TCB_UNLOCK(stcb);
3582 case SCTP_PLUGGABLE_SS:
3584 struct sctp_assoc_value *av;
3586 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3587 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
3588 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
3589 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
3590 (av->assoc_value != SCTP_SS_PRIORITY) &&
3591 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
3592 (av->assoc_value != SCTP_SS_FIRST_COME)) {
3593 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3597 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3599 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3600 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3601 stcb->asoc.stream_scheduling_module = av->assoc_value;
3602 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3603 SCTP_TCB_UNLOCK(stcb);
3605 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3606 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3607 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3608 (av->assoc_id == SCTP_ALL_ASSOC)) {
3609 SCTP_INP_WLOCK(inp);
3610 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
3611 SCTP_INP_WUNLOCK(inp);
3613 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3614 (av->assoc_id == SCTP_ALL_ASSOC)) {
3615 SCTP_INP_RLOCK(inp);
3616 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3617 SCTP_TCB_LOCK(stcb);
3618 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3619 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3620 stcb->asoc.stream_scheduling_module = av->assoc_value;
3621 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3622 SCTP_TCB_UNLOCK(stcb);
3624 SCTP_INP_RUNLOCK(inp);
3631 struct sctp_stream_value *av;
3633 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
3634 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3636 if (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
3637 av->stream_value) < 0) {
3638 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3641 SCTP_TCB_UNLOCK(stcb);
3643 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
3644 SCTP_INP_RLOCK(inp);
3645 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3646 SCTP_TCB_LOCK(stcb);
3647 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
3649 &stcb->asoc.strmout[av->stream_id],
3651 SCTP_TCB_UNLOCK(stcb);
3653 SCTP_INP_RUNLOCK(inp);
3657 * Can't set stream value without
3660 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3666 case SCTP_CLR_STAT_LOG:
3667 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3672 struct sctp_assoc_value *av;
3674 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3675 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3678 stcb->asoc.context = av->assoc_value;
3679 SCTP_TCB_UNLOCK(stcb);
3681 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3682 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3683 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3684 (av->assoc_id == SCTP_ALL_ASSOC)) {
3685 SCTP_INP_WLOCK(inp);
3686 inp->sctp_context = av->assoc_value;
3687 SCTP_INP_WUNLOCK(inp);
3689 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3690 (av->assoc_id == SCTP_ALL_ASSOC)) {
3691 SCTP_INP_RLOCK(inp);
3692 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3693 SCTP_TCB_LOCK(stcb);
3694 stcb->asoc.context = av->assoc_value;
3695 SCTP_TCB_UNLOCK(stcb);
3697 SCTP_INP_RUNLOCK(inp);
3704 uint32_t *default_vrfid;
3706 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
3707 if (*default_vrfid > SCTP_MAX_VRF_ID) {
3708 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3712 inp->def_vrf_id = *default_vrfid;
3715 case SCTP_DEL_VRF_ID:
3717 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3721 case SCTP_ADD_VRF_ID:
3723 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3727 case SCTP_DELAYED_SACK:
3729 struct sctp_sack_info *sack;
3731 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
3732 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
3733 if (sack->sack_delay) {
3734 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
3735 sack->sack_delay = SCTP_MAX_SACK_DELAY;
3736 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
3737 sack->sack_delay = TICKS_TO_MSEC(1);
3741 if (sack->sack_delay) {
3742 stcb->asoc.delayed_ack = sack->sack_delay;
3744 if (sack->sack_freq) {
3745 stcb->asoc.sack_freq = sack->sack_freq;
3747 SCTP_TCB_UNLOCK(stcb);
3749 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3750 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3751 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
3752 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3753 SCTP_INP_WLOCK(inp);
3754 if (sack->sack_delay) {
3755 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
3757 if (sack->sack_freq) {
3758 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
3760 SCTP_INP_WUNLOCK(inp);
3762 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
3763 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3764 SCTP_INP_RLOCK(inp);
3765 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3766 SCTP_TCB_LOCK(stcb);
3767 if (sack->sack_delay) {
3768 stcb->asoc.delayed_ack = sack->sack_delay;
3770 if (sack->sack_freq) {
3771 stcb->asoc.sack_freq = sack->sack_freq;
3773 SCTP_TCB_UNLOCK(stcb);
3775 SCTP_INP_RUNLOCK(inp);
3780 case SCTP_AUTH_CHUNK:
3782 struct sctp_authchunk *sauth;
3784 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
3786 SCTP_INP_WLOCK(inp);
3787 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
3788 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3791 SCTP_INP_WUNLOCK(inp);
3796 struct sctp_authkey *sca;
3797 struct sctp_keyhead *shared_keys;
3798 sctp_sharedkey_t *shared_key;
3799 sctp_key_t *key = NULL;
3802 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
3803 if (sca->sca_keylength == 0) {
3804 size = optsize - sizeof(struct sctp_authkey);
3806 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
3807 size = sca->sca_keylength;
3809 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3814 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
3817 shared_keys = &stcb->asoc.shared_keys;
3818 /* clear the cached keys for this key id */
3819 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3821 * create the new shared key and
3825 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3827 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3829 SCTP_TCB_UNLOCK(stcb);
3833 shared_key = sctp_alloc_sharedkey();
3834 if (shared_key == NULL) {
3836 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3838 SCTP_TCB_UNLOCK(stcb);
3841 shared_key->key = key;
3842 shared_key->keyid = sca->sca_keynumber;
3843 error = sctp_insert_sharedkey(shared_keys, shared_key);
3844 SCTP_TCB_UNLOCK(stcb);
3846 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3847 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3848 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
3849 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3850 SCTP_INP_WLOCK(inp);
3851 shared_keys = &inp->sctp_ep.shared_keys;
3853 * clear the cached keys on all
3854 * assocs for this key id
3856 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
3858 * create the new shared key and
3862 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3864 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3866 SCTP_INP_WUNLOCK(inp);
3870 shared_key = sctp_alloc_sharedkey();
3871 if (shared_key == NULL) {
3873 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3875 SCTP_INP_WUNLOCK(inp);
3878 shared_key->key = key;
3879 shared_key->keyid = sca->sca_keynumber;
3880 error = sctp_insert_sharedkey(shared_keys, shared_key);
3881 SCTP_INP_WUNLOCK(inp);
3883 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
3884 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3885 SCTP_INP_RLOCK(inp);
3886 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3887 SCTP_TCB_LOCK(stcb);
3888 shared_keys = &stcb->asoc.shared_keys;
3890 * clear the cached keys for
3893 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3895 * create the new shared key
3896 * and insert/replace it
3899 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3901 SCTP_TCB_UNLOCK(stcb);
3905 shared_key = sctp_alloc_sharedkey();
3906 if (shared_key == NULL) {
3908 SCTP_TCB_UNLOCK(stcb);
3911 shared_key->key = key;
3912 shared_key->keyid = sca->sca_keynumber;
3913 error = sctp_insert_sharedkey(shared_keys, shared_key);
3914 SCTP_TCB_UNLOCK(stcb);
3916 SCTP_INP_RUNLOCK(inp);
3921 case SCTP_HMAC_IDENT:
3923 struct sctp_hmacalgo *shmac;
3924 sctp_hmaclist_t *hmaclist;
3929 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
3930 if (optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) {
3931 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3935 hmaclist = sctp_alloc_hmaclist(shmac->shmac_number_of_idents);
3936 if (hmaclist == NULL) {
3937 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3941 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
3942 hmacid = shmac->shmac_idents[i];
3943 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
3944 /* invalid HMACs were found */ ;
3945 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3947 sctp_free_hmaclist(hmaclist);
3948 goto sctp_set_hmac_done;
3952 for (i = 0; i < hmaclist->num_algo; i++) {
3953 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
3954 /* already in list */
3959 sctp_free_hmaclist(hmaclist);
3960 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3964 /* set it on the endpoint */
3965 SCTP_INP_WLOCK(inp);
3966 if (inp->sctp_ep.local_hmacs)
3967 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
3968 inp->sctp_ep.local_hmacs = hmaclist;
3969 SCTP_INP_WUNLOCK(inp);
3973 case SCTP_AUTH_ACTIVE_KEY:
3975 struct sctp_authkeyid *scact;
3977 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
3978 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
3980 /* set the active key on the right place */
3982 /* set the active key on the assoc */
3983 if (sctp_auth_setactivekey(stcb,
3984 scact->scact_keynumber)) {
3985 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
3986 SCTP_FROM_SCTP_USRREQ,
3990 SCTP_TCB_UNLOCK(stcb);
3992 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3993 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3994 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
3995 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
3996 SCTP_INP_WLOCK(inp);
3997 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
3998 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4001 SCTP_INP_WUNLOCK(inp);
4003 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4004 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4005 SCTP_INP_RLOCK(inp);
4006 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4007 SCTP_TCB_LOCK(stcb);
4008 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4009 SCTP_TCB_UNLOCK(stcb);
4011 SCTP_INP_RUNLOCK(inp);
4016 case SCTP_AUTH_DELETE_KEY:
4018 struct sctp_authkeyid *scdel;
4020 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4021 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4023 /* delete the key from the right place */
4025 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4026 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4029 SCTP_TCB_UNLOCK(stcb);
4031 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4032 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4033 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4034 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4035 SCTP_INP_WLOCK(inp);
4036 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4037 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4040 SCTP_INP_WUNLOCK(inp);
4042 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4043 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4044 SCTP_INP_RLOCK(inp);
4045 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4046 SCTP_TCB_LOCK(stcb);
4047 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4048 SCTP_TCB_UNLOCK(stcb);
4050 SCTP_INP_RUNLOCK(inp);
4055 case SCTP_AUTH_DEACTIVATE_KEY:
4057 struct sctp_authkeyid *keyid;
4059 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4060 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4062 /* deactivate the key from the right place */
4064 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4065 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4068 SCTP_TCB_UNLOCK(stcb);
4070 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4071 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4072 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4073 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4074 SCTP_INP_WLOCK(inp);
4075 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4076 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4079 SCTP_INP_WUNLOCK(inp);
4081 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4082 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4083 SCTP_INP_RLOCK(inp);
4084 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4085 SCTP_TCB_LOCK(stcb);
4086 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4087 SCTP_TCB_UNLOCK(stcb);
4089 SCTP_INP_RUNLOCK(inp);
4094 case SCTP_ENABLE_STREAM_RESET:
4096 struct sctp_assoc_value *av;
4098 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4099 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4100 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4104 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4106 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4107 SCTP_TCB_UNLOCK(stcb);
4109 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4110 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4111 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4112 (av->assoc_id == SCTP_ALL_ASSOC)) {
4113 SCTP_INP_WLOCK(inp);
4114 inp->local_strreset_support = (uint8_t) av->assoc_value;
4115 SCTP_INP_WUNLOCK(inp);
4117 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4118 (av->assoc_id == SCTP_ALL_ASSOC)) {
4119 SCTP_INP_RLOCK(inp);
4120 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4121 SCTP_TCB_LOCK(stcb);
4122 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4123 SCTP_TCB_UNLOCK(stcb);
4125 SCTP_INP_RUNLOCK(inp);
4130 case SCTP_RESET_STREAMS:
4132 struct sctp_reset_streams *strrst;
4133 int i, send_out = 0;
4136 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4137 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4139 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4143 if (stcb->asoc.peer_supports_strreset == 0) {
4145 * Peer does not support the chunk type.
4147 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4149 SCTP_TCB_UNLOCK(stcb);
4152 if (stcb->asoc.stream_reset_outstanding) {
4153 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4155 SCTP_TCB_UNLOCK(stcb);
4158 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4161 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4164 if ((send_in == 0) && (send_out == 0)) {
4165 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4167 SCTP_TCB_UNLOCK(stcb);
4170 for (i = 0; i < strrst->srs_number_streams; i++) {
4172 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4173 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4178 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4179 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4185 SCTP_TCB_UNLOCK(stcb);
4188 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4189 strrst->srs_stream_list,
4190 send_out, send_in, 0, 0, 0, 0, 0);
4192 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4193 SCTP_TCB_UNLOCK(stcb);
4196 case SCTP_ADD_STREAMS:
4198 struct sctp_add_streams *stradd;
4199 uint8_t addstream = 0;
4200 uint16_t add_o_strmcnt = 0;
4201 uint16_t add_i_strmcnt = 0;
4203 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4204 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4206 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4210 if (stcb->asoc.peer_supports_strreset == 0) {
4212 * Peer does not support the chunk type.
4214 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4216 SCTP_TCB_UNLOCK(stcb);
4219 if (stcb->asoc.stream_reset_outstanding) {
4220 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4222 SCTP_TCB_UNLOCK(stcb);
4225 if ((stradd->sas_outstrms == 0) &&
4226 (stradd->sas_instrms == 0)) {
4230 if (stradd->sas_outstrms) {
4232 /* We allocate here */
4233 add_o_strmcnt = stradd->sas_outstrms;
4234 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4235 /* You can't have more than 64k */
4240 if (stradd->sas_instrms) {
4245 * We allocate inside
4246 * sctp_send_str_reset_req()
4248 add_i_strmcnt = stradd->sas_instrms;
4249 cnt = add_i_strmcnt;
4250 cnt += stcb->asoc.streamincnt;
4251 if (cnt > 0x0000ffff) {
4252 /* You can't have more than 64k */
4256 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4257 /* More than you are allowed */
4262 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4263 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4265 SCTP_TCB_UNLOCK(stcb);
4268 case SCTP_RESET_ASSOC:
4272 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4273 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4275 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4279 if (stcb->asoc.peer_supports_strreset == 0) {
4281 * Peer does not support the chunk type.
4283 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4285 SCTP_TCB_UNLOCK(stcb);
4288 if (stcb->asoc.stream_reset_outstanding) {
4289 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4291 SCTP_TCB_UNLOCK(stcb);
4294 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 1, 0, 0, 0, 0);
4295 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4296 SCTP_TCB_UNLOCK(stcb);
4299 case SCTP_CONNECT_X:
4300 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4301 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4305 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4307 case SCTP_CONNECT_X_DELAYED:
4308 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4309 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4313 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4315 case SCTP_CONNECT_X_COMPLETE:
4317 struct sockaddr *sa;
4318 struct sctp_nets *net;
4320 /* FIXME MT: check correct? */
4321 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4324 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4325 SCTP_INP_RLOCK(inp);
4326 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4328 SCTP_TCB_LOCK(stcb);
4329 net = sctp_findnet(stcb, sa);
4331 SCTP_INP_RUNLOCK(inp);
4334 * We increment here since
4335 * sctp_findassociation_ep_addr() wil do a
4336 * decrement if it finds the stcb as long as
4337 * the locked tcb (last argument) is NOT a
4340 SCTP_INP_INCR_REF(inp);
4341 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
4343 SCTP_INP_DECR_REF(inp);
4348 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4352 if (stcb->asoc.delayed_connection == 1) {
4353 stcb->asoc.delayed_connection = 0;
4354 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4355 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4356 stcb->asoc.primary_destination,
4357 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
4358 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4361 * already expired or did not use delayed
4364 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4367 SCTP_TCB_UNLOCK(stcb);
4370 case SCTP_MAX_BURST:
4374 SCTP_CHECK_AND_CAST(burst, optval, uint8_t, optsize);
4376 SCTP_INP_WLOCK(inp);
4377 inp->sctp_ep.max_burst = *burst;
4378 SCTP_INP_WUNLOCK(inp);
4383 struct sctp_assoc_value *av;
4386 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4387 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4389 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4390 ovh = SCTP_MED_OVERHEAD;
4392 ovh = SCTP_MED_V4_OVERHEAD;
4395 if (av->assoc_value) {
4396 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4398 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4400 SCTP_TCB_UNLOCK(stcb);
4402 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4403 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4404 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4405 SCTP_INP_WLOCK(inp);
4407 * FIXME MT: I think this is not in
4408 * tune with the API ID
4410 if (av->assoc_value) {
4411 inp->sctp_frag_point = (av->assoc_value + ovh);
4413 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4415 SCTP_INP_WUNLOCK(inp);
4417 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4425 struct sctp_event_subscribe *events;
4427 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4429 SCTP_INP_WLOCK(inp);
4430 if (events->sctp_data_io_event) {
4431 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4433 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4436 if (events->sctp_association_event) {
4437 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4439 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4442 if (events->sctp_address_event) {
4443 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4445 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4448 if (events->sctp_send_failure_event) {
4449 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4451 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4454 if (events->sctp_peer_error_event) {
4455 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4457 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4460 if (events->sctp_shutdown_event) {
4461 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4463 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4466 if (events->sctp_partial_delivery_event) {
4467 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4469 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4472 if (events->sctp_adaptation_layer_event) {
4473 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4475 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4478 if (events->sctp_authentication_event) {
4479 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4481 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4484 if (events->sctp_sender_dry_event) {
4485 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
4487 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
4490 if (events->sctp_stream_reset_event) {
4491 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4493 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4495 SCTP_INP_WUNLOCK(inp);
4497 SCTP_INP_RLOCK(inp);
4498 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4499 SCTP_TCB_LOCK(stcb);
4500 if (events->sctp_association_event) {
4501 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4503 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4505 if (events->sctp_address_event) {
4506 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4508 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4510 if (events->sctp_send_failure_event) {
4511 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4513 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4515 if (events->sctp_peer_error_event) {
4516 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4518 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4520 if (events->sctp_shutdown_event) {
4521 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4523 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4525 if (events->sctp_partial_delivery_event) {
4526 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4528 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4530 if (events->sctp_adaptation_layer_event) {
4531 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4533 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4535 if (events->sctp_authentication_event) {
4536 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4538 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4540 if (events->sctp_sender_dry_event) {
4541 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4543 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4545 if (events->sctp_stream_reset_event) {
4546 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4548 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4550 SCTP_TCB_UNLOCK(stcb);
4553 * Send up the sender dry event only for 1-to-1
4556 if (events->sctp_sender_dry_event) {
4557 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4558 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
4559 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4561 SCTP_TCB_LOCK(stcb);
4562 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
4563 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
4564 (stcb->asoc.stream_queue_cnt == 0)) {
4565 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
4567 SCTP_TCB_UNLOCK(stcb);
4571 SCTP_INP_RUNLOCK(inp);
4574 case SCTP_ADAPTATION_LAYER:
4576 struct sctp_setadaptation *adap_bits;
4578 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
4579 SCTP_INP_WLOCK(inp);
4580 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
4581 SCTP_INP_WUNLOCK(inp);
4585 case SCTP_SET_INITIAL_DBG_SEQ:
4589 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
4590 SCTP_INP_WLOCK(inp);
4591 inp->sctp_ep.initial_sequence_debug = *vvv;
4592 SCTP_INP_WUNLOCK(inp);
4596 case SCTP_DEFAULT_SEND_PARAM:
4598 struct sctp_sndrcvinfo *s_info;
4600 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
4601 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
4604 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4605 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4607 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4610 SCTP_TCB_UNLOCK(stcb);
4612 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4613 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4614 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
4615 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4616 SCTP_INP_WLOCK(inp);
4617 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
4618 SCTP_INP_WUNLOCK(inp);
4620 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
4621 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4622 SCTP_INP_RLOCK(inp);
4623 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4624 SCTP_TCB_LOCK(stcb);
4625 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4626 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4628 SCTP_TCB_UNLOCK(stcb);
4630 SCTP_INP_RUNLOCK(inp);
4635 case SCTP_PEER_ADDR_PARAMS:
4637 struct sctp_paddrparams *paddrp;
4638 struct sctp_nets *net;
4640 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
4641 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
4644 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
4647 * We increment here since
4648 * sctp_findassociation_ep_addr() wil do a
4649 * decrement if it finds the stcb as long as
4650 * the locked tcb (last argument) is NOT a
4653 SCTP_INP_INCR_REF(inp);
4654 stcb = sctp_findassociation_ep_addr(&inp,
4655 (struct sockaddr *)&paddrp->spp_address,
4658 SCTP_INP_DECR_REF(inp);
4661 if (stcb && (net == NULL)) {
4662 struct sockaddr *sa;
4664 sa = (struct sockaddr *)&paddrp->spp_address;
4666 if (sa->sa_family == AF_INET) {
4668 struct sockaddr_in *sin;
4670 sin = (struct sockaddr_in *)sa;
4671 if (sin->sin_addr.s_addr) {
4672 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4673 SCTP_TCB_UNLOCK(stcb);
4680 if (sa->sa_family == AF_INET6) {
4681 struct sockaddr_in6 *sin6;
4683 sin6 = (struct sockaddr_in6 *)sa;
4684 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
4685 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4686 SCTP_TCB_UNLOCK(stcb);
4693 error = EAFNOSUPPORT;
4694 SCTP_TCB_UNLOCK(stcb);
4695 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4700 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
4702 SCTP_TCB_UNLOCK(stcb);
4703 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4706 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
4708 SCTP_TCB_UNLOCK(stcb);
4709 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4713 /************************TCB SPECIFIC SET ******************/
4715 * do we change the timer for HB, we run
4720 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4721 ovh = SCTP_MED_OVERHEAD;
4723 ovh = SCTP_MED_V4_OVERHEAD;
4726 /* network sets ? */
4728 /************************NET SPECIFIC SET ******************/
4729 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4730 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
4731 !(net->dest_state & SCTP_ADDR_NOHB)) {
4732 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4733 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4735 net->dest_state |= SCTP_ADDR_NOHB;
4737 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4738 if (paddrp->spp_hbinterval) {
4739 net->heart_beat_delay = paddrp->spp_hbinterval;
4740 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4741 net->heart_beat_delay = 0;
4743 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4744 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4745 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4746 net->dest_state &= ~SCTP_ADDR_NOHB;
4748 if (paddrp->spp_flags & SPP_HB_DEMAND) {
4750 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4751 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
4752 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4754 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4755 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4756 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4757 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4759 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4760 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4761 net->mtu = paddrp->spp_pathmtu + ovh;
4762 if (net->mtu < stcb->asoc.smallest_mtu) {
4763 sctp_pathmtu_adjustment(stcb, net->mtu);
4767 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4768 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4769 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4771 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4773 if (paddrp->spp_pathmaxrxt) {
4774 if (net->dest_state & SCTP_ADDR_PF) {
4775 if (net->error_count > paddrp->spp_pathmaxrxt) {
4776 net->dest_state &= ~SCTP_ADDR_PF;
4779 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4780 (net->error_count > net->pf_threshold)) {
4781 net->dest_state |= SCTP_ADDR_PF;
4782 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4783 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4784 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4787 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4788 if (net->error_count > paddrp->spp_pathmaxrxt) {
4789 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4790 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
4793 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4794 net->dest_state |= SCTP_ADDR_REACHABLE;
4795 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
4798 net->failure_threshold = paddrp->spp_pathmaxrxt;
4800 if (paddrp->spp_flags & SPP_DSCP) {
4801 net->dscp = paddrp->spp_dscp & 0xfc;
4805 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4806 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4807 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4808 net->flowlabel |= 0x80000000;
4813 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
4814 if (paddrp->spp_pathmaxrxt) {
4815 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
4816 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4817 if (net->dest_state & SCTP_ADDR_PF) {
4818 if (net->error_count > paddrp->spp_pathmaxrxt) {
4819 net->dest_state &= ~SCTP_ADDR_PF;
4822 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4823 (net->error_count > net->pf_threshold)) {
4824 net->dest_state |= SCTP_ADDR_PF;
4825 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4826 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4827 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4830 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4831 if (net->error_count > paddrp->spp_pathmaxrxt) {
4832 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4833 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
4836 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4837 net->dest_state |= SCTP_ADDR_REACHABLE;
4838 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
4841 net->failure_threshold = paddrp->spp_pathmaxrxt;
4844 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4845 if (paddrp->spp_hbinterval) {
4846 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
4847 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4848 stcb->asoc.heart_beat_delay = 0;
4850 /* Turn back on the timer */
4851 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4852 if (paddrp->spp_hbinterval) {
4853 net->heart_beat_delay = paddrp->spp_hbinterval;
4854 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4855 net->heart_beat_delay = 0;
4857 if (net->dest_state & SCTP_ADDR_NOHB) {
4858 net->dest_state &= ~SCTP_ADDR_NOHB;
4860 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4861 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4862 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4864 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4866 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4867 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4868 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
4869 net->dest_state |= SCTP_ADDR_NOHB;
4870 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
4871 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4875 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4877 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4878 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4879 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4880 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4881 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4883 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4884 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4885 net->mtu = paddrp->spp_pathmtu + ovh;
4886 if (net->mtu < stcb->asoc.smallest_mtu) {
4887 sctp_pathmtu_adjustment(stcb, net->mtu);
4891 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4893 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4894 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4895 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4896 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4898 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4900 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4902 if (paddrp->spp_flags & SPP_DSCP) {
4903 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4904 net->dscp = paddrp->spp_dscp & 0xfc;
4907 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
4908 stcb->asoc.default_dscp |= 0x01;
4911 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4912 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4913 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4914 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4915 net->flowlabel |= 0x80000000;
4918 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4919 stcb->asoc.default_flowlabel |= 0x80000000;
4923 SCTP_TCB_UNLOCK(stcb);
4925 /************************NO TCB, SET TO default stuff ******************/
4926 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4927 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4928 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
4929 SCTP_INP_WLOCK(inp);
4931 * For the TOS/FLOWLABEL stuff you
4932 * set it with the options on the
4935 if (paddrp->spp_pathmaxrxt) {
4936 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
4938 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
4939 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4940 else if (paddrp->spp_hbinterval) {
4941 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
4942 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
4943 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4945 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4946 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4947 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4948 } else if (paddrp->spp_hbinterval) {
4949 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4951 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4952 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
4953 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4955 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4956 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4957 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
4958 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4960 if (paddrp->spp_flags & SPP_DSCP) {
4961 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
4962 inp->sctp_ep.default_dscp |= 0x01;
4965 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4966 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4967 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4968 inp->sctp_ep.default_flowlabel |= 0x80000000;
4972 SCTP_INP_WUNLOCK(inp);
4974 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4982 struct sctp_rtoinfo *srto;
4983 uint32_t new_init, new_min, new_max;
4985 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
4986 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
4989 if (srto->srto_initial)
4990 new_init = srto->srto_initial;
4992 new_init = stcb->asoc.initial_rto;
4994 new_max = srto->srto_max;
4996 new_max = stcb->asoc.maxrto;
4998 new_min = srto->srto_min;
5000 new_min = stcb->asoc.minrto;
5001 if ((new_min <= new_init) && (new_init <= new_max)) {
5002 stcb->asoc.initial_rto = new_init;
5003 stcb->asoc.maxrto = new_max;
5004 stcb->asoc.minrto = new_min;
5006 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5009 SCTP_TCB_UNLOCK(stcb);
5011 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5012 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5013 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5014 SCTP_INP_WLOCK(inp);
5015 if (srto->srto_initial)
5016 new_init = srto->srto_initial;
5018 new_init = inp->sctp_ep.initial_rto;
5020 new_max = srto->srto_max;
5022 new_max = inp->sctp_ep.sctp_maxrto;
5024 new_min = srto->srto_min;
5026 new_min = inp->sctp_ep.sctp_minrto;
5027 if ((new_min <= new_init) && (new_init <= new_max)) {
5028 inp->sctp_ep.initial_rto = new_init;
5029 inp->sctp_ep.sctp_maxrto = new_max;
5030 inp->sctp_ep.sctp_minrto = new_min;
5032 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5035 SCTP_INP_WUNLOCK(inp);
5037 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5043 case SCTP_ASSOCINFO:
5045 struct sctp_assocparams *sasoc;
5047 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5048 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5049 if (sasoc->sasoc_cookie_life) {
5050 /* boundary check the cookie life */
5051 if (sasoc->sasoc_cookie_life < 1000)
5052 sasoc->sasoc_cookie_life = 1000;
5053 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5054 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5058 if (sasoc->sasoc_asocmaxrxt)
5059 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5060 if (sasoc->sasoc_cookie_life) {
5061 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5063 SCTP_TCB_UNLOCK(stcb);
5065 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5066 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5067 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5068 SCTP_INP_WLOCK(inp);
5069 if (sasoc->sasoc_asocmaxrxt)
5070 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5071 if (sasoc->sasoc_cookie_life) {
5072 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5074 SCTP_INP_WUNLOCK(inp);
5076 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5084 struct sctp_initmsg *sinit;
5086 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5087 SCTP_INP_WLOCK(inp);
5088 if (sinit->sinit_num_ostreams)
5089 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5091 if (sinit->sinit_max_instreams)
5092 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5094 if (sinit->sinit_max_attempts)
5095 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5097 if (sinit->sinit_max_init_timeo)
5098 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5099 SCTP_INP_WUNLOCK(inp);
5102 case SCTP_PRIMARY_ADDR:
5104 struct sctp_setprim *spa;
5105 struct sctp_nets *net;
5107 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5108 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5112 net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
5115 * We increment here since
5116 * sctp_findassociation_ep_addr() wil do a
5117 * decrement if it finds the stcb as long as
5118 * the locked tcb (last argument) is NOT a
5121 SCTP_INP_INCR_REF(inp);
5122 stcb = sctp_findassociation_ep_addr(&inp,
5123 (struct sockaddr *)&spa->ssp_addr,
5126 SCTP_INP_DECR_REF(inp);
5130 if ((stcb) && (net)) {
5131 if ((net != stcb->asoc.primary_destination) &&
5132 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
5133 /* Ok we need to set it */
5134 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5135 if ((stcb->asoc.alternate) &&
5136 (!(net->dest_state & SCTP_ADDR_PF)) &&
5137 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5138 sctp_free_remote_addr(stcb->asoc.alternate);
5139 stcb->asoc.alternate = NULL;
5144 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5148 SCTP_TCB_UNLOCK(stcb);
5152 case SCTP_SET_DYNAMIC_PRIMARY:
5154 union sctp_sockstore *ss;
5156 error = priv_check(curthread,
5157 PRIV_NETINET_RESERVEDPORT);
5161 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5162 /* SUPER USER CHECK? */
5163 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5166 case SCTP_SET_PEER_PRIMARY_ADDR:
5168 struct sctp_setpeerprim *sspp;
5170 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5171 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5173 struct sctp_ifa *ifa;
5175 ifa = sctp_find_ifa_by_addr((struct sockaddr *)&sspp->sspp_addr,
5176 stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5178 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5182 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5184 * Must validate the ifa found is in
5187 struct sctp_laddr *laddr;
5190 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5191 if (laddr->ifa == NULL) {
5192 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5196 if (laddr->ifa == ifa) {
5202 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5207 if (sctp_set_primary_ip_address_sa(stcb,
5208 (struct sockaddr *)&sspp->sspp_addr) != 0) {
5209 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5213 SCTP_TCB_UNLOCK(stcb);
5215 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5220 case SCTP_BINDX_ADD_ADDR:
5222 struct sctp_getaddresses *addrs;
5225 td = (struct thread *)p;
5226 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5229 if (addrs->addr->sa_family == AF_INET) {
5230 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5231 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5235 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5236 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5242 if (addrs->addr->sa_family == AF_INET6) {
5243 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5244 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5248 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5249 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5250 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5256 error = EAFNOSUPPORT;
5259 sctp_bindx_add_address(so, inp, addrs->addr,
5260 addrs->sget_assoc_id, vrf_id,
5264 case SCTP_BINDX_REM_ADDR:
5266 struct sctp_getaddresses *addrs;
5269 td = (struct thread *)p;
5271 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5273 if (addrs->addr->sa_family == AF_INET) {
5274 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5275 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5279 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5280 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5286 if (addrs->addr->sa_family == AF_INET6) {
5287 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5288 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5293 (error = prison_local_ip6(td->td_ucred,
5294 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5295 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5296 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5302 error = EAFNOSUPPORT;
5305 sctp_bindx_delete_address(inp, addrs->addr,
5306 addrs->sget_assoc_id, vrf_id,
5312 struct sctp_event *event;
5313 uint32_t event_type;
5315 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5316 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5317 switch (event->se_type) {
5318 case SCTP_ASSOC_CHANGE:
5319 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5321 case SCTP_PEER_ADDR_CHANGE:
5322 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5324 case SCTP_REMOTE_ERROR:
5325 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5327 case SCTP_SEND_FAILED:
5328 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5330 case SCTP_SHUTDOWN_EVENT:
5331 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5333 case SCTP_ADAPTATION_INDICATION:
5334 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5336 case SCTP_PARTIAL_DELIVERY_EVENT:
5337 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5339 case SCTP_AUTHENTICATION_EVENT:
5340 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5342 case SCTP_STREAM_RESET_EVENT:
5343 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5345 case SCTP_SENDER_DRY_EVENT:
5346 event_type = SCTP_PCB_FLAGS_DRYEVNT;
5348 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
5350 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5353 case SCTP_ASSOC_RESET_EVENT:
5354 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
5356 case SCTP_STREAM_CHANGE_EVENT:
5357 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
5359 case SCTP_SEND_FAILED_EVENT:
5360 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
5364 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5368 if (event_type > 0) {
5371 sctp_stcb_feature_on(inp, stcb, event_type);
5372 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
5373 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5374 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5375 (stcb->asoc.stream_queue_cnt == 0)) {
5376 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5380 sctp_stcb_feature_off(inp, stcb, event_type);
5382 SCTP_TCB_UNLOCK(stcb);
5385 * We don't want to send up a storm
5386 * of events, so return an error for
5389 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
5390 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
5391 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
5392 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
5393 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
5394 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5398 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5399 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5400 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
5401 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5402 SCTP_INP_WLOCK(inp);
5404 sctp_feature_on(inp, event_type);
5406 sctp_feature_off(inp, event_type);
5408 SCTP_INP_WUNLOCK(inp);
5410 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
5411 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5412 SCTP_INP_RLOCK(inp);
5413 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5414 SCTP_TCB_LOCK(stcb);
5416 sctp_stcb_feature_on(inp, stcb, event_type);
5418 sctp_stcb_feature_off(inp, stcb, event_type);
5420 SCTP_TCB_UNLOCK(stcb);
5422 SCTP_INP_RUNLOCK(inp);
5428 case SCTP_RECVRCVINFO:
5432 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5433 SCTP_INP_WLOCK(inp);
5435 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5437 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5439 SCTP_INP_WUNLOCK(inp);
5442 case SCTP_RECVNXTINFO:
5446 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5447 SCTP_INP_WLOCK(inp);
5449 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5451 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5453 SCTP_INP_WUNLOCK(inp);
5456 case SCTP_DEFAULT_SNDINFO:
5458 struct sctp_sndinfo *info;
5461 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
5462 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
5465 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5466 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5467 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5468 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5469 stcb->asoc.def_send.sinfo_flags |= policy;
5470 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5471 stcb->asoc.def_send.sinfo_context = info->snd_context;
5473 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5476 SCTP_TCB_UNLOCK(stcb);
5478 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5479 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5480 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
5481 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5482 SCTP_INP_WLOCK(inp);
5483 inp->def_send.sinfo_stream = info->snd_sid;
5484 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
5485 inp->def_send.sinfo_flags = info->snd_flags;
5486 inp->def_send.sinfo_flags |= policy;
5487 inp->def_send.sinfo_ppid = info->snd_ppid;
5488 inp->def_send.sinfo_context = info->snd_context;
5489 SCTP_INP_WUNLOCK(inp);
5491 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
5492 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5493 SCTP_INP_RLOCK(inp);
5494 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5495 SCTP_TCB_LOCK(stcb);
5496 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5497 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5498 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5499 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5500 stcb->asoc.def_send.sinfo_flags |= policy;
5501 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5502 stcb->asoc.def_send.sinfo_context = info->snd_context;
5504 SCTP_TCB_UNLOCK(stcb);
5506 SCTP_INP_RUNLOCK(inp);
5511 case SCTP_DEFAULT_PRINFO:
5513 struct sctp_default_prinfo *info;
5515 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
5516 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
5518 if (PR_SCTP_INVALID_POLICY(info->pr_policy)) {
5519 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5524 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5525 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5526 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5527 SCTP_TCB_UNLOCK(stcb);
5529 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5530 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5531 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
5532 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5533 SCTP_INP_WLOCK(inp);
5534 inp->def_send.sinfo_flags &= 0xfff0;
5535 inp->def_send.sinfo_flags |= info->pr_policy;
5536 inp->def_send.sinfo_timetolive = info->pr_value;
5537 SCTP_INP_WUNLOCK(inp);
5539 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
5540 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5541 SCTP_INP_RLOCK(inp);
5542 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5543 SCTP_TCB_LOCK(stcb);
5544 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5545 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5546 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5547 SCTP_TCB_UNLOCK(stcb);
5549 SCTP_INP_RUNLOCK(inp);
5554 case SCTP_PEER_ADDR_THLDS:
5555 /* Applies to the specific association */
5557 struct sctp_paddrthlds *thlds;
5558 struct sctp_nets *net;
5560 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
5561 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
5564 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_assoc_id);
5567 * We increment here since
5568 * sctp_findassociation_ep_addr() wil do a
5569 * decrement if it finds the stcb as long as
5570 * the locked tcb (last argument) is NOT a
5573 SCTP_INP_INCR_REF(inp);
5574 stcb = sctp_findassociation_ep_addr(&inp,
5575 (struct sockaddr *)&thlds->spt_assoc_id,
5578 SCTP_INP_DECR_REF(inp);
5581 if (stcb && (net == NULL)) {
5582 struct sockaddr *sa;
5584 sa = (struct sockaddr *)&thlds->spt_assoc_id;
5586 if (sa->sa_family == AF_INET) {
5588 struct sockaddr_in *sin;
5590 sin = (struct sockaddr_in *)sa;
5591 if (sin->sin_addr.s_addr) {
5592 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5593 SCTP_TCB_UNLOCK(stcb);
5600 if (sa->sa_family == AF_INET6) {
5601 struct sockaddr_in6 *sin6;
5603 sin6 = (struct sockaddr_in6 *)sa;
5604 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5605 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5606 SCTP_TCB_UNLOCK(stcb);
5613 error = EAFNOSUPPORT;
5614 SCTP_TCB_UNLOCK(stcb);
5615 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5621 if (net->dest_state & SCTP_ADDR_PF) {
5622 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5623 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5624 net->dest_state &= ~SCTP_ADDR_PF;
5627 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5628 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5629 net->dest_state |= SCTP_ADDR_PF;
5630 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5631 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5632 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5635 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5636 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5637 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5638 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5641 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5642 net->dest_state |= SCTP_ADDR_REACHABLE;
5643 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5646 net->failure_threshold = thlds->spt_pathmaxrxt;
5647 net->pf_threshold = thlds->spt_pathpfthld;
5649 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5650 if (net->dest_state & SCTP_ADDR_PF) {
5651 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5652 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5653 net->dest_state &= ~SCTP_ADDR_PF;
5656 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5657 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5658 net->dest_state |= SCTP_ADDR_PF;
5659 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5660 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5661 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5664 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5665 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5666 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5667 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5670 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5671 net->dest_state |= SCTP_ADDR_REACHABLE;
5672 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5675 net->failure_threshold = thlds->spt_pathmaxrxt;
5676 net->pf_threshold = thlds->spt_pathpfthld;
5678 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
5679 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
5682 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5683 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5684 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
5685 SCTP_INP_WLOCK(inp);
5686 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
5687 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
5688 SCTP_INP_WUNLOCK(inp);
5690 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5696 case SCTP_REMOTE_UDP_ENCAPS_PORT:
5698 struct sctp_udpencaps *encaps;
5699 struct sctp_nets *net;
5701 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
5702 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
5704 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
5707 * We increment here since
5708 * sctp_findassociation_ep_addr() wil do a
5709 * decrement if it finds the stcb as long as
5710 * the locked tcb (last argument) is NOT a
5714 SCTP_INP_INCR_REF(inp);
5715 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
5717 SCTP_INP_DECR_REF(inp);
5720 if (stcb && (net == NULL)) {
5721 struct sockaddr *sa;
5723 sa = (struct sockaddr *)&encaps->sue_address;
5725 if (sa->sa_family == AF_INET) {
5727 struct sockaddr_in *sin;
5729 sin = (struct sockaddr_in *)sa;
5730 if (sin->sin_addr.s_addr) {
5731 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5732 SCTP_TCB_UNLOCK(stcb);
5739 if (sa->sa_family == AF_INET6) {
5740 struct sockaddr_in6 *sin6;
5742 sin6 = (struct sockaddr_in6 *)sa;
5743 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5744 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5745 SCTP_TCB_UNLOCK(stcb);
5752 error = EAFNOSUPPORT;
5753 SCTP_TCB_UNLOCK(stcb);
5754 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5760 net->port = encaps->sue_port;
5762 stcb->asoc.port = encaps->sue_port;
5764 SCTP_TCB_UNLOCK(stcb);
5766 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5767 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5768 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
5769 SCTP_INP_WLOCK(inp);
5770 inp->sctp_ep.port = encaps->sue_port;
5771 SCTP_INP_WUNLOCK(inp);
5773 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5780 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
5781 error = ENOPROTOOPT;
5783 } /* end switch (opt) */
5788 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
5790 void *optval = NULL;
5795 if (sopt->sopt_level != IPPROTO_SCTP) {
5796 /* wrong proto level... send back up to IP */
5798 if (INP_CHECK_SOCKAF(so, AF_INET6))
5799 error = ip6_ctloutput(so, sopt);
5801 #if defined(INET) && defined(INET6)
5805 error = ip_ctloutput(so, sopt);
5809 optsize = sopt->sopt_valsize;
5811 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
5812 if (optval == NULL) {
5813 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
5816 error = sooptcopyin(sopt, optval, optsize, optsize);
5818 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5822 p = (void *)sopt->sopt_td;
5823 if (sopt->sopt_dir == SOPT_SET) {
5824 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
5825 } else if (sopt->sopt_dir == SOPT_GET) {
5826 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
5828 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5831 if ((error == 0) && (optval != NULL)) {
5832 error = sooptcopyout(sopt, optval, optsize);
5833 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5834 } else if (optval != NULL) {
5835 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5843 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
5846 int create_lock_on = 0;
5848 struct sctp_inpcb *inp;
5849 struct sctp_tcb *stcb = NULL;
5851 inp = (struct sctp_inpcb *)so->so_pcb;
5853 /* I made the same as TCP since we are not setup? */
5854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5855 return (ECONNRESET);
5858 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5861 switch (addr->sa_family) {
5865 struct sockaddr_in6 *sin6p;
5867 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
5868 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5871 sin6p = (struct sockaddr_in6 *)addr;
5872 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
5873 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5882 struct sockaddr_in *sinp;
5884 if (addr->sa_len != sizeof(struct sockaddr_in)) {
5885 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5888 sinp = (struct sockaddr_in *)addr;
5889 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
5890 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5897 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
5898 return (EAFNOSUPPORT);
5900 SCTP_INP_INCR_REF(inp);
5901 SCTP_ASOC_CREATE_LOCK(inp);
5905 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
5906 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
5907 /* Should I really unlock ? */
5908 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
5913 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
5914 (addr->sa_family == AF_INET6)) {
5915 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5920 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
5921 SCTP_PCB_FLAGS_UNBOUND) {
5922 /* Bind a ephemeral port */
5923 error = sctp_inpcb_bind(so, NULL, NULL, p);
5928 /* Now do we connect? */
5929 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
5930 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
5931 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5935 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
5936 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
5937 /* We are already connected AND the TCP model */
5938 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
5942 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
5943 SCTP_INP_RLOCK(inp);
5944 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5945 SCTP_INP_RUNLOCK(inp);
5948 * We increment here since sctp_findassociation_ep_addr()
5949 * will do a decrement if it finds the stcb as long as the
5950 * locked tcb (last argument) is NOT a TCB.. aka NULL.
5952 SCTP_INP_INCR_REF(inp);
5953 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
5955 SCTP_INP_DECR_REF(inp);
5957 SCTP_TCB_UNLOCK(stcb);
5961 /* Already have or am bring up an association */
5962 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
5966 vrf_id = inp->def_vrf_id;
5967 /* We are GOOD to go */
5968 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
5970 /* Gak! no memory */
5973 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
5974 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
5975 /* Set the connected flag so we can queue data */
5978 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
5979 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
5981 /* initialize authentication parameters for the assoc */
5982 sctp_initialize_auth_params(inp, stcb);
5984 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
5985 SCTP_TCB_UNLOCK(stcb);
5987 if (create_lock_on) {
5988 SCTP_ASOC_CREATE_UNLOCK(inp);
5990 SCTP_INP_DECR_REF(inp);
5997 sctp_listen(struct socket *so, int backlog, struct thread *p)
6000 * Note this module depends on the protocol processing being called
6001 * AFTER any socket level flags and backlog are applied to the
6002 * socket. The traditional way that the socket flags are applied is
6003 * AFTER protocol processing. We have made a change to the
6004 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
6005 * place if the socket API for SCTP is to work properly.
6009 struct sctp_inpcb *inp;
6011 inp = (struct sctp_inpcb *)so->so_pcb;
6013 /* I made the same as TCP since we are not setup? */
6014 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6015 return (ECONNRESET);
6017 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
6018 /* See if we have a listener */
6019 struct sctp_inpcb *tinp;
6020 union sctp_sockstore store, *sp;
6023 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
6025 struct sctp_laddr *laddr;
6027 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6028 memcpy(&store, &laddr->ifa->address, sizeof(store));
6029 switch (sp->sa.sa_family) {
6032 sp->sin.sin_port = inp->sctp_lport;
6037 sp->sin6.sin6_port = inp->sctp_lport;
6043 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6044 if (tinp && (tinp != inp) &&
6045 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6046 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6047 (tinp->sctp_socket->so_qlimit)) {
6049 * we have a listener already and
6052 SCTP_INP_DECR_REF(tinp);
6053 return (EADDRINUSE);
6055 SCTP_INP_DECR_REF(tinp);
6059 /* Setup a local addr bound all */
6060 memset(&store, 0, sizeof(store));
6061 switch (sp->sa.sa_family) {
6064 store.sin.sin_port = inp->sctp_lport;
6069 sp->sin6.sin6_port = inp->sctp_lport;
6076 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
6077 store.sa.sa_family = AF_INET6;
6078 store.sa.sa_len = sizeof(struct sockaddr_in6);
6082 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
6083 store.sa.sa_family = AF_INET;
6084 store.sa.sa_len = sizeof(struct sockaddr_in);
6087 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6088 if (tinp && (tinp != inp) &&
6089 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6090 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6091 (tinp->sctp_socket->so_qlimit)) {
6093 * we have a listener already and its not
6096 SCTP_INP_DECR_REF(tinp);
6097 return (EADDRINUSE);
6099 SCTP_INP_DECR_REF(inp);
6103 SCTP_INP_RLOCK(inp);
6104 #ifdef SCTP_LOCK_LOGGING
6105 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
6106 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
6110 error = solisten_proto_check(so);
6113 SCTP_INP_RUNLOCK(inp);
6116 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
6117 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
6119 * The unlucky case - We are in the tcp pool with this guy.
6120 * - Someone else is in the main inp slot. - We must move
6121 * this guy (the listener) to the main slot - We must then
6122 * move the guy that was listener to the TCP Pool.
6124 if (sctp_swap_inpcb_for_listen(inp)) {
6128 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6129 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6130 /* We are already connected AND the TCP model */
6132 SCTP_INP_RUNLOCK(inp);
6134 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6135 return (EADDRINUSE);
6137 SCTP_INP_RUNLOCK(inp);
6138 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
6139 /* We must do a bind. */
6141 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
6142 /* bind error, probably perm */
6147 /* It appears for 7.0 and on, we must always call this. */
6148 solisten_proto(so, backlog);
6149 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6150 /* remove the ACCEPTCONN flag for one-to-many sockets */
6151 so->so_options &= ~SO_ACCEPTCONN;
6154 /* turning off listen */
6155 so->so_options &= ~SO_ACCEPTCONN;
6161 static int sctp_defered_wakeup_cnt = 0;
6164 sctp_accept(struct socket *so, struct sockaddr **addr)
6166 struct sctp_tcb *stcb;
6167 struct sctp_inpcb *inp;
6168 union sctp_sockstore store;
6174 inp = (struct sctp_inpcb *)so->so_pcb;
6177 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6178 return (ECONNRESET);
6180 SCTP_INP_RLOCK(inp);
6181 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6182 SCTP_INP_RUNLOCK(inp);
6183 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
6184 return (EOPNOTSUPP);
6186 if (so->so_state & SS_ISDISCONNECTED) {
6187 SCTP_INP_RUNLOCK(inp);
6188 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
6189 return (ECONNABORTED);
6191 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6193 SCTP_INP_RUNLOCK(inp);
6194 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6195 return (ECONNRESET);
6197 SCTP_TCB_LOCK(stcb);
6198 SCTP_INP_RUNLOCK(inp);
6199 store = stcb->asoc.primary_destination->ro._l_addr;
6200 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
6201 SCTP_TCB_UNLOCK(stcb);
6202 switch (store.sa.sa_family) {
6206 struct sockaddr_in *sin;
6208 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6211 sin->sin_family = AF_INET;
6212 sin->sin_len = sizeof(*sin);
6213 sin->sin_port = ((struct sockaddr_in *)&store)->sin_port;
6214 sin->sin_addr = ((struct sockaddr_in *)&store)->sin_addr;
6215 *addr = (struct sockaddr *)sin;
6222 struct sockaddr_in6 *sin6;
6224 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
6227 sin6->sin6_family = AF_INET6;
6228 sin6->sin6_len = sizeof(*sin6);
6229 sin6->sin6_port = ((struct sockaddr_in6 *)&store)->sin6_port;
6231 sin6->sin6_addr = ((struct sockaddr_in6 *)&store)->sin6_addr;
6232 if ((error = sa6_recoverscope(sin6)) != 0) {
6233 SCTP_FREE_SONAME(sin6);
6236 *addr = (struct sockaddr *)sin6;
6244 /* Wake any delayed sleep action */
6245 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
6246 SCTP_INP_WLOCK(inp);
6247 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
6248 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
6249 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
6250 SCTP_INP_WUNLOCK(inp);
6251 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
6252 if (sowriteable(inp->sctp_socket)) {
6253 sowwakeup_locked(inp->sctp_socket);
6255 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
6257 SCTP_INP_WLOCK(inp);
6259 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
6260 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
6261 SCTP_INP_WUNLOCK(inp);
6262 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
6263 if (soreadable(inp->sctp_socket)) {
6264 sctp_defered_wakeup_cnt++;
6265 sorwakeup_locked(inp->sctp_socket);
6267 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
6269 SCTP_INP_WLOCK(inp);
6271 SCTP_INP_WUNLOCK(inp);
6273 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
6274 SCTP_TCB_LOCK(stcb);
6275 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
6282 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
6284 struct sockaddr_in *sin;
6286 struct sctp_inpcb *inp;
6287 struct sctp_ifa *sctp_ifa;
6290 * Do the malloc first in case it blocks.
6292 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6295 sin->sin_family = AF_INET;
6296 sin->sin_len = sizeof(*sin);
6297 inp = (struct sctp_inpcb *)so->so_pcb;
6299 SCTP_FREE_SONAME(sin);
6300 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6301 return (ECONNRESET);
6303 SCTP_INP_RLOCK(inp);
6304 sin->sin_port = inp->sctp_lport;
6305 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
6306 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6307 struct sctp_tcb *stcb;
6308 struct sockaddr_in *sin_a;
6309 struct sctp_nets *net;
6312 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6318 SCTP_TCB_LOCK(stcb);
6319 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6320 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6322 /* this will make coverity happy */
6325 if (sin_a->sin_family == AF_INET) {
6330 if ((!fnd) || (sin_a == NULL)) {
6332 SCTP_TCB_UNLOCK(stcb);
6335 vrf_id = inp->def_vrf_id;
6336 sctp_ifa = sctp_source_address_selection(inp,
6338 (sctp_route_t *) & net->ro,
6341 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
6342 sctp_free_ifa(sctp_ifa);
6344 SCTP_TCB_UNLOCK(stcb);
6346 /* For the bound all case you get back 0 */
6348 sin->sin_addr.s_addr = 0;
6352 /* Take the first IPv4 address in the list */
6353 struct sctp_laddr *laddr;
6356 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6357 if (laddr->ifa->address.sa.sa_family == AF_INET) {
6358 struct sockaddr_in *sin_a;
6360 sin_a = (struct sockaddr_in *)&laddr->ifa->address.sa;
6361 sin->sin_addr = sin_a->sin_addr;
6367 SCTP_FREE_SONAME(sin);
6368 SCTP_INP_RUNLOCK(inp);
6369 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6373 SCTP_INP_RUNLOCK(inp);
6374 (*addr) = (struct sockaddr *)sin;
6379 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
6381 struct sockaddr_in *sin;
6383 struct sockaddr_in *sin_a;
6384 struct sctp_inpcb *inp;
6385 struct sctp_tcb *stcb;
6386 struct sctp_nets *net;
6388 /* Do the malloc first in case it blocks. */
6389 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6392 sin->sin_family = AF_INET;
6393 sin->sin_len = sizeof(*sin);
6395 inp = (struct sctp_inpcb *)so->so_pcb;
6396 if ((inp == NULL) ||
6397 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
6398 /* UDP type and listeners will drop out here */
6399 SCTP_FREE_SONAME(sin);
6400 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
6403 SCTP_INP_RLOCK(inp);
6404 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6406 SCTP_TCB_LOCK(stcb);
6408 SCTP_INP_RUNLOCK(inp);
6410 SCTP_FREE_SONAME(sin);
6411 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6412 return (ECONNRESET);
6415 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6416 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6417 if (sin_a->sin_family == AF_INET) {
6419 sin->sin_port = stcb->rport;
6420 sin->sin_addr = sin_a->sin_addr;
6424 SCTP_TCB_UNLOCK(stcb);
6426 /* No IPv4 address */
6427 SCTP_FREE_SONAME(sin);
6428 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6431 (*addr) = (struct sockaddr *)sin;
6435 struct pr_usrreqs sctp_usrreqs = {
6436 .pru_abort = sctp_abort,
6437 .pru_accept = sctp_accept,
6438 .pru_attach = sctp_attach,
6439 .pru_bind = sctp_bind,
6440 .pru_connect = sctp_connect,
6441 .pru_control = in_control,
6442 .pru_close = sctp_close,
6443 .pru_detach = sctp_close,
6444 .pru_sopoll = sopoll_generic,
6445 .pru_flush = sctp_flush,
6446 .pru_disconnect = sctp_disconnect,
6447 .pru_listen = sctp_listen,
6448 .pru_peeraddr = sctp_peeraddr,
6449 .pru_send = sctp_sendm,
6450 .pru_shutdown = sctp_shutdown,
6451 .pru_sockaddr = sctp_ingetaddr,
6452 .pru_sosend = sctp_sosend,
6453 .pru_soreceive = sctp_soreceive