2 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * a) Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
10 * b) Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the distribution.
14 * c) Neither the name of Cisco Systems, Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE.
31 /* $KAME: sctp_usrreq.c,v 1.48 2005/03/07 23:26:08 itojun Exp $ */
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
35 #include <netinet/sctp_os.h>
37 #include <netinet/sctp_pcb.h>
38 #include <netinet/sctp_header.h>
39 #include <netinet/sctp_var.h>
42 #include <netinet/sctp_sysctl.h>
43 #include <netinet/sctp_output.h>
44 #include <netinet/sctp_uio.h>
45 #include <netinet/sctp_asconf.h>
46 #include <netinet/sctputil.h>
47 #include <netinet/sctp_indata.h>
48 #include <netinet/sctp_timer.h>
49 #include <netinet/sctp_auth.h>
50 #include <netinet/sctp_bsd_addr.h>
51 #include <netinet/sctp_cc_functions.h>
52 #include <netinet/udp.h>
62 bzero(&SCTP_BASE_STATS, sizeof(struct sctpstat));
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);
82 SCTP_BASE_VAR(first_time) = 0;
83 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
85 #if defined(SCTP_PACKET_LOGGING)
86 SCTP_BASE_VAR(packet_log_writers) = 0;
87 SCTP_BASE_VAR(packet_log_end) = 0;
88 bzero(&SCTP_BASE_VAR(packet_log_buffer), SCTP_PACKET_LOG_SIZE);
103 sctp_pathmtu_adjustment(struct sctp_inpcb *inp,
104 struct sctp_tcb *stcb,
105 struct sctp_nets *net,
108 struct sctp_tmit_chunk *chk;
111 /* Adjust that too */
112 stcb->asoc.smallest_mtu = nxtsz;
113 /* now off to subtract IP_DF flag if needed */
114 #ifdef SCTP_PRINT_FOR_B_AND_M
115 SCTP_PRINTF("sctp_pathmtu_adjust called inp:%p stcb:%p net:%p nxtsz:%d\n",
116 inp, stcb, net, nxtsz);
118 overhead = IP_HDR_SIZE;
119 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
120 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
122 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
123 if ((chk->send_size + overhead) > nxtsz) {
124 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
127 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
128 if ((chk->send_size + overhead) > nxtsz) {
130 * For this guy we also mark for immediate resend
131 * since we sent to big of chunk
133 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
134 if (chk->sent < SCTP_DATAGRAM_RESEND) {
135 sctp_flight_size_decrease(chk);
136 sctp_total_flight_decrease(stcb, chk);
138 if (chk->sent != SCTP_DATAGRAM_RESEND) {
139 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
141 chk->sent = SCTP_DATAGRAM_RESEND;
142 chk->rec.data.doing_fast_retransmit = 0;
143 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
144 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
145 chk->whoTo->flight_size,
147 (uintptr_t) chk->whoTo,
148 chk->rec.data.TSN_seq);
150 /* Clear any time so NO RTT is being done */
157 sctp_notify_mbuf(struct sctp_inpcb *inp,
158 struct sctp_tcb *stcb,
159 struct sctp_nets *net,
164 int totsz, tmr_stopped = 0;
168 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
169 (ip == NULL) || (sh == NULL)) {
171 SCTP_TCB_UNLOCK(stcb);
175 /* First job is to verify the vtag matches what I would send */
176 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
177 SCTP_TCB_UNLOCK(stcb);
180 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
182 if (icmph->icmp_type != ICMP_UNREACH) {
183 /* We only care about unreachable */
184 SCTP_TCB_UNLOCK(stcb);
187 if (icmph->icmp_code != ICMP_UNREACH_NEEDFRAG) {
188 /* not a unreachable message due to frag. */
189 SCTP_TCB_UNLOCK(stcb);
194 nxtsz = ntohs(icmph->icmp_nextmtu);
197 * old type router that does not tell us what the next size
198 * mtu is. Rats we will have to guess (in a educated fashion
201 nxtsz = find_next_best_mtu(totsz);
203 /* Stop any PMTU timer */
204 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
206 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
207 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
209 /* Adjust destination size limit */
210 if (net->mtu > nxtsz) {
213 net->mtu -= sizeof(struct udphdr);
216 /* now what about the ep? */
217 if (stcb->asoc.smallest_mtu > nxtsz) {
218 #ifdef SCTP_PRINT_FOR_B_AND_M
219 SCTP_PRINTF("notify_mbuf (ICMP) calls sctp_pathmtu_adjust mtu:%d\n",
222 sctp_pathmtu_adjustment(inp, stcb, net, nxtsz);
225 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
227 SCTP_TCB_UNLOCK(stcb);
232 sctp_notify(struct sctp_inpcb *inp,
236 struct sctp_tcb *stcb,
237 struct sctp_nets *net)
239 #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
248 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
249 (sh == NULL) || (to == NULL)) {
251 SCTP_TCB_UNLOCK(stcb);
254 /* First job is to verify the vtag matches what I would send */
255 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
256 SCTP_TCB_UNLOCK(stcb);
259 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
261 if (icmph->icmp_type != ICMP_UNREACH) {
262 /* We only care about unreachable */
263 SCTP_TCB_UNLOCK(stcb);
266 if ((icmph->icmp_code == ICMP_UNREACH_NET) ||
267 (icmph->icmp_code == ICMP_UNREACH_HOST) ||
268 (icmph->icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
269 (icmph->icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
270 (icmph->icmp_code == ICMP_UNREACH_ISOLATED) ||
271 (icmph->icmp_code == ICMP_UNREACH_NET_PROHIB) ||
272 (icmph->icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
273 (icmph->icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
276 * Hmm reachablity problems we must examine closely. If its
277 * not reachable, we may have lost a network. Or if there is
278 * NO protocol at the other end named SCTP. well we consider
281 if (net->dest_state & SCTP_ADDR_REACHABLE) {
282 /* Ok that destination is NOT reachable */
283 SCTP_PRINTF("ICMP (thresh %d/%d) takes interface %p down\n",
285 net->failure_threshold,
288 net->dest_state &= ~SCTP_ADDR_REACHABLE;
289 net->dest_state |= SCTP_ADDR_NOT_REACHABLE;
291 * JRS 5/14/07 - If a destination is unreachable,
292 * the PF bit is turned off. This allows an
293 * unambiguous use of the PF bit for destinations
294 * that are reachable but potentially failed. If the
295 * destination is set to the unreachable state, also
296 * set the destination to the PF state.
299 * Add debug message here if destination is not in
302 /* Stop any running T3 timers here? */
303 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off) && SCTP_BASE_SYSCTL(sctp_cmt_pf)) {
304 net->dest_state &= ~SCTP_ADDR_PF;
305 SCTPDBG(SCTP_DEBUG_TIMER4, "Destination %p moved from PF to unreachable.\n",
308 net->error_count = net->failure_threshold + 1;
309 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
310 stcb, SCTP_FAILED_THRESHOLD,
311 (void *)net, SCTP_SO_NOT_LOCKED);
313 SCTP_TCB_UNLOCK(stcb);
314 } else if ((icmph->icmp_code == ICMP_UNREACH_PROTOCOL) ||
315 (icmph->icmp_code == ICMP_UNREACH_PORT)) {
317 * Here the peer is either playing tricks on us, including
318 * an address that belongs to someone who does not support
319 * SCTP OR was a userland implementation that shutdown and
320 * now is dead. In either case treat it like a OOTB abort
323 reason = SCTP_PEER_FAULTY;
324 sctp_abort_notification(stcb, reason, SCTP_SO_NOT_LOCKED);
325 #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
326 so = SCTP_INP_SO(inp);
327 atomic_add_int(&stcb->asoc.refcnt, 1);
328 SCTP_TCB_UNLOCK(stcb);
329 SCTP_SOCKET_LOCK(so, 1);
331 atomic_subtract_int(&stcb->asoc.refcnt, 1);
333 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
334 #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
335 SCTP_SOCKET_UNLOCK(so, 1);
336 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
338 /* no need to unlock here, since the TCB is gone */
340 SCTP_TCB_UNLOCK(stcb);
345 sctp_ctlinput(cmd, sa, vip)
354 /* FIX, for non-bsd is this right? */
355 vrf_id = SCTP_DEFAULT_VRFID;
356 if (sa->sa_family != AF_INET ||
357 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
360 if (PRC_IS_REDIRECT(cmd)) {
362 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
366 struct sctp_inpcb *inp = NULL;
367 struct sctp_tcb *stcb = NULL;
368 struct sctp_nets *net = NULL;
369 struct sockaddr_in to, from;
371 sh = (struct sctphdr *)((caddr_t)ip + (ip->ip_hl << 2));
372 bzero(&to, sizeof(to));
373 bzero(&from, sizeof(from));
374 from.sin_family = to.sin_family = AF_INET;
375 from.sin_len = to.sin_len = sizeof(to);
376 from.sin_port = sh->src_port;
377 from.sin_addr = ip->ip_src;
378 to.sin_port = sh->dest_port;
379 to.sin_addr = ip->ip_dst;
382 * 'to' holds the dest of the packet that failed to be sent.
383 * 'from' holds our local endpoint address. Thus we reverse
384 * the to and the from in the lookup.
386 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&from,
387 (struct sockaddr *)&to,
388 &inp, &net, 1, vrf_id);
389 if (stcb != NULL && inp && (inp->sctp_socket != NULL)) {
390 if (cmd != PRC_MSGSIZE) {
391 sctp_notify(inp, ip, sh,
392 (struct sockaddr *)&to, stcb,
395 /* handle possible ICMP size messages */
396 sctp_notify_mbuf(inp, stcb, net, ip, sh);
399 if ((stcb == NULL) && (inp != NULL)) {
400 /* reduce ref-count */
402 SCTP_INP_DECR_REF(inp);
403 SCTP_INP_WUNLOCK(inp);
406 SCTP_TCB_UNLOCK(stcb);
414 sctp_getcred(SYSCTL_HANDLER_ARGS)
417 struct sockaddr_in addrs[2];
418 struct sctp_inpcb *inp;
419 struct sctp_nets *net;
420 struct sctp_tcb *stcb;
424 /* FIX, for non-bsd is this right? */
425 vrf_id = SCTP_DEFAULT_VRFID;
427 error = priv_check(req->td, PRIV_NETINET_GETCRED);
432 error = SYSCTL_IN(req, addrs, sizeof(addrs));
436 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[0]),
438 &inp, &net, 1, vrf_id);
439 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
440 if ((inp != NULL) && (stcb == NULL)) {
441 /* reduce ref-count */
443 SCTP_INP_DECR_REF(inp);
446 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
450 SCTP_TCB_UNLOCK(stcb);
452 * We use the write lock here, only since in the error leg we need
453 * it. If we used RLOCK, then we would have to
454 * wlock/decr/unlock/rlock. Which in theory could create a hole.
455 * Better to use higher wlock.
459 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
461 SCTP_INP_WUNLOCK(inp);
464 cru2x(inp->sctp_socket->so_cred, &xuc);
465 SCTP_INP_WUNLOCK(inp);
466 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
471 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
472 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
476 sctp_abort(struct socket *so)
478 struct sctp_inpcb *inp;
481 inp = (struct sctp_inpcb *)so->so_pcb;
486 flags = inp->sctp_flags;
487 #ifdef SCTP_LOG_CLOSING
488 sctp_log_closing(inp, NULL, 17);
490 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
491 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
492 #ifdef SCTP_LOG_CLOSING
493 sctp_log_closing(inp, NULL, 16);
495 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
496 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
498 SCTP_SB_CLEAR(so->so_snd);
500 * same for the rcv ones, they are only here for the
503 SCTP_SB_CLEAR(so->so_rcv);
505 /* Now null out the reference, we are completely detached. */
509 flags = inp->sctp_flags;
510 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
511 goto sctp_must_try_again;
518 sctp_attach(struct socket *so, int proto, struct thread *p)
520 struct sctp_inpcb *inp;
521 struct inpcb *ip_inp;
523 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
530 inp = (struct sctp_inpcb *)so->so_pcb;
532 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
535 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
536 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
541 error = sctp_inpcb_alloc(so, vrf_id);
545 inp = (struct sctp_inpcb *)so->so_pcb;
547 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
548 ip_inp = &inp->ip_inp.inp;
549 ip_inp->inp_vflag |= INP_IPV4;
550 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
552 error = ipsec_init_policy(so, &ip_inp->inp_sp);
553 #ifdef SCTP_LOG_CLOSING
554 sctp_log_closing(inp, NULL, 17);
558 flags = inp->sctp_flags;
559 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
560 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
561 #ifdef SCTP_LOG_CLOSING
562 sctp_log_closing(inp, NULL, 15);
564 SCTP_INP_WUNLOCK(inp);
565 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
566 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
568 flags = inp->sctp_flags;
569 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
572 SCTP_INP_WUNLOCK(inp);
578 SCTP_INP_WUNLOCK(inp);
583 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
585 struct sctp_inpcb *inp = NULL;
589 if (addr && addr->sa_family != AF_INET) {
590 /* must be a v4 address! */
591 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
595 if (addr && (addr->sa_len != sizeof(struct sockaddr_in))) {
596 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
599 inp = (struct sctp_inpcb *)so->so_pcb;
601 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
604 error = sctp_inpcb_bind(so, addr, NULL, p);
609 sctp_close(struct socket *so)
611 struct sctp_inpcb *inp;
614 inp = (struct sctp_inpcb *)so->so_pcb;
619 * Inform all the lower layer assoc that we are done.
622 flags = inp->sctp_flags;
623 #ifdef SCTP_LOG_CLOSING
624 sctp_log_closing(inp, NULL, 17);
626 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
627 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
628 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
629 (so->so_rcv.sb_cc > 0)) {
630 #ifdef SCTP_LOG_CLOSING
631 sctp_log_closing(inp, NULL, 13);
633 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
634 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
636 #ifdef SCTP_LOG_CLOSING
637 sctp_log_closing(inp, NULL, 14);
639 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
640 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
643 * The socket is now detached, no matter what the state of
644 * the SCTP association.
647 SCTP_SB_CLEAR(so->so_snd);
649 * same for the rcv ones, they are only here for the
652 SCTP_SB_CLEAR(so->so_rcv);
654 /* Now null out the reference, we are completely detached. */
658 flags = inp->sctp_flags;
659 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
660 goto sctp_must_try_again;
668 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
669 struct mbuf *control, struct thread *p);
673 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
674 struct mbuf *control, struct thread *p)
676 struct sctp_inpcb *inp;
679 inp = (struct sctp_inpcb *)so->so_pcb;
682 sctp_m_freem(control);
685 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
689 /* Got to have an to address if we are NOT a connected socket */
690 if ((addr == NULL) &&
691 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
692 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))
695 } else if (addr == NULL) {
696 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
697 error = EDESTADDRREQ;
700 sctp_m_freem(control);
706 if (addr->sa_family != AF_INET) {
707 /* must be a v4 address! */
708 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
711 sctp_m_freem(control);
714 error = EDESTADDRREQ;
719 /* now what about control */
722 SCTP_PRINTF("huh? control set?\n");
723 sctp_m_freem(inp->control);
726 inp->control = control;
730 SCTP_BUF_NEXT(inp->pkt_last) = m;
733 inp->pkt_last = inp->pkt = m;
736 /* FreeBSD uses a flag passed */
737 ((flags & PRUS_MORETOCOME) == 0)
740 * note with the current version this code will only be used
741 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
742 * re-defining sosend to use the sctp_sosend. One can
743 * optionally switch back to this code (by changing back the
744 * definitions) but this is not advisable. This code is used
745 * by FreeBSD when sending a file with sendfile() though.
749 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
759 sctp_disconnect(struct socket *so)
761 struct sctp_inpcb *inp;
763 inp = (struct sctp_inpcb *)so->so_pcb;
765 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
769 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
770 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
771 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
773 SCTP_INP_RUNLOCK(inp);
776 struct sctp_association *asoc;
777 struct sctp_tcb *stcb;
779 stcb = LIST_FIRST(&inp->sctp_asoc_list);
781 SCTP_INP_RUNLOCK(inp);
782 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
787 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
788 /* We are about to be freed, out of here */
789 SCTP_TCB_UNLOCK(stcb);
790 SCTP_INP_RUNLOCK(inp);
793 if (((so->so_options & SO_LINGER) &&
794 (so->so_linger == 0)) ||
795 (so->so_rcv.sb_cc > 0)) {
796 if (SCTP_GET_STATE(asoc) !=
797 SCTP_STATE_COOKIE_WAIT) {
798 /* Left with Data unread */
801 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_DONTWAIT, 1, MT_DATA);
807 struct sctp_paramhdr *ph;
809 ph = mtod(err, struct sctp_paramhdr *);
810 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
811 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
812 ph->param_length = htons(SCTP_BUF_LEN(err));
814 #if defined(SCTP_PANIC_ON_ABORT)
815 panic("disconnect does an abort");
817 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
818 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
820 SCTP_INP_RUNLOCK(inp);
821 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
822 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
823 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
825 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
826 /* No unlock tcb assoc is gone */
829 if (TAILQ_EMPTY(&asoc->send_queue) &&
830 TAILQ_EMPTY(&asoc->sent_queue) &&
831 (asoc->stream_queue_cnt == 0)) {
832 /* there is nothing queued to send, so done */
833 if (asoc->locked_on_sending) {
836 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
837 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
838 /* only send SHUTDOWN 1st time thru */
839 sctp_stop_timers_for_shutdown(stcb);
840 sctp_send_shutdown(stcb,
841 stcb->asoc.primary_destination);
842 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
843 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
844 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
845 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
847 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
848 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
849 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
851 asoc->primary_destination);
852 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
854 asoc->primary_destination);
858 * we still got (or just got) data to send,
859 * so set SHUTDOWN_PENDING
862 * XXX sockets draft says that SCTP_EOF
863 * should be sent with no data. currently,
864 * we will allow user data to be sent first
865 * and move to SHUTDOWN-PENDING
867 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
868 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
869 asoc->primary_destination);
870 if (asoc->locked_on_sending) {
871 /* Locked to send out the data */
872 struct sctp_stream_queue_pending *sp;
874 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
876 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
877 asoc->locked_on_sending->stream_no);
879 if ((sp->length == 0) && (sp->msg_is_complete == 0))
880 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
883 if (TAILQ_EMPTY(&asoc->send_queue) &&
884 TAILQ_EMPTY(&asoc->sent_queue) &&
885 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
889 op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
890 0, M_DONTWAIT, 1, MT_DATA);
896 struct sctp_paramhdr *ph;
899 SCTP_BUF_LEN(op_err) =
900 (sizeof(struct sctp_paramhdr) + sizeof(uint32_t));
902 struct sctp_paramhdr *);
903 ph->param_type = htons(
904 SCTP_CAUSE_USER_INITIATED_ABT);
905 ph->param_length = htons(SCTP_BUF_LEN(op_err));
906 ippp = (uint32_t *) (ph + 1);
907 *ippp = htonl(SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4);
909 #if defined(SCTP_PANIC_ON_ABORT)
910 panic("disconnect does an abort");
913 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
914 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
915 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
916 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
917 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
918 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
920 SCTP_INP_RUNLOCK(inp);
921 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
924 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
927 soisdisconnecting(so);
928 SCTP_TCB_UNLOCK(stcb);
929 SCTP_INP_RUNLOCK(inp);
934 /* UDP model does not support this */
935 SCTP_INP_RUNLOCK(inp);
936 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
942 sctp_flush(struct socket *so, int how)
945 * We will just clear out the values and let subsequent close clear
946 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
947 * they will not be able to read the data, the socket will block
948 * that from happening.
950 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
952 * First make sure the sb will be happy, we don't use these
953 * except maybe the count
955 so->so_rcv.sb_cc = 0;
956 so->so_rcv.sb_mbcnt = 0;
957 so->so_rcv.sb_mb = NULL;
959 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
961 * First make sure the sb will be happy, we don't use these
962 * except maybe the count
964 so->so_snd.sb_cc = 0;
965 so->so_snd.sb_mbcnt = 0;
966 so->so_snd.sb_mb = NULL;
973 sctp_shutdown(struct socket *so)
975 struct sctp_inpcb *inp;
977 inp = (struct sctp_inpcb *)so->so_pcb;
979 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
983 /* For UDP model this is a invalid call */
984 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
985 /* Restore the flags that the soshutdown took away. */
986 SOCKBUF_LOCK(&so->so_rcv);
987 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
988 SOCKBUF_UNLOCK(&so->so_rcv);
989 /* This proc will wakeup for read and do nothing (I hope) */
990 SCTP_INP_RUNLOCK(inp);
991 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
995 * Ok if we reach here its the TCP model and it is either a SHUT_WR
996 * or SHUT_RDWR. This means we put the shutdown flag against it.
999 struct sctp_tcb *stcb;
1000 struct sctp_association *asoc;
1003 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
1004 SCTP_INP_RUNLOCK(inp);
1009 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1012 * Ok we hit the case that the shutdown call was
1013 * made after an abort or something. Nothing to do
1016 SCTP_INP_RUNLOCK(inp);
1019 SCTP_TCB_LOCK(stcb);
1021 if (TAILQ_EMPTY(&asoc->send_queue) &&
1022 TAILQ_EMPTY(&asoc->sent_queue) &&
1023 (asoc->stream_queue_cnt == 0)) {
1024 if (asoc->locked_on_sending) {
1027 /* there is nothing queued to send, so I'm done... */
1028 if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) {
1029 /* only send SHUTDOWN the first time through */
1030 sctp_stop_timers_for_shutdown(stcb);
1031 sctp_send_shutdown(stcb,
1032 stcb->asoc.primary_destination);
1033 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
1034 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
1035 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
1036 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1038 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
1039 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
1040 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1041 stcb->sctp_ep, stcb,
1042 asoc->primary_destination);
1043 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1044 stcb->sctp_ep, stcb,
1045 asoc->primary_destination);
1049 * we still got (or just got) data to send, so set
1052 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1053 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
1054 asoc->primary_destination);
1056 if (asoc->locked_on_sending) {
1057 /* Locked to send out the data */
1058 struct sctp_stream_queue_pending *sp;
1060 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
1062 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
1063 asoc->locked_on_sending->stream_no);
1065 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
1066 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
1070 if (TAILQ_EMPTY(&asoc->send_queue) &&
1071 TAILQ_EMPTY(&asoc->sent_queue) &&
1072 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1073 struct mbuf *op_err;
1076 op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
1077 0, M_DONTWAIT, 1, MT_DATA);
1079 /* Fill in the user initiated abort */
1080 struct sctp_paramhdr *ph;
1083 SCTP_BUF_LEN(op_err) =
1084 sizeof(struct sctp_paramhdr) + sizeof(uint32_t);
1086 struct sctp_paramhdr *);
1087 ph->param_type = htons(
1088 SCTP_CAUSE_USER_INITIATED_ABT);
1089 ph->param_length = htons(SCTP_BUF_LEN(op_err));
1090 ippp = (uint32_t *) (ph + 1);
1091 *ippp = htonl(SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1093 #if defined(SCTP_PANIC_ON_ABORT)
1094 panic("shutdown does an abort");
1096 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
1097 sctp_abort_an_association(stcb->sctp_ep, stcb,
1098 SCTP_RESPONSE_TO_USER_REQ,
1099 op_err, SCTP_SO_LOCKED);
1102 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1105 SCTP_TCB_UNLOCK(stcb);
1108 SCTP_INP_RUNLOCK(inp);
1113 * copies a "user" presentable address and removes embedded scope, etc.
1114 * returns 0 on success, 1 on error
1117 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1120 struct sockaddr_in6 lsa6;
1122 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1125 memcpy(ss, sa, sa->sa_len);
1132 * NOTE: assumes addr lock is held
1135 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1136 struct sctp_tcb *stcb,
1138 struct sockaddr_storage *sas,
1141 struct sctp_ifn *sctp_ifn;
1142 struct sctp_ifa *sctp_ifa;
1143 int loopback_scope, ipv4_local_scope, local_scope, site_scope;
1145 int ipv4_addr_legal, ipv6_addr_legal;
1146 struct sctp_vrf *vrf;
1153 /* Turn on all the appropriate scope */
1154 loopback_scope = stcb->asoc.loopback_scope;
1155 ipv4_local_scope = stcb->asoc.ipv4_local_scope;
1156 local_scope = stcb->asoc.local_scope;
1157 site_scope = stcb->asoc.site_scope;
1159 /* Turn on ALL scope, since we look at the EP */
1160 loopback_scope = ipv4_local_scope = local_scope =
1163 ipv4_addr_legal = ipv6_addr_legal = 0;
1164 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1165 ipv6_addr_legal = 1;
1166 if (SCTP_IPV6_V6ONLY(inp) == 0) {
1167 ipv4_addr_legal = 1;
1170 ipv4_addr_legal = 1;
1172 vrf = sctp_find_vrf(vrf_id);
1176 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1177 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1178 if ((loopback_scope == 0) &&
1179 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1180 /* Skip loopback if loopback_scope not set */
1183 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1186 * For the BOUND-ALL case, the list
1187 * associated with a TCB is Always
1188 * considered a reverse list.. i.e.
1189 * it lists addresses that are NOT
1190 * part of the association. If this
1191 * is one of those we must skip it.
1193 if (sctp_is_addr_restricted(stcb,
1198 switch (sctp_ifa->address.sa.sa_family) {
1200 if (ipv4_addr_legal) {
1201 struct sockaddr_in *sin;
1203 sin = (struct sockaddr_in *)&sctp_ifa->address.sa;
1204 if (sin->sin_addr.s_addr == 0) {
1212 if ((ipv4_local_scope == 0) &&
1213 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1217 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1218 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1219 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1220 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1221 actual += sizeof(struct sockaddr_in6);
1224 memcpy(sas, sin, sizeof(*sin));
1225 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1226 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1227 actual += sizeof(*sin);
1231 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))
1308 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1309 sas = (struct sockaddr_storage *)((caddr_t)sas +
1310 laddr->ifa->address.sa.sa_len);
1311 actual += laddr->ifa->address.sa.sa_len;
1312 if (actual >= limit) {
1321 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1322 struct sctp_tcb *stcb,
1324 struct sockaddr_storage *sas)
1328 SCTP_IPI_ADDR_RLOCK();
1329 /* fill up addresses for the endpoint's default vrf */
1330 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1332 SCTP_IPI_ADDR_RUNLOCK();
1337 * NOTE: assumes addr lock is held
1340 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1343 struct sctp_vrf *vrf = NULL;
1346 * In both sub-set bound an bound_all cases we return the MAXIMUM
1347 * number of addresses that you COULD get. In reality the sub-set
1348 * bound may have an exclusion list for a given TCB OR in the
1349 * bound-all case a TCB may NOT include the loopback or other
1350 * addresses as well.
1352 vrf = sctp_find_vrf(vrf_id);
1356 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1357 struct sctp_ifn *sctp_ifn;
1358 struct sctp_ifa *sctp_ifa;
1360 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1361 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1362 /* Count them if they are the right type */
1363 if (sctp_ifa->address.sa.sa_family == AF_INET) {
1364 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1365 cnt += sizeof(struct sockaddr_in6);
1367 cnt += sizeof(struct sockaddr_in);
1369 } else if (sctp_ifa->address.sa.sa_family == AF_INET6)
1370 cnt += sizeof(struct sockaddr_in6);
1374 struct sctp_laddr *laddr;
1376 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1377 if (laddr->ifa->address.sa.sa_family == AF_INET) {
1378 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1379 cnt += sizeof(struct sockaddr_in6);
1381 cnt += sizeof(struct sockaddr_in);
1383 } else if (laddr->ifa->address.sa.sa_family == AF_INET6)
1384 cnt += sizeof(struct sockaddr_in6);
1391 sctp_count_max_addresses(struct sctp_inpcb *inp)
1395 SCTP_IPI_ADDR_RLOCK();
1396 /* count addresses for the endpoint's default VRF */
1397 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1398 SCTP_IPI_ADDR_RUNLOCK();
1403 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1404 size_t optsize, void *p, int delay)
1407 int creat_lock_on = 0;
1408 struct sctp_tcb *stcb = NULL;
1409 struct sockaddr *sa;
1410 int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1413 int bad_addresses = 0;
1416 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1418 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1419 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1420 /* We are already connected AND the TCP model */
1421 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1422 return (EADDRINUSE);
1424 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1425 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1426 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1429 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1430 SCTP_INP_RLOCK(inp);
1431 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1432 SCTP_INP_RUNLOCK(inp);
1435 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1438 SCTP_INP_INCR_REF(inp);
1439 SCTP_ASOC_CREATE_LOCK(inp);
1441 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1442 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1443 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1447 totaddrp = (int *)optval;
1448 totaddr = *totaddrp;
1449 sa = (struct sockaddr *)(totaddrp + 1);
1450 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (optsize - sizeof(int)), &bad_addresses);
1451 if ((stcb != NULL) || bad_addresses) {
1452 /* Already have or am bring up an association */
1453 SCTP_ASOC_CREATE_UNLOCK(inp);
1456 SCTP_TCB_UNLOCK(stcb);
1457 if (bad_addresses == 0) {
1458 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1464 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1469 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1471 struct in6pcb *inp6;
1473 inp6 = (struct in6pcb *)inp;
1474 if (SCTP_IPV6_V6ONLY(inp6)) {
1476 * if IPV6_V6ONLY flag, ignore connections destined
1477 * to a v4 addr or v4-mapped addr
1479 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1485 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1486 SCTP_PCB_FLAGS_UNBOUND) {
1487 /* Bind a ephemeral port */
1488 error = sctp_inpcb_bind(so, NULL, NULL, p);
1493 /* FIX ME: do we want to pass in a vrf on the connect call? */
1494 vrf_id = inp->def_vrf_id;
1497 /* We are GOOD to go */
1498 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1502 /* Gak! no memory */
1505 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1506 /* move to second address */
1507 if (sa->sa_family == AF_INET)
1508 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1510 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1513 added = sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1514 /* Fill in the return id */
1516 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1519 a_id = (sctp_assoc_t *) optval;
1520 *a_id = sctp_get_associd(stcb);
1522 /* initialize authentication parameters for the assoc */
1523 sctp_initialize_auth_params(inp, stcb);
1526 /* doing delayed connection */
1527 stcb->asoc.delayed_connection = 1;
1528 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1530 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1531 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1533 SCTP_TCB_UNLOCK(stcb);
1534 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1535 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1536 /* Set the connected flag so we can queue data */
1540 if (creat_lock_on) {
1541 SCTP_ASOC_CREATE_UNLOCK(inp);
1543 SCTP_INP_DECR_REF(inp);
1547 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1548 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1549 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1550 SCTP_INP_RLOCK(inp); \
1551 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1553 SCTP_TCB_LOCK(stcb); \
1555 SCTP_INP_RUNLOCK(inp); \
1556 } else if (assoc_id != 0) { \
1557 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1558 if (stcb == NULL) { \
1559 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1569 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1570 if (size < sizeof(type)) { \
1571 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1575 destp = (type *)srcp; \
1580 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1583 struct sctp_inpcb *inp = NULL;
1585 struct sctp_tcb *stcb = NULL;
1587 if (optval == NULL) {
1588 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1591 inp = (struct sctp_inpcb *)so->so_pcb;
1593 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1600 case SCTP_AUTOCLOSE:
1601 case SCTP_EXPLICIT_EOR:
1602 case SCTP_AUTO_ASCONF:
1603 case SCTP_DISABLE_FRAGMENTS:
1604 case SCTP_I_WANT_MAPPED_V4_ADDR:
1605 case SCTP_USE_EXT_RCVINFO:
1606 SCTP_INP_RLOCK(inp);
1608 case SCTP_DISABLE_FRAGMENTS:
1609 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1611 case SCTP_I_WANT_MAPPED_V4_ADDR:
1612 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1614 case SCTP_AUTO_ASCONF:
1615 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1616 /* only valid for bound all sockets */
1617 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1619 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1624 case SCTP_EXPLICIT_EOR:
1625 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1628 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1630 case SCTP_USE_EXT_RCVINFO:
1631 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1633 case SCTP_AUTOCLOSE:
1634 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1635 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1641 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1642 error = ENOPROTOOPT;
1643 } /* end switch (sopt->sopt_name) */
1644 if (optname != SCTP_AUTOCLOSE) {
1645 /* make it an "on/off" value */
1648 if (*optsize < sizeof(val)) {
1649 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1653 SCTP_INP_RUNLOCK(inp);
1655 /* return the option value */
1656 *(int *)optval = val;
1657 *optsize = sizeof(val);
1660 case SCTP_GET_PACKET_LOG:
1662 #ifdef SCTP_PACKET_LOGGING
1666 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1667 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1670 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1675 case SCTP_REUSE_PORT:
1679 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1680 /* Can't do this for a 1-m socket */
1684 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1685 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1686 *optsize = sizeof(uint32_t);
1689 case SCTP_PARTIAL_DELIVERY_POINT:
1693 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1694 *value = inp->partial_delivery_point;
1695 *optsize = sizeof(uint32_t);
1698 case SCTP_FRAGMENT_INTERLEAVE:
1702 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1703 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1704 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1705 *value = SCTP_FRAG_LEVEL_2;
1707 *value = SCTP_FRAG_LEVEL_1;
1710 *value = SCTP_FRAG_LEVEL_0;
1712 *optsize = sizeof(uint32_t);
1715 case SCTP_CMT_ON_OFF:
1717 struct sctp_assoc_value *av;
1719 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1720 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
1721 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1723 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1724 SCTP_TCB_UNLOCK(stcb);
1727 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1731 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1732 error = ENOPROTOOPT;
1734 *optsize = sizeof(*av);
1737 /* EY - set socket option for nr_sacks */
1738 case SCTP_NR_SACK_ON_OFF:
1740 struct sctp_assoc_value *av;
1742 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1743 if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off)) {
1744 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1746 av->assoc_value = stcb->asoc.sctp_nr_sack_on_off;
1747 SCTP_TCB_UNLOCK(stcb);
1750 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1754 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1755 error = ENOPROTOOPT;
1757 *optsize = sizeof(*av);
1760 /* JRS - Get socket option for pluggable congestion control */
1761 case SCTP_PLUGGABLE_CC:
1763 struct sctp_assoc_value *av;
1765 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1766 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1768 av->assoc_value = stcb->asoc.congestion_control_module;
1769 SCTP_TCB_UNLOCK(stcb);
1771 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1773 *optsize = sizeof(*av);
1776 case SCTP_GET_ADDR_LEN:
1778 struct sctp_assoc_value *av;
1780 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1783 if (av->assoc_value == AF_INET) {
1784 av->assoc_value = sizeof(struct sockaddr_in);
1789 if (av->assoc_value == AF_INET6) {
1790 av->assoc_value = sizeof(struct sockaddr_in6);
1795 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1797 *optsize = sizeof(*av);
1800 case SCTP_GET_ASSOC_NUMBER:
1802 uint32_t *value, cnt;
1804 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1806 SCTP_INP_RLOCK(inp);
1807 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1810 SCTP_INP_RUNLOCK(inp);
1812 *optsize = sizeof(uint32_t);
1816 case SCTP_GET_ASSOC_ID_LIST:
1818 struct sctp_assoc_ids *ids;
1819 unsigned int at, limit;
1821 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1823 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1824 SCTP_INP_RLOCK(inp);
1825 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1827 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1830 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1834 SCTP_INP_RUNLOCK(inp);
1835 ids->gaids_number_of_ids = at;
1836 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1841 struct sctp_assoc_value *av;
1843 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1844 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1847 av->assoc_value = stcb->asoc.context;
1848 SCTP_TCB_UNLOCK(stcb);
1850 SCTP_INP_RLOCK(inp);
1851 av->assoc_value = inp->sctp_context;
1852 SCTP_INP_RUNLOCK(inp);
1854 *optsize = sizeof(*av);
1859 uint32_t *default_vrfid;
1861 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1862 *default_vrfid = inp->def_vrf_id;
1865 case SCTP_GET_ASOC_VRF:
1867 struct sctp_assoc_value *id;
1869 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1870 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1873 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1876 id->assoc_value = stcb->asoc.vrf_id;
1879 case SCTP_GET_VRF_IDS:
1881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1885 case SCTP_GET_NONCE_VALUES:
1887 struct sctp_get_nonce_values *gnv;
1889 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1890 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1893 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1894 gnv->gn_local_tag = stcb->asoc.my_vtag;
1895 SCTP_TCB_UNLOCK(stcb);
1897 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1900 *optsize = sizeof(*gnv);
1903 case SCTP_DELAYED_SACK:
1905 struct sctp_sack_info *sack;
1907 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1908 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1910 sack->sack_delay = stcb->asoc.delayed_ack;
1911 sack->sack_freq = stcb->asoc.sack_freq;
1912 SCTP_TCB_UNLOCK(stcb);
1914 SCTP_INP_RLOCK(inp);
1915 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
1916 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
1917 SCTP_INP_RUNLOCK(inp);
1919 *optsize = sizeof(*sack);
1923 case SCTP_GET_SNDBUF_USE:
1925 struct sctp_sockstat *ss;
1927 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
1928 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
1931 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
1932 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
1933 stcb->asoc.size_on_all_streams);
1934 SCTP_TCB_UNLOCK(stcb);
1936 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1939 *optsize = sizeof(struct sctp_sockstat);
1942 case SCTP_MAX_BURST:
1946 SCTP_CHECK_AND_CAST(value, optval, uint8_t, *optsize);
1948 SCTP_INP_RLOCK(inp);
1949 *value = inp->sctp_ep.max_burst;
1950 SCTP_INP_RUNLOCK(inp);
1951 *optsize = sizeof(uint8_t);
1956 struct sctp_assoc_value *av;
1959 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1960 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1963 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
1964 SCTP_TCB_UNLOCK(stcb);
1966 SCTP_INP_RLOCK(inp);
1967 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1968 ovh = SCTP_MED_OVERHEAD;
1970 ovh = SCTP_MED_V4_OVERHEAD;
1972 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
1973 av->assoc_value = 0;
1975 av->assoc_value = inp->sctp_frag_point - ovh;
1976 SCTP_INP_RUNLOCK(inp);
1978 *optsize = sizeof(struct sctp_assoc_value);
1981 case SCTP_GET_STAT_LOG:
1982 error = sctp_fill_stat_log(optval, optsize);
1986 struct sctp_event_subscribe *events;
1988 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
1989 memset(events, 0, sizeof(*events));
1990 SCTP_INP_RLOCK(inp);
1991 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
1992 events->sctp_data_io_event = 1;
1994 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
1995 events->sctp_association_event = 1;
1997 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
1998 events->sctp_address_event = 1;
2000 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2001 events->sctp_send_failure_event = 1;
2003 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2004 events->sctp_peer_error_event = 1;
2006 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2007 events->sctp_shutdown_event = 1;
2009 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2010 events->sctp_partial_delivery_event = 1;
2012 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2013 events->sctp_adaptation_layer_event = 1;
2015 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2016 events->sctp_authentication_event = 1;
2018 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2019 events->sctp_sender_dry_event = 1;
2021 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2022 events->sctp_stream_reset_event = 1;
2023 SCTP_INP_RUNLOCK(inp);
2024 *optsize = sizeof(struct sctp_event_subscribe);
2028 case SCTP_ADAPTATION_LAYER:
2032 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2034 SCTP_INP_RLOCK(inp);
2035 *value = inp->sctp_ep.adaptation_layer_indicator;
2036 SCTP_INP_RUNLOCK(inp);
2037 *optsize = sizeof(uint32_t);
2040 case SCTP_SET_INITIAL_DBG_SEQ:
2044 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2045 SCTP_INP_RLOCK(inp);
2046 *value = inp->sctp_ep.initial_sequence_debug;
2047 SCTP_INP_RUNLOCK(inp);
2048 *optsize = sizeof(uint32_t);
2051 case SCTP_GET_LOCAL_ADDR_SIZE:
2055 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2056 SCTP_INP_RLOCK(inp);
2057 *value = sctp_count_max_addresses(inp);
2058 SCTP_INP_RUNLOCK(inp);
2059 *optsize = sizeof(uint32_t);
2062 case SCTP_GET_REMOTE_ADDR_SIZE:
2066 struct sctp_nets *net;
2068 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2069 /* FIXME MT: change to sctp_assoc_value? */
2070 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2074 /* Count the sizes */
2075 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2076 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) ||
2077 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET6)) {
2078 size += sizeof(struct sockaddr_in6);
2079 } else if (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET) {
2080 size += sizeof(struct sockaddr_in);
2086 SCTP_TCB_UNLOCK(stcb);
2087 *value = (uint32_t) size;
2089 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2092 *optsize = sizeof(uint32_t);
2095 case SCTP_GET_PEER_ADDRESSES:
2097 * Get the address information, an array is passed in to
2098 * fill up we pack it.
2102 struct sockaddr_storage *sas;
2103 struct sctp_nets *net;
2104 struct sctp_getaddresses *saddr;
2106 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2107 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2110 left = (*optsize) - sizeof(struct sctp_getaddresses);
2111 *optsize = sizeof(struct sctp_getaddresses);
2112 sas = (struct sockaddr_storage *)&saddr->addr[0];
2114 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2115 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) ||
2116 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET6)) {
2117 cpsz = sizeof(struct sockaddr_in6);
2118 } else if (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET) {
2119 cpsz = sizeof(struct sockaddr_in);
2125 /* not enough room. */
2129 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2130 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
2131 /* Must map the address */
2132 in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
2133 (struct sockaddr_in6 *)sas);
2136 memcpy(sas, &net->ro._l_addr, cpsz);
2140 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2142 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2146 SCTP_TCB_UNLOCK(stcb);
2148 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2153 case SCTP_GET_LOCAL_ADDRESSES:
2155 size_t limit, actual;
2156 struct sockaddr_storage *sas;
2157 struct sctp_getaddresses *saddr;
2159 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2160 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2162 sas = (struct sockaddr_storage *)&saddr->addr[0];
2163 limit = *optsize - sizeof(sctp_assoc_t);
2164 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2166 SCTP_TCB_UNLOCK(stcb);
2168 *optsize = sizeof(struct sockaddr_storage) + actual;
2171 case SCTP_PEER_ADDR_PARAMS:
2173 struct sctp_paddrparams *paddrp;
2174 struct sctp_nets *net;
2176 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2177 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2181 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2184 * We increment here since
2185 * sctp_findassociation_ep_addr() wil do a
2186 * decrement if it finds the stcb as long as
2187 * the locked tcb (last argument) is NOT a
2190 SCTP_INP_INCR_REF(inp);
2191 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddrp->spp_address, &net, NULL, NULL);
2193 SCTP_INP_DECR_REF(inp);
2196 if (stcb && (net == NULL)) {
2197 struct sockaddr *sa;
2199 sa = (struct sockaddr *)&paddrp->spp_address;
2200 if (sa->sa_family == AF_INET) {
2201 struct sockaddr_in *sin;
2203 sin = (struct sockaddr_in *)sa;
2204 if (sin->sin_addr.s_addr) {
2206 SCTP_TCB_UNLOCK(stcb);
2207 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2210 } else if (sa->sa_family == AF_INET6) {
2211 struct sockaddr_in6 *sin6;
2213 sin6 = (struct sockaddr_in6 *)sa;
2214 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2216 SCTP_TCB_UNLOCK(stcb);
2217 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2221 error = EAFNOSUPPORT;
2222 SCTP_TCB_UNLOCK(stcb);
2223 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2228 /* Applys to the specific association */
2229 paddrp->spp_flags = 0;
2233 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2234 ovh = SCTP_MED_OVERHEAD;
2236 ovh = SCTP_MED_V4_OVERHEAD;
2240 paddrp->spp_pathmaxrxt = net->failure_threshold;
2241 paddrp->spp_pathmtu = net->mtu - ovh;
2242 /* get flags for HB */
2243 if (net->dest_state & SCTP_ADDR_NOHB)
2244 paddrp->spp_flags |= SPP_HB_DISABLE;
2246 paddrp->spp_flags |= SPP_HB_ENABLE;
2247 /* get flags for PMTU */
2248 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
2249 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2251 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2254 if (net->ro._l_addr.sin.sin_family == AF_INET) {
2255 paddrp->spp_ipv4_tos = net->tos_flowlabel & 0x000000fc;
2256 paddrp->spp_flags |= SPP_IPV4_TOS;
2260 if (net->ro._l_addr.sin6.sin6_family == AF_INET6) {
2261 paddrp->spp_ipv6_flowlabel = net->tos_flowlabel;
2262 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2267 * No destination so return default
2272 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2273 paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
2275 paddrp->spp_ipv4_tos = stcb->asoc.default_tos & 0x000000fc;
2276 paddrp->spp_flags |= SPP_IPV4_TOS;
2279 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel;
2280 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2282 /* default settings should be these */
2283 if (stcb->asoc.hb_is_disabled == 0) {
2284 paddrp->spp_flags |= SPP_HB_ENABLE;
2286 paddrp->spp_flags |= SPP_HB_DISABLE;
2288 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2289 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
2294 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2297 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2298 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2299 SCTP_TCB_UNLOCK(stcb);
2301 /* Use endpoint defaults */
2302 SCTP_INP_RLOCK(inp);
2303 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2304 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2305 paddrp->spp_assoc_id = (sctp_assoc_t) 0;
2306 /* get inp's default */
2308 paddrp->spp_ipv4_tos = inp->ip_inp.inp.inp_ip_tos;
2309 paddrp->spp_flags |= SPP_IPV4_TOS;
2312 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2313 paddrp->spp_ipv6_flowlabel = ((struct in6pcb *)inp)->in6p_flowinfo;
2314 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2317 /* can't return this */
2318 paddrp->spp_pathmtu = 0;
2320 /* default behavior, no stcb */
2321 paddrp->spp_flags = SPP_PMTUD_ENABLE;
2323 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2324 paddrp->spp_flags |= SPP_HB_ENABLE;
2326 paddrp->spp_flags |= SPP_HB_DISABLE;
2328 SCTP_INP_RUNLOCK(inp);
2330 *optsize = sizeof(struct sctp_paddrparams);
2333 case SCTP_GET_PEER_ADDR_INFO:
2335 struct sctp_paddrinfo *paddri;
2336 struct sctp_nets *net;
2338 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2339 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2343 net = sctp_findnet(stcb, (struct sockaddr *)&paddri->spinfo_address);
2346 * We increment here since
2347 * sctp_findassociation_ep_addr() wil do a
2348 * decrement if it finds the stcb as long as
2349 * the locked tcb (last argument) is NOT a
2352 SCTP_INP_INCR_REF(inp);
2353 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddri->spinfo_address, &net, NULL, NULL);
2355 SCTP_INP_DECR_REF(inp);
2359 if ((stcb) && (net)) {
2360 paddri->spinfo_state = net->dest_state & (SCTP_REACHABLE_MASK | SCTP_ADDR_NOHB);
2361 paddri->spinfo_cwnd = net->cwnd;
2362 paddri->spinfo_srtt = ((net->lastsa >> 2) + net->lastsv) >> 1;
2363 paddri->spinfo_rto = net->RTO;
2364 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2365 SCTP_TCB_UNLOCK(stcb);
2368 SCTP_TCB_UNLOCK(stcb);
2370 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2373 *optsize = sizeof(struct sctp_paddrinfo);
2376 case SCTP_PCB_STATUS:
2378 struct sctp_pcbinfo *spcb;
2380 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2381 sctp_fill_pcbinfo(spcb);
2382 *optsize = sizeof(struct sctp_pcbinfo);
2388 struct sctp_nets *net;
2389 struct sctp_status *sstat;
2391 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2392 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2395 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2400 * I think passing the state is fine since
2401 * sctp_constants.h will be available to the user
2404 sstat->sstat_state = stcb->asoc.state;
2405 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2406 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2407 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2409 * We can't include chunks that have been passed to
2410 * the socket layer. Only things in queue.
2412 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2413 stcb->asoc.cnt_on_all_streams);
2416 sstat->sstat_instrms = stcb->asoc.streamincnt;
2417 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2418 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2419 memcpy(&sstat->sstat_primary.spinfo_address,
2420 &stcb->asoc.primary_destination->ro._l_addr,
2421 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2422 net = stcb->asoc.primary_destination;
2423 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2425 * Again the user can get info from sctp_constants.h
2426 * for what the state of the network is.
2428 sstat->sstat_primary.spinfo_state = net->dest_state & SCTP_REACHABLE_MASK;
2429 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2430 sstat->sstat_primary.spinfo_srtt = net->lastsa;
2431 sstat->sstat_primary.spinfo_rto = net->RTO;
2432 sstat->sstat_primary.spinfo_mtu = net->mtu;
2433 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2434 SCTP_TCB_UNLOCK(stcb);
2435 *optsize = sizeof(*sstat);
2440 struct sctp_rtoinfo *srto;
2442 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2443 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2446 srto->srto_initial = stcb->asoc.initial_rto;
2447 srto->srto_max = stcb->asoc.maxrto;
2448 srto->srto_min = stcb->asoc.minrto;
2449 SCTP_TCB_UNLOCK(stcb);
2451 SCTP_INP_RLOCK(inp);
2452 srto->srto_initial = inp->sctp_ep.initial_rto;
2453 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2454 srto->srto_min = inp->sctp_ep.sctp_minrto;
2455 SCTP_INP_RUNLOCK(inp);
2457 *optsize = sizeof(*srto);
2460 case SCTP_ASSOCINFO:
2462 struct sctp_assocparams *sasoc;
2465 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2466 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2469 oldval = sasoc->sasoc_cookie_life;
2470 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2471 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2472 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2473 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2474 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2475 SCTP_TCB_UNLOCK(stcb);
2477 SCTP_INP_RLOCK(inp);
2478 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2479 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2480 sasoc->sasoc_number_peer_destinations = 0;
2481 sasoc->sasoc_peer_rwnd = 0;
2482 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2483 SCTP_INP_RUNLOCK(inp);
2485 *optsize = sizeof(*sasoc);
2488 case SCTP_DEFAULT_SEND_PARAM:
2490 struct sctp_sndrcvinfo *s_info;
2492 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2493 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2496 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2497 SCTP_TCB_UNLOCK(stcb);
2499 SCTP_INP_RLOCK(inp);
2500 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2501 SCTP_INP_RUNLOCK(inp);
2503 *optsize = sizeof(*s_info);
2508 struct sctp_initmsg *sinit;
2510 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2511 SCTP_INP_RLOCK(inp);
2512 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2513 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2514 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2515 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2516 SCTP_INP_RUNLOCK(inp);
2517 *optsize = sizeof(*sinit);
2520 case SCTP_PRIMARY_ADDR:
2521 /* we allow a "get" operation on this */
2523 struct sctp_setprim *ssp;
2525 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2526 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2529 /* simply copy out the sockaddr_storage... */
2533 if (len > stcb->asoc.primary_destination->ro._l_addr.sa.sa_len)
2534 len = stcb->asoc.primary_destination->ro._l_addr.sa.sa_len;
2536 memcpy(&ssp->ssp_addr,
2537 &stcb->asoc.primary_destination->ro._l_addr,
2539 SCTP_TCB_UNLOCK(stcb);
2541 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2544 *optsize = sizeof(*ssp);
2548 case SCTP_HMAC_IDENT:
2550 struct sctp_hmacalgo *shmac;
2551 sctp_hmaclist_t *hmaclist;
2555 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2557 SCTP_INP_RLOCK(inp);
2558 hmaclist = inp->sctp_ep.local_hmacs;
2559 if (hmaclist == NULL) {
2560 /* no HMACs to return */
2561 *optsize = sizeof(*shmac);
2562 SCTP_INP_RUNLOCK(inp);
2565 /* is there room for all of the hmac ids? */
2566 size = sizeof(*shmac) + (hmaclist->num_algo *
2567 sizeof(shmac->shmac_idents[0]));
2568 if ((size_t)(*optsize) < size) {
2569 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2571 SCTP_INP_RUNLOCK(inp);
2574 /* copy in the list */
2575 shmac->shmac_number_of_idents = hmaclist->num_algo;
2576 for (i = 0; i < hmaclist->num_algo; i++) {
2577 shmac->shmac_idents[i] = hmaclist->hmac[i];
2579 SCTP_INP_RUNLOCK(inp);
2583 case SCTP_AUTH_ACTIVE_KEY:
2585 struct sctp_authkeyid *scact;
2587 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2588 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2591 /* get the active key on the assoc */
2592 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2593 SCTP_TCB_UNLOCK(stcb);
2595 /* get the endpoint active key */
2596 SCTP_INP_RLOCK(inp);
2597 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2598 SCTP_INP_RUNLOCK(inp);
2600 *optsize = sizeof(*scact);
2603 case SCTP_LOCAL_AUTH_CHUNKS:
2605 struct sctp_authchunks *sac;
2606 sctp_auth_chklist_t *chklist = NULL;
2609 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2610 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2613 /* get off the assoc */
2614 chklist = stcb->asoc.local_auth_chunks;
2615 /* is there enough space? */
2616 size = sctp_auth_get_chklist_size(chklist);
2617 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2619 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2621 /* copy in the chunks */
2622 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2624 SCTP_TCB_UNLOCK(stcb);
2626 /* get off the endpoint */
2627 SCTP_INP_RLOCK(inp);
2628 chklist = inp->sctp_ep.local_auth_chunks;
2629 /* is there enough space? */
2630 size = sctp_auth_get_chklist_size(chklist);
2631 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2633 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2635 /* copy in the chunks */
2636 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2638 SCTP_INP_RUNLOCK(inp);
2640 *optsize = sizeof(struct sctp_authchunks) + size;
2643 case SCTP_PEER_AUTH_CHUNKS:
2645 struct sctp_authchunks *sac;
2646 sctp_auth_chklist_t *chklist = NULL;
2649 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2650 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2653 /* get off the assoc */
2654 chklist = stcb->asoc.peer_auth_chunks;
2655 /* is there enough space? */
2656 size = sctp_auth_get_chklist_size(chklist);
2657 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2659 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2661 /* copy in the chunks */
2662 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2664 SCTP_TCB_UNLOCK(stcb);
2666 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2669 *optsize = sizeof(struct sctp_authchunks) + size;
2675 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
2676 error = ENOPROTOOPT;
2679 } /* end switch (sopt->sopt_name) */
2684 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
2689 struct sctp_tcb *stcb = NULL;
2690 struct sctp_inpcb *inp = NULL;
2693 if (optval == NULL) {
2694 SCTP_PRINTF("optval is NULL\n");
2695 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2698 inp = (struct sctp_inpcb *)so->so_pcb;
2700 SCTP_PRINTF("inp is NULL?\n");
2701 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2704 vrf_id = inp->def_vrf_id;
2709 case SCTP_AUTOCLOSE:
2710 case SCTP_AUTO_ASCONF:
2711 case SCTP_EXPLICIT_EOR:
2712 case SCTP_DISABLE_FRAGMENTS:
2713 case SCTP_USE_EXT_RCVINFO:
2714 case SCTP_I_WANT_MAPPED_V4_ADDR:
2715 /* copy in the option value */
2716 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
2721 case SCTP_DISABLE_FRAGMENTS:
2722 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
2724 case SCTP_AUTO_ASCONF:
2726 * NOTE: we don't really support this flag
2728 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
2729 /* only valid for bound all sockets */
2730 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
2732 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2736 case SCTP_EXPLICIT_EOR:
2737 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
2739 case SCTP_USE_EXT_RCVINFO:
2740 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
2742 case SCTP_I_WANT_MAPPED_V4_ADDR:
2743 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2744 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
2746 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2751 set_opt = SCTP_PCB_FLAGS_NODELAY;
2753 case SCTP_AUTOCLOSE:
2754 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2755 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
2756 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2759 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
2761 * The value is in ticks. Note this does not effect
2762 * old associations, only new ones.
2764 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
2767 SCTP_INP_WLOCK(inp);
2769 sctp_feature_on(inp, set_opt);
2771 sctp_feature_off(inp, set_opt);
2773 SCTP_INP_WUNLOCK(inp);
2775 case SCTP_REUSE_PORT:
2777 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
2778 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
2779 /* Can't set it after we are bound */
2783 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
2784 /* Can't do this for a 1-m socket */
2789 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
2791 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
2794 case SCTP_PARTIAL_DELIVERY_POINT:
2798 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
2799 if (*value > SCTP_SB_LIMIT_RCV(so)) {
2800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2804 inp->partial_delivery_point = *value;
2807 case SCTP_FRAGMENT_INTERLEAVE:
2808 /* not yet until we re-write sctp_recvmsg() */
2812 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
2813 if (*level == SCTP_FRAG_LEVEL_2) {
2814 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
2815 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
2816 } else if (*level == SCTP_FRAG_LEVEL_1) {
2817 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
2818 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
2819 } else if (*level == SCTP_FRAG_LEVEL_0) {
2820 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
2821 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
2824 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2829 case SCTP_CMT_ON_OFF:
2831 struct sctp_assoc_value *av;
2833 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
2834 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
2835 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2837 stcb->asoc.sctp_cmt_on_off = (uint8_t) av->assoc_value;
2838 SCTP_TCB_UNLOCK(stcb);
2840 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2844 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
2845 error = ENOPROTOOPT;
2849 /* EY nr_sack_on_off socket option */
2850 case SCTP_NR_SACK_ON_OFF:
2852 struct sctp_assoc_value *av;
2854 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
2855 if (SCTP_BASE_SYSCTL(sctp_nr_sack_on_off)) {
2856 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2858 stcb->asoc.sctp_nr_sack_on_off = (uint8_t) av->assoc_value;
2859 SCTP_TCB_UNLOCK(stcb);
2861 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2865 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
2866 error = ENOPROTOOPT;
2870 /* JRS - Set socket option for pluggable congestion control */
2871 case SCTP_PLUGGABLE_CC:
2873 struct sctp_assoc_value *av;
2875 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
2876 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2878 switch (av->assoc_value) {
2880 * JRS - Standard TCP congestion
2883 case SCTP_CC_RFC2581:
2885 stcb->asoc.congestion_control_module = SCTP_CC_RFC2581;
2886 stcb->asoc.cc_functions.sctp_set_initial_cc_param = &sctp_set_initial_cc_param;
2887 stcb->asoc.cc_functions.sctp_cwnd_update_after_sack = &sctp_cwnd_update_after_sack;
2888 stcb->asoc.cc_functions.sctp_cwnd_update_after_fr = &sctp_cwnd_update_after_fr;
2889 stcb->asoc.cc_functions.sctp_cwnd_update_after_timeout = &sctp_cwnd_update_after_timeout;
2890 stcb->asoc.cc_functions.sctp_cwnd_update_after_ecn_echo = &sctp_cwnd_update_after_ecn_echo;
2891 stcb->asoc.cc_functions.sctp_cwnd_update_after_packet_dropped = &sctp_cwnd_update_after_packet_dropped;
2892 stcb->asoc.cc_functions.sctp_cwnd_update_after_output = &sctp_cwnd_update_after_output;
2893 stcb->asoc.cc_functions.sctp_cwnd_update_after_fr_timer = &sctp_cwnd_update_after_fr_timer;
2894 SCTP_TCB_UNLOCK(stcb);
2898 * JRS - High Speed TCP congestion
2903 stcb->asoc.congestion_control_module = SCTP_CC_HSTCP;
2904 stcb->asoc.cc_functions.sctp_set_initial_cc_param = &sctp_set_initial_cc_param;
2905 stcb->asoc.cc_functions.sctp_cwnd_update_after_sack = &sctp_hs_cwnd_update_after_sack;
2906 stcb->asoc.cc_functions.sctp_cwnd_update_after_fr = &sctp_hs_cwnd_update_after_fr;
2907 stcb->asoc.cc_functions.sctp_cwnd_update_after_timeout = &sctp_cwnd_update_after_timeout;
2908 stcb->asoc.cc_functions.sctp_cwnd_update_after_ecn_echo = &sctp_cwnd_update_after_ecn_echo;
2909 stcb->asoc.cc_functions.sctp_cwnd_update_after_packet_dropped = &sctp_cwnd_update_after_packet_dropped;
2910 stcb->asoc.cc_functions.sctp_cwnd_update_after_output = &sctp_cwnd_update_after_output;
2911 stcb->asoc.cc_functions.sctp_cwnd_update_after_fr_timer = &sctp_cwnd_update_after_fr_timer;
2912 SCTP_TCB_UNLOCK(stcb);
2915 /* JRS - HTCP congestion control */
2918 stcb->asoc.congestion_control_module = SCTP_CC_HTCP;
2919 stcb->asoc.cc_functions.sctp_set_initial_cc_param = &sctp_htcp_set_initial_cc_param;
2920 stcb->asoc.cc_functions.sctp_cwnd_update_after_sack = &sctp_htcp_cwnd_update_after_sack;
2921 stcb->asoc.cc_functions.sctp_cwnd_update_after_fr = &sctp_htcp_cwnd_update_after_fr;
2922 stcb->asoc.cc_functions.sctp_cwnd_update_after_timeout = &sctp_htcp_cwnd_update_after_timeout;
2923 stcb->asoc.cc_functions.sctp_cwnd_update_after_ecn_echo = &sctp_htcp_cwnd_update_after_ecn_echo;
2924 stcb->asoc.cc_functions.sctp_cwnd_update_after_packet_dropped = &sctp_cwnd_update_after_packet_dropped;
2925 stcb->asoc.cc_functions.sctp_cwnd_update_after_output = &sctp_cwnd_update_after_output;
2926 stcb->asoc.cc_functions.sctp_cwnd_update_after_fr_timer = &sctp_htcp_cwnd_update_after_fr_timer;
2927 SCTP_TCB_UNLOCK(stcb);
2931 * JRS - All other values are
2936 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2938 SCTP_TCB_UNLOCK(stcb);
2943 switch (av->assoc_value) {
2944 case SCTP_CC_RFC2581:
2947 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
2950 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2957 case SCTP_CLR_STAT_LOG:
2958 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
2963 struct sctp_assoc_value *av;
2965 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
2966 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2969 stcb->asoc.context = av->assoc_value;
2970 SCTP_TCB_UNLOCK(stcb);
2972 SCTP_INP_WLOCK(inp);
2973 inp->sctp_context = av->assoc_value;
2974 SCTP_INP_WUNLOCK(inp);
2980 uint32_t *default_vrfid;
2982 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
2983 if (*default_vrfid > SCTP_MAX_VRF_ID) {
2984 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2988 inp->def_vrf_id = *default_vrfid;
2991 case SCTP_DEL_VRF_ID:
2993 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
2997 case SCTP_ADD_VRF_ID:
2999 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3003 case SCTP_DELAYED_SACK:
3005 struct sctp_sack_info *sack;
3007 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
3008 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
3009 if (sack->sack_delay) {
3010 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
3011 sack->sack_delay = SCTP_MAX_SACK_DELAY;
3014 if (sack->sack_delay) {
3015 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
3016 sack->sack_delay = TICKS_TO_MSEC(1);
3018 stcb->asoc.delayed_ack = sack->sack_delay;
3020 if (sack->sack_freq) {
3021 stcb->asoc.sack_freq = sack->sack_freq;
3023 SCTP_TCB_UNLOCK(stcb);
3025 SCTP_INP_WLOCK(inp);
3026 if (sack->sack_delay) {
3027 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
3028 sack->sack_delay = TICKS_TO_MSEC(1);
3030 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
3032 if (sack->sack_freq) {
3033 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
3035 SCTP_INP_WUNLOCK(inp);
3039 case SCTP_AUTH_CHUNK:
3041 struct sctp_authchunk *sauth;
3043 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
3045 SCTP_INP_WLOCK(inp);
3046 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
3047 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3050 SCTP_INP_WUNLOCK(inp);
3055 struct sctp_authkey *sca;
3056 struct sctp_keyhead *shared_keys;
3057 sctp_sharedkey_t *shared_key;
3058 sctp_key_t *key = NULL;
3061 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
3062 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
3063 size = optsize - sizeof(*sca);
3066 /* set it on the assoc */
3067 shared_keys = &stcb->asoc.shared_keys;
3068 /* clear the cached keys for this key id */
3069 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3071 * create the new shared key and
3075 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3077 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3079 SCTP_TCB_UNLOCK(stcb);
3083 shared_key = sctp_alloc_sharedkey();
3084 if (shared_key == NULL) {
3086 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3088 SCTP_TCB_UNLOCK(stcb);
3091 shared_key->key = key;
3092 shared_key->keyid = sca->sca_keynumber;
3093 error = sctp_insert_sharedkey(shared_keys, shared_key);
3094 SCTP_TCB_UNLOCK(stcb);
3096 /* set it on the endpoint */
3097 SCTP_INP_WLOCK(inp);
3098 shared_keys = &inp->sctp_ep.shared_keys;
3100 * clear the cached keys on all assocs for
3103 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
3105 * create the new shared key and
3109 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3111 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3113 SCTP_INP_WUNLOCK(inp);
3117 shared_key = sctp_alloc_sharedkey();
3118 if (shared_key == NULL) {
3120 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3122 SCTP_INP_WUNLOCK(inp);
3125 shared_key->key = key;
3126 shared_key->keyid = sca->sca_keynumber;
3127 error = sctp_insert_sharedkey(shared_keys, shared_key);
3128 SCTP_INP_WUNLOCK(inp);
3132 case SCTP_HMAC_IDENT:
3134 struct sctp_hmacalgo *shmac;
3135 sctp_hmaclist_t *hmaclist;
3141 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
3142 if (optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) {
3143 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3147 hmaclist = sctp_alloc_hmaclist(shmac->shmac_number_of_idents);
3148 if (hmaclist == NULL) {
3149 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3153 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
3154 hmacid = shmac->shmac_idents[i];
3155 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
3156 /* invalid HMACs were found */ ;
3157 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3159 sctp_free_hmaclist(hmaclist);
3160 goto sctp_set_hmac_done;
3164 for (i = 0; i < hmaclist->num_algo; i++) {
3165 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
3166 /* already in list */
3171 sctp_free_hmaclist(hmaclist);
3172 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3176 /* set it on the endpoint */
3177 SCTP_INP_WLOCK(inp);
3178 if (inp->sctp_ep.local_hmacs)
3179 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
3180 inp->sctp_ep.local_hmacs = hmaclist;
3181 SCTP_INP_WUNLOCK(inp);
3185 case SCTP_AUTH_ACTIVE_KEY:
3187 struct sctp_authkeyid *scact;
3189 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid,
3191 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
3193 /* set the active key on the right place */
3195 /* set the active key on the assoc */
3196 if (sctp_auth_setactivekey(stcb,
3197 scact->scact_keynumber)) {
3198 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
3199 SCTP_FROM_SCTP_USRREQ,
3203 SCTP_TCB_UNLOCK(stcb);
3205 /* set the active key on the endpoint */
3206 SCTP_INP_WLOCK(inp);
3207 if (sctp_auth_setactivekey_ep(inp,
3208 scact->scact_keynumber)) {
3209 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
3210 SCTP_FROM_SCTP_USRREQ,
3214 SCTP_INP_WUNLOCK(inp);
3218 case SCTP_AUTH_DELETE_KEY:
3220 struct sctp_authkeyid *scdel;
3222 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid,
3224 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
3226 /* delete the key from the right place */
3228 if (sctp_delete_sharedkey(stcb,
3229 scdel->scact_keynumber)) {
3230 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
3231 SCTP_FROM_SCTP_USRREQ,
3235 SCTP_TCB_UNLOCK(stcb);
3237 SCTP_INP_WLOCK(inp);
3238 if (sctp_delete_sharedkey_ep(inp,
3239 scdel->scact_keynumber)) {
3240 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
3241 SCTP_FROM_SCTP_USRREQ,
3245 SCTP_INP_WUNLOCK(inp);
3249 case SCTP_AUTH_DEACTIVATE_KEY:
3251 struct sctp_authkeyid *keyid;
3253 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid,
3255 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
3257 /* deactivate the key from the right place */
3259 if (sctp_deact_sharedkey(stcb,
3260 keyid->scact_keynumber)) {
3261 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
3262 SCTP_FROM_SCTP_USRREQ,
3266 SCTP_TCB_UNLOCK(stcb);
3268 SCTP_INP_WLOCK(inp);
3269 if (sctp_deact_sharedkey_ep(inp,
3270 keyid->scact_keynumber)) {
3271 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
3272 SCTP_FROM_SCTP_USRREQ,
3276 SCTP_INP_WUNLOCK(inp);
3281 case SCTP_RESET_STREAMS:
3283 struct sctp_stream_reset *strrst;
3284 uint8_t send_in = 0, send_tsn = 0, send_out = 0,
3286 uint16_t addstrmcnt = 0;
3289 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_stream_reset, optsize);
3290 SCTP_FIND_STCB(inp, stcb, strrst->strrst_assoc_id);
3293 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3297 if (stcb->asoc.peer_supports_strreset == 0) {
3299 * Peer does not support it, we return
3300 * protocol not supported since this is true
3301 * for this feature and this peer, not the
3302 * socket request in general.
3304 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPROTONOSUPPORT);
3305 error = EPROTONOSUPPORT;
3306 SCTP_TCB_UNLOCK(stcb);
3309 if (stcb->asoc.stream_reset_outstanding) {
3310 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
3312 SCTP_TCB_UNLOCK(stcb);
3315 if (strrst->strrst_flags == SCTP_RESET_LOCAL_RECV) {
3317 } else if (strrst->strrst_flags == SCTP_RESET_LOCAL_SEND) {
3319 } else if (strrst->strrst_flags == SCTP_RESET_BOTH) {
3322 } else if (strrst->strrst_flags == SCTP_RESET_TSN) {
3324 } else if (strrst->strrst_flags == SCTP_RESET_ADD_STREAMS) {
3328 /* We can't do that and add streams */
3332 if (stcb->asoc.stream_reset_outstanding) {
3337 /* We allocate here */
3338 addstrmcnt = strrst->strrst_num_streams;
3339 if ((int)(addstrmcnt + stcb->asoc.streamoutcnt) > 0xffff) {
3340 /* You can't have more than 64k */
3344 if ((stcb->asoc.strm_realoutsize - stcb->asoc.streamoutcnt) < addstrmcnt) {
3345 /* Need to allocate more */
3346 struct sctp_stream_out *oldstream;
3347 struct sctp_stream_queue_pending *sp;
3350 oldstream = stcb->asoc.strmout;
3352 SCTP_MALLOC(stcb->asoc.strmout, struct sctp_stream_out *,
3353 ((stcb->asoc.streamoutcnt + addstrmcnt) * sizeof(struct sctp_stream_out)),
3355 if (stcb->asoc.strmout == NULL) {
3356 stcb->asoc.strmout = oldstream;
3361 * Ok now we proceed with copying
3362 * the old out stuff and
3363 * initializing the new stuff.
3365 SCTP_TCB_SEND_LOCK(stcb);
3366 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
3367 TAILQ_INIT(&stcb->asoc.strmout[i].outqueue);
3368 stcb->asoc.strmout[i].next_sequence_sent = oldstream[i].next_sequence_sent;
3369 stcb->asoc.strmout[i].last_msg_incomplete = oldstream[i].last_msg_incomplete;
3370 stcb->asoc.strmout[i].stream_no = i;
3371 if (oldstream[i].next_spoke.tqe_next) {
3372 sctp_remove_from_wheel(stcb, &stcb->asoc, &oldstream[i], 1);
3373 stcb->asoc.strmout[i].next_spoke.tqe_next = NULL;
3374 stcb->asoc.strmout[i].next_spoke.tqe_prev = NULL;
3377 /* not on out wheel */
3378 stcb->asoc.strmout[i].next_spoke.tqe_next = NULL;
3379 stcb->asoc.strmout[i].next_spoke.tqe_prev = NULL;
3383 * now anything on those
3386 while (TAILQ_EMPTY(&oldstream[i].outqueue) == 0) {
3387 sp = TAILQ_FIRST(&oldstream[i].outqueue);
3388 TAILQ_REMOVE(&oldstream[i].outqueue, sp, next);
3389 TAILQ_INSERT_TAIL(&stcb->asoc.strmout[i].outqueue, sp, next);
3391 /* Did we disrupt the wheel? */
3393 sctp_insert_on_wheel(stcb,
3395 &stcb->asoc.strmout[i],
3399 * Now move assoc pointers
3402 if (stcb->asoc.last_out_stream == &oldstream[i]) {
3403 stcb->asoc.last_out_stream = &stcb->asoc.strmout[i];
3405 if (stcb->asoc.locked_on_sending == &oldstream[i]) {
3406 stcb->asoc.locked_on_sending = &stcb->asoc.strmout[i];
3409 /* now the new streams */
3410 for (i = stcb->asoc.streamoutcnt; i < (stcb->asoc.streamoutcnt + addstrmcnt); i++) {
3411 stcb->asoc.strmout[i].next_sequence_sent = 0x0;
3412 TAILQ_INIT(&stcb->asoc.strmout[i].outqueue);
3413 stcb->asoc.strmout[i].stream_no = i;
3414 stcb->asoc.strmout[i].last_msg_incomplete = 0;
3415 stcb->asoc.strmout[i].next_spoke.tqe_next = NULL;
3416 stcb->asoc.strmout[i].next_spoke.tqe_prev = NULL;
3418 stcb->asoc.strm_realoutsize = stcb->asoc.streamoutcnt + addstrmcnt;
3419 SCTP_FREE(oldstream, SCTP_M_STRMO);
3421 SCTP_TCB_SEND_UNLOCK(stcb);
3424 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3426 SCTP_TCB_UNLOCK(stcb);
3429 for (i = 0; i < strrst->strrst_num_streams; i++) {
3432 (strrst->strrst_list[i] > stcb->asoc.streamincnt)) {
3433 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3438 (strrst->strrst_list[i] > stcb->asoc.streamoutcnt)) {
3439 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3447 SCTP_TCB_UNLOCK(stcb);
3450 error = sctp_send_str_reset_req(stcb, strrst->strrst_num_streams,
3451 strrst->strrst_list,
3452 send_out, (stcb->asoc.str_reset_seq_in - 3),
3453 send_in, send_tsn, addstream, addstrmcnt);
3455 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
3456 SCTP_TCB_UNLOCK(stcb);
3460 case SCTP_CONNECT_X:
3461 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
3462 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3466 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
3469 case SCTP_CONNECT_X_DELAYED:
3470 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
3471 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3475 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
3478 case SCTP_CONNECT_X_COMPLETE:
3480 struct sockaddr *sa;
3481 struct sctp_nets *net;
3483 /* FIXME MT: check correct? */
3484 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
3487 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
3488 SCTP_INP_RLOCK(inp);
3489 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3491 SCTP_TCB_LOCK(stcb);
3492 net = sctp_findnet(stcb, sa);
3494 SCTP_INP_RUNLOCK(inp);
3497 * We increment here since
3498 * sctp_findassociation_ep_addr() wil do a
3499 * decrement if it finds the stcb as long as
3500 * the locked tcb (last argument) is NOT a
3503 SCTP_INP_INCR_REF(inp);
3504 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
3506 SCTP_INP_DECR_REF(inp);
3511 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3515 if (stcb->asoc.delayed_connection == 1) {
3516 stcb->asoc.delayed_connection = 0;
3517 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
3518 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
3519 stcb->asoc.primary_destination,
3520 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
3521 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
3524 * already expired or did not use delayed
3527 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
3530 SCTP_TCB_UNLOCK(stcb);
3533 case SCTP_MAX_BURST:
3537 SCTP_CHECK_AND_CAST(burst, optval, uint8_t, optsize);
3539 SCTP_INP_WLOCK(inp);
3541 inp->sctp_ep.max_burst = *burst;
3543 SCTP_INP_WUNLOCK(inp);
3548 struct sctp_assoc_value *av;
3551 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3552 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3554 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3555 ovh = SCTP_MED_OVERHEAD;
3557 ovh = SCTP_MED_V4_OVERHEAD;
3560 if (av->assoc_value) {
3561 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
3563 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
3565 SCTP_TCB_UNLOCK(stcb);
3567 SCTP_INP_WLOCK(inp);
3569 * FIXME MT: I think this is not in tune
3572 if (av->assoc_value) {
3573 inp->sctp_frag_point = (av->assoc_value + ovh);
3575 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
3577 SCTP_INP_WUNLOCK(inp);
3583 struct sctp_event_subscribe *events;
3585 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
3587 SCTP_INP_WLOCK(inp);
3588 if (events->sctp_data_io_event) {
3589 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
3591 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
3594 if (events->sctp_association_event) {
3595 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
3597 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
3600 if (events->sctp_address_event) {
3601 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
3603 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
3606 if (events->sctp_send_failure_event) {
3607 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
3609 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
3612 if (events->sctp_peer_error_event) {
3613 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
3615 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
3618 if (events->sctp_shutdown_event) {
3619 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
3621 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
3624 if (events->sctp_partial_delivery_event) {
3625 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
3627 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
3630 if (events->sctp_adaptation_layer_event) {
3631 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
3633 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
3636 if (events->sctp_authentication_event) {
3637 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
3639 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
3642 if (events->sctp_sender_dry_event) {
3643 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
3644 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3645 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3646 stcb = LIST_FIRST(&inp->sctp_asoc_list);
3648 SCTP_TCB_LOCK(stcb);
3651 TAILQ_EMPTY(&stcb->asoc.send_queue) &&
3652 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
3653 (stcb->asoc.stream_queue_cnt == 0)) {
3654 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
3657 SCTP_TCB_UNLOCK(stcb);
3661 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
3664 if (events->sctp_stream_reset_event) {
3665 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
3667 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
3669 SCTP_INP_WUNLOCK(inp);
3673 case SCTP_ADAPTATION_LAYER:
3675 struct sctp_setadaptation *adap_bits;
3677 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
3678 SCTP_INP_WLOCK(inp);
3679 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
3680 SCTP_INP_WUNLOCK(inp);
3684 case SCTP_SET_INITIAL_DBG_SEQ:
3688 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
3689 SCTP_INP_WLOCK(inp);
3690 inp->sctp_ep.initial_sequence_debug = *vvv;
3691 SCTP_INP_WUNLOCK(inp);
3695 case SCTP_DEFAULT_SEND_PARAM:
3697 struct sctp_sndrcvinfo *s_info;
3699 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
3700 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
3703 if (s_info->sinfo_stream <= stcb->asoc.streamoutcnt) {
3704 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
3706 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3709 SCTP_TCB_UNLOCK(stcb);
3711 SCTP_INP_WLOCK(inp);
3712 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
3713 SCTP_INP_WUNLOCK(inp);
3717 case SCTP_PEER_ADDR_PARAMS:
3718 /* Applys to the specific association */
3720 struct sctp_paddrparams *paddrp;
3721 struct sctp_nets *net;
3723 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
3724 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
3727 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
3730 * We increment here since
3731 * sctp_findassociation_ep_addr() wil do a
3732 * decrement if it finds the stcb as long as
3733 * the locked tcb (last argument) is NOT a
3736 SCTP_INP_INCR_REF(inp);
3737 stcb = sctp_findassociation_ep_addr(&inp,
3738 (struct sockaddr *)&paddrp->spp_address,
3741 SCTP_INP_DECR_REF(inp);
3744 if (stcb && (net == NULL)) {
3745 struct sockaddr *sa;
3747 sa = (struct sockaddr *)&paddrp->spp_address;
3748 if (sa->sa_family == AF_INET) {
3749 struct sockaddr_in *sin;
3751 sin = (struct sockaddr_in *)sa;
3752 if (sin->sin_addr.s_addr) {
3753 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3754 SCTP_TCB_UNLOCK(stcb);
3758 } else if (sa->sa_family == AF_INET6) {
3759 struct sockaddr_in6 *sin6;
3761 sin6 = (struct sockaddr_in6 *)sa;
3762 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3763 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3764 SCTP_TCB_UNLOCK(stcb);
3769 error = EAFNOSUPPORT;
3770 SCTP_TCB_UNLOCK(stcb);
3771 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3776 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
3778 SCTP_TCB_UNLOCK(stcb);
3779 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3782 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
3784 SCTP_TCB_UNLOCK(stcb);
3785 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3789 /************************TCB SPECIFIC SET ******************/
3791 * do we change the timer for HB, we run
3796 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3797 ovh = SCTP_MED_OVERHEAD;
3799 ovh = SCTP_MED_V4_OVERHEAD;
3802 if (paddrp->spp_hbinterval)
3803 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
3804 else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
3805 stcb->asoc.heart_beat_delay = 0;
3807 /* network sets ? */
3809 /************************NET SPECIFIC SET ******************/
3810 if (paddrp->spp_flags & SPP_HB_DEMAND) {
3812 if (sctp_send_hb(stcb, 1, net) < 0) {
3813 /* asoc destroyed */
3814 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3819 if (paddrp->spp_flags & SPP_HB_DISABLE) {
3820 net->dest_state |= SCTP_ADDR_NOHB;
3822 if (paddrp->spp_flags & SPP_HB_ENABLE) {
3823 net->dest_state &= ~SCTP_ADDR_NOHB;
3825 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
3826 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
3827 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
3828 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
3830 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
3831 net->mtu = paddrp->spp_pathmtu + ovh;
3832 if (net->mtu < stcb->asoc.smallest_mtu) {
3833 #ifdef SCTP_PRINT_FOR_B_AND_M
3834 SCTP_PRINTF("SCTP_PMTU_DISABLE calls sctp_pathmtu_adjustment:%d\n",
3837 sctp_pathmtu_adjustment(inp, stcb, net, net->mtu);
3841 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
3842 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
3843 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
3846 if (paddrp->spp_pathmaxrxt)
3847 net->failure_threshold = paddrp->spp_pathmaxrxt;
3849 if (paddrp->spp_flags & SPP_IPV4_TOS) {
3850 if (net->ro._l_addr.sin.sin_family == AF_INET) {
3851 net->tos_flowlabel = paddrp->spp_ipv4_tos & 0x000000fc;
3856 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
3857 if (net->ro._l_addr.sin6.sin6_family == AF_INET6) {
3858 net->tos_flowlabel = paddrp->spp_ipv6_flowlabel;
3863 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
3864 if (paddrp->spp_pathmaxrxt)
3865 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
3867 if (paddrp->spp_flags & SPP_HB_ENABLE) {
3868 /* Turn back on the timer */
3869 stcb->asoc.hb_is_disabled = 0;
3870 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
3872 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
3873 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3874 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
3875 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
3876 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
3878 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
3879 net->mtu = paddrp->spp_pathmtu + ovh;
3880 if (net->mtu < stcb->asoc.smallest_mtu) {
3881 #ifdef SCTP_PRINT_FOR_B_AND_M
3882 SCTP_PRINTF("SCTP_PMTU_DISABLE calls sctp_pathmtu_adjustment:%d\n",
3885 sctp_pathmtu_adjustment(inp, stcb, net, net->mtu);
3890 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
3891 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3892 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
3893 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
3897 if (paddrp->spp_flags & SPP_HB_DISABLE) {
3898 int cnt_of_unconf = 0;
3899 struct sctp_nets *lnet;
3901 stcb->asoc.hb_is_disabled = 1;
3902 TAILQ_FOREACH(lnet, &stcb->asoc.nets, sctp_next) {
3903 if (lnet->dest_state & SCTP_ADDR_UNCONFIRMED) {
3908 * stop the timer ONLY if we
3909 * have no unconfirmed
3912 if (cnt_of_unconf == 0) {
3913 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3914 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
3915 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
3919 if (paddrp->spp_flags & SPP_HB_ENABLE) {
3920 /* start up the timer. */
3921 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3922 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
3926 if (paddrp->spp_flags & SPP_IPV4_TOS)
3927 stcb->asoc.default_tos = paddrp->spp_ipv4_tos & 0x000000fc;
3930 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL)
3931 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel;
3935 SCTP_TCB_UNLOCK(stcb);
3937 /************************NO TCB, SET TO default stuff ******************/
3938 SCTP_INP_WLOCK(inp);
3940 * For the TOS/FLOWLABEL stuff you set it
3941 * with the options on the socket
3943 if (paddrp->spp_pathmaxrxt) {
3944 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
3946 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
3947 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
3948 else if (paddrp->spp_hbinterval) {
3949 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
3950 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
3951 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
3953 if (paddrp->spp_flags & SPP_HB_ENABLE) {
3954 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
3956 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
3957 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
3959 SCTP_INP_WUNLOCK(inp);
3965 struct sctp_rtoinfo *srto;
3966 uint32_t new_init, new_min, new_max;
3968 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
3969 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
3972 if (srto->srto_initial)
3973 new_init = srto->srto_initial;
3975 new_init = stcb->asoc.initial_rto;
3977 new_max = srto->srto_max;
3979 new_max = stcb->asoc.maxrto;
3981 new_min = srto->srto_min;
3983 new_min = stcb->asoc.minrto;
3984 if ((new_min <= new_init) && (new_init <= new_max)) {
3985 stcb->asoc.initial_rto = new_init;
3986 stcb->asoc.maxrto = new_max;
3987 stcb->asoc.minrto = new_min;
3989 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3992 SCTP_TCB_UNLOCK(stcb);
3994 SCTP_INP_WLOCK(inp);
3995 if (srto->srto_initial)
3996 new_init = srto->srto_initial;
3998 new_init = inp->sctp_ep.initial_rto;
4000 new_max = srto->srto_max;
4002 new_max = inp->sctp_ep.sctp_maxrto;
4004 new_min = srto->srto_min;
4006 new_min = inp->sctp_ep.sctp_minrto;
4007 if ((new_min <= new_init) && (new_init <= new_max)) {
4008 inp->sctp_ep.initial_rto = new_init;
4009 inp->sctp_ep.sctp_maxrto = new_max;
4010 inp->sctp_ep.sctp_minrto = new_min;
4012 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4015 SCTP_INP_WUNLOCK(inp);
4019 case SCTP_ASSOCINFO:
4021 struct sctp_assocparams *sasoc;
4023 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
4024 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
4025 if (sasoc->sasoc_cookie_life) {
4026 /* boundary check the cookie life */
4027 if (sasoc->sasoc_cookie_life < 1000)
4028 sasoc->sasoc_cookie_life = 1000;
4029 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
4030 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
4034 if (sasoc->sasoc_asocmaxrxt)
4035 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
4036 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
4037 sasoc->sasoc_peer_rwnd = 0;
4038 sasoc->sasoc_local_rwnd = 0;
4039 if (sasoc->sasoc_cookie_life) {
4040 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
4042 SCTP_TCB_UNLOCK(stcb);
4044 SCTP_INP_WLOCK(inp);
4045 if (sasoc->sasoc_asocmaxrxt)
4046 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
4047 sasoc->sasoc_number_peer_destinations = 0;
4048 sasoc->sasoc_peer_rwnd = 0;
4049 sasoc->sasoc_local_rwnd = 0;
4050 if (sasoc->sasoc_cookie_life) {
4051 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
4053 SCTP_INP_WUNLOCK(inp);
4059 struct sctp_initmsg *sinit;
4061 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
4062 SCTP_INP_WLOCK(inp);
4063 if (sinit->sinit_num_ostreams)
4064 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
4066 if (sinit->sinit_max_instreams)
4067 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
4069 if (sinit->sinit_max_attempts)
4070 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
4072 if (sinit->sinit_max_init_timeo)
4073 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
4074 SCTP_INP_WUNLOCK(inp);
4077 case SCTP_PRIMARY_ADDR:
4079 struct sctp_setprim *spa;
4080 struct sctp_nets *net, *lnet;
4082 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
4083 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
4087 net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
4090 * We increment here since
4091 * sctp_findassociation_ep_addr() wil do a
4092 * decrement if it finds the stcb as long as
4093 * the locked tcb (last argument) is NOT a
4096 SCTP_INP_INCR_REF(inp);
4097 stcb = sctp_findassociation_ep_addr(&inp,
4098 (struct sockaddr *)&spa->ssp_addr,
4101 SCTP_INP_DECR_REF(inp);
4105 if ((stcb) && (net)) {
4106 if ((net != stcb->asoc.primary_destination) &&
4107 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
4108 /* Ok we need to set it */
4109 lnet = stcb->asoc.primary_destination;
4110 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
4111 if (net->dest_state & SCTP_ADDR_SWITCH_PRIMARY) {
4112 net->dest_state |= SCTP_ADDR_DOUBLE_SWITCH;
4114 net->dest_state |= SCTP_ADDR_SWITCH_PRIMARY;
4118 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4122 SCTP_TCB_UNLOCK(stcb);
4126 case SCTP_SET_DYNAMIC_PRIMARY:
4128 union sctp_sockstore *ss;
4130 error = priv_check(curthread,
4131 PRIV_NETINET_RESERVEDPORT);
4135 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
4136 /* SUPER USER CHECK? */
4137 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
4140 case SCTP_SET_PEER_PRIMARY_ADDR:
4142 struct sctp_setpeerprim *sspp;
4144 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
4145 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
4147 struct sctp_ifa *ifa;
4149 ifa = sctp_find_ifa_by_addr((struct sockaddr *)&sspp->sspp_addr,
4150 stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
4152 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4156 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
4158 * Must validate the ifa found is in
4161 struct sctp_laddr *laddr;
4164 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
4165 if (laddr->ifa == NULL) {
4166 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
4170 if (laddr->ifa == ifa) {
4176 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4181 if (sctp_set_primary_ip_address_sa(stcb,
4182 (struct sockaddr *)&sspp->sspp_addr) != 0) {
4183 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4187 SCTP_TCB_UNLOCK(stcb);
4189 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4195 case SCTP_BINDX_ADD_ADDR:
4197 struct sctp_getaddresses *addrs;
4201 td = (struct thread *)p;
4202 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
4204 if (addrs->addr->sa_family == AF_INET) {
4205 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in);
4207 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4211 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
4212 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
4216 } else if (addrs->addr->sa_family == AF_INET6) {
4217 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6);
4219 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4223 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
4224 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
4225 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
4230 error = EAFNOSUPPORT;
4233 sctp_bindx_add_address(so, inp, addrs->addr,
4234 addrs->sget_assoc_id, vrf_id,
4238 case SCTP_BINDX_REM_ADDR:
4240 struct sctp_getaddresses *addrs;
4244 td = (struct thread *)p;
4246 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
4247 if (addrs->addr->sa_family == AF_INET) {
4248 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in);
4250 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4254 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
4255 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
4259 } else if (addrs->addr->sa_family == AF_INET6) {
4260 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6);
4262 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4266 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
4267 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
4268 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
4273 error = EAFNOSUPPORT;
4276 sctp_bindx_delete_address(so, inp, addrs->addr,
4277 addrs->sget_assoc_id, vrf_id,
4282 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
4283 error = ENOPROTOOPT;
4285 } /* end switch (opt) */
4290 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
4292 void *optval = NULL;
4294 struct sctp_inpcb *inp;
4298 inp = (struct sctp_inpcb *)so->so_pcb;
4300 /* I made the same as TCP since we are not setup? */
4301 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4302 return (ECONNRESET);
4304 if (sopt->sopt_level != IPPROTO_SCTP) {
4305 /* wrong proto level... send back up to IP */
4307 if (INP_CHECK_SOCKAF(so, AF_INET6))
4308 error = ip6_ctloutput(so, sopt);
4311 error = ip_ctloutput(so, sopt);
4314 optsize = sopt->sopt_valsize;
4316 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
4317 if (optval == NULL) {
4318 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
4321 error = sooptcopyin(sopt, optval, optsize, optsize);
4323 SCTP_FREE(optval, SCTP_M_SOCKOPT);
4327 p = (void *)sopt->sopt_td;
4328 if (sopt->sopt_dir == SOPT_SET) {
4329 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
4330 } else if (sopt->sopt_dir == SOPT_GET) {
4331 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
4333 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4336 if ((error == 0) && (optval != NULL)) {
4337 error = sooptcopyout(sopt, optval, optsize);
4338 SCTP_FREE(optval, SCTP_M_SOCKOPT);
4339 } else if (optval != NULL) {
4340 SCTP_FREE(optval, SCTP_M_SOCKOPT);
4348 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
4351 int create_lock_on = 0;
4353 struct sctp_inpcb *inp;
4354 struct sctp_tcb *stcb = NULL;
4356 inp = (struct sctp_inpcb *)so->so_pcb;
4358 /* I made the same as TCP since we are not setup? */
4359 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4360 return (ECONNRESET);
4363 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4367 if (addr->sa_family == AF_INET6) {
4368 struct sockaddr_in6 *sin6p;
4370 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
4371 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4374 sin6p = (struct sockaddr_in6 *)addr;
4375 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
4376 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4381 if (addr->sa_family == AF_INET) {
4382 struct sockaddr_in *sinp;
4384 if (addr->sa_len != sizeof(struct sockaddr_in)) {
4385 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4388 sinp = (struct sockaddr_in *)addr;
4389 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
4390 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4394 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
4395 return (EAFNOSUPPORT);
4397 SCTP_INP_INCR_REF(inp);
4398 SCTP_ASOC_CREATE_LOCK(inp);
4402 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
4403 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
4404 /* Should I really unlock ? */
4405 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
4410 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
4411 (addr->sa_family == AF_INET6)) {
4412 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4417 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
4418 SCTP_PCB_FLAGS_UNBOUND) {
4419 /* Bind a ephemeral port */
4420 error = sctp_inpcb_bind(so, NULL, NULL, p);
4425 /* Now do we connect? */
4426 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
4427 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
4428 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4432 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
4433 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
4434 /* We are already connected AND the TCP model */
4435 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
4439 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4440 SCTP_INP_RLOCK(inp);
4441 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4442 SCTP_INP_RUNLOCK(inp);
4445 * We increment here since sctp_findassociation_ep_addr()
4446 * will do a decrement if it finds the stcb as long as the
4447 * locked tcb (last argument) is NOT a TCB.. aka NULL.
4449 SCTP_INP_INCR_REF(inp);
4450 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
4452 SCTP_INP_DECR_REF(inp);
4454 SCTP_TCB_UNLOCK(stcb);
4458 /* Already have or am bring up an association */
4459 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4463 vrf_id = inp->def_vrf_id;
4464 /* We are GOOD to go */
4465 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
4467 /* Gak! no memory */
4470 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
4471 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
4472 /* Set the connected flag so we can queue data */
4473 SOCKBUF_LOCK(&so->so_rcv);
4474 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
4475 SOCKBUF_UNLOCK(&so->so_rcv);
4476 SOCKBUF_LOCK(&so->so_snd);
4477 so->so_snd.sb_state &= ~SBS_CANTSENDMORE;
4478 SOCKBUF_UNLOCK(&so->so_snd);
4480 so->so_state &= ~SS_ISDISCONNECTING;
4484 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
4485 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4487 /* initialize authentication parameters for the assoc */
4488 sctp_initialize_auth_params(inp, stcb);
4490 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4491 SCTP_TCB_UNLOCK(stcb);
4493 if (create_lock_on) {
4494 SCTP_ASOC_CREATE_UNLOCK(inp);
4496 SCTP_INP_DECR_REF(inp);
4501 sctp_listen(struct socket *so, int backlog, struct thread *p)
4504 * Note this module depends on the protocol processing being called
4505 * AFTER any socket level flags and backlog are applied to the
4506 * socket. The traditional way that the socket flags are applied is
4507 * AFTER protocol processing. We have made a change to the
4508 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
4509 * place if the socket API for SCTP is to work properly.
4513 struct sctp_inpcb *inp;
4515 inp = (struct sctp_inpcb *)so->so_pcb;
4517 /* I made the same as TCP since we are not setup? */
4518 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4519 return (ECONNRESET);
4521 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
4522 /* See if we have a listener */
4523 struct sctp_inpcb *tinp;
4524 union sctp_sockstore store, *sp;
4527 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
4529 struct sctp_laddr *laddr;
4531 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
4532 memcpy(&store, &laddr->ifa->address, sizeof(store));
4533 sp->sin.sin_port = inp->sctp_lport;
4534 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
4535 if (tinp && (tinp != inp) &&
4536 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
4537 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
4538 (tinp->sctp_socket->so_qlimit)) {
4540 * we have a listener already and
4543 SCTP_INP_DECR_REF(tinp);
4544 return (EADDRINUSE);
4546 SCTP_INP_DECR_REF(tinp);
4550 /* Setup a local addr bound all */
4551 memset(&store, 0, sizeof(store));
4552 store.sin.sin_port = inp->sctp_lport;
4554 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4555 store.sa.sa_family = AF_INET6;
4556 store.sa.sa_len = sizeof(struct sockaddr_in6);
4559 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
4560 store.sa.sa_family = AF_INET;
4561 store.sa.sa_len = sizeof(struct sockaddr_in);
4563 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
4564 if (tinp && (tinp != inp) &&
4565 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
4566 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
4567 (tinp->sctp_socket->so_qlimit)) {
4569 * we have a listener already and its not
4572 SCTP_INP_DECR_REF(tinp);
4573 return (EADDRINUSE);
4575 SCTP_INP_DECR_REF(inp);
4579 SCTP_INP_RLOCK(inp);
4580 #ifdef SCTP_LOCK_LOGGING
4581 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
4582 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
4586 error = solisten_proto_check(so);
4589 SCTP_INP_RUNLOCK(inp);
4592 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
4593 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
4595 * The unlucky case - We are in the tcp pool with this guy.
4596 * - Someone else is in the main inp slot. - We must move
4597 * this guy (the listener) to the main slot - We must then
4598 * move the guy that was listener to the TCP Pool.
4600 if (sctp_swap_inpcb_for_listen(inp)) {
4604 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
4605 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
4606 /* We are already connected AND the TCP model */
4608 SCTP_INP_RUNLOCK(inp);
4610 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
4611 return (EADDRINUSE);
4613 SCTP_INP_RUNLOCK(inp);
4614 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
4615 /* We must do a bind. */
4617 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
4618 /* bind error, probably perm */
4623 /* It appears for 7.0 and on, we must always call this. */
4624 solisten_proto(so, backlog);
4625 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
4626 /* remove the ACCEPTCONN flag for one-to-many sockets */
4627 so->so_options &= ~SO_ACCEPTCONN;
4630 /* turning off listen */
4631 so->so_options &= ~SO_ACCEPTCONN;
4637 static int sctp_defered_wakeup_cnt = 0;
4640 sctp_accept(struct socket *so, struct sockaddr **addr)
4642 struct sctp_tcb *stcb;
4643 struct sctp_inpcb *inp;
4644 union sctp_sockstore store;
4650 inp = (struct sctp_inpcb *)so->so_pcb;
4653 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4654 return (ECONNRESET);
4656 SCTP_INP_RLOCK(inp);
4657 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
4658 SCTP_INP_RUNLOCK(inp);
4659 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4660 return (EOPNOTSUPP);
4662 if (so->so_state & SS_ISDISCONNECTED) {
4663 SCTP_INP_RUNLOCK(inp);
4664 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
4665 return (ECONNABORTED);
4667 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4669 SCTP_INP_RUNLOCK(inp);
4670 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4671 return (ECONNRESET);
4673 SCTP_TCB_LOCK(stcb);
4674 SCTP_INP_RUNLOCK(inp);
4675 store = stcb->asoc.primary_destination->ro._l_addr;
4676 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
4677 SCTP_TCB_UNLOCK(stcb);
4678 switch (store.sa.sa_family) {
4681 struct sockaddr_in *sin;
4683 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
4686 sin->sin_family = AF_INET;
4687 sin->sin_len = sizeof(*sin);
4688 sin->sin_port = ((struct sockaddr_in *)&store)->sin_port;
4689 sin->sin_addr = ((struct sockaddr_in *)&store)->sin_addr;
4690 *addr = (struct sockaddr *)sin;
4696 struct sockaddr_in6 *sin6;
4698 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
4701 sin6->sin6_family = AF_INET6;
4702 sin6->sin6_len = sizeof(*sin6);
4703 sin6->sin6_port = ((struct sockaddr_in6 *)&store)->sin6_port;
4705 sin6->sin6_addr = ((struct sockaddr_in6 *)&store)->sin6_addr;
4706 if ((error = sa6_recoverscope(sin6)) != 0) {
4707 SCTP_FREE_SONAME(sin6);
4710 *addr = (struct sockaddr *)sin6;
4718 /* Wake any delayed sleep action */
4719 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
4720 SCTP_INP_WLOCK(inp);
4721 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
4722 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
4723 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
4724 SCTP_INP_WUNLOCK(inp);
4725 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
4726 if (sowriteable(inp->sctp_socket)) {
4727 sowwakeup_locked(inp->sctp_socket);
4729 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
4731 SCTP_INP_WLOCK(inp);
4733 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
4734 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
4735 SCTP_INP_WUNLOCK(inp);
4736 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
4737 if (soreadable(inp->sctp_socket)) {
4738 sctp_defered_wakeup_cnt++;
4739 sorwakeup_locked(inp->sctp_socket);
4741 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
4743 SCTP_INP_WLOCK(inp);
4745 SCTP_INP_WUNLOCK(inp);
4747 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
4748 SCTP_TCB_LOCK(stcb);
4749 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
4755 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
4757 struct sockaddr_in *sin;
4759 struct sctp_inpcb *inp;
4760 struct sctp_ifa *sctp_ifa;
4763 * Do the malloc first in case it blocks.
4765 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
4768 sin->sin_family = AF_INET;
4769 sin->sin_len = sizeof(*sin);
4770 inp = (struct sctp_inpcb *)so->so_pcb;
4772 SCTP_FREE_SONAME(sin);
4773 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4776 SCTP_INP_RLOCK(inp);
4777 sin->sin_port = inp->sctp_lport;
4778 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
4779 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4780 struct sctp_tcb *stcb;
4781 struct sockaddr_in *sin_a;
4782 struct sctp_nets *net;
4785 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4791 SCTP_TCB_LOCK(stcb);
4792 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4793 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
4795 /* this will make coverity happy */
4798 if (sin_a->sin_family == AF_INET) {
4803 if ((!fnd) || (sin_a == NULL)) {
4805 SCTP_TCB_UNLOCK(stcb);
4808 vrf_id = inp->def_vrf_id;
4809 sctp_ifa = sctp_source_address_selection(inp,
4811 (sctp_route_t *) & net->ro,
4814 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
4815 sctp_free_ifa(sctp_ifa);
4817 SCTP_TCB_UNLOCK(stcb);
4819 /* For the bound all case you get back 0 */
4821 sin->sin_addr.s_addr = 0;
4825 /* Take the first IPv4 address in the list */
4826 struct sctp_laddr *laddr;
4829 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
4830 if (laddr->ifa->address.sa.sa_family == AF_INET) {
4831 struct sockaddr_in *sin_a;
4833 sin_a = (struct sockaddr_in *)&laddr->ifa->address.sa;
4834 sin->sin_addr = sin_a->sin_addr;
4840 SCTP_FREE_SONAME(sin);
4841 SCTP_INP_RUNLOCK(inp);
4842 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4846 SCTP_INP_RUNLOCK(inp);
4847 (*addr) = (struct sockaddr *)sin;
4852 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
4854 struct sockaddr_in *sin = (struct sockaddr_in *)*addr;
4856 struct sockaddr_in *sin_a;
4857 struct sctp_inpcb *inp;
4858 struct sctp_tcb *stcb;
4859 struct sctp_nets *net;
4861 /* Do the malloc first in case it blocks. */
4862 inp = (struct sctp_inpcb *)so->so_pcb;
4863 if ((inp == NULL) ||
4864 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
4865 /* UDP type and listeners will drop out here */
4866 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
4869 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
4872 sin->sin_family = AF_INET;
4873 sin->sin_len = sizeof(*sin);
4875 /* We must recapture incase we blocked */
4876 inp = (struct sctp_inpcb *)so->so_pcb;
4878 SCTP_FREE_SONAME(sin);
4879 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4882 SCTP_INP_RLOCK(inp);
4883 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4885 SCTP_TCB_LOCK(stcb);
4887 SCTP_INP_RUNLOCK(inp);
4889 SCTP_FREE_SONAME(sin);
4890 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4894 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4895 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
4896 if (sin_a->sin_family == AF_INET) {
4898 sin->sin_port = stcb->rport;
4899 sin->sin_addr = sin_a->sin_addr;
4903 SCTP_TCB_UNLOCK(stcb);
4905 /* No IPv4 address */
4906 SCTP_FREE_SONAME(sin);
4907 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4910 (*addr) = (struct sockaddr *)sin;
4914 struct pr_usrreqs sctp_usrreqs = {
4915 .pru_abort = sctp_abort,
4916 .pru_accept = sctp_accept,
4917 .pru_attach = sctp_attach,
4918 .pru_bind = sctp_bind,
4919 .pru_connect = sctp_connect,
4920 .pru_control = in_control,
4921 .pru_close = sctp_close,
4922 .pru_detach = sctp_close,
4923 .pru_sopoll = sopoll_generic,
4924 .pru_flush = sctp_flush,
4925 .pru_disconnect = sctp_disconnect,
4926 .pru_listen = sctp_listen,
4927 .pru_peeraddr = sctp_peeraddr,
4928 .pru_send = sctp_sendm,
4929 .pru_shutdown = sctp_shutdown,
4930 .pru_sockaddr = sctp_ingetaddr,
4931 .pru_sosend = sctp_sosend,
4932 .pru_soreceive = sctp_soreceive