2 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * a) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
12 * b) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the distribution.
16 * c) Neither the name of Cisco Systems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <netinet/sctp_os.h>
38 #include <netinet/sctp_pcb.h>
39 #include <netinet/sctp_header.h>
40 #include <netinet/sctp_var.h>
43 #include <netinet/sctp_sysctl.h>
44 #include <netinet/sctp_output.h>
45 #include <netinet/sctp_uio.h>
46 #include <netinet/sctp_asconf.h>
47 #include <netinet/sctputil.h>
48 #include <netinet/sctp_indata.h>
49 #include <netinet/sctp_timer.h>
50 #include <netinet/sctp_auth.h>
51 #include <netinet/sctp_bsd_addr.h>
52 #include <netinet/udp.h>
56 extern struct sctp_cc_functions sctp_cc_functions[];
57 extern struct sctp_ss_functions sctp_ss_functions[];
64 /* Initialize and modify the sysctled variables */
66 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
67 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
69 * Allow a user to take no more than 1/2 the number of clusters or
70 * the SB_MAX whichever is smaller for the send window.
72 sb_max_adj = (u_long)((u_quad_t) (SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
73 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
74 (((uint32_t) nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
76 * Now for the recv window, should we take the same amount? or
77 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
78 * now I will just copy.
80 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
81 SCTP_BASE_VAR(first_time) = 0;
82 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
84 #if defined(SCTP_PACKET_LOGGING)
85 SCTP_BASE_VAR(packet_log_writers) = 0;
86 SCTP_BASE_VAR(packet_log_end) = 0;
87 bzero(&SCTP_BASE_VAR(packet_log_buffer), SCTP_PACKET_LOG_SIZE);
100 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
102 struct sctp_tmit_chunk *chk;
105 /* Adjust that too */
106 stcb->asoc.smallest_mtu = nxtsz;
107 /* now off to subtract IP_DF flag if needed */
108 overhead = IP_HDR_SIZE;
109 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
110 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
112 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
113 if ((chk->send_size + overhead) > nxtsz) {
114 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
117 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
118 if ((chk->send_size + overhead) > nxtsz) {
120 * For this guy we also mark for immediate resend
121 * since we sent to big of chunk
123 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
124 if (chk->sent < SCTP_DATAGRAM_RESEND) {
125 sctp_flight_size_decrease(chk);
126 sctp_total_flight_decrease(stcb, chk);
128 if (chk->sent != SCTP_DATAGRAM_RESEND) {
129 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
131 chk->sent = SCTP_DATAGRAM_RESEND;
132 chk->rec.data.doing_fast_retransmit = 0;
133 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
134 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
135 chk->whoTo->flight_size,
137 (uintptr_t) chk->whoTo,
138 chk->rec.data.TSN_seq);
140 /* Clear any time so NO RTT is being done */
148 sctp_notify_mbuf(struct sctp_inpcb *inp,
149 struct sctp_tcb *stcb,
150 struct sctp_nets *net,
155 int totsz, tmr_stopped = 0;
159 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
160 (ip == NULL) || (sh == NULL)) {
162 SCTP_TCB_UNLOCK(stcb);
166 /* First job is to verify the vtag matches what I would send */
167 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
168 SCTP_TCB_UNLOCK(stcb);
171 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
173 if (icmph->icmp_type != ICMP_UNREACH) {
174 /* We only care about unreachable */
175 SCTP_TCB_UNLOCK(stcb);
178 if (icmph->icmp_code != ICMP_UNREACH_NEEDFRAG) {
179 /* not a unreachable message due to frag. */
180 SCTP_TCB_UNLOCK(stcb);
185 nxtsz = ntohs(icmph->icmp_nextmtu);
188 * old type router that does not tell us what the next size
189 * mtu is. Rats we will have to guess (in a educated fashion
192 nxtsz = sctp_get_prev_mtu(totsz);
194 /* Stop any PMTU timer */
195 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
197 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
198 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
200 /* Adjust destination size limit */
201 if (net->mtu > nxtsz) {
204 net->mtu -= sizeof(struct udphdr);
207 /* now what about the ep? */
208 if (stcb->asoc.smallest_mtu > nxtsz) {
209 sctp_pathmtu_adjustment(stcb, nxtsz);
212 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
214 SCTP_TCB_UNLOCK(stcb);
220 sctp_notify(struct sctp_inpcb *inp,
224 struct sctp_tcb *stcb,
225 struct sctp_nets *net)
227 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
234 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
235 (sh == NULL) || (to == NULL)) {
237 SCTP_TCB_UNLOCK(stcb);
240 /* First job is to verify the vtag matches what I would send */
241 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
242 SCTP_TCB_UNLOCK(stcb);
245 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
247 if (icmph->icmp_type != ICMP_UNREACH) {
248 /* We only care about unreachable */
249 SCTP_TCB_UNLOCK(stcb);
252 if ((icmph->icmp_code == ICMP_UNREACH_NET) ||
253 (icmph->icmp_code == ICMP_UNREACH_HOST) ||
254 (icmph->icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
255 (icmph->icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
256 (icmph->icmp_code == ICMP_UNREACH_ISOLATED) ||
257 (icmph->icmp_code == ICMP_UNREACH_NET_PROHIB) ||
258 (icmph->icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
259 (icmph->icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
262 * Hmm reachablity problems we must examine closely. If its
263 * not reachable, we may have lost a network. Or if there is
264 * NO protocol at the other end named SCTP. well we consider
267 if (net->dest_state & SCTP_ADDR_REACHABLE) {
268 /* Ok that destination is NOT reachable */
269 net->dest_state &= ~SCTP_ADDR_REACHABLE;
270 net->dest_state &= ~SCTP_ADDR_PF;
271 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
273 (void *)net, SCTP_SO_NOT_LOCKED);
275 SCTP_TCB_UNLOCK(stcb);
276 } else if ((icmph->icmp_code == ICMP_UNREACH_PROTOCOL) ||
277 (icmph->icmp_code == ICMP_UNREACH_PORT)) {
279 * Here the peer is either playing tricks on us, including
280 * an address that belongs to someone who does not support
281 * SCTP OR was a userland implementation that shutdown and
282 * now is dead. In either case treat it like a OOTB abort
285 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
286 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
287 so = SCTP_INP_SO(inp);
288 atomic_add_int(&stcb->asoc.refcnt, 1);
289 SCTP_TCB_UNLOCK(stcb);
290 SCTP_SOCKET_LOCK(so, 1);
292 atomic_subtract_int(&stcb->asoc.refcnt, 1);
294 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
295 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
296 SCTP_SOCKET_UNLOCK(so, 1);
297 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
299 /* no need to unlock here, since the TCB is gone */
301 SCTP_TCB_UNLOCK(stcb);
307 sctp_ctlinput(cmd, sa, vip)
316 /* FIX, for non-bsd is this right? */
317 vrf_id = SCTP_DEFAULT_VRFID;
318 if (sa->sa_family != AF_INET ||
319 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
322 if (PRC_IS_REDIRECT(cmd)) {
324 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
328 struct sctp_inpcb *inp = NULL;
329 struct sctp_tcb *stcb = NULL;
330 struct sctp_nets *net = NULL;
331 struct sockaddr_in to, from;
333 sh = (struct sctphdr *)((caddr_t)ip + (ip->ip_hl << 2));
334 bzero(&to, sizeof(to));
335 bzero(&from, sizeof(from));
336 from.sin_family = to.sin_family = AF_INET;
337 from.sin_len = to.sin_len = sizeof(to);
338 from.sin_port = sh->src_port;
339 from.sin_addr = ip->ip_src;
340 to.sin_port = sh->dest_port;
341 to.sin_addr = ip->ip_dst;
344 * 'to' holds the dest of the packet that failed to be sent.
345 * 'from' holds our local endpoint address. Thus we reverse
346 * the to and the from in the lookup.
348 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&to,
349 (struct sockaddr *)&from,
350 &inp, &net, 1, vrf_id);
351 if (stcb != NULL && inp && (inp->sctp_socket != NULL)) {
352 if (cmd != PRC_MSGSIZE) {
353 sctp_notify(inp, ip, sh,
354 (struct sockaddr *)&to, stcb,
357 /* handle possible ICMP size messages */
358 sctp_notify_mbuf(inp, stcb, net, ip, sh);
361 if ((stcb == NULL) && (inp != NULL)) {
362 /* reduce ref-count */
364 SCTP_INP_DECR_REF(inp);
365 SCTP_INP_WUNLOCK(inp);
368 SCTP_TCB_UNLOCK(stcb);
378 sctp_getcred(SYSCTL_HANDLER_ARGS)
381 struct sockaddr_in addrs[2];
382 struct sctp_inpcb *inp;
383 struct sctp_nets *net;
384 struct sctp_tcb *stcb;
388 /* FIX, for non-bsd is this right? */
389 vrf_id = SCTP_DEFAULT_VRFID;
391 error = priv_check(req->td, PRIV_NETINET_GETCRED);
396 error = SYSCTL_IN(req, addrs, sizeof(addrs));
400 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
402 &inp, &net, 1, vrf_id);
403 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
404 if ((inp != NULL) && (stcb == NULL)) {
405 /* reduce ref-count */
407 SCTP_INP_DECR_REF(inp);
410 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
414 SCTP_TCB_UNLOCK(stcb);
416 * We use the write lock here, only since in the error leg we need
417 * it. If we used RLOCK, then we would have to
418 * wlock/decr/unlock/rlock. Which in theory could create a hole.
419 * Better to use higher wlock.
423 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
425 SCTP_INP_WUNLOCK(inp);
428 cru2x(inp->sctp_socket->so_cred, &xuc);
429 SCTP_INP_WUNLOCK(inp);
430 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
435 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
436 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
441 sctp_abort(struct socket *so)
443 struct sctp_inpcb *inp;
446 inp = (struct sctp_inpcb *)so->so_pcb;
451 flags = inp->sctp_flags;
452 #ifdef SCTP_LOG_CLOSING
453 sctp_log_closing(inp, NULL, 17);
455 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
456 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
457 #ifdef SCTP_LOG_CLOSING
458 sctp_log_closing(inp, NULL, 16);
460 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
461 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
463 SCTP_SB_CLEAR(so->so_snd);
465 * same for the rcv ones, they are only here for the
468 SCTP_SB_CLEAR(so->so_rcv);
470 /* Now null out the reference, we are completely detached. */
474 flags = inp->sctp_flags;
475 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
476 goto sctp_must_try_again;
483 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
485 struct sctp_inpcb *inp;
486 struct inpcb *ip_inp;
488 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
495 inp = (struct sctp_inpcb *)so->so_pcb;
497 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
500 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
501 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
506 error = sctp_inpcb_alloc(so, vrf_id);
510 inp = (struct sctp_inpcb *)so->so_pcb;
512 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
513 ip_inp = &inp->ip_inp.inp;
514 ip_inp->inp_vflag |= INP_IPV4;
515 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
517 error = ipsec_init_policy(so, &ip_inp->inp_sp);
518 #ifdef SCTP_LOG_CLOSING
519 sctp_log_closing(inp, NULL, 17);
523 flags = inp->sctp_flags;
524 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
525 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
526 #ifdef SCTP_LOG_CLOSING
527 sctp_log_closing(inp, NULL, 15);
529 SCTP_INP_WUNLOCK(inp);
530 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
531 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
533 flags = inp->sctp_flags;
534 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
537 SCTP_INP_WUNLOCK(inp);
543 SCTP_INP_WUNLOCK(inp);
548 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
550 struct sctp_inpcb *inp;
552 inp = (struct sctp_inpcb *)so->so_pcb;
554 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
558 if ((addr->sa_family != AF_INET) ||
559 (addr->sa_len != sizeof(struct sockaddr_in))) {
560 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
564 return (sctp_inpcb_bind(so, addr, NULL, p));
569 sctp_close(struct socket *so)
571 struct sctp_inpcb *inp;
574 inp = (struct sctp_inpcb *)so->so_pcb;
579 * Inform all the lower layer assoc that we are done.
582 flags = inp->sctp_flags;
583 #ifdef SCTP_LOG_CLOSING
584 sctp_log_closing(inp, NULL, 17);
586 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
587 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
588 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
589 (so->so_rcv.sb_cc > 0)) {
590 #ifdef SCTP_LOG_CLOSING
591 sctp_log_closing(inp, NULL, 13);
593 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
594 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
596 #ifdef SCTP_LOG_CLOSING
597 sctp_log_closing(inp, NULL, 14);
599 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
600 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
603 * The socket is now detached, no matter what the state of
604 * the SCTP association.
607 SCTP_SB_CLEAR(so->so_snd);
609 * same for the rcv ones, they are only here for the
612 SCTP_SB_CLEAR(so->so_rcv);
614 /* Now null out the reference, we are completely detached. */
618 flags = inp->sctp_flags;
619 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
620 goto sctp_must_try_again;
628 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
629 struct mbuf *control, struct thread *p);
633 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
634 struct mbuf *control, struct thread *p)
636 struct sctp_inpcb *inp;
639 inp = (struct sctp_inpcb *)so->so_pcb;
642 sctp_m_freem(control);
645 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
649 /* Got to have an to address if we are NOT a connected socket */
650 if ((addr == NULL) &&
651 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
652 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
654 } else if (addr == NULL) {
655 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
656 error = EDESTADDRREQ;
659 sctp_m_freem(control);
665 if (addr->sa_family != AF_INET) {
666 /* must be a v4 address! */
667 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
670 sctp_m_freem(control);
673 error = EDESTADDRREQ;
678 /* now what about control */
681 SCTP_PRINTF("huh? control set?\n");
682 sctp_m_freem(inp->control);
685 inp->control = control;
689 SCTP_BUF_NEXT(inp->pkt_last) = m;
692 inp->pkt_last = inp->pkt = m;
695 /* FreeBSD uses a flag passed */
696 ((flags & PRUS_MORETOCOME) == 0)
699 * note with the current version this code will only be used
700 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
701 * re-defining sosend to use the sctp_sosend. One can
702 * optionally switch back to this code (by changing back the
703 * definitions) but this is not advisable. This code is used
704 * by FreeBSD when sending a file with sendfile() though.
708 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
718 sctp_disconnect(struct socket *so)
720 struct sctp_inpcb *inp;
722 inp = (struct sctp_inpcb *)so->so_pcb;
724 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
728 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
729 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
730 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
732 SCTP_INP_RUNLOCK(inp);
735 struct sctp_association *asoc;
736 struct sctp_tcb *stcb;
738 stcb = LIST_FIRST(&inp->sctp_asoc_list);
740 SCTP_INP_RUNLOCK(inp);
741 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
746 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
747 /* We are about to be freed, out of here */
748 SCTP_TCB_UNLOCK(stcb);
749 SCTP_INP_RUNLOCK(inp);
752 if (((so->so_options & SO_LINGER) &&
753 (so->so_linger == 0)) ||
754 (so->so_rcv.sb_cc > 0)) {
755 if (SCTP_GET_STATE(asoc) !=
756 SCTP_STATE_COOKIE_WAIT) {
757 /* Left with Data unread */
760 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_DONTWAIT, 1, MT_DATA);
766 struct sctp_paramhdr *ph;
768 ph = mtod(err, struct sctp_paramhdr *);
769 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
770 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
771 ph->param_length = htons(SCTP_BUF_LEN(err));
773 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
774 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
776 SCTP_INP_RUNLOCK(inp);
777 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
778 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
779 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
781 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
782 /* No unlock tcb assoc is gone */
785 if (TAILQ_EMPTY(&asoc->send_queue) &&
786 TAILQ_EMPTY(&asoc->sent_queue) &&
787 (asoc->stream_queue_cnt == 0)) {
788 /* there is nothing queued to send, so done */
789 if (asoc->locked_on_sending) {
792 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
793 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
794 /* only send SHUTDOWN 1st time thru */
795 struct sctp_nets *netp;
797 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
798 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
799 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
801 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
802 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
803 sctp_stop_timers_for_shutdown(stcb);
804 if (stcb->asoc.alternate) {
805 netp = stcb->asoc.alternate;
807 netp = stcb->asoc.primary_destination;
809 sctp_send_shutdown(stcb, netp);
810 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
811 stcb->sctp_ep, stcb, netp);
812 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
813 stcb->sctp_ep, stcb, netp);
814 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
818 * we still got (or just got) data to send,
819 * so set SHUTDOWN_PENDING
822 * XXX sockets draft says that SCTP_EOF
823 * should be sent with no data. currently,
824 * we will allow user data to be sent first
825 * and move to SHUTDOWN-PENDING
827 struct sctp_nets *netp;
829 if (stcb->asoc.alternate) {
830 netp = stcb->asoc.alternate;
832 netp = stcb->asoc.primary_destination;
835 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
836 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
838 if (asoc->locked_on_sending) {
839 /* Locked to send out the data */
840 struct sctp_stream_queue_pending *sp;
842 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
844 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
845 asoc->locked_on_sending->stream_no);
847 if ((sp->length == 0) && (sp->msg_is_complete == 0))
848 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
851 if (TAILQ_EMPTY(&asoc->send_queue) &&
852 TAILQ_EMPTY(&asoc->sent_queue) &&
853 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
857 op_err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr),
858 0, M_DONTWAIT, 1, MT_DATA);
864 struct sctp_paramhdr *ph;
866 SCTP_BUF_LEN(op_err) = sizeof(struct sctp_paramhdr);
867 ph = mtod(op_err, struct sctp_paramhdr *);
868 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
869 ph->param_length = htons(SCTP_BUF_LEN(op_err));
871 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
872 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
873 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
874 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
875 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
876 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
878 SCTP_INP_RUNLOCK(inp);
879 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
882 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
885 soisdisconnecting(so);
886 SCTP_TCB_UNLOCK(stcb);
887 SCTP_INP_RUNLOCK(inp);
892 /* UDP model does not support this */
893 SCTP_INP_RUNLOCK(inp);
894 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
900 sctp_flush(struct socket *so, int how)
903 * We will just clear out the values and let subsequent close clear
904 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
905 * they will not be able to read the data, the socket will block
906 * that from happening.
908 struct sctp_inpcb *inp;
910 inp = (struct sctp_inpcb *)so->so_pcb;
912 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
916 /* For the 1 to many model this does nothing */
917 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
918 SCTP_INP_RUNLOCK(inp);
921 SCTP_INP_RUNLOCK(inp);
922 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
924 * First make sure the sb will be happy, we don't use these
925 * except maybe the count
928 SCTP_INP_READ_LOCK(inp);
929 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
930 SCTP_INP_READ_UNLOCK(inp);
931 SCTP_INP_WUNLOCK(inp);
932 so->so_rcv.sb_cc = 0;
933 so->so_rcv.sb_mbcnt = 0;
934 so->so_rcv.sb_mb = NULL;
936 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
938 * First make sure the sb will be happy, we don't use these
939 * except maybe the count
941 so->so_snd.sb_cc = 0;
942 so->so_snd.sb_mbcnt = 0;
943 so->so_snd.sb_mb = NULL;
950 sctp_shutdown(struct socket *so)
952 struct sctp_inpcb *inp;
954 inp = (struct sctp_inpcb *)so->so_pcb;
956 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
960 /* For UDP model this is a invalid call */
961 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
962 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
963 /* Restore the flags that the soshutdown took away. */
964 SOCKBUF_LOCK(&so->so_rcv);
965 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
966 SOCKBUF_UNLOCK(&so->so_rcv);
967 /* This proc will wakeup for read and do nothing (I hope) */
968 SCTP_INP_RUNLOCK(inp);
969 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
973 * Ok if we reach here its the TCP model and it is either a SHUT_WR
974 * or SHUT_RDWR. This means we put the shutdown flag against it.
977 struct sctp_tcb *stcb;
978 struct sctp_association *asoc;
981 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
982 SCTP_INP_RUNLOCK(inp);
987 stcb = LIST_FIRST(&inp->sctp_asoc_list);
990 * Ok we hit the case that the shutdown call was
991 * made after an abort or something. Nothing to do
994 SCTP_INP_RUNLOCK(inp);
999 if (TAILQ_EMPTY(&asoc->send_queue) &&
1000 TAILQ_EMPTY(&asoc->sent_queue) &&
1001 (asoc->stream_queue_cnt == 0)) {
1002 if (asoc->locked_on_sending) {
1005 /* there is nothing queued to send, so I'm done... */
1006 if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) {
1007 /* only send SHUTDOWN the first time through */
1008 struct sctp_nets *netp;
1010 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
1011 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
1012 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1014 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
1015 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
1016 sctp_stop_timers_for_shutdown(stcb);
1017 if (stcb->asoc.alternate) {
1018 netp = stcb->asoc.alternate;
1020 netp = stcb->asoc.primary_destination;
1022 sctp_send_shutdown(stcb, netp);
1023 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1024 stcb->sctp_ep, stcb, netp);
1025 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1026 stcb->sctp_ep, stcb, netp);
1027 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
1031 * we still got (or just got) data to send, so set
1034 struct sctp_nets *netp;
1036 if (stcb->asoc.alternate) {
1037 netp = stcb->asoc.alternate;
1039 netp = stcb->asoc.primary_destination;
1042 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1043 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
1046 if (asoc->locked_on_sending) {
1047 /* Locked to send out the data */
1048 struct sctp_stream_queue_pending *sp;
1050 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
1052 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
1053 asoc->locked_on_sending->stream_no);
1055 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
1056 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
1060 if (TAILQ_EMPTY(&asoc->send_queue) &&
1061 TAILQ_EMPTY(&asoc->sent_queue) &&
1062 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1063 struct mbuf *op_err;
1066 op_err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr),
1067 0, M_DONTWAIT, 1, MT_DATA);
1069 /* Fill in the user initiated abort */
1070 struct sctp_paramhdr *ph;
1072 SCTP_BUF_LEN(op_err) = sizeof(struct sctp_paramhdr);
1073 ph = mtod(op_err, struct sctp_paramhdr *);
1074 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
1075 ph->param_length = htons(SCTP_BUF_LEN(op_err));
1077 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
1078 sctp_abort_an_association(stcb->sctp_ep, stcb,
1079 op_err, SCTP_SO_LOCKED);
1082 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1085 SCTP_TCB_UNLOCK(stcb);
1088 SCTP_INP_RUNLOCK(inp);
1093 * copies a "user" presentable address and removes embedded scope, etc.
1094 * returns 0 on success, 1 on error
1097 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1100 struct sockaddr_in6 lsa6;
1102 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1105 memcpy(ss, sa, sa->sa_len);
1112 * NOTE: assumes addr lock is held
1115 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1116 struct sctp_tcb *stcb,
1118 struct sockaddr_storage *sas,
1121 struct sctp_ifn *sctp_ifn;
1122 struct sctp_ifa *sctp_ifa;
1123 int loopback_scope, ipv4_local_scope, local_scope, site_scope;
1125 int ipv4_addr_legal, ipv6_addr_legal;
1126 struct sctp_vrf *vrf;
1133 /* Turn on all the appropriate scope */
1134 loopback_scope = stcb->asoc.scope.loopback_scope;
1135 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1136 local_scope = stcb->asoc.scope.local_scope;
1137 site_scope = stcb->asoc.scope.site_scope;
1138 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1139 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1141 /* Use generic values for endpoints. */
1143 ipv4_local_scope = 1;
1146 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1147 ipv6_addr_legal = 1;
1148 if (SCTP_IPV6_V6ONLY(inp)) {
1149 ipv4_addr_legal = 0;
1151 ipv4_addr_legal = 1;
1154 ipv6_addr_legal = 0;
1155 ipv4_addr_legal = 1;
1158 vrf = sctp_find_vrf(vrf_id);
1162 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1163 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1164 if ((loopback_scope == 0) &&
1165 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1166 /* Skip loopback if loopback_scope not set */
1169 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1172 * For the BOUND-ALL case, the list
1173 * associated with a TCB is Always
1174 * considered a reverse list.. i.e.
1175 * it lists addresses that are NOT
1176 * part of the association. If this
1177 * is one of those we must skip it.
1179 if (sctp_is_addr_restricted(stcb,
1184 switch (sctp_ifa->address.sa.sa_family) {
1187 if (ipv4_addr_legal) {
1188 struct sockaddr_in *sin;
1190 sin = (struct sockaddr_in *)&sctp_ifa->address.sa;
1191 if (sin->sin_addr.s_addr == 0) {
1199 if ((ipv4_local_scope == 0) &&
1200 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1204 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1205 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1206 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1207 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1208 actual += sizeof(struct sockaddr_in6);
1211 memcpy(sas, sin, sizeof(*sin));
1212 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1213 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1214 actual += sizeof(*sin);
1218 if (actual >= limit) {
1228 if (ipv6_addr_legal) {
1229 struct sockaddr_in6 *sin6;
1231 sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sa;
1232 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1240 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1241 if (local_scope == 0)
1243 if (sin6->sin6_scope_id == 0) {
1244 if (sa6_recoverscope(sin6) != 0)
1262 if ((site_scope == 0) &&
1263 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1266 memcpy(sas, sin6, sizeof(*sin6));
1267 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1268 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1269 actual += sizeof(*sin6);
1270 if (actual >= limit) {
1285 struct sctp_laddr *laddr;
1287 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1289 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1293 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1295 switch (laddr->ifa->address.sa.sa_family) {
1298 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1303 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1310 sas = (struct sockaddr_storage *)((caddr_t)sas +
1311 laddr->ifa->address.sa.sa_len);
1312 actual += laddr->ifa->address.sa.sa_len;
1313 if (actual >= limit) {
1322 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1323 struct sctp_tcb *stcb,
1325 struct sockaddr_storage *sas)
1329 SCTP_IPI_ADDR_RLOCK();
1330 /* fill up addresses for the endpoint's default vrf */
1331 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1333 SCTP_IPI_ADDR_RUNLOCK();
1338 * NOTE: assumes addr lock is held
1341 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1344 struct sctp_vrf *vrf = NULL;
1347 * In both sub-set bound an bound_all cases we return the MAXIMUM
1348 * number of addresses that you COULD get. In reality the sub-set
1349 * bound may have an exclusion list for a given TCB OR in the
1350 * bound-all case a TCB may NOT include the loopback or other
1351 * addresses as well.
1353 vrf = sctp_find_vrf(vrf_id);
1357 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1358 struct sctp_ifn *sctp_ifn;
1359 struct sctp_ifa *sctp_ifa;
1361 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1362 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1363 /* Count them if they are the right type */
1364 switch (sctp_ifa->address.sa.sa_family) {
1367 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1368 cnt += sizeof(struct sockaddr_in6);
1370 cnt += sizeof(struct sockaddr_in);
1375 cnt += sizeof(struct sockaddr_in6);
1384 struct sctp_laddr *laddr;
1386 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1387 switch (laddr->ifa->address.sa.sa_family) {
1390 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1391 cnt += sizeof(struct sockaddr_in6);
1393 cnt += sizeof(struct sockaddr_in);
1398 cnt += sizeof(struct sockaddr_in6);
1410 sctp_count_max_addresses(struct sctp_inpcb *inp)
1414 SCTP_IPI_ADDR_RLOCK();
1415 /* count addresses for the endpoint's default VRF */
1416 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1417 SCTP_IPI_ADDR_RUNLOCK();
1422 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1423 size_t optsize, void *p, int delay)
1426 int creat_lock_on = 0;
1427 struct sctp_tcb *stcb = NULL;
1428 struct sockaddr *sa;
1429 int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1431 int bad_addresses = 0;
1434 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1436 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1437 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1438 /* We are already connected AND the TCP model */
1439 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1440 return (EADDRINUSE);
1442 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1443 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1444 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1447 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1448 SCTP_INP_RLOCK(inp);
1449 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1450 SCTP_INP_RUNLOCK(inp);
1453 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1456 SCTP_INP_INCR_REF(inp);
1457 SCTP_ASOC_CREATE_LOCK(inp);
1459 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1460 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1461 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1465 totaddrp = (int *)optval;
1466 totaddr = *totaddrp;
1467 sa = (struct sockaddr *)(totaddrp + 1);
1468 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (optsize - sizeof(int)), &bad_addresses);
1469 if ((stcb != NULL) || bad_addresses) {
1470 /* Already have or am bring up an association */
1471 SCTP_ASOC_CREATE_UNLOCK(inp);
1474 SCTP_TCB_UNLOCK(stcb);
1475 if (bad_addresses == 0) {
1476 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1482 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1487 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1489 struct in6pcb *inp6;
1491 inp6 = (struct in6pcb *)inp;
1492 if (SCTP_IPV6_V6ONLY(inp6)) {
1494 * if IPV6_V6ONLY flag, ignore connections destined
1495 * to a v4 addr or v4-mapped addr
1497 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1503 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1504 SCTP_PCB_FLAGS_UNBOUND) {
1505 /* Bind a ephemeral port */
1506 error = sctp_inpcb_bind(so, NULL, NULL, p);
1511 /* FIX ME: do we want to pass in a vrf on the connect call? */
1512 vrf_id = inp->def_vrf_id;
1515 /* We are GOOD to go */
1516 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1520 /* Gak! no memory */
1523 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1524 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1525 /* Set the connected flag so we can queue data */
1528 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1529 /* move to second address */
1530 switch (sa->sa_family) {
1533 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1538 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1546 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1547 /* Fill in the return id */
1549 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1552 a_id = (sctp_assoc_t *) optval;
1553 *a_id = sctp_get_associd(stcb);
1555 /* initialize authentication parameters for the assoc */
1556 sctp_initialize_auth_params(inp, stcb);
1559 /* doing delayed connection */
1560 stcb->asoc.delayed_connection = 1;
1561 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1563 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1564 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1566 SCTP_TCB_UNLOCK(stcb);
1567 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1568 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1569 /* Set the connected flag so we can queue data */
1573 if (creat_lock_on) {
1574 SCTP_ASOC_CREATE_UNLOCK(inp);
1576 SCTP_INP_DECR_REF(inp);
1580 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1581 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1582 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1583 SCTP_INP_RLOCK(inp); \
1584 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1586 SCTP_TCB_LOCK(stcb); \
1588 SCTP_INP_RUNLOCK(inp); \
1589 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1590 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1591 if (stcb == NULL) { \
1592 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1602 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1603 if (size < sizeof(type)) { \
1604 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1608 destp = (type *)srcp; \
1613 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1616 struct sctp_inpcb *inp = NULL;
1618 struct sctp_tcb *stcb = NULL;
1620 if (optval == NULL) {
1621 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1624 inp = (struct sctp_inpcb *)so->so_pcb;
1626 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1633 case SCTP_AUTOCLOSE:
1634 case SCTP_EXPLICIT_EOR:
1635 case SCTP_AUTO_ASCONF:
1636 case SCTP_DISABLE_FRAGMENTS:
1637 case SCTP_I_WANT_MAPPED_V4_ADDR:
1638 case SCTP_USE_EXT_RCVINFO:
1639 SCTP_INP_RLOCK(inp);
1641 case SCTP_DISABLE_FRAGMENTS:
1642 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1644 case SCTP_I_WANT_MAPPED_V4_ADDR:
1645 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1647 case SCTP_AUTO_ASCONF:
1648 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1649 /* only valid for bound all sockets */
1650 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1652 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1657 case SCTP_EXPLICIT_EOR:
1658 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1661 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1663 case SCTP_USE_EXT_RCVINFO:
1664 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1666 case SCTP_AUTOCLOSE:
1667 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1668 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1674 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1675 error = ENOPROTOOPT;
1676 } /* end switch (sopt->sopt_name) */
1677 if (*optsize < sizeof(val)) {
1678 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1682 SCTP_INP_RUNLOCK(inp);
1684 /* return the option value */
1685 *(int *)optval = val;
1686 *optsize = sizeof(val);
1689 case SCTP_GET_PACKET_LOG:
1691 #ifdef SCTP_PACKET_LOGGING
1695 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1696 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1699 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1704 case SCTP_REUSE_PORT:
1708 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1709 /* Can't do this for a 1-m socket */
1713 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1714 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1715 *optsize = sizeof(uint32_t);
1718 case SCTP_PARTIAL_DELIVERY_POINT:
1722 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1723 *value = inp->partial_delivery_point;
1724 *optsize = sizeof(uint32_t);
1727 case SCTP_FRAGMENT_INTERLEAVE:
1731 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1732 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1733 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1734 *value = SCTP_FRAG_LEVEL_2;
1736 *value = SCTP_FRAG_LEVEL_1;
1739 *value = SCTP_FRAG_LEVEL_0;
1741 *optsize = sizeof(uint32_t);
1744 case SCTP_CMT_ON_OFF:
1746 struct sctp_assoc_value *av;
1748 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1749 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1751 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1752 SCTP_TCB_UNLOCK(stcb);
1754 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1755 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1756 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1757 SCTP_INP_RLOCK(inp);
1758 av->assoc_value = inp->sctp_cmt_on_off;
1759 SCTP_INP_RUNLOCK(inp);
1761 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1766 *optsize = sizeof(struct sctp_assoc_value);
1770 case SCTP_PLUGGABLE_CC:
1772 struct sctp_assoc_value *av;
1774 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1775 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1777 av->assoc_value = stcb->asoc.congestion_control_module;
1778 SCTP_TCB_UNLOCK(stcb);
1780 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1781 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1782 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1783 SCTP_INP_RLOCK(inp);
1784 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1785 SCTP_INP_RUNLOCK(inp);
1787 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1792 *optsize = sizeof(struct sctp_assoc_value);
1796 case SCTP_CC_OPTION:
1798 struct sctp_cc_option *cc_opt;
1800 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1801 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1805 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1808 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1809 *optsize = sizeof(struct sctp_cc_option);
1811 SCTP_TCB_UNLOCK(stcb);
1815 case SCTP_PLUGGABLE_SS:
1817 struct sctp_assoc_value *av;
1819 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1820 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1822 av->assoc_value = stcb->asoc.stream_scheduling_module;
1823 SCTP_TCB_UNLOCK(stcb);
1825 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1826 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1827 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1828 SCTP_INP_RLOCK(inp);
1829 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1830 SCTP_INP_RUNLOCK(inp);
1832 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1837 *optsize = sizeof(struct sctp_assoc_value);
1843 struct sctp_stream_value *av;
1845 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1846 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1848 if (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1849 &av->stream_value) < 0) {
1850 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1853 *optsize = sizeof(struct sctp_stream_value);
1855 SCTP_TCB_UNLOCK(stcb);
1858 * Can't get stream value without
1861 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1866 case SCTP_GET_ADDR_LEN:
1868 struct sctp_assoc_value *av;
1870 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1873 if (av->assoc_value == AF_INET) {
1874 av->assoc_value = sizeof(struct sockaddr_in);
1879 if (av->assoc_value == AF_INET6) {
1880 av->assoc_value = sizeof(struct sockaddr_in6);
1885 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1887 *optsize = sizeof(struct sctp_assoc_value);
1891 case SCTP_GET_ASSOC_NUMBER:
1893 uint32_t *value, cnt;
1895 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1897 SCTP_INP_RLOCK(inp);
1898 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1901 SCTP_INP_RUNLOCK(inp);
1903 *optsize = sizeof(uint32_t);
1906 case SCTP_GET_ASSOC_ID_LIST:
1908 struct sctp_assoc_ids *ids;
1909 unsigned int at, limit;
1911 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1913 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1914 SCTP_INP_RLOCK(inp);
1915 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1917 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1920 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1924 SCTP_INP_RUNLOCK(inp);
1926 ids->gaids_number_of_ids = at;
1927 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1933 struct sctp_assoc_value *av;
1935 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1936 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1939 av->assoc_value = stcb->asoc.context;
1940 SCTP_TCB_UNLOCK(stcb);
1942 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1943 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1944 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1945 SCTP_INP_RLOCK(inp);
1946 av->assoc_value = inp->sctp_context;
1947 SCTP_INP_RUNLOCK(inp);
1949 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1954 *optsize = sizeof(struct sctp_assoc_value);
1960 uint32_t *default_vrfid;
1962 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1963 *default_vrfid = inp->def_vrf_id;
1964 *optsize = sizeof(uint32_t);
1967 case SCTP_GET_ASOC_VRF:
1969 struct sctp_assoc_value *id;
1971 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1972 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1975 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1977 id->assoc_value = stcb->asoc.vrf_id;
1978 *optsize = sizeof(struct sctp_assoc_value);
1982 case SCTP_GET_VRF_IDS:
1984 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1988 case SCTP_GET_NONCE_VALUES:
1990 struct sctp_get_nonce_values *gnv;
1992 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1993 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1996 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1997 gnv->gn_local_tag = stcb->asoc.my_vtag;
1998 SCTP_TCB_UNLOCK(stcb);
1999 *optsize = sizeof(struct sctp_get_nonce_values);
2001 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2006 case SCTP_DELAYED_SACK:
2008 struct sctp_sack_info *sack;
2010 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2011 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2013 sack->sack_delay = stcb->asoc.delayed_ack;
2014 sack->sack_freq = stcb->asoc.sack_freq;
2015 SCTP_TCB_UNLOCK(stcb);
2017 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2018 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2019 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2020 SCTP_INP_RLOCK(inp);
2021 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2022 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2023 SCTP_INP_RUNLOCK(inp);
2025 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2030 *optsize = sizeof(struct sctp_sack_info);
2034 case SCTP_GET_SNDBUF_USE:
2036 struct sctp_sockstat *ss;
2038 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2039 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2042 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2043 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2044 stcb->asoc.size_on_all_streams);
2045 SCTP_TCB_UNLOCK(stcb);
2046 *optsize = sizeof(struct sctp_sockstat);
2048 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2053 case SCTP_MAX_BURST:
2057 SCTP_CHECK_AND_CAST(value, optval, uint8_t, *optsize);
2059 SCTP_INP_RLOCK(inp);
2060 if (inp->sctp_ep.max_burst < 256) {
2061 *value = inp->sctp_ep.max_burst;
2065 SCTP_INP_RUNLOCK(inp);
2066 *optsize = sizeof(uint8_t);
2071 struct sctp_assoc_value *av;
2074 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2075 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2078 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2079 SCTP_TCB_UNLOCK(stcb);
2081 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2082 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2083 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2084 SCTP_INP_RLOCK(inp);
2085 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2086 ovh = SCTP_MED_OVERHEAD;
2088 ovh = SCTP_MED_V4_OVERHEAD;
2090 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2091 av->assoc_value = 0;
2093 av->assoc_value = inp->sctp_frag_point - ovh;
2094 SCTP_INP_RUNLOCK(inp);
2096 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2101 *optsize = sizeof(struct sctp_assoc_value);
2105 case SCTP_GET_STAT_LOG:
2106 error = sctp_fill_stat_log(optval, optsize);
2110 struct sctp_event_subscribe *events;
2112 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2113 memset(events, 0, sizeof(struct sctp_event_subscribe));
2114 SCTP_INP_RLOCK(inp);
2115 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2116 events->sctp_data_io_event = 1;
2118 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2119 events->sctp_association_event = 1;
2121 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2122 events->sctp_address_event = 1;
2124 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2125 events->sctp_send_failure_event = 1;
2127 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2128 events->sctp_peer_error_event = 1;
2130 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2131 events->sctp_shutdown_event = 1;
2133 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2134 events->sctp_partial_delivery_event = 1;
2136 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2137 events->sctp_adaptation_layer_event = 1;
2139 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2140 events->sctp_authentication_event = 1;
2142 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2143 events->sctp_sender_dry_event = 1;
2145 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2146 events->sctp_stream_reset_event = 1;
2147 SCTP_INP_RUNLOCK(inp);
2148 *optsize = sizeof(struct sctp_event_subscribe);
2151 case SCTP_ADAPTATION_LAYER:
2155 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2157 SCTP_INP_RLOCK(inp);
2158 *value = inp->sctp_ep.adaptation_layer_indicator;
2159 SCTP_INP_RUNLOCK(inp);
2160 *optsize = sizeof(uint32_t);
2163 case SCTP_SET_INITIAL_DBG_SEQ:
2167 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2168 SCTP_INP_RLOCK(inp);
2169 *value = inp->sctp_ep.initial_sequence_debug;
2170 SCTP_INP_RUNLOCK(inp);
2171 *optsize = sizeof(uint32_t);
2174 case SCTP_GET_LOCAL_ADDR_SIZE:
2178 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2179 SCTP_INP_RLOCK(inp);
2180 *value = sctp_count_max_addresses(inp);
2181 SCTP_INP_RUNLOCK(inp);
2182 *optsize = sizeof(uint32_t);
2185 case SCTP_GET_REMOTE_ADDR_SIZE:
2189 struct sctp_nets *net;
2191 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2192 /* FIXME MT: change to sctp_assoc_value? */
2193 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2197 /* Count the sizes */
2198 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2199 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2200 size += sizeof(struct sockaddr_in6);
2202 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2205 size += sizeof(struct sockaddr_in);
2210 size += sizeof(struct sockaddr_in6);
2218 SCTP_TCB_UNLOCK(stcb);
2219 *value = (uint32_t) size;
2220 *optsize = sizeof(uint32_t);
2222 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2227 case SCTP_GET_PEER_ADDRESSES:
2229 * Get the address information, an array is passed in to
2230 * fill up we pack it.
2234 struct sockaddr_storage *sas;
2235 struct sctp_nets *net;
2236 struct sctp_getaddresses *saddr;
2238 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2239 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2242 left = (*optsize) - sizeof(struct sctp_getaddresses);
2243 *optsize = sizeof(struct sctp_getaddresses);
2244 sas = (struct sockaddr_storage *)&saddr->addr[0];
2246 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2247 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2248 cpsz = sizeof(struct sockaddr_in6);
2250 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2253 cpsz = sizeof(struct sockaddr_in);
2258 cpsz = sizeof(struct sockaddr_in6);
2270 /* not enough room. */
2273 #if defined(INET) && defined(INET6)
2274 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2275 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
2276 /* Must map the address */
2277 in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
2278 (struct sockaddr_in6 *)sas);
2281 memcpy(sas, &net->ro._l_addr, cpsz);
2282 #if defined(INET) && defined(INET6)
2285 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2287 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2291 SCTP_TCB_UNLOCK(stcb);
2293 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2298 case SCTP_GET_LOCAL_ADDRESSES:
2300 size_t limit, actual;
2301 struct sockaddr_storage *sas;
2302 struct sctp_getaddresses *saddr;
2304 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2305 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2307 sas = (struct sockaddr_storage *)&saddr->addr[0];
2308 limit = *optsize - sizeof(sctp_assoc_t);
2309 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2311 SCTP_TCB_UNLOCK(stcb);
2313 *optsize = sizeof(struct sockaddr_storage) + actual;
2316 case SCTP_PEER_ADDR_PARAMS:
2318 struct sctp_paddrparams *paddrp;
2319 struct sctp_nets *net;
2321 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2322 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2326 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2329 * We increment here since
2330 * sctp_findassociation_ep_addr() wil do a
2331 * decrement if it finds the stcb as long as
2332 * the locked tcb (last argument) is NOT a
2335 SCTP_INP_INCR_REF(inp);
2336 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddrp->spp_address, &net, NULL, NULL);
2338 SCTP_INP_DECR_REF(inp);
2341 if (stcb && (net == NULL)) {
2342 struct sockaddr *sa;
2344 sa = (struct sockaddr *)&paddrp->spp_address;
2346 if (sa->sa_family == AF_INET) {
2347 struct sockaddr_in *sin;
2349 sin = (struct sockaddr_in *)sa;
2350 if (sin->sin_addr.s_addr) {
2352 SCTP_TCB_UNLOCK(stcb);
2353 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2359 if (sa->sa_family == AF_INET6) {
2360 struct sockaddr_in6 *sin6;
2362 sin6 = (struct sockaddr_in6 *)sa;
2363 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2365 SCTP_TCB_UNLOCK(stcb);
2366 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2372 error = EAFNOSUPPORT;
2373 SCTP_TCB_UNLOCK(stcb);
2374 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2379 /* Applies to the specific association */
2380 paddrp->spp_flags = 0;
2384 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2385 ovh = SCTP_MED_OVERHEAD;
2387 ovh = SCTP_MED_V4_OVERHEAD;
2390 paddrp->spp_hbinterval = net->heart_beat_delay;
2391 paddrp->spp_pathmaxrxt = net->failure_threshold;
2392 paddrp->spp_pathmtu = net->mtu - ovh;
2393 /* get flags for HB */
2394 if (net->dest_state & SCTP_ADDR_NOHB) {
2395 paddrp->spp_flags |= SPP_HB_DISABLE;
2397 paddrp->spp_flags |= SPP_HB_ENABLE;
2399 /* get flags for PMTU */
2400 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2401 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2403 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2405 if (net->dscp & 0x01) {
2406 paddrp->spp_dscp = net->dscp & 0xfc;
2407 paddrp->spp_flags |= SPP_DSCP;
2410 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2411 (net->flowlabel & 0x80000000)) {
2412 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2413 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2418 * No destination so return default
2421 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2422 paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
2423 if (stcb->asoc.default_dscp & 0x01) {
2424 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2425 paddrp->spp_flags |= SPP_DSCP;
2428 if (stcb->asoc.default_flowlabel & 0x80000000) {
2429 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2430 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2433 /* default settings should be these */
2434 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2435 paddrp->spp_flags |= SPP_HB_DISABLE;
2437 paddrp->spp_flags |= SPP_HB_ENABLE;
2439 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2440 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2442 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2444 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2446 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2447 SCTP_TCB_UNLOCK(stcb);
2449 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2450 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2451 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2452 /* Use endpoint defaults */
2453 SCTP_INP_RLOCK(inp);
2454 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2455 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2456 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2457 /* get inp's default */
2458 if (inp->sctp_ep.default_dscp & 0x01) {
2459 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2460 paddrp->spp_flags |= SPP_DSCP;
2463 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2464 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2465 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2466 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2469 /* can't return this */
2470 paddrp->spp_pathmtu = 0;
2472 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2473 paddrp->spp_flags |= SPP_HB_ENABLE;
2475 paddrp->spp_flags |= SPP_HB_DISABLE;
2477 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2478 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2480 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2482 SCTP_INP_RUNLOCK(inp);
2484 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2489 *optsize = sizeof(struct sctp_paddrparams);
2493 case SCTP_GET_PEER_ADDR_INFO:
2495 struct sctp_paddrinfo *paddri;
2496 struct sctp_nets *net;
2498 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2499 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2503 net = sctp_findnet(stcb, (struct sockaddr *)&paddri->spinfo_address);
2506 * We increment here since
2507 * sctp_findassociation_ep_addr() wil do a
2508 * decrement if it finds the stcb as long as
2509 * the locked tcb (last argument) is NOT a
2512 SCTP_INP_INCR_REF(inp);
2513 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddri->spinfo_address, &net, NULL, NULL);
2515 SCTP_INP_DECR_REF(inp);
2519 if ((stcb) && (net)) {
2520 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2521 /* It's unconfirmed */
2522 paddri->spinfo_state = SCTP_UNCONFIRMED;
2523 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2525 paddri->spinfo_state = SCTP_ACTIVE;
2528 paddri->spinfo_state = SCTP_INACTIVE;
2530 paddri->spinfo_cwnd = net->cwnd;
2531 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2532 paddri->spinfo_rto = net->RTO;
2533 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2534 paddri->spinfo_mtu = net->mtu;
2535 SCTP_TCB_UNLOCK(stcb);
2536 *optsize = sizeof(struct sctp_paddrinfo);
2539 SCTP_TCB_UNLOCK(stcb);
2541 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2546 case SCTP_PCB_STATUS:
2548 struct sctp_pcbinfo *spcb;
2550 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2551 sctp_fill_pcbinfo(spcb);
2552 *optsize = sizeof(struct sctp_pcbinfo);
2557 struct sctp_nets *net;
2558 struct sctp_status *sstat;
2560 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2561 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2564 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2569 * I think passing the state is fine since
2570 * sctp_constants.h will be available to the user
2573 sstat->sstat_state = stcb->asoc.state;
2574 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2575 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2576 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2578 * We can't include chunks that have been passed to
2579 * the socket layer. Only things in queue.
2581 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2582 stcb->asoc.cnt_on_all_streams);
2585 sstat->sstat_instrms = stcb->asoc.streamincnt;
2586 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2587 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2588 memcpy(&sstat->sstat_primary.spinfo_address,
2589 &stcb->asoc.primary_destination->ro._l_addr,
2590 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2591 net = stcb->asoc.primary_destination;
2592 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2594 * Again the user can get info from sctp_constants.h
2595 * for what the state of the network is.
2597 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2598 /* It's unconfirmed */
2599 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2600 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2602 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2605 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2607 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2608 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2609 sstat->sstat_primary.spinfo_rto = net->RTO;
2610 sstat->sstat_primary.spinfo_mtu = net->mtu;
2611 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2612 SCTP_TCB_UNLOCK(stcb);
2613 *optsize = sizeof(struct sctp_status);
2618 struct sctp_rtoinfo *srto;
2620 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2621 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2624 srto->srto_initial = stcb->asoc.initial_rto;
2625 srto->srto_max = stcb->asoc.maxrto;
2626 srto->srto_min = stcb->asoc.minrto;
2627 SCTP_TCB_UNLOCK(stcb);
2629 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2630 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2631 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2632 SCTP_INP_RLOCK(inp);
2633 srto->srto_initial = inp->sctp_ep.initial_rto;
2634 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2635 srto->srto_min = inp->sctp_ep.sctp_minrto;
2636 SCTP_INP_RUNLOCK(inp);
2638 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2643 *optsize = sizeof(struct sctp_rtoinfo);
2649 struct sctp_timeouts *stimo;
2651 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2652 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2655 stimo->stimo_init = stcb->asoc.timoinit;
2656 stimo->stimo_data = stcb->asoc.timodata;
2657 stimo->stimo_sack = stcb->asoc.timosack;
2658 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2659 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2660 stimo->stimo_cookie = stcb->asoc.timocookie;
2661 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2662 SCTP_TCB_UNLOCK(stcb);
2663 *optsize = sizeof(struct sctp_timeouts);
2665 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2670 case SCTP_ASSOCINFO:
2672 struct sctp_assocparams *sasoc;
2674 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2675 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2678 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2679 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2680 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2681 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2682 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2683 SCTP_TCB_UNLOCK(stcb);
2685 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2686 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2687 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2688 SCTP_INP_RLOCK(inp);
2689 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2690 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2691 sasoc->sasoc_number_peer_destinations = 0;
2692 sasoc->sasoc_peer_rwnd = 0;
2693 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2694 SCTP_INP_RUNLOCK(inp);
2696 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2701 *optsize = sizeof(struct sctp_assocparams);
2705 case SCTP_DEFAULT_SEND_PARAM:
2707 struct sctp_sndrcvinfo *s_info;
2709 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2710 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2713 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2714 SCTP_TCB_UNLOCK(stcb);
2716 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2717 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2718 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2719 SCTP_INP_RLOCK(inp);
2720 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2721 SCTP_INP_RUNLOCK(inp);
2723 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2728 *optsize = sizeof(struct sctp_sndrcvinfo);
2734 struct sctp_initmsg *sinit;
2736 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2737 SCTP_INP_RLOCK(inp);
2738 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2739 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2740 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2741 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2742 SCTP_INP_RUNLOCK(inp);
2743 *optsize = sizeof(struct sctp_initmsg);
2746 case SCTP_PRIMARY_ADDR:
2747 /* we allow a "get" operation on this */
2749 struct sctp_setprim *ssp;
2751 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2752 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2755 /* simply copy out the sockaddr_storage... */
2759 if (len > stcb->asoc.primary_destination->ro._l_addr.sa.sa_len)
2760 len = stcb->asoc.primary_destination->ro._l_addr.sa.sa_len;
2762 memcpy(&ssp->ssp_addr,
2763 &stcb->asoc.primary_destination->ro._l_addr,
2765 SCTP_TCB_UNLOCK(stcb);
2766 *optsize = sizeof(struct sctp_setprim);
2768 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2773 case SCTP_HMAC_IDENT:
2775 struct sctp_hmacalgo *shmac;
2776 sctp_hmaclist_t *hmaclist;
2780 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2782 SCTP_INP_RLOCK(inp);
2783 hmaclist = inp->sctp_ep.local_hmacs;
2784 if (hmaclist == NULL) {
2785 /* no HMACs to return */
2786 *optsize = sizeof(*shmac);
2787 SCTP_INP_RUNLOCK(inp);
2790 /* is there room for all of the hmac ids? */
2791 size = sizeof(*shmac) + (hmaclist->num_algo *
2792 sizeof(shmac->shmac_idents[0]));
2793 if ((size_t)(*optsize) < size) {
2794 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2796 SCTP_INP_RUNLOCK(inp);
2799 /* copy in the list */
2800 shmac->shmac_number_of_idents = hmaclist->num_algo;
2801 for (i = 0; i < hmaclist->num_algo; i++) {
2802 shmac->shmac_idents[i] = hmaclist->hmac[i];
2804 SCTP_INP_RUNLOCK(inp);
2808 case SCTP_AUTH_ACTIVE_KEY:
2810 struct sctp_authkeyid *scact;
2812 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2813 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2816 /* get the active key on the assoc */
2817 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2818 SCTP_TCB_UNLOCK(stcb);
2820 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2821 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2822 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2823 /* get the endpoint active key */
2824 SCTP_INP_RLOCK(inp);
2825 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2826 SCTP_INP_RUNLOCK(inp);
2828 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2833 *optsize = sizeof(struct sctp_authkeyid);
2837 case SCTP_LOCAL_AUTH_CHUNKS:
2839 struct sctp_authchunks *sac;
2840 sctp_auth_chklist_t *chklist = NULL;
2843 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2844 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2847 /* get off the assoc */
2848 chklist = stcb->asoc.local_auth_chunks;
2849 /* is there enough space? */
2850 size = sctp_auth_get_chklist_size(chklist);
2851 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2853 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2855 /* copy in the chunks */
2856 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2857 sac->gauth_number_of_chunks = (uint32_t) size;
2858 *optsize = sizeof(struct sctp_authchunks) + size;
2860 SCTP_TCB_UNLOCK(stcb);
2862 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2863 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2864 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2865 /* get off the endpoint */
2866 SCTP_INP_RLOCK(inp);
2867 chklist = inp->sctp_ep.local_auth_chunks;
2868 /* is there enough space? */
2869 size = sctp_auth_get_chklist_size(chklist);
2870 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2872 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2874 /* copy in the chunks */
2875 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2876 sac->gauth_number_of_chunks = (uint32_t) size;
2877 *optsize = sizeof(struct sctp_authchunks) + size;
2879 SCTP_INP_RUNLOCK(inp);
2881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2887 case SCTP_PEER_AUTH_CHUNKS:
2889 struct sctp_authchunks *sac;
2890 sctp_auth_chklist_t *chklist = NULL;
2893 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2894 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2897 /* get off the assoc */
2898 chklist = stcb->asoc.peer_auth_chunks;
2899 /* is there enough space? */
2900 size = sctp_auth_get_chklist_size(chklist);
2901 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2903 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2905 /* copy in the chunks */
2906 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2907 sac->gauth_number_of_chunks = (uint32_t) size;
2908 *optsize = sizeof(struct sctp_authchunks) + size;
2910 SCTP_TCB_UNLOCK(stcb);
2912 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2919 struct sctp_event *event;
2920 uint32_t event_type;
2922 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2923 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
2925 switch (event->se_type) {
2926 case SCTP_ASSOC_CHANGE:
2927 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
2929 case SCTP_PEER_ADDR_CHANGE:
2930 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
2932 case SCTP_REMOTE_ERROR:
2933 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
2935 case SCTP_SEND_FAILED:
2936 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
2938 case SCTP_SHUTDOWN_EVENT:
2939 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
2941 case SCTP_ADAPTATION_INDICATION:
2942 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
2944 case SCTP_PARTIAL_DELIVERY_EVENT:
2945 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
2947 case SCTP_AUTHENTICATION_EVENT:
2948 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
2950 case SCTP_STREAM_RESET_EVENT:
2951 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
2953 case SCTP_SENDER_DRY_EVENT:
2954 event_type = SCTP_PCB_FLAGS_DRYEVNT;
2956 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
2958 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
2961 case SCTP_ASSOC_RESET_EVENT:
2962 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
2964 case SCTP_STREAM_CHANGE_EVENT:
2965 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
2967 case SCTP_SEND_FAILED_EVENT:
2968 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
2972 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2976 if (event_type > 0) {
2978 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
2979 SCTP_TCB_UNLOCK(stcb);
2981 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2982 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2983 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
2984 SCTP_INP_RLOCK(inp);
2985 event->se_on = sctp_is_feature_on(inp, event_type);
2986 SCTP_INP_RUNLOCK(inp);
2988 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2994 *optsize = sizeof(struct sctp_event);
2998 case SCTP_RECVRCVINFO:
3002 if (*optsize < sizeof(int)) {
3003 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3006 SCTP_INP_RLOCK(inp);
3007 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3008 SCTP_INP_RUNLOCK(inp);
3011 /* return the option value */
3012 *(int *)optval = onoff;
3013 *optsize = sizeof(int);
3017 case SCTP_RECVNXTINFO:
3021 if (*optsize < sizeof(int)) {
3022 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3025 SCTP_INP_RLOCK(inp);
3026 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3027 SCTP_INP_RUNLOCK(inp);
3030 /* return the option value */
3031 *(int *)optval = onoff;
3032 *optsize = sizeof(int);
3036 case SCTP_DEFAULT_SNDINFO:
3038 struct sctp_sndinfo *info;
3040 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3041 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3044 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3045 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3046 info->snd_flags &= 0xfff0;
3047 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3048 info->snd_context = stcb->asoc.def_send.sinfo_context;
3049 SCTP_TCB_UNLOCK(stcb);
3051 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3052 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3053 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3054 SCTP_INP_RLOCK(inp);
3055 info->snd_sid = inp->def_send.sinfo_stream;
3056 info->snd_flags = inp->def_send.sinfo_flags;
3057 info->snd_flags &= 0xfff0;
3058 info->snd_ppid = inp->def_send.sinfo_ppid;
3059 info->snd_context = inp->def_send.sinfo_context;
3060 SCTP_INP_RUNLOCK(inp);
3062 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3067 *optsize = sizeof(struct sctp_sndinfo);
3071 case SCTP_DEFAULT_PRINFO:
3073 struct sctp_default_prinfo *info;
3075 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3076 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3079 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3080 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3081 SCTP_TCB_UNLOCK(stcb);
3083 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3084 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3085 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3086 SCTP_INP_RLOCK(inp);
3087 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3088 info->pr_value = inp->def_send.sinfo_timetolive;
3089 SCTP_INP_RUNLOCK(inp);
3091 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3096 *optsize = sizeof(struct sctp_default_prinfo);
3100 case SCTP_PEER_ADDR_THLDS:
3102 struct sctp_paddrthlds *thlds;
3103 struct sctp_nets *net;
3105 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3106 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3110 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_address);
3113 * We increment here since
3114 * sctp_findassociation_ep_addr() wil do a
3115 * decrement if it finds the stcb as long as
3116 * the locked tcb (last argument) is NOT a
3119 SCTP_INP_INCR_REF(inp);
3120 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&thlds->spt_address, &net, NULL, NULL);
3122 SCTP_INP_DECR_REF(inp);
3125 if (stcb && (net == NULL)) {
3126 struct sockaddr *sa;
3128 sa = (struct sockaddr *)&thlds->spt_address;
3130 if (sa->sa_family == AF_INET) {
3131 struct sockaddr_in *sin;
3133 sin = (struct sockaddr_in *)sa;
3134 if (sin->sin_addr.s_addr) {
3136 SCTP_TCB_UNLOCK(stcb);
3137 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3143 if (sa->sa_family == AF_INET6) {
3144 struct sockaddr_in6 *sin6;
3146 sin6 = (struct sockaddr_in6 *)sa;
3147 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3149 SCTP_TCB_UNLOCK(stcb);
3150 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3156 error = EAFNOSUPPORT;
3157 SCTP_TCB_UNLOCK(stcb);
3158 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3164 thlds->spt_pathmaxrxt = net->failure_threshold;
3165 thlds->spt_pathpfthld = net->pf_threshold;
3167 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3168 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3170 thlds->spt_assoc_id = sctp_get_associd(stcb);
3171 SCTP_TCB_UNLOCK(stcb);
3173 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3174 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3175 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3176 /* Use endpoint defaults */
3177 SCTP_INP_RLOCK(inp);
3178 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3179 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3180 SCTP_INP_RUNLOCK(inp);
3182 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3187 *optsize = sizeof(struct sctp_paddrthlds);
3191 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3193 struct sctp_udpencaps *encaps;
3194 struct sctp_nets *net;
3196 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3197 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3200 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
3203 * We increment here since
3204 * sctp_findassociation_ep_addr() wil do a
3205 * decrement if it finds the stcb as long as
3206 * the locked tcb (last argument) is NOT a
3210 SCTP_INP_INCR_REF(inp);
3211 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
3213 SCTP_INP_DECR_REF(inp);
3216 if (stcb && (net == NULL)) {
3217 struct sockaddr *sa;
3219 sa = (struct sockaddr *)&encaps->sue_address;
3221 if (sa->sa_family == AF_INET) {
3222 struct sockaddr_in *sin;
3224 sin = (struct sockaddr_in *)sa;
3225 if (sin->sin_addr.s_addr) {
3227 SCTP_TCB_UNLOCK(stcb);
3228 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3234 if (sa->sa_family == AF_INET6) {
3235 struct sockaddr_in6 *sin6;
3237 sin6 = (struct sockaddr_in6 *)sa;
3238 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3240 SCTP_TCB_UNLOCK(stcb);
3241 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3247 error = EAFNOSUPPORT;
3248 SCTP_TCB_UNLOCK(stcb);
3249 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3255 encaps->sue_port = net->port;
3257 encaps->sue_port = stcb->asoc.port;
3259 SCTP_TCB_UNLOCK(stcb);
3261 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3262 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3263 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3264 SCTP_INP_RLOCK(inp);
3265 encaps->sue_port = inp->sctp_ep.port;
3266 SCTP_INP_RUNLOCK(inp);
3268 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3273 *optsize = sizeof(struct sctp_paddrparams);
3277 case SCTP_ENABLE_STREAM_RESET:
3279 struct sctp_assoc_value *av;
3281 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3282 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3285 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3286 SCTP_TCB_UNLOCK(stcb);
3288 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3289 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3290 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3291 SCTP_INP_RLOCK(inp);
3292 av->assoc_value = (uint32_t) inp->local_strreset_support;
3293 SCTP_INP_RUNLOCK(inp);
3295 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3300 *optsize = sizeof(struct sctp_assoc_value);
3305 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3306 error = ENOPROTOOPT;
3308 } /* end switch (sopt->sopt_name) */
3316 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3321 struct sctp_tcb *stcb = NULL;
3322 struct sctp_inpcb *inp = NULL;
3325 if (optval == NULL) {
3326 SCTP_PRINTF("optval is NULL\n");
3327 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3330 inp = (struct sctp_inpcb *)so->so_pcb;
3332 SCTP_PRINTF("inp is NULL?\n");
3333 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3336 vrf_id = inp->def_vrf_id;
3341 case SCTP_AUTOCLOSE:
3342 case SCTP_AUTO_ASCONF:
3343 case SCTP_EXPLICIT_EOR:
3344 case SCTP_DISABLE_FRAGMENTS:
3345 case SCTP_USE_EXT_RCVINFO:
3346 case SCTP_I_WANT_MAPPED_V4_ADDR:
3347 /* copy in the option value */
3348 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3353 case SCTP_DISABLE_FRAGMENTS:
3354 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3356 case SCTP_AUTO_ASCONF:
3358 * NOTE: we don't really support this flag
3360 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3361 /* only valid for bound all sockets */
3362 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3364 /* forbidden by admin */
3365 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3368 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3370 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3374 case SCTP_EXPLICIT_EOR:
3375 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3377 case SCTP_USE_EXT_RCVINFO:
3378 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3380 case SCTP_I_WANT_MAPPED_V4_ADDR:
3381 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3382 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3384 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3389 set_opt = SCTP_PCB_FLAGS_NODELAY;
3391 case SCTP_AUTOCLOSE:
3392 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3393 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3394 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3397 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3399 * The value is in ticks. Note this does not effect
3400 * old associations, only new ones.
3402 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3405 SCTP_INP_WLOCK(inp);
3407 sctp_feature_on(inp, set_opt);
3409 sctp_feature_off(inp, set_opt);
3411 SCTP_INP_WUNLOCK(inp);
3413 case SCTP_REUSE_PORT:
3415 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3416 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3417 /* Can't set it after we are bound */
3421 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3422 /* Can't do this for a 1-m socket */
3427 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3429 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3432 case SCTP_PARTIAL_DELIVERY_POINT:
3436 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3437 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3438 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3442 inp->partial_delivery_point = *value;
3445 case SCTP_FRAGMENT_INTERLEAVE:
3446 /* not yet until we re-write sctp_recvmsg() */
3450 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3451 if (*level == SCTP_FRAG_LEVEL_2) {
3452 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3453 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3454 } else if (*level == SCTP_FRAG_LEVEL_1) {
3455 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3456 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3457 } else if (*level == SCTP_FRAG_LEVEL_0) {
3458 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3459 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3462 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3467 case SCTP_CMT_ON_OFF:
3468 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3469 struct sctp_assoc_value *av;
3471 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3472 if (av->assoc_value > SCTP_CMT_MAX) {
3473 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3477 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3479 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3480 SCTP_TCB_UNLOCK(stcb);
3482 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3483 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3484 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3485 (av->assoc_id == SCTP_ALL_ASSOC)) {
3486 SCTP_INP_WLOCK(inp);
3487 inp->sctp_cmt_on_off = av->assoc_value;
3488 SCTP_INP_WUNLOCK(inp);
3490 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3491 (av->assoc_id == SCTP_ALL_ASSOC)) {
3492 SCTP_INP_RLOCK(inp);
3493 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3494 SCTP_TCB_LOCK(stcb);
3495 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3496 SCTP_TCB_UNLOCK(stcb);
3498 SCTP_INP_RUNLOCK(inp);
3502 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3503 error = ENOPROTOOPT;
3506 case SCTP_PLUGGABLE_CC:
3508 struct sctp_assoc_value *av;
3509 struct sctp_nets *net;
3511 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3512 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3513 (av->assoc_value != SCTP_CC_HSTCP) &&
3514 (av->assoc_value != SCTP_CC_HTCP) &&
3515 (av->assoc_value != SCTP_CC_RTCC)) {
3516 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3520 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3522 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3523 stcb->asoc.congestion_control_module = av->assoc_value;
3524 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3525 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3526 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3529 SCTP_TCB_UNLOCK(stcb);
3531 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3532 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3533 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3534 (av->assoc_id == SCTP_ALL_ASSOC)) {
3535 SCTP_INP_WLOCK(inp);
3536 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3537 SCTP_INP_WUNLOCK(inp);
3539 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3540 (av->assoc_id == SCTP_ALL_ASSOC)) {
3541 SCTP_INP_RLOCK(inp);
3542 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3543 SCTP_TCB_LOCK(stcb);
3544 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3545 stcb->asoc.congestion_control_module = av->assoc_value;
3546 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3547 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3548 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3551 SCTP_TCB_UNLOCK(stcb);
3553 SCTP_INP_RUNLOCK(inp);
3558 case SCTP_CC_OPTION:
3560 struct sctp_cc_option *cc_opt;
3562 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
3563 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
3565 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
3566 SCTP_INP_RLOCK(inp);
3567 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3568 SCTP_TCB_LOCK(stcb);
3569 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
3570 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
3572 SCTP_TCB_UNLOCK(stcb);
3574 SCTP_INP_RUNLOCK(inp);
3579 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
3582 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
3585 SCTP_TCB_UNLOCK(stcb);
3589 case SCTP_PLUGGABLE_SS:
3591 struct sctp_assoc_value *av;
3593 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3594 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
3595 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
3596 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
3597 (av->assoc_value != SCTP_SS_PRIORITY) &&
3598 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
3599 (av->assoc_value != SCTP_SS_FIRST_COME)) {
3600 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3604 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3606 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3607 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3608 stcb->asoc.stream_scheduling_module = av->assoc_value;
3609 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3610 SCTP_TCB_UNLOCK(stcb);
3612 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3613 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3614 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3615 (av->assoc_id == SCTP_ALL_ASSOC)) {
3616 SCTP_INP_WLOCK(inp);
3617 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
3618 SCTP_INP_WUNLOCK(inp);
3620 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3621 (av->assoc_id == SCTP_ALL_ASSOC)) {
3622 SCTP_INP_RLOCK(inp);
3623 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3624 SCTP_TCB_LOCK(stcb);
3625 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3626 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3627 stcb->asoc.stream_scheduling_module = av->assoc_value;
3628 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3629 SCTP_TCB_UNLOCK(stcb);
3631 SCTP_INP_RUNLOCK(inp);
3638 struct sctp_stream_value *av;
3640 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
3641 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3643 if (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
3644 av->stream_value) < 0) {
3645 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3648 SCTP_TCB_UNLOCK(stcb);
3650 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
3651 SCTP_INP_RLOCK(inp);
3652 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3653 SCTP_TCB_LOCK(stcb);
3654 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
3656 &stcb->asoc.strmout[av->stream_id],
3658 SCTP_TCB_UNLOCK(stcb);
3660 SCTP_INP_RUNLOCK(inp);
3664 * Can't set stream value without
3667 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3673 case SCTP_CLR_STAT_LOG:
3674 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3679 struct sctp_assoc_value *av;
3681 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3682 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3685 stcb->asoc.context = av->assoc_value;
3686 SCTP_TCB_UNLOCK(stcb);
3688 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3689 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3690 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3691 (av->assoc_id == SCTP_ALL_ASSOC)) {
3692 SCTP_INP_WLOCK(inp);
3693 inp->sctp_context = av->assoc_value;
3694 SCTP_INP_WUNLOCK(inp);
3696 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3697 (av->assoc_id == SCTP_ALL_ASSOC)) {
3698 SCTP_INP_RLOCK(inp);
3699 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3700 SCTP_TCB_LOCK(stcb);
3701 stcb->asoc.context = av->assoc_value;
3702 SCTP_TCB_UNLOCK(stcb);
3704 SCTP_INP_RUNLOCK(inp);
3711 uint32_t *default_vrfid;
3713 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
3714 if (*default_vrfid > SCTP_MAX_VRF_ID) {
3715 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3719 inp->def_vrf_id = *default_vrfid;
3722 case SCTP_DEL_VRF_ID:
3724 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3728 case SCTP_ADD_VRF_ID:
3730 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3734 case SCTP_DELAYED_SACK:
3736 struct sctp_sack_info *sack;
3738 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
3739 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
3740 if (sack->sack_delay) {
3741 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
3742 sack->sack_delay = SCTP_MAX_SACK_DELAY;
3743 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
3744 sack->sack_delay = TICKS_TO_MSEC(1);
3748 if (sack->sack_delay) {
3749 stcb->asoc.delayed_ack = sack->sack_delay;
3751 if (sack->sack_freq) {
3752 stcb->asoc.sack_freq = sack->sack_freq;
3754 SCTP_TCB_UNLOCK(stcb);
3756 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3757 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3758 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
3759 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3760 SCTP_INP_WLOCK(inp);
3761 if (sack->sack_delay) {
3762 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
3764 if (sack->sack_freq) {
3765 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
3767 SCTP_INP_WUNLOCK(inp);
3769 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
3770 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3771 SCTP_INP_RLOCK(inp);
3772 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3773 SCTP_TCB_LOCK(stcb);
3774 if (sack->sack_delay) {
3775 stcb->asoc.delayed_ack = sack->sack_delay;
3777 if (sack->sack_freq) {
3778 stcb->asoc.sack_freq = sack->sack_freq;
3780 SCTP_TCB_UNLOCK(stcb);
3782 SCTP_INP_RUNLOCK(inp);
3787 case SCTP_AUTH_CHUNK:
3789 struct sctp_authchunk *sauth;
3791 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
3793 SCTP_INP_WLOCK(inp);
3794 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
3795 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3798 SCTP_INP_WUNLOCK(inp);
3803 struct sctp_authkey *sca;
3804 struct sctp_keyhead *shared_keys;
3805 sctp_sharedkey_t *shared_key;
3806 sctp_key_t *key = NULL;
3809 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
3810 if (sca->sca_keylength == 0) {
3811 size = optsize - sizeof(struct sctp_authkey);
3813 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
3814 size = sca->sca_keylength;
3816 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3821 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
3824 shared_keys = &stcb->asoc.shared_keys;
3825 /* clear the cached keys for this key id */
3826 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3828 * create the new shared key and
3832 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3834 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3836 SCTP_TCB_UNLOCK(stcb);
3840 shared_key = sctp_alloc_sharedkey();
3841 if (shared_key == NULL) {
3843 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3845 SCTP_TCB_UNLOCK(stcb);
3848 shared_key->key = key;
3849 shared_key->keyid = sca->sca_keynumber;
3850 error = sctp_insert_sharedkey(shared_keys, shared_key);
3851 SCTP_TCB_UNLOCK(stcb);
3853 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3854 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3855 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
3856 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3857 SCTP_INP_WLOCK(inp);
3858 shared_keys = &inp->sctp_ep.shared_keys;
3860 * clear the cached keys on all
3861 * assocs for this key id
3863 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
3865 * create the new shared key and
3869 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3871 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3873 SCTP_INP_WUNLOCK(inp);
3877 shared_key = sctp_alloc_sharedkey();
3878 if (shared_key == NULL) {
3880 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3882 SCTP_INP_WUNLOCK(inp);
3885 shared_key->key = key;
3886 shared_key->keyid = sca->sca_keynumber;
3887 error = sctp_insert_sharedkey(shared_keys, shared_key);
3888 SCTP_INP_WUNLOCK(inp);
3890 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
3891 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3892 SCTP_INP_RLOCK(inp);
3893 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3894 SCTP_TCB_LOCK(stcb);
3895 shared_keys = &stcb->asoc.shared_keys;
3897 * clear the cached keys for
3900 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3902 * create the new shared key
3903 * and insert/replace it
3906 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3908 SCTP_TCB_UNLOCK(stcb);
3912 shared_key = sctp_alloc_sharedkey();
3913 if (shared_key == NULL) {
3915 SCTP_TCB_UNLOCK(stcb);
3918 shared_key->key = key;
3919 shared_key->keyid = sca->sca_keynumber;
3920 error = sctp_insert_sharedkey(shared_keys, shared_key);
3921 SCTP_TCB_UNLOCK(stcb);
3923 SCTP_INP_RUNLOCK(inp);
3928 case SCTP_HMAC_IDENT:
3930 struct sctp_hmacalgo *shmac;
3931 sctp_hmaclist_t *hmaclist;
3936 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
3937 if (optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) {
3938 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3942 hmaclist = sctp_alloc_hmaclist(shmac->shmac_number_of_idents);
3943 if (hmaclist == NULL) {
3944 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3948 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
3949 hmacid = shmac->shmac_idents[i];
3950 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
3951 /* invalid HMACs were found */ ;
3952 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3954 sctp_free_hmaclist(hmaclist);
3955 goto sctp_set_hmac_done;
3959 for (i = 0; i < hmaclist->num_algo; i++) {
3960 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
3961 /* already in list */
3966 sctp_free_hmaclist(hmaclist);
3967 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3971 /* set it on the endpoint */
3972 SCTP_INP_WLOCK(inp);
3973 if (inp->sctp_ep.local_hmacs)
3974 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
3975 inp->sctp_ep.local_hmacs = hmaclist;
3976 SCTP_INP_WUNLOCK(inp);
3980 case SCTP_AUTH_ACTIVE_KEY:
3982 struct sctp_authkeyid *scact;
3984 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
3985 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
3987 /* set the active key on the right place */
3989 /* set the active key on the assoc */
3990 if (sctp_auth_setactivekey(stcb,
3991 scact->scact_keynumber)) {
3992 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
3993 SCTP_FROM_SCTP_USRREQ,
3997 SCTP_TCB_UNLOCK(stcb);
3999 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4000 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4001 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4002 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4003 SCTP_INP_WLOCK(inp);
4004 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4005 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4008 SCTP_INP_WUNLOCK(inp);
4010 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4011 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4012 SCTP_INP_RLOCK(inp);
4013 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4014 SCTP_TCB_LOCK(stcb);
4015 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4016 SCTP_TCB_UNLOCK(stcb);
4018 SCTP_INP_RUNLOCK(inp);
4023 case SCTP_AUTH_DELETE_KEY:
4025 struct sctp_authkeyid *scdel;
4027 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4028 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4030 /* delete the key from the right place */
4032 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4033 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4036 SCTP_TCB_UNLOCK(stcb);
4038 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4039 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4040 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4041 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4042 SCTP_INP_WLOCK(inp);
4043 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4044 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4047 SCTP_INP_WUNLOCK(inp);
4049 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4050 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4051 SCTP_INP_RLOCK(inp);
4052 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4053 SCTP_TCB_LOCK(stcb);
4054 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4055 SCTP_TCB_UNLOCK(stcb);
4057 SCTP_INP_RUNLOCK(inp);
4062 case SCTP_AUTH_DEACTIVATE_KEY:
4064 struct sctp_authkeyid *keyid;
4066 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4067 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4069 /* deactivate the key from the right place */
4071 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4072 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4075 SCTP_TCB_UNLOCK(stcb);
4077 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4078 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4079 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4080 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4081 SCTP_INP_WLOCK(inp);
4082 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4083 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4086 SCTP_INP_WUNLOCK(inp);
4088 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4089 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4090 SCTP_INP_RLOCK(inp);
4091 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4092 SCTP_TCB_LOCK(stcb);
4093 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4094 SCTP_TCB_UNLOCK(stcb);
4096 SCTP_INP_RUNLOCK(inp);
4101 case SCTP_ENABLE_STREAM_RESET:
4103 struct sctp_assoc_value *av;
4105 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4106 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4107 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4111 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4113 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4114 SCTP_TCB_UNLOCK(stcb);
4116 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4117 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4118 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4119 (av->assoc_id == SCTP_ALL_ASSOC)) {
4120 SCTP_INP_WLOCK(inp);
4121 inp->local_strreset_support = (uint8_t) av->assoc_value;
4122 SCTP_INP_WUNLOCK(inp);
4124 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4125 (av->assoc_id == SCTP_ALL_ASSOC)) {
4126 SCTP_INP_RLOCK(inp);
4127 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4128 SCTP_TCB_LOCK(stcb);
4129 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4130 SCTP_TCB_UNLOCK(stcb);
4132 SCTP_INP_RUNLOCK(inp);
4137 case SCTP_RESET_STREAMS:
4139 struct sctp_reset_streams *strrst;
4140 int i, send_out = 0;
4143 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4144 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4146 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4150 if (stcb->asoc.peer_supports_strreset == 0) {
4152 * Peer does not support the chunk type.
4154 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4156 SCTP_TCB_UNLOCK(stcb);
4159 if (stcb->asoc.stream_reset_outstanding) {
4160 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4162 SCTP_TCB_UNLOCK(stcb);
4165 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4168 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4171 if ((send_in == 0) && (send_out == 0)) {
4172 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4174 SCTP_TCB_UNLOCK(stcb);
4177 for (i = 0; i < strrst->srs_number_streams; i++) {
4179 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4180 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4185 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4186 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4192 SCTP_TCB_UNLOCK(stcb);
4195 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4196 strrst->srs_stream_list,
4197 send_out, send_in, 0, 0, 0, 0, 0);
4199 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4200 SCTP_TCB_UNLOCK(stcb);
4203 case SCTP_ADD_STREAMS:
4205 struct sctp_add_streams *stradd;
4206 uint8_t addstream = 0;
4207 uint16_t add_o_strmcnt = 0;
4208 uint16_t add_i_strmcnt = 0;
4210 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4211 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4213 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4217 if (stcb->asoc.peer_supports_strreset == 0) {
4219 * Peer does not support the chunk type.
4221 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4223 SCTP_TCB_UNLOCK(stcb);
4226 if (stcb->asoc.stream_reset_outstanding) {
4227 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4229 SCTP_TCB_UNLOCK(stcb);
4232 if ((stradd->sas_outstrms == 0) &&
4233 (stradd->sas_instrms == 0)) {
4237 if (stradd->sas_outstrms) {
4239 /* We allocate here */
4240 add_o_strmcnt = stradd->sas_outstrms;
4241 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4242 /* You can't have more than 64k */
4247 if (stradd->sas_instrms) {
4252 * We allocate inside
4253 * sctp_send_str_reset_req()
4255 add_i_strmcnt = stradd->sas_instrms;
4256 cnt = add_i_strmcnt;
4257 cnt += stcb->asoc.streamincnt;
4258 if (cnt > 0x0000ffff) {
4259 /* You can't have more than 64k */
4263 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4264 /* More than you are allowed */
4269 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4270 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4272 SCTP_TCB_UNLOCK(stcb);
4275 case SCTP_RESET_ASSOC:
4279 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4280 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4282 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4286 if (stcb->asoc.peer_supports_strreset == 0) {
4288 * Peer does not support the chunk type.
4290 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4292 SCTP_TCB_UNLOCK(stcb);
4295 if (stcb->asoc.stream_reset_outstanding) {
4296 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4298 SCTP_TCB_UNLOCK(stcb);
4301 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 1, 0, 0, 0, 0);
4302 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4303 SCTP_TCB_UNLOCK(stcb);
4306 case SCTP_CONNECT_X:
4307 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4308 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4312 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4314 case SCTP_CONNECT_X_DELAYED:
4315 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4316 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4320 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4322 case SCTP_CONNECT_X_COMPLETE:
4324 struct sockaddr *sa;
4325 struct sctp_nets *net;
4327 /* FIXME MT: check correct? */
4328 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4331 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4332 SCTP_INP_RLOCK(inp);
4333 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4335 SCTP_TCB_LOCK(stcb);
4336 net = sctp_findnet(stcb, sa);
4338 SCTP_INP_RUNLOCK(inp);
4341 * We increment here since
4342 * sctp_findassociation_ep_addr() wil do a
4343 * decrement if it finds the stcb as long as
4344 * the locked tcb (last argument) is NOT a
4347 SCTP_INP_INCR_REF(inp);
4348 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
4350 SCTP_INP_DECR_REF(inp);
4355 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4359 if (stcb->asoc.delayed_connection == 1) {
4360 stcb->asoc.delayed_connection = 0;
4361 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4362 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4363 stcb->asoc.primary_destination,
4364 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
4365 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4368 * already expired or did not use delayed
4371 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4374 SCTP_TCB_UNLOCK(stcb);
4377 case SCTP_MAX_BURST:
4381 SCTP_CHECK_AND_CAST(burst, optval, uint8_t, optsize);
4383 SCTP_INP_WLOCK(inp);
4384 inp->sctp_ep.max_burst = *burst;
4385 SCTP_INP_WUNLOCK(inp);
4390 struct sctp_assoc_value *av;
4393 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4394 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4396 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4397 ovh = SCTP_MED_OVERHEAD;
4399 ovh = SCTP_MED_V4_OVERHEAD;
4402 if (av->assoc_value) {
4403 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4405 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4407 SCTP_TCB_UNLOCK(stcb);
4409 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4410 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4411 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4412 SCTP_INP_WLOCK(inp);
4414 * FIXME MT: I think this is not in
4415 * tune with the API ID
4417 if (av->assoc_value) {
4418 inp->sctp_frag_point = (av->assoc_value + ovh);
4420 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4422 SCTP_INP_WUNLOCK(inp);
4424 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4432 struct sctp_event_subscribe *events;
4434 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4436 SCTP_INP_WLOCK(inp);
4437 if (events->sctp_data_io_event) {
4438 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4440 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4443 if (events->sctp_association_event) {
4444 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4446 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4449 if (events->sctp_address_event) {
4450 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4452 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4455 if (events->sctp_send_failure_event) {
4456 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4458 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4461 if (events->sctp_peer_error_event) {
4462 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4464 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4467 if (events->sctp_shutdown_event) {
4468 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4470 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4473 if (events->sctp_partial_delivery_event) {
4474 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4476 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4479 if (events->sctp_adaptation_layer_event) {
4480 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4482 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4485 if (events->sctp_authentication_event) {
4486 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4488 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4491 if (events->sctp_sender_dry_event) {
4492 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
4494 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
4497 if (events->sctp_stream_reset_event) {
4498 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4500 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4502 SCTP_INP_WUNLOCK(inp);
4504 SCTP_INP_RLOCK(inp);
4505 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4506 SCTP_TCB_LOCK(stcb);
4507 if (events->sctp_association_event) {
4508 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4510 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4512 if (events->sctp_address_event) {
4513 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4515 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4517 if (events->sctp_send_failure_event) {
4518 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4520 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4522 if (events->sctp_peer_error_event) {
4523 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4525 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4527 if (events->sctp_shutdown_event) {
4528 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4530 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4532 if (events->sctp_partial_delivery_event) {
4533 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4535 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4537 if (events->sctp_adaptation_layer_event) {
4538 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4540 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4542 if (events->sctp_authentication_event) {
4543 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4545 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4547 if (events->sctp_sender_dry_event) {
4548 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4550 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4552 if (events->sctp_stream_reset_event) {
4553 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4555 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4557 SCTP_TCB_UNLOCK(stcb);
4560 * Send up the sender dry event only for 1-to-1
4563 if (events->sctp_sender_dry_event) {
4564 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4565 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
4566 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4568 SCTP_TCB_LOCK(stcb);
4569 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
4570 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
4571 (stcb->asoc.stream_queue_cnt == 0)) {
4572 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
4574 SCTP_TCB_UNLOCK(stcb);
4578 SCTP_INP_RUNLOCK(inp);
4581 case SCTP_ADAPTATION_LAYER:
4583 struct sctp_setadaptation *adap_bits;
4585 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
4586 SCTP_INP_WLOCK(inp);
4587 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
4588 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
4589 SCTP_INP_WUNLOCK(inp);
4593 case SCTP_SET_INITIAL_DBG_SEQ:
4597 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
4598 SCTP_INP_WLOCK(inp);
4599 inp->sctp_ep.initial_sequence_debug = *vvv;
4600 SCTP_INP_WUNLOCK(inp);
4604 case SCTP_DEFAULT_SEND_PARAM:
4606 struct sctp_sndrcvinfo *s_info;
4608 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
4609 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
4612 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4613 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4615 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4618 SCTP_TCB_UNLOCK(stcb);
4620 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4621 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4622 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
4623 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4624 SCTP_INP_WLOCK(inp);
4625 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
4626 SCTP_INP_WUNLOCK(inp);
4628 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
4629 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4630 SCTP_INP_RLOCK(inp);
4631 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4632 SCTP_TCB_LOCK(stcb);
4633 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4634 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4636 SCTP_TCB_UNLOCK(stcb);
4638 SCTP_INP_RUNLOCK(inp);
4643 case SCTP_PEER_ADDR_PARAMS:
4645 struct sctp_paddrparams *paddrp;
4646 struct sctp_nets *net;
4648 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
4649 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
4652 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
4655 * We increment here since
4656 * sctp_findassociation_ep_addr() wil do a
4657 * decrement if it finds the stcb as long as
4658 * the locked tcb (last argument) is NOT a
4661 SCTP_INP_INCR_REF(inp);
4662 stcb = sctp_findassociation_ep_addr(&inp,
4663 (struct sockaddr *)&paddrp->spp_address,
4666 SCTP_INP_DECR_REF(inp);
4669 if (stcb && (net == NULL)) {
4670 struct sockaddr *sa;
4672 sa = (struct sockaddr *)&paddrp->spp_address;
4674 if (sa->sa_family == AF_INET) {
4676 struct sockaddr_in *sin;
4678 sin = (struct sockaddr_in *)sa;
4679 if (sin->sin_addr.s_addr) {
4680 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4681 SCTP_TCB_UNLOCK(stcb);
4688 if (sa->sa_family == AF_INET6) {
4689 struct sockaddr_in6 *sin6;
4691 sin6 = (struct sockaddr_in6 *)sa;
4692 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
4693 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4694 SCTP_TCB_UNLOCK(stcb);
4701 error = EAFNOSUPPORT;
4702 SCTP_TCB_UNLOCK(stcb);
4703 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4708 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
4710 SCTP_TCB_UNLOCK(stcb);
4711 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4714 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
4716 SCTP_TCB_UNLOCK(stcb);
4717 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4721 /************************TCB SPECIFIC SET ******************/
4723 * do we change the timer for HB, we run
4728 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4729 ovh = SCTP_MED_OVERHEAD;
4731 ovh = SCTP_MED_V4_OVERHEAD;
4734 /* network sets ? */
4736 /************************NET SPECIFIC SET ******************/
4737 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4738 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
4739 !(net->dest_state & SCTP_ADDR_NOHB)) {
4740 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4741 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4743 net->dest_state |= SCTP_ADDR_NOHB;
4745 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4746 if (paddrp->spp_hbinterval) {
4747 net->heart_beat_delay = paddrp->spp_hbinterval;
4748 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4749 net->heart_beat_delay = 0;
4751 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4752 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4753 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4754 net->dest_state &= ~SCTP_ADDR_NOHB;
4756 if (paddrp->spp_flags & SPP_HB_DEMAND) {
4758 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4759 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
4760 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4762 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4763 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4764 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4765 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4767 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4768 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4769 net->mtu = paddrp->spp_pathmtu + ovh;
4770 if (net->mtu < stcb->asoc.smallest_mtu) {
4771 sctp_pathmtu_adjustment(stcb, net->mtu);
4775 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4776 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4777 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4779 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4781 if (paddrp->spp_pathmaxrxt) {
4782 if (net->dest_state & SCTP_ADDR_PF) {
4783 if (net->error_count > paddrp->spp_pathmaxrxt) {
4784 net->dest_state &= ~SCTP_ADDR_PF;
4787 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4788 (net->error_count > net->pf_threshold)) {
4789 net->dest_state |= SCTP_ADDR_PF;
4790 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4791 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4792 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4795 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4796 if (net->error_count > paddrp->spp_pathmaxrxt) {
4797 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4798 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
4801 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4802 net->dest_state |= SCTP_ADDR_REACHABLE;
4803 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
4806 net->failure_threshold = paddrp->spp_pathmaxrxt;
4808 if (paddrp->spp_flags & SPP_DSCP) {
4809 net->dscp = paddrp->spp_dscp & 0xfc;
4813 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4814 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4815 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4816 net->flowlabel |= 0x80000000;
4821 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
4822 if (paddrp->spp_pathmaxrxt) {
4823 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
4824 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4825 if (net->dest_state & SCTP_ADDR_PF) {
4826 if (net->error_count > paddrp->spp_pathmaxrxt) {
4827 net->dest_state &= ~SCTP_ADDR_PF;
4830 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4831 (net->error_count > net->pf_threshold)) {
4832 net->dest_state |= SCTP_ADDR_PF;
4833 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4834 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4835 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4838 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4839 if (net->error_count > paddrp->spp_pathmaxrxt) {
4840 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4841 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
4844 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4845 net->dest_state |= SCTP_ADDR_REACHABLE;
4846 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
4849 net->failure_threshold = paddrp->spp_pathmaxrxt;
4852 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4853 if (paddrp->spp_hbinterval) {
4854 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
4855 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4856 stcb->asoc.heart_beat_delay = 0;
4858 /* Turn back on the timer */
4859 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4860 if (paddrp->spp_hbinterval) {
4861 net->heart_beat_delay = paddrp->spp_hbinterval;
4862 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4863 net->heart_beat_delay = 0;
4865 if (net->dest_state & SCTP_ADDR_NOHB) {
4866 net->dest_state &= ~SCTP_ADDR_NOHB;
4868 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4869 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4870 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4872 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4874 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4875 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4876 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
4877 net->dest_state |= SCTP_ADDR_NOHB;
4878 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
4879 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4883 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4885 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4886 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4887 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4888 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4889 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4891 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4892 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4893 net->mtu = paddrp->spp_pathmtu + ovh;
4894 if (net->mtu < stcb->asoc.smallest_mtu) {
4895 sctp_pathmtu_adjustment(stcb, net->mtu);
4899 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4901 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4902 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4903 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4904 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4906 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4908 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4910 if (paddrp->spp_flags & SPP_DSCP) {
4911 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4912 net->dscp = paddrp->spp_dscp & 0xfc;
4915 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
4916 stcb->asoc.default_dscp |= 0x01;
4919 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4920 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4921 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4922 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4923 net->flowlabel |= 0x80000000;
4926 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4927 stcb->asoc.default_flowlabel |= 0x80000000;
4931 SCTP_TCB_UNLOCK(stcb);
4933 /************************NO TCB, SET TO default stuff ******************/
4934 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4935 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4936 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
4937 SCTP_INP_WLOCK(inp);
4939 * For the TOS/FLOWLABEL stuff you
4940 * set it with the options on the
4943 if (paddrp->spp_pathmaxrxt) {
4944 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
4946 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
4947 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4948 else if (paddrp->spp_hbinterval) {
4949 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
4950 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
4951 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4953 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4954 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4955 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4956 } else if (paddrp->spp_hbinterval) {
4957 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4959 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4960 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
4961 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4963 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4964 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4965 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
4966 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4968 if (paddrp->spp_flags & SPP_DSCP) {
4969 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
4970 inp->sctp_ep.default_dscp |= 0x01;
4973 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4974 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4975 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4976 inp->sctp_ep.default_flowlabel |= 0x80000000;
4980 SCTP_INP_WUNLOCK(inp);
4982 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4990 struct sctp_rtoinfo *srto;
4991 uint32_t new_init, new_min, new_max;
4993 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
4994 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
4997 if (srto->srto_initial)
4998 new_init = srto->srto_initial;
5000 new_init = stcb->asoc.initial_rto;
5002 new_max = srto->srto_max;
5004 new_max = stcb->asoc.maxrto;
5006 new_min = srto->srto_min;
5008 new_min = stcb->asoc.minrto;
5009 if ((new_min <= new_init) && (new_init <= new_max)) {
5010 stcb->asoc.initial_rto = new_init;
5011 stcb->asoc.maxrto = new_max;
5012 stcb->asoc.minrto = new_min;
5014 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5017 SCTP_TCB_UNLOCK(stcb);
5019 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5020 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5021 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5022 SCTP_INP_WLOCK(inp);
5023 if (srto->srto_initial)
5024 new_init = srto->srto_initial;
5026 new_init = inp->sctp_ep.initial_rto;
5028 new_max = srto->srto_max;
5030 new_max = inp->sctp_ep.sctp_maxrto;
5032 new_min = srto->srto_min;
5034 new_min = inp->sctp_ep.sctp_minrto;
5035 if ((new_min <= new_init) && (new_init <= new_max)) {
5036 inp->sctp_ep.initial_rto = new_init;
5037 inp->sctp_ep.sctp_maxrto = new_max;
5038 inp->sctp_ep.sctp_minrto = new_min;
5040 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5043 SCTP_INP_WUNLOCK(inp);
5045 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5051 case SCTP_ASSOCINFO:
5053 struct sctp_assocparams *sasoc;
5055 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5056 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5057 if (sasoc->sasoc_cookie_life) {
5058 /* boundary check the cookie life */
5059 if (sasoc->sasoc_cookie_life < 1000)
5060 sasoc->sasoc_cookie_life = 1000;
5061 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5062 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5066 if (sasoc->sasoc_asocmaxrxt)
5067 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5068 if (sasoc->sasoc_cookie_life) {
5069 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5071 SCTP_TCB_UNLOCK(stcb);
5073 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5074 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5075 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5076 SCTP_INP_WLOCK(inp);
5077 if (sasoc->sasoc_asocmaxrxt)
5078 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5079 if (sasoc->sasoc_cookie_life) {
5080 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5082 SCTP_INP_WUNLOCK(inp);
5084 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5092 struct sctp_initmsg *sinit;
5094 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5095 SCTP_INP_WLOCK(inp);
5096 if (sinit->sinit_num_ostreams)
5097 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5099 if (sinit->sinit_max_instreams)
5100 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5102 if (sinit->sinit_max_attempts)
5103 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5105 if (sinit->sinit_max_init_timeo)
5106 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5107 SCTP_INP_WUNLOCK(inp);
5110 case SCTP_PRIMARY_ADDR:
5112 struct sctp_setprim *spa;
5113 struct sctp_nets *net;
5115 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5116 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5120 net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
5123 * We increment here since
5124 * sctp_findassociation_ep_addr() wil do a
5125 * decrement if it finds the stcb as long as
5126 * the locked tcb (last argument) is NOT a
5129 SCTP_INP_INCR_REF(inp);
5130 stcb = sctp_findassociation_ep_addr(&inp,
5131 (struct sockaddr *)&spa->ssp_addr,
5134 SCTP_INP_DECR_REF(inp);
5138 if ((stcb) && (net)) {
5139 if ((net != stcb->asoc.primary_destination) &&
5140 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
5141 /* Ok we need to set it */
5142 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5143 if ((stcb->asoc.alternate) &&
5144 (!(net->dest_state & SCTP_ADDR_PF)) &&
5145 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5146 sctp_free_remote_addr(stcb->asoc.alternate);
5147 stcb->asoc.alternate = NULL;
5152 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5156 SCTP_TCB_UNLOCK(stcb);
5160 case SCTP_SET_DYNAMIC_PRIMARY:
5162 union sctp_sockstore *ss;
5164 error = priv_check(curthread,
5165 PRIV_NETINET_RESERVEDPORT);
5169 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5170 /* SUPER USER CHECK? */
5171 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5174 case SCTP_SET_PEER_PRIMARY_ADDR:
5176 struct sctp_setpeerprim *sspp;
5178 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5179 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5181 struct sctp_ifa *ifa;
5183 ifa = sctp_find_ifa_by_addr((struct sockaddr *)&sspp->sspp_addr,
5184 stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5186 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5190 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5192 * Must validate the ifa found is in
5195 struct sctp_laddr *laddr;
5198 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5199 if (laddr->ifa == NULL) {
5200 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5204 if (laddr->ifa == ifa) {
5210 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5215 if (sctp_set_primary_ip_address_sa(stcb,
5216 (struct sockaddr *)&sspp->sspp_addr) != 0) {
5217 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5221 SCTP_TCB_UNLOCK(stcb);
5223 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5228 case SCTP_BINDX_ADD_ADDR:
5230 struct sctp_getaddresses *addrs;
5233 td = (struct thread *)p;
5234 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5237 if (addrs->addr->sa_family == AF_INET) {
5238 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5239 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5243 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5244 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5250 if (addrs->addr->sa_family == AF_INET6) {
5251 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5252 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5256 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5257 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5258 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5264 error = EAFNOSUPPORT;
5267 sctp_bindx_add_address(so, inp, addrs->addr,
5268 addrs->sget_assoc_id, vrf_id,
5272 case SCTP_BINDX_REM_ADDR:
5274 struct sctp_getaddresses *addrs;
5277 td = (struct thread *)p;
5279 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5281 if (addrs->addr->sa_family == AF_INET) {
5282 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5283 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5287 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5288 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5294 if (addrs->addr->sa_family == AF_INET6) {
5295 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5296 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5301 (error = prison_local_ip6(td->td_ucred,
5302 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5303 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5304 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5310 error = EAFNOSUPPORT;
5313 sctp_bindx_delete_address(inp, addrs->addr,
5314 addrs->sget_assoc_id, vrf_id,
5320 struct sctp_event *event;
5321 uint32_t event_type;
5323 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5324 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5325 switch (event->se_type) {
5326 case SCTP_ASSOC_CHANGE:
5327 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5329 case SCTP_PEER_ADDR_CHANGE:
5330 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5332 case SCTP_REMOTE_ERROR:
5333 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5335 case SCTP_SEND_FAILED:
5336 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5338 case SCTP_SHUTDOWN_EVENT:
5339 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5341 case SCTP_ADAPTATION_INDICATION:
5342 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5344 case SCTP_PARTIAL_DELIVERY_EVENT:
5345 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5347 case SCTP_AUTHENTICATION_EVENT:
5348 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5350 case SCTP_STREAM_RESET_EVENT:
5351 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5353 case SCTP_SENDER_DRY_EVENT:
5354 event_type = SCTP_PCB_FLAGS_DRYEVNT;
5356 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
5358 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5361 case SCTP_ASSOC_RESET_EVENT:
5362 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
5364 case SCTP_STREAM_CHANGE_EVENT:
5365 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
5367 case SCTP_SEND_FAILED_EVENT:
5368 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
5372 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5376 if (event_type > 0) {
5379 sctp_stcb_feature_on(inp, stcb, event_type);
5380 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
5381 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5382 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5383 (stcb->asoc.stream_queue_cnt == 0)) {
5384 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5388 sctp_stcb_feature_off(inp, stcb, event_type);
5390 SCTP_TCB_UNLOCK(stcb);
5393 * We don't want to send up a storm
5394 * of events, so return an error for
5397 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
5398 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
5399 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
5400 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
5401 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
5402 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5406 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5407 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5408 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
5409 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5410 SCTP_INP_WLOCK(inp);
5412 sctp_feature_on(inp, event_type);
5414 sctp_feature_off(inp, event_type);
5416 SCTP_INP_WUNLOCK(inp);
5418 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
5419 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5420 SCTP_INP_RLOCK(inp);
5421 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5422 SCTP_TCB_LOCK(stcb);
5424 sctp_stcb_feature_on(inp, stcb, event_type);
5426 sctp_stcb_feature_off(inp, stcb, event_type);
5428 SCTP_TCB_UNLOCK(stcb);
5430 SCTP_INP_RUNLOCK(inp);
5436 case SCTP_RECVRCVINFO:
5440 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5441 SCTP_INP_WLOCK(inp);
5443 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5445 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5447 SCTP_INP_WUNLOCK(inp);
5450 case SCTP_RECVNXTINFO:
5454 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5455 SCTP_INP_WLOCK(inp);
5457 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5459 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5461 SCTP_INP_WUNLOCK(inp);
5464 case SCTP_DEFAULT_SNDINFO:
5466 struct sctp_sndinfo *info;
5469 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
5470 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
5473 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5474 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5475 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5476 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5477 stcb->asoc.def_send.sinfo_flags |= policy;
5478 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5479 stcb->asoc.def_send.sinfo_context = info->snd_context;
5481 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5484 SCTP_TCB_UNLOCK(stcb);
5486 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5487 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5488 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
5489 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5490 SCTP_INP_WLOCK(inp);
5491 inp->def_send.sinfo_stream = info->snd_sid;
5492 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
5493 inp->def_send.sinfo_flags = info->snd_flags;
5494 inp->def_send.sinfo_flags |= policy;
5495 inp->def_send.sinfo_ppid = info->snd_ppid;
5496 inp->def_send.sinfo_context = info->snd_context;
5497 SCTP_INP_WUNLOCK(inp);
5499 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
5500 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5501 SCTP_INP_RLOCK(inp);
5502 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5503 SCTP_TCB_LOCK(stcb);
5504 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5505 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5506 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5507 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5508 stcb->asoc.def_send.sinfo_flags |= policy;
5509 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5510 stcb->asoc.def_send.sinfo_context = info->snd_context;
5512 SCTP_TCB_UNLOCK(stcb);
5514 SCTP_INP_RUNLOCK(inp);
5519 case SCTP_DEFAULT_PRINFO:
5521 struct sctp_default_prinfo *info;
5523 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
5524 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
5526 if (PR_SCTP_INVALID_POLICY(info->pr_policy)) {
5527 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5532 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5533 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5534 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
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->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
5540 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5541 SCTP_INP_WLOCK(inp);
5542 inp->def_send.sinfo_flags &= 0xfff0;
5543 inp->def_send.sinfo_flags |= info->pr_policy;
5544 inp->def_send.sinfo_timetolive = info->pr_value;
5545 SCTP_INP_WUNLOCK(inp);
5547 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
5548 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5549 SCTP_INP_RLOCK(inp);
5550 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5551 SCTP_TCB_LOCK(stcb);
5552 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5553 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5554 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5555 SCTP_TCB_UNLOCK(stcb);
5557 SCTP_INP_RUNLOCK(inp);
5562 case SCTP_PEER_ADDR_THLDS:
5563 /* Applies to the specific association */
5565 struct sctp_paddrthlds *thlds;
5566 struct sctp_nets *net;
5568 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
5569 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
5572 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_assoc_id);
5575 * We increment here since
5576 * sctp_findassociation_ep_addr() wil do a
5577 * decrement if it finds the stcb as long as
5578 * the locked tcb (last argument) is NOT a
5581 SCTP_INP_INCR_REF(inp);
5582 stcb = sctp_findassociation_ep_addr(&inp,
5583 (struct sockaddr *)&thlds->spt_assoc_id,
5586 SCTP_INP_DECR_REF(inp);
5589 if (stcb && (net == NULL)) {
5590 struct sockaddr *sa;
5592 sa = (struct sockaddr *)&thlds->spt_assoc_id;
5594 if (sa->sa_family == AF_INET) {
5596 struct sockaddr_in *sin;
5598 sin = (struct sockaddr_in *)sa;
5599 if (sin->sin_addr.s_addr) {
5600 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5601 SCTP_TCB_UNLOCK(stcb);
5608 if (sa->sa_family == AF_INET6) {
5609 struct sockaddr_in6 *sin6;
5611 sin6 = (struct sockaddr_in6 *)sa;
5612 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5613 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5614 SCTP_TCB_UNLOCK(stcb);
5621 error = EAFNOSUPPORT;
5622 SCTP_TCB_UNLOCK(stcb);
5623 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5629 if (net->dest_state & SCTP_ADDR_PF) {
5630 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5631 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5632 net->dest_state &= ~SCTP_ADDR_PF;
5635 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5636 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5637 net->dest_state |= SCTP_ADDR_PF;
5638 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5639 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5640 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5643 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5644 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5645 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5646 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5649 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5650 net->dest_state |= SCTP_ADDR_REACHABLE;
5651 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5654 net->failure_threshold = thlds->spt_pathmaxrxt;
5655 net->pf_threshold = thlds->spt_pathpfthld;
5657 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5658 if (net->dest_state & SCTP_ADDR_PF) {
5659 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5660 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5661 net->dest_state &= ~SCTP_ADDR_PF;
5664 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5665 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5666 net->dest_state |= SCTP_ADDR_PF;
5667 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5668 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5669 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5672 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5673 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5674 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5675 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5678 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5679 net->dest_state |= SCTP_ADDR_REACHABLE;
5680 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5683 net->failure_threshold = thlds->spt_pathmaxrxt;
5684 net->pf_threshold = thlds->spt_pathpfthld;
5686 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
5687 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
5690 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5691 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5692 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
5693 SCTP_INP_WLOCK(inp);
5694 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
5695 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
5696 SCTP_INP_WUNLOCK(inp);
5698 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5704 case SCTP_REMOTE_UDP_ENCAPS_PORT:
5706 struct sctp_udpencaps *encaps;
5707 struct sctp_nets *net;
5709 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
5710 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
5712 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
5715 * We increment here since
5716 * sctp_findassociation_ep_addr() wil do a
5717 * decrement if it finds the stcb as long as
5718 * the locked tcb (last argument) is NOT a
5722 SCTP_INP_INCR_REF(inp);
5723 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
5725 SCTP_INP_DECR_REF(inp);
5728 if (stcb && (net == NULL)) {
5729 struct sockaddr *sa;
5731 sa = (struct sockaddr *)&encaps->sue_address;
5733 if (sa->sa_family == AF_INET) {
5735 struct sockaddr_in *sin;
5737 sin = (struct sockaddr_in *)sa;
5738 if (sin->sin_addr.s_addr) {
5739 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5740 SCTP_TCB_UNLOCK(stcb);
5747 if (sa->sa_family == AF_INET6) {
5748 struct sockaddr_in6 *sin6;
5750 sin6 = (struct sockaddr_in6 *)sa;
5751 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5752 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5753 SCTP_TCB_UNLOCK(stcb);
5760 error = EAFNOSUPPORT;
5761 SCTP_TCB_UNLOCK(stcb);
5762 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5768 net->port = encaps->sue_port;
5770 stcb->asoc.port = encaps->sue_port;
5772 SCTP_TCB_UNLOCK(stcb);
5774 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5775 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5776 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
5777 SCTP_INP_WLOCK(inp);
5778 inp->sctp_ep.port = encaps->sue_port;
5779 SCTP_INP_WUNLOCK(inp);
5781 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5788 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
5789 error = ENOPROTOOPT;
5791 } /* end switch (opt) */
5796 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
5798 void *optval = NULL;
5803 if (sopt->sopt_level != IPPROTO_SCTP) {
5804 /* wrong proto level... send back up to IP */
5806 if (INP_CHECK_SOCKAF(so, AF_INET6))
5807 error = ip6_ctloutput(so, sopt);
5809 #if defined(INET) && defined(INET6)
5813 error = ip_ctloutput(so, sopt);
5817 optsize = sopt->sopt_valsize;
5819 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
5820 if (optval == NULL) {
5821 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
5824 error = sooptcopyin(sopt, optval, optsize, optsize);
5826 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5830 p = (void *)sopt->sopt_td;
5831 if (sopt->sopt_dir == SOPT_SET) {
5832 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
5833 } else if (sopt->sopt_dir == SOPT_GET) {
5834 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
5836 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5839 if ((error == 0) && (optval != NULL)) {
5840 error = sooptcopyout(sopt, optval, optsize);
5841 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5842 } else if (optval != NULL) {
5843 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5851 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
5854 int create_lock_on = 0;
5856 struct sctp_inpcb *inp;
5857 struct sctp_tcb *stcb = NULL;
5859 inp = (struct sctp_inpcb *)so->so_pcb;
5861 /* I made the same as TCP since we are not setup? */
5862 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5863 return (ECONNRESET);
5866 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5869 switch (addr->sa_family) {
5873 struct sockaddr_in6 *sin6p;
5875 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
5876 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5879 sin6p = (struct sockaddr_in6 *)addr;
5880 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
5881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5890 struct sockaddr_in *sinp;
5892 if (addr->sa_len != sizeof(struct sockaddr_in)) {
5893 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5896 sinp = (struct sockaddr_in *)addr;
5897 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
5898 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5905 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
5906 return (EAFNOSUPPORT);
5908 SCTP_INP_INCR_REF(inp);
5909 SCTP_ASOC_CREATE_LOCK(inp);
5913 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
5914 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
5915 /* Should I really unlock ? */
5916 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
5921 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
5922 (addr->sa_family == AF_INET6)) {
5923 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5928 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
5929 SCTP_PCB_FLAGS_UNBOUND) {
5930 /* Bind a ephemeral port */
5931 error = sctp_inpcb_bind(so, NULL, NULL, p);
5936 /* Now do we connect? */
5937 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
5938 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
5939 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5943 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
5944 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
5945 /* We are already connected AND the TCP model */
5946 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
5950 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
5951 SCTP_INP_RLOCK(inp);
5952 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5953 SCTP_INP_RUNLOCK(inp);
5956 * We increment here since sctp_findassociation_ep_addr()
5957 * will do a decrement if it finds the stcb as long as the
5958 * locked tcb (last argument) is NOT a TCB.. aka NULL.
5960 SCTP_INP_INCR_REF(inp);
5961 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
5963 SCTP_INP_DECR_REF(inp);
5965 SCTP_TCB_UNLOCK(stcb);
5969 /* Already have or am bring up an association */
5970 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
5974 vrf_id = inp->def_vrf_id;
5975 /* We are GOOD to go */
5976 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
5978 /* Gak! no memory */
5981 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
5982 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
5983 /* Set the connected flag so we can queue data */
5986 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
5987 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
5989 /* initialize authentication parameters for the assoc */
5990 sctp_initialize_auth_params(inp, stcb);
5992 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
5993 SCTP_TCB_UNLOCK(stcb);
5995 if (create_lock_on) {
5996 SCTP_ASOC_CREATE_UNLOCK(inp);
5998 SCTP_INP_DECR_REF(inp);
6005 sctp_listen(struct socket *so, int backlog, struct thread *p)
6008 * Note this module depends on the protocol processing being called
6009 * AFTER any socket level flags and backlog are applied to the
6010 * socket. The traditional way that the socket flags are applied is
6011 * AFTER protocol processing. We have made a change to the
6012 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
6013 * place if the socket API for SCTP is to work properly.
6017 struct sctp_inpcb *inp;
6019 inp = (struct sctp_inpcb *)so->so_pcb;
6021 /* I made the same as TCP since we are not setup? */
6022 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6023 return (ECONNRESET);
6025 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
6026 /* See if we have a listener */
6027 struct sctp_inpcb *tinp;
6028 union sctp_sockstore store, *sp;
6031 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
6033 struct sctp_laddr *laddr;
6035 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6036 memcpy(&store, &laddr->ifa->address, sizeof(store));
6037 switch (sp->sa.sa_family) {
6040 sp->sin.sin_port = inp->sctp_lport;
6045 sp->sin6.sin6_port = inp->sctp_lport;
6051 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6052 if (tinp && (tinp != inp) &&
6053 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6054 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6055 (tinp->sctp_socket->so_qlimit)) {
6057 * we have a listener already and
6060 SCTP_INP_DECR_REF(tinp);
6061 return (EADDRINUSE);
6063 SCTP_INP_DECR_REF(tinp);
6067 /* Setup a local addr bound all */
6068 memset(&store, 0, sizeof(store));
6069 switch (sp->sa.sa_family) {
6072 store.sin.sin_port = inp->sctp_lport;
6077 sp->sin6.sin6_port = inp->sctp_lport;
6084 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
6085 store.sa.sa_family = AF_INET6;
6086 store.sa.sa_len = sizeof(struct sockaddr_in6);
6090 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
6091 store.sa.sa_family = AF_INET;
6092 store.sa.sa_len = sizeof(struct sockaddr_in);
6095 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6096 if (tinp && (tinp != inp) &&
6097 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6098 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6099 (tinp->sctp_socket->so_qlimit)) {
6101 * we have a listener already and its not
6104 SCTP_INP_DECR_REF(tinp);
6105 return (EADDRINUSE);
6107 SCTP_INP_DECR_REF(inp);
6111 SCTP_INP_RLOCK(inp);
6112 #ifdef SCTP_LOCK_LOGGING
6113 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
6114 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
6118 error = solisten_proto_check(so);
6121 SCTP_INP_RUNLOCK(inp);
6124 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
6125 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
6127 * The unlucky case - We are in the tcp pool with this guy.
6128 * - Someone else is in the main inp slot. - We must move
6129 * this guy (the listener) to the main slot - We must then
6130 * move the guy that was listener to the TCP Pool.
6132 if (sctp_swap_inpcb_for_listen(inp)) {
6136 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6137 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6138 /* We are already connected AND the TCP model */
6140 SCTP_INP_RUNLOCK(inp);
6142 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6143 return (EADDRINUSE);
6145 SCTP_INP_RUNLOCK(inp);
6146 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
6147 /* We must do a bind. */
6149 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
6150 /* bind error, probably perm */
6155 /* It appears for 7.0 and on, we must always call this. */
6156 solisten_proto(so, backlog);
6157 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6158 /* remove the ACCEPTCONN flag for one-to-many sockets */
6159 so->so_options &= ~SO_ACCEPTCONN;
6162 /* turning off listen */
6163 so->so_options &= ~SO_ACCEPTCONN;
6169 static int sctp_defered_wakeup_cnt = 0;
6172 sctp_accept(struct socket *so, struct sockaddr **addr)
6174 struct sctp_tcb *stcb;
6175 struct sctp_inpcb *inp;
6176 union sctp_sockstore store;
6182 inp = (struct sctp_inpcb *)so->so_pcb;
6185 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6186 return (ECONNRESET);
6188 SCTP_INP_RLOCK(inp);
6189 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6190 SCTP_INP_RUNLOCK(inp);
6191 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
6192 return (EOPNOTSUPP);
6194 if (so->so_state & SS_ISDISCONNECTED) {
6195 SCTP_INP_RUNLOCK(inp);
6196 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
6197 return (ECONNABORTED);
6199 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6201 SCTP_INP_RUNLOCK(inp);
6202 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6203 return (ECONNRESET);
6205 SCTP_TCB_LOCK(stcb);
6206 SCTP_INP_RUNLOCK(inp);
6207 store = stcb->asoc.primary_destination->ro._l_addr;
6208 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
6209 SCTP_TCB_UNLOCK(stcb);
6210 switch (store.sa.sa_family) {
6214 struct sockaddr_in *sin;
6216 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6219 sin->sin_family = AF_INET;
6220 sin->sin_len = sizeof(*sin);
6221 sin->sin_port = store.sin.sin_port;
6222 sin->sin_addr = store.sin.sin_addr;
6223 *addr = (struct sockaddr *)sin;
6230 struct sockaddr_in6 *sin6;
6232 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
6235 sin6->sin6_family = AF_INET6;
6236 sin6->sin6_len = sizeof(*sin6);
6237 sin6->sin6_port = store.sin6.sin6_port;
6238 sin6->sin6_addr = store.sin6.sin6_addr;
6239 if ((error = sa6_recoverscope(sin6)) != 0) {
6240 SCTP_FREE_SONAME(sin6);
6243 *addr = (struct sockaddr *)sin6;
6251 /* Wake any delayed sleep action */
6252 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
6253 SCTP_INP_WLOCK(inp);
6254 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
6255 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
6256 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
6257 SCTP_INP_WUNLOCK(inp);
6258 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
6259 if (sowriteable(inp->sctp_socket)) {
6260 sowwakeup_locked(inp->sctp_socket);
6262 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
6264 SCTP_INP_WLOCK(inp);
6266 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
6267 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
6268 SCTP_INP_WUNLOCK(inp);
6269 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
6270 if (soreadable(inp->sctp_socket)) {
6271 sctp_defered_wakeup_cnt++;
6272 sorwakeup_locked(inp->sctp_socket);
6274 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
6276 SCTP_INP_WLOCK(inp);
6278 SCTP_INP_WUNLOCK(inp);
6280 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
6281 SCTP_TCB_LOCK(stcb);
6282 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
6289 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
6291 struct sockaddr_in *sin;
6293 struct sctp_inpcb *inp;
6294 struct sctp_ifa *sctp_ifa;
6297 * Do the malloc first in case it blocks.
6299 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6302 sin->sin_family = AF_INET;
6303 sin->sin_len = sizeof(*sin);
6304 inp = (struct sctp_inpcb *)so->so_pcb;
6306 SCTP_FREE_SONAME(sin);
6307 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6308 return (ECONNRESET);
6310 SCTP_INP_RLOCK(inp);
6311 sin->sin_port = inp->sctp_lport;
6312 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
6313 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6314 struct sctp_tcb *stcb;
6315 struct sockaddr_in *sin_a;
6316 struct sctp_nets *net;
6319 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6325 SCTP_TCB_LOCK(stcb);
6326 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6327 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6329 /* this will make coverity happy */
6332 if (sin_a->sin_family == AF_INET) {
6337 if ((!fnd) || (sin_a == NULL)) {
6339 SCTP_TCB_UNLOCK(stcb);
6342 vrf_id = inp->def_vrf_id;
6343 sctp_ifa = sctp_source_address_selection(inp,
6345 (sctp_route_t *) & net->ro,
6348 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
6349 sctp_free_ifa(sctp_ifa);
6351 SCTP_TCB_UNLOCK(stcb);
6353 /* For the bound all case you get back 0 */
6355 sin->sin_addr.s_addr = 0;
6359 /* Take the first IPv4 address in the list */
6360 struct sctp_laddr *laddr;
6363 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6364 if (laddr->ifa->address.sa.sa_family == AF_INET) {
6365 struct sockaddr_in *sin_a;
6367 sin_a = (struct sockaddr_in *)&laddr->ifa->address.sa;
6368 sin->sin_addr = sin_a->sin_addr;
6374 SCTP_FREE_SONAME(sin);
6375 SCTP_INP_RUNLOCK(inp);
6376 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6380 SCTP_INP_RUNLOCK(inp);
6381 (*addr) = (struct sockaddr *)sin;
6386 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
6388 struct sockaddr_in *sin;
6390 struct sockaddr_in *sin_a;
6391 struct sctp_inpcb *inp;
6392 struct sctp_tcb *stcb;
6393 struct sctp_nets *net;
6395 /* Do the malloc first in case it blocks. */
6396 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6399 sin->sin_family = AF_INET;
6400 sin->sin_len = sizeof(*sin);
6402 inp = (struct sctp_inpcb *)so->so_pcb;
6403 if ((inp == NULL) ||
6404 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
6405 /* UDP type and listeners will drop out here */
6406 SCTP_FREE_SONAME(sin);
6407 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
6410 SCTP_INP_RLOCK(inp);
6411 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6413 SCTP_TCB_LOCK(stcb);
6415 SCTP_INP_RUNLOCK(inp);
6417 SCTP_FREE_SONAME(sin);
6418 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6419 return (ECONNRESET);
6422 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6423 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6424 if (sin_a->sin_family == AF_INET) {
6426 sin->sin_port = stcb->rport;
6427 sin->sin_addr = sin_a->sin_addr;
6431 SCTP_TCB_UNLOCK(stcb);
6433 /* No IPv4 address */
6434 SCTP_FREE_SONAME(sin);
6435 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6438 (*addr) = (struct sockaddr *)sin;
6442 struct pr_usrreqs sctp_usrreqs = {
6443 .pru_abort = sctp_abort,
6444 .pru_accept = sctp_accept,
6445 .pru_attach = sctp_attach,
6446 .pru_bind = sctp_bind,
6447 .pru_connect = sctp_connect,
6448 .pru_control = in_control,
6449 .pru_close = sctp_close,
6450 .pru_detach = sctp_close,
6451 .pru_sopoll = sopoll_generic,
6452 .pru_flush = sctp_flush,
6453 .pru_disconnect = sctp_disconnect,
6454 .pru_listen = sctp_listen,
6455 .pru_peeraddr = sctp_peeraddr,
6456 .pru_send = sctp_sendm,
6457 .pru_shutdown = sctp_shutdown,
6458 .pru_sockaddr = sctp_ingetaddr,
6459 .pru_sosend = sctp_sosend,
6460 .pru_soreceive = sctp_soreceive