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);
183 totsz = ntohs(ip->ip_len);
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_NOWAIT, 1, MT_DATA);
766 struct sctp_paramhdr *ph;
768 ph = mtod(err, struct sctp_paramhdr *);
769 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
770 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
771 ph->param_length = htons(SCTP_BUF_LEN(err));
773 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
774 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
776 SCTP_INP_RUNLOCK(inp);
777 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
778 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
779 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
781 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
782 /* No unlock tcb assoc is gone */
785 if (TAILQ_EMPTY(&asoc->send_queue) &&
786 TAILQ_EMPTY(&asoc->sent_queue) &&
787 (asoc->stream_queue_cnt == 0)) {
788 /* there is nothing queued to send, so done */
789 if (asoc->locked_on_sending) {
792 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
793 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
794 /* only send SHUTDOWN 1st time thru */
795 struct sctp_nets *netp;
797 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
798 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
799 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
801 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
802 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
803 sctp_stop_timers_for_shutdown(stcb);
804 if (stcb->asoc.alternate) {
805 netp = stcb->asoc.alternate;
807 netp = stcb->asoc.primary_destination;
809 sctp_send_shutdown(stcb, netp);
810 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
811 stcb->sctp_ep, stcb, netp);
812 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
813 stcb->sctp_ep, stcb, netp);
814 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
818 * we still got (or just got) data to send,
819 * so set SHUTDOWN_PENDING
822 * XXX sockets draft says that SCTP_EOF
823 * should be sent with no data. currently,
824 * we will allow user data to be sent first
825 * and move to SHUTDOWN-PENDING
827 struct sctp_nets *netp;
829 if (stcb->asoc.alternate) {
830 netp = stcb->asoc.alternate;
832 netp = stcb->asoc.primary_destination;
835 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
836 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
838 if (asoc->locked_on_sending) {
839 /* Locked to send out the data */
840 struct sctp_stream_queue_pending *sp;
842 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
844 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
845 asoc->locked_on_sending->stream_no);
847 if ((sp->length == 0) && (sp->msg_is_complete == 0))
848 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
851 if (TAILQ_EMPTY(&asoc->send_queue) &&
852 TAILQ_EMPTY(&asoc->sent_queue) &&
853 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
857 op_err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr),
858 0, M_NOWAIT, 1, MT_DATA);
864 struct sctp_paramhdr *ph;
866 SCTP_BUF_LEN(op_err) = sizeof(struct sctp_paramhdr);
867 ph = mtod(op_err, struct sctp_paramhdr *);
868 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
869 ph->param_length = htons(SCTP_BUF_LEN(op_err));
871 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
872 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
873 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
874 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
875 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
876 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
878 SCTP_INP_RUNLOCK(inp);
879 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
882 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
885 soisdisconnecting(so);
886 SCTP_TCB_UNLOCK(stcb);
887 SCTP_INP_RUNLOCK(inp);
892 /* UDP model does not support this */
893 SCTP_INP_RUNLOCK(inp);
894 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
900 sctp_flush(struct socket *so, int how)
903 * We will just clear out the values and let subsequent close clear
904 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
905 * they will not be able to read the data, the socket will block
906 * that from happening.
908 struct sctp_inpcb *inp;
910 inp = (struct sctp_inpcb *)so->so_pcb;
912 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
916 /* For the 1 to many model this does nothing */
917 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
918 SCTP_INP_RUNLOCK(inp);
921 SCTP_INP_RUNLOCK(inp);
922 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
924 * First make sure the sb will be happy, we don't use these
925 * except maybe the count
928 SCTP_INP_READ_LOCK(inp);
929 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
930 SCTP_INP_READ_UNLOCK(inp);
931 SCTP_INP_WUNLOCK(inp);
932 so->so_rcv.sb_cc = 0;
933 so->so_rcv.sb_mbcnt = 0;
934 so->so_rcv.sb_mb = NULL;
936 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
938 * First make sure the sb will be happy, we don't use these
939 * except maybe the count
941 so->so_snd.sb_cc = 0;
942 so->so_snd.sb_mbcnt = 0;
943 so->so_snd.sb_mb = NULL;
950 sctp_shutdown(struct socket *so)
952 struct sctp_inpcb *inp;
954 inp = (struct sctp_inpcb *)so->so_pcb;
956 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
960 /* For UDP model this is a invalid call */
961 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
962 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
963 /* Restore the flags that the soshutdown took away. */
964 SOCKBUF_LOCK(&so->so_rcv);
965 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
966 SOCKBUF_UNLOCK(&so->so_rcv);
967 /* This proc will wakeup for read and do nothing (I hope) */
968 SCTP_INP_RUNLOCK(inp);
969 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
973 * Ok if we reach here its the TCP model and it is either a SHUT_WR
974 * or SHUT_RDWR. This means we put the shutdown flag against it.
977 struct sctp_tcb *stcb;
978 struct sctp_association *asoc;
981 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
982 SCTP_INP_RUNLOCK(inp);
987 stcb = LIST_FIRST(&inp->sctp_asoc_list);
990 * Ok we hit the case that the shutdown call was
991 * made after an abort or something. Nothing to do
994 SCTP_INP_RUNLOCK(inp);
999 if (TAILQ_EMPTY(&asoc->send_queue) &&
1000 TAILQ_EMPTY(&asoc->sent_queue) &&
1001 (asoc->stream_queue_cnt == 0)) {
1002 if (asoc->locked_on_sending) {
1005 /* there is nothing queued to send, so I'm done... */
1006 if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) {
1007 /* only send SHUTDOWN the first time through */
1008 struct sctp_nets *netp;
1010 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
1011 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
1012 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1014 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
1015 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
1016 sctp_stop_timers_for_shutdown(stcb);
1017 if (stcb->asoc.alternate) {
1018 netp = stcb->asoc.alternate;
1020 netp = stcb->asoc.primary_destination;
1022 sctp_send_shutdown(stcb, netp);
1023 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1024 stcb->sctp_ep, stcb, netp);
1025 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1026 stcb->sctp_ep, stcb, netp);
1027 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
1031 * we still got (or just got) data to send, so set
1034 struct sctp_nets *netp;
1036 if (stcb->asoc.alternate) {
1037 netp = stcb->asoc.alternate;
1039 netp = stcb->asoc.primary_destination;
1042 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1043 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
1046 if (asoc->locked_on_sending) {
1047 /* Locked to send out the data */
1048 struct sctp_stream_queue_pending *sp;
1050 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
1052 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
1053 asoc->locked_on_sending->stream_no);
1055 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
1056 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
1060 if (TAILQ_EMPTY(&asoc->send_queue) &&
1061 TAILQ_EMPTY(&asoc->sent_queue) &&
1062 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1063 struct mbuf *op_err;
1066 op_err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr),
1067 0, M_NOWAIT, 1, MT_DATA);
1069 /* Fill in the user initiated abort */
1070 struct sctp_paramhdr *ph;
1072 SCTP_BUF_LEN(op_err) = sizeof(struct sctp_paramhdr);
1073 ph = mtod(op_err, struct sctp_paramhdr *);
1074 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
1075 ph->param_length = htons(SCTP_BUF_LEN(op_err));
1077 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
1078 sctp_abort_an_association(stcb->sctp_ep, stcb,
1079 op_err, SCTP_SO_LOCKED);
1082 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1085 SCTP_TCB_UNLOCK(stcb);
1088 SCTP_INP_RUNLOCK(inp);
1093 * copies a "user" presentable address and removes embedded scope, etc.
1094 * returns 0 on success, 1 on error
1097 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1100 struct sockaddr_in6 lsa6;
1102 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1105 memcpy(ss, sa, sa->sa_len);
1112 * NOTE: assumes addr lock is held
1115 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1116 struct sctp_tcb *stcb,
1118 struct sockaddr_storage *sas,
1121 struct sctp_ifn *sctp_ifn;
1122 struct sctp_ifa *sctp_ifa;
1127 int ipv4_local_scope, ipv4_addr_legal;
1131 int local_scope, site_scope, ipv6_addr_legal;
1134 struct sctp_vrf *vrf;
1141 /* Turn on all the appropriate scope */
1142 loopback_scope = stcb->asoc.scope.loopback_scope;
1144 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1145 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1148 local_scope = stcb->asoc.scope.local_scope;
1149 site_scope = stcb->asoc.scope.site_scope;
1150 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1153 /* Use generic values for endpoints. */
1156 ipv4_local_scope = 1;
1162 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1164 ipv6_addr_legal = 1;
1167 if (SCTP_IPV6_V6ONLY(inp)) {
1168 ipv4_addr_legal = 0;
1170 ipv4_addr_legal = 1;
1175 ipv6_addr_legal = 0;
1178 ipv4_addr_legal = 1;
1182 vrf = sctp_find_vrf(vrf_id);
1186 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1187 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1188 if ((loopback_scope == 0) &&
1189 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1190 /* Skip loopback if loopback_scope not set */
1193 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1196 * For the BOUND-ALL case, the list
1197 * associated with a TCB is Always
1198 * considered a reverse list.. i.e.
1199 * it lists addresses that are NOT
1200 * part of the association. If this
1201 * is one of those we must skip it.
1203 if (sctp_is_addr_restricted(stcb,
1208 switch (sctp_ifa->address.sa.sa_family) {
1211 if (ipv4_addr_legal) {
1212 struct sockaddr_in *sin;
1214 sin = (struct sockaddr_in *)&sctp_ifa->address.sa;
1215 if (sin->sin_addr.s_addr == 0) {
1223 if ((ipv4_local_scope == 0) &&
1224 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1228 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1229 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1230 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1231 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1232 actual += sizeof(struct sockaddr_in6);
1235 memcpy(sas, sin, sizeof(*sin));
1236 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1237 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1238 actual += sizeof(*sin);
1242 if (actual >= limit) {
1252 if (ipv6_addr_legal) {
1253 struct sockaddr_in6 *sin6;
1255 sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sa;
1256 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1264 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1265 if (local_scope == 0)
1267 if (sin6->sin6_scope_id == 0) {
1268 if (sa6_recoverscope(sin6) != 0)
1286 if ((site_scope == 0) &&
1287 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1290 memcpy(sas, sin6, sizeof(*sin6));
1291 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1292 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1293 actual += sizeof(*sin6);
1294 if (actual >= limit) {
1309 struct sctp_laddr *laddr;
1311 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1313 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1317 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1319 switch (laddr->ifa->address.sa.sa_family) {
1322 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1327 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1334 sas = (struct sockaddr_storage *)((caddr_t)sas +
1335 laddr->ifa->address.sa.sa_len);
1336 actual += laddr->ifa->address.sa.sa_len;
1337 if (actual >= limit) {
1346 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1347 struct sctp_tcb *stcb,
1349 struct sockaddr_storage *sas)
1353 SCTP_IPI_ADDR_RLOCK();
1354 /* fill up addresses for the endpoint's default vrf */
1355 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1357 SCTP_IPI_ADDR_RUNLOCK();
1362 * NOTE: assumes addr lock is held
1365 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1368 struct sctp_vrf *vrf = NULL;
1371 * In both sub-set bound an bound_all cases we return the MAXIMUM
1372 * number of addresses that you COULD get. In reality the sub-set
1373 * bound may have an exclusion list for a given TCB OR in the
1374 * bound-all case a TCB may NOT include the loopback or other
1375 * addresses as well.
1377 vrf = sctp_find_vrf(vrf_id);
1381 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1382 struct sctp_ifn *sctp_ifn;
1383 struct sctp_ifa *sctp_ifa;
1385 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1386 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1387 /* Count them if they are the right type */
1388 switch (sctp_ifa->address.sa.sa_family) {
1391 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1392 cnt += sizeof(struct sockaddr_in6);
1394 cnt += sizeof(struct sockaddr_in);
1399 cnt += sizeof(struct sockaddr_in6);
1408 struct sctp_laddr *laddr;
1410 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1411 switch (laddr->ifa->address.sa.sa_family) {
1414 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1415 cnt += sizeof(struct sockaddr_in6);
1417 cnt += sizeof(struct sockaddr_in);
1422 cnt += sizeof(struct sockaddr_in6);
1434 sctp_count_max_addresses(struct sctp_inpcb *inp)
1438 SCTP_IPI_ADDR_RLOCK();
1439 /* count addresses for the endpoint's default VRF */
1440 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1441 SCTP_IPI_ADDR_RUNLOCK();
1446 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1447 size_t optsize, void *p, int delay)
1450 int creat_lock_on = 0;
1451 struct sctp_tcb *stcb = NULL;
1452 struct sockaddr *sa;
1453 int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1455 int bad_addresses = 0;
1458 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1460 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1461 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1462 /* We are already connected AND the TCP model */
1463 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1464 return (EADDRINUSE);
1466 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1467 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1468 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1471 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1472 SCTP_INP_RLOCK(inp);
1473 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1474 SCTP_INP_RUNLOCK(inp);
1477 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1480 SCTP_INP_INCR_REF(inp);
1481 SCTP_ASOC_CREATE_LOCK(inp);
1483 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1484 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1485 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1489 totaddrp = (int *)optval;
1490 totaddr = *totaddrp;
1491 sa = (struct sockaddr *)(totaddrp + 1);
1492 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (optsize - sizeof(int)), &bad_addresses);
1493 if ((stcb != NULL) || bad_addresses) {
1494 /* Already have or am bring up an association */
1495 SCTP_ASOC_CREATE_UNLOCK(inp);
1498 SCTP_TCB_UNLOCK(stcb);
1499 if (bad_addresses == 0) {
1500 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1506 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1511 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1513 struct in6pcb *inp6;
1515 inp6 = (struct in6pcb *)inp;
1516 if (SCTP_IPV6_V6ONLY(inp6)) {
1518 * if IPV6_V6ONLY flag, ignore connections destined
1519 * to a v4 addr or v4-mapped addr
1521 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1527 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1528 SCTP_PCB_FLAGS_UNBOUND) {
1529 /* Bind a ephemeral port */
1530 error = sctp_inpcb_bind(so, NULL, NULL, p);
1535 /* FIX ME: do we want to pass in a vrf on the connect call? */
1536 vrf_id = inp->def_vrf_id;
1539 /* We are GOOD to go */
1540 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1544 /* Gak! no memory */
1547 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1548 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1549 /* Set the connected flag so we can queue data */
1552 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1553 /* move to second address */
1554 switch (sa->sa_family) {
1557 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1562 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1570 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1571 /* Fill in the return id */
1573 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1576 a_id = (sctp_assoc_t *) optval;
1577 *a_id = sctp_get_associd(stcb);
1579 /* initialize authentication parameters for the assoc */
1580 sctp_initialize_auth_params(inp, stcb);
1583 /* doing delayed connection */
1584 stcb->asoc.delayed_connection = 1;
1585 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1587 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1588 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1590 SCTP_TCB_UNLOCK(stcb);
1591 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1592 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1593 /* Set the connected flag so we can queue data */
1597 if (creat_lock_on) {
1598 SCTP_ASOC_CREATE_UNLOCK(inp);
1600 SCTP_INP_DECR_REF(inp);
1604 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1605 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1606 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1607 SCTP_INP_RLOCK(inp); \
1608 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1610 SCTP_TCB_LOCK(stcb); \
1612 SCTP_INP_RUNLOCK(inp); \
1613 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1614 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1615 if (stcb == NULL) { \
1616 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1626 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1627 if (size < sizeof(type)) { \
1628 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1632 destp = (type *)srcp; \
1637 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1640 struct sctp_inpcb *inp = NULL;
1642 struct sctp_tcb *stcb = NULL;
1644 if (optval == NULL) {
1645 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1648 inp = (struct sctp_inpcb *)so->so_pcb;
1650 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1657 case SCTP_AUTOCLOSE:
1658 case SCTP_EXPLICIT_EOR:
1659 case SCTP_AUTO_ASCONF:
1660 case SCTP_DISABLE_FRAGMENTS:
1661 case SCTP_I_WANT_MAPPED_V4_ADDR:
1662 case SCTP_USE_EXT_RCVINFO:
1663 SCTP_INP_RLOCK(inp);
1665 case SCTP_DISABLE_FRAGMENTS:
1666 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1668 case SCTP_I_WANT_MAPPED_V4_ADDR:
1669 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1671 case SCTP_AUTO_ASCONF:
1672 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1673 /* only valid for bound all sockets */
1674 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1676 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1681 case SCTP_EXPLICIT_EOR:
1682 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1685 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1687 case SCTP_USE_EXT_RCVINFO:
1688 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1690 case SCTP_AUTOCLOSE:
1691 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1692 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1698 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1699 error = ENOPROTOOPT;
1700 } /* end switch (sopt->sopt_name) */
1701 if (*optsize < sizeof(val)) {
1702 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1706 SCTP_INP_RUNLOCK(inp);
1708 /* return the option value */
1709 *(int *)optval = val;
1710 *optsize = sizeof(val);
1713 case SCTP_GET_PACKET_LOG:
1715 #ifdef SCTP_PACKET_LOGGING
1719 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1720 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1723 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1728 case SCTP_REUSE_PORT:
1732 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1733 /* Can't do this for a 1-m socket */
1737 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1738 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1739 *optsize = sizeof(uint32_t);
1742 case SCTP_PARTIAL_DELIVERY_POINT:
1746 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1747 *value = inp->partial_delivery_point;
1748 *optsize = sizeof(uint32_t);
1751 case SCTP_FRAGMENT_INTERLEAVE:
1755 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1756 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1757 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1758 *value = SCTP_FRAG_LEVEL_2;
1760 *value = SCTP_FRAG_LEVEL_1;
1763 *value = SCTP_FRAG_LEVEL_0;
1765 *optsize = sizeof(uint32_t);
1768 case SCTP_CMT_ON_OFF:
1770 struct sctp_assoc_value *av;
1772 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1773 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1775 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1776 SCTP_TCB_UNLOCK(stcb);
1778 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1779 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1780 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1781 SCTP_INP_RLOCK(inp);
1782 av->assoc_value = inp->sctp_cmt_on_off;
1783 SCTP_INP_RUNLOCK(inp);
1785 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1790 *optsize = sizeof(struct sctp_assoc_value);
1794 case SCTP_PLUGGABLE_CC:
1796 struct sctp_assoc_value *av;
1798 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1799 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1801 av->assoc_value = stcb->asoc.congestion_control_module;
1802 SCTP_TCB_UNLOCK(stcb);
1804 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1805 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1806 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1807 SCTP_INP_RLOCK(inp);
1808 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1809 SCTP_INP_RUNLOCK(inp);
1811 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1816 *optsize = sizeof(struct sctp_assoc_value);
1820 case SCTP_CC_OPTION:
1822 struct sctp_cc_option *cc_opt;
1824 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1825 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1829 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1832 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1833 *optsize = sizeof(struct sctp_cc_option);
1835 SCTP_TCB_UNLOCK(stcb);
1839 case SCTP_PLUGGABLE_SS:
1841 struct sctp_assoc_value *av;
1843 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1844 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1846 av->assoc_value = stcb->asoc.stream_scheduling_module;
1847 SCTP_TCB_UNLOCK(stcb);
1849 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1850 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1851 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1852 SCTP_INP_RLOCK(inp);
1853 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1854 SCTP_INP_RUNLOCK(inp);
1856 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1861 *optsize = sizeof(struct sctp_assoc_value);
1867 struct sctp_stream_value *av;
1869 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1870 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1872 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1873 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1874 &av->stream_value) < 0)) {
1875 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1878 *optsize = sizeof(struct sctp_stream_value);
1880 SCTP_TCB_UNLOCK(stcb);
1883 * Can't get stream value without
1886 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1891 case SCTP_GET_ADDR_LEN:
1893 struct sctp_assoc_value *av;
1895 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1898 if (av->assoc_value == AF_INET) {
1899 av->assoc_value = sizeof(struct sockaddr_in);
1904 if (av->assoc_value == AF_INET6) {
1905 av->assoc_value = sizeof(struct sockaddr_in6);
1910 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1912 *optsize = sizeof(struct sctp_assoc_value);
1916 case SCTP_GET_ASSOC_NUMBER:
1918 uint32_t *value, cnt;
1920 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1922 SCTP_INP_RLOCK(inp);
1923 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1926 SCTP_INP_RUNLOCK(inp);
1928 *optsize = sizeof(uint32_t);
1931 case SCTP_GET_ASSOC_ID_LIST:
1933 struct sctp_assoc_ids *ids;
1934 unsigned int at, limit;
1936 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1938 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1939 SCTP_INP_RLOCK(inp);
1940 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1942 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1945 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1949 SCTP_INP_RUNLOCK(inp);
1951 ids->gaids_number_of_ids = at;
1952 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1958 struct sctp_assoc_value *av;
1960 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1961 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1964 av->assoc_value = stcb->asoc.context;
1965 SCTP_TCB_UNLOCK(stcb);
1967 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1968 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1969 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1970 SCTP_INP_RLOCK(inp);
1971 av->assoc_value = inp->sctp_context;
1972 SCTP_INP_RUNLOCK(inp);
1974 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1979 *optsize = sizeof(struct sctp_assoc_value);
1985 uint32_t *default_vrfid;
1987 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1988 *default_vrfid = inp->def_vrf_id;
1989 *optsize = sizeof(uint32_t);
1992 case SCTP_GET_ASOC_VRF:
1994 struct sctp_assoc_value *id;
1996 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1997 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
2000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2002 id->assoc_value = stcb->asoc.vrf_id;
2003 *optsize = sizeof(struct sctp_assoc_value);
2007 case SCTP_GET_VRF_IDS:
2009 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
2013 case SCTP_GET_NONCE_VALUES:
2015 struct sctp_get_nonce_values *gnv;
2017 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
2018 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
2021 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
2022 gnv->gn_local_tag = stcb->asoc.my_vtag;
2023 SCTP_TCB_UNLOCK(stcb);
2024 *optsize = sizeof(struct sctp_get_nonce_values);
2026 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2031 case SCTP_DELAYED_SACK:
2033 struct sctp_sack_info *sack;
2035 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2036 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2038 sack->sack_delay = stcb->asoc.delayed_ack;
2039 sack->sack_freq = stcb->asoc.sack_freq;
2040 SCTP_TCB_UNLOCK(stcb);
2042 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2043 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2044 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2045 SCTP_INP_RLOCK(inp);
2046 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2047 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2048 SCTP_INP_RUNLOCK(inp);
2050 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2055 *optsize = sizeof(struct sctp_sack_info);
2059 case SCTP_GET_SNDBUF_USE:
2061 struct sctp_sockstat *ss;
2063 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2064 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2067 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2068 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2069 stcb->asoc.size_on_all_streams);
2070 SCTP_TCB_UNLOCK(stcb);
2071 *optsize = sizeof(struct sctp_sockstat);
2073 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2078 case SCTP_MAX_BURST:
2080 struct sctp_assoc_value *av;
2082 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2083 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2086 av->assoc_value = stcb->asoc.max_burst;
2087 SCTP_TCB_UNLOCK(stcb);
2089 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2090 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2091 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2092 SCTP_INP_RLOCK(inp);
2093 av->assoc_value = inp->sctp_ep.max_burst;
2094 SCTP_INP_RUNLOCK(inp);
2096 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2101 *optsize = sizeof(struct sctp_assoc_value);
2107 struct sctp_assoc_value *av;
2110 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2111 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2114 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2115 SCTP_TCB_UNLOCK(stcb);
2117 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2118 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2119 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2120 SCTP_INP_RLOCK(inp);
2121 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2122 ovh = SCTP_MED_OVERHEAD;
2124 ovh = SCTP_MED_V4_OVERHEAD;
2126 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2127 av->assoc_value = 0;
2129 av->assoc_value = inp->sctp_frag_point - ovh;
2130 SCTP_INP_RUNLOCK(inp);
2132 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2137 *optsize = sizeof(struct sctp_assoc_value);
2141 case SCTP_GET_STAT_LOG:
2142 error = sctp_fill_stat_log(optval, optsize);
2146 struct sctp_event_subscribe *events;
2148 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2149 memset(events, 0, sizeof(struct sctp_event_subscribe));
2150 SCTP_INP_RLOCK(inp);
2151 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2152 events->sctp_data_io_event = 1;
2154 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2155 events->sctp_association_event = 1;
2157 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2158 events->sctp_address_event = 1;
2160 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2161 events->sctp_send_failure_event = 1;
2163 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2164 events->sctp_peer_error_event = 1;
2166 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2167 events->sctp_shutdown_event = 1;
2169 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2170 events->sctp_partial_delivery_event = 1;
2172 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2173 events->sctp_adaptation_layer_event = 1;
2175 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2176 events->sctp_authentication_event = 1;
2178 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2179 events->sctp_sender_dry_event = 1;
2181 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2182 events->sctp_stream_reset_event = 1;
2183 SCTP_INP_RUNLOCK(inp);
2184 *optsize = sizeof(struct sctp_event_subscribe);
2187 case SCTP_ADAPTATION_LAYER:
2191 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2193 SCTP_INP_RLOCK(inp);
2194 *value = inp->sctp_ep.adaptation_layer_indicator;
2195 SCTP_INP_RUNLOCK(inp);
2196 *optsize = sizeof(uint32_t);
2199 case SCTP_SET_INITIAL_DBG_SEQ:
2203 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2204 SCTP_INP_RLOCK(inp);
2205 *value = inp->sctp_ep.initial_sequence_debug;
2206 SCTP_INP_RUNLOCK(inp);
2207 *optsize = sizeof(uint32_t);
2210 case SCTP_GET_LOCAL_ADDR_SIZE:
2214 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2215 SCTP_INP_RLOCK(inp);
2216 *value = sctp_count_max_addresses(inp);
2217 SCTP_INP_RUNLOCK(inp);
2218 *optsize = sizeof(uint32_t);
2221 case SCTP_GET_REMOTE_ADDR_SIZE:
2225 struct sctp_nets *net;
2227 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2228 /* FIXME MT: change to sctp_assoc_value? */
2229 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2233 /* Count the sizes */
2234 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2235 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2236 size += sizeof(struct sockaddr_in6);
2238 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2241 size += sizeof(struct sockaddr_in);
2246 size += sizeof(struct sockaddr_in6);
2254 SCTP_TCB_UNLOCK(stcb);
2255 *value = (uint32_t) size;
2256 *optsize = sizeof(uint32_t);
2258 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2263 case SCTP_GET_PEER_ADDRESSES:
2265 * Get the address information, an array is passed in to
2266 * fill up we pack it.
2270 struct sockaddr_storage *sas;
2271 struct sctp_nets *net;
2272 struct sctp_getaddresses *saddr;
2274 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2275 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2278 left = (*optsize) - sizeof(struct sctp_getaddresses);
2279 *optsize = sizeof(struct sctp_getaddresses);
2280 sas = (struct sockaddr_storage *)&saddr->addr[0];
2282 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2283 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2284 cpsz = sizeof(struct sockaddr_in6);
2286 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2289 cpsz = sizeof(struct sockaddr_in);
2294 cpsz = sizeof(struct sockaddr_in6);
2306 /* not enough room. */
2309 #if defined(INET) && defined(INET6)
2310 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2311 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
2312 /* Must map the address */
2313 in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
2314 (struct sockaddr_in6 *)sas);
2317 memcpy(sas, &net->ro._l_addr, cpsz);
2318 #if defined(INET) && defined(INET6)
2321 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2323 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2327 SCTP_TCB_UNLOCK(stcb);
2329 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2334 case SCTP_GET_LOCAL_ADDRESSES:
2336 size_t limit, actual;
2337 struct sockaddr_storage *sas;
2338 struct sctp_getaddresses *saddr;
2340 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2341 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2343 sas = (struct sockaddr_storage *)&saddr->addr[0];
2344 limit = *optsize - sizeof(sctp_assoc_t);
2345 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2347 SCTP_TCB_UNLOCK(stcb);
2349 *optsize = sizeof(struct sockaddr_storage) + actual;
2352 case SCTP_PEER_ADDR_PARAMS:
2354 struct sctp_paddrparams *paddrp;
2355 struct sctp_nets *net;
2357 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2358 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2362 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2365 * We increment here since
2366 * sctp_findassociation_ep_addr() wil do a
2367 * decrement if it finds the stcb as long as
2368 * the locked tcb (last argument) is NOT a
2371 SCTP_INP_INCR_REF(inp);
2372 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddrp->spp_address, &net, NULL, NULL);
2374 SCTP_INP_DECR_REF(inp);
2377 if (stcb && (net == NULL)) {
2378 struct sockaddr *sa;
2380 sa = (struct sockaddr *)&paddrp->spp_address;
2382 if (sa->sa_family == AF_INET) {
2383 struct sockaddr_in *sin;
2385 sin = (struct sockaddr_in *)sa;
2386 if (sin->sin_addr.s_addr) {
2388 SCTP_TCB_UNLOCK(stcb);
2389 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2395 if (sa->sa_family == AF_INET6) {
2396 struct sockaddr_in6 *sin6;
2398 sin6 = (struct sockaddr_in6 *)sa;
2399 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2401 SCTP_TCB_UNLOCK(stcb);
2402 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2408 error = EAFNOSUPPORT;
2409 SCTP_TCB_UNLOCK(stcb);
2410 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2415 /* Applies to the specific association */
2416 paddrp->spp_flags = 0;
2420 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2421 ovh = SCTP_MED_OVERHEAD;
2423 ovh = SCTP_MED_V4_OVERHEAD;
2426 paddrp->spp_hbinterval = net->heart_beat_delay;
2427 paddrp->spp_pathmaxrxt = net->failure_threshold;
2428 paddrp->spp_pathmtu = net->mtu - ovh;
2429 /* get flags for HB */
2430 if (net->dest_state & SCTP_ADDR_NOHB) {
2431 paddrp->spp_flags |= SPP_HB_DISABLE;
2433 paddrp->spp_flags |= SPP_HB_ENABLE;
2435 /* get flags for PMTU */
2436 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2437 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2439 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2441 if (net->dscp & 0x01) {
2442 paddrp->spp_dscp = net->dscp & 0xfc;
2443 paddrp->spp_flags |= SPP_DSCP;
2446 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2447 (net->flowlabel & 0x80000000)) {
2448 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2449 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2454 * No destination so return default
2457 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2458 paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
2459 if (stcb->asoc.default_dscp & 0x01) {
2460 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2461 paddrp->spp_flags |= SPP_DSCP;
2464 if (stcb->asoc.default_flowlabel & 0x80000000) {
2465 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2466 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2469 /* default settings should be these */
2470 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2471 paddrp->spp_flags |= SPP_HB_DISABLE;
2473 paddrp->spp_flags |= SPP_HB_ENABLE;
2475 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2476 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2478 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2480 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2482 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2483 SCTP_TCB_UNLOCK(stcb);
2485 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2486 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2487 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2488 /* Use endpoint defaults */
2489 SCTP_INP_RLOCK(inp);
2490 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2491 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2492 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2493 /* get inp's default */
2494 if (inp->sctp_ep.default_dscp & 0x01) {
2495 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2496 paddrp->spp_flags |= SPP_DSCP;
2499 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2500 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2501 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2502 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2505 /* can't return this */
2506 paddrp->spp_pathmtu = 0;
2508 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2509 paddrp->spp_flags |= SPP_HB_ENABLE;
2511 paddrp->spp_flags |= SPP_HB_DISABLE;
2513 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2514 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2516 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2518 SCTP_INP_RUNLOCK(inp);
2520 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2525 *optsize = sizeof(struct sctp_paddrparams);
2529 case SCTP_GET_PEER_ADDR_INFO:
2531 struct sctp_paddrinfo *paddri;
2532 struct sctp_nets *net;
2534 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2535 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2539 net = sctp_findnet(stcb, (struct sockaddr *)&paddri->spinfo_address);
2542 * We increment here since
2543 * sctp_findassociation_ep_addr() wil do a
2544 * decrement if it finds the stcb as long as
2545 * the locked tcb (last argument) is NOT a
2548 SCTP_INP_INCR_REF(inp);
2549 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddri->spinfo_address, &net, NULL, NULL);
2551 SCTP_INP_DECR_REF(inp);
2555 if ((stcb) && (net)) {
2556 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2557 /* It's unconfirmed */
2558 paddri->spinfo_state = SCTP_UNCONFIRMED;
2559 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2561 paddri->spinfo_state = SCTP_ACTIVE;
2564 paddri->spinfo_state = SCTP_INACTIVE;
2566 paddri->spinfo_cwnd = net->cwnd;
2567 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2568 paddri->spinfo_rto = net->RTO;
2569 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2570 paddri->spinfo_mtu = net->mtu;
2571 SCTP_TCB_UNLOCK(stcb);
2572 *optsize = sizeof(struct sctp_paddrinfo);
2575 SCTP_TCB_UNLOCK(stcb);
2577 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2582 case SCTP_PCB_STATUS:
2584 struct sctp_pcbinfo *spcb;
2586 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2587 sctp_fill_pcbinfo(spcb);
2588 *optsize = sizeof(struct sctp_pcbinfo);
2593 struct sctp_nets *net;
2594 struct sctp_status *sstat;
2596 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2597 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2600 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2605 * I think passing the state is fine since
2606 * sctp_constants.h will be available to the user
2609 sstat->sstat_state = stcb->asoc.state;
2610 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2611 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2612 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2614 * We can't include chunks that have been passed to
2615 * the socket layer. Only things in queue.
2617 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2618 stcb->asoc.cnt_on_all_streams);
2621 sstat->sstat_instrms = stcb->asoc.streamincnt;
2622 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2623 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2624 memcpy(&sstat->sstat_primary.spinfo_address,
2625 &stcb->asoc.primary_destination->ro._l_addr,
2626 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2627 net = stcb->asoc.primary_destination;
2628 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2630 * Again the user can get info from sctp_constants.h
2631 * for what the state of the network is.
2633 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2634 /* It's unconfirmed */
2635 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2636 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2638 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2641 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2643 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2644 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2645 sstat->sstat_primary.spinfo_rto = net->RTO;
2646 sstat->sstat_primary.spinfo_mtu = net->mtu;
2647 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2648 SCTP_TCB_UNLOCK(stcb);
2649 *optsize = sizeof(struct sctp_status);
2654 struct sctp_rtoinfo *srto;
2656 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2657 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2660 srto->srto_initial = stcb->asoc.initial_rto;
2661 srto->srto_max = stcb->asoc.maxrto;
2662 srto->srto_min = stcb->asoc.minrto;
2663 SCTP_TCB_UNLOCK(stcb);
2665 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2666 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2667 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2668 SCTP_INP_RLOCK(inp);
2669 srto->srto_initial = inp->sctp_ep.initial_rto;
2670 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2671 srto->srto_min = inp->sctp_ep.sctp_minrto;
2672 SCTP_INP_RUNLOCK(inp);
2674 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2679 *optsize = sizeof(struct sctp_rtoinfo);
2685 struct sctp_timeouts *stimo;
2687 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2688 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2691 stimo->stimo_init = stcb->asoc.timoinit;
2692 stimo->stimo_data = stcb->asoc.timodata;
2693 stimo->stimo_sack = stcb->asoc.timosack;
2694 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2695 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2696 stimo->stimo_cookie = stcb->asoc.timocookie;
2697 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2698 SCTP_TCB_UNLOCK(stcb);
2699 *optsize = sizeof(struct sctp_timeouts);
2701 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2706 case SCTP_ASSOCINFO:
2708 struct sctp_assocparams *sasoc;
2710 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2711 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2714 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2715 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2716 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2717 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2718 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2719 SCTP_TCB_UNLOCK(stcb);
2721 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2722 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2723 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2724 SCTP_INP_RLOCK(inp);
2725 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2726 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2727 sasoc->sasoc_number_peer_destinations = 0;
2728 sasoc->sasoc_peer_rwnd = 0;
2729 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2730 SCTP_INP_RUNLOCK(inp);
2732 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2737 *optsize = sizeof(struct sctp_assocparams);
2741 case SCTP_DEFAULT_SEND_PARAM:
2743 struct sctp_sndrcvinfo *s_info;
2745 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2746 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2749 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2750 SCTP_TCB_UNLOCK(stcb);
2752 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2753 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2754 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2755 SCTP_INP_RLOCK(inp);
2756 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2757 SCTP_INP_RUNLOCK(inp);
2759 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2764 *optsize = sizeof(struct sctp_sndrcvinfo);
2770 struct sctp_initmsg *sinit;
2772 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2773 SCTP_INP_RLOCK(inp);
2774 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2775 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2776 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2777 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2778 SCTP_INP_RUNLOCK(inp);
2779 *optsize = sizeof(struct sctp_initmsg);
2782 case SCTP_PRIMARY_ADDR:
2783 /* we allow a "get" operation on this */
2785 struct sctp_setprim *ssp;
2787 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2788 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2791 /* simply copy out the sockaddr_storage... */
2795 if (len > stcb->asoc.primary_destination->ro._l_addr.sa.sa_len)
2796 len = stcb->asoc.primary_destination->ro._l_addr.sa.sa_len;
2798 memcpy(&ssp->ssp_addr,
2799 &stcb->asoc.primary_destination->ro._l_addr,
2801 SCTP_TCB_UNLOCK(stcb);
2802 *optsize = sizeof(struct sctp_setprim);
2804 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2809 case SCTP_HMAC_IDENT:
2811 struct sctp_hmacalgo *shmac;
2812 sctp_hmaclist_t *hmaclist;
2816 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2818 SCTP_INP_RLOCK(inp);
2819 hmaclist = inp->sctp_ep.local_hmacs;
2820 if (hmaclist == NULL) {
2821 /* no HMACs to return */
2822 *optsize = sizeof(*shmac);
2823 SCTP_INP_RUNLOCK(inp);
2826 /* is there room for all of the hmac ids? */
2827 size = sizeof(*shmac) + (hmaclist->num_algo *
2828 sizeof(shmac->shmac_idents[0]));
2829 if ((size_t)(*optsize) < size) {
2830 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2832 SCTP_INP_RUNLOCK(inp);
2835 /* copy in the list */
2836 shmac->shmac_number_of_idents = hmaclist->num_algo;
2837 for (i = 0; i < hmaclist->num_algo; i++) {
2838 shmac->shmac_idents[i] = hmaclist->hmac[i];
2840 SCTP_INP_RUNLOCK(inp);
2844 case SCTP_AUTH_ACTIVE_KEY:
2846 struct sctp_authkeyid *scact;
2848 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2849 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2852 /* get the active key on the assoc */
2853 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2854 SCTP_TCB_UNLOCK(stcb);
2856 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2857 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2858 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2859 /* get the endpoint active key */
2860 SCTP_INP_RLOCK(inp);
2861 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2862 SCTP_INP_RUNLOCK(inp);
2864 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2869 *optsize = sizeof(struct sctp_authkeyid);
2873 case SCTP_LOCAL_AUTH_CHUNKS:
2875 struct sctp_authchunks *sac;
2876 sctp_auth_chklist_t *chklist = NULL;
2879 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2880 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2883 /* get off the assoc */
2884 chklist = stcb->asoc.local_auth_chunks;
2885 /* is there enough space? */
2886 size = sctp_auth_get_chklist_size(chklist);
2887 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2889 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2891 /* copy in the chunks */
2892 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2893 sac->gauth_number_of_chunks = (uint32_t) size;
2894 *optsize = sizeof(struct sctp_authchunks) + size;
2896 SCTP_TCB_UNLOCK(stcb);
2898 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2899 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2900 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2901 /* get off the endpoint */
2902 SCTP_INP_RLOCK(inp);
2903 chklist = inp->sctp_ep.local_auth_chunks;
2904 /* is there enough space? */
2905 size = sctp_auth_get_chklist_size(chklist);
2906 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2908 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2910 /* copy in the chunks */
2911 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2912 sac->gauth_number_of_chunks = (uint32_t) size;
2913 *optsize = sizeof(struct sctp_authchunks) + size;
2915 SCTP_INP_RUNLOCK(inp);
2917 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2923 case SCTP_PEER_AUTH_CHUNKS:
2925 struct sctp_authchunks *sac;
2926 sctp_auth_chklist_t *chklist = NULL;
2929 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2930 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2933 /* get off the assoc */
2934 chklist = stcb->asoc.peer_auth_chunks;
2935 /* is there enough space? */
2936 size = sctp_auth_get_chklist_size(chklist);
2937 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2939 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2941 /* copy in the chunks */
2942 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2943 sac->gauth_number_of_chunks = (uint32_t) size;
2944 *optsize = sizeof(struct sctp_authchunks) + size;
2946 SCTP_TCB_UNLOCK(stcb);
2948 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2955 struct sctp_event *event;
2956 uint32_t event_type;
2958 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2959 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
2961 switch (event->se_type) {
2962 case SCTP_ASSOC_CHANGE:
2963 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
2965 case SCTP_PEER_ADDR_CHANGE:
2966 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
2968 case SCTP_REMOTE_ERROR:
2969 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
2971 case SCTP_SEND_FAILED:
2972 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
2974 case SCTP_SHUTDOWN_EVENT:
2975 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
2977 case SCTP_ADAPTATION_INDICATION:
2978 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
2980 case SCTP_PARTIAL_DELIVERY_EVENT:
2981 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
2983 case SCTP_AUTHENTICATION_EVENT:
2984 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
2986 case SCTP_STREAM_RESET_EVENT:
2987 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
2989 case SCTP_SENDER_DRY_EVENT:
2990 event_type = SCTP_PCB_FLAGS_DRYEVNT;
2992 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
2994 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
2997 case SCTP_ASSOC_RESET_EVENT:
2998 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3000 case SCTP_STREAM_CHANGE_EVENT:
3001 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3003 case SCTP_SEND_FAILED_EVENT:
3004 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3008 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3012 if (event_type > 0) {
3014 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3015 SCTP_TCB_UNLOCK(stcb);
3017 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3018 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3019 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3020 SCTP_INP_RLOCK(inp);
3021 event->se_on = sctp_is_feature_on(inp, event_type);
3022 SCTP_INP_RUNLOCK(inp);
3024 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3030 *optsize = sizeof(struct sctp_event);
3034 case SCTP_RECVRCVINFO:
3038 if (*optsize < sizeof(int)) {
3039 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3042 SCTP_INP_RLOCK(inp);
3043 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3044 SCTP_INP_RUNLOCK(inp);
3047 /* return the option value */
3048 *(int *)optval = onoff;
3049 *optsize = sizeof(int);
3053 case SCTP_RECVNXTINFO:
3057 if (*optsize < sizeof(int)) {
3058 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3061 SCTP_INP_RLOCK(inp);
3062 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3063 SCTP_INP_RUNLOCK(inp);
3066 /* return the option value */
3067 *(int *)optval = onoff;
3068 *optsize = sizeof(int);
3072 case SCTP_DEFAULT_SNDINFO:
3074 struct sctp_sndinfo *info;
3076 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3077 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3080 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3081 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3082 info->snd_flags &= 0xfff0;
3083 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3084 info->snd_context = stcb->asoc.def_send.sinfo_context;
3085 SCTP_TCB_UNLOCK(stcb);
3087 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3088 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3089 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3090 SCTP_INP_RLOCK(inp);
3091 info->snd_sid = inp->def_send.sinfo_stream;
3092 info->snd_flags = inp->def_send.sinfo_flags;
3093 info->snd_flags &= 0xfff0;
3094 info->snd_ppid = inp->def_send.sinfo_ppid;
3095 info->snd_context = inp->def_send.sinfo_context;
3096 SCTP_INP_RUNLOCK(inp);
3098 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3103 *optsize = sizeof(struct sctp_sndinfo);
3107 case SCTP_DEFAULT_PRINFO:
3109 struct sctp_default_prinfo *info;
3111 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3112 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3115 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3116 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3117 SCTP_TCB_UNLOCK(stcb);
3119 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3120 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3121 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3122 SCTP_INP_RLOCK(inp);
3123 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3124 info->pr_value = inp->def_send.sinfo_timetolive;
3125 SCTP_INP_RUNLOCK(inp);
3127 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3132 *optsize = sizeof(struct sctp_default_prinfo);
3136 case SCTP_PEER_ADDR_THLDS:
3138 struct sctp_paddrthlds *thlds;
3139 struct sctp_nets *net;
3141 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3142 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3146 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_address);
3149 * We increment here since
3150 * sctp_findassociation_ep_addr() wil do a
3151 * decrement if it finds the stcb as long as
3152 * the locked tcb (last argument) is NOT a
3155 SCTP_INP_INCR_REF(inp);
3156 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&thlds->spt_address, &net, NULL, NULL);
3158 SCTP_INP_DECR_REF(inp);
3161 if (stcb && (net == NULL)) {
3162 struct sockaddr *sa;
3164 sa = (struct sockaddr *)&thlds->spt_address;
3166 if (sa->sa_family == AF_INET) {
3167 struct sockaddr_in *sin;
3169 sin = (struct sockaddr_in *)sa;
3170 if (sin->sin_addr.s_addr) {
3172 SCTP_TCB_UNLOCK(stcb);
3173 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3179 if (sa->sa_family == AF_INET6) {
3180 struct sockaddr_in6 *sin6;
3182 sin6 = (struct sockaddr_in6 *)sa;
3183 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3185 SCTP_TCB_UNLOCK(stcb);
3186 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3192 error = EAFNOSUPPORT;
3193 SCTP_TCB_UNLOCK(stcb);
3194 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3200 thlds->spt_pathmaxrxt = net->failure_threshold;
3201 thlds->spt_pathpfthld = net->pf_threshold;
3203 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3204 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3206 thlds->spt_assoc_id = sctp_get_associd(stcb);
3207 SCTP_TCB_UNLOCK(stcb);
3209 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3210 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3211 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3212 /* Use endpoint defaults */
3213 SCTP_INP_RLOCK(inp);
3214 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3215 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3216 SCTP_INP_RUNLOCK(inp);
3218 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3223 *optsize = sizeof(struct sctp_paddrthlds);
3227 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3229 struct sctp_udpencaps *encaps;
3230 struct sctp_nets *net;
3232 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3233 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3236 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
3239 * We increment here since
3240 * sctp_findassociation_ep_addr() wil do a
3241 * decrement if it finds the stcb as long as
3242 * the locked tcb (last argument) is NOT a
3246 SCTP_INP_INCR_REF(inp);
3247 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
3249 SCTP_INP_DECR_REF(inp);
3252 if (stcb && (net == NULL)) {
3253 struct sockaddr *sa;
3255 sa = (struct sockaddr *)&encaps->sue_address;
3257 if (sa->sa_family == AF_INET) {
3258 struct sockaddr_in *sin;
3260 sin = (struct sockaddr_in *)sa;
3261 if (sin->sin_addr.s_addr) {
3263 SCTP_TCB_UNLOCK(stcb);
3264 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3270 if (sa->sa_family == AF_INET6) {
3271 struct sockaddr_in6 *sin6;
3273 sin6 = (struct sockaddr_in6 *)sa;
3274 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3276 SCTP_TCB_UNLOCK(stcb);
3277 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3283 error = EAFNOSUPPORT;
3284 SCTP_TCB_UNLOCK(stcb);
3285 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3291 encaps->sue_port = net->port;
3293 encaps->sue_port = stcb->asoc.port;
3295 SCTP_TCB_UNLOCK(stcb);
3297 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3298 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3299 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3300 SCTP_INP_RLOCK(inp);
3301 encaps->sue_port = inp->sctp_ep.port;
3302 SCTP_INP_RUNLOCK(inp);
3304 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3309 *optsize = sizeof(struct sctp_udpencaps);
3313 case SCTP_ENABLE_STREAM_RESET:
3315 struct sctp_assoc_value *av;
3317 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3318 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3321 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3322 SCTP_TCB_UNLOCK(stcb);
3324 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3325 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3326 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3327 SCTP_INP_RLOCK(inp);
3328 av->assoc_value = (uint32_t) inp->local_strreset_support;
3329 SCTP_INP_RUNLOCK(inp);
3331 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3336 *optsize = sizeof(struct sctp_assoc_value);
3341 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3342 error = ENOPROTOOPT;
3344 } /* end switch (sopt->sopt_name) */
3352 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3357 struct sctp_tcb *stcb = NULL;
3358 struct sctp_inpcb *inp = NULL;
3361 if (optval == NULL) {
3362 SCTP_PRINTF("optval is NULL\n");
3363 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3366 inp = (struct sctp_inpcb *)so->so_pcb;
3368 SCTP_PRINTF("inp is NULL?\n");
3369 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3372 vrf_id = inp->def_vrf_id;
3377 case SCTP_AUTOCLOSE:
3378 case SCTP_AUTO_ASCONF:
3379 case SCTP_EXPLICIT_EOR:
3380 case SCTP_DISABLE_FRAGMENTS:
3381 case SCTP_USE_EXT_RCVINFO:
3382 case SCTP_I_WANT_MAPPED_V4_ADDR:
3383 /* copy in the option value */
3384 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3389 case SCTP_DISABLE_FRAGMENTS:
3390 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3392 case SCTP_AUTO_ASCONF:
3394 * NOTE: we don't really support this flag
3396 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3397 /* only valid for bound all sockets */
3398 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3400 /* forbidden by admin */
3401 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3404 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3406 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3410 case SCTP_EXPLICIT_EOR:
3411 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3413 case SCTP_USE_EXT_RCVINFO:
3414 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3416 case SCTP_I_WANT_MAPPED_V4_ADDR:
3417 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3418 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3420 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3425 set_opt = SCTP_PCB_FLAGS_NODELAY;
3427 case SCTP_AUTOCLOSE:
3428 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3429 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3430 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3433 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3435 * The value is in ticks. Note this does not effect
3436 * old associations, only new ones.
3438 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3441 SCTP_INP_WLOCK(inp);
3443 sctp_feature_on(inp, set_opt);
3445 sctp_feature_off(inp, set_opt);
3447 SCTP_INP_WUNLOCK(inp);
3449 case SCTP_REUSE_PORT:
3451 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3452 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3453 /* Can't set it after we are bound */
3457 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3458 /* Can't do this for a 1-m socket */
3463 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3465 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3468 case SCTP_PARTIAL_DELIVERY_POINT:
3472 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3473 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3474 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3478 inp->partial_delivery_point = *value;
3481 case SCTP_FRAGMENT_INTERLEAVE:
3482 /* not yet until we re-write sctp_recvmsg() */
3486 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3487 if (*level == SCTP_FRAG_LEVEL_2) {
3488 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3489 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3490 } else if (*level == SCTP_FRAG_LEVEL_1) {
3491 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3492 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3493 } else if (*level == SCTP_FRAG_LEVEL_0) {
3494 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3495 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3498 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3503 case SCTP_CMT_ON_OFF:
3504 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3505 struct sctp_assoc_value *av;
3507 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3508 if (av->assoc_value > SCTP_CMT_MAX) {
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.sctp_cmt_on_off = av->assoc_value;
3516 SCTP_TCB_UNLOCK(stcb);
3518 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3519 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3520 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3521 (av->assoc_id == SCTP_ALL_ASSOC)) {
3522 SCTP_INP_WLOCK(inp);
3523 inp->sctp_cmt_on_off = av->assoc_value;
3524 SCTP_INP_WUNLOCK(inp);
3526 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3527 (av->assoc_id == SCTP_ALL_ASSOC)) {
3528 SCTP_INP_RLOCK(inp);
3529 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3530 SCTP_TCB_LOCK(stcb);
3531 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3532 SCTP_TCB_UNLOCK(stcb);
3534 SCTP_INP_RUNLOCK(inp);
3538 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3539 error = ENOPROTOOPT;
3542 case SCTP_PLUGGABLE_CC:
3544 struct sctp_assoc_value *av;
3545 struct sctp_nets *net;
3547 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3548 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3549 (av->assoc_value != SCTP_CC_HSTCP) &&
3550 (av->assoc_value != SCTP_CC_HTCP) &&
3551 (av->assoc_value != SCTP_CC_RTCC)) {
3552 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3556 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3558 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3559 stcb->asoc.congestion_control_module = av->assoc_value;
3560 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3561 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3562 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3565 SCTP_TCB_UNLOCK(stcb);
3567 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3568 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3569 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3570 (av->assoc_id == SCTP_ALL_ASSOC)) {
3571 SCTP_INP_WLOCK(inp);
3572 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3573 SCTP_INP_WUNLOCK(inp);
3575 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3576 (av->assoc_id == SCTP_ALL_ASSOC)) {
3577 SCTP_INP_RLOCK(inp);
3578 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3579 SCTP_TCB_LOCK(stcb);
3580 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3581 stcb->asoc.congestion_control_module = av->assoc_value;
3582 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3583 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3584 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3587 SCTP_TCB_UNLOCK(stcb);
3589 SCTP_INP_RUNLOCK(inp);
3594 case SCTP_CC_OPTION:
3596 struct sctp_cc_option *cc_opt;
3598 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
3599 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
3601 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
3602 SCTP_INP_RLOCK(inp);
3603 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3604 SCTP_TCB_LOCK(stcb);
3605 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
3606 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
3608 SCTP_TCB_UNLOCK(stcb);
3610 SCTP_INP_RUNLOCK(inp);
3615 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
3618 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
3621 SCTP_TCB_UNLOCK(stcb);
3625 case SCTP_PLUGGABLE_SS:
3627 struct sctp_assoc_value *av;
3629 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3630 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
3631 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
3632 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
3633 (av->assoc_value != SCTP_SS_PRIORITY) &&
3634 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
3635 (av->assoc_value != SCTP_SS_FIRST_COME)) {
3636 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3640 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3642 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3643 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3644 stcb->asoc.stream_scheduling_module = av->assoc_value;
3645 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3646 SCTP_TCB_UNLOCK(stcb);
3648 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3649 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3650 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3651 (av->assoc_id == SCTP_ALL_ASSOC)) {
3652 SCTP_INP_WLOCK(inp);
3653 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
3654 SCTP_INP_WUNLOCK(inp);
3656 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3657 (av->assoc_id == SCTP_ALL_ASSOC)) {
3658 SCTP_INP_RLOCK(inp);
3659 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3660 SCTP_TCB_LOCK(stcb);
3661 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3662 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3663 stcb->asoc.stream_scheduling_module = av->assoc_value;
3664 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3665 SCTP_TCB_UNLOCK(stcb);
3667 SCTP_INP_RUNLOCK(inp);
3674 struct sctp_stream_value *av;
3676 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
3677 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3679 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
3680 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
3681 av->stream_value) < 0)) {
3682 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3685 SCTP_TCB_UNLOCK(stcb);
3687 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
3688 SCTP_INP_RLOCK(inp);
3689 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3690 SCTP_TCB_LOCK(stcb);
3691 if (av->stream_id < stcb->asoc.streamoutcnt) {
3692 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
3694 &stcb->asoc.strmout[av->stream_id],
3697 SCTP_TCB_UNLOCK(stcb);
3699 SCTP_INP_RUNLOCK(inp);
3703 * Can't set stream value without
3706 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3712 case SCTP_CLR_STAT_LOG:
3713 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3718 struct sctp_assoc_value *av;
3720 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3721 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3724 stcb->asoc.context = av->assoc_value;
3725 SCTP_TCB_UNLOCK(stcb);
3727 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3728 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3729 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3730 (av->assoc_id == SCTP_ALL_ASSOC)) {
3731 SCTP_INP_WLOCK(inp);
3732 inp->sctp_context = av->assoc_value;
3733 SCTP_INP_WUNLOCK(inp);
3735 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3736 (av->assoc_id == SCTP_ALL_ASSOC)) {
3737 SCTP_INP_RLOCK(inp);
3738 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3739 SCTP_TCB_LOCK(stcb);
3740 stcb->asoc.context = av->assoc_value;
3741 SCTP_TCB_UNLOCK(stcb);
3743 SCTP_INP_RUNLOCK(inp);
3750 uint32_t *default_vrfid;
3752 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
3753 if (*default_vrfid > SCTP_MAX_VRF_ID) {
3754 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3758 inp->def_vrf_id = *default_vrfid;
3761 case SCTP_DEL_VRF_ID:
3763 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3767 case SCTP_ADD_VRF_ID:
3769 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3773 case SCTP_DELAYED_SACK:
3775 struct sctp_sack_info *sack;
3777 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
3778 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
3779 if (sack->sack_delay) {
3780 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
3781 sack->sack_delay = SCTP_MAX_SACK_DELAY;
3782 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
3783 sack->sack_delay = TICKS_TO_MSEC(1);
3787 if (sack->sack_delay) {
3788 stcb->asoc.delayed_ack = sack->sack_delay;
3790 if (sack->sack_freq) {
3791 stcb->asoc.sack_freq = sack->sack_freq;
3793 SCTP_TCB_UNLOCK(stcb);
3795 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3796 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3797 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
3798 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3799 SCTP_INP_WLOCK(inp);
3800 if (sack->sack_delay) {
3801 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
3803 if (sack->sack_freq) {
3804 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
3806 SCTP_INP_WUNLOCK(inp);
3808 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
3809 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3810 SCTP_INP_RLOCK(inp);
3811 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3812 SCTP_TCB_LOCK(stcb);
3813 if (sack->sack_delay) {
3814 stcb->asoc.delayed_ack = sack->sack_delay;
3816 if (sack->sack_freq) {
3817 stcb->asoc.sack_freq = sack->sack_freq;
3819 SCTP_TCB_UNLOCK(stcb);
3821 SCTP_INP_RUNLOCK(inp);
3826 case SCTP_AUTH_CHUNK:
3828 struct sctp_authchunk *sauth;
3830 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
3832 SCTP_INP_WLOCK(inp);
3833 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
3834 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3837 SCTP_INP_WUNLOCK(inp);
3842 struct sctp_authkey *sca;
3843 struct sctp_keyhead *shared_keys;
3844 sctp_sharedkey_t *shared_key;
3845 sctp_key_t *key = NULL;
3848 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
3849 if (sca->sca_keylength == 0) {
3850 size = optsize - sizeof(struct sctp_authkey);
3852 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
3853 size = sca->sca_keylength;
3855 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3860 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
3863 shared_keys = &stcb->asoc.shared_keys;
3864 /* clear the cached keys for this key id */
3865 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3867 * create the new shared key and
3871 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3873 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3875 SCTP_TCB_UNLOCK(stcb);
3879 shared_key = sctp_alloc_sharedkey();
3880 if (shared_key == NULL) {
3882 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3884 SCTP_TCB_UNLOCK(stcb);
3887 shared_key->key = key;
3888 shared_key->keyid = sca->sca_keynumber;
3889 error = sctp_insert_sharedkey(shared_keys, shared_key);
3890 SCTP_TCB_UNLOCK(stcb);
3892 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3893 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3894 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
3895 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3896 SCTP_INP_WLOCK(inp);
3897 shared_keys = &inp->sctp_ep.shared_keys;
3899 * clear the cached keys on all
3900 * assocs for this key id
3902 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
3904 * create the new shared key and
3908 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3910 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3912 SCTP_INP_WUNLOCK(inp);
3916 shared_key = sctp_alloc_sharedkey();
3917 if (shared_key == NULL) {
3919 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3921 SCTP_INP_WUNLOCK(inp);
3924 shared_key->key = key;
3925 shared_key->keyid = sca->sca_keynumber;
3926 error = sctp_insert_sharedkey(shared_keys, shared_key);
3927 SCTP_INP_WUNLOCK(inp);
3929 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
3930 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3931 SCTP_INP_RLOCK(inp);
3932 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3933 SCTP_TCB_LOCK(stcb);
3934 shared_keys = &stcb->asoc.shared_keys;
3936 * clear the cached keys for
3939 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3941 * create the new shared key
3942 * and insert/replace it
3945 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3947 SCTP_TCB_UNLOCK(stcb);
3951 shared_key = sctp_alloc_sharedkey();
3952 if (shared_key == NULL) {
3954 SCTP_TCB_UNLOCK(stcb);
3957 shared_key->key = key;
3958 shared_key->keyid = sca->sca_keynumber;
3959 error = sctp_insert_sharedkey(shared_keys, shared_key);
3960 SCTP_TCB_UNLOCK(stcb);
3962 SCTP_INP_RUNLOCK(inp);
3967 case SCTP_HMAC_IDENT:
3969 struct sctp_hmacalgo *shmac;
3970 sctp_hmaclist_t *hmaclist;
3974 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
3975 if (optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) {
3976 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3980 hmaclist = sctp_alloc_hmaclist(shmac->shmac_number_of_idents);
3981 if (hmaclist == NULL) {
3982 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3986 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
3987 hmacid = shmac->shmac_idents[i];
3988 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
3989 /* invalid HMACs were found */ ;
3990 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3992 sctp_free_hmaclist(hmaclist);
3993 goto sctp_set_hmac_done;
3996 for (i = 0; i < hmaclist->num_algo; i++) {
3997 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
3998 /* already in list */
4002 if (i == hmaclist->num_algo) {
4003 /* not found in list */
4004 sctp_free_hmaclist(hmaclist);
4005 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4009 /* set it on the endpoint */
4010 SCTP_INP_WLOCK(inp);
4011 if (inp->sctp_ep.local_hmacs)
4012 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4013 inp->sctp_ep.local_hmacs = hmaclist;
4014 SCTP_INP_WUNLOCK(inp);
4018 case SCTP_AUTH_ACTIVE_KEY:
4020 struct sctp_authkeyid *scact;
4022 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4023 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4025 /* set the active key on the right place */
4027 /* set the active key on the assoc */
4028 if (sctp_auth_setactivekey(stcb,
4029 scact->scact_keynumber)) {
4030 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4031 SCTP_FROM_SCTP_USRREQ,
4035 SCTP_TCB_UNLOCK(stcb);
4037 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4038 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4039 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4040 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4041 SCTP_INP_WLOCK(inp);
4042 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4043 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4046 SCTP_INP_WUNLOCK(inp);
4048 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4049 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4050 SCTP_INP_RLOCK(inp);
4051 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4052 SCTP_TCB_LOCK(stcb);
4053 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4054 SCTP_TCB_UNLOCK(stcb);
4056 SCTP_INP_RUNLOCK(inp);
4061 case SCTP_AUTH_DELETE_KEY:
4063 struct sctp_authkeyid *scdel;
4065 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4066 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4068 /* delete the key from the right place */
4070 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4071 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4074 SCTP_TCB_UNLOCK(stcb);
4076 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4077 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4078 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4079 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4080 SCTP_INP_WLOCK(inp);
4081 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4082 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4085 SCTP_INP_WUNLOCK(inp);
4087 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4088 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4089 SCTP_INP_RLOCK(inp);
4090 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4091 SCTP_TCB_LOCK(stcb);
4092 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4093 SCTP_TCB_UNLOCK(stcb);
4095 SCTP_INP_RUNLOCK(inp);
4100 case SCTP_AUTH_DEACTIVATE_KEY:
4102 struct sctp_authkeyid *keyid;
4104 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4105 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4107 /* deactivate the key from the right place */
4109 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4110 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4113 SCTP_TCB_UNLOCK(stcb);
4115 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4116 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4117 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4118 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4119 SCTP_INP_WLOCK(inp);
4120 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4121 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4124 SCTP_INP_WUNLOCK(inp);
4126 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4127 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4128 SCTP_INP_RLOCK(inp);
4129 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4130 SCTP_TCB_LOCK(stcb);
4131 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4132 SCTP_TCB_UNLOCK(stcb);
4134 SCTP_INP_RUNLOCK(inp);
4139 case SCTP_ENABLE_STREAM_RESET:
4141 struct sctp_assoc_value *av;
4143 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4144 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4145 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4149 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4151 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4152 SCTP_TCB_UNLOCK(stcb);
4154 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4155 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4156 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4157 (av->assoc_id == SCTP_ALL_ASSOC)) {
4158 SCTP_INP_WLOCK(inp);
4159 inp->local_strreset_support = (uint8_t) av->assoc_value;
4160 SCTP_INP_WUNLOCK(inp);
4162 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4163 (av->assoc_id == SCTP_ALL_ASSOC)) {
4164 SCTP_INP_RLOCK(inp);
4165 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4166 SCTP_TCB_LOCK(stcb);
4167 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4168 SCTP_TCB_UNLOCK(stcb);
4170 SCTP_INP_RUNLOCK(inp);
4175 case SCTP_RESET_STREAMS:
4177 struct sctp_reset_streams *strrst;
4178 int i, send_out = 0;
4181 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4182 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4184 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4188 if (stcb->asoc.peer_supports_strreset == 0) {
4190 * Peer does not support the chunk type.
4192 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4194 SCTP_TCB_UNLOCK(stcb);
4197 if (stcb->asoc.stream_reset_outstanding) {
4198 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4200 SCTP_TCB_UNLOCK(stcb);
4203 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4206 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4209 if ((send_in == 0) && (send_out == 0)) {
4210 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4212 SCTP_TCB_UNLOCK(stcb);
4215 for (i = 0; i < strrst->srs_number_streams; i++) {
4217 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4218 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4223 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4224 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4230 SCTP_TCB_UNLOCK(stcb);
4233 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4234 strrst->srs_stream_list,
4235 send_out, send_in, 0, 0, 0, 0, 0);
4237 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4238 SCTP_TCB_UNLOCK(stcb);
4241 case SCTP_ADD_STREAMS:
4243 struct sctp_add_streams *stradd;
4244 uint8_t addstream = 0;
4245 uint16_t add_o_strmcnt = 0;
4246 uint16_t add_i_strmcnt = 0;
4248 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4249 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4251 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4255 if (stcb->asoc.peer_supports_strreset == 0) {
4257 * Peer does not support the chunk type.
4259 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4261 SCTP_TCB_UNLOCK(stcb);
4264 if (stcb->asoc.stream_reset_outstanding) {
4265 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4267 SCTP_TCB_UNLOCK(stcb);
4270 if ((stradd->sas_outstrms == 0) &&
4271 (stradd->sas_instrms == 0)) {
4275 if (stradd->sas_outstrms) {
4277 /* We allocate here */
4278 add_o_strmcnt = stradd->sas_outstrms;
4279 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4280 /* You can't have more than 64k */
4285 if (stradd->sas_instrms) {
4290 * We allocate inside
4291 * sctp_send_str_reset_req()
4293 add_i_strmcnt = stradd->sas_instrms;
4294 cnt = add_i_strmcnt;
4295 cnt += stcb->asoc.streamincnt;
4296 if (cnt > 0x0000ffff) {
4297 /* You can't have more than 64k */
4301 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4302 /* More than you are allowed */
4307 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4308 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4310 SCTP_TCB_UNLOCK(stcb);
4313 case SCTP_RESET_ASSOC:
4317 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4318 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4320 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4324 if (stcb->asoc.peer_supports_strreset == 0) {
4326 * Peer does not support the chunk type.
4328 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4330 SCTP_TCB_UNLOCK(stcb);
4333 if (stcb->asoc.stream_reset_outstanding) {
4334 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4336 SCTP_TCB_UNLOCK(stcb);
4339 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 1, 0, 0, 0, 0);
4340 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4341 SCTP_TCB_UNLOCK(stcb);
4344 case SCTP_CONNECT_X:
4345 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4346 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4350 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4352 case SCTP_CONNECT_X_DELAYED:
4353 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4354 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4358 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4360 case SCTP_CONNECT_X_COMPLETE:
4362 struct sockaddr *sa;
4363 struct sctp_nets *net;
4365 /* FIXME MT: check correct? */
4366 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4369 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4370 SCTP_INP_RLOCK(inp);
4371 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4373 SCTP_TCB_LOCK(stcb);
4374 net = sctp_findnet(stcb, sa);
4376 SCTP_INP_RUNLOCK(inp);
4379 * We increment here since
4380 * sctp_findassociation_ep_addr() wil do a
4381 * decrement if it finds the stcb as long as
4382 * the locked tcb (last argument) is NOT a
4385 SCTP_INP_INCR_REF(inp);
4386 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
4388 SCTP_INP_DECR_REF(inp);
4393 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4397 if (stcb->asoc.delayed_connection == 1) {
4398 stcb->asoc.delayed_connection = 0;
4399 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4400 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4401 stcb->asoc.primary_destination,
4402 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
4403 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4406 * already expired or did not use delayed
4409 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4412 SCTP_TCB_UNLOCK(stcb);
4415 case SCTP_MAX_BURST:
4417 struct sctp_assoc_value *av;
4419 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4420 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4423 stcb->asoc.max_burst = av->assoc_value;
4424 SCTP_TCB_UNLOCK(stcb);
4426 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4427 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4428 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4429 (av->assoc_id == SCTP_ALL_ASSOC)) {
4430 SCTP_INP_WLOCK(inp);
4431 inp->sctp_ep.max_burst = av->assoc_value;
4432 SCTP_INP_WUNLOCK(inp);
4434 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4435 (av->assoc_id == SCTP_ALL_ASSOC)) {
4436 SCTP_INP_RLOCK(inp);
4437 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4438 SCTP_TCB_LOCK(stcb);
4439 stcb->asoc.max_burst = av->assoc_value;
4440 SCTP_TCB_UNLOCK(stcb);
4442 SCTP_INP_RUNLOCK(inp);
4449 struct sctp_assoc_value *av;
4452 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4453 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4455 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4456 ovh = SCTP_MED_OVERHEAD;
4458 ovh = SCTP_MED_V4_OVERHEAD;
4461 if (av->assoc_value) {
4462 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4464 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4466 SCTP_TCB_UNLOCK(stcb);
4468 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4469 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4470 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4471 SCTP_INP_WLOCK(inp);
4473 * FIXME MT: I think this is not in
4474 * tune with the API ID
4476 if (av->assoc_value) {
4477 inp->sctp_frag_point = (av->assoc_value + ovh);
4479 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4481 SCTP_INP_WUNLOCK(inp);
4483 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4491 struct sctp_event_subscribe *events;
4493 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4495 SCTP_INP_WLOCK(inp);
4496 if (events->sctp_data_io_event) {
4497 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4499 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4502 if (events->sctp_association_event) {
4503 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4505 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4508 if (events->sctp_address_event) {
4509 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4511 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4514 if (events->sctp_send_failure_event) {
4515 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4517 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4520 if (events->sctp_peer_error_event) {
4521 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4523 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4526 if (events->sctp_shutdown_event) {
4527 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4529 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4532 if (events->sctp_partial_delivery_event) {
4533 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4535 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4538 if (events->sctp_adaptation_layer_event) {
4539 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4541 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4544 if (events->sctp_authentication_event) {
4545 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4547 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4550 if (events->sctp_sender_dry_event) {
4551 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
4553 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
4556 if (events->sctp_stream_reset_event) {
4557 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4559 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4561 SCTP_INP_WUNLOCK(inp);
4563 SCTP_INP_RLOCK(inp);
4564 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4565 SCTP_TCB_LOCK(stcb);
4566 if (events->sctp_association_event) {
4567 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4569 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4571 if (events->sctp_address_event) {
4572 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4574 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4576 if (events->sctp_send_failure_event) {
4577 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4579 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4581 if (events->sctp_peer_error_event) {
4582 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4584 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4586 if (events->sctp_shutdown_event) {
4587 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4589 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4591 if (events->sctp_partial_delivery_event) {
4592 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4594 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4596 if (events->sctp_adaptation_layer_event) {
4597 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4599 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4601 if (events->sctp_authentication_event) {
4602 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4604 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4606 if (events->sctp_sender_dry_event) {
4607 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4609 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4611 if (events->sctp_stream_reset_event) {
4612 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4614 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4616 SCTP_TCB_UNLOCK(stcb);
4619 * Send up the sender dry event only for 1-to-1
4622 if (events->sctp_sender_dry_event) {
4623 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4624 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
4625 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4627 SCTP_TCB_LOCK(stcb);
4628 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
4629 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
4630 (stcb->asoc.stream_queue_cnt == 0)) {
4631 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
4633 SCTP_TCB_UNLOCK(stcb);
4637 SCTP_INP_RUNLOCK(inp);
4640 case SCTP_ADAPTATION_LAYER:
4642 struct sctp_setadaptation *adap_bits;
4644 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
4645 SCTP_INP_WLOCK(inp);
4646 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
4647 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
4648 SCTP_INP_WUNLOCK(inp);
4652 case SCTP_SET_INITIAL_DBG_SEQ:
4656 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
4657 SCTP_INP_WLOCK(inp);
4658 inp->sctp_ep.initial_sequence_debug = *vvv;
4659 SCTP_INP_WUNLOCK(inp);
4663 case SCTP_DEFAULT_SEND_PARAM:
4665 struct sctp_sndrcvinfo *s_info;
4667 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
4668 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
4671 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4672 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4674 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4677 SCTP_TCB_UNLOCK(stcb);
4679 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4680 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4681 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
4682 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4683 SCTP_INP_WLOCK(inp);
4684 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
4685 SCTP_INP_WUNLOCK(inp);
4687 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
4688 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4689 SCTP_INP_RLOCK(inp);
4690 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4691 SCTP_TCB_LOCK(stcb);
4692 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4693 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4695 SCTP_TCB_UNLOCK(stcb);
4697 SCTP_INP_RUNLOCK(inp);
4702 case SCTP_PEER_ADDR_PARAMS:
4704 struct sctp_paddrparams *paddrp;
4705 struct sctp_nets *net;
4707 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
4708 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
4711 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
4714 * We increment here since
4715 * sctp_findassociation_ep_addr() wil do a
4716 * decrement if it finds the stcb as long as
4717 * the locked tcb (last argument) is NOT a
4720 SCTP_INP_INCR_REF(inp);
4721 stcb = sctp_findassociation_ep_addr(&inp,
4722 (struct sockaddr *)&paddrp->spp_address,
4725 SCTP_INP_DECR_REF(inp);
4728 if (stcb && (net == NULL)) {
4729 struct sockaddr *sa;
4731 sa = (struct sockaddr *)&paddrp->spp_address;
4733 if (sa->sa_family == AF_INET) {
4735 struct sockaddr_in *sin;
4737 sin = (struct sockaddr_in *)sa;
4738 if (sin->sin_addr.s_addr) {
4739 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4740 SCTP_TCB_UNLOCK(stcb);
4747 if (sa->sa_family == AF_INET6) {
4748 struct sockaddr_in6 *sin6;
4750 sin6 = (struct sockaddr_in6 *)sa;
4751 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
4752 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4753 SCTP_TCB_UNLOCK(stcb);
4760 error = EAFNOSUPPORT;
4761 SCTP_TCB_UNLOCK(stcb);
4762 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4767 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
4769 SCTP_TCB_UNLOCK(stcb);
4770 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4773 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
4775 SCTP_TCB_UNLOCK(stcb);
4776 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4780 /************************TCB SPECIFIC SET ******************/
4782 * do we change the timer for HB, we run
4787 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4788 ovh = SCTP_MED_OVERHEAD;
4790 ovh = SCTP_MED_V4_OVERHEAD;
4793 /* network sets ? */
4795 /************************NET SPECIFIC SET ******************/
4796 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4797 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
4798 !(net->dest_state & SCTP_ADDR_NOHB)) {
4799 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4800 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4802 net->dest_state |= SCTP_ADDR_NOHB;
4804 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4805 if (paddrp->spp_hbinterval) {
4806 net->heart_beat_delay = paddrp->spp_hbinterval;
4807 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4808 net->heart_beat_delay = 0;
4810 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4811 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4812 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4813 net->dest_state &= ~SCTP_ADDR_NOHB;
4815 if (paddrp->spp_flags & SPP_HB_DEMAND) {
4817 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4818 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
4819 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4821 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4822 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4823 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4824 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4826 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4827 net->mtu = paddrp->spp_pathmtu + ovh;
4828 if (net->mtu < stcb->asoc.smallest_mtu) {
4829 sctp_pathmtu_adjustment(stcb, net->mtu);
4832 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4833 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4834 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4836 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4838 if (paddrp->spp_pathmaxrxt) {
4839 if (net->dest_state & SCTP_ADDR_PF) {
4840 if (net->error_count > paddrp->spp_pathmaxrxt) {
4841 net->dest_state &= ~SCTP_ADDR_PF;
4844 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4845 (net->error_count > net->pf_threshold)) {
4846 net->dest_state |= SCTP_ADDR_PF;
4847 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4848 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4849 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4852 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4853 if (net->error_count > paddrp->spp_pathmaxrxt) {
4854 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4855 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
4858 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4859 net->dest_state |= SCTP_ADDR_REACHABLE;
4860 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
4863 net->failure_threshold = paddrp->spp_pathmaxrxt;
4865 if (paddrp->spp_flags & SPP_DSCP) {
4866 net->dscp = paddrp->spp_dscp & 0xfc;
4870 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4871 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4872 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4873 net->flowlabel |= 0x80000000;
4878 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
4879 if (paddrp->spp_pathmaxrxt) {
4880 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
4881 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4882 if (net->dest_state & SCTP_ADDR_PF) {
4883 if (net->error_count > paddrp->spp_pathmaxrxt) {
4884 net->dest_state &= ~SCTP_ADDR_PF;
4887 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4888 (net->error_count > net->pf_threshold)) {
4889 net->dest_state |= SCTP_ADDR_PF;
4890 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4891 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4892 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4895 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4896 if (net->error_count > paddrp->spp_pathmaxrxt) {
4897 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4898 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
4901 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4902 net->dest_state |= SCTP_ADDR_REACHABLE;
4903 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
4906 net->failure_threshold = paddrp->spp_pathmaxrxt;
4909 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4910 if (paddrp->spp_hbinterval) {
4911 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
4912 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4913 stcb->asoc.heart_beat_delay = 0;
4915 /* Turn back on the timer */
4916 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4917 if (paddrp->spp_hbinterval) {
4918 net->heart_beat_delay = paddrp->spp_hbinterval;
4919 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4920 net->heart_beat_delay = 0;
4922 if (net->dest_state & SCTP_ADDR_NOHB) {
4923 net->dest_state &= ~SCTP_ADDR_NOHB;
4925 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4926 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4927 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4929 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4931 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4932 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4933 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
4934 net->dest_state |= SCTP_ADDR_NOHB;
4935 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
4936 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4940 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4942 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4943 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4944 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4945 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4946 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4948 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4949 net->mtu = paddrp->spp_pathmtu + ovh;
4950 if (net->mtu < stcb->asoc.smallest_mtu) {
4951 sctp_pathmtu_adjustment(stcb, net->mtu);
4954 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4956 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4957 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4958 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4959 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4961 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4963 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4965 if (paddrp->spp_flags & SPP_DSCP) {
4966 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4967 net->dscp = paddrp->spp_dscp & 0xfc;
4970 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
4971 stcb->asoc.default_dscp |= 0x01;
4974 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4975 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4976 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4977 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4978 net->flowlabel |= 0x80000000;
4981 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4982 stcb->asoc.default_flowlabel |= 0x80000000;
4986 SCTP_TCB_UNLOCK(stcb);
4988 /************************NO TCB, SET TO default stuff ******************/
4989 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4990 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4991 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
4992 SCTP_INP_WLOCK(inp);
4994 * For the TOS/FLOWLABEL stuff you
4995 * set it with the options on the
4998 if (paddrp->spp_pathmaxrxt) {
4999 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5001 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5002 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5003 else if (paddrp->spp_hbinterval) {
5004 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5005 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5006 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5008 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5009 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5010 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5011 } else if (paddrp->spp_hbinterval) {
5012 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5014 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5015 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5016 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5018 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5019 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5020 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5021 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5023 if (paddrp->spp_flags & SPP_DSCP) {
5024 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5025 inp->sctp_ep.default_dscp |= 0x01;
5028 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5029 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5030 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5031 inp->sctp_ep.default_flowlabel |= 0x80000000;
5035 SCTP_INP_WUNLOCK(inp);
5037 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5045 struct sctp_rtoinfo *srto;
5046 uint32_t new_init, new_min, new_max;
5048 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5049 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5052 if (srto->srto_initial)
5053 new_init = srto->srto_initial;
5055 new_init = stcb->asoc.initial_rto;
5057 new_max = srto->srto_max;
5059 new_max = stcb->asoc.maxrto;
5061 new_min = srto->srto_min;
5063 new_min = stcb->asoc.minrto;
5064 if ((new_min <= new_init) && (new_init <= new_max)) {
5065 stcb->asoc.initial_rto = new_init;
5066 stcb->asoc.maxrto = new_max;
5067 stcb->asoc.minrto = new_min;
5069 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5072 SCTP_TCB_UNLOCK(stcb);
5074 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5075 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5076 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5077 SCTP_INP_WLOCK(inp);
5078 if (srto->srto_initial)
5079 new_init = srto->srto_initial;
5081 new_init = inp->sctp_ep.initial_rto;
5083 new_max = srto->srto_max;
5085 new_max = inp->sctp_ep.sctp_maxrto;
5087 new_min = srto->srto_min;
5089 new_min = inp->sctp_ep.sctp_minrto;
5090 if ((new_min <= new_init) && (new_init <= new_max)) {
5091 inp->sctp_ep.initial_rto = new_init;
5092 inp->sctp_ep.sctp_maxrto = new_max;
5093 inp->sctp_ep.sctp_minrto = new_min;
5095 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5098 SCTP_INP_WUNLOCK(inp);
5100 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5106 case SCTP_ASSOCINFO:
5108 struct sctp_assocparams *sasoc;
5110 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5111 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5112 if (sasoc->sasoc_cookie_life) {
5113 /* boundary check the cookie life */
5114 if (sasoc->sasoc_cookie_life < 1000)
5115 sasoc->sasoc_cookie_life = 1000;
5116 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5117 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5121 if (sasoc->sasoc_asocmaxrxt)
5122 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5123 if (sasoc->sasoc_cookie_life) {
5124 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5126 SCTP_TCB_UNLOCK(stcb);
5128 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5129 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5130 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5131 SCTP_INP_WLOCK(inp);
5132 if (sasoc->sasoc_asocmaxrxt)
5133 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5134 if (sasoc->sasoc_cookie_life) {
5135 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5137 SCTP_INP_WUNLOCK(inp);
5139 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5147 struct sctp_initmsg *sinit;
5149 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5150 SCTP_INP_WLOCK(inp);
5151 if (sinit->sinit_num_ostreams)
5152 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5154 if (sinit->sinit_max_instreams)
5155 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5157 if (sinit->sinit_max_attempts)
5158 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5160 if (sinit->sinit_max_init_timeo)
5161 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5162 SCTP_INP_WUNLOCK(inp);
5165 case SCTP_PRIMARY_ADDR:
5167 struct sctp_setprim *spa;
5168 struct sctp_nets *net;
5170 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5171 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5175 net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
5178 * We increment here since
5179 * sctp_findassociation_ep_addr() wil do a
5180 * decrement if it finds the stcb as long as
5181 * the locked tcb (last argument) is NOT a
5184 SCTP_INP_INCR_REF(inp);
5185 stcb = sctp_findassociation_ep_addr(&inp,
5186 (struct sockaddr *)&spa->ssp_addr,
5189 SCTP_INP_DECR_REF(inp);
5193 if ((stcb) && (net)) {
5194 if ((net != stcb->asoc.primary_destination) &&
5195 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
5196 /* Ok we need to set it */
5197 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5198 if ((stcb->asoc.alternate) &&
5199 (!(net->dest_state & SCTP_ADDR_PF)) &&
5200 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5201 sctp_free_remote_addr(stcb->asoc.alternate);
5202 stcb->asoc.alternate = NULL;
5207 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5211 SCTP_TCB_UNLOCK(stcb);
5215 case SCTP_SET_DYNAMIC_PRIMARY:
5217 union sctp_sockstore *ss;
5219 error = priv_check(curthread,
5220 PRIV_NETINET_RESERVEDPORT);
5224 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5225 /* SUPER USER CHECK? */
5226 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5229 case SCTP_SET_PEER_PRIMARY_ADDR:
5231 struct sctp_setpeerprim *sspp;
5233 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5234 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5236 struct sctp_ifa *ifa;
5238 ifa = sctp_find_ifa_by_addr((struct sockaddr *)&sspp->sspp_addr,
5239 stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5241 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5245 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5247 * Must validate the ifa found is in
5250 struct sctp_laddr *laddr;
5253 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5254 if (laddr->ifa == NULL) {
5255 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5259 if (laddr->ifa == ifa) {
5265 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5270 if (sctp_set_primary_ip_address_sa(stcb,
5271 (struct sockaddr *)&sspp->sspp_addr) != 0) {
5272 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5276 SCTP_TCB_UNLOCK(stcb);
5278 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5283 case SCTP_BINDX_ADD_ADDR:
5285 struct sctp_getaddresses *addrs;
5288 td = (struct thread *)p;
5289 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5292 if (addrs->addr->sa_family == AF_INET) {
5293 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5294 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5298 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5299 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5305 if (addrs->addr->sa_family == AF_INET6) {
5306 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5307 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5311 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5312 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5313 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5319 error = EAFNOSUPPORT;
5322 sctp_bindx_add_address(so, inp, addrs->addr,
5323 addrs->sget_assoc_id, vrf_id,
5327 case SCTP_BINDX_REM_ADDR:
5329 struct sctp_getaddresses *addrs;
5332 td = (struct thread *)p;
5334 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5336 if (addrs->addr->sa_family == AF_INET) {
5337 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5338 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5342 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5343 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5349 if (addrs->addr->sa_family == AF_INET6) {
5350 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5351 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5356 (error = prison_local_ip6(td->td_ucred,
5357 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5358 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5359 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5365 error = EAFNOSUPPORT;
5368 sctp_bindx_delete_address(inp, addrs->addr,
5369 addrs->sget_assoc_id, vrf_id,
5375 struct sctp_event *event;
5376 uint32_t event_type;
5378 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5379 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5380 switch (event->se_type) {
5381 case SCTP_ASSOC_CHANGE:
5382 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5384 case SCTP_PEER_ADDR_CHANGE:
5385 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5387 case SCTP_REMOTE_ERROR:
5388 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5390 case SCTP_SEND_FAILED:
5391 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5393 case SCTP_SHUTDOWN_EVENT:
5394 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5396 case SCTP_ADAPTATION_INDICATION:
5397 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5399 case SCTP_PARTIAL_DELIVERY_EVENT:
5400 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5402 case SCTP_AUTHENTICATION_EVENT:
5403 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5405 case SCTP_STREAM_RESET_EVENT:
5406 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5408 case SCTP_SENDER_DRY_EVENT:
5409 event_type = SCTP_PCB_FLAGS_DRYEVNT;
5411 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
5413 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5416 case SCTP_ASSOC_RESET_EVENT:
5417 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
5419 case SCTP_STREAM_CHANGE_EVENT:
5420 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
5422 case SCTP_SEND_FAILED_EVENT:
5423 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
5427 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5431 if (event_type > 0) {
5434 sctp_stcb_feature_on(inp, stcb, event_type);
5435 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
5436 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5437 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5438 (stcb->asoc.stream_queue_cnt == 0)) {
5439 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5443 sctp_stcb_feature_off(inp, stcb, event_type);
5445 SCTP_TCB_UNLOCK(stcb);
5448 * We don't want to send up a storm
5449 * of events, so return an error for
5452 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
5453 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
5454 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
5455 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
5456 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
5457 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5461 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5462 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5463 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
5464 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5465 SCTP_INP_WLOCK(inp);
5467 sctp_feature_on(inp, event_type);
5469 sctp_feature_off(inp, event_type);
5471 SCTP_INP_WUNLOCK(inp);
5473 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
5474 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5475 SCTP_INP_RLOCK(inp);
5476 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5477 SCTP_TCB_LOCK(stcb);
5479 sctp_stcb_feature_on(inp, stcb, event_type);
5481 sctp_stcb_feature_off(inp, stcb, event_type);
5483 SCTP_TCB_UNLOCK(stcb);
5485 SCTP_INP_RUNLOCK(inp);
5491 case SCTP_RECVRCVINFO:
5495 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5496 SCTP_INP_WLOCK(inp);
5498 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5500 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5502 SCTP_INP_WUNLOCK(inp);
5505 case SCTP_RECVNXTINFO:
5509 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5510 SCTP_INP_WLOCK(inp);
5512 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5514 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5516 SCTP_INP_WUNLOCK(inp);
5519 case SCTP_DEFAULT_SNDINFO:
5521 struct sctp_sndinfo *info;
5524 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
5525 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
5528 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5529 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5530 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5531 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5532 stcb->asoc.def_send.sinfo_flags |= policy;
5533 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5534 stcb->asoc.def_send.sinfo_context = info->snd_context;
5536 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5539 SCTP_TCB_UNLOCK(stcb);
5541 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5542 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5543 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
5544 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5545 SCTP_INP_WLOCK(inp);
5546 inp->def_send.sinfo_stream = info->snd_sid;
5547 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
5548 inp->def_send.sinfo_flags = info->snd_flags;
5549 inp->def_send.sinfo_flags |= policy;
5550 inp->def_send.sinfo_ppid = info->snd_ppid;
5551 inp->def_send.sinfo_context = info->snd_context;
5552 SCTP_INP_WUNLOCK(inp);
5554 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
5555 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5556 SCTP_INP_RLOCK(inp);
5557 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5558 SCTP_TCB_LOCK(stcb);
5559 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5560 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5561 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5562 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5563 stcb->asoc.def_send.sinfo_flags |= policy;
5564 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5565 stcb->asoc.def_send.sinfo_context = info->snd_context;
5567 SCTP_TCB_UNLOCK(stcb);
5569 SCTP_INP_RUNLOCK(inp);
5574 case SCTP_DEFAULT_PRINFO:
5576 struct sctp_default_prinfo *info;
5578 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
5579 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
5581 if (PR_SCTP_INVALID_POLICY(info->pr_policy)) {
5582 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5587 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5588 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5589 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5590 SCTP_TCB_UNLOCK(stcb);
5592 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5593 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5594 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
5595 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5596 SCTP_INP_WLOCK(inp);
5597 inp->def_send.sinfo_flags &= 0xfff0;
5598 inp->def_send.sinfo_flags |= info->pr_policy;
5599 inp->def_send.sinfo_timetolive = info->pr_value;
5600 SCTP_INP_WUNLOCK(inp);
5602 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
5603 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5604 SCTP_INP_RLOCK(inp);
5605 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5606 SCTP_TCB_LOCK(stcb);
5607 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5608 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5609 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5610 SCTP_TCB_UNLOCK(stcb);
5612 SCTP_INP_RUNLOCK(inp);
5617 case SCTP_PEER_ADDR_THLDS:
5618 /* Applies to the specific association */
5620 struct sctp_paddrthlds *thlds;
5621 struct sctp_nets *net;
5623 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
5624 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
5627 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_assoc_id);
5630 * We increment here since
5631 * sctp_findassociation_ep_addr() wil do a
5632 * decrement if it finds the stcb as long as
5633 * the locked tcb (last argument) is NOT a
5636 SCTP_INP_INCR_REF(inp);
5637 stcb = sctp_findassociation_ep_addr(&inp,
5638 (struct sockaddr *)&thlds->spt_assoc_id,
5641 SCTP_INP_DECR_REF(inp);
5644 if (stcb && (net == NULL)) {
5645 struct sockaddr *sa;
5647 sa = (struct sockaddr *)&thlds->spt_assoc_id;
5649 if (sa->sa_family == AF_INET) {
5651 struct sockaddr_in *sin;
5653 sin = (struct sockaddr_in *)sa;
5654 if (sin->sin_addr.s_addr) {
5655 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5656 SCTP_TCB_UNLOCK(stcb);
5663 if (sa->sa_family == AF_INET6) {
5664 struct sockaddr_in6 *sin6;
5666 sin6 = (struct sockaddr_in6 *)sa;
5667 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5668 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5669 SCTP_TCB_UNLOCK(stcb);
5676 error = EAFNOSUPPORT;
5677 SCTP_TCB_UNLOCK(stcb);
5678 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5684 if (net->dest_state & SCTP_ADDR_PF) {
5685 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5686 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5687 net->dest_state &= ~SCTP_ADDR_PF;
5690 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5691 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5692 net->dest_state |= SCTP_ADDR_PF;
5693 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5694 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5695 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5698 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5699 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5700 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5701 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5704 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5705 net->dest_state |= SCTP_ADDR_REACHABLE;
5706 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5709 net->failure_threshold = thlds->spt_pathmaxrxt;
5710 net->pf_threshold = thlds->spt_pathpfthld;
5712 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5713 if (net->dest_state & SCTP_ADDR_PF) {
5714 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5715 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5716 net->dest_state &= ~SCTP_ADDR_PF;
5719 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5720 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5721 net->dest_state |= SCTP_ADDR_PF;
5722 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5723 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5724 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5727 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5728 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5729 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5730 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5733 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5734 net->dest_state |= SCTP_ADDR_REACHABLE;
5735 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5738 net->failure_threshold = thlds->spt_pathmaxrxt;
5739 net->pf_threshold = thlds->spt_pathpfthld;
5741 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
5742 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
5745 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5746 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5747 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
5748 SCTP_INP_WLOCK(inp);
5749 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
5750 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
5751 SCTP_INP_WUNLOCK(inp);
5753 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5759 case SCTP_REMOTE_UDP_ENCAPS_PORT:
5761 struct sctp_udpencaps *encaps;
5762 struct sctp_nets *net;
5764 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
5765 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
5767 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
5770 * We increment here since
5771 * sctp_findassociation_ep_addr() wil do a
5772 * decrement if it finds the stcb as long as
5773 * the locked tcb (last argument) is NOT a
5777 SCTP_INP_INCR_REF(inp);
5778 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
5780 SCTP_INP_DECR_REF(inp);
5783 if (stcb && (net == NULL)) {
5784 struct sockaddr *sa;
5786 sa = (struct sockaddr *)&encaps->sue_address;
5788 if (sa->sa_family == AF_INET) {
5790 struct sockaddr_in *sin;
5792 sin = (struct sockaddr_in *)sa;
5793 if (sin->sin_addr.s_addr) {
5794 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5795 SCTP_TCB_UNLOCK(stcb);
5802 if (sa->sa_family == AF_INET6) {
5803 struct sockaddr_in6 *sin6;
5805 sin6 = (struct sockaddr_in6 *)sa;
5806 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5807 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5808 SCTP_TCB_UNLOCK(stcb);
5815 error = EAFNOSUPPORT;
5816 SCTP_TCB_UNLOCK(stcb);
5817 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5823 net->port = encaps->sue_port;
5825 stcb->asoc.port = encaps->sue_port;
5827 SCTP_TCB_UNLOCK(stcb);
5829 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5830 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5831 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
5832 SCTP_INP_WLOCK(inp);
5833 inp->sctp_ep.port = encaps->sue_port;
5834 SCTP_INP_WUNLOCK(inp);
5836 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5843 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
5844 error = ENOPROTOOPT;
5846 } /* end switch (opt) */
5851 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
5853 void *optval = NULL;
5858 if (sopt->sopt_level != IPPROTO_SCTP) {
5859 /* wrong proto level... send back up to IP */
5861 if (INP_CHECK_SOCKAF(so, AF_INET6))
5862 error = ip6_ctloutput(so, sopt);
5864 #if defined(INET) && defined(INET6)
5868 error = ip_ctloutput(so, sopt);
5872 optsize = sopt->sopt_valsize;
5874 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
5875 if (optval == NULL) {
5876 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
5879 error = sooptcopyin(sopt, optval, optsize, optsize);
5881 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5885 p = (void *)sopt->sopt_td;
5886 if (sopt->sopt_dir == SOPT_SET) {
5887 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
5888 } else if (sopt->sopt_dir == SOPT_GET) {
5889 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
5891 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5894 if ((error == 0) && (optval != NULL)) {
5895 error = sooptcopyout(sopt, optval, optsize);
5896 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5897 } else if (optval != NULL) {
5898 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5906 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
5909 int create_lock_on = 0;
5911 struct sctp_inpcb *inp;
5912 struct sctp_tcb *stcb = NULL;
5914 inp = (struct sctp_inpcb *)so->so_pcb;
5916 /* I made the same as TCP since we are not setup? */
5917 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5918 return (ECONNRESET);
5921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5924 switch (addr->sa_family) {
5928 struct sockaddr_in6 *sin6p;
5930 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
5931 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5934 sin6p = (struct sockaddr_in6 *)addr;
5935 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
5936 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5945 struct sockaddr_in *sinp;
5947 if (addr->sa_len != sizeof(struct sockaddr_in)) {
5948 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5951 sinp = (struct sockaddr_in *)addr;
5952 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
5953 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5960 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
5961 return (EAFNOSUPPORT);
5963 SCTP_INP_INCR_REF(inp);
5964 SCTP_ASOC_CREATE_LOCK(inp);
5968 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
5969 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
5970 /* Should I really unlock ? */
5971 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
5976 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
5977 (addr->sa_family == AF_INET6)) {
5978 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5983 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
5984 SCTP_PCB_FLAGS_UNBOUND) {
5985 /* Bind a ephemeral port */
5986 error = sctp_inpcb_bind(so, NULL, NULL, p);
5991 /* Now do we connect? */
5992 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
5993 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
5994 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5998 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
5999 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6000 /* We are already connected AND the TCP model */
6001 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6005 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6006 SCTP_INP_RLOCK(inp);
6007 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6008 SCTP_INP_RUNLOCK(inp);
6011 * We increment here since sctp_findassociation_ep_addr()
6012 * will do a decrement if it finds the stcb as long as the
6013 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6015 SCTP_INP_INCR_REF(inp);
6016 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6018 SCTP_INP_DECR_REF(inp);
6020 SCTP_TCB_UNLOCK(stcb);
6024 /* Already have or am bring up an association */
6025 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
6029 vrf_id = inp->def_vrf_id;
6030 /* We are GOOD to go */
6031 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
6033 /* Gak! no memory */
6036 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
6037 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
6038 /* Set the connected flag so we can queue data */
6041 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
6042 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
6044 /* initialize authentication parameters for the assoc */
6045 sctp_initialize_auth_params(inp, stcb);
6047 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
6048 SCTP_TCB_UNLOCK(stcb);
6050 if (create_lock_on) {
6051 SCTP_ASOC_CREATE_UNLOCK(inp);
6053 SCTP_INP_DECR_REF(inp);
6060 sctp_listen(struct socket *so, int backlog, struct thread *p)
6063 * Note this module depends on the protocol processing being called
6064 * AFTER any socket level flags and backlog are applied to the
6065 * socket. The traditional way that the socket flags are applied is
6066 * AFTER protocol processing. We have made a change to the
6067 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
6068 * place if the socket API for SCTP is to work properly.
6072 struct sctp_inpcb *inp;
6074 inp = (struct sctp_inpcb *)so->so_pcb;
6076 /* I made the same as TCP since we are not setup? */
6077 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6078 return (ECONNRESET);
6080 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
6081 /* See if we have a listener */
6082 struct sctp_inpcb *tinp;
6083 union sctp_sockstore store, *sp;
6086 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
6088 struct sctp_laddr *laddr;
6090 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6091 memcpy(&store, &laddr->ifa->address, sizeof(store));
6092 switch (sp->sa.sa_family) {
6095 sp->sin.sin_port = inp->sctp_lport;
6100 sp->sin6.sin6_port = inp->sctp_lport;
6106 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6107 if (tinp && (tinp != inp) &&
6108 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6109 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6110 (tinp->sctp_socket->so_qlimit)) {
6112 * we have a listener already and
6115 SCTP_INP_DECR_REF(tinp);
6116 return (EADDRINUSE);
6118 SCTP_INP_DECR_REF(tinp);
6122 /* Setup a local addr bound all */
6123 memset(&store, 0, sizeof(store));
6124 switch (sp->sa.sa_family) {
6127 store.sin.sin_port = inp->sctp_lport;
6132 sp->sin6.sin6_port = inp->sctp_lport;
6139 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
6140 store.sa.sa_family = AF_INET6;
6141 store.sa.sa_len = sizeof(struct sockaddr_in6);
6145 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
6146 store.sa.sa_family = AF_INET;
6147 store.sa.sa_len = sizeof(struct sockaddr_in);
6150 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6151 if (tinp && (tinp != inp) &&
6152 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6153 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6154 (tinp->sctp_socket->so_qlimit)) {
6156 * we have a listener already and its not
6159 SCTP_INP_DECR_REF(tinp);
6160 return (EADDRINUSE);
6162 SCTP_INP_DECR_REF(inp);
6166 SCTP_INP_RLOCK(inp);
6167 #ifdef SCTP_LOCK_LOGGING
6168 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
6169 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
6173 error = solisten_proto_check(so);
6176 SCTP_INP_RUNLOCK(inp);
6179 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
6180 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
6182 * The unlucky case - We are in the tcp pool with this guy.
6183 * - Someone else is in the main inp slot. - We must move
6184 * this guy (the listener) to the main slot - We must then
6185 * move the guy that was listener to the TCP Pool.
6187 if (sctp_swap_inpcb_for_listen(inp)) {
6191 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6192 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6193 /* We are already connected AND the TCP model */
6195 SCTP_INP_RUNLOCK(inp);
6197 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6198 return (EADDRINUSE);
6200 SCTP_INP_RUNLOCK(inp);
6201 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
6202 /* We must do a bind. */
6204 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
6205 /* bind error, probably perm */
6210 /* It appears for 7.0 and on, we must always call this. */
6211 solisten_proto(so, backlog);
6212 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6213 /* remove the ACCEPTCONN flag for one-to-many sockets */
6214 so->so_options &= ~SO_ACCEPTCONN;
6217 /* turning off listen */
6218 so->so_options &= ~SO_ACCEPTCONN;
6224 static int sctp_defered_wakeup_cnt = 0;
6227 sctp_accept(struct socket *so, struct sockaddr **addr)
6229 struct sctp_tcb *stcb;
6230 struct sctp_inpcb *inp;
6231 union sctp_sockstore store;
6237 inp = (struct sctp_inpcb *)so->so_pcb;
6240 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6241 return (ECONNRESET);
6243 SCTP_INP_RLOCK(inp);
6244 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6245 SCTP_INP_RUNLOCK(inp);
6246 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
6247 return (EOPNOTSUPP);
6249 if (so->so_state & SS_ISDISCONNECTED) {
6250 SCTP_INP_RUNLOCK(inp);
6251 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
6252 return (ECONNABORTED);
6254 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6256 SCTP_INP_RUNLOCK(inp);
6257 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6258 return (ECONNRESET);
6260 SCTP_TCB_LOCK(stcb);
6261 SCTP_INP_RUNLOCK(inp);
6262 store = stcb->asoc.primary_destination->ro._l_addr;
6263 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
6264 SCTP_TCB_UNLOCK(stcb);
6265 switch (store.sa.sa_family) {
6269 struct sockaddr_in *sin;
6271 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6274 sin->sin_family = AF_INET;
6275 sin->sin_len = sizeof(*sin);
6276 sin->sin_port = store.sin.sin_port;
6277 sin->sin_addr = store.sin.sin_addr;
6278 *addr = (struct sockaddr *)sin;
6285 struct sockaddr_in6 *sin6;
6287 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
6290 sin6->sin6_family = AF_INET6;
6291 sin6->sin6_len = sizeof(*sin6);
6292 sin6->sin6_port = store.sin6.sin6_port;
6293 sin6->sin6_addr = store.sin6.sin6_addr;
6294 if ((error = sa6_recoverscope(sin6)) != 0) {
6295 SCTP_FREE_SONAME(sin6);
6298 *addr = (struct sockaddr *)sin6;
6306 /* Wake any delayed sleep action */
6307 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
6308 SCTP_INP_WLOCK(inp);
6309 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
6310 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
6311 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
6312 SCTP_INP_WUNLOCK(inp);
6313 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
6314 if (sowriteable(inp->sctp_socket)) {
6315 sowwakeup_locked(inp->sctp_socket);
6317 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
6319 SCTP_INP_WLOCK(inp);
6321 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
6322 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
6323 SCTP_INP_WUNLOCK(inp);
6324 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
6325 if (soreadable(inp->sctp_socket)) {
6326 sctp_defered_wakeup_cnt++;
6327 sorwakeup_locked(inp->sctp_socket);
6329 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
6331 SCTP_INP_WLOCK(inp);
6333 SCTP_INP_WUNLOCK(inp);
6335 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
6336 SCTP_TCB_LOCK(stcb);
6337 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
6344 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
6346 struct sockaddr_in *sin;
6348 struct sctp_inpcb *inp;
6349 struct sctp_ifa *sctp_ifa;
6352 * Do the malloc first in case it blocks.
6354 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6357 sin->sin_family = AF_INET;
6358 sin->sin_len = sizeof(*sin);
6359 inp = (struct sctp_inpcb *)so->so_pcb;
6361 SCTP_FREE_SONAME(sin);
6362 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6363 return (ECONNRESET);
6365 SCTP_INP_RLOCK(inp);
6366 sin->sin_port = inp->sctp_lport;
6367 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
6368 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6369 struct sctp_tcb *stcb;
6370 struct sockaddr_in *sin_a;
6371 struct sctp_nets *net;
6374 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6380 SCTP_TCB_LOCK(stcb);
6381 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6382 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6384 /* this will make coverity happy */
6387 if (sin_a->sin_family == AF_INET) {
6392 if ((!fnd) || (sin_a == NULL)) {
6394 SCTP_TCB_UNLOCK(stcb);
6397 vrf_id = inp->def_vrf_id;
6398 sctp_ifa = sctp_source_address_selection(inp,
6400 (sctp_route_t *) & net->ro,
6403 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
6404 sctp_free_ifa(sctp_ifa);
6406 SCTP_TCB_UNLOCK(stcb);
6408 /* For the bound all case you get back 0 */
6410 sin->sin_addr.s_addr = 0;
6414 /* Take the first IPv4 address in the list */
6415 struct sctp_laddr *laddr;
6418 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6419 if (laddr->ifa->address.sa.sa_family == AF_INET) {
6420 struct sockaddr_in *sin_a;
6422 sin_a = (struct sockaddr_in *)&laddr->ifa->address.sa;
6423 sin->sin_addr = sin_a->sin_addr;
6429 SCTP_FREE_SONAME(sin);
6430 SCTP_INP_RUNLOCK(inp);
6431 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6435 SCTP_INP_RUNLOCK(inp);
6436 (*addr) = (struct sockaddr *)sin;
6441 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
6443 struct sockaddr_in *sin;
6445 struct sockaddr_in *sin_a;
6446 struct sctp_inpcb *inp;
6447 struct sctp_tcb *stcb;
6448 struct sctp_nets *net;
6450 /* Do the malloc first in case it blocks. */
6451 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6454 sin->sin_family = AF_INET;
6455 sin->sin_len = sizeof(*sin);
6457 inp = (struct sctp_inpcb *)so->so_pcb;
6458 if ((inp == NULL) ||
6459 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
6460 /* UDP type and listeners will drop out here */
6461 SCTP_FREE_SONAME(sin);
6462 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
6465 SCTP_INP_RLOCK(inp);
6466 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6468 SCTP_TCB_LOCK(stcb);
6470 SCTP_INP_RUNLOCK(inp);
6472 SCTP_FREE_SONAME(sin);
6473 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6474 return (ECONNRESET);
6477 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6478 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6479 if (sin_a->sin_family == AF_INET) {
6481 sin->sin_port = stcb->rport;
6482 sin->sin_addr = sin_a->sin_addr;
6486 SCTP_TCB_UNLOCK(stcb);
6488 /* No IPv4 address */
6489 SCTP_FREE_SONAME(sin);
6490 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6493 (*addr) = (struct sockaddr *)sin;
6497 struct pr_usrreqs sctp_usrreqs = {
6498 .pru_abort = sctp_abort,
6499 .pru_accept = sctp_accept,
6500 .pru_attach = sctp_attach,
6501 .pru_bind = sctp_bind,
6502 .pru_connect = sctp_connect,
6503 .pru_control = in_control,
6504 .pru_close = sctp_close,
6505 .pru_detach = sctp_close,
6506 .pru_sopoll = sopoll_generic,
6507 .pru_flush = sctp_flush,
6508 .pru_disconnect = sctp_disconnect,
6509 .pru_listen = sctp_listen,
6510 .pru_peeraddr = sctp_peeraddr,
6511 .pru_send = sctp_sendm,
6512 .pru_shutdown = sctp_shutdown,
6513 .pru_sockaddr = sctp_ingetaddr,
6514 .pru_sosend = sctp_sosend,
6515 .pru_soreceive = sctp_soreceive