2 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * a) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
12 * b) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the distribution.
16 * c) Neither the name of Cisco Systems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <netinet/sctp_os.h>
38 #include <netinet/sctp_pcb.h>
39 #include <netinet/sctp_header.h>
40 #include <netinet/sctp_var.h>
43 #include <netinet/sctp_sysctl.h>
44 #include <netinet/sctp_output.h>
45 #include <netinet/sctp_uio.h>
46 #include <netinet/sctp_asconf.h>
47 #include <netinet/sctputil.h>
48 #include <netinet/sctp_indata.h>
49 #include <netinet/sctp_timer.h>
50 #include <netinet/sctp_auth.h>
51 #include <netinet/sctp_bsd_addr.h>
52 #include <netinet/udp.h>
56 extern struct sctp_cc_functions sctp_cc_functions[];
57 extern struct sctp_ss_functions sctp_ss_functions[];
64 /* Initialize and modify the sysctled variables */
66 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
67 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
69 * Allow a user to take no more than 1/2 the number of clusters or
70 * the SB_MAX whichever is smaller for the send window.
72 sb_max_adj = (u_long)((u_quad_t) (SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
73 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
74 (((uint32_t) nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
76 * Now for the recv window, should we take the same amount? or
77 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
78 * now I will just copy.
80 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
81 SCTP_BASE_VAR(first_time) = 0;
82 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
84 #if defined(SCTP_PACKET_LOGGING)
85 SCTP_BASE_VAR(packet_log_writers) = 0;
86 SCTP_BASE_VAR(packet_log_end) = 0;
87 bzero(&SCTP_BASE_VAR(packet_log_buffer), SCTP_PACKET_LOG_SIZE);
100 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
102 struct sctp_tmit_chunk *chk;
105 /* Adjust that too */
106 stcb->asoc.smallest_mtu = nxtsz;
107 /* now off to subtract IP_DF flag if needed */
108 overhead = IP_HDR_SIZE;
109 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
110 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
112 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
113 if ((chk->send_size + overhead) > nxtsz) {
114 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
117 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
118 if ((chk->send_size + overhead) > nxtsz) {
120 * For this guy we also mark for immediate resend
121 * since we sent to big of chunk
123 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
124 if (chk->sent < SCTP_DATAGRAM_RESEND) {
125 sctp_flight_size_decrease(chk);
126 sctp_total_flight_decrease(stcb, chk);
128 if (chk->sent != SCTP_DATAGRAM_RESEND) {
129 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
131 chk->sent = SCTP_DATAGRAM_RESEND;
132 chk->rec.data.doing_fast_retransmit = 0;
133 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
134 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
135 chk->whoTo->flight_size,
137 (uintptr_t) chk->whoTo,
138 chk->rec.data.TSN_seq);
140 /* Clear any time so NO RTT is being done */
148 sctp_notify_mbuf(struct sctp_inpcb *inp,
149 struct sctp_tcb *stcb,
150 struct sctp_nets *net,
155 int totsz, tmr_stopped = 0;
159 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
160 (ip == NULL) || (sh == NULL)) {
162 SCTP_TCB_UNLOCK(stcb);
166 /* First job is to verify the vtag matches what I would send */
167 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
168 SCTP_TCB_UNLOCK(stcb);
171 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
173 if (icmph->icmp_type != ICMP_UNREACH) {
174 /* We only care about unreachable */
175 SCTP_TCB_UNLOCK(stcb);
178 if (icmph->icmp_code != ICMP_UNREACH_NEEDFRAG) {
179 /* not a unreachable message due to frag. */
180 SCTP_TCB_UNLOCK(stcb);
185 nxtsz = ntohs(icmph->icmp_nextmtu);
188 * old type router that does not tell us what the next size
189 * mtu is. Rats we will have to guess (in a educated fashion
192 nxtsz = sctp_get_prev_mtu(totsz);
194 /* Stop any PMTU timer */
195 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
197 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
198 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
200 /* Adjust destination size limit */
201 if (net->mtu > nxtsz) {
204 net->mtu -= sizeof(struct udphdr);
207 /* now what about the ep? */
208 if (stcb->asoc.smallest_mtu > nxtsz) {
209 sctp_pathmtu_adjustment(stcb, nxtsz);
212 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
214 SCTP_TCB_UNLOCK(stcb);
220 sctp_notify(struct sctp_inpcb *inp,
224 struct sctp_tcb *stcb,
225 struct sctp_nets *net)
227 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
234 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
235 (sh == NULL) || (to == NULL)) {
237 SCTP_TCB_UNLOCK(stcb);
240 /* First job is to verify the vtag matches what I would send */
241 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
242 SCTP_TCB_UNLOCK(stcb);
245 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
247 if (icmph->icmp_type != ICMP_UNREACH) {
248 /* We only care about unreachable */
249 SCTP_TCB_UNLOCK(stcb);
252 if ((icmph->icmp_code == ICMP_UNREACH_NET) ||
253 (icmph->icmp_code == ICMP_UNREACH_HOST) ||
254 (icmph->icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
255 (icmph->icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
256 (icmph->icmp_code == ICMP_UNREACH_ISOLATED) ||
257 (icmph->icmp_code == ICMP_UNREACH_NET_PROHIB) ||
258 (icmph->icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
259 (icmph->icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
262 * Hmm reachablity problems we must examine closely. If its
263 * not reachable, we may have lost a network. Or if there is
264 * NO protocol at the other end named SCTP. well we consider
267 if (net->dest_state & SCTP_ADDR_REACHABLE) {
268 /* Ok that destination is NOT reachable */
269 net->dest_state &= ~SCTP_ADDR_REACHABLE;
270 net->dest_state &= ~SCTP_ADDR_PF;
271 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
273 (void *)net, SCTP_SO_NOT_LOCKED);
275 SCTP_TCB_UNLOCK(stcb);
276 } else if ((icmph->icmp_code == ICMP_UNREACH_PROTOCOL) ||
277 (icmph->icmp_code == ICMP_UNREACH_PORT)) {
279 * Here the peer is either playing tricks on us, including
280 * an address that belongs to someone who does not support
281 * SCTP OR was a userland implementation that shutdown and
282 * now is dead. In either case treat it like a OOTB abort
285 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
286 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
287 so = SCTP_INP_SO(inp);
288 atomic_add_int(&stcb->asoc.refcnt, 1);
289 SCTP_TCB_UNLOCK(stcb);
290 SCTP_SOCKET_LOCK(so, 1);
292 atomic_subtract_int(&stcb->asoc.refcnt, 1);
294 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
295 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
296 SCTP_SOCKET_UNLOCK(so, 1);
297 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
299 /* no need to unlock here, since the TCB is gone */
301 SCTP_TCB_UNLOCK(stcb);
307 sctp_ctlinput(cmd, sa, vip)
316 /* FIX, for non-bsd is this right? */
317 vrf_id = SCTP_DEFAULT_VRFID;
318 if (sa->sa_family != AF_INET ||
319 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
322 if (PRC_IS_REDIRECT(cmd)) {
324 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
328 struct sctp_inpcb *inp = NULL;
329 struct sctp_tcb *stcb = NULL;
330 struct sctp_nets *net = NULL;
331 struct sockaddr_in to, from;
333 sh = (struct sctphdr *)((caddr_t)ip + (ip->ip_hl << 2));
334 bzero(&to, sizeof(to));
335 bzero(&from, sizeof(from));
336 from.sin_family = to.sin_family = AF_INET;
337 from.sin_len = to.sin_len = sizeof(to);
338 from.sin_port = sh->src_port;
339 from.sin_addr = ip->ip_src;
340 to.sin_port = sh->dest_port;
341 to.sin_addr = ip->ip_dst;
344 * 'to' holds the dest of the packet that failed to be sent.
345 * 'from' holds our local endpoint address. Thus we reverse
346 * the to and the from in the lookup.
348 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&to,
349 (struct sockaddr *)&from,
350 &inp, &net, 1, vrf_id);
351 if (stcb != NULL && inp && (inp->sctp_socket != NULL)) {
352 if (cmd != PRC_MSGSIZE) {
353 sctp_notify(inp, ip, sh,
354 (struct sockaddr *)&to, stcb,
357 /* handle possible ICMP size messages */
358 sctp_notify_mbuf(inp, stcb, net, ip, sh);
361 if ((stcb == NULL) && (inp != NULL)) {
362 /* reduce ref-count */
364 SCTP_INP_DECR_REF(inp);
365 SCTP_INP_WUNLOCK(inp);
368 SCTP_TCB_UNLOCK(stcb);
378 sctp_getcred(SYSCTL_HANDLER_ARGS)
381 struct sockaddr_in addrs[2];
382 struct sctp_inpcb *inp;
383 struct sctp_nets *net;
384 struct sctp_tcb *stcb;
388 /* FIX, for non-bsd is this right? */
389 vrf_id = SCTP_DEFAULT_VRFID;
391 error = priv_check(req->td, PRIV_NETINET_GETCRED);
396 error = SYSCTL_IN(req, addrs, sizeof(addrs));
400 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
402 &inp, &net, 1, vrf_id);
403 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
404 if ((inp != NULL) && (stcb == NULL)) {
405 /* reduce ref-count */
407 SCTP_INP_DECR_REF(inp);
410 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
414 SCTP_TCB_UNLOCK(stcb);
416 * We use the write lock here, only since in the error leg we need
417 * it. If we used RLOCK, then we would have to
418 * wlock/decr/unlock/rlock. Which in theory could create a hole.
419 * Better to use higher wlock.
423 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
425 SCTP_INP_WUNLOCK(inp);
428 cru2x(inp->sctp_socket->so_cred, &xuc);
429 SCTP_INP_WUNLOCK(inp);
430 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
435 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
436 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
441 sctp_abort(struct socket *so)
443 struct sctp_inpcb *inp;
446 inp = (struct sctp_inpcb *)so->so_pcb;
451 flags = inp->sctp_flags;
452 #ifdef SCTP_LOG_CLOSING
453 sctp_log_closing(inp, NULL, 17);
455 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
456 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
457 #ifdef SCTP_LOG_CLOSING
458 sctp_log_closing(inp, NULL, 16);
460 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
461 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
463 SCTP_SB_CLEAR(so->so_snd);
465 * same for the rcv ones, they are only here for the
468 SCTP_SB_CLEAR(so->so_rcv);
470 /* Now null out the reference, we are completely detached. */
474 flags = inp->sctp_flags;
475 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
476 goto sctp_must_try_again;
483 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
485 struct sctp_inpcb *inp;
486 struct inpcb *ip_inp;
488 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
495 inp = (struct sctp_inpcb *)so->so_pcb;
497 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
500 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
501 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
506 error = sctp_inpcb_alloc(so, vrf_id);
510 inp = (struct sctp_inpcb *)so->so_pcb;
512 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
513 ip_inp = &inp->ip_inp.inp;
514 ip_inp->inp_vflag |= INP_IPV4;
515 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
517 error = ipsec_init_policy(so, &ip_inp->inp_sp);
518 #ifdef SCTP_LOG_CLOSING
519 sctp_log_closing(inp, NULL, 17);
523 flags = inp->sctp_flags;
524 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
525 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
526 #ifdef SCTP_LOG_CLOSING
527 sctp_log_closing(inp, NULL, 15);
529 SCTP_INP_WUNLOCK(inp);
530 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
531 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
533 flags = inp->sctp_flags;
534 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
537 SCTP_INP_WUNLOCK(inp);
543 SCTP_INP_WUNLOCK(inp);
548 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
550 struct sctp_inpcb *inp;
552 inp = (struct sctp_inpcb *)so->so_pcb;
554 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
558 if ((addr->sa_family != AF_INET) ||
559 (addr->sa_len != sizeof(struct sockaddr_in))) {
560 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
564 return (sctp_inpcb_bind(so, addr, NULL, p));
569 sctp_close(struct socket *so)
571 struct sctp_inpcb *inp;
574 inp = (struct sctp_inpcb *)so->so_pcb;
579 * Inform all the lower layer assoc that we are done.
582 flags = inp->sctp_flags;
583 #ifdef SCTP_LOG_CLOSING
584 sctp_log_closing(inp, NULL, 17);
586 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
587 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
588 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
589 (so->so_rcv.sb_cc > 0)) {
590 #ifdef SCTP_LOG_CLOSING
591 sctp_log_closing(inp, NULL, 13);
593 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
594 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
596 #ifdef SCTP_LOG_CLOSING
597 sctp_log_closing(inp, NULL, 14);
599 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
600 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
603 * The socket is now detached, no matter what the state of
604 * the SCTP association.
607 SCTP_SB_CLEAR(so->so_snd);
609 * same for the rcv ones, they are only here for the
612 SCTP_SB_CLEAR(so->so_rcv);
614 /* Now null out the reference, we are completely detached. */
618 flags = inp->sctp_flags;
619 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
620 goto sctp_must_try_again;
628 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
629 struct mbuf *control, struct thread *p);
633 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
634 struct mbuf *control, struct thread *p)
636 struct sctp_inpcb *inp;
639 inp = (struct sctp_inpcb *)so->so_pcb;
642 sctp_m_freem(control);
645 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
649 /* Got to have an to address if we are NOT a connected socket */
650 if ((addr == NULL) &&
651 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
652 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
654 } else if (addr == NULL) {
655 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
656 error = EDESTADDRREQ;
659 sctp_m_freem(control);
665 if (addr->sa_family != AF_INET) {
666 /* must be a v4 address! */
667 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
670 sctp_m_freem(control);
673 error = EDESTADDRREQ;
678 /* now what about control */
681 SCTP_PRINTF("huh? control set?\n");
682 sctp_m_freem(inp->control);
685 inp->control = control;
689 SCTP_BUF_NEXT(inp->pkt_last) = m;
692 inp->pkt_last = inp->pkt = m;
695 /* FreeBSD uses a flag passed */
696 ((flags & PRUS_MORETOCOME) == 0)
699 * note with the current version this code will only be used
700 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
701 * re-defining sosend to use the sctp_sosend. One can
702 * optionally switch back to this code (by changing back the
703 * definitions) but this is not advisable. This code is used
704 * by FreeBSD when sending a file with sendfile() though.
708 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
718 sctp_disconnect(struct socket *so)
720 struct sctp_inpcb *inp;
722 inp = (struct sctp_inpcb *)so->so_pcb;
724 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
728 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
729 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
730 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
732 SCTP_INP_RUNLOCK(inp);
735 struct sctp_association *asoc;
736 struct sctp_tcb *stcb;
738 stcb = LIST_FIRST(&inp->sctp_asoc_list);
740 SCTP_INP_RUNLOCK(inp);
741 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
746 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
747 /* We are about to be freed, out of here */
748 SCTP_TCB_UNLOCK(stcb);
749 SCTP_INP_RUNLOCK(inp);
752 if (((so->so_options & SO_LINGER) &&
753 (so->so_linger == 0)) ||
754 (so->so_rcv.sb_cc > 0)) {
755 if (SCTP_GET_STATE(asoc) !=
756 SCTP_STATE_COOKIE_WAIT) {
757 /* Left with Data unread */
760 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_DONTWAIT, 1, MT_DATA);
766 struct sctp_paramhdr *ph;
768 ph = mtod(err, struct sctp_paramhdr *);
769 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
770 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
771 ph->param_length = htons(SCTP_BUF_LEN(err));
773 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
774 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
776 SCTP_INP_RUNLOCK(inp);
777 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
778 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
779 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
781 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
782 /* No unlock tcb assoc is gone */
785 if (TAILQ_EMPTY(&asoc->send_queue) &&
786 TAILQ_EMPTY(&asoc->sent_queue) &&
787 (asoc->stream_queue_cnt == 0)) {
788 /* there is nothing queued to send, so done */
789 if (asoc->locked_on_sending) {
792 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
793 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
794 /* only send SHUTDOWN 1st time thru */
795 struct sctp_nets *netp;
797 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
798 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
799 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
801 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
802 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
803 sctp_stop_timers_for_shutdown(stcb);
804 if (stcb->asoc.alternate) {
805 netp = stcb->asoc.alternate;
807 netp = stcb->asoc.primary_destination;
809 sctp_send_shutdown(stcb, netp);
810 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
811 stcb->sctp_ep, stcb, netp);
812 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
813 stcb->sctp_ep, stcb, netp);
814 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
818 * we still got (or just got) data to send,
819 * so set SHUTDOWN_PENDING
822 * XXX sockets draft says that SCTP_EOF
823 * should be sent with no data. currently,
824 * we will allow user data to be sent first
825 * and move to SHUTDOWN-PENDING
827 struct sctp_nets *netp;
829 if (stcb->asoc.alternate) {
830 netp = stcb->asoc.alternate;
832 netp = stcb->asoc.primary_destination;
835 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
836 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
838 if (asoc->locked_on_sending) {
839 /* Locked to send out the data */
840 struct sctp_stream_queue_pending *sp;
842 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
844 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
845 asoc->locked_on_sending->stream_no);
847 if ((sp->length == 0) && (sp->msg_is_complete == 0))
848 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
851 if (TAILQ_EMPTY(&asoc->send_queue) &&
852 TAILQ_EMPTY(&asoc->sent_queue) &&
853 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
857 op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
858 0, M_DONTWAIT, 1, MT_DATA);
864 struct sctp_paramhdr *ph;
867 SCTP_BUF_LEN(op_err) =
868 (sizeof(struct sctp_paramhdr) + sizeof(uint32_t));
870 struct sctp_paramhdr *);
871 ph->param_type = htons(
872 SCTP_CAUSE_USER_INITIATED_ABT);
873 ph->param_length = htons(SCTP_BUF_LEN(op_err));
874 ippp = (uint32_t *) (ph + 1);
875 *ippp = htonl(SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4);
877 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
878 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
879 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
880 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
881 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
882 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
884 SCTP_INP_RUNLOCK(inp);
885 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
888 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
891 soisdisconnecting(so);
892 SCTP_TCB_UNLOCK(stcb);
893 SCTP_INP_RUNLOCK(inp);
898 /* UDP model does not support this */
899 SCTP_INP_RUNLOCK(inp);
900 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
906 sctp_flush(struct socket *so, int how)
909 * We will just clear out the values and let subsequent close clear
910 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
911 * they will not be able to read the data, the socket will block
912 * that from happening.
914 struct sctp_inpcb *inp;
916 inp = (struct sctp_inpcb *)so->so_pcb;
918 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
922 /* For the 1 to many model this does nothing */
923 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
924 SCTP_INP_RUNLOCK(inp);
927 SCTP_INP_RUNLOCK(inp);
928 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
930 * First make sure the sb will be happy, we don't use these
931 * except maybe the count
934 SCTP_INP_READ_LOCK(inp);
935 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
936 SCTP_INP_READ_UNLOCK(inp);
937 SCTP_INP_WUNLOCK(inp);
938 so->so_rcv.sb_cc = 0;
939 so->so_rcv.sb_mbcnt = 0;
940 so->so_rcv.sb_mb = NULL;
942 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
944 * First make sure the sb will be happy, we don't use these
945 * except maybe the count
947 so->so_snd.sb_cc = 0;
948 so->so_snd.sb_mbcnt = 0;
949 so->so_snd.sb_mb = NULL;
956 sctp_shutdown(struct socket *so)
958 struct sctp_inpcb *inp;
960 inp = (struct sctp_inpcb *)so->so_pcb;
962 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
966 /* For UDP model this is a invalid call */
967 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
968 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
969 /* Restore the flags that the soshutdown took away. */
970 SOCKBUF_LOCK(&so->so_rcv);
971 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
972 SOCKBUF_UNLOCK(&so->so_rcv);
973 /* This proc will wakeup for read and do nothing (I hope) */
974 SCTP_INP_RUNLOCK(inp);
975 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
979 * Ok if we reach here its the TCP model and it is either a SHUT_WR
980 * or SHUT_RDWR. This means we put the shutdown flag against it.
983 struct sctp_tcb *stcb;
984 struct sctp_association *asoc;
987 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
988 SCTP_INP_RUNLOCK(inp);
993 stcb = LIST_FIRST(&inp->sctp_asoc_list);
996 * Ok we hit the case that the shutdown call was
997 * made after an abort or something. Nothing to do
1000 SCTP_INP_RUNLOCK(inp);
1003 SCTP_TCB_LOCK(stcb);
1005 if (TAILQ_EMPTY(&asoc->send_queue) &&
1006 TAILQ_EMPTY(&asoc->sent_queue) &&
1007 (asoc->stream_queue_cnt == 0)) {
1008 if (asoc->locked_on_sending) {
1011 /* there is nothing queued to send, so I'm done... */
1012 if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) {
1013 /* only send SHUTDOWN the first time through */
1014 struct sctp_nets *netp;
1016 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
1017 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
1018 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1020 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
1021 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
1022 sctp_stop_timers_for_shutdown(stcb);
1023 if (stcb->asoc.alternate) {
1024 netp = stcb->asoc.alternate;
1026 netp = stcb->asoc.primary_destination;
1028 sctp_send_shutdown(stcb, netp);
1029 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1030 stcb->sctp_ep, stcb, netp);
1031 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1032 stcb->sctp_ep, stcb, netp);
1033 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
1037 * we still got (or just got) data to send, so set
1040 struct sctp_nets *netp;
1042 if (stcb->asoc.alternate) {
1043 netp = stcb->asoc.alternate;
1045 netp = stcb->asoc.primary_destination;
1048 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1049 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
1052 if (asoc->locked_on_sending) {
1053 /* Locked to send out the data */
1054 struct sctp_stream_queue_pending *sp;
1056 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
1058 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
1059 asoc->locked_on_sending->stream_no);
1061 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
1062 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
1066 if (TAILQ_EMPTY(&asoc->send_queue) &&
1067 TAILQ_EMPTY(&asoc->sent_queue) &&
1068 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1069 struct mbuf *op_err;
1072 op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
1073 0, M_DONTWAIT, 1, MT_DATA);
1075 /* Fill in the user initiated abort */
1076 struct sctp_paramhdr *ph;
1079 SCTP_BUF_LEN(op_err) =
1080 sizeof(struct sctp_paramhdr) + sizeof(uint32_t);
1082 struct sctp_paramhdr *);
1083 ph->param_type = htons(
1084 SCTP_CAUSE_USER_INITIATED_ABT);
1085 ph->param_length = htons(SCTP_BUF_LEN(op_err));
1086 ippp = (uint32_t *) (ph + 1);
1087 *ippp = htonl(SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1089 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
1090 sctp_abort_an_association(stcb->sctp_ep, stcb,
1091 op_err, SCTP_SO_LOCKED);
1094 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1097 SCTP_TCB_UNLOCK(stcb);
1100 SCTP_INP_RUNLOCK(inp);
1105 * copies a "user" presentable address and removes embedded scope, etc.
1106 * returns 0 on success, 1 on error
1109 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1112 struct sockaddr_in6 lsa6;
1114 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1117 memcpy(ss, sa, sa->sa_len);
1124 * NOTE: assumes addr lock is held
1127 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1128 struct sctp_tcb *stcb,
1130 struct sockaddr_storage *sas,
1133 struct sctp_ifn *sctp_ifn;
1134 struct sctp_ifa *sctp_ifa;
1135 int loopback_scope, ipv4_local_scope, local_scope, site_scope;
1137 int ipv4_addr_legal, ipv6_addr_legal;
1138 struct sctp_vrf *vrf;
1145 /* Turn on all the appropriate scope */
1146 loopback_scope = stcb->asoc.scope.loopback_scope;
1147 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1148 local_scope = stcb->asoc.scope.local_scope;
1149 site_scope = stcb->asoc.scope.site_scope;
1150 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1151 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1153 /* Use generic values for endpoints. */
1155 ipv4_local_scope = 1;
1158 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1159 ipv6_addr_legal = 1;
1160 if (SCTP_IPV6_V6ONLY(inp)) {
1161 ipv4_addr_legal = 0;
1163 ipv4_addr_legal = 1;
1166 ipv6_addr_legal = 0;
1167 ipv4_addr_legal = 1;
1170 vrf = sctp_find_vrf(vrf_id);
1174 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1175 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1176 if ((loopback_scope == 0) &&
1177 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1178 /* Skip loopback if loopback_scope not set */
1181 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1184 * For the BOUND-ALL case, the list
1185 * associated with a TCB is Always
1186 * considered a reverse list.. i.e.
1187 * it lists addresses that are NOT
1188 * part of the association. If this
1189 * is one of those we must skip it.
1191 if (sctp_is_addr_restricted(stcb,
1196 switch (sctp_ifa->address.sa.sa_family) {
1199 if (ipv4_addr_legal) {
1200 struct sockaddr_in *sin;
1202 sin = (struct sockaddr_in *)&sctp_ifa->address.sa;
1203 if (sin->sin_addr.s_addr == 0) {
1211 if ((ipv4_local_scope == 0) &&
1212 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1216 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1217 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1218 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1219 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1220 actual += sizeof(struct sockaddr_in6);
1223 memcpy(sas, sin, sizeof(*sin));
1224 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1225 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1226 actual += sizeof(*sin);
1230 if (actual >= limit) {
1240 if (ipv6_addr_legal) {
1241 struct sockaddr_in6 *sin6;
1243 sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sa;
1244 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1252 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1253 if (local_scope == 0)
1255 if (sin6->sin6_scope_id == 0) {
1256 if (sa6_recoverscope(sin6) != 0)
1274 if ((site_scope == 0) &&
1275 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1278 memcpy(sas, sin6, sizeof(*sin6));
1279 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1280 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1281 actual += sizeof(*sin6);
1282 if (actual >= limit) {
1297 struct sctp_laddr *laddr;
1299 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1301 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1305 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1307 switch (laddr->ifa->address.sa.sa_family) {
1310 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1315 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1322 sas = (struct sockaddr_storage *)((caddr_t)sas +
1323 laddr->ifa->address.sa.sa_len);
1324 actual += laddr->ifa->address.sa.sa_len;
1325 if (actual >= limit) {
1334 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1335 struct sctp_tcb *stcb,
1337 struct sockaddr_storage *sas)
1341 SCTP_IPI_ADDR_RLOCK();
1342 /* fill up addresses for the endpoint's default vrf */
1343 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1345 SCTP_IPI_ADDR_RUNLOCK();
1350 * NOTE: assumes addr lock is held
1353 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1356 struct sctp_vrf *vrf = NULL;
1359 * In both sub-set bound an bound_all cases we return the MAXIMUM
1360 * number of addresses that you COULD get. In reality the sub-set
1361 * bound may have an exclusion list for a given TCB OR in the
1362 * bound-all case a TCB may NOT include the loopback or other
1363 * addresses as well.
1365 vrf = sctp_find_vrf(vrf_id);
1369 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1370 struct sctp_ifn *sctp_ifn;
1371 struct sctp_ifa *sctp_ifa;
1373 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1374 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1375 /* Count them if they are the right type */
1376 switch (sctp_ifa->address.sa.sa_family) {
1379 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1380 cnt += sizeof(struct sockaddr_in6);
1382 cnt += sizeof(struct sockaddr_in);
1387 cnt += sizeof(struct sockaddr_in6);
1396 struct sctp_laddr *laddr;
1398 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1399 switch (laddr->ifa->address.sa.sa_family) {
1402 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1403 cnt += sizeof(struct sockaddr_in6);
1405 cnt += sizeof(struct sockaddr_in);
1410 cnt += sizeof(struct sockaddr_in6);
1422 sctp_count_max_addresses(struct sctp_inpcb *inp)
1426 SCTP_IPI_ADDR_RLOCK();
1427 /* count addresses for the endpoint's default VRF */
1428 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1429 SCTP_IPI_ADDR_RUNLOCK();
1434 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1435 size_t optsize, void *p, int delay)
1438 int creat_lock_on = 0;
1439 struct sctp_tcb *stcb = NULL;
1440 struct sockaddr *sa;
1441 int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1443 int bad_addresses = 0;
1446 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1448 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1449 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1450 /* We are already connected AND the TCP model */
1451 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1452 return (EADDRINUSE);
1454 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1455 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1456 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1459 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1460 SCTP_INP_RLOCK(inp);
1461 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1462 SCTP_INP_RUNLOCK(inp);
1465 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1468 SCTP_INP_INCR_REF(inp);
1469 SCTP_ASOC_CREATE_LOCK(inp);
1471 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1472 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1473 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1477 totaddrp = (int *)optval;
1478 totaddr = *totaddrp;
1479 sa = (struct sockaddr *)(totaddrp + 1);
1480 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (optsize - sizeof(int)), &bad_addresses);
1481 if ((stcb != NULL) || bad_addresses) {
1482 /* Already have or am bring up an association */
1483 SCTP_ASOC_CREATE_UNLOCK(inp);
1486 SCTP_TCB_UNLOCK(stcb);
1487 if (bad_addresses == 0) {
1488 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1494 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1499 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1501 struct in6pcb *inp6;
1503 inp6 = (struct in6pcb *)inp;
1504 if (SCTP_IPV6_V6ONLY(inp6)) {
1506 * if IPV6_V6ONLY flag, ignore connections destined
1507 * to a v4 addr or v4-mapped addr
1509 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1515 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1516 SCTP_PCB_FLAGS_UNBOUND) {
1517 /* Bind a ephemeral port */
1518 error = sctp_inpcb_bind(so, NULL, NULL, p);
1523 /* FIX ME: do we want to pass in a vrf on the connect call? */
1524 vrf_id = inp->def_vrf_id;
1527 /* We are GOOD to go */
1528 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1532 /* Gak! no memory */
1535 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1536 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1537 /* Set the connected flag so we can queue data */
1540 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1541 /* move to second address */
1542 switch (sa->sa_family) {
1545 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1550 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1558 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1559 /* Fill in the return id */
1561 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1564 a_id = (sctp_assoc_t *) optval;
1565 *a_id = sctp_get_associd(stcb);
1567 /* initialize authentication parameters for the assoc */
1568 sctp_initialize_auth_params(inp, stcb);
1571 /* doing delayed connection */
1572 stcb->asoc.delayed_connection = 1;
1573 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1575 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1576 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1578 SCTP_TCB_UNLOCK(stcb);
1579 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1580 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1581 /* Set the connected flag so we can queue data */
1585 if (creat_lock_on) {
1586 SCTP_ASOC_CREATE_UNLOCK(inp);
1588 SCTP_INP_DECR_REF(inp);
1592 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1593 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1594 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1595 SCTP_INP_RLOCK(inp); \
1596 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1598 SCTP_TCB_LOCK(stcb); \
1600 SCTP_INP_RUNLOCK(inp); \
1601 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1602 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1603 if (stcb == NULL) { \
1604 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1614 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1615 if (size < sizeof(type)) { \
1616 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1620 destp = (type *)srcp; \
1625 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1628 struct sctp_inpcb *inp = NULL;
1630 struct sctp_tcb *stcb = NULL;
1632 if (optval == NULL) {
1633 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1636 inp = (struct sctp_inpcb *)so->so_pcb;
1638 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1645 case SCTP_AUTOCLOSE:
1646 case SCTP_EXPLICIT_EOR:
1647 case SCTP_AUTO_ASCONF:
1648 case SCTP_DISABLE_FRAGMENTS:
1649 case SCTP_I_WANT_MAPPED_V4_ADDR:
1650 case SCTP_USE_EXT_RCVINFO:
1651 SCTP_INP_RLOCK(inp);
1653 case SCTP_DISABLE_FRAGMENTS:
1654 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1656 case SCTP_I_WANT_MAPPED_V4_ADDR:
1657 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1659 case SCTP_AUTO_ASCONF:
1660 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1661 /* only valid for bound all sockets */
1662 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1664 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1669 case SCTP_EXPLICIT_EOR:
1670 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1673 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1675 case SCTP_USE_EXT_RCVINFO:
1676 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1678 case SCTP_AUTOCLOSE:
1679 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1680 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1686 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1687 error = ENOPROTOOPT;
1688 } /* end switch (sopt->sopt_name) */
1689 if (*optsize < sizeof(val)) {
1690 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1694 SCTP_INP_RUNLOCK(inp);
1696 /* return the option value */
1697 *(int *)optval = val;
1698 *optsize = sizeof(val);
1701 case SCTP_GET_PACKET_LOG:
1703 #ifdef SCTP_PACKET_LOGGING
1707 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1708 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1711 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1716 case SCTP_REUSE_PORT:
1720 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1721 /* Can't do this for a 1-m socket */
1725 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1726 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1727 *optsize = sizeof(uint32_t);
1730 case SCTP_PARTIAL_DELIVERY_POINT:
1734 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1735 *value = inp->partial_delivery_point;
1736 *optsize = sizeof(uint32_t);
1739 case SCTP_FRAGMENT_INTERLEAVE:
1743 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1744 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1745 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1746 *value = SCTP_FRAG_LEVEL_2;
1748 *value = SCTP_FRAG_LEVEL_1;
1751 *value = SCTP_FRAG_LEVEL_0;
1753 *optsize = sizeof(uint32_t);
1756 case SCTP_CMT_ON_OFF:
1758 struct sctp_assoc_value *av;
1760 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1761 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1763 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1764 SCTP_TCB_UNLOCK(stcb);
1766 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1767 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1768 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1769 SCTP_INP_RLOCK(inp);
1770 av->assoc_value = inp->sctp_cmt_on_off;
1771 SCTP_INP_RUNLOCK(inp);
1773 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1778 *optsize = sizeof(struct sctp_assoc_value);
1782 case SCTP_PLUGGABLE_CC:
1784 struct sctp_assoc_value *av;
1786 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1787 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1789 av->assoc_value = stcb->asoc.congestion_control_module;
1790 SCTP_TCB_UNLOCK(stcb);
1792 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1793 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1794 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1795 SCTP_INP_RLOCK(inp);
1796 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1797 SCTP_INP_RUNLOCK(inp);
1799 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1804 *optsize = sizeof(struct sctp_assoc_value);
1808 case SCTP_CC_OPTION:
1810 struct sctp_cc_option *cc_opt;
1812 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1813 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1817 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1820 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1821 *optsize = sizeof(struct sctp_cc_option);
1823 SCTP_TCB_UNLOCK(stcb);
1827 case SCTP_PLUGGABLE_SS:
1829 struct sctp_assoc_value *av;
1831 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1832 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1834 av->assoc_value = stcb->asoc.stream_scheduling_module;
1835 SCTP_TCB_UNLOCK(stcb);
1837 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1838 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1839 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1840 SCTP_INP_RLOCK(inp);
1841 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1842 SCTP_INP_RUNLOCK(inp);
1844 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1849 *optsize = sizeof(struct sctp_assoc_value);
1855 struct sctp_stream_value *av;
1857 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1858 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1860 if (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1861 &av->stream_value) < 0) {
1862 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1865 *optsize = sizeof(struct sctp_stream_value);
1867 SCTP_TCB_UNLOCK(stcb);
1870 * Can't get stream value without
1873 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1878 case SCTP_GET_ADDR_LEN:
1880 struct sctp_assoc_value *av;
1882 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1885 if (av->assoc_value == AF_INET) {
1886 av->assoc_value = sizeof(struct sockaddr_in);
1891 if (av->assoc_value == AF_INET6) {
1892 av->assoc_value = sizeof(struct sockaddr_in6);
1897 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1899 *optsize = sizeof(struct sctp_assoc_value);
1903 case SCTP_GET_ASSOC_NUMBER:
1905 uint32_t *value, cnt;
1907 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1909 SCTP_INP_RLOCK(inp);
1910 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1913 SCTP_INP_RUNLOCK(inp);
1915 *optsize = sizeof(uint32_t);
1918 case SCTP_GET_ASSOC_ID_LIST:
1920 struct sctp_assoc_ids *ids;
1921 unsigned int at, limit;
1923 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1925 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1926 SCTP_INP_RLOCK(inp);
1927 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1929 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1932 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1936 SCTP_INP_RUNLOCK(inp);
1938 ids->gaids_number_of_ids = at;
1939 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1945 struct sctp_assoc_value *av;
1947 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1948 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1951 av->assoc_value = stcb->asoc.context;
1952 SCTP_TCB_UNLOCK(stcb);
1954 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1955 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1956 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1957 SCTP_INP_RLOCK(inp);
1958 av->assoc_value = inp->sctp_context;
1959 SCTP_INP_RUNLOCK(inp);
1961 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1966 *optsize = sizeof(struct sctp_assoc_value);
1972 uint32_t *default_vrfid;
1974 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1975 *default_vrfid = inp->def_vrf_id;
1976 *optsize = sizeof(uint32_t);
1979 case SCTP_GET_ASOC_VRF:
1981 struct sctp_assoc_value *id;
1983 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1984 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1987 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1989 id->assoc_value = stcb->asoc.vrf_id;
1990 *optsize = sizeof(struct sctp_assoc_value);
1994 case SCTP_GET_VRF_IDS:
1996 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
2000 case SCTP_GET_NONCE_VALUES:
2002 struct sctp_get_nonce_values *gnv;
2004 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
2005 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
2008 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
2009 gnv->gn_local_tag = stcb->asoc.my_vtag;
2010 SCTP_TCB_UNLOCK(stcb);
2011 *optsize = sizeof(struct sctp_get_nonce_values);
2013 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2018 case SCTP_DELAYED_SACK:
2020 struct sctp_sack_info *sack;
2022 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2023 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2025 sack->sack_delay = stcb->asoc.delayed_ack;
2026 sack->sack_freq = stcb->asoc.sack_freq;
2027 SCTP_TCB_UNLOCK(stcb);
2029 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2030 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2031 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2032 SCTP_INP_RLOCK(inp);
2033 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2034 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2035 SCTP_INP_RUNLOCK(inp);
2037 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2042 *optsize = sizeof(struct sctp_sack_info);
2046 case SCTP_GET_SNDBUF_USE:
2048 struct sctp_sockstat *ss;
2050 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2051 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2054 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2055 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2056 stcb->asoc.size_on_all_streams);
2057 SCTP_TCB_UNLOCK(stcb);
2058 *optsize = sizeof(struct sctp_sockstat);
2060 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2065 case SCTP_MAX_BURST:
2069 SCTP_CHECK_AND_CAST(value, optval, uint8_t, *optsize);
2071 SCTP_INP_RLOCK(inp);
2072 if (inp->sctp_ep.max_burst < 256) {
2073 *value = inp->sctp_ep.max_burst;
2077 SCTP_INP_RUNLOCK(inp);
2078 *optsize = sizeof(uint8_t);
2083 struct sctp_assoc_value *av;
2086 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2087 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2090 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2091 SCTP_TCB_UNLOCK(stcb);
2093 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2094 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2095 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2096 SCTP_INP_RLOCK(inp);
2097 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2098 ovh = SCTP_MED_OVERHEAD;
2100 ovh = SCTP_MED_V4_OVERHEAD;
2102 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2103 av->assoc_value = 0;
2105 av->assoc_value = inp->sctp_frag_point - ovh;
2106 SCTP_INP_RUNLOCK(inp);
2108 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2113 *optsize = sizeof(struct sctp_assoc_value);
2117 case SCTP_GET_STAT_LOG:
2118 error = sctp_fill_stat_log(optval, optsize);
2122 struct sctp_event_subscribe *events;
2124 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2125 memset(events, 0, sizeof(struct sctp_event_subscribe));
2126 SCTP_INP_RLOCK(inp);
2127 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2128 events->sctp_data_io_event = 1;
2130 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2131 events->sctp_association_event = 1;
2133 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2134 events->sctp_address_event = 1;
2136 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2137 events->sctp_send_failure_event = 1;
2139 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2140 events->sctp_peer_error_event = 1;
2142 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2143 events->sctp_shutdown_event = 1;
2145 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2146 events->sctp_partial_delivery_event = 1;
2148 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2149 events->sctp_adaptation_layer_event = 1;
2151 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2152 events->sctp_authentication_event = 1;
2154 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2155 events->sctp_sender_dry_event = 1;
2157 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2158 events->sctp_stream_reset_event = 1;
2159 SCTP_INP_RUNLOCK(inp);
2160 *optsize = sizeof(struct sctp_event_subscribe);
2163 case SCTP_ADAPTATION_LAYER:
2167 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2169 SCTP_INP_RLOCK(inp);
2170 *value = inp->sctp_ep.adaptation_layer_indicator;
2171 SCTP_INP_RUNLOCK(inp);
2172 *optsize = sizeof(uint32_t);
2175 case SCTP_SET_INITIAL_DBG_SEQ:
2179 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2180 SCTP_INP_RLOCK(inp);
2181 *value = inp->sctp_ep.initial_sequence_debug;
2182 SCTP_INP_RUNLOCK(inp);
2183 *optsize = sizeof(uint32_t);
2186 case SCTP_GET_LOCAL_ADDR_SIZE:
2190 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2191 SCTP_INP_RLOCK(inp);
2192 *value = sctp_count_max_addresses(inp);
2193 SCTP_INP_RUNLOCK(inp);
2194 *optsize = sizeof(uint32_t);
2197 case SCTP_GET_REMOTE_ADDR_SIZE:
2201 struct sctp_nets *net;
2203 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2204 /* FIXME MT: change to sctp_assoc_value? */
2205 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2209 /* Count the sizes */
2210 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2211 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2212 size += sizeof(struct sockaddr_in6);
2214 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2217 size += sizeof(struct sockaddr_in);
2222 size += sizeof(struct sockaddr_in6);
2230 SCTP_TCB_UNLOCK(stcb);
2231 *value = (uint32_t) size;
2232 *optsize = sizeof(uint32_t);
2234 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2239 case SCTP_GET_PEER_ADDRESSES:
2241 * Get the address information, an array is passed in to
2242 * fill up we pack it.
2246 struct sockaddr_storage *sas;
2247 struct sctp_nets *net;
2248 struct sctp_getaddresses *saddr;
2250 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2251 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2254 left = (*optsize) - sizeof(struct sctp_getaddresses);
2255 *optsize = sizeof(struct sctp_getaddresses);
2256 sas = (struct sockaddr_storage *)&saddr->addr[0];
2258 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2259 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2260 cpsz = sizeof(struct sockaddr_in6);
2262 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2265 cpsz = sizeof(struct sockaddr_in);
2270 cpsz = sizeof(struct sockaddr_in6);
2282 /* not enough room. */
2285 #if defined(INET) && defined(INET6)
2286 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2287 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
2288 /* Must map the address */
2289 in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
2290 (struct sockaddr_in6 *)sas);
2293 memcpy(sas, &net->ro._l_addr, cpsz);
2294 #if defined(INET) && defined(INET6)
2297 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2299 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2303 SCTP_TCB_UNLOCK(stcb);
2305 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2310 case SCTP_GET_LOCAL_ADDRESSES:
2312 size_t limit, actual;
2313 struct sockaddr_storage *sas;
2314 struct sctp_getaddresses *saddr;
2316 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2317 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2319 sas = (struct sockaddr_storage *)&saddr->addr[0];
2320 limit = *optsize - sizeof(sctp_assoc_t);
2321 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2323 SCTP_TCB_UNLOCK(stcb);
2325 *optsize = sizeof(struct sockaddr_storage) + actual;
2328 case SCTP_PEER_ADDR_PARAMS:
2330 struct sctp_paddrparams *paddrp;
2331 struct sctp_nets *net;
2333 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2334 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2338 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2341 * We increment here since
2342 * sctp_findassociation_ep_addr() wil do a
2343 * decrement if it finds the stcb as long as
2344 * the locked tcb (last argument) is NOT a
2347 SCTP_INP_INCR_REF(inp);
2348 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddrp->spp_address, &net, NULL, NULL);
2350 SCTP_INP_DECR_REF(inp);
2353 if (stcb && (net == NULL)) {
2354 struct sockaddr *sa;
2356 sa = (struct sockaddr *)&paddrp->spp_address;
2358 if (sa->sa_family == AF_INET) {
2359 struct sockaddr_in *sin;
2361 sin = (struct sockaddr_in *)sa;
2362 if (sin->sin_addr.s_addr) {
2364 SCTP_TCB_UNLOCK(stcb);
2365 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2371 if (sa->sa_family == AF_INET6) {
2372 struct sockaddr_in6 *sin6;
2374 sin6 = (struct sockaddr_in6 *)sa;
2375 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2377 SCTP_TCB_UNLOCK(stcb);
2378 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2384 error = EAFNOSUPPORT;
2385 SCTP_TCB_UNLOCK(stcb);
2386 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2391 /* Applies to the specific association */
2392 paddrp->spp_flags = 0;
2396 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2397 ovh = SCTP_MED_OVERHEAD;
2399 ovh = SCTP_MED_V4_OVERHEAD;
2402 paddrp->spp_hbinterval = net->heart_beat_delay;
2403 paddrp->spp_pathmaxrxt = net->failure_threshold;
2404 paddrp->spp_pathmtu = net->mtu - ovh;
2405 /* get flags for HB */
2406 if (net->dest_state & SCTP_ADDR_NOHB) {
2407 paddrp->spp_flags |= SPP_HB_DISABLE;
2409 paddrp->spp_flags |= SPP_HB_ENABLE;
2411 /* get flags for PMTU */
2412 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2413 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2415 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2417 if (net->dscp & 0x01) {
2418 paddrp->spp_dscp = net->dscp & 0xfc;
2419 paddrp->spp_flags |= SPP_DSCP;
2422 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2423 (net->flowlabel & 0x80000000)) {
2424 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2425 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2430 * No destination so return default
2433 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2434 paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
2435 if (stcb->asoc.default_dscp & 0x01) {
2436 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2437 paddrp->spp_flags |= SPP_DSCP;
2440 if (stcb->asoc.default_flowlabel & 0x80000000) {
2441 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2442 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2445 /* default settings should be these */
2446 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2447 paddrp->spp_flags |= SPP_HB_DISABLE;
2449 paddrp->spp_flags |= SPP_HB_ENABLE;
2451 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2452 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2454 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2456 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2458 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2459 SCTP_TCB_UNLOCK(stcb);
2461 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2462 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2463 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2464 /* Use endpoint defaults */
2465 SCTP_INP_RLOCK(inp);
2466 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2467 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2468 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2469 /* get inp's default */
2470 if (inp->sctp_ep.default_dscp & 0x01) {
2471 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2472 paddrp->spp_flags |= SPP_DSCP;
2475 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2476 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2477 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2478 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2481 /* can't return this */
2482 paddrp->spp_pathmtu = 0;
2484 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2485 paddrp->spp_flags |= SPP_HB_ENABLE;
2487 paddrp->spp_flags |= SPP_HB_DISABLE;
2489 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2490 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2492 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2494 SCTP_INP_RUNLOCK(inp);
2496 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2501 *optsize = sizeof(struct sctp_paddrparams);
2505 case SCTP_GET_PEER_ADDR_INFO:
2507 struct sctp_paddrinfo *paddri;
2508 struct sctp_nets *net;
2510 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2511 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2515 net = sctp_findnet(stcb, (struct sockaddr *)&paddri->spinfo_address);
2518 * We increment here since
2519 * sctp_findassociation_ep_addr() wil do a
2520 * decrement if it finds the stcb as long as
2521 * the locked tcb (last argument) is NOT a
2524 SCTP_INP_INCR_REF(inp);
2525 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddri->spinfo_address, &net, NULL, NULL);
2527 SCTP_INP_DECR_REF(inp);
2531 if ((stcb) && (net)) {
2532 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2533 /* It's unconfirmed */
2534 paddri->spinfo_state = SCTP_UNCONFIRMED;
2535 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2537 paddri->spinfo_state = SCTP_ACTIVE;
2540 paddri->spinfo_state = SCTP_INACTIVE;
2542 paddri->spinfo_cwnd = net->cwnd;
2543 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2544 paddri->spinfo_rto = net->RTO;
2545 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2546 paddri->spinfo_mtu = net->mtu;
2547 SCTP_TCB_UNLOCK(stcb);
2548 *optsize = sizeof(struct sctp_paddrinfo);
2551 SCTP_TCB_UNLOCK(stcb);
2553 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2558 case SCTP_PCB_STATUS:
2560 struct sctp_pcbinfo *spcb;
2562 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2563 sctp_fill_pcbinfo(spcb);
2564 *optsize = sizeof(struct sctp_pcbinfo);
2569 struct sctp_nets *net;
2570 struct sctp_status *sstat;
2572 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2573 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2576 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2581 * I think passing the state is fine since
2582 * sctp_constants.h will be available to the user
2585 sstat->sstat_state = stcb->asoc.state;
2586 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2587 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2588 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2590 * We can't include chunks that have been passed to
2591 * the socket layer. Only things in queue.
2593 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2594 stcb->asoc.cnt_on_all_streams);
2597 sstat->sstat_instrms = stcb->asoc.streamincnt;
2598 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2599 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2600 memcpy(&sstat->sstat_primary.spinfo_address,
2601 &stcb->asoc.primary_destination->ro._l_addr,
2602 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2603 net = stcb->asoc.primary_destination;
2604 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2606 * Again the user can get info from sctp_constants.h
2607 * for what the state of the network is.
2609 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2610 /* It's unconfirmed */
2611 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2612 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2614 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2617 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2619 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2620 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2621 sstat->sstat_primary.spinfo_rto = net->RTO;
2622 sstat->sstat_primary.spinfo_mtu = net->mtu;
2623 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2624 SCTP_TCB_UNLOCK(stcb);
2625 *optsize = sizeof(struct sctp_status);
2630 struct sctp_rtoinfo *srto;
2632 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2633 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2636 srto->srto_initial = stcb->asoc.initial_rto;
2637 srto->srto_max = stcb->asoc.maxrto;
2638 srto->srto_min = stcb->asoc.minrto;
2639 SCTP_TCB_UNLOCK(stcb);
2641 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2642 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2643 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2644 SCTP_INP_RLOCK(inp);
2645 srto->srto_initial = inp->sctp_ep.initial_rto;
2646 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2647 srto->srto_min = inp->sctp_ep.sctp_minrto;
2648 SCTP_INP_RUNLOCK(inp);
2650 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2655 *optsize = sizeof(struct sctp_rtoinfo);
2661 struct sctp_timeouts *stimo;
2663 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2664 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2667 stimo->stimo_init = stcb->asoc.timoinit;
2668 stimo->stimo_data = stcb->asoc.timodata;
2669 stimo->stimo_sack = stcb->asoc.timosack;
2670 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2671 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2672 stimo->stimo_cookie = stcb->asoc.timocookie;
2673 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2674 SCTP_TCB_UNLOCK(stcb);
2675 *optsize = sizeof(struct sctp_timeouts);
2677 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2682 case SCTP_ASSOCINFO:
2684 struct sctp_assocparams *sasoc;
2686 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2687 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2690 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2691 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2692 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2693 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2694 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2695 SCTP_TCB_UNLOCK(stcb);
2697 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2698 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2699 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2700 SCTP_INP_RLOCK(inp);
2701 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2702 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2703 sasoc->sasoc_number_peer_destinations = 0;
2704 sasoc->sasoc_peer_rwnd = 0;
2705 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2706 SCTP_INP_RUNLOCK(inp);
2708 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2713 *optsize = sizeof(struct sctp_assocparams);
2717 case SCTP_DEFAULT_SEND_PARAM:
2719 struct sctp_sndrcvinfo *s_info;
2721 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2722 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2725 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2726 SCTP_TCB_UNLOCK(stcb);
2728 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2729 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2730 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2731 SCTP_INP_RLOCK(inp);
2732 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2733 SCTP_INP_RUNLOCK(inp);
2735 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2740 *optsize = sizeof(struct sctp_sndrcvinfo);
2746 struct sctp_initmsg *sinit;
2748 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2749 SCTP_INP_RLOCK(inp);
2750 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2751 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2752 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2753 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2754 SCTP_INP_RUNLOCK(inp);
2755 *optsize = sizeof(struct sctp_initmsg);
2758 case SCTP_PRIMARY_ADDR:
2759 /* we allow a "get" operation on this */
2761 struct sctp_setprim *ssp;
2763 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2764 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2767 /* simply copy out the sockaddr_storage... */
2771 if (len > stcb->asoc.primary_destination->ro._l_addr.sa.sa_len)
2772 len = stcb->asoc.primary_destination->ro._l_addr.sa.sa_len;
2774 memcpy(&ssp->ssp_addr,
2775 &stcb->asoc.primary_destination->ro._l_addr,
2777 SCTP_TCB_UNLOCK(stcb);
2778 *optsize = sizeof(struct sctp_setprim);
2780 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2785 case SCTP_HMAC_IDENT:
2787 struct sctp_hmacalgo *shmac;
2788 sctp_hmaclist_t *hmaclist;
2792 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2794 SCTP_INP_RLOCK(inp);
2795 hmaclist = inp->sctp_ep.local_hmacs;
2796 if (hmaclist == NULL) {
2797 /* no HMACs to return */
2798 *optsize = sizeof(*shmac);
2799 SCTP_INP_RUNLOCK(inp);
2802 /* is there room for all of the hmac ids? */
2803 size = sizeof(*shmac) + (hmaclist->num_algo *
2804 sizeof(shmac->shmac_idents[0]));
2805 if ((size_t)(*optsize) < size) {
2806 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2808 SCTP_INP_RUNLOCK(inp);
2811 /* copy in the list */
2812 shmac->shmac_number_of_idents = hmaclist->num_algo;
2813 for (i = 0; i < hmaclist->num_algo; i++) {
2814 shmac->shmac_idents[i] = hmaclist->hmac[i];
2816 SCTP_INP_RUNLOCK(inp);
2820 case SCTP_AUTH_ACTIVE_KEY:
2822 struct sctp_authkeyid *scact;
2824 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2825 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2828 /* get the active key on the assoc */
2829 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2830 SCTP_TCB_UNLOCK(stcb);
2832 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2833 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2834 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2835 /* get the endpoint active key */
2836 SCTP_INP_RLOCK(inp);
2837 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2838 SCTP_INP_RUNLOCK(inp);
2840 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2845 *optsize = sizeof(struct sctp_authkeyid);
2849 case SCTP_LOCAL_AUTH_CHUNKS:
2851 struct sctp_authchunks *sac;
2852 sctp_auth_chklist_t *chklist = NULL;
2855 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2856 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2859 /* get off the assoc */
2860 chklist = stcb->asoc.local_auth_chunks;
2861 /* is there enough space? */
2862 size = sctp_auth_get_chklist_size(chklist);
2863 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2865 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2867 /* copy in the chunks */
2868 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2869 sac->gauth_number_of_chunks = (uint32_t) size;
2870 *optsize = sizeof(struct sctp_authchunks) + size;
2872 SCTP_TCB_UNLOCK(stcb);
2874 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2875 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2876 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2877 /* get off the endpoint */
2878 SCTP_INP_RLOCK(inp);
2879 chklist = inp->sctp_ep.local_auth_chunks;
2880 /* is there enough space? */
2881 size = sctp_auth_get_chklist_size(chklist);
2882 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2884 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2886 /* copy in the chunks */
2887 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2888 sac->gauth_number_of_chunks = (uint32_t) size;
2889 *optsize = sizeof(struct sctp_authchunks) + size;
2891 SCTP_INP_RUNLOCK(inp);
2893 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2899 case SCTP_PEER_AUTH_CHUNKS:
2901 struct sctp_authchunks *sac;
2902 sctp_auth_chklist_t *chklist = NULL;
2905 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2906 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2909 /* get off the assoc */
2910 chklist = stcb->asoc.peer_auth_chunks;
2911 /* is there enough space? */
2912 size = sctp_auth_get_chklist_size(chklist);
2913 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2915 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2917 /* copy in the chunks */
2918 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2919 sac->gauth_number_of_chunks = (uint32_t) size;
2920 *optsize = sizeof(struct sctp_authchunks) + size;
2922 SCTP_TCB_UNLOCK(stcb);
2924 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2931 struct sctp_event *event;
2932 uint32_t event_type;
2934 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2935 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
2937 switch (event->se_type) {
2938 case SCTP_ASSOC_CHANGE:
2939 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
2941 case SCTP_PEER_ADDR_CHANGE:
2942 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
2944 case SCTP_REMOTE_ERROR:
2945 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
2947 case SCTP_SEND_FAILED:
2948 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
2950 case SCTP_SHUTDOWN_EVENT:
2951 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
2953 case SCTP_ADAPTATION_INDICATION:
2954 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
2956 case SCTP_PARTIAL_DELIVERY_EVENT:
2957 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
2959 case SCTP_AUTHENTICATION_EVENT:
2960 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
2962 case SCTP_STREAM_RESET_EVENT:
2963 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
2965 case SCTP_SENDER_DRY_EVENT:
2966 event_type = SCTP_PCB_FLAGS_DRYEVNT;
2968 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
2970 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
2973 case SCTP_ASSOC_RESET_EVENT:
2974 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
2976 case SCTP_STREAM_CHANGE_EVENT:
2977 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
2979 case SCTP_SEND_FAILED_EVENT:
2980 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
2984 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2988 if (event_type > 0) {
2990 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
2991 SCTP_TCB_UNLOCK(stcb);
2993 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2994 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2995 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
2996 SCTP_INP_RLOCK(inp);
2997 event->se_on = sctp_is_feature_on(inp, event_type);
2998 SCTP_INP_RUNLOCK(inp);
3000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3006 *optsize = sizeof(struct sctp_event);
3010 case SCTP_RECVRCVINFO:
3014 if (*optsize < sizeof(int)) {
3015 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3018 SCTP_INP_RLOCK(inp);
3019 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3020 SCTP_INP_RUNLOCK(inp);
3023 /* return the option value */
3024 *(int *)optval = onoff;
3025 *optsize = sizeof(int);
3029 case SCTP_RECVNXTINFO:
3033 if (*optsize < sizeof(int)) {
3034 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3037 SCTP_INP_RLOCK(inp);
3038 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3039 SCTP_INP_RUNLOCK(inp);
3042 /* return the option value */
3043 *(int *)optval = onoff;
3044 *optsize = sizeof(int);
3048 case SCTP_DEFAULT_SNDINFO:
3050 struct sctp_sndinfo *info;
3052 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3053 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3056 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3057 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3058 info->snd_flags &= 0xfff0;
3059 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3060 info->snd_context = stcb->asoc.def_send.sinfo_context;
3061 SCTP_TCB_UNLOCK(stcb);
3063 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3064 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3065 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3066 SCTP_INP_RLOCK(inp);
3067 info->snd_sid = inp->def_send.sinfo_stream;
3068 info->snd_flags = inp->def_send.sinfo_flags;
3069 info->snd_flags &= 0xfff0;
3070 info->snd_ppid = inp->def_send.sinfo_ppid;
3071 info->snd_context = inp->def_send.sinfo_context;
3072 SCTP_INP_RUNLOCK(inp);
3074 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3079 *optsize = sizeof(struct sctp_sndinfo);
3083 case SCTP_DEFAULT_PRINFO:
3085 struct sctp_default_prinfo *info;
3087 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3088 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3091 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3092 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3093 SCTP_TCB_UNLOCK(stcb);
3095 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3096 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3097 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3098 SCTP_INP_RLOCK(inp);
3099 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3100 info->pr_value = inp->def_send.sinfo_timetolive;
3101 SCTP_INP_RUNLOCK(inp);
3103 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3108 *optsize = sizeof(struct sctp_default_prinfo);
3112 case SCTP_PEER_ADDR_THLDS:
3114 struct sctp_paddrthlds *thlds;
3115 struct sctp_nets *net;
3117 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3118 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3122 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_address);
3125 * We increment here since
3126 * sctp_findassociation_ep_addr() wil do a
3127 * decrement if it finds the stcb as long as
3128 * the locked tcb (last argument) is NOT a
3131 SCTP_INP_INCR_REF(inp);
3132 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&thlds->spt_address, &net, NULL, NULL);
3134 SCTP_INP_DECR_REF(inp);
3137 if (stcb && (net == NULL)) {
3138 struct sockaddr *sa;
3140 sa = (struct sockaddr *)&thlds->spt_address;
3142 if (sa->sa_family == AF_INET) {
3143 struct sockaddr_in *sin;
3145 sin = (struct sockaddr_in *)sa;
3146 if (sin->sin_addr.s_addr) {
3148 SCTP_TCB_UNLOCK(stcb);
3149 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3155 if (sa->sa_family == AF_INET6) {
3156 struct sockaddr_in6 *sin6;
3158 sin6 = (struct sockaddr_in6 *)sa;
3159 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3161 SCTP_TCB_UNLOCK(stcb);
3162 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3168 error = EAFNOSUPPORT;
3169 SCTP_TCB_UNLOCK(stcb);
3170 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3176 thlds->spt_pathmaxrxt = net->failure_threshold;
3177 thlds->spt_pathpfthld = net->pf_threshold;
3179 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3180 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3182 thlds->spt_assoc_id = sctp_get_associd(stcb);
3183 SCTP_TCB_UNLOCK(stcb);
3185 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3186 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3187 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3188 /* Use endpoint defaults */
3189 SCTP_INP_RLOCK(inp);
3190 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3191 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3192 SCTP_INP_RUNLOCK(inp);
3194 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3199 *optsize = sizeof(struct sctp_paddrthlds);
3203 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3205 struct sctp_udpencaps *encaps;
3206 struct sctp_nets *net;
3208 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3209 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3212 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
3215 * We increment here since
3216 * sctp_findassociation_ep_addr() wil do a
3217 * decrement if it finds the stcb as long as
3218 * the locked tcb (last argument) is NOT a
3222 SCTP_INP_INCR_REF(inp);
3223 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
3225 SCTP_INP_DECR_REF(inp);
3228 if (stcb && (net == NULL)) {
3229 struct sockaddr *sa;
3231 sa = (struct sockaddr *)&encaps->sue_address;
3233 if (sa->sa_family == AF_INET) {
3234 struct sockaddr_in *sin;
3236 sin = (struct sockaddr_in *)sa;
3237 if (sin->sin_addr.s_addr) {
3239 SCTP_TCB_UNLOCK(stcb);
3240 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3246 if (sa->sa_family == AF_INET6) {
3247 struct sockaddr_in6 *sin6;
3249 sin6 = (struct sockaddr_in6 *)sa;
3250 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3252 SCTP_TCB_UNLOCK(stcb);
3253 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3259 error = EAFNOSUPPORT;
3260 SCTP_TCB_UNLOCK(stcb);
3261 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3267 encaps->sue_port = net->port;
3269 encaps->sue_port = stcb->asoc.port;
3271 SCTP_TCB_UNLOCK(stcb);
3273 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3274 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3275 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3276 SCTP_INP_RLOCK(inp);
3277 encaps->sue_port = inp->sctp_ep.port;
3278 SCTP_INP_RUNLOCK(inp);
3280 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3285 *optsize = sizeof(struct sctp_paddrparams);
3289 case SCTP_ENABLE_STREAM_RESET:
3291 struct sctp_assoc_value *av;
3293 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3294 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3297 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3298 SCTP_TCB_UNLOCK(stcb);
3300 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3301 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3302 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3303 SCTP_INP_RLOCK(inp);
3304 av->assoc_value = (uint32_t) inp->local_strreset_support;
3305 SCTP_INP_RUNLOCK(inp);
3307 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3312 *optsize = sizeof(struct sctp_assoc_value);
3317 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3318 error = ENOPROTOOPT;
3320 } /* end switch (sopt->sopt_name) */
3328 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3333 struct sctp_tcb *stcb = NULL;
3334 struct sctp_inpcb *inp = NULL;
3337 if (optval == NULL) {
3338 SCTP_PRINTF("optval is NULL\n");
3339 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3342 inp = (struct sctp_inpcb *)so->so_pcb;
3344 SCTP_PRINTF("inp is NULL?\n");
3345 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3348 vrf_id = inp->def_vrf_id;
3353 case SCTP_AUTOCLOSE:
3354 case SCTP_AUTO_ASCONF:
3355 case SCTP_EXPLICIT_EOR:
3356 case SCTP_DISABLE_FRAGMENTS:
3357 case SCTP_USE_EXT_RCVINFO:
3358 case SCTP_I_WANT_MAPPED_V4_ADDR:
3359 /* copy in the option value */
3360 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3365 case SCTP_DISABLE_FRAGMENTS:
3366 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3368 case SCTP_AUTO_ASCONF:
3370 * NOTE: we don't really support this flag
3372 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3373 /* only valid for bound all sockets */
3374 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3376 /* forbidden by admin */
3377 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3380 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3382 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3386 case SCTP_EXPLICIT_EOR:
3387 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3389 case SCTP_USE_EXT_RCVINFO:
3390 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3392 case SCTP_I_WANT_MAPPED_V4_ADDR:
3393 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3394 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3396 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3401 set_opt = SCTP_PCB_FLAGS_NODELAY;
3403 case SCTP_AUTOCLOSE:
3404 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3405 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3406 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3409 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3411 * The value is in ticks. Note this does not effect
3412 * old associations, only new ones.
3414 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3417 SCTP_INP_WLOCK(inp);
3419 sctp_feature_on(inp, set_opt);
3421 sctp_feature_off(inp, set_opt);
3423 SCTP_INP_WUNLOCK(inp);
3425 case SCTP_REUSE_PORT:
3427 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3428 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3429 /* Can't set it after we are bound */
3433 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3434 /* Can't do this for a 1-m socket */
3439 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3441 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3444 case SCTP_PARTIAL_DELIVERY_POINT:
3448 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3449 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3450 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3454 inp->partial_delivery_point = *value;
3457 case SCTP_FRAGMENT_INTERLEAVE:
3458 /* not yet until we re-write sctp_recvmsg() */
3462 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3463 if (*level == SCTP_FRAG_LEVEL_2) {
3464 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3465 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3466 } else if (*level == SCTP_FRAG_LEVEL_1) {
3467 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3468 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3469 } else if (*level == SCTP_FRAG_LEVEL_0) {
3470 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3471 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3474 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3479 case SCTP_CMT_ON_OFF:
3480 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3481 struct sctp_assoc_value *av;
3483 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3484 if (av->assoc_value > SCTP_CMT_MAX) {
3485 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3489 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3491 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3492 SCTP_TCB_UNLOCK(stcb);
3494 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3495 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3496 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3497 (av->assoc_id == SCTP_ALL_ASSOC)) {
3498 SCTP_INP_WLOCK(inp);
3499 inp->sctp_cmt_on_off = av->assoc_value;
3500 SCTP_INP_WUNLOCK(inp);
3502 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3503 (av->assoc_id == SCTP_ALL_ASSOC)) {
3504 SCTP_INP_RLOCK(inp);
3505 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3506 SCTP_TCB_LOCK(stcb);
3507 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3508 SCTP_TCB_UNLOCK(stcb);
3510 SCTP_INP_RUNLOCK(inp);
3514 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3515 error = ENOPROTOOPT;
3518 case SCTP_PLUGGABLE_CC:
3520 struct sctp_assoc_value *av;
3521 struct sctp_nets *net;
3523 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3524 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3525 (av->assoc_value != SCTP_CC_HSTCP) &&
3526 (av->assoc_value != SCTP_CC_HTCP) &&
3527 (av->assoc_value != SCTP_CC_RTCC)) {
3528 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3532 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3534 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3535 stcb->asoc.congestion_control_module = av->assoc_value;
3536 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3537 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3538 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3541 SCTP_TCB_UNLOCK(stcb);
3543 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3544 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3545 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3546 (av->assoc_id == SCTP_ALL_ASSOC)) {
3547 SCTP_INP_WLOCK(inp);
3548 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3549 SCTP_INP_WUNLOCK(inp);
3551 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3552 (av->assoc_id == SCTP_ALL_ASSOC)) {
3553 SCTP_INP_RLOCK(inp);
3554 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3555 SCTP_TCB_LOCK(stcb);
3556 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3557 stcb->asoc.congestion_control_module = av->assoc_value;
3558 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3559 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3560 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3563 SCTP_TCB_UNLOCK(stcb);
3565 SCTP_INP_RUNLOCK(inp);
3570 case SCTP_CC_OPTION:
3572 struct sctp_cc_option *cc_opt;
3574 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
3575 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
3577 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
3578 SCTP_INP_RLOCK(inp);
3579 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3580 SCTP_TCB_LOCK(stcb);
3581 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
3582 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
3584 SCTP_TCB_UNLOCK(stcb);
3586 SCTP_INP_RUNLOCK(inp);
3591 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
3594 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
3597 SCTP_TCB_UNLOCK(stcb);
3601 case SCTP_PLUGGABLE_SS:
3603 struct sctp_assoc_value *av;
3605 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3606 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
3607 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
3608 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
3609 (av->assoc_value != SCTP_SS_PRIORITY) &&
3610 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
3611 (av->assoc_value != SCTP_SS_FIRST_COME)) {
3612 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3616 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3618 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3619 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3620 stcb->asoc.stream_scheduling_module = av->assoc_value;
3621 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3622 SCTP_TCB_UNLOCK(stcb);
3624 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3625 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3626 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3627 (av->assoc_id == SCTP_ALL_ASSOC)) {
3628 SCTP_INP_WLOCK(inp);
3629 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
3630 SCTP_INP_WUNLOCK(inp);
3632 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3633 (av->assoc_id == SCTP_ALL_ASSOC)) {
3634 SCTP_INP_RLOCK(inp);
3635 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3636 SCTP_TCB_LOCK(stcb);
3637 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3638 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3639 stcb->asoc.stream_scheduling_module = av->assoc_value;
3640 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3641 SCTP_TCB_UNLOCK(stcb);
3643 SCTP_INP_RUNLOCK(inp);
3650 struct sctp_stream_value *av;
3652 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
3653 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3655 if (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
3656 av->stream_value) < 0) {
3657 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3660 SCTP_TCB_UNLOCK(stcb);
3662 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
3663 SCTP_INP_RLOCK(inp);
3664 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3665 SCTP_TCB_LOCK(stcb);
3666 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
3668 &stcb->asoc.strmout[av->stream_id],
3670 SCTP_TCB_UNLOCK(stcb);
3672 SCTP_INP_RUNLOCK(inp);
3676 * Can't set stream value without
3679 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3685 case SCTP_CLR_STAT_LOG:
3686 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3691 struct sctp_assoc_value *av;
3693 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3694 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3697 stcb->asoc.context = av->assoc_value;
3698 SCTP_TCB_UNLOCK(stcb);
3700 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3701 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3702 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3703 (av->assoc_id == SCTP_ALL_ASSOC)) {
3704 SCTP_INP_WLOCK(inp);
3705 inp->sctp_context = av->assoc_value;
3706 SCTP_INP_WUNLOCK(inp);
3708 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3709 (av->assoc_id == SCTP_ALL_ASSOC)) {
3710 SCTP_INP_RLOCK(inp);
3711 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3712 SCTP_TCB_LOCK(stcb);
3713 stcb->asoc.context = av->assoc_value;
3714 SCTP_TCB_UNLOCK(stcb);
3716 SCTP_INP_RUNLOCK(inp);
3723 uint32_t *default_vrfid;
3725 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
3726 if (*default_vrfid > SCTP_MAX_VRF_ID) {
3727 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3731 inp->def_vrf_id = *default_vrfid;
3734 case SCTP_DEL_VRF_ID:
3736 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3740 case SCTP_ADD_VRF_ID:
3742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3746 case SCTP_DELAYED_SACK:
3748 struct sctp_sack_info *sack;
3750 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
3751 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
3752 if (sack->sack_delay) {
3753 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
3754 sack->sack_delay = SCTP_MAX_SACK_DELAY;
3755 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
3756 sack->sack_delay = TICKS_TO_MSEC(1);
3760 if (sack->sack_delay) {
3761 stcb->asoc.delayed_ack = sack->sack_delay;
3763 if (sack->sack_freq) {
3764 stcb->asoc.sack_freq = sack->sack_freq;
3766 SCTP_TCB_UNLOCK(stcb);
3768 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3769 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3770 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
3771 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3772 SCTP_INP_WLOCK(inp);
3773 if (sack->sack_delay) {
3774 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
3776 if (sack->sack_freq) {
3777 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
3779 SCTP_INP_WUNLOCK(inp);
3781 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
3782 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3783 SCTP_INP_RLOCK(inp);
3784 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3785 SCTP_TCB_LOCK(stcb);
3786 if (sack->sack_delay) {
3787 stcb->asoc.delayed_ack = sack->sack_delay;
3789 if (sack->sack_freq) {
3790 stcb->asoc.sack_freq = sack->sack_freq;
3792 SCTP_TCB_UNLOCK(stcb);
3794 SCTP_INP_RUNLOCK(inp);
3799 case SCTP_AUTH_CHUNK:
3801 struct sctp_authchunk *sauth;
3803 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
3805 SCTP_INP_WLOCK(inp);
3806 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
3807 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3810 SCTP_INP_WUNLOCK(inp);
3815 struct sctp_authkey *sca;
3816 struct sctp_keyhead *shared_keys;
3817 sctp_sharedkey_t *shared_key;
3818 sctp_key_t *key = NULL;
3821 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
3822 if (sca->sca_keylength == 0) {
3823 size = optsize - sizeof(struct sctp_authkey);
3825 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
3826 size = sca->sca_keylength;
3828 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3833 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
3836 shared_keys = &stcb->asoc.shared_keys;
3837 /* clear the cached keys for this key id */
3838 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3840 * create the new shared key and
3844 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3846 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3848 SCTP_TCB_UNLOCK(stcb);
3852 shared_key = sctp_alloc_sharedkey();
3853 if (shared_key == NULL) {
3855 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3857 SCTP_TCB_UNLOCK(stcb);
3860 shared_key->key = key;
3861 shared_key->keyid = sca->sca_keynumber;
3862 error = sctp_insert_sharedkey(shared_keys, shared_key);
3863 SCTP_TCB_UNLOCK(stcb);
3865 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3866 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3867 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
3868 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3869 SCTP_INP_WLOCK(inp);
3870 shared_keys = &inp->sctp_ep.shared_keys;
3872 * clear the cached keys on all
3873 * assocs for this key id
3875 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
3877 * create the new shared key and
3881 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3883 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3885 SCTP_INP_WUNLOCK(inp);
3889 shared_key = sctp_alloc_sharedkey();
3890 if (shared_key == NULL) {
3892 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3894 SCTP_INP_WUNLOCK(inp);
3897 shared_key->key = key;
3898 shared_key->keyid = sca->sca_keynumber;
3899 error = sctp_insert_sharedkey(shared_keys, shared_key);
3900 SCTP_INP_WUNLOCK(inp);
3902 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
3903 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3904 SCTP_INP_RLOCK(inp);
3905 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3906 SCTP_TCB_LOCK(stcb);
3907 shared_keys = &stcb->asoc.shared_keys;
3909 * clear the cached keys for
3912 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3914 * create the new shared key
3915 * and insert/replace it
3918 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3920 SCTP_TCB_UNLOCK(stcb);
3924 shared_key = sctp_alloc_sharedkey();
3925 if (shared_key == NULL) {
3927 SCTP_TCB_UNLOCK(stcb);
3930 shared_key->key = key;
3931 shared_key->keyid = sca->sca_keynumber;
3932 error = sctp_insert_sharedkey(shared_keys, shared_key);
3933 SCTP_TCB_UNLOCK(stcb);
3935 SCTP_INP_RUNLOCK(inp);
3940 case SCTP_HMAC_IDENT:
3942 struct sctp_hmacalgo *shmac;
3943 sctp_hmaclist_t *hmaclist;
3948 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
3949 if (optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) {
3950 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3954 hmaclist = sctp_alloc_hmaclist(shmac->shmac_number_of_idents);
3955 if (hmaclist == NULL) {
3956 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3960 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
3961 hmacid = shmac->shmac_idents[i];
3962 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
3963 /* invalid HMACs were found */ ;
3964 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3966 sctp_free_hmaclist(hmaclist);
3967 goto sctp_set_hmac_done;
3971 for (i = 0; i < hmaclist->num_algo; i++) {
3972 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
3973 /* already in list */
3978 sctp_free_hmaclist(hmaclist);
3979 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3983 /* set it on the endpoint */
3984 SCTP_INP_WLOCK(inp);
3985 if (inp->sctp_ep.local_hmacs)
3986 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
3987 inp->sctp_ep.local_hmacs = hmaclist;
3988 SCTP_INP_WUNLOCK(inp);
3992 case SCTP_AUTH_ACTIVE_KEY:
3994 struct sctp_authkeyid *scact;
3996 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
3997 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
3999 /* set the active key on the right place */
4001 /* set the active key on the assoc */
4002 if (sctp_auth_setactivekey(stcb,
4003 scact->scact_keynumber)) {
4004 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4005 SCTP_FROM_SCTP_USRREQ,
4009 SCTP_TCB_UNLOCK(stcb);
4011 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4012 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4013 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4014 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4015 SCTP_INP_WLOCK(inp);
4016 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4017 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4020 SCTP_INP_WUNLOCK(inp);
4022 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4023 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4024 SCTP_INP_RLOCK(inp);
4025 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4026 SCTP_TCB_LOCK(stcb);
4027 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4028 SCTP_TCB_UNLOCK(stcb);
4030 SCTP_INP_RUNLOCK(inp);
4035 case SCTP_AUTH_DELETE_KEY:
4037 struct sctp_authkeyid *scdel;
4039 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4040 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4042 /* delete the key from the right place */
4044 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4045 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4048 SCTP_TCB_UNLOCK(stcb);
4050 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4051 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4052 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4053 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4054 SCTP_INP_WLOCK(inp);
4055 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4056 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4059 SCTP_INP_WUNLOCK(inp);
4061 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4062 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4063 SCTP_INP_RLOCK(inp);
4064 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4065 SCTP_TCB_LOCK(stcb);
4066 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4067 SCTP_TCB_UNLOCK(stcb);
4069 SCTP_INP_RUNLOCK(inp);
4074 case SCTP_AUTH_DEACTIVATE_KEY:
4076 struct sctp_authkeyid *keyid;
4078 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4079 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4081 /* deactivate the key from the right place */
4083 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4084 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4087 SCTP_TCB_UNLOCK(stcb);
4089 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4090 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4091 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4092 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4093 SCTP_INP_WLOCK(inp);
4094 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4095 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4098 SCTP_INP_WUNLOCK(inp);
4100 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4101 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4102 SCTP_INP_RLOCK(inp);
4103 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4104 SCTP_TCB_LOCK(stcb);
4105 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4106 SCTP_TCB_UNLOCK(stcb);
4108 SCTP_INP_RUNLOCK(inp);
4113 case SCTP_ENABLE_STREAM_RESET:
4115 struct sctp_assoc_value *av;
4117 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4118 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4119 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4123 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4125 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4126 SCTP_TCB_UNLOCK(stcb);
4128 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4129 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4130 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4131 (av->assoc_id == SCTP_ALL_ASSOC)) {
4132 SCTP_INP_WLOCK(inp);
4133 inp->local_strreset_support = (uint8_t) av->assoc_value;
4134 SCTP_INP_WUNLOCK(inp);
4136 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4137 (av->assoc_id == SCTP_ALL_ASSOC)) {
4138 SCTP_INP_RLOCK(inp);
4139 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4140 SCTP_TCB_LOCK(stcb);
4141 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4142 SCTP_TCB_UNLOCK(stcb);
4144 SCTP_INP_RUNLOCK(inp);
4149 case SCTP_RESET_STREAMS:
4151 struct sctp_reset_streams *strrst;
4152 int i, send_out = 0;
4155 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4156 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4158 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4162 if (stcb->asoc.peer_supports_strreset == 0) {
4164 * Peer does not support the chunk type.
4166 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4168 SCTP_TCB_UNLOCK(stcb);
4171 if (stcb->asoc.stream_reset_outstanding) {
4172 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4174 SCTP_TCB_UNLOCK(stcb);
4177 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4180 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4183 if ((send_in == 0) && (send_out == 0)) {
4184 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4186 SCTP_TCB_UNLOCK(stcb);
4189 for (i = 0; i < strrst->srs_number_streams; i++) {
4191 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4192 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4197 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4198 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4204 SCTP_TCB_UNLOCK(stcb);
4207 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4208 strrst->srs_stream_list,
4209 send_out, send_in, 0, 0, 0, 0, 0);
4211 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4212 SCTP_TCB_UNLOCK(stcb);
4215 case SCTP_ADD_STREAMS:
4217 struct sctp_add_streams *stradd;
4218 uint8_t addstream = 0;
4219 uint16_t add_o_strmcnt = 0;
4220 uint16_t add_i_strmcnt = 0;
4222 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4223 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4225 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4229 if (stcb->asoc.peer_supports_strreset == 0) {
4231 * Peer does not support the chunk type.
4233 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4235 SCTP_TCB_UNLOCK(stcb);
4238 if (stcb->asoc.stream_reset_outstanding) {
4239 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4241 SCTP_TCB_UNLOCK(stcb);
4244 if ((stradd->sas_outstrms == 0) &&
4245 (stradd->sas_instrms == 0)) {
4249 if (stradd->sas_outstrms) {
4251 /* We allocate here */
4252 add_o_strmcnt = stradd->sas_outstrms;
4253 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4254 /* You can't have more than 64k */
4259 if (stradd->sas_instrms) {
4264 * We allocate inside
4265 * sctp_send_str_reset_req()
4267 add_i_strmcnt = stradd->sas_instrms;
4268 cnt = add_i_strmcnt;
4269 cnt += stcb->asoc.streamincnt;
4270 if (cnt > 0x0000ffff) {
4271 /* You can't have more than 64k */
4275 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4276 /* More than you are allowed */
4281 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4282 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4284 SCTP_TCB_UNLOCK(stcb);
4287 case SCTP_RESET_ASSOC:
4291 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4292 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4294 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4298 if (stcb->asoc.peer_supports_strreset == 0) {
4300 * Peer does not support the chunk type.
4302 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4304 SCTP_TCB_UNLOCK(stcb);
4307 if (stcb->asoc.stream_reset_outstanding) {
4308 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4310 SCTP_TCB_UNLOCK(stcb);
4313 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 1, 0, 0, 0, 0);
4314 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4315 SCTP_TCB_UNLOCK(stcb);
4318 case SCTP_CONNECT_X:
4319 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4320 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4324 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4326 case SCTP_CONNECT_X_DELAYED:
4327 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4328 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4332 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4334 case SCTP_CONNECT_X_COMPLETE:
4336 struct sockaddr *sa;
4337 struct sctp_nets *net;
4339 /* FIXME MT: check correct? */
4340 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4343 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4344 SCTP_INP_RLOCK(inp);
4345 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4347 SCTP_TCB_LOCK(stcb);
4348 net = sctp_findnet(stcb, sa);
4350 SCTP_INP_RUNLOCK(inp);
4353 * We increment here since
4354 * sctp_findassociation_ep_addr() wil do a
4355 * decrement if it finds the stcb as long as
4356 * the locked tcb (last argument) is NOT a
4359 SCTP_INP_INCR_REF(inp);
4360 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
4362 SCTP_INP_DECR_REF(inp);
4367 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4371 if (stcb->asoc.delayed_connection == 1) {
4372 stcb->asoc.delayed_connection = 0;
4373 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4374 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4375 stcb->asoc.primary_destination,
4376 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
4377 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4380 * already expired or did not use delayed
4383 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4386 SCTP_TCB_UNLOCK(stcb);
4389 case SCTP_MAX_BURST:
4393 SCTP_CHECK_AND_CAST(burst, optval, uint8_t, optsize);
4395 SCTP_INP_WLOCK(inp);
4396 inp->sctp_ep.max_burst = *burst;
4397 SCTP_INP_WUNLOCK(inp);
4402 struct sctp_assoc_value *av;
4405 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4406 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4408 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4409 ovh = SCTP_MED_OVERHEAD;
4411 ovh = SCTP_MED_V4_OVERHEAD;
4414 if (av->assoc_value) {
4415 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4417 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4419 SCTP_TCB_UNLOCK(stcb);
4421 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4422 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4423 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4424 SCTP_INP_WLOCK(inp);
4426 * FIXME MT: I think this is not in
4427 * tune with the API ID
4429 if (av->assoc_value) {
4430 inp->sctp_frag_point = (av->assoc_value + ovh);
4432 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4434 SCTP_INP_WUNLOCK(inp);
4436 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4444 struct sctp_event_subscribe *events;
4446 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4448 SCTP_INP_WLOCK(inp);
4449 if (events->sctp_data_io_event) {
4450 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4452 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4455 if (events->sctp_association_event) {
4456 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4458 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4461 if (events->sctp_address_event) {
4462 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4464 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4467 if (events->sctp_send_failure_event) {
4468 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4470 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4473 if (events->sctp_peer_error_event) {
4474 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4476 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4479 if (events->sctp_shutdown_event) {
4480 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4482 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4485 if (events->sctp_partial_delivery_event) {
4486 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4488 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4491 if (events->sctp_adaptation_layer_event) {
4492 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4494 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4497 if (events->sctp_authentication_event) {
4498 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4500 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4503 if (events->sctp_sender_dry_event) {
4504 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
4506 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
4509 if (events->sctp_stream_reset_event) {
4510 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4512 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4514 SCTP_INP_WUNLOCK(inp);
4516 SCTP_INP_RLOCK(inp);
4517 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4518 SCTP_TCB_LOCK(stcb);
4519 if (events->sctp_association_event) {
4520 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4522 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4524 if (events->sctp_address_event) {
4525 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4527 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4529 if (events->sctp_send_failure_event) {
4530 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4532 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4534 if (events->sctp_peer_error_event) {
4535 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4537 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4539 if (events->sctp_shutdown_event) {
4540 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4542 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4544 if (events->sctp_partial_delivery_event) {
4545 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4547 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4549 if (events->sctp_adaptation_layer_event) {
4550 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4552 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4554 if (events->sctp_authentication_event) {
4555 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4557 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4559 if (events->sctp_sender_dry_event) {
4560 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4562 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4564 if (events->sctp_stream_reset_event) {
4565 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4567 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4569 SCTP_TCB_UNLOCK(stcb);
4572 * Send up the sender dry event only for 1-to-1
4575 if (events->sctp_sender_dry_event) {
4576 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4577 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
4578 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4580 SCTP_TCB_LOCK(stcb);
4581 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
4582 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
4583 (stcb->asoc.stream_queue_cnt == 0)) {
4584 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
4586 SCTP_TCB_UNLOCK(stcb);
4590 SCTP_INP_RUNLOCK(inp);
4593 case SCTP_ADAPTATION_LAYER:
4595 struct sctp_setadaptation *adap_bits;
4597 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
4598 SCTP_INP_WLOCK(inp);
4599 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
4600 SCTP_INP_WUNLOCK(inp);
4604 case SCTP_SET_INITIAL_DBG_SEQ:
4608 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
4609 SCTP_INP_WLOCK(inp);
4610 inp->sctp_ep.initial_sequence_debug = *vvv;
4611 SCTP_INP_WUNLOCK(inp);
4615 case SCTP_DEFAULT_SEND_PARAM:
4617 struct sctp_sndrcvinfo *s_info;
4619 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
4620 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
4623 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4624 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4626 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4629 SCTP_TCB_UNLOCK(stcb);
4631 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4632 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4633 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
4634 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4635 SCTP_INP_WLOCK(inp);
4636 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
4637 SCTP_INP_WUNLOCK(inp);
4639 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
4640 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4641 SCTP_INP_RLOCK(inp);
4642 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4643 SCTP_TCB_LOCK(stcb);
4644 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4645 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4647 SCTP_TCB_UNLOCK(stcb);
4649 SCTP_INP_RUNLOCK(inp);
4654 case SCTP_PEER_ADDR_PARAMS:
4656 struct sctp_paddrparams *paddrp;
4657 struct sctp_nets *net;
4659 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
4660 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
4663 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
4666 * We increment here since
4667 * sctp_findassociation_ep_addr() wil do a
4668 * decrement if it finds the stcb as long as
4669 * the locked tcb (last argument) is NOT a
4672 SCTP_INP_INCR_REF(inp);
4673 stcb = sctp_findassociation_ep_addr(&inp,
4674 (struct sockaddr *)&paddrp->spp_address,
4677 SCTP_INP_DECR_REF(inp);
4680 if (stcb && (net == NULL)) {
4681 struct sockaddr *sa;
4683 sa = (struct sockaddr *)&paddrp->spp_address;
4685 if (sa->sa_family == AF_INET) {
4687 struct sockaddr_in *sin;
4689 sin = (struct sockaddr_in *)sa;
4690 if (sin->sin_addr.s_addr) {
4691 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4692 SCTP_TCB_UNLOCK(stcb);
4699 if (sa->sa_family == AF_INET6) {
4700 struct sockaddr_in6 *sin6;
4702 sin6 = (struct sockaddr_in6 *)sa;
4703 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
4704 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4705 SCTP_TCB_UNLOCK(stcb);
4712 error = EAFNOSUPPORT;
4713 SCTP_TCB_UNLOCK(stcb);
4714 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4719 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
4721 SCTP_TCB_UNLOCK(stcb);
4722 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4725 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
4727 SCTP_TCB_UNLOCK(stcb);
4728 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4732 /************************TCB SPECIFIC SET ******************/
4734 * do we change the timer for HB, we run
4739 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4740 ovh = SCTP_MED_OVERHEAD;
4742 ovh = SCTP_MED_V4_OVERHEAD;
4745 /* network sets ? */
4747 /************************NET SPECIFIC SET ******************/
4748 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4749 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
4750 !(net->dest_state & SCTP_ADDR_NOHB)) {
4751 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4752 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4754 net->dest_state |= SCTP_ADDR_NOHB;
4756 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4757 if (paddrp->spp_hbinterval) {
4758 net->heart_beat_delay = paddrp->spp_hbinterval;
4759 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4760 net->heart_beat_delay = 0;
4762 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4763 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4764 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4765 net->dest_state &= ~SCTP_ADDR_NOHB;
4767 if (paddrp->spp_flags & SPP_HB_DEMAND) {
4769 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4770 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
4771 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4773 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4774 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4775 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4776 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4778 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4779 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4780 net->mtu = paddrp->spp_pathmtu + ovh;
4781 if (net->mtu < stcb->asoc.smallest_mtu) {
4782 sctp_pathmtu_adjustment(stcb, net->mtu);
4786 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4787 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4788 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4790 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4792 if (paddrp->spp_pathmaxrxt) {
4793 if (net->dest_state & SCTP_ADDR_PF) {
4794 if (net->error_count > paddrp->spp_pathmaxrxt) {
4795 net->dest_state &= ~SCTP_ADDR_PF;
4798 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4799 (net->error_count > net->pf_threshold)) {
4800 net->dest_state |= SCTP_ADDR_PF;
4801 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4802 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4803 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4806 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4807 if (net->error_count > paddrp->spp_pathmaxrxt) {
4808 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4809 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
4812 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4813 net->dest_state |= SCTP_ADDR_REACHABLE;
4814 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
4817 net->failure_threshold = paddrp->spp_pathmaxrxt;
4819 if (paddrp->spp_flags & SPP_DSCP) {
4820 net->dscp = paddrp->spp_dscp & 0xfc;
4824 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4825 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4826 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4827 net->flowlabel |= 0x80000000;
4832 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
4833 if (paddrp->spp_pathmaxrxt) {
4834 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
4835 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4836 if (net->dest_state & SCTP_ADDR_PF) {
4837 if (net->error_count > paddrp->spp_pathmaxrxt) {
4838 net->dest_state &= ~SCTP_ADDR_PF;
4841 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4842 (net->error_count > net->pf_threshold)) {
4843 net->dest_state |= SCTP_ADDR_PF;
4844 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4845 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4846 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4849 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4850 if (net->error_count > paddrp->spp_pathmaxrxt) {
4851 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4852 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
4855 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4856 net->dest_state |= SCTP_ADDR_REACHABLE;
4857 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
4860 net->failure_threshold = paddrp->spp_pathmaxrxt;
4863 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4864 if (paddrp->spp_hbinterval) {
4865 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
4866 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4867 stcb->asoc.heart_beat_delay = 0;
4869 /* Turn back on the timer */
4870 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4871 if (paddrp->spp_hbinterval) {
4872 net->heart_beat_delay = paddrp->spp_hbinterval;
4873 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4874 net->heart_beat_delay = 0;
4876 if (net->dest_state & SCTP_ADDR_NOHB) {
4877 net->dest_state &= ~SCTP_ADDR_NOHB;
4879 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4880 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4881 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4883 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4885 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4886 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4887 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
4888 net->dest_state |= SCTP_ADDR_NOHB;
4889 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
4890 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4894 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4896 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4897 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4898 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4899 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4900 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4902 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4903 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4904 net->mtu = paddrp->spp_pathmtu + ovh;
4905 if (net->mtu < stcb->asoc.smallest_mtu) {
4906 sctp_pathmtu_adjustment(stcb, net->mtu);
4910 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4912 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4913 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4914 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4915 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4917 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4919 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4921 if (paddrp->spp_flags & SPP_DSCP) {
4922 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4923 net->dscp = paddrp->spp_dscp & 0xfc;
4926 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
4927 stcb->asoc.default_dscp |= 0x01;
4930 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4931 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4932 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4933 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4934 net->flowlabel |= 0x80000000;
4937 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4938 stcb->asoc.default_flowlabel |= 0x80000000;
4942 SCTP_TCB_UNLOCK(stcb);
4944 /************************NO TCB, SET TO default stuff ******************/
4945 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4946 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4947 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
4948 SCTP_INP_WLOCK(inp);
4950 * For the TOS/FLOWLABEL stuff you
4951 * set it with the options on the
4954 if (paddrp->spp_pathmaxrxt) {
4955 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
4957 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
4958 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4959 else if (paddrp->spp_hbinterval) {
4960 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
4961 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
4962 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4964 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4965 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4966 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4967 } else if (paddrp->spp_hbinterval) {
4968 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4970 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4971 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
4972 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4974 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4975 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4976 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
4977 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4979 if (paddrp->spp_flags & SPP_DSCP) {
4980 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
4981 inp->sctp_ep.default_dscp |= 0x01;
4984 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4985 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4986 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4987 inp->sctp_ep.default_flowlabel |= 0x80000000;
4991 SCTP_INP_WUNLOCK(inp);
4993 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5001 struct sctp_rtoinfo *srto;
5002 uint32_t new_init, new_min, new_max;
5004 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5005 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5008 if (srto->srto_initial)
5009 new_init = srto->srto_initial;
5011 new_init = stcb->asoc.initial_rto;
5013 new_max = srto->srto_max;
5015 new_max = stcb->asoc.maxrto;
5017 new_min = srto->srto_min;
5019 new_min = stcb->asoc.minrto;
5020 if ((new_min <= new_init) && (new_init <= new_max)) {
5021 stcb->asoc.initial_rto = new_init;
5022 stcb->asoc.maxrto = new_max;
5023 stcb->asoc.minrto = new_min;
5025 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5028 SCTP_TCB_UNLOCK(stcb);
5030 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5031 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5032 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5033 SCTP_INP_WLOCK(inp);
5034 if (srto->srto_initial)
5035 new_init = srto->srto_initial;
5037 new_init = inp->sctp_ep.initial_rto;
5039 new_max = srto->srto_max;
5041 new_max = inp->sctp_ep.sctp_maxrto;
5043 new_min = srto->srto_min;
5045 new_min = inp->sctp_ep.sctp_minrto;
5046 if ((new_min <= new_init) && (new_init <= new_max)) {
5047 inp->sctp_ep.initial_rto = new_init;
5048 inp->sctp_ep.sctp_maxrto = new_max;
5049 inp->sctp_ep.sctp_minrto = new_min;
5051 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5054 SCTP_INP_WUNLOCK(inp);
5056 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5062 case SCTP_ASSOCINFO:
5064 struct sctp_assocparams *sasoc;
5066 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5067 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5068 if (sasoc->sasoc_cookie_life) {
5069 /* boundary check the cookie life */
5070 if (sasoc->sasoc_cookie_life < 1000)
5071 sasoc->sasoc_cookie_life = 1000;
5072 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5073 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5077 if (sasoc->sasoc_asocmaxrxt)
5078 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5079 if (sasoc->sasoc_cookie_life) {
5080 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5082 SCTP_TCB_UNLOCK(stcb);
5084 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5085 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5086 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5087 SCTP_INP_WLOCK(inp);
5088 if (sasoc->sasoc_asocmaxrxt)
5089 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5090 if (sasoc->sasoc_cookie_life) {
5091 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5093 SCTP_INP_WUNLOCK(inp);
5095 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5103 struct sctp_initmsg *sinit;
5105 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5106 SCTP_INP_WLOCK(inp);
5107 if (sinit->sinit_num_ostreams)
5108 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5110 if (sinit->sinit_max_instreams)
5111 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5113 if (sinit->sinit_max_attempts)
5114 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5116 if (sinit->sinit_max_init_timeo)
5117 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5118 SCTP_INP_WUNLOCK(inp);
5121 case SCTP_PRIMARY_ADDR:
5123 struct sctp_setprim *spa;
5124 struct sctp_nets *net;
5126 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5127 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5131 net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
5134 * We increment here since
5135 * sctp_findassociation_ep_addr() wil do a
5136 * decrement if it finds the stcb as long as
5137 * the locked tcb (last argument) is NOT a
5140 SCTP_INP_INCR_REF(inp);
5141 stcb = sctp_findassociation_ep_addr(&inp,
5142 (struct sockaddr *)&spa->ssp_addr,
5145 SCTP_INP_DECR_REF(inp);
5149 if ((stcb) && (net)) {
5150 if ((net != stcb->asoc.primary_destination) &&
5151 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
5152 /* Ok we need to set it */
5153 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5154 if ((stcb->asoc.alternate) &&
5155 (!(net->dest_state & SCTP_ADDR_PF)) &&
5156 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5157 sctp_free_remote_addr(stcb->asoc.alternate);
5158 stcb->asoc.alternate = NULL;
5163 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5167 SCTP_TCB_UNLOCK(stcb);
5171 case SCTP_SET_DYNAMIC_PRIMARY:
5173 union sctp_sockstore *ss;
5175 error = priv_check(curthread,
5176 PRIV_NETINET_RESERVEDPORT);
5180 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5181 /* SUPER USER CHECK? */
5182 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5185 case SCTP_SET_PEER_PRIMARY_ADDR:
5187 struct sctp_setpeerprim *sspp;
5189 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5190 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5192 struct sctp_ifa *ifa;
5194 ifa = sctp_find_ifa_by_addr((struct sockaddr *)&sspp->sspp_addr,
5195 stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5197 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5201 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5203 * Must validate the ifa found is in
5206 struct sctp_laddr *laddr;
5209 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5210 if (laddr->ifa == NULL) {
5211 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5215 if (laddr->ifa == ifa) {
5221 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5226 if (sctp_set_primary_ip_address_sa(stcb,
5227 (struct sockaddr *)&sspp->sspp_addr) != 0) {
5228 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5232 SCTP_TCB_UNLOCK(stcb);
5234 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5239 case SCTP_BINDX_ADD_ADDR:
5241 struct sctp_getaddresses *addrs;
5244 td = (struct thread *)p;
5245 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5248 if (addrs->addr->sa_family == AF_INET) {
5249 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5250 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5254 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5255 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5261 if (addrs->addr->sa_family == AF_INET6) {
5262 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5263 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5267 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5268 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5269 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5275 error = EAFNOSUPPORT;
5278 sctp_bindx_add_address(so, inp, addrs->addr,
5279 addrs->sget_assoc_id, vrf_id,
5283 case SCTP_BINDX_REM_ADDR:
5285 struct sctp_getaddresses *addrs;
5288 td = (struct thread *)p;
5290 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5292 if (addrs->addr->sa_family == AF_INET) {
5293 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5294 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5298 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5299 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5305 if (addrs->addr->sa_family == AF_INET6) {
5306 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5307 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5312 (error = prison_local_ip6(td->td_ucred,
5313 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5314 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5315 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5321 error = EAFNOSUPPORT;
5324 sctp_bindx_delete_address(inp, addrs->addr,
5325 addrs->sget_assoc_id, vrf_id,
5331 struct sctp_event *event;
5332 uint32_t event_type;
5334 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5335 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5336 switch (event->se_type) {
5337 case SCTP_ASSOC_CHANGE:
5338 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5340 case SCTP_PEER_ADDR_CHANGE:
5341 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5343 case SCTP_REMOTE_ERROR:
5344 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5346 case SCTP_SEND_FAILED:
5347 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5349 case SCTP_SHUTDOWN_EVENT:
5350 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5352 case SCTP_ADAPTATION_INDICATION:
5353 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5355 case SCTP_PARTIAL_DELIVERY_EVENT:
5356 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5358 case SCTP_AUTHENTICATION_EVENT:
5359 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5361 case SCTP_STREAM_RESET_EVENT:
5362 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5364 case SCTP_SENDER_DRY_EVENT:
5365 event_type = SCTP_PCB_FLAGS_DRYEVNT;
5367 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
5369 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5372 case SCTP_ASSOC_RESET_EVENT:
5373 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
5375 case SCTP_STREAM_CHANGE_EVENT:
5376 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
5378 case SCTP_SEND_FAILED_EVENT:
5379 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
5383 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5387 if (event_type > 0) {
5390 sctp_stcb_feature_on(inp, stcb, event_type);
5391 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
5392 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5393 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5394 (stcb->asoc.stream_queue_cnt == 0)) {
5395 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5399 sctp_stcb_feature_off(inp, stcb, event_type);
5401 SCTP_TCB_UNLOCK(stcb);
5404 * We don't want to send up a storm
5405 * of events, so return an error for
5408 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
5409 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
5410 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
5411 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
5412 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
5413 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5417 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5418 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5419 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
5420 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5421 SCTP_INP_WLOCK(inp);
5423 sctp_feature_on(inp, event_type);
5425 sctp_feature_off(inp, event_type);
5427 SCTP_INP_WUNLOCK(inp);
5429 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
5430 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5431 SCTP_INP_RLOCK(inp);
5432 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5433 SCTP_TCB_LOCK(stcb);
5435 sctp_stcb_feature_on(inp, stcb, event_type);
5437 sctp_stcb_feature_off(inp, stcb, event_type);
5439 SCTP_TCB_UNLOCK(stcb);
5441 SCTP_INP_RUNLOCK(inp);
5447 case SCTP_RECVRCVINFO:
5451 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5452 SCTP_INP_WLOCK(inp);
5454 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5456 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5458 SCTP_INP_WUNLOCK(inp);
5461 case SCTP_RECVNXTINFO:
5465 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5466 SCTP_INP_WLOCK(inp);
5468 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5470 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5472 SCTP_INP_WUNLOCK(inp);
5475 case SCTP_DEFAULT_SNDINFO:
5477 struct sctp_sndinfo *info;
5480 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
5481 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
5484 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5485 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5486 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5487 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5488 stcb->asoc.def_send.sinfo_flags |= policy;
5489 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5490 stcb->asoc.def_send.sinfo_context = info->snd_context;
5492 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5495 SCTP_TCB_UNLOCK(stcb);
5497 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5498 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5499 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
5500 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5501 SCTP_INP_WLOCK(inp);
5502 inp->def_send.sinfo_stream = info->snd_sid;
5503 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
5504 inp->def_send.sinfo_flags = info->snd_flags;
5505 inp->def_send.sinfo_flags |= policy;
5506 inp->def_send.sinfo_ppid = info->snd_ppid;
5507 inp->def_send.sinfo_context = info->snd_context;
5508 SCTP_INP_WUNLOCK(inp);
5510 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
5511 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5512 SCTP_INP_RLOCK(inp);
5513 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5514 SCTP_TCB_LOCK(stcb);
5515 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5516 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5517 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5518 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5519 stcb->asoc.def_send.sinfo_flags |= policy;
5520 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5521 stcb->asoc.def_send.sinfo_context = info->snd_context;
5523 SCTP_TCB_UNLOCK(stcb);
5525 SCTP_INP_RUNLOCK(inp);
5530 case SCTP_DEFAULT_PRINFO:
5532 struct sctp_default_prinfo *info;
5534 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
5535 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
5537 if (PR_SCTP_INVALID_POLICY(info->pr_policy)) {
5538 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5543 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5544 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5545 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5546 SCTP_TCB_UNLOCK(stcb);
5548 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5549 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5550 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
5551 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5552 SCTP_INP_WLOCK(inp);
5553 inp->def_send.sinfo_flags &= 0xfff0;
5554 inp->def_send.sinfo_flags |= info->pr_policy;
5555 inp->def_send.sinfo_timetolive = info->pr_value;
5556 SCTP_INP_WUNLOCK(inp);
5558 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
5559 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5560 SCTP_INP_RLOCK(inp);
5561 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5562 SCTP_TCB_LOCK(stcb);
5563 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5564 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5565 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5566 SCTP_TCB_UNLOCK(stcb);
5568 SCTP_INP_RUNLOCK(inp);
5573 case SCTP_PEER_ADDR_THLDS:
5574 /* Applies to the specific association */
5576 struct sctp_paddrthlds *thlds;
5577 struct sctp_nets *net;
5579 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
5580 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
5583 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_assoc_id);
5586 * We increment here since
5587 * sctp_findassociation_ep_addr() wil do a
5588 * decrement if it finds the stcb as long as
5589 * the locked tcb (last argument) is NOT a
5592 SCTP_INP_INCR_REF(inp);
5593 stcb = sctp_findassociation_ep_addr(&inp,
5594 (struct sockaddr *)&thlds->spt_assoc_id,
5597 SCTP_INP_DECR_REF(inp);
5600 if (stcb && (net == NULL)) {
5601 struct sockaddr *sa;
5603 sa = (struct sockaddr *)&thlds->spt_assoc_id;
5605 if (sa->sa_family == AF_INET) {
5607 struct sockaddr_in *sin;
5609 sin = (struct sockaddr_in *)sa;
5610 if (sin->sin_addr.s_addr) {
5611 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5612 SCTP_TCB_UNLOCK(stcb);
5619 if (sa->sa_family == AF_INET6) {
5620 struct sockaddr_in6 *sin6;
5622 sin6 = (struct sockaddr_in6 *)sa;
5623 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5624 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5625 SCTP_TCB_UNLOCK(stcb);
5632 error = EAFNOSUPPORT;
5633 SCTP_TCB_UNLOCK(stcb);
5634 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5640 if (net->dest_state & SCTP_ADDR_PF) {
5641 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5642 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5643 net->dest_state &= ~SCTP_ADDR_PF;
5646 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5647 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5648 net->dest_state |= SCTP_ADDR_PF;
5649 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5650 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5651 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5654 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5655 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5656 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5657 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5660 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5661 net->dest_state |= SCTP_ADDR_REACHABLE;
5662 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5665 net->failure_threshold = thlds->spt_pathmaxrxt;
5666 net->pf_threshold = thlds->spt_pathpfthld;
5668 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5669 if (net->dest_state & SCTP_ADDR_PF) {
5670 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5671 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5672 net->dest_state &= ~SCTP_ADDR_PF;
5675 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5676 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5677 net->dest_state |= SCTP_ADDR_PF;
5678 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5679 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5680 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5683 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5684 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5685 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5686 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5689 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5690 net->dest_state |= SCTP_ADDR_REACHABLE;
5691 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5694 net->failure_threshold = thlds->spt_pathmaxrxt;
5695 net->pf_threshold = thlds->spt_pathpfthld;
5697 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
5698 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
5701 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5702 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5703 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
5704 SCTP_INP_WLOCK(inp);
5705 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
5706 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
5707 SCTP_INP_WUNLOCK(inp);
5709 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5715 case SCTP_REMOTE_UDP_ENCAPS_PORT:
5717 struct sctp_udpencaps *encaps;
5718 struct sctp_nets *net;
5720 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
5721 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
5723 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
5726 * We increment here since
5727 * sctp_findassociation_ep_addr() wil do a
5728 * decrement if it finds the stcb as long as
5729 * the locked tcb (last argument) is NOT a
5733 SCTP_INP_INCR_REF(inp);
5734 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
5736 SCTP_INP_DECR_REF(inp);
5739 if (stcb && (net == NULL)) {
5740 struct sockaddr *sa;
5742 sa = (struct sockaddr *)&encaps->sue_address;
5744 if (sa->sa_family == AF_INET) {
5746 struct sockaddr_in *sin;
5748 sin = (struct sockaddr_in *)sa;
5749 if (sin->sin_addr.s_addr) {
5750 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5751 SCTP_TCB_UNLOCK(stcb);
5758 if (sa->sa_family == AF_INET6) {
5759 struct sockaddr_in6 *sin6;
5761 sin6 = (struct sockaddr_in6 *)sa;
5762 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5763 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5764 SCTP_TCB_UNLOCK(stcb);
5771 error = EAFNOSUPPORT;
5772 SCTP_TCB_UNLOCK(stcb);
5773 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5779 net->port = encaps->sue_port;
5781 stcb->asoc.port = encaps->sue_port;
5783 SCTP_TCB_UNLOCK(stcb);
5785 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5786 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5787 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
5788 SCTP_INP_WLOCK(inp);
5789 inp->sctp_ep.port = encaps->sue_port;
5790 SCTP_INP_WUNLOCK(inp);
5792 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5799 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
5800 error = ENOPROTOOPT;
5802 } /* end switch (opt) */
5807 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
5809 void *optval = NULL;
5814 if (sopt->sopt_level != IPPROTO_SCTP) {
5815 /* wrong proto level... send back up to IP */
5817 if (INP_CHECK_SOCKAF(so, AF_INET6))
5818 error = ip6_ctloutput(so, sopt);
5820 #if defined(INET) && defined(INET6)
5824 error = ip_ctloutput(so, sopt);
5828 optsize = sopt->sopt_valsize;
5830 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
5831 if (optval == NULL) {
5832 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
5835 error = sooptcopyin(sopt, optval, optsize, optsize);
5837 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5841 p = (void *)sopt->sopt_td;
5842 if (sopt->sopt_dir == SOPT_SET) {
5843 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
5844 } else if (sopt->sopt_dir == SOPT_GET) {
5845 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
5847 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5850 if ((error == 0) && (optval != NULL)) {
5851 error = sooptcopyout(sopt, optval, optsize);
5852 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5853 } else if (optval != NULL) {
5854 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5862 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
5865 int create_lock_on = 0;
5867 struct sctp_inpcb *inp;
5868 struct sctp_tcb *stcb = NULL;
5870 inp = (struct sctp_inpcb *)so->so_pcb;
5872 /* I made the same as TCP since we are not setup? */
5873 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5874 return (ECONNRESET);
5877 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5880 switch (addr->sa_family) {
5884 struct sockaddr_in6 *sin6p;
5886 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
5887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5890 sin6p = (struct sockaddr_in6 *)addr;
5891 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
5892 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5901 struct sockaddr_in *sinp;
5903 if (addr->sa_len != sizeof(struct sockaddr_in)) {
5904 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5907 sinp = (struct sockaddr_in *)addr;
5908 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
5909 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5916 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
5917 return (EAFNOSUPPORT);
5919 SCTP_INP_INCR_REF(inp);
5920 SCTP_ASOC_CREATE_LOCK(inp);
5924 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
5925 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
5926 /* Should I really unlock ? */
5927 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
5932 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
5933 (addr->sa_family == AF_INET6)) {
5934 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5939 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
5940 SCTP_PCB_FLAGS_UNBOUND) {
5941 /* Bind a ephemeral port */
5942 error = sctp_inpcb_bind(so, NULL, NULL, p);
5947 /* Now do we connect? */
5948 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
5949 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
5950 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5954 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
5955 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
5956 /* We are already connected AND the TCP model */
5957 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
5961 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
5962 SCTP_INP_RLOCK(inp);
5963 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5964 SCTP_INP_RUNLOCK(inp);
5967 * We increment here since sctp_findassociation_ep_addr()
5968 * will do a decrement if it finds the stcb as long as the
5969 * locked tcb (last argument) is NOT a TCB.. aka NULL.
5971 SCTP_INP_INCR_REF(inp);
5972 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
5974 SCTP_INP_DECR_REF(inp);
5976 SCTP_TCB_UNLOCK(stcb);
5980 /* Already have or am bring up an association */
5981 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
5985 vrf_id = inp->def_vrf_id;
5986 /* We are GOOD to go */
5987 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
5989 /* Gak! no memory */
5992 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
5993 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
5994 /* Set the connected flag so we can queue data */
5997 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
5998 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
6000 /* initialize authentication parameters for the assoc */
6001 sctp_initialize_auth_params(inp, stcb);
6003 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
6004 SCTP_TCB_UNLOCK(stcb);
6006 if (create_lock_on) {
6007 SCTP_ASOC_CREATE_UNLOCK(inp);
6009 SCTP_INP_DECR_REF(inp);
6016 sctp_listen(struct socket *so, int backlog, struct thread *p)
6019 * Note this module depends on the protocol processing being called
6020 * AFTER any socket level flags and backlog are applied to the
6021 * socket. The traditional way that the socket flags are applied is
6022 * AFTER protocol processing. We have made a change to the
6023 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
6024 * place if the socket API for SCTP is to work properly.
6028 struct sctp_inpcb *inp;
6030 inp = (struct sctp_inpcb *)so->so_pcb;
6032 /* I made the same as TCP since we are not setup? */
6033 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6034 return (ECONNRESET);
6036 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
6037 /* See if we have a listener */
6038 struct sctp_inpcb *tinp;
6039 union sctp_sockstore store, *sp;
6042 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
6044 struct sctp_laddr *laddr;
6046 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6047 memcpy(&store, &laddr->ifa->address, sizeof(store));
6048 switch (sp->sa.sa_family) {
6051 sp->sin.sin_port = inp->sctp_lport;
6056 sp->sin6.sin6_port = inp->sctp_lport;
6062 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6063 if (tinp && (tinp != inp) &&
6064 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6065 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6066 (tinp->sctp_socket->so_qlimit)) {
6068 * we have a listener already and
6071 SCTP_INP_DECR_REF(tinp);
6072 return (EADDRINUSE);
6074 SCTP_INP_DECR_REF(tinp);
6078 /* Setup a local addr bound all */
6079 memset(&store, 0, sizeof(store));
6080 switch (sp->sa.sa_family) {
6083 store.sin.sin_port = inp->sctp_lport;
6088 sp->sin6.sin6_port = inp->sctp_lport;
6095 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
6096 store.sa.sa_family = AF_INET6;
6097 store.sa.sa_len = sizeof(struct sockaddr_in6);
6101 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
6102 store.sa.sa_family = AF_INET;
6103 store.sa.sa_len = sizeof(struct sockaddr_in);
6106 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6107 if (tinp && (tinp != inp) &&
6108 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6109 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6110 (tinp->sctp_socket->so_qlimit)) {
6112 * we have a listener already and its not
6115 SCTP_INP_DECR_REF(tinp);
6116 return (EADDRINUSE);
6118 SCTP_INP_DECR_REF(inp);
6122 SCTP_INP_RLOCK(inp);
6123 #ifdef SCTP_LOCK_LOGGING
6124 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
6125 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
6129 error = solisten_proto_check(so);
6132 SCTP_INP_RUNLOCK(inp);
6135 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
6136 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
6138 * The unlucky case - We are in the tcp pool with this guy.
6139 * - Someone else is in the main inp slot. - We must move
6140 * this guy (the listener) to the main slot - We must then
6141 * move the guy that was listener to the TCP Pool.
6143 if (sctp_swap_inpcb_for_listen(inp)) {
6147 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6148 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6149 /* We are already connected AND the TCP model */
6151 SCTP_INP_RUNLOCK(inp);
6153 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6154 return (EADDRINUSE);
6156 SCTP_INP_RUNLOCK(inp);
6157 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
6158 /* We must do a bind. */
6160 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
6161 /* bind error, probably perm */
6166 /* It appears for 7.0 and on, we must always call this. */
6167 solisten_proto(so, backlog);
6168 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6169 /* remove the ACCEPTCONN flag for one-to-many sockets */
6170 so->so_options &= ~SO_ACCEPTCONN;
6173 /* turning off listen */
6174 so->so_options &= ~SO_ACCEPTCONN;
6180 static int sctp_defered_wakeup_cnt = 0;
6183 sctp_accept(struct socket *so, struct sockaddr **addr)
6185 struct sctp_tcb *stcb;
6186 struct sctp_inpcb *inp;
6187 union sctp_sockstore store;
6193 inp = (struct sctp_inpcb *)so->so_pcb;
6196 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6197 return (ECONNRESET);
6199 SCTP_INP_RLOCK(inp);
6200 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6201 SCTP_INP_RUNLOCK(inp);
6202 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
6203 return (EOPNOTSUPP);
6205 if (so->so_state & SS_ISDISCONNECTED) {
6206 SCTP_INP_RUNLOCK(inp);
6207 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
6208 return (ECONNABORTED);
6210 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6212 SCTP_INP_RUNLOCK(inp);
6213 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6214 return (ECONNRESET);
6216 SCTP_TCB_LOCK(stcb);
6217 SCTP_INP_RUNLOCK(inp);
6218 store = stcb->asoc.primary_destination->ro._l_addr;
6219 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
6220 SCTP_TCB_UNLOCK(stcb);
6221 switch (store.sa.sa_family) {
6225 struct sockaddr_in *sin;
6227 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6230 sin->sin_family = AF_INET;
6231 sin->sin_len = sizeof(*sin);
6232 sin->sin_port = store.sin.sin_port;
6233 sin->sin_addr = store.sin.sin_addr;
6234 *addr = (struct sockaddr *)sin;
6241 struct sockaddr_in6 *sin6;
6243 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
6246 sin6->sin6_family = AF_INET6;
6247 sin6->sin6_len = sizeof(*sin6);
6248 sin6->sin6_port = store.sin6.sin6_port;
6249 sin6->sin6_addr = store.sin6.sin6_addr;
6250 if ((error = sa6_recoverscope(sin6)) != 0) {
6251 SCTP_FREE_SONAME(sin6);
6254 *addr = (struct sockaddr *)sin6;
6262 /* Wake any delayed sleep action */
6263 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
6264 SCTP_INP_WLOCK(inp);
6265 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
6266 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
6267 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
6268 SCTP_INP_WUNLOCK(inp);
6269 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
6270 if (sowriteable(inp->sctp_socket)) {
6271 sowwakeup_locked(inp->sctp_socket);
6273 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
6275 SCTP_INP_WLOCK(inp);
6277 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
6278 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
6279 SCTP_INP_WUNLOCK(inp);
6280 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
6281 if (soreadable(inp->sctp_socket)) {
6282 sctp_defered_wakeup_cnt++;
6283 sorwakeup_locked(inp->sctp_socket);
6285 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
6287 SCTP_INP_WLOCK(inp);
6289 SCTP_INP_WUNLOCK(inp);
6291 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
6292 SCTP_TCB_LOCK(stcb);
6293 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
6300 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
6302 struct sockaddr_in *sin;
6304 struct sctp_inpcb *inp;
6305 struct sctp_ifa *sctp_ifa;
6308 * Do the malloc first in case it blocks.
6310 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6313 sin->sin_family = AF_INET;
6314 sin->sin_len = sizeof(*sin);
6315 inp = (struct sctp_inpcb *)so->so_pcb;
6317 SCTP_FREE_SONAME(sin);
6318 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6319 return (ECONNRESET);
6321 SCTP_INP_RLOCK(inp);
6322 sin->sin_port = inp->sctp_lport;
6323 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
6324 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6325 struct sctp_tcb *stcb;
6326 struct sockaddr_in *sin_a;
6327 struct sctp_nets *net;
6330 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6336 SCTP_TCB_LOCK(stcb);
6337 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6338 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6340 /* this will make coverity happy */
6343 if (sin_a->sin_family == AF_INET) {
6348 if ((!fnd) || (sin_a == NULL)) {
6350 SCTP_TCB_UNLOCK(stcb);
6353 vrf_id = inp->def_vrf_id;
6354 sctp_ifa = sctp_source_address_selection(inp,
6356 (sctp_route_t *) & net->ro,
6359 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
6360 sctp_free_ifa(sctp_ifa);
6362 SCTP_TCB_UNLOCK(stcb);
6364 /* For the bound all case you get back 0 */
6366 sin->sin_addr.s_addr = 0;
6370 /* Take the first IPv4 address in the list */
6371 struct sctp_laddr *laddr;
6374 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6375 if (laddr->ifa->address.sa.sa_family == AF_INET) {
6376 struct sockaddr_in *sin_a;
6378 sin_a = (struct sockaddr_in *)&laddr->ifa->address.sa;
6379 sin->sin_addr = sin_a->sin_addr;
6385 SCTP_FREE_SONAME(sin);
6386 SCTP_INP_RUNLOCK(inp);
6387 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6391 SCTP_INP_RUNLOCK(inp);
6392 (*addr) = (struct sockaddr *)sin;
6397 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
6399 struct sockaddr_in *sin;
6401 struct sockaddr_in *sin_a;
6402 struct sctp_inpcb *inp;
6403 struct sctp_tcb *stcb;
6404 struct sctp_nets *net;
6406 /* Do the malloc first in case it blocks. */
6407 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6410 sin->sin_family = AF_INET;
6411 sin->sin_len = sizeof(*sin);
6413 inp = (struct sctp_inpcb *)so->so_pcb;
6414 if ((inp == NULL) ||
6415 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
6416 /* UDP type and listeners will drop out here */
6417 SCTP_FREE_SONAME(sin);
6418 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
6421 SCTP_INP_RLOCK(inp);
6422 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6424 SCTP_TCB_LOCK(stcb);
6426 SCTP_INP_RUNLOCK(inp);
6428 SCTP_FREE_SONAME(sin);
6429 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6430 return (ECONNRESET);
6433 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6434 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6435 if (sin_a->sin_family == AF_INET) {
6437 sin->sin_port = stcb->rport;
6438 sin->sin_addr = sin_a->sin_addr;
6442 SCTP_TCB_UNLOCK(stcb);
6444 /* No IPv4 address */
6445 SCTP_FREE_SONAME(sin);
6446 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6449 (*addr) = (struct sockaddr *)sin;
6453 struct pr_usrreqs sctp_usrreqs = {
6454 .pru_abort = sctp_abort,
6455 .pru_accept = sctp_accept,
6456 .pru_attach = sctp_attach,
6457 .pru_bind = sctp_bind,
6458 .pru_connect = sctp_connect,
6459 .pru_control = in_control,
6460 .pru_close = sctp_close,
6461 .pru_detach = sctp_close,
6462 .pru_sopoll = sopoll_generic,
6463 .pru_flush = sctp_flush,
6464 .pru_disconnect = sctp_disconnect,
6465 .pru_listen = sctp_listen,
6466 .pru_peeraddr = sctp_peeraddr,
6467 .pru_send = sctp_sendm,
6468 .pru_shutdown = sctp_shutdown,
6469 .pru_sockaddr = sctp_ingetaddr,
6470 .pru_sosend = sctp_sosend,
6471 .pru_soreceive = sctp_soreceive