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 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1873 &av->stream_value) < 0) {
1874 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1877 *optsize = sizeof(struct sctp_stream_value);
1879 SCTP_TCB_UNLOCK(stcb);
1882 * Can't get stream value without
1885 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1890 case SCTP_GET_ADDR_LEN:
1892 struct sctp_assoc_value *av;
1894 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1897 if (av->assoc_value == AF_INET) {
1898 av->assoc_value = sizeof(struct sockaddr_in);
1903 if (av->assoc_value == AF_INET6) {
1904 av->assoc_value = sizeof(struct sockaddr_in6);
1909 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1911 *optsize = sizeof(struct sctp_assoc_value);
1915 case SCTP_GET_ASSOC_NUMBER:
1917 uint32_t *value, cnt;
1919 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1921 SCTP_INP_RLOCK(inp);
1922 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1925 SCTP_INP_RUNLOCK(inp);
1927 *optsize = sizeof(uint32_t);
1930 case SCTP_GET_ASSOC_ID_LIST:
1932 struct sctp_assoc_ids *ids;
1933 unsigned int at, limit;
1935 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1937 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1938 SCTP_INP_RLOCK(inp);
1939 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1941 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1944 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1948 SCTP_INP_RUNLOCK(inp);
1950 ids->gaids_number_of_ids = at;
1951 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1957 struct sctp_assoc_value *av;
1959 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1960 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1963 av->assoc_value = stcb->asoc.context;
1964 SCTP_TCB_UNLOCK(stcb);
1966 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1967 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1968 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1969 SCTP_INP_RLOCK(inp);
1970 av->assoc_value = inp->sctp_context;
1971 SCTP_INP_RUNLOCK(inp);
1973 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1978 *optsize = sizeof(struct sctp_assoc_value);
1984 uint32_t *default_vrfid;
1986 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1987 *default_vrfid = inp->def_vrf_id;
1988 *optsize = sizeof(uint32_t);
1991 case SCTP_GET_ASOC_VRF:
1993 struct sctp_assoc_value *id;
1995 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1996 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1999 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2001 id->assoc_value = stcb->asoc.vrf_id;
2002 *optsize = sizeof(struct sctp_assoc_value);
2006 case SCTP_GET_VRF_IDS:
2008 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
2012 case SCTP_GET_NONCE_VALUES:
2014 struct sctp_get_nonce_values *gnv;
2016 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
2017 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
2020 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
2021 gnv->gn_local_tag = stcb->asoc.my_vtag;
2022 SCTP_TCB_UNLOCK(stcb);
2023 *optsize = sizeof(struct sctp_get_nonce_values);
2025 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2030 case SCTP_DELAYED_SACK:
2032 struct sctp_sack_info *sack;
2034 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2035 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2037 sack->sack_delay = stcb->asoc.delayed_ack;
2038 sack->sack_freq = stcb->asoc.sack_freq;
2039 SCTP_TCB_UNLOCK(stcb);
2041 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2042 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2043 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2044 SCTP_INP_RLOCK(inp);
2045 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2046 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2047 SCTP_INP_RUNLOCK(inp);
2049 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2054 *optsize = sizeof(struct sctp_sack_info);
2058 case SCTP_GET_SNDBUF_USE:
2060 struct sctp_sockstat *ss;
2062 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2063 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2066 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2067 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2068 stcb->asoc.size_on_all_streams);
2069 SCTP_TCB_UNLOCK(stcb);
2070 *optsize = sizeof(struct sctp_sockstat);
2072 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2077 case SCTP_MAX_BURST:
2079 struct sctp_assoc_value *av;
2081 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2082 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2085 av->assoc_value = stcb->asoc.max_burst;
2086 SCTP_TCB_UNLOCK(stcb);
2088 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2089 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2090 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2091 SCTP_INP_RLOCK(inp);
2092 av->assoc_value = inp->sctp_ep.max_burst;
2093 SCTP_INP_RUNLOCK(inp);
2095 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2100 *optsize = sizeof(struct sctp_assoc_value);
2106 struct sctp_assoc_value *av;
2109 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2110 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2113 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2114 SCTP_TCB_UNLOCK(stcb);
2116 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2117 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2118 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2119 SCTP_INP_RLOCK(inp);
2120 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2121 ovh = SCTP_MED_OVERHEAD;
2123 ovh = SCTP_MED_V4_OVERHEAD;
2125 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2126 av->assoc_value = 0;
2128 av->assoc_value = inp->sctp_frag_point - ovh;
2129 SCTP_INP_RUNLOCK(inp);
2131 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2136 *optsize = sizeof(struct sctp_assoc_value);
2140 case SCTP_GET_STAT_LOG:
2141 error = sctp_fill_stat_log(optval, optsize);
2145 struct sctp_event_subscribe *events;
2147 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2148 memset(events, 0, sizeof(struct sctp_event_subscribe));
2149 SCTP_INP_RLOCK(inp);
2150 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2151 events->sctp_data_io_event = 1;
2153 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2154 events->sctp_association_event = 1;
2156 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2157 events->sctp_address_event = 1;
2159 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2160 events->sctp_send_failure_event = 1;
2162 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2163 events->sctp_peer_error_event = 1;
2165 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2166 events->sctp_shutdown_event = 1;
2168 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2169 events->sctp_partial_delivery_event = 1;
2171 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2172 events->sctp_adaptation_layer_event = 1;
2174 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2175 events->sctp_authentication_event = 1;
2177 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2178 events->sctp_sender_dry_event = 1;
2180 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2181 events->sctp_stream_reset_event = 1;
2182 SCTP_INP_RUNLOCK(inp);
2183 *optsize = sizeof(struct sctp_event_subscribe);
2186 case SCTP_ADAPTATION_LAYER:
2190 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2192 SCTP_INP_RLOCK(inp);
2193 *value = inp->sctp_ep.adaptation_layer_indicator;
2194 SCTP_INP_RUNLOCK(inp);
2195 *optsize = sizeof(uint32_t);
2198 case SCTP_SET_INITIAL_DBG_SEQ:
2202 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2203 SCTP_INP_RLOCK(inp);
2204 *value = inp->sctp_ep.initial_sequence_debug;
2205 SCTP_INP_RUNLOCK(inp);
2206 *optsize = sizeof(uint32_t);
2209 case SCTP_GET_LOCAL_ADDR_SIZE:
2213 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2214 SCTP_INP_RLOCK(inp);
2215 *value = sctp_count_max_addresses(inp);
2216 SCTP_INP_RUNLOCK(inp);
2217 *optsize = sizeof(uint32_t);
2220 case SCTP_GET_REMOTE_ADDR_SIZE:
2224 struct sctp_nets *net;
2226 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2227 /* FIXME MT: change to sctp_assoc_value? */
2228 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2232 /* Count the sizes */
2233 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2234 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2235 size += sizeof(struct sockaddr_in6);
2237 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2240 size += sizeof(struct sockaddr_in);
2245 size += sizeof(struct sockaddr_in6);
2253 SCTP_TCB_UNLOCK(stcb);
2254 *value = (uint32_t) size;
2255 *optsize = sizeof(uint32_t);
2257 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2262 case SCTP_GET_PEER_ADDRESSES:
2264 * Get the address information, an array is passed in to
2265 * fill up we pack it.
2269 struct sockaddr_storage *sas;
2270 struct sctp_nets *net;
2271 struct sctp_getaddresses *saddr;
2273 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2274 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2277 left = (*optsize) - sizeof(struct sctp_getaddresses);
2278 *optsize = sizeof(struct sctp_getaddresses);
2279 sas = (struct sockaddr_storage *)&saddr->addr[0];
2281 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2282 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2283 cpsz = sizeof(struct sockaddr_in6);
2285 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2288 cpsz = sizeof(struct sockaddr_in);
2293 cpsz = sizeof(struct sockaddr_in6);
2305 /* not enough room. */
2308 #if defined(INET) && defined(INET6)
2309 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2310 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
2311 /* Must map the address */
2312 in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
2313 (struct sockaddr_in6 *)sas);
2316 memcpy(sas, &net->ro._l_addr, cpsz);
2317 #if defined(INET) && defined(INET6)
2320 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2322 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2326 SCTP_TCB_UNLOCK(stcb);
2328 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2333 case SCTP_GET_LOCAL_ADDRESSES:
2335 size_t limit, actual;
2336 struct sockaddr_storage *sas;
2337 struct sctp_getaddresses *saddr;
2339 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2340 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2342 sas = (struct sockaddr_storage *)&saddr->addr[0];
2343 limit = *optsize - sizeof(sctp_assoc_t);
2344 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2346 SCTP_TCB_UNLOCK(stcb);
2348 *optsize = sizeof(struct sockaddr_storage) + actual;
2351 case SCTP_PEER_ADDR_PARAMS:
2353 struct sctp_paddrparams *paddrp;
2354 struct sctp_nets *net;
2356 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2357 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2361 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2364 * We increment here since
2365 * sctp_findassociation_ep_addr() wil do a
2366 * decrement if it finds the stcb as long as
2367 * the locked tcb (last argument) is NOT a
2370 SCTP_INP_INCR_REF(inp);
2371 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddrp->spp_address, &net, NULL, NULL);
2373 SCTP_INP_DECR_REF(inp);
2376 if (stcb && (net == NULL)) {
2377 struct sockaddr *sa;
2379 sa = (struct sockaddr *)&paddrp->spp_address;
2381 if (sa->sa_family == AF_INET) {
2382 struct sockaddr_in *sin;
2384 sin = (struct sockaddr_in *)sa;
2385 if (sin->sin_addr.s_addr) {
2387 SCTP_TCB_UNLOCK(stcb);
2388 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2394 if (sa->sa_family == AF_INET6) {
2395 struct sockaddr_in6 *sin6;
2397 sin6 = (struct sockaddr_in6 *)sa;
2398 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2400 SCTP_TCB_UNLOCK(stcb);
2401 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2407 error = EAFNOSUPPORT;
2408 SCTP_TCB_UNLOCK(stcb);
2409 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2414 /* Applies to the specific association */
2415 paddrp->spp_flags = 0;
2419 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2420 ovh = SCTP_MED_OVERHEAD;
2422 ovh = SCTP_MED_V4_OVERHEAD;
2425 paddrp->spp_hbinterval = net->heart_beat_delay;
2426 paddrp->spp_pathmaxrxt = net->failure_threshold;
2427 paddrp->spp_pathmtu = net->mtu - ovh;
2428 /* get flags for HB */
2429 if (net->dest_state & SCTP_ADDR_NOHB) {
2430 paddrp->spp_flags |= SPP_HB_DISABLE;
2432 paddrp->spp_flags |= SPP_HB_ENABLE;
2434 /* get flags for PMTU */
2435 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2436 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2438 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2440 if (net->dscp & 0x01) {
2441 paddrp->spp_dscp = net->dscp & 0xfc;
2442 paddrp->spp_flags |= SPP_DSCP;
2445 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2446 (net->flowlabel & 0x80000000)) {
2447 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2448 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2453 * No destination so return default
2456 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2457 paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
2458 if (stcb->asoc.default_dscp & 0x01) {
2459 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2460 paddrp->spp_flags |= SPP_DSCP;
2463 if (stcb->asoc.default_flowlabel & 0x80000000) {
2464 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2465 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2468 /* default settings should be these */
2469 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2470 paddrp->spp_flags |= SPP_HB_DISABLE;
2472 paddrp->spp_flags |= SPP_HB_ENABLE;
2474 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2475 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2477 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2479 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2481 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2482 SCTP_TCB_UNLOCK(stcb);
2484 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2485 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2486 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2487 /* Use endpoint defaults */
2488 SCTP_INP_RLOCK(inp);
2489 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2490 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2491 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2492 /* get inp's default */
2493 if (inp->sctp_ep.default_dscp & 0x01) {
2494 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2495 paddrp->spp_flags |= SPP_DSCP;
2498 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2499 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2500 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2501 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2504 /* can't return this */
2505 paddrp->spp_pathmtu = 0;
2507 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2508 paddrp->spp_flags |= SPP_HB_ENABLE;
2510 paddrp->spp_flags |= SPP_HB_DISABLE;
2512 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2513 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2515 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2517 SCTP_INP_RUNLOCK(inp);
2519 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2524 *optsize = sizeof(struct sctp_paddrparams);
2528 case SCTP_GET_PEER_ADDR_INFO:
2530 struct sctp_paddrinfo *paddri;
2531 struct sctp_nets *net;
2533 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2534 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2538 net = sctp_findnet(stcb, (struct sockaddr *)&paddri->spinfo_address);
2541 * We increment here since
2542 * sctp_findassociation_ep_addr() wil do a
2543 * decrement if it finds the stcb as long as
2544 * the locked tcb (last argument) is NOT a
2547 SCTP_INP_INCR_REF(inp);
2548 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddri->spinfo_address, &net, NULL, NULL);
2550 SCTP_INP_DECR_REF(inp);
2554 if ((stcb) && (net)) {
2555 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2556 /* It's unconfirmed */
2557 paddri->spinfo_state = SCTP_UNCONFIRMED;
2558 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2560 paddri->spinfo_state = SCTP_ACTIVE;
2563 paddri->spinfo_state = SCTP_INACTIVE;
2565 paddri->spinfo_cwnd = net->cwnd;
2566 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2567 paddri->spinfo_rto = net->RTO;
2568 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2569 paddri->spinfo_mtu = net->mtu;
2570 SCTP_TCB_UNLOCK(stcb);
2571 *optsize = sizeof(struct sctp_paddrinfo);
2574 SCTP_TCB_UNLOCK(stcb);
2576 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2581 case SCTP_PCB_STATUS:
2583 struct sctp_pcbinfo *spcb;
2585 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2586 sctp_fill_pcbinfo(spcb);
2587 *optsize = sizeof(struct sctp_pcbinfo);
2592 struct sctp_nets *net;
2593 struct sctp_status *sstat;
2595 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2596 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2599 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2604 * I think passing the state is fine since
2605 * sctp_constants.h will be available to the user
2608 sstat->sstat_state = stcb->asoc.state;
2609 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2610 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2611 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2613 * We can't include chunks that have been passed to
2614 * the socket layer. Only things in queue.
2616 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2617 stcb->asoc.cnt_on_all_streams);
2620 sstat->sstat_instrms = stcb->asoc.streamincnt;
2621 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2622 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2623 memcpy(&sstat->sstat_primary.spinfo_address,
2624 &stcb->asoc.primary_destination->ro._l_addr,
2625 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2626 net = stcb->asoc.primary_destination;
2627 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2629 * Again the user can get info from sctp_constants.h
2630 * for what the state of the network is.
2632 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2633 /* It's unconfirmed */
2634 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2635 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2637 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2640 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2642 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2643 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2644 sstat->sstat_primary.spinfo_rto = net->RTO;
2645 sstat->sstat_primary.spinfo_mtu = net->mtu;
2646 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2647 SCTP_TCB_UNLOCK(stcb);
2648 *optsize = sizeof(struct sctp_status);
2653 struct sctp_rtoinfo *srto;
2655 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2656 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2659 srto->srto_initial = stcb->asoc.initial_rto;
2660 srto->srto_max = stcb->asoc.maxrto;
2661 srto->srto_min = stcb->asoc.minrto;
2662 SCTP_TCB_UNLOCK(stcb);
2664 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2665 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2666 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2667 SCTP_INP_RLOCK(inp);
2668 srto->srto_initial = inp->sctp_ep.initial_rto;
2669 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2670 srto->srto_min = inp->sctp_ep.sctp_minrto;
2671 SCTP_INP_RUNLOCK(inp);
2673 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2678 *optsize = sizeof(struct sctp_rtoinfo);
2684 struct sctp_timeouts *stimo;
2686 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2687 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2690 stimo->stimo_init = stcb->asoc.timoinit;
2691 stimo->stimo_data = stcb->asoc.timodata;
2692 stimo->stimo_sack = stcb->asoc.timosack;
2693 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2694 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2695 stimo->stimo_cookie = stcb->asoc.timocookie;
2696 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2697 SCTP_TCB_UNLOCK(stcb);
2698 *optsize = sizeof(struct sctp_timeouts);
2700 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2705 case SCTP_ASSOCINFO:
2707 struct sctp_assocparams *sasoc;
2709 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2710 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2713 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2714 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2715 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2716 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2717 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2718 SCTP_TCB_UNLOCK(stcb);
2720 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2721 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2722 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2723 SCTP_INP_RLOCK(inp);
2724 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2725 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2726 sasoc->sasoc_number_peer_destinations = 0;
2727 sasoc->sasoc_peer_rwnd = 0;
2728 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2729 SCTP_INP_RUNLOCK(inp);
2731 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2736 *optsize = sizeof(struct sctp_assocparams);
2740 case SCTP_DEFAULT_SEND_PARAM:
2742 struct sctp_sndrcvinfo *s_info;
2744 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2745 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2748 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2749 SCTP_TCB_UNLOCK(stcb);
2751 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2752 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2753 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2754 SCTP_INP_RLOCK(inp);
2755 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2756 SCTP_INP_RUNLOCK(inp);
2758 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2763 *optsize = sizeof(struct sctp_sndrcvinfo);
2769 struct sctp_initmsg *sinit;
2771 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2772 SCTP_INP_RLOCK(inp);
2773 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2774 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2775 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2776 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2777 SCTP_INP_RUNLOCK(inp);
2778 *optsize = sizeof(struct sctp_initmsg);
2781 case SCTP_PRIMARY_ADDR:
2782 /* we allow a "get" operation on this */
2784 struct sctp_setprim *ssp;
2786 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2787 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2790 /* simply copy out the sockaddr_storage... */
2794 if (len > stcb->asoc.primary_destination->ro._l_addr.sa.sa_len)
2795 len = stcb->asoc.primary_destination->ro._l_addr.sa.sa_len;
2797 memcpy(&ssp->ssp_addr,
2798 &stcb->asoc.primary_destination->ro._l_addr,
2800 SCTP_TCB_UNLOCK(stcb);
2801 *optsize = sizeof(struct sctp_setprim);
2803 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2808 case SCTP_HMAC_IDENT:
2810 struct sctp_hmacalgo *shmac;
2811 sctp_hmaclist_t *hmaclist;
2815 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2817 SCTP_INP_RLOCK(inp);
2818 hmaclist = inp->sctp_ep.local_hmacs;
2819 if (hmaclist == NULL) {
2820 /* no HMACs to return */
2821 *optsize = sizeof(*shmac);
2822 SCTP_INP_RUNLOCK(inp);
2825 /* is there room for all of the hmac ids? */
2826 size = sizeof(*shmac) + (hmaclist->num_algo *
2827 sizeof(shmac->shmac_idents[0]));
2828 if ((size_t)(*optsize) < size) {
2829 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2831 SCTP_INP_RUNLOCK(inp);
2834 /* copy in the list */
2835 shmac->shmac_number_of_idents = hmaclist->num_algo;
2836 for (i = 0; i < hmaclist->num_algo; i++) {
2837 shmac->shmac_idents[i] = hmaclist->hmac[i];
2839 SCTP_INP_RUNLOCK(inp);
2843 case SCTP_AUTH_ACTIVE_KEY:
2845 struct sctp_authkeyid *scact;
2847 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2848 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2851 /* get the active key on the assoc */
2852 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2853 SCTP_TCB_UNLOCK(stcb);
2855 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2856 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2857 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2858 /* get the endpoint active key */
2859 SCTP_INP_RLOCK(inp);
2860 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2861 SCTP_INP_RUNLOCK(inp);
2863 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2868 *optsize = sizeof(struct sctp_authkeyid);
2872 case SCTP_LOCAL_AUTH_CHUNKS:
2874 struct sctp_authchunks *sac;
2875 sctp_auth_chklist_t *chklist = NULL;
2878 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2879 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2882 /* get off the assoc */
2883 chklist = stcb->asoc.local_auth_chunks;
2884 /* is there enough space? */
2885 size = sctp_auth_get_chklist_size(chklist);
2886 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2888 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2890 /* copy in the chunks */
2891 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2892 sac->gauth_number_of_chunks = (uint32_t) size;
2893 *optsize = sizeof(struct sctp_authchunks) + size;
2895 SCTP_TCB_UNLOCK(stcb);
2897 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2898 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2899 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2900 /* get off the endpoint */
2901 SCTP_INP_RLOCK(inp);
2902 chklist = inp->sctp_ep.local_auth_chunks;
2903 /* is there enough space? */
2904 size = sctp_auth_get_chklist_size(chklist);
2905 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2907 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2909 /* copy in the chunks */
2910 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2911 sac->gauth_number_of_chunks = (uint32_t) size;
2912 *optsize = sizeof(struct sctp_authchunks) + size;
2914 SCTP_INP_RUNLOCK(inp);
2916 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2922 case SCTP_PEER_AUTH_CHUNKS:
2924 struct sctp_authchunks *sac;
2925 sctp_auth_chklist_t *chklist = NULL;
2928 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2929 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2932 /* get off the assoc */
2933 chklist = stcb->asoc.peer_auth_chunks;
2934 /* is there enough space? */
2935 size = sctp_auth_get_chklist_size(chklist);
2936 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2938 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2940 /* copy in the chunks */
2941 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2942 sac->gauth_number_of_chunks = (uint32_t) size;
2943 *optsize = sizeof(struct sctp_authchunks) + size;
2945 SCTP_TCB_UNLOCK(stcb);
2947 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2954 struct sctp_event *event;
2955 uint32_t event_type;
2957 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2958 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
2960 switch (event->se_type) {
2961 case SCTP_ASSOC_CHANGE:
2962 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
2964 case SCTP_PEER_ADDR_CHANGE:
2965 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
2967 case SCTP_REMOTE_ERROR:
2968 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
2970 case SCTP_SEND_FAILED:
2971 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
2973 case SCTP_SHUTDOWN_EVENT:
2974 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
2976 case SCTP_ADAPTATION_INDICATION:
2977 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
2979 case SCTP_PARTIAL_DELIVERY_EVENT:
2980 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
2982 case SCTP_AUTHENTICATION_EVENT:
2983 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
2985 case SCTP_STREAM_RESET_EVENT:
2986 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
2988 case SCTP_SENDER_DRY_EVENT:
2989 event_type = SCTP_PCB_FLAGS_DRYEVNT;
2991 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
2993 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
2996 case SCTP_ASSOC_RESET_EVENT:
2997 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
2999 case SCTP_STREAM_CHANGE_EVENT:
3000 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3002 case SCTP_SEND_FAILED_EVENT:
3003 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3007 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3011 if (event_type > 0) {
3013 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3014 SCTP_TCB_UNLOCK(stcb);
3016 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3017 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3018 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3019 SCTP_INP_RLOCK(inp);
3020 event->se_on = sctp_is_feature_on(inp, event_type);
3021 SCTP_INP_RUNLOCK(inp);
3023 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3029 *optsize = sizeof(struct sctp_event);
3033 case SCTP_RECVRCVINFO:
3037 if (*optsize < sizeof(int)) {
3038 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3041 SCTP_INP_RLOCK(inp);
3042 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3043 SCTP_INP_RUNLOCK(inp);
3046 /* return the option value */
3047 *(int *)optval = onoff;
3048 *optsize = sizeof(int);
3052 case SCTP_RECVNXTINFO:
3056 if (*optsize < sizeof(int)) {
3057 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3060 SCTP_INP_RLOCK(inp);
3061 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3062 SCTP_INP_RUNLOCK(inp);
3065 /* return the option value */
3066 *(int *)optval = onoff;
3067 *optsize = sizeof(int);
3071 case SCTP_DEFAULT_SNDINFO:
3073 struct sctp_sndinfo *info;
3075 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3076 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3079 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3080 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3081 info->snd_flags &= 0xfff0;
3082 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3083 info->snd_context = stcb->asoc.def_send.sinfo_context;
3084 SCTP_TCB_UNLOCK(stcb);
3086 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3087 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3088 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3089 SCTP_INP_RLOCK(inp);
3090 info->snd_sid = inp->def_send.sinfo_stream;
3091 info->snd_flags = inp->def_send.sinfo_flags;
3092 info->snd_flags &= 0xfff0;
3093 info->snd_ppid = inp->def_send.sinfo_ppid;
3094 info->snd_context = inp->def_send.sinfo_context;
3095 SCTP_INP_RUNLOCK(inp);
3097 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3102 *optsize = sizeof(struct sctp_sndinfo);
3106 case SCTP_DEFAULT_PRINFO:
3108 struct sctp_default_prinfo *info;
3110 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3111 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3114 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3115 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3116 SCTP_TCB_UNLOCK(stcb);
3118 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3119 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3120 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3121 SCTP_INP_RLOCK(inp);
3122 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3123 info->pr_value = inp->def_send.sinfo_timetolive;
3124 SCTP_INP_RUNLOCK(inp);
3126 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3131 *optsize = sizeof(struct sctp_default_prinfo);
3135 case SCTP_PEER_ADDR_THLDS:
3137 struct sctp_paddrthlds *thlds;
3138 struct sctp_nets *net;
3140 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3141 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3145 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_address);
3148 * We increment here since
3149 * sctp_findassociation_ep_addr() wil do a
3150 * decrement if it finds the stcb as long as
3151 * the locked tcb (last argument) is NOT a
3154 SCTP_INP_INCR_REF(inp);
3155 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&thlds->spt_address, &net, NULL, NULL);
3157 SCTP_INP_DECR_REF(inp);
3160 if (stcb && (net == NULL)) {
3161 struct sockaddr *sa;
3163 sa = (struct sockaddr *)&thlds->spt_address;
3165 if (sa->sa_family == AF_INET) {
3166 struct sockaddr_in *sin;
3168 sin = (struct sockaddr_in *)sa;
3169 if (sin->sin_addr.s_addr) {
3171 SCTP_TCB_UNLOCK(stcb);
3172 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3178 if (sa->sa_family == AF_INET6) {
3179 struct sockaddr_in6 *sin6;
3181 sin6 = (struct sockaddr_in6 *)sa;
3182 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3184 SCTP_TCB_UNLOCK(stcb);
3185 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3191 error = EAFNOSUPPORT;
3192 SCTP_TCB_UNLOCK(stcb);
3193 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3199 thlds->spt_pathmaxrxt = net->failure_threshold;
3200 thlds->spt_pathpfthld = net->pf_threshold;
3202 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3203 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3205 thlds->spt_assoc_id = sctp_get_associd(stcb);
3206 SCTP_TCB_UNLOCK(stcb);
3208 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3209 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3210 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3211 /* Use endpoint defaults */
3212 SCTP_INP_RLOCK(inp);
3213 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3214 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3215 SCTP_INP_RUNLOCK(inp);
3217 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3222 *optsize = sizeof(struct sctp_paddrthlds);
3226 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3228 struct sctp_udpencaps *encaps;
3229 struct sctp_nets *net;
3231 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3232 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3235 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
3238 * We increment here since
3239 * sctp_findassociation_ep_addr() wil do a
3240 * decrement if it finds the stcb as long as
3241 * the locked tcb (last argument) is NOT a
3245 SCTP_INP_INCR_REF(inp);
3246 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
3248 SCTP_INP_DECR_REF(inp);
3251 if (stcb && (net == NULL)) {
3252 struct sockaddr *sa;
3254 sa = (struct sockaddr *)&encaps->sue_address;
3256 if (sa->sa_family == AF_INET) {
3257 struct sockaddr_in *sin;
3259 sin = (struct sockaddr_in *)sa;
3260 if (sin->sin_addr.s_addr) {
3262 SCTP_TCB_UNLOCK(stcb);
3263 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3269 if (sa->sa_family == AF_INET6) {
3270 struct sockaddr_in6 *sin6;
3272 sin6 = (struct sockaddr_in6 *)sa;
3273 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3275 SCTP_TCB_UNLOCK(stcb);
3276 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3282 error = EAFNOSUPPORT;
3283 SCTP_TCB_UNLOCK(stcb);
3284 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3290 encaps->sue_port = net->port;
3292 encaps->sue_port = stcb->asoc.port;
3294 SCTP_TCB_UNLOCK(stcb);
3296 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3297 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3298 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3299 SCTP_INP_RLOCK(inp);
3300 encaps->sue_port = inp->sctp_ep.port;
3301 SCTP_INP_RUNLOCK(inp);
3303 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3308 *optsize = sizeof(struct sctp_udpencaps);
3312 case SCTP_ENABLE_STREAM_RESET:
3314 struct sctp_assoc_value *av;
3316 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3317 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3320 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3321 SCTP_TCB_UNLOCK(stcb);
3323 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3324 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3325 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3326 SCTP_INP_RLOCK(inp);
3327 av->assoc_value = (uint32_t) inp->local_strreset_support;
3328 SCTP_INP_RUNLOCK(inp);
3330 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3335 *optsize = sizeof(struct sctp_assoc_value);
3340 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3341 error = ENOPROTOOPT;
3343 } /* end switch (sopt->sopt_name) */
3351 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3356 struct sctp_tcb *stcb = NULL;
3357 struct sctp_inpcb *inp = NULL;
3360 if (optval == NULL) {
3361 SCTP_PRINTF("optval is NULL\n");
3362 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3365 inp = (struct sctp_inpcb *)so->so_pcb;
3367 SCTP_PRINTF("inp is NULL?\n");
3368 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3371 vrf_id = inp->def_vrf_id;
3376 case SCTP_AUTOCLOSE:
3377 case SCTP_AUTO_ASCONF:
3378 case SCTP_EXPLICIT_EOR:
3379 case SCTP_DISABLE_FRAGMENTS:
3380 case SCTP_USE_EXT_RCVINFO:
3381 case SCTP_I_WANT_MAPPED_V4_ADDR:
3382 /* copy in the option value */
3383 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3388 case SCTP_DISABLE_FRAGMENTS:
3389 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3391 case SCTP_AUTO_ASCONF:
3393 * NOTE: we don't really support this flag
3395 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3396 /* only valid for bound all sockets */
3397 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3399 /* forbidden by admin */
3400 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3403 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3405 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3409 case SCTP_EXPLICIT_EOR:
3410 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3412 case SCTP_USE_EXT_RCVINFO:
3413 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3415 case SCTP_I_WANT_MAPPED_V4_ADDR:
3416 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3417 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3419 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3424 set_opt = SCTP_PCB_FLAGS_NODELAY;
3426 case SCTP_AUTOCLOSE:
3427 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3428 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3429 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3432 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3434 * The value is in ticks. Note this does not effect
3435 * old associations, only new ones.
3437 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3440 SCTP_INP_WLOCK(inp);
3442 sctp_feature_on(inp, set_opt);
3444 sctp_feature_off(inp, set_opt);
3446 SCTP_INP_WUNLOCK(inp);
3448 case SCTP_REUSE_PORT:
3450 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3451 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3452 /* Can't set it after we are bound */
3456 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3457 /* Can't do this for a 1-m socket */
3462 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3464 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3467 case SCTP_PARTIAL_DELIVERY_POINT:
3471 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3472 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3473 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3477 inp->partial_delivery_point = *value;
3480 case SCTP_FRAGMENT_INTERLEAVE:
3481 /* not yet until we re-write sctp_recvmsg() */
3485 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3486 if (*level == SCTP_FRAG_LEVEL_2) {
3487 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3488 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3489 } else if (*level == SCTP_FRAG_LEVEL_1) {
3490 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3491 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3492 } else if (*level == SCTP_FRAG_LEVEL_0) {
3493 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3494 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3497 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3502 case SCTP_CMT_ON_OFF:
3503 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3504 struct sctp_assoc_value *av;
3506 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3507 if (av->assoc_value > SCTP_CMT_MAX) {
3508 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3512 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3514 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3515 SCTP_TCB_UNLOCK(stcb);
3517 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3518 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3519 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3520 (av->assoc_id == SCTP_ALL_ASSOC)) {
3521 SCTP_INP_WLOCK(inp);
3522 inp->sctp_cmt_on_off = av->assoc_value;
3523 SCTP_INP_WUNLOCK(inp);
3525 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3526 (av->assoc_id == SCTP_ALL_ASSOC)) {
3527 SCTP_INP_RLOCK(inp);
3528 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3529 SCTP_TCB_LOCK(stcb);
3530 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3531 SCTP_TCB_UNLOCK(stcb);
3533 SCTP_INP_RUNLOCK(inp);
3537 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3538 error = ENOPROTOOPT;
3541 case SCTP_PLUGGABLE_CC:
3543 struct sctp_assoc_value *av;
3544 struct sctp_nets *net;
3546 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3547 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3548 (av->assoc_value != SCTP_CC_HSTCP) &&
3549 (av->assoc_value != SCTP_CC_HTCP) &&
3550 (av->assoc_value != SCTP_CC_RTCC)) {
3551 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3555 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3557 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3558 stcb->asoc.congestion_control_module = av->assoc_value;
3559 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3560 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3561 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3564 SCTP_TCB_UNLOCK(stcb);
3566 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3567 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3568 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3569 (av->assoc_id == SCTP_ALL_ASSOC)) {
3570 SCTP_INP_WLOCK(inp);
3571 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3572 SCTP_INP_WUNLOCK(inp);
3574 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3575 (av->assoc_id == SCTP_ALL_ASSOC)) {
3576 SCTP_INP_RLOCK(inp);
3577 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3578 SCTP_TCB_LOCK(stcb);
3579 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3580 stcb->asoc.congestion_control_module = av->assoc_value;
3581 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3582 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3583 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3586 SCTP_TCB_UNLOCK(stcb);
3588 SCTP_INP_RUNLOCK(inp);
3593 case SCTP_CC_OPTION:
3595 struct sctp_cc_option *cc_opt;
3597 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
3598 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
3600 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
3601 SCTP_INP_RLOCK(inp);
3602 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3603 SCTP_TCB_LOCK(stcb);
3604 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
3605 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
3607 SCTP_TCB_UNLOCK(stcb);
3609 SCTP_INP_RUNLOCK(inp);
3614 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
3617 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
3620 SCTP_TCB_UNLOCK(stcb);
3624 case SCTP_PLUGGABLE_SS:
3626 struct sctp_assoc_value *av;
3628 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3629 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
3630 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
3631 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
3632 (av->assoc_value != SCTP_SS_PRIORITY) &&
3633 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
3634 (av->assoc_value != SCTP_SS_FIRST_COME)) {
3635 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3639 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3641 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3642 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3643 stcb->asoc.stream_scheduling_module = av->assoc_value;
3644 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3645 SCTP_TCB_UNLOCK(stcb);
3647 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3648 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3649 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3650 (av->assoc_id == SCTP_ALL_ASSOC)) {
3651 SCTP_INP_WLOCK(inp);
3652 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
3653 SCTP_INP_WUNLOCK(inp);
3655 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3656 (av->assoc_id == SCTP_ALL_ASSOC)) {
3657 SCTP_INP_RLOCK(inp);
3658 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3659 SCTP_TCB_LOCK(stcb);
3660 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3661 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3662 stcb->asoc.stream_scheduling_module = av->assoc_value;
3663 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3664 SCTP_TCB_UNLOCK(stcb);
3666 SCTP_INP_RUNLOCK(inp);
3673 struct sctp_stream_value *av;
3675 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
3676 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3678 if (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
3679 av->stream_value) < 0) {
3680 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3683 SCTP_TCB_UNLOCK(stcb);
3685 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
3686 SCTP_INP_RLOCK(inp);
3687 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3688 SCTP_TCB_LOCK(stcb);
3689 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
3691 &stcb->asoc.strmout[av->stream_id],
3693 SCTP_TCB_UNLOCK(stcb);
3695 SCTP_INP_RUNLOCK(inp);
3699 * Can't set stream value without
3702 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3708 case SCTP_CLR_STAT_LOG:
3709 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3714 struct sctp_assoc_value *av;
3716 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3717 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3720 stcb->asoc.context = av->assoc_value;
3721 SCTP_TCB_UNLOCK(stcb);
3723 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3724 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3725 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3726 (av->assoc_id == SCTP_ALL_ASSOC)) {
3727 SCTP_INP_WLOCK(inp);
3728 inp->sctp_context = av->assoc_value;
3729 SCTP_INP_WUNLOCK(inp);
3731 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3732 (av->assoc_id == SCTP_ALL_ASSOC)) {
3733 SCTP_INP_RLOCK(inp);
3734 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3735 SCTP_TCB_LOCK(stcb);
3736 stcb->asoc.context = av->assoc_value;
3737 SCTP_TCB_UNLOCK(stcb);
3739 SCTP_INP_RUNLOCK(inp);
3746 uint32_t *default_vrfid;
3748 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
3749 if (*default_vrfid > SCTP_MAX_VRF_ID) {
3750 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3754 inp->def_vrf_id = *default_vrfid;
3757 case SCTP_DEL_VRF_ID:
3759 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3763 case SCTP_ADD_VRF_ID:
3765 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3769 case SCTP_DELAYED_SACK:
3771 struct sctp_sack_info *sack;
3773 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
3774 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
3775 if (sack->sack_delay) {
3776 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
3777 sack->sack_delay = SCTP_MAX_SACK_DELAY;
3778 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
3779 sack->sack_delay = TICKS_TO_MSEC(1);
3783 if (sack->sack_delay) {
3784 stcb->asoc.delayed_ack = sack->sack_delay;
3786 if (sack->sack_freq) {
3787 stcb->asoc.sack_freq = sack->sack_freq;
3789 SCTP_TCB_UNLOCK(stcb);
3791 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3792 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3793 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
3794 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3795 SCTP_INP_WLOCK(inp);
3796 if (sack->sack_delay) {
3797 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
3799 if (sack->sack_freq) {
3800 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
3802 SCTP_INP_WUNLOCK(inp);
3804 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
3805 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3806 SCTP_INP_RLOCK(inp);
3807 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3808 SCTP_TCB_LOCK(stcb);
3809 if (sack->sack_delay) {
3810 stcb->asoc.delayed_ack = sack->sack_delay;
3812 if (sack->sack_freq) {
3813 stcb->asoc.sack_freq = sack->sack_freq;
3815 SCTP_TCB_UNLOCK(stcb);
3817 SCTP_INP_RUNLOCK(inp);
3822 case SCTP_AUTH_CHUNK:
3824 struct sctp_authchunk *sauth;
3826 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
3828 SCTP_INP_WLOCK(inp);
3829 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
3830 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3833 SCTP_INP_WUNLOCK(inp);
3838 struct sctp_authkey *sca;
3839 struct sctp_keyhead *shared_keys;
3840 sctp_sharedkey_t *shared_key;
3841 sctp_key_t *key = NULL;
3844 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
3845 if (sca->sca_keylength == 0) {
3846 size = optsize - sizeof(struct sctp_authkey);
3848 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
3849 size = sca->sca_keylength;
3851 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3856 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
3859 shared_keys = &stcb->asoc.shared_keys;
3860 /* clear the cached keys for this key id */
3861 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3863 * create the new shared key and
3867 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3869 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3871 SCTP_TCB_UNLOCK(stcb);
3875 shared_key = sctp_alloc_sharedkey();
3876 if (shared_key == NULL) {
3878 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3880 SCTP_TCB_UNLOCK(stcb);
3883 shared_key->key = key;
3884 shared_key->keyid = sca->sca_keynumber;
3885 error = sctp_insert_sharedkey(shared_keys, shared_key);
3886 SCTP_TCB_UNLOCK(stcb);
3888 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3889 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3890 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
3891 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3892 SCTP_INP_WLOCK(inp);
3893 shared_keys = &inp->sctp_ep.shared_keys;
3895 * clear the cached keys on all
3896 * assocs for this key id
3898 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
3900 * create the new shared key and
3904 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3906 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3908 SCTP_INP_WUNLOCK(inp);
3912 shared_key = sctp_alloc_sharedkey();
3913 if (shared_key == NULL) {
3915 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3917 SCTP_INP_WUNLOCK(inp);
3920 shared_key->key = key;
3921 shared_key->keyid = sca->sca_keynumber;
3922 error = sctp_insert_sharedkey(shared_keys, shared_key);
3923 SCTP_INP_WUNLOCK(inp);
3925 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
3926 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3927 SCTP_INP_RLOCK(inp);
3928 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3929 SCTP_TCB_LOCK(stcb);
3930 shared_keys = &stcb->asoc.shared_keys;
3932 * clear the cached keys for
3935 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3937 * create the new shared key
3938 * and insert/replace it
3941 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3943 SCTP_TCB_UNLOCK(stcb);
3947 shared_key = sctp_alloc_sharedkey();
3948 if (shared_key == NULL) {
3950 SCTP_TCB_UNLOCK(stcb);
3953 shared_key->key = key;
3954 shared_key->keyid = sca->sca_keynumber;
3955 error = sctp_insert_sharedkey(shared_keys, shared_key);
3956 SCTP_TCB_UNLOCK(stcb);
3958 SCTP_INP_RUNLOCK(inp);
3963 case SCTP_HMAC_IDENT:
3965 struct sctp_hmacalgo *shmac;
3966 sctp_hmaclist_t *hmaclist;
3970 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
3971 if (optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) {
3972 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3976 hmaclist = sctp_alloc_hmaclist(shmac->shmac_number_of_idents);
3977 if (hmaclist == NULL) {
3978 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3982 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
3983 hmacid = shmac->shmac_idents[i];
3984 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
3985 /* invalid HMACs were found */ ;
3986 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3988 sctp_free_hmaclist(hmaclist);
3989 goto sctp_set_hmac_done;
3992 for (i = 0; i < hmaclist->num_algo; i++) {
3993 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
3994 /* already in list */
3998 if (i == hmaclist->num_algo) {
3999 /* not found in list */
4000 sctp_free_hmaclist(hmaclist);
4001 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4005 /* set it on the endpoint */
4006 SCTP_INP_WLOCK(inp);
4007 if (inp->sctp_ep.local_hmacs)
4008 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4009 inp->sctp_ep.local_hmacs = hmaclist;
4010 SCTP_INP_WUNLOCK(inp);
4014 case SCTP_AUTH_ACTIVE_KEY:
4016 struct sctp_authkeyid *scact;
4018 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4019 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4021 /* set the active key on the right place */
4023 /* set the active key on the assoc */
4024 if (sctp_auth_setactivekey(stcb,
4025 scact->scact_keynumber)) {
4026 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4027 SCTP_FROM_SCTP_USRREQ,
4031 SCTP_TCB_UNLOCK(stcb);
4033 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4034 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4035 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4036 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4037 SCTP_INP_WLOCK(inp);
4038 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4039 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4042 SCTP_INP_WUNLOCK(inp);
4044 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4045 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4046 SCTP_INP_RLOCK(inp);
4047 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4048 SCTP_TCB_LOCK(stcb);
4049 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4050 SCTP_TCB_UNLOCK(stcb);
4052 SCTP_INP_RUNLOCK(inp);
4057 case SCTP_AUTH_DELETE_KEY:
4059 struct sctp_authkeyid *scdel;
4061 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4062 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4064 /* delete the key from the right place */
4066 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4067 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4070 SCTP_TCB_UNLOCK(stcb);
4072 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4073 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4074 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4075 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4076 SCTP_INP_WLOCK(inp);
4077 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4078 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4081 SCTP_INP_WUNLOCK(inp);
4083 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4084 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4085 SCTP_INP_RLOCK(inp);
4086 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4087 SCTP_TCB_LOCK(stcb);
4088 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4089 SCTP_TCB_UNLOCK(stcb);
4091 SCTP_INP_RUNLOCK(inp);
4096 case SCTP_AUTH_DEACTIVATE_KEY:
4098 struct sctp_authkeyid *keyid;
4100 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4101 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4103 /* deactivate the key from the right place */
4105 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4106 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4109 SCTP_TCB_UNLOCK(stcb);
4111 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4112 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4113 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4114 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4115 SCTP_INP_WLOCK(inp);
4116 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4117 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4120 SCTP_INP_WUNLOCK(inp);
4122 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4123 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4124 SCTP_INP_RLOCK(inp);
4125 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4126 SCTP_TCB_LOCK(stcb);
4127 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4128 SCTP_TCB_UNLOCK(stcb);
4130 SCTP_INP_RUNLOCK(inp);
4135 case SCTP_ENABLE_STREAM_RESET:
4137 struct sctp_assoc_value *av;
4139 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4140 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4141 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4145 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4147 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4148 SCTP_TCB_UNLOCK(stcb);
4150 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4151 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4152 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4153 (av->assoc_id == SCTP_ALL_ASSOC)) {
4154 SCTP_INP_WLOCK(inp);
4155 inp->local_strreset_support = (uint8_t) av->assoc_value;
4156 SCTP_INP_WUNLOCK(inp);
4158 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4159 (av->assoc_id == SCTP_ALL_ASSOC)) {
4160 SCTP_INP_RLOCK(inp);
4161 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4162 SCTP_TCB_LOCK(stcb);
4163 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4164 SCTP_TCB_UNLOCK(stcb);
4166 SCTP_INP_RUNLOCK(inp);
4171 case SCTP_RESET_STREAMS:
4173 struct sctp_reset_streams *strrst;
4174 int i, send_out = 0;
4177 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4178 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4180 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4184 if (stcb->asoc.peer_supports_strreset == 0) {
4186 * Peer does not support the chunk type.
4188 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4190 SCTP_TCB_UNLOCK(stcb);
4193 if (stcb->asoc.stream_reset_outstanding) {
4194 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4196 SCTP_TCB_UNLOCK(stcb);
4199 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4202 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4205 if ((send_in == 0) && (send_out == 0)) {
4206 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4208 SCTP_TCB_UNLOCK(stcb);
4211 for (i = 0; i < strrst->srs_number_streams; i++) {
4213 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4214 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4219 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4220 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4226 SCTP_TCB_UNLOCK(stcb);
4229 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4230 strrst->srs_stream_list,
4231 send_out, send_in, 0, 0, 0, 0, 0);
4233 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4234 SCTP_TCB_UNLOCK(stcb);
4237 case SCTP_ADD_STREAMS:
4239 struct sctp_add_streams *stradd;
4240 uint8_t addstream = 0;
4241 uint16_t add_o_strmcnt = 0;
4242 uint16_t add_i_strmcnt = 0;
4244 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4245 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4247 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4251 if (stcb->asoc.peer_supports_strreset == 0) {
4253 * Peer does not support the chunk type.
4255 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4257 SCTP_TCB_UNLOCK(stcb);
4260 if (stcb->asoc.stream_reset_outstanding) {
4261 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4263 SCTP_TCB_UNLOCK(stcb);
4266 if ((stradd->sas_outstrms == 0) &&
4267 (stradd->sas_instrms == 0)) {
4271 if (stradd->sas_outstrms) {
4273 /* We allocate here */
4274 add_o_strmcnt = stradd->sas_outstrms;
4275 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4276 /* You can't have more than 64k */
4281 if (stradd->sas_instrms) {
4286 * We allocate inside
4287 * sctp_send_str_reset_req()
4289 add_i_strmcnt = stradd->sas_instrms;
4290 cnt = add_i_strmcnt;
4291 cnt += stcb->asoc.streamincnt;
4292 if (cnt > 0x0000ffff) {
4293 /* You can't have more than 64k */
4297 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4298 /* More than you are allowed */
4303 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4304 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4306 SCTP_TCB_UNLOCK(stcb);
4309 case SCTP_RESET_ASSOC:
4313 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4314 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4316 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4320 if (stcb->asoc.peer_supports_strreset == 0) {
4322 * Peer does not support the chunk type.
4324 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4326 SCTP_TCB_UNLOCK(stcb);
4329 if (stcb->asoc.stream_reset_outstanding) {
4330 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4332 SCTP_TCB_UNLOCK(stcb);
4335 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 1, 0, 0, 0, 0);
4336 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4337 SCTP_TCB_UNLOCK(stcb);
4340 case SCTP_CONNECT_X:
4341 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4342 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4346 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4348 case SCTP_CONNECT_X_DELAYED:
4349 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4350 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4354 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4356 case SCTP_CONNECT_X_COMPLETE:
4358 struct sockaddr *sa;
4359 struct sctp_nets *net;
4361 /* FIXME MT: check correct? */
4362 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4365 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4366 SCTP_INP_RLOCK(inp);
4367 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4369 SCTP_TCB_LOCK(stcb);
4370 net = sctp_findnet(stcb, sa);
4372 SCTP_INP_RUNLOCK(inp);
4375 * We increment here since
4376 * sctp_findassociation_ep_addr() wil do a
4377 * decrement if it finds the stcb as long as
4378 * the locked tcb (last argument) is NOT a
4381 SCTP_INP_INCR_REF(inp);
4382 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
4384 SCTP_INP_DECR_REF(inp);
4389 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4393 if (stcb->asoc.delayed_connection == 1) {
4394 stcb->asoc.delayed_connection = 0;
4395 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4396 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4397 stcb->asoc.primary_destination,
4398 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
4399 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4402 * already expired or did not use delayed
4405 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4408 SCTP_TCB_UNLOCK(stcb);
4411 case SCTP_MAX_BURST:
4413 struct sctp_assoc_value *av;
4415 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4416 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4419 stcb->asoc.max_burst = av->assoc_value;
4420 SCTP_TCB_UNLOCK(stcb);
4422 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4423 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4424 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4425 (av->assoc_id == SCTP_ALL_ASSOC)) {
4426 SCTP_INP_WLOCK(inp);
4427 inp->sctp_ep.max_burst = av->assoc_value;
4428 SCTP_INP_WUNLOCK(inp);
4430 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4431 (av->assoc_id == SCTP_ALL_ASSOC)) {
4432 SCTP_INP_RLOCK(inp);
4433 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4434 SCTP_TCB_LOCK(stcb);
4435 stcb->asoc.max_burst = av->assoc_value;
4436 SCTP_TCB_UNLOCK(stcb);
4438 SCTP_INP_RUNLOCK(inp);
4445 struct sctp_assoc_value *av;
4448 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4449 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4451 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4452 ovh = SCTP_MED_OVERHEAD;
4454 ovh = SCTP_MED_V4_OVERHEAD;
4457 if (av->assoc_value) {
4458 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4460 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4462 SCTP_TCB_UNLOCK(stcb);
4464 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4465 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4466 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4467 SCTP_INP_WLOCK(inp);
4469 * FIXME MT: I think this is not in
4470 * tune with the API ID
4472 if (av->assoc_value) {
4473 inp->sctp_frag_point = (av->assoc_value + ovh);
4475 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4477 SCTP_INP_WUNLOCK(inp);
4479 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4487 struct sctp_event_subscribe *events;
4489 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4491 SCTP_INP_WLOCK(inp);
4492 if (events->sctp_data_io_event) {
4493 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4495 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4498 if (events->sctp_association_event) {
4499 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4501 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4504 if (events->sctp_address_event) {
4505 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4507 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4510 if (events->sctp_send_failure_event) {
4511 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4513 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4516 if (events->sctp_peer_error_event) {
4517 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4519 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4522 if (events->sctp_shutdown_event) {
4523 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4525 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4528 if (events->sctp_partial_delivery_event) {
4529 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4531 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4534 if (events->sctp_adaptation_layer_event) {
4535 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4537 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4540 if (events->sctp_authentication_event) {
4541 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4543 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4546 if (events->sctp_sender_dry_event) {
4547 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
4549 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
4552 if (events->sctp_stream_reset_event) {
4553 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4555 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4557 SCTP_INP_WUNLOCK(inp);
4559 SCTP_INP_RLOCK(inp);
4560 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4561 SCTP_TCB_LOCK(stcb);
4562 if (events->sctp_association_event) {
4563 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4565 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4567 if (events->sctp_address_event) {
4568 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4570 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4572 if (events->sctp_send_failure_event) {
4573 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4575 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4577 if (events->sctp_peer_error_event) {
4578 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4580 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4582 if (events->sctp_shutdown_event) {
4583 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4585 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4587 if (events->sctp_partial_delivery_event) {
4588 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4590 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4592 if (events->sctp_adaptation_layer_event) {
4593 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4595 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4597 if (events->sctp_authentication_event) {
4598 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4600 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4602 if (events->sctp_sender_dry_event) {
4603 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4605 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4607 if (events->sctp_stream_reset_event) {
4608 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4610 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4612 SCTP_TCB_UNLOCK(stcb);
4615 * Send up the sender dry event only for 1-to-1
4618 if (events->sctp_sender_dry_event) {
4619 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4620 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
4621 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4623 SCTP_TCB_LOCK(stcb);
4624 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
4625 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
4626 (stcb->asoc.stream_queue_cnt == 0)) {
4627 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
4629 SCTP_TCB_UNLOCK(stcb);
4633 SCTP_INP_RUNLOCK(inp);
4636 case SCTP_ADAPTATION_LAYER:
4638 struct sctp_setadaptation *adap_bits;
4640 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
4641 SCTP_INP_WLOCK(inp);
4642 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
4643 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
4644 SCTP_INP_WUNLOCK(inp);
4648 case SCTP_SET_INITIAL_DBG_SEQ:
4652 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
4653 SCTP_INP_WLOCK(inp);
4654 inp->sctp_ep.initial_sequence_debug = *vvv;
4655 SCTP_INP_WUNLOCK(inp);
4659 case SCTP_DEFAULT_SEND_PARAM:
4661 struct sctp_sndrcvinfo *s_info;
4663 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
4664 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
4667 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4668 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4670 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4673 SCTP_TCB_UNLOCK(stcb);
4675 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4676 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4677 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
4678 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4679 SCTP_INP_WLOCK(inp);
4680 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
4681 SCTP_INP_WUNLOCK(inp);
4683 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
4684 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4685 SCTP_INP_RLOCK(inp);
4686 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4687 SCTP_TCB_LOCK(stcb);
4688 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4689 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4691 SCTP_TCB_UNLOCK(stcb);
4693 SCTP_INP_RUNLOCK(inp);
4698 case SCTP_PEER_ADDR_PARAMS:
4700 struct sctp_paddrparams *paddrp;
4701 struct sctp_nets *net;
4703 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
4704 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
4707 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
4710 * We increment here since
4711 * sctp_findassociation_ep_addr() wil do a
4712 * decrement if it finds the stcb as long as
4713 * the locked tcb (last argument) is NOT a
4716 SCTP_INP_INCR_REF(inp);
4717 stcb = sctp_findassociation_ep_addr(&inp,
4718 (struct sockaddr *)&paddrp->spp_address,
4721 SCTP_INP_DECR_REF(inp);
4724 if (stcb && (net == NULL)) {
4725 struct sockaddr *sa;
4727 sa = (struct sockaddr *)&paddrp->spp_address;
4729 if (sa->sa_family == AF_INET) {
4731 struct sockaddr_in *sin;
4733 sin = (struct sockaddr_in *)sa;
4734 if (sin->sin_addr.s_addr) {
4735 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4736 SCTP_TCB_UNLOCK(stcb);
4743 if (sa->sa_family == AF_INET6) {
4744 struct sockaddr_in6 *sin6;
4746 sin6 = (struct sockaddr_in6 *)sa;
4747 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
4748 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4749 SCTP_TCB_UNLOCK(stcb);
4756 error = EAFNOSUPPORT;
4757 SCTP_TCB_UNLOCK(stcb);
4758 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4763 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
4765 SCTP_TCB_UNLOCK(stcb);
4766 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4769 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
4771 SCTP_TCB_UNLOCK(stcb);
4772 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4776 /************************TCB SPECIFIC SET ******************/
4778 * do we change the timer for HB, we run
4783 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4784 ovh = SCTP_MED_OVERHEAD;
4786 ovh = SCTP_MED_V4_OVERHEAD;
4789 /* network sets ? */
4791 /************************NET SPECIFIC SET ******************/
4792 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4793 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
4794 !(net->dest_state & SCTP_ADDR_NOHB)) {
4795 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4796 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4798 net->dest_state |= SCTP_ADDR_NOHB;
4800 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4801 if (paddrp->spp_hbinterval) {
4802 net->heart_beat_delay = paddrp->spp_hbinterval;
4803 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4804 net->heart_beat_delay = 0;
4806 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4807 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4808 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4809 net->dest_state &= ~SCTP_ADDR_NOHB;
4811 if (paddrp->spp_flags & SPP_HB_DEMAND) {
4813 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4814 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
4815 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4817 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4818 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4819 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4820 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4822 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4823 net->mtu = paddrp->spp_pathmtu + ovh;
4824 if (net->mtu < stcb->asoc.smallest_mtu) {
4825 sctp_pathmtu_adjustment(stcb, net->mtu);
4828 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4829 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4830 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4832 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4834 if (paddrp->spp_pathmaxrxt) {
4835 if (net->dest_state & SCTP_ADDR_PF) {
4836 if (net->error_count > paddrp->spp_pathmaxrxt) {
4837 net->dest_state &= ~SCTP_ADDR_PF;
4840 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4841 (net->error_count > net->pf_threshold)) {
4842 net->dest_state |= SCTP_ADDR_PF;
4843 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4844 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4845 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4848 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4849 if (net->error_count > paddrp->spp_pathmaxrxt) {
4850 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4851 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
4854 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4855 net->dest_state |= SCTP_ADDR_REACHABLE;
4856 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
4859 net->failure_threshold = paddrp->spp_pathmaxrxt;
4861 if (paddrp->spp_flags & SPP_DSCP) {
4862 net->dscp = paddrp->spp_dscp & 0xfc;
4866 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4867 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4868 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4869 net->flowlabel |= 0x80000000;
4874 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
4875 if (paddrp->spp_pathmaxrxt) {
4876 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
4877 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4878 if (net->dest_state & SCTP_ADDR_PF) {
4879 if (net->error_count > paddrp->spp_pathmaxrxt) {
4880 net->dest_state &= ~SCTP_ADDR_PF;
4883 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4884 (net->error_count > net->pf_threshold)) {
4885 net->dest_state |= SCTP_ADDR_PF;
4886 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4887 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4888 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4891 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4892 if (net->error_count > paddrp->spp_pathmaxrxt) {
4893 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4894 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
4897 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4898 net->dest_state |= SCTP_ADDR_REACHABLE;
4899 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
4902 net->failure_threshold = paddrp->spp_pathmaxrxt;
4905 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4906 if (paddrp->spp_hbinterval) {
4907 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
4908 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4909 stcb->asoc.heart_beat_delay = 0;
4911 /* Turn back on the timer */
4912 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4913 if (paddrp->spp_hbinterval) {
4914 net->heart_beat_delay = paddrp->spp_hbinterval;
4915 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4916 net->heart_beat_delay = 0;
4918 if (net->dest_state & SCTP_ADDR_NOHB) {
4919 net->dest_state &= ~SCTP_ADDR_NOHB;
4921 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4922 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4923 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4925 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4927 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4928 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4929 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
4930 net->dest_state |= SCTP_ADDR_NOHB;
4931 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
4932 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4936 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4938 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4939 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4940 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4941 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4942 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4944 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4945 net->mtu = paddrp->spp_pathmtu + ovh;
4946 if (net->mtu < stcb->asoc.smallest_mtu) {
4947 sctp_pathmtu_adjustment(stcb, net->mtu);
4950 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4952 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4953 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4954 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4955 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4957 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4959 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4961 if (paddrp->spp_flags & SPP_DSCP) {
4962 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4963 net->dscp = paddrp->spp_dscp & 0xfc;
4966 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
4967 stcb->asoc.default_dscp |= 0x01;
4970 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4971 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4972 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4973 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4974 net->flowlabel |= 0x80000000;
4977 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4978 stcb->asoc.default_flowlabel |= 0x80000000;
4982 SCTP_TCB_UNLOCK(stcb);
4984 /************************NO TCB, SET TO default stuff ******************/
4985 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4986 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4987 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
4988 SCTP_INP_WLOCK(inp);
4990 * For the TOS/FLOWLABEL stuff you
4991 * set it with the options on the
4994 if (paddrp->spp_pathmaxrxt) {
4995 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
4997 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
4998 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4999 else if (paddrp->spp_hbinterval) {
5000 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5001 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5002 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5004 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5005 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5006 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5007 } else if (paddrp->spp_hbinterval) {
5008 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5010 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5011 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5012 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5014 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5015 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5016 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5017 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5019 if (paddrp->spp_flags & SPP_DSCP) {
5020 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5021 inp->sctp_ep.default_dscp |= 0x01;
5024 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5025 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5026 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5027 inp->sctp_ep.default_flowlabel |= 0x80000000;
5031 SCTP_INP_WUNLOCK(inp);
5033 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5041 struct sctp_rtoinfo *srto;
5042 uint32_t new_init, new_min, new_max;
5044 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5045 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5048 if (srto->srto_initial)
5049 new_init = srto->srto_initial;
5051 new_init = stcb->asoc.initial_rto;
5053 new_max = srto->srto_max;
5055 new_max = stcb->asoc.maxrto;
5057 new_min = srto->srto_min;
5059 new_min = stcb->asoc.minrto;
5060 if ((new_min <= new_init) && (new_init <= new_max)) {
5061 stcb->asoc.initial_rto = new_init;
5062 stcb->asoc.maxrto = new_max;
5063 stcb->asoc.minrto = new_min;
5065 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5068 SCTP_TCB_UNLOCK(stcb);
5070 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5071 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5072 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5073 SCTP_INP_WLOCK(inp);
5074 if (srto->srto_initial)
5075 new_init = srto->srto_initial;
5077 new_init = inp->sctp_ep.initial_rto;
5079 new_max = srto->srto_max;
5081 new_max = inp->sctp_ep.sctp_maxrto;
5083 new_min = srto->srto_min;
5085 new_min = inp->sctp_ep.sctp_minrto;
5086 if ((new_min <= new_init) && (new_init <= new_max)) {
5087 inp->sctp_ep.initial_rto = new_init;
5088 inp->sctp_ep.sctp_maxrto = new_max;
5089 inp->sctp_ep.sctp_minrto = new_min;
5091 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5094 SCTP_INP_WUNLOCK(inp);
5096 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5102 case SCTP_ASSOCINFO:
5104 struct sctp_assocparams *sasoc;
5106 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5107 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5108 if (sasoc->sasoc_cookie_life) {
5109 /* boundary check the cookie life */
5110 if (sasoc->sasoc_cookie_life < 1000)
5111 sasoc->sasoc_cookie_life = 1000;
5112 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5113 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5117 if (sasoc->sasoc_asocmaxrxt)
5118 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5119 if (sasoc->sasoc_cookie_life) {
5120 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5122 SCTP_TCB_UNLOCK(stcb);
5124 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5125 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5126 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5127 SCTP_INP_WLOCK(inp);
5128 if (sasoc->sasoc_asocmaxrxt)
5129 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5130 if (sasoc->sasoc_cookie_life) {
5131 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5133 SCTP_INP_WUNLOCK(inp);
5135 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5143 struct sctp_initmsg *sinit;
5145 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5146 SCTP_INP_WLOCK(inp);
5147 if (sinit->sinit_num_ostreams)
5148 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5150 if (sinit->sinit_max_instreams)
5151 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5153 if (sinit->sinit_max_attempts)
5154 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5156 if (sinit->sinit_max_init_timeo)
5157 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5158 SCTP_INP_WUNLOCK(inp);
5161 case SCTP_PRIMARY_ADDR:
5163 struct sctp_setprim *spa;
5164 struct sctp_nets *net;
5166 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5167 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5171 net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
5174 * We increment here since
5175 * sctp_findassociation_ep_addr() wil do a
5176 * decrement if it finds the stcb as long as
5177 * the locked tcb (last argument) is NOT a
5180 SCTP_INP_INCR_REF(inp);
5181 stcb = sctp_findassociation_ep_addr(&inp,
5182 (struct sockaddr *)&spa->ssp_addr,
5185 SCTP_INP_DECR_REF(inp);
5189 if ((stcb) && (net)) {
5190 if ((net != stcb->asoc.primary_destination) &&
5191 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
5192 /* Ok we need to set it */
5193 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5194 if ((stcb->asoc.alternate) &&
5195 (!(net->dest_state & SCTP_ADDR_PF)) &&
5196 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5197 sctp_free_remote_addr(stcb->asoc.alternate);
5198 stcb->asoc.alternate = NULL;
5203 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5207 SCTP_TCB_UNLOCK(stcb);
5211 case SCTP_SET_DYNAMIC_PRIMARY:
5213 union sctp_sockstore *ss;
5215 error = priv_check(curthread,
5216 PRIV_NETINET_RESERVEDPORT);
5220 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5221 /* SUPER USER CHECK? */
5222 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5225 case SCTP_SET_PEER_PRIMARY_ADDR:
5227 struct sctp_setpeerprim *sspp;
5229 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5230 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5232 struct sctp_ifa *ifa;
5234 ifa = sctp_find_ifa_by_addr((struct sockaddr *)&sspp->sspp_addr,
5235 stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5237 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5241 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5243 * Must validate the ifa found is in
5246 struct sctp_laddr *laddr;
5249 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5250 if (laddr->ifa == NULL) {
5251 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5255 if (laddr->ifa == ifa) {
5261 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5266 if (sctp_set_primary_ip_address_sa(stcb,
5267 (struct sockaddr *)&sspp->sspp_addr) != 0) {
5268 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5272 SCTP_TCB_UNLOCK(stcb);
5274 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5279 case SCTP_BINDX_ADD_ADDR:
5281 struct sctp_getaddresses *addrs;
5284 td = (struct thread *)p;
5285 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5288 if (addrs->addr->sa_family == AF_INET) {
5289 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5290 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5294 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5295 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5301 if (addrs->addr->sa_family == AF_INET6) {
5302 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5303 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5307 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5308 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5309 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5315 error = EAFNOSUPPORT;
5318 sctp_bindx_add_address(so, inp, addrs->addr,
5319 addrs->sget_assoc_id, vrf_id,
5323 case SCTP_BINDX_REM_ADDR:
5325 struct sctp_getaddresses *addrs;
5328 td = (struct thread *)p;
5330 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5332 if (addrs->addr->sa_family == AF_INET) {
5333 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5334 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5338 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5339 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5345 if (addrs->addr->sa_family == AF_INET6) {
5346 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5347 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5352 (error = prison_local_ip6(td->td_ucred,
5353 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5354 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5355 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5361 error = EAFNOSUPPORT;
5364 sctp_bindx_delete_address(inp, addrs->addr,
5365 addrs->sget_assoc_id, vrf_id,
5371 struct sctp_event *event;
5372 uint32_t event_type;
5374 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5375 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5376 switch (event->se_type) {
5377 case SCTP_ASSOC_CHANGE:
5378 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5380 case SCTP_PEER_ADDR_CHANGE:
5381 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5383 case SCTP_REMOTE_ERROR:
5384 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5386 case SCTP_SEND_FAILED:
5387 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5389 case SCTP_SHUTDOWN_EVENT:
5390 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5392 case SCTP_ADAPTATION_INDICATION:
5393 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5395 case SCTP_PARTIAL_DELIVERY_EVENT:
5396 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5398 case SCTP_AUTHENTICATION_EVENT:
5399 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5401 case SCTP_STREAM_RESET_EVENT:
5402 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5404 case SCTP_SENDER_DRY_EVENT:
5405 event_type = SCTP_PCB_FLAGS_DRYEVNT;
5407 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
5409 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5412 case SCTP_ASSOC_RESET_EVENT:
5413 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
5415 case SCTP_STREAM_CHANGE_EVENT:
5416 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
5418 case SCTP_SEND_FAILED_EVENT:
5419 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
5423 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5427 if (event_type > 0) {
5430 sctp_stcb_feature_on(inp, stcb, event_type);
5431 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
5432 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5433 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5434 (stcb->asoc.stream_queue_cnt == 0)) {
5435 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5439 sctp_stcb_feature_off(inp, stcb, event_type);
5441 SCTP_TCB_UNLOCK(stcb);
5444 * We don't want to send up a storm
5445 * of events, so return an error for
5448 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
5449 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
5450 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
5451 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
5452 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
5453 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5457 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5458 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5459 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
5460 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5461 SCTP_INP_WLOCK(inp);
5463 sctp_feature_on(inp, event_type);
5465 sctp_feature_off(inp, event_type);
5467 SCTP_INP_WUNLOCK(inp);
5469 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
5470 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5471 SCTP_INP_RLOCK(inp);
5472 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5473 SCTP_TCB_LOCK(stcb);
5475 sctp_stcb_feature_on(inp, stcb, event_type);
5477 sctp_stcb_feature_off(inp, stcb, event_type);
5479 SCTP_TCB_UNLOCK(stcb);
5481 SCTP_INP_RUNLOCK(inp);
5487 case SCTP_RECVRCVINFO:
5491 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5492 SCTP_INP_WLOCK(inp);
5494 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5496 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5498 SCTP_INP_WUNLOCK(inp);
5501 case SCTP_RECVNXTINFO:
5505 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5506 SCTP_INP_WLOCK(inp);
5508 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5510 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5512 SCTP_INP_WUNLOCK(inp);
5515 case SCTP_DEFAULT_SNDINFO:
5517 struct sctp_sndinfo *info;
5520 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
5521 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
5524 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5525 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5526 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5527 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5528 stcb->asoc.def_send.sinfo_flags |= policy;
5529 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5530 stcb->asoc.def_send.sinfo_context = info->snd_context;
5532 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5535 SCTP_TCB_UNLOCK(stcb);
5537 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5538 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5539 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
5540 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5541 SCTP_INP_WLOCK(inp);
5542 inp->def_send.sinfo_stream = info->snd_sid;
5543 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
5544 inp->def_send.sinfo_flags = info->snd_flags;
5545 inp->def_send.sinfo_flags |= policy;
5546 inp->def_send.sinfo_ppid = info->snd_ppid;
5547 inp->def_send.sinfo_context = info->snd_context;
5548 SCTP_INP_WUNLOCK(inp);
5550 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
5551 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5552 SCTP_INP_RLOCK(inp);
5553 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5554 SCTP_TCB_LOCK(stcb);
5555 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5556 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5557 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5558 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5559 stcb->asoc.def_send.sinfo_flags |= policy;
5560 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5561 stcb->asoc.def_send.sinfo_context = info->snd_context;
5563 SCTP_TCB_UNLOCK(stcb);
5565 SCTP_INP_RUNLOCK(inp);
5570 case SCTP_DEFAULT_PRINFO:
5572 struct sctp_default_prinfo *info;
5574 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
5575 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
5577 if (PR_SCTP_INVALID_POLICY(info->pr_policy)) {
5578 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5583 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5584 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5585 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5586 SCTP_TCB_UNLOCK(stcb);
5588 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5589 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5590 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
5591 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5592 SCTP_INP_WLOCK(inp);
5593 inp->def_send.sinfo_flags &= 0xfff0;
5594 inp->def_send.sinfo_flags |= info->pr_policy;
5595 inp->def_send.sinfo_timetolive = info->pr_value;
5596 SCTP_INP_WUNLOCK(inp);
5598 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
5599 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5600 SCTP_INP_RLOCK(inp);
5601 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5602 SCTP_TCB_LOCK(stcb);
5603 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5604 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5605 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5606 SCTP_TCB_UNLOCK(stcb);
5608 SCTP_INP_RUNLOCK(inp);
5613 case SCTP_PEER_ADDR_THLDS:
5614 /* Applies to the specific association */
5616 struct sctp_paddrthlds *thlds;
5617 struct sctp_nets *net;
5619 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
5620 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
5623 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_assoc_id);
5626 * We increment here since
5627 * sctp_findassociation_ep_addr() wil do a
5628 * decrement if it finds the stcb as long as
5629 * the locked tcb (last argument) is NOT a
5632 SCTP_INP_INCR_REF(inp);
5633 stcb = sctp_findassociation_ep_addr(&inp,
5634 (struct sockaddr *)&thlds->spt_assoc_id,
5637 SCTP_INP_DECR_REF(inp);
5640 if (stcb && (net == NULL)) {
5641 struct sockaddr *sa;
5643 sa = (struct sockaddr *)&thlds->spt_assoc_id;
5645 if (sa->sa_family == AF_INET) {
5647 struct sockaddr_in *sin;
5649 sin = (struct sockaddr_in *)sa;
5650 if (sin->sin_addr.s_addr) {
5651 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5652 SCTP_TCB_UNLOCK(stcb);
5659 if (sa->sa_family == AF_INET6) {
5660 struct sockaddr_in6 *sin6;
5662 sin6 = (struct sockaddr_in6 *)sa;
5663 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5664 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5665 SCTP_TCB_UNLOCK(stcb);
5672 error = EAFNOSUPPORT;
5673 SCTP_TCB_UNLOCK(stcb);
5674 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5680 if (net->dest_state & SCTP_ADDR_PF) {
5681 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5682 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5683 net->dest_state &= ~SCTP_ADDR_PF;
5686 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5687 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5688 net->dest_state |= SCTP_ADDR_PF;
5689 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5690 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5691 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5694 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5695 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5696 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5697 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5700 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5701 net->dest_state |= SCTP_ADDR_REACHABLE;
5702 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5705 net->failure_threshold = thlds->spt_pathmaxrxt;
5706 net->pf_threshold = thlds->spt_pathpfthld;
5708 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5709 if (net->dest_state & SCTP_ADDR_PF) {
5710 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5711 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5712 net->dest_state &= ~SCTP_ADDR_PF;
5715 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5716 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5717 net->dest_state |= SCTP_ADDR_PF;
5718 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5719 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5720 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5723 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5724 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5725 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5726 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5729 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5730 net->dest_state |= SCTP_ADDR_REACHABLE;
5731 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5734 net->failure_threshold = thlds->spt_pathmaxrxt;
5735 net->pf_threshold = thlds->spt_pathpfthld;
5737 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
5738 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
5741 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5742 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5743 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
5744 SCTP_INP_WLOCK(inp);
5745 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
5746 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
5747 SCTP_INP_WUNLOCK(inp);
5749 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5755 case SCTP_REMOTE_UDP_ENCAPS_PORT:
5757 struct sctp_udpencaps *encaps;
5758 struct sctp_nets *net;
5760 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
5761 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
5763 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
5766 * We increment here since
5767 * sctp_findassociation_ep_addr() wil do a
5768 * decrement if it finds the stcb as long as
5769 * the locked tcb (last argument) is NOT a
5773 SCTP_INP_INCR_REF(inp);
5774 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
5776 SCTP_INP_DECR_REF(inp);
5779 if (stcb && (net == NULL)) {
5780 struct sockaddr *sa;
5782 sa = (struct sockaddr *)&encaps->sue_address;
5784 if (sa->sa_family == AF_INET) {
5786 struct sockaddr_in *sin;
5788 sin = (struct sockaddr_in *)sa;
5789 if (sin->sin_addr.s_addr) {
5790 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5791 SCTP_TCB_UNLOCK(stcb);
5798 if (sa->sa_family == AF_INET6) {
5799 struct sockaddr_in6 *sin6;
5801 sin6 = (struct sockaddr_in6 *)sa;
5802 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5803 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5804 SCTP_TCB_UNLOCK(stcb);
5811 error = EAFNOSUPPORT;
5812 SCTP_TCB_UNLOCK(stcb);
5813 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5819 net->port = encaps->sue_port;
5821 stcb->asoc.port = encaps->sue_port;
5823 SCTP_TCB_UNLOCK(stcb);
5825 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5826 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5827 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
5828 SCTP_INP_WLOCK(inp);
5829 inp->sctp_ep.port = encaps->sue_port;
5830 SCTP_INP_WUNLOCK(inp);
5832 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5839 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
5840 error = ENOPROTOOPT;
5842 } /* end switch (opt) */
5847 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
5849 void *optval = NULL;
5854 if (sopt->sopt_level != IPPROTO_SCTP) {
5855 /* wrong proto level... send back up to IP */
5857 if (INP_CHECK_SOCKAF(so, AF_INET6))
5858 error = ip6_ctloutput(so, sopt);
5860 #if defined(INET) && defined(INET6)
5864 error = ip_ctloutput(so, sopt);
5868 optsize = sopt->sopt_valsize;
5870 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
5871 if (optval == NULL) {
5872 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
5875 error = sooptcopyin(sopt, optval, optsize, optsize);
5877 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5881 p = (void *)sopt->sopt_td;
5882 if (sopt->sopt_dir == SOPT_SET) {
5883 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
5884 } else if (sopt->sopt_dir == SOPT_GET) {
5885 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
5887 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5890 if ((error == 0) && (optval != NULL)) {
5891 error = sooptcopyout(sopt, optval, optsize);
5892 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5893 } else if (optval != NULL) {
5894 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5902 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
5905 int create_lock_on = 0;
5907 struct sctp_inpcb *inp;
5908 struct sctp_tcb *stcb = NULL;
5910 inp = (struct sctp_inpcb *)so->so_pcb;
5912 /* I made the same as TCP since we are not setup? */
5913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5914 return (ECONNRESET);
5917 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5920 switch (addr->sa_family) {
5924 struct sockaddr_in6 *sin6p;
5926 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
5927 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5930 sin6p = (struct sockaddr_in6 *)addr;
5931 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
5932 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5941 struct sockaddr_in *sinp;
5943 if (addr->sa_len != sizeof(struct sockaddr_in)) {
5944 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5947 sinp = (struct sockaddr_in *)addr;
5948 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
5949 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5956 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
5957 return (EAFNOSUPPORT);
5959 SCTP_INP_INCR_REF(inp);
5960 SCTP_ASOC_CREATE_LOCK(inp);
5964 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
5965 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
5966 /* Should I really unlock ? */
5967 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
5972 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
5973 (addr->sa_family == AF_INET6)) {
5974 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5979 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
5980 SCTP_PCB_FLAGS_UNBOUND) {
5981 /* Bind a ephemeral port */
5982 error = sctp_inpcb_bind(so, NULL, NULL, p);
5987 /* Now do we connect? */
5988 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
5989 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
5990 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5994 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
5995 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
5996 /* We are already connected AND the TCP model */
5997 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6001 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6002 SCTP_INP_RLOCK(inp);
6003 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6004 SCTP_INP_RUNLOCK(inp);
6007 * We increment here since sctp_findassociation_ep_addr()
6008 * will do a decrement if it finds the stcb as long as the
6009 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6011 SCTP_INP_INCR_REF(inp);
6012 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6014 SCTP_INP_DECR_REF(inp);
6016 SCTP_TCB_UNLOCK(stcb);
6020 /* Already have or am bring up an association */
6021 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
6025 vrf_id = inp->def_vrf_id;
6026 /* We are GOOD to go */
6027 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
6029 /* Gak! no memory */
6032 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
6033 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
6034 /* Set the connected flag so we can queue data */
6037 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
6038 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
6040 /* initialize authentication parameters for the assoc */
6041 sctp_initialize_auth_params(inp, stcb);
6043 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
6044 SCTP_TCB_UNLOCK(stcb);
6046 if (create_lock_on) {
6047 SCTP_ASOC_CREATE_UNLOCK(inp);
6049 SCTP_INP_DECR_REF(inp);
6056 sctp_listen(struct socket *so, int backlog, struct thread *p)
6059 * Note this module depends on the protocol processing being called
6060 * AFTER any socket level flags and backlog are applied to the
6061 * socket. The traditional way that the socket flags are applied is
6062 * AFTER protocol processing. We have made a change to the
6063 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
6064 * place if the socket API for SCTP is to work properly.
6068 struct sctp_inpcb *inp;
6070 inp = (struct sctp_inpcb *)so->so_pcb;
6072 /* I made the same as TCP since we are not setup? */
6073 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6074 return (ECONNRESET);
6076 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
6077 /* See if we have a listener */
6078 struct sctp_inpcb *tinp;
6079 union sctp_sockstore store, *sp;
6082 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
6084 struct sctp_laddr *laddr;
6086 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6087 memcpy(&store, &laddr->ifa->address, sizeof(store));
6088 switch (sp->sa.sa_family) {
6091 sp->sin.sin_port = inp->sctp_lport;
6096 sp->sin6.sin6_port = inp->sctp_lport;
6102 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6103 if (tinp && (tinp != inp) &&
6104 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6105 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6106 (tinp->sctp_socket->so_qlimit)) {
6108 * we have a listener already and
6111 SCTP_INP_DECR_REF(tinp);
6112 return (EADDRINUSE);
6114 SCTP_INP_DECR_REF(tinp);
6118 /* Setup a local addr bound all */
6119 memset(&store, 0, sizeof(store));
6120 switch (sp->sa.sa_family) {
6123 store.sin.sin_port = inp->sctp_lport;
6128 sp->sin6.sin6_port = inp->sctp_lport;
6135 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
6136 store.sa.sa_family = AF_INET6;
6137 store.sa.sa_len = sizeof(struct sockaddr_in6);
6141 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
6142 store.sa.sa_family = AF_INET;
6143 store.sa.sa_len = sizeof(struct sockaddr_in);
6146 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6147 if (tinp && (tinp != inp) &&
6148 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6149 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6150 (tinp->sctp_socket->so_qlimit)) {
6152 * we have a listener already and its not
6155 SCTP_INP_DECR_REF(tinp);
6156 return (EADDRINUSE);
6158 SCTP_INP_DECR_REF(inp);
6162 SCTP_INP_RLOCK(inp);
6163 #ifdef SCTP_LOCK_LOGGING
6164 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
6165 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
6169 error = solisten_proto_check(so);
6172 SCTP_INP_RUNLOCK(inp);
6175 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
6176 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
6178 * The unlucky case - We are in the tcp pool with this guy.
6179 * - Someone else is in the main inp slot. - We must move
6180 * this guy (the listener) to the main slot - We must then
6181 * move the guy that was listener to the TCP Pool.
6183 if (sctp_swap_inpcb_for_listen(inp)) {
6187 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6188 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6189 /* We are already connected AND the TCP model */
6191 SCTP_INP_RUNLOCK(inp);
6193 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6194 return (EADDRINUSE);
6196 SCTP_INP_RUNLOCK(inp);
6197 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
6198 /* We must do a bind. */
6200 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
6201 /* bind error, probably perm */
6206 /* It appears for 7.0 and on, we must always call this. */
6207 solisten_proto(so, backlog);
6208 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6209 /* remove the ACCEPTCONN flag for one-to-many sockets */
6210 so->so_options &= ~SO_ACCEPTCONN;
6213 /* turning off listen */
6214 so->so_options &= ~SO_ACCEPTCONN;
6220 static int sctp_defered_wakeup_cnt = 0;
6223 sctp_accept(struct socket *so, struct sockaddr **addr)
6225 struct sctp_tcb *stcb;
6226 struct sctp_inpcb *inp;
6227 union sctp_sockstore store;
6233 inp = (struct sctp_inpcb *)so->so_pcb;
6236 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6237 return (ECONNRESET);
6239 SCTP_INP_RLOCK(inp);
6240 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6241 SCTP_INP_RUNLOCK(inp);
6242 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
6243 return (EOPNOTSUPP);
6245 if (so->so_state & SS_ISDISCONNECTED) {
6246 SCTP_INP_RUNLOCK(inp);
6247 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
6248 return (ECONNABORTED);
6250 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6252 SCTP_INP_RUNLOCK(inp);
6253 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6254 return (ECONNRESET);
6256 SCTP_TCB_LOCK(stcb);
6257 SCTP_INP_RUNLOCK(inp);
6258 store = stcb->asoc.primary_destination->ro._l_addr;
6259 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
6260 SCTP_TCB_UNLOCK(stcb);
6261 switch (store.sa.sa_family) {
6265 struct sockaddr_in *sin;
6267 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6270 sin->sin_family = AF_INET;
6271 sin->sin_len = sizeof(*sin);
6272 sin->sin_port = store.sin.sin_port;
6273 sin->sin_addr = store.sin.sin_addr;
6274 *addr = (struct sockaddr *)sin;
6281 struct sockaddr_in6 *sin6;
6283 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
6286 sin6->sin6_family = AF_INET6;
6287 sin6->sin6_len = sizeof(*sin6);
6288 sin6->sin6_port = store.sin6.sin6_port;
6289 sin6->sin6_addr = store.sin6.sin6_addr;
6290 if ((error = sa6_recoverscope(sin6)) != 0) {
6291 SCTP_FREE_SONAME(sin6);
6294 *addr = (struct sockaddr *)sin6;
6302 /* Wake any delayed sleep action */
6303 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
6304 SCTP_INP_WLOCK(inp);
6305 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
6306 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
6307 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
6308 SCTP_INP_WUNLOCK(inp);
6309 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
6310 if (sowriteable(inp->sctp_socket)) {
6311 sowwakeup_locked(inp->sctp_socket);
6313 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
6315 SCTP_INP_WLOCK(inp);
6317 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
6318 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
6319 SCTP_INP_WUNLOCK(inp);
6320 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
6321 if (soreadable(inp->sctp_socket)) {
6322 sctp_defered_wakeup_cnt++;
6323 sorwakeup_locked(inp->sctp_socket);
6325 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
6327 SCTP_INP_WLOCK(inp);
6329 SCTP_INP_WUNLOCK(inp);
6331 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
6332 SCTP_TCB_LOCK(stcb);
6333 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
6340 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
6342 struct sockaddr_in *sin;
6344 struct sctp_inpcb *inp;
6345 struct sctp_ifa *sctp_ifa;
6348 * Do the malloc first in case it blocks.
6350 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6353 sin->sin_family = AF_INET;
6354 sin->sin_len = sizeof(*sin);
6355 inp = (struct sctp_inpcb *)so->so_pcb;
6357 SCTP_FREE_SONAME(sin);
6358 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6359 return (ECONNRESET);
6361 SCTP_INP_RLOCK(inp);
6362 sin->sin_port = inp->sctp_lport;
6363 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
6364 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6365 struct sctp_tcb *stcb;
6366 struct sockaddr_in *sin_a;
6367 struct sctp_nets *net;
6370 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6376 SCTP_TCB_LOCK(stcb);
6377 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6378 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6380 /* this will make coverity happy */
6383 if (sin_a->sin_family == AF_INET) {
6388 if ((!fnd) || (sin_a == NULL)) {
6390 SCTP_TCB_UNLOCK(stcb);
6393 vrf_id = inp->def_vrf_id;
6394 sctp_ifa = sctp_source_address_selection(inp,
6396 (sctp_route_t *) & net->ro,
6399 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
6400 sctp_free_ifa(sctp_ifa);
6402 SCTP_TCB_UNLOCK(stcb);
6404 /* For the bound all case you get back 0 */
6406 sin->sin_addr.s_addr = 0;
6410 /* Take the first IPv4 address in the list */
6411 struct sctp_laddr *laddr;
6414 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6415 if (laddr->ifa->address.sa.sa_family == AF_INET) {
6416 struct sockaddr_in *sin_a;
6418 sin_a = (struct sockaddr_in *)&laddr->ifa->address.sa;
6419 sin->sin_addr = sin_a->sin_addr;
6425 SCTP_FREE_SONAME(sin);
6426 SCTP_INP_RUNLOCK(inp);
6427 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6431 SCTP_INP_RUNLOCK(inp);
6432 (*addr) = (struct sockaddr *)sin;
6437 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
6439 struct sockaddr_in *sin;
6441 struct sockaddr_in *sin_a;
6442 struct sctp_inpcb *inp;
6443 struct sctp_tcb *stcb;
6444 struct sctp_nets *net;
6446 /* Do the malloc first in case it blocks. */
6447 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6450 sin->sin_family = AF_INET;
6451 sin->sin_len = sizeof(*sin);
6453 inp = (struct sctp_inpcb *)so->so_pcb;
6454 if ((inp == NULL) ||
6455 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
6456 /* UDP type and listeners will drop out here */
6457 SCTP_FREE_SONAME(sin);
6458 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
6461 SCTP_INP_RLOCK(inp);
6462 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6464 SCTP_TCB_LOCK(stcb);
6466 SCTP_INP_RUNLOCK(inp);
6468 SCTP_FREE_SONAME(sin);
6469 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6470 return (ECONNRESET);
6473 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6474 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6475 if (sin_a->sin_family == AF_INET) {
6477 sin->sin_port = stcb->rport;
6478 sin->sin_addr = sin_a->sin_addr;
6482 SCTP_TCB_UNLOCK(stcb);
6484 /* No IPv4 address */
6485 SCTP_FREE_SONAME(sin);
6486 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6489 (*addr) = (struct sockaddr *)sin;
6493 struct pr_usrreqs sctp_usrreqs = {
6494 .pru_abort = sctp_abort,
6495 .pru_accept = sctp_accept,
6496 .pru_attach = sctp_attach,
6497 .pru_bind = sctp_bind,
6498 .pru_connect = sctp_connect,
6499 .pru_control = in_control,
6500 .pru_close = sctp_close,
6501 .pru_detach = sctp_close,
6502 .pru_sopoll = sopoll_generic,
6503 .pru_flush = sctp_flush,
6504 .pru_disconnect = sctp_disconnect,
6505 .pru_listen = sctp_listen,
6506 .pru_peeraddr = sctp_peeraddr,
6507 .pru_send = sctp_sendm,
6508 .pru_shutdown = sctp_shutdown,
6509 .pru_sockaddr = sctp_ingetaddr,
6510 .pru_sosend = sctp_sosend,
6511 .pru_soreceive = sctp_soreceive