2 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * a) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
12 * b) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the distribution.
16 * c) Neither the name of Cisco Systems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD: head/sys/netinet/sctp_usrreq.c 267688 2014-06-20 20:17:39Z tuexen $");
38 #include <netinet/sctp_os.h>
42 #include <netinet/sctp_pcb.h>
43 #include <netinet/sctp_header.h>
44 #include <netinet/sctp_var.h>
46 #if defined(__Userspace_os_FreeBSD)
47 #include <netinet6/sctp6_var.h>
50 #include <netinet/sctp_sysctl.h>
51 #include <netinet/sctp_output.h>
52 #include <netinet/sctp_uio.h>
53 #include <netinet/sctp_asconf.h>
54 #include <netinet/sctputil.h>
55 #include <netinet/sctp_indata.h>
56 #include <netinet/sctp_timer.h>
57 #include <netinet/sctp_auth.h>
58 #include <netinet/sctp_bsd_addr.h>
59 #if !defined(__Userspace__)
60 #include <netinet/udp.h>
63 #if defined(HAVE_SCTP_PEELOFF_SOCKOPT)
64 #include <netinet/sctp_peeloff.h>
65 #endif /* HAVE_SCTP_PEELOFF_SOCKOPT */
67 #if defined(__APPLE__)
68 #define APPLE_FILE_NO 7
71 extern struct sctp_cc_functions sctp_cc_functions[];
72 extern struct sctp_ss_functions sctp_ss_functions[];
75 #if defined(__Userspace__)
76 sctp_init(uint16_t port,
77 int (*conn_output)(void *addr, void *buffer, size_t length, uint8_t tos, uint8_t set_df),
78 void (*debug_printf)(const char *format, ...))
79 #elif defined(__APPLE__) && (!defined(APPLE_LEOPARD) && !defined(APPLE_SNOWLEOPARD) &&!defined(APPLE_LION) && !defined(APPLE_MOUNTAINLION))
80 sctp_init(struct protosw *pp SCTP_UNUSED, struct domain *dp SCTP_UNUSED)
85 #if !defined(__Panda__) && !defined(__Userspace__)
89 #if defined(__Userspace__)
90 #if defined(__Userspace_os_Windows)
91 #if defined(INET) || defined(INET6)
94 if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
95 SCTP_PRINTF("WSAStartup failed\n");
99 InitializeConditionVariable(&accept_cond);
100 InitializeCriticalSection(&accept_mtx);
102 pthread_cond_init(&accept_cond, NULL);
103 pthread_mutex_init(&accept_mtx, NULL);
106 /* Initialize and modify the sysctled variables */
108 #if defined(__Userspace__)
109 #if defined(__Userspace_os_Windows)
110 srand((unsigned int)time(NULL));
112 srandom(getpid()); /* so inp->sctp_ep.random_numbers are truly random... */
115 #if defined(__Panda__)
116 sctp_sendspace = SB_MAX;
117 sctp_recvspace = SB_MAX;
119 #elif defined(__Userspace__)
120 SCTP_BASE_SYSCTL(sctp_sendspace) = SB_MAX;
121 SCTP_BASE_SYSCTL(sctp_recvspace) = SB_RAW;
122 SCTP_BASE_SYSCTL(sctp_udp_tunneling_port) = port;
124 #if !defined(__APPLE__)
125 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
126 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
129 * Allow a user to take no more than 1/2 the number of clusters or
130 * the SB_MAX whichever is smaller for the send window.
132 #if defined(__APPLE__)
133 sb_max_adj = (u_long)((u_quad_t) (sb_max) * MCLBYTES / (MSIZE + MCLBYTES));
135 sb_max_adj = (u_long)((u_quad_t) (SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
137 #if defined(__APPLE__)
138 SCTP_BASE_SYSCTL(sctp_sendspace) = sb_max_adj;
140 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
141 (((uint32_t)nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
144 * Now for the recv window, should we take the same amount? or
145 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
146 * now I will just copy.
148 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
150 SCTP_BASE_VAR(first_time) = 0;
151 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
152 #if defined(__Userspace__)
153 #if !defined(__Userspace_os_Windows)
154 #if defined(INET) || defined(INET6)
155 SCTP_BASE_VAR(userspace_route) = -1;
159 SCTP_BASE_VAR(userspace_rawsctp) = -1;
160 SCTP_BASE_VAR(userspace_udpsctp) = -1;
163 SCTP_BASE_VAR(userspace_rawsctp6) = -1;
164 SCTP_BASE_VAR(userspace_udpsctp6) = -1;
166 SCTP_BASE_VAR(timer_thread_should_exit) = 0;
167 SCTP_BASE_VAR(conn_output) = conn_output;
168 SCTP_BASE_VAR(debug_printf) = debug_printf;
171 #if defined(__Userspace__)
174 #if defined(SCTP_PACKET_LOGGING)
175 SCTP_BASE_VAR(packet_log_writers) = 0;
176 SCTP_BASE_VAR(packet_log_end) = 0;
177 bzero(&SCTP_BASE_VAR(packet_log_buffer), SCTP_PACKET_LOG_SIZE);
179 #if defined(__APPLE__)
180 SCTP_BASE_VAR(sctp_main_timer_ticks) = 0;
181 sctp_start_main_timer();
182 timeout(sctp_delayed_startup, NULL, 1);
189 #if defined(__APPLE__)
190 untimeout(sctp_delayed_startup, NULL);
191 sctp_over_udp_stop();
192 sctp_address_monitor_stop();
193 sctp_stop_main_timer();
195 #if defined(__Userspace__)
196 #if defined(INET) || defined(INET6)
197 recv_thread_destroy();
199 #if !defined(__Userspace_os_Windows)
200 #if defined(INET) || defined(INET6)
201 if (SCTP_BASE_VAR(userspace_route) != -1) {
202 pthread_join(SCTP_BASE_VAR(recvthreadroute), NULL);
207 if (SCTP_BASE_VAR(userspace_rawsctp) != -1) {
208 #if defined(__Userspace_os_Windows)
209 WaitForSingleObject(SCTP_BASE_VAR(recvthreadraw), INFINITE);
210 CloseHandle(SCTP_BASE_VAR(recvthreadraw));
212 pthread_join(SCTP_BASE_VAR(recvthreadraw), NULL);
215 if (SCTP_BASE_VAR(userspace_udpsctp) != -1) {
216 #if defined(__Userspace_os_Windows)
217 WaitForSingleObject(SCTP_BASE_VAR(recvthreadudp), INFINITE);
218 CloseHandle(SCTP_BASE_VAR(recvthreadudp));
220 pthread_join(SCTP_BASE_VAR(recvthreadudp), NULL);
225 if (SCTP_BASE_VAR(userspace_rawsctp6) != -1) {
226 #if defined(__Userspace_os_Windows)
227 WaitForSingleObject(SCTP_BASE_VAR(recvthreadraw6), INFINITE);
228 CloseHandle(SCTP_BASE_VAR(recvthreadraw6));
230 pthread_join(SCTP_BASE_VAR(recvthreadraw6), NULL);
233 if (SCTP_BASE_VAR(userspace_udpsctp6) != -1) {
234 #if defined(__Userspace_os_Windows)
235 WaitForSingleObject(SCTP_BASE_VAR(recvthreadudp6), INFINITE);
236 CloseHandle(SCTP_BASE_VAR(recvthreadudp6));
238 pthread_join(SCTP_BASE_VAR(recvthreadudp6), NULL);
242 SCTP_BASE_VAR(timer_thread_should_exit) = 1;
243 #if defined(__Userspace_os_Windows)
244 WaitForSingleObject(SCTP_BASE_VAR(timer_thread), INFINITE);
245 CloseHandle(SCTP_BASE_VAR(timer_thread));
247 pthread_join(SCTP_BASE_VAR(timer_thread), NULL);
251 #if defined(__Userspace__)
252 #if defined(__Userspace_os_Windows)
253 DeleteConditionVariable(&accept_cond);
254 DeleteCriticalSection(&accept_mtx);
256 pthread_cond_destroy(&accept_cond);
257 pthread_mutex_destroy(&accept_mtx);
260 #if defined(__Windows__)
261 sctp_finish_sysctls();
262 #if defined(INET) || defined(INET6)
271 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
273 struct sctp_tmit_chunk *chk;
276 /* Adjust that too */
277 stcb->asoc.smallest_mtu = nxtsz;
278 /* now off to subtract IP_DF flag if needed */
279 overhead = IP_HDR_SIZE;
280 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
281 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
283 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
284 if ((chk->send_size + overhead) > nxtsz) {
285 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
288 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
289 if ((chk->send_size + overhead) > nxtsz) {
291 * For this guy we also mark for immediate resend
292 * since we sent to big of chunk
294 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
295 if (chk->sent < SCTP_DATAGRAM_RESEND) {
296 sctp_flight_size_decrease(chk);
297 sctp_total_flight_decrease(stcb, chk);
299 if (chk->sent != SCTP_DATAGRAM_RESEND) {
300 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
302 chk->sent = SCTP_DATAGRAM_RESEND;
303 chk->rec.data.doing_fast_retransmit = 0;
304 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
305 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
306 chk->whoTo->flight_size,
308 (uintptr_t)chk->whoTo,
309 chk->rec.data.TSN_seq);
311 /* Clear any time so NO RTT is being done */
318 #if !defined(__Userspace__)
319 #if defined(__Panda__) || defined(__Windows__)
324 sctp_notify_mbuf(struct sctp_inpcb *inp,
325 struct sctp_tcb *stcb,
326 struct sctp_nets *net,
331 int totsz, tmr_stopped = 0;
335 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
336 (ip == NULL) || (sh == NULL)) {
338 SCTP_TCB_UNLOCK(stcb);
342 /* First job is to verify the vtag matches what I would send */
343 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
344 SCTP_TCB_UNLOCK(stcb);
347 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
349 if (icmph->icmp_type != ICMP_UNREACH) {
350 /* We only care about unreachable */
351 SCTP_TCB_UNLOCK(stcb);
354 if (icmph->icmp_code != ICMP_UNREACH_NEEDFRAG) {
355 /* not a unreachable message due to frag. */
356 SCTP_TCB_UNLOCK(stcb);
359 #if defined(__FreeBSD__) && __FreeBSD_version >= 1000000
360 totsz = ntohs(ip->ip_len);
365 nxtsz = ntohs(icmph->icmp_nextmtu);
368 * old type router that does not tell us what the next size
369 * mtu is. Rats we will have to guess (in a educated fashion
372 nxtsz = sctp_get_prev_mtu(totsz);
374 /* Stop any PMTU timer */
375 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
377 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
378 SCTP_FROM_SCTP_USRREQ+SCTP_LOC_1);
380 /* Adjust destination size limit */
381 if (net->mtu > nxtsz) {
384 net->mtu -= sizeof(struct udphdr);
387 /* now what about the ep? */
388 if (stcb->asoc.smallest_mtu > nxtsz) {
389 sctp_pathmtu_adjustment(stcb, nxtsz);
392 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
394 SCTP_TCB_UNLOCK(stcb);
398 sctp_notify(struct sctp_inpcb *inp,
402 struct sctp_tcb *stcb,
403 struct sctp_nets *net)
405 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
412 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
413 (sh == NULL) || (to == NULL)) {
415 SCTP_TCB_UNLOCK(stcb);
418 /* First job is to verify the vtag matches what I would send */
419 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
420 SCTP_TCB_UNLOCK(stcb);
424 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
426 if (icmph->icmp_type != ICMP_UNREACH) {
427 /* We only care about unreachable */
428 SCTP_TCB_UNLOCK(stcb);
431 if ((icmph->icmp_code == ICMP_UNREACH_NET) ||
432 (icmph->icmp_code == ICMP_UNREACH_HOST) ||
433 (icmph->icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
434 (icmph->icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
435 (icmph->icmp_code == ICMP_UNREACH_ISOLATED) ||
436 (icmph->icmp_code == ICMP_UNREACH_NET_PROHIB) ||
437 (icmph->icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
438 #if defined(__Panda__)
439 (icmph->icmp_code == ICMP_UNREACH_ADMIN)) {
440 #elif defined(__Userspace_os_NetBSD)
441 (icmph->icmp_code == ICMP_UNREACH_ADMIN_PROHIBIT)) {
443 (icmph->icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
447 * Hmm reachablity problems we must examine closely. If its
448 * not reachable, we may have lost a network. Or if there is
449 * NO protocol at the other end named SCTP. well we consider
452 if (net->dest_state & SCTP_ADDR_REACHABLE) {
453 /* Ok that destination is NOT reachable */
454 net->dest_state &= ~SCTP_ADDR_REACHABLE;
455 net->dest_state &= ~SCTP_ADDR_PF;
456 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
458 (void *)net, SCTP_SO_NOT_LOCKED);
460 SCTP_TCB_UNLOCK(stcb);
461 } else if ((icmph->icmp_code == ICMP_UNREACH_PROTOCOL) ||
462 (icmph->icmp_code == ICMP_UNREACH_PORT)) {
464 * Here the peer is either playing tricks on us,
465 * including an address that belongs to someone who
466 * does not support SCTP OR was a userland
467 * implementation that shutdown and now is dead. In
468 * either case treat it like a OOTB abort with no
471 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
472 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
473 so = SCTP_INP_SO(inp);
474 atomic_add_int(&stcb->asoc.refcnt, 1);
475 SCTP_TCB_UNLOCK(stcb);
476 SCTP_SOCKET_LOCK(so, 1);
478 atomic_subtract_int(&stcb->asoc.refcnt, 1);
480 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ+SCTP_LOC_2);
481 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
482 SCTP_SOCKET_UNLOCK(so, 1);
483 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed.*/
485 /* no need to unlock here, since the TCB is gone */
487 SCTP_TCB_UNLOCK(stcb);
494 #if !defined(__Panda__) && !defined(__Userspace__)
495 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
500 sctp_ctlinput(cmd, sa, vip)
508 /* FIX, for non-bsd is this right? */
509 vrf_id = SCTP_DEFAULT_VRFID;
510 if (sa->sa_family != AF_INET ||
511 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
512 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
518 if (PRC_IS_REDIRECT(cmd)) {
520 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
521 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
528 struct sctp_inpcb *inp = NULL;
529 struct sctp_tcb *stcb = NULL;
530 struct sctp_nets *net = NULL;
531 struct sockaddr_in to, from;
533 sh = (struct sctphdr *)((caddr_t)ip + (ip->ip_hl << 2));
534 bzero(&to, sizeof(to));
535 bzero(&from, sizeof(from));
536 from.sin_family = to.sin_family = AF_INET;
538 from.sin_len = to.sin_len = sizeof(to);
540 from.sin_port = sh->src_port;
541 from.sin_addr = ip->ip_src;
542 to.sin_port = sh->dest_port;
543 to.sin_addr = ip->ip_dst;
546 * 'to' holds the dest of the packet that failed to be sent.
547 * 'from' holds our local endpoint address. Thus we reverse
548 * the to and the from in the lookup.
550 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&to,
551 (struct sockaddr *)&from,
552 &inp, &net, 1, vrf_id);
553 if (stcb != NULL && inp && (inp->sctp_socket != NULL)) {
554 if (cmd != PRC_MSGSIZE) {
555 sctp_notify(inp, ip, sh,
556 (struct sockaddr *)&to, stcb,
559 /* handle possible ICMP size messages */
560 sctp_notify_mbuf(inp, stcb, net, ip, sh);
563 #if defined(__FreeBSD__) && __FreeBSD_version < 500000
565 * XXX must be fixed for 5.x and higher, leave for
568 if (PRC_IS_REDIRECT(cmd) && inp) {
569 in_rtchange((struct inpcb *)inp,
573 if ((stcb == NULL) && (inp != NULL)) {
574 /* reduce ref-count */
576 SCTP_INP_DECR_REF(inp);
577 SCTP_INP_WUNLOCK(inp);
580 SCTP_TCB_UNLOCK(stcb);
584 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
593 #if defined(__FreeBSD__)
595 sctp_getcred(SYSCTL_HANDLER_ARGS)
598 struct sockaddr_in addrs[2];
599 struct sctp_inpcb *inp;
600 struct sctp_nets *net;
601 struct sctp_tcb *stcb;
605 /* FIX, for non-bsd is this right? */
606 vrf_id = SCTP_DEFAULT_VRFID;
608 #if __FreeBSD_version > 602000
609 error = priv_check(req->td, PRIV_NETINET_GETCRED);
611 #elif __FreeBSD_version >= 500000
612 error = suser(req->td);
614 error = suser(req->p);
619 error = SYSCTL_IN(req, addrs, sizeof(addrs));
623 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
625 &inp, &net, 1, vrf_id);
626 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
627 if ((inp != NULL) && (stcb == NULL)) {
628 /* reduce ref-count */
630 SCTP_INP_DECR_REF(inp);
634 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
638 SCTP_TCB_UNLOCK(stcb);
639 /* We use the write lock here, only
640 * since in the error leg we need it.
641 * If we used RLOCK, then we would have
642 * to wlock/decr/unlock/rlock. Which
643 * in theory could create a hole. Better
644 * to use higher wlock.
648 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
650 SCTP_INP_WUNLOCK(inp);
653 cru2x(inp->sctp_socket->so_cred, &xuc);
654 SCTP_INP_WUNLOCK(inp);
655 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
660 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
661 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
662 #endif /* #if defined(__FreeBSD__) */
666 #if defined(__Panda__) || defined(__Windows__) || defined(__Userspace__)
668 #elif defined(__FreeBSD__) && __FreeBSD_version > 690000
673 sctp_abort(struct socket *so)
675 struct sctp_inpcb *inp;
678 inp = (struct sctp_inpcb *)so->so_pcb;
680 #if defined(__FreeBSD__) && __FreeBSD_version > 690000
683 SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
689 flags = inp->sctp_flags;
690 #ifdef SCTP_LOG_CLOSING
691 sctp_log_closing(inp, NULL, 17);
693 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
694 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
695 #ifdef SCTP_LOG_CLOSING
696 sctp_log_closing(inp, NULL, 16);
698 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
699 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
701 SCTP_SB_CLEAR(so->so_snd);
702 /* same for the rcv ones, they are only
703 * here for the accounting/select.
705 SCTP_SB_CLEAR(so->so_rcv);
707 #if defined(__APPLE__)
710 /* Now null out the reference, we are completely detached. */
715 flags = inp->sctp_flags;
716 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
717 goto sctp_must_try_again;
720 #if defined(__FreeBSD__) && __FreeBSD_version > 690000
727 #if defined(__Panda__) || defined(__Userspace__)
732 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
733 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
734 #elif defined(__Panda__) || defined(__Userspace__)
735 sctp_attach(struct socket *so, int proto SCTP_UNUSED, uint32_t vrf_id)
736 #elif defined(__Windows__)
737 sctp_attach(struct socket *so, int proto SCTP_UNUSED, PKTHREAD p SCTP_UNUSED)
739 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct proc *p SCTP_UNUSED)
742 struct sctp_inpcb *inp;
743 struct inpcb *ip_inp;
745 #if !defined(__Panda__) && !defined(__Userspace__)
746 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
752 inp = (struct sctp_inpcb *)so->so_pcb;
754 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
757 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
758 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
763 error = sctp_inpcb_alloc(so, vrf_id);
767 inp = (struct sctp_inpcb *)so->so_pcb;
769 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
770 ip_inp = &inp->ip_inp.inp;
771 ip_inp->inp_vflag |= INP_IPV4;
772 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
774 #if !(defined(__APPLE__))
775 error = ipsec_init_policy(so, &ip_inp->inp_sp);
776 #ifdef SCTP_LOG_CLOSING
777 sctp_log_closing(inp, NULL, 17);
781 flags = inp->sctp_flags;
782 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
783 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
784 #ifdef SCTP_LOG_CLOSING
785 sctp_log_closing(inp, NULL, 15);
787 SCTP_INP_WUNLOCK(inp);
788 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
789 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
791 flags = inp->sctp_flags;
792 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
795 SCTP_INP_WUNLOCK(inp);
802 SCTP_INP_WUNLOCK(inp);
806 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
808 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
810 #elif defined(__FreeBSD__) || defined(__APPLE__)
812 sctp_bind(struct socket *so, struct sockaddr *addr, struct proc *p) {
813 #elif defined(__Panda__) || defined(__Userspace__)
815 sctp_bind(struct socket *so, struct sockaddr *addr) {
817 #elif defined(__Windows__)
819 sctp_bind(struct socket *so, struct sockaddr *addr, PKTHREAD p) {
822 sctp_bind(struct socket *so, struct mbuf *nam, struct proc *p)
824 struct sockaddr *addr = nam ? mtod(nam, struct sockaddr *): NULL;
827 struct sctp_inpcb *inp;
829 inp = (struct sctp_inpcb *)so->so_pcb;
831 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
836 if ((addr->sa_family != AF_INET) ||
837 (addr->sa_len != sizeof(struct sockaddr_in))) {
839 if (addr->sa_family != AF_INET) {
841 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
845 return (sctp_inpcb_bind(so, addr, NULL, p));
849 #if defined(__Userspace__)
852 sctpconn_attach(struct socket *so, int proto SCTP_UNUSED, uint32_t vrf_id)
854 struct sctp_inpcb *inp;
855 struct inpcb *ip_inp;
858 inp = (struct sctp_inpcb *)so->so_pcb;
860 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
863 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
864 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
869 error = sctp_inpcb_alloc(so, vrf_id);
873 inp = (struct sctp_inpcb *)so->so_pcb;
875 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6;
876 inp->sctp_flags |= SCTP_PCB_FLAGS_BOUND_CONN;
877 ip_inp = &inp->ip_inp.inp;
878 ip_inp->inp_vflag |= INP_CONN;
879 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
880 SCTP_INP_WUNLOCK(inp);
885 sctpconn_bind(struct socket *so, struct sockaddr *addr)
887 struct sctp_inpcb *inp;
889 inp = (struct sctp_inpcb *)so->so_pcb;
891 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
896 if ((addr->sa_family != AF_CONN) ||
897 (addr->sa_len != sizeof(struct sockaddr_conn))) {
899 if (addr->sa_family != AF_CONN) {
901 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
905 return (sctp_inpcb_bind(so, addr, NULL, NULL));
909 #if (defined(__FreeBSD__) && __FreeBSD_version > 690000) || defined(__Windows__) || defined(__Userspace__)
911 sctp_close(struct socket *so)
913 struct sctp_inpcb *inp;
916 inp = (struct sctp_inpcb *)so->so_pcb;
920 /* Inform all the lower layer assoc that we
924 flags = inp->sctp_flags;
925 #ifdef SCTP_LOG_CLOSING
926 sctp_log_closing(inp, NULL, 17);
928 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
929 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
930 #if defined(__Userspace__)
931 if (((so->so_options & SCTP_SO_LINGER) && (so->so_linger == 0)) ||
932 (so->so_rcv.sb_cc > 0)) {
934 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
935 (so->so_rcv.sb_cc > 0)) {
937 #ifdef SCTP_LOG_CLOSING
938 sctp_log_closing(inp, NULL, 13);
940 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
941 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
943 #ifdef SCTP_LOG_CLOSING
944 sctp_log_closing(inp, NULL, 14);
946 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
947 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
949 /* The socket is now detached, no matter what
950 * the state of the SCTP association.
953 SCTP_SB_CLEAR(so->so_snd);
954 /* same for the rcv ones, they are only
955 * here for the accounting/select.
957 SCTP_SB_CLEAR(so->so_rcv);
959 #if !defined(__APPLE__)
960 /* Now null out the reference, we are completely detached. */
965 flags = inp->sctp_flags;
966 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
967 goto sctp_must_try_again;
977 sctp_detach(struct socket *so)
979 struct sctp_inpcb *inp;
982 inp = (struct sctp_inpcb *)so->so_pcb;
984 #if defined(__FreeBSD__) && __FreeBSD_version > 690000
987 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
992 flags = inp->sctp_flags;
993 #ifdef SCTP_LOG_CLOSING
994 sctp_log_closing(inp, NULL, 17);
996 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
997 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
998 #if defined(__Userspace__)
999 if (((so->so_options & SCTP_SO_LINGER) && (so->so_linger == 0)) ||
1000 (so->so_rcv.sb_cc > 0)) {
1002 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
1003 (so->so_rcv.sb_cc > 0)) {
1005 #ifdef SCTP_LOG_CLOSING
1006 sctp_log_closing(inp, NULL, 13);
1008 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
1009 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
1011 #ifdef SCTP_LOG_CLOSING
1012 sctp_log_closing(inp, NULL, 13);
1014 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
1015 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
1017 /* The socket is now detached, no matter what
1018 * the state of the SCTP association.
1020 SCTP_SB_CLEAR(so->so_snd);
1021 /* same for the rcv ones, they are only
1022 * here for the accounting/select.
1024 SCTP_SB_CLEAR(so->so_rcv);
1025 #if !defined(__APPLE__)
1026 /* Now disconnect */
1030 flags = inp->sctp_flags;
1031 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
1032 goto sctp_must_try_again;
1035 #if defined(__FreeBSD__) && __FreeBSD_version > 690000
1043 #if defined(__Userspace__)
1044 /* __Userspace__ is not calling sctp_sendm */
1046 #if !(defined(__Panda__) || defined(__Windows__))
1048 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
1049 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
1050 struct mbuf *control, struct thread *p);
1053 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
1054 struct mbuf *control, struct proc *p);
1059 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
1060 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
1061 struct mbuf *control, struct thread *p)
1064 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
1065 struct mbuf *control, struct proc *p)
1068 struct sctp_inpcb *inp;
1071 inp = (struct sctp_inpcb *)so->so_pcb;
1074 sctp_m_freem(control);
1077 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1081 /* Got to have an to address if we are NOT a connected socket */
1082 if ((addr == NULL) &&
1083 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
1084 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
1085 goto connected_type;
1086 } else if (addr == NULL) {
1087 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
1088 error = EDESTADDRREQ;
1091 sctp_m_freem(control);
1097 if (addr->sa_family != AF_INET) {
1098 /* must be a v4 address! */
1099 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
1102 sctp_m_freem(control);
1105 error = EDESTADDRREQ;
1110 /* now what about control */
1113 SCTP_PRINTF("huh? control set?\n");
1114 sctp_m_freem(inp->control);
1115 inp->control = NULL;
1117 inp->control = control;
1119 /* Place the data */
1121 SCTP_BUF_NEXT(inp->pkt_last) = m;
1124 inp->pkt_last = inp->pkt = m;
1127 #if defined(__FreeBSD__) || defined(__APPLE__)
1128 /* FreeBSD uses a flag passed */
1129 ((flags & PRUS_MORETOCOME) == 0)
1131 1 /* Open BSD does not have any "more to come"
1136 * note with the current version this code will only be used
1137 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
1138 * re-defining sosend to use the sctp_sosend. One can
1139 * optionally switch back to this code (by changing back the
1140 * definitions) but this is not advisable. This code is used
1141 * by FreeBSD when sending a file with sendfile() though.
1145 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
1147 inp->control = NULL;
1156 sctp_disconnect(struct socket *so)
1158 struct sctp_inpcb *inp;
1160 inp = (struct sctp_inpcb *)so->so_pcb;
1162 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1165 SCTP_INP_RLOCK(inp);
1166 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1167 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1168 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
1170 SCTP_INP_RUNLOCK(inp);
1173 struct sctp_association *asoc;
1174 struct sctp_tcb *stcb;
1176 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1178 SCTP_INP_RUNLOCK(inp);
1179 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1182 SCTP_TCB_LOCK(stcb);
1184 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
1185 /* We are about to be freed, out of here */
1186 SCTP_TCB_UNLOCK(stcb);
1187 SCTP_INP_RUNLOCK(inp);
1190 #if defined(__Userspace__)
1191 if (((so->so_options & SCTP_SO_LINGER) &&
1192 (so->so_linger == 0)) ||
1193 (so->so_rcv.sb_cc > 0)) {
1195 if (((so->so_options & SO_LINGER) &&
1196 (so->so_linger == 0)) ||
1197 (so->so_rcv.sb_cc > 0)) {
1199 if (SCTP_GET_STATE(asoc) !=
1200 SCTP_STATE_COOKIE_WAIT) {
1201 /* Left with Data unread */
1204 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_NOWAIT, 1, MT_DATA);
1210 struct sctp_paramhdr *ph;
1212 ph = mtod(err, struct sctp_paramhdr *);
1213 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
1214 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
1215 ph->param_length = htons(SCTP_BUF_LEN(err));
1217 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
1218 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
1220 SCTP_INP_RUNLOCK(inp);
1221 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
1222 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
1223 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1225 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ+SCTP_LOC_3);
1226 /* No unlock tcb assoc is gone */
1229 if (TAILQ_EMPTY(&asoc->send_queue) &&
1230 TAILQ_EMPTY(&asoc->sent_queue) &&
1231 (asoc->stream_queue_cnt == 0)) {
1232 /* there is nothing queued to send, so done */
1233 if (asoc->locked_on_sending) {
1236 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
1237 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
1238 /* only send SHUTDOWN 1st time thru */
1239 struct sctp_nets *netp;
1241 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
1242 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
1243 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1245 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
1246 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
1247 sctp_stop_timers_for_shutdown(stcb);
1248 if (stcb->asoc.alternate) {
1249 netp = stcb->asoc.alternate;
1251 netp = stcb->asoc.primary_destination;
1253 sctp_send_shutdown(stcb,netp);
1254 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1255 stcb->sctp_ep, stcb, netp);
1256 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1257 stcb->sctp_ep, stcb, netp);
1258 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
1262 * we still got (or just got) data to send,
1263 * so set SHUTDOWN_PENDING
1266 * XXX sockets draft says that SCTP_EOF
1267 * should be sent with no data. currently,
1268 * we will allow user data to be sent first
1269 * and move to SHUTDOWN-PENDING
1271 struct sctp_nets *netp;
1272 if (stcb->asoc.alternate) {
1273 netp = stcb->asoc.alternate;
1275 netp = stcb->asoc.primary_destination;
1278 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1279 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
1281 if (asoc->locked_on_sending) {
1282 /* Locked to send out the data */
1283 struct sctp_stream_queue_pending *sp;
1284 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
1286 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
1287 asoc->locked_on_sending->stream_no);
1289 if ((sp->length == 0) && (sp->msg_is_complete == 0))
1290 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
1293 if (TAILQ_EMPTY(&asoc->send_queue) &&
1294 TAILQ_EMPTY(&asoc->sent_queue) &&
1295 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1296 struct mbuf *op_err;
1298 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
1299 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ+SCTP_LOC_4;
1300 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
1301 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
1302 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
1303 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
1304 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1306 SCTP_INP_RUNLOCK(inp);
1307 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ+SCTP_LOC_5);
1310 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1313 soisdisconnecting(so);
1314 SCTP_TCB_UNLOCK(stcb);
1315 SCTP_INP_RUNLOCK(inp);
1320 /* UDP model does not support this */
1321 SCTP_INP_RUNLOCK(inp);
1322 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1323 return (EOPNOTSUPP);
1327 #if defined(__FreeBSD__) || defined(__Windows__) || defined(__Userspace__)
1329 sctp_flush(struct socket *so, int how)
1332 * We will just clear out the values and let
1333 * subsequent close clear out the data, if any.
1334 * Note if the user did a shutdown(SHUT_RD) they
1335 * will not be able to read the data, the socket
1336 * will block that from happening.
1338 struct sctp_inpcb *inp;
1340 inp = (struct sctp_inpcb *)so->so_pcb;
1342 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1345 SCTP_INP_RLOCK(inp);
1346 /* For the 1 to many model this does nothing */
1347 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
1348 SCTP_INP_RUNLOCK(inp);
1351 SCTP_INP_RUNLOCK(inp);
1352 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
1353 /* First make sure the sb will be happy, we don't
1354 * use these except maybe the count
1356 SCTP_INP_WLOCK(inp);
1357 SCTP_INP_READ_LOCK(inp);
1358 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
1359 SCTP_INP_READ_UNLOCK(inp);
1360 SCTP_INP_WUNLOCK(inp);
1361 so->so_rcv.sb_cc = 0;
1362 so->so_rcv.sb_mbcnt = 0;
1363 so->so_rcv.sb_mb = NULL;
1365 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
1366 /* First make sure the sb will be happy, we don't
1367 * use these except maybe the count
1369 so->so_snd.sb_cc = 0;
1370 so->so_snd.sb_mbcnt = 0;
1371 so->so_snd.sb_mb = NULL;
1379 sctp_shutdown(struct socket *so)
1381 struct sctp_inpcb *inp;
1383 inp = (struct sctp_inpcb *)so->so_pcb;
1385 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1388 SCTP_INP_RLOCK(inp);
1389 /* For UDP model this is a invalid call */
1390 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1391 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
1392 /* Restore the flags that the soshutdown took away. */
1393 #if (defined(__FreeBSD__) && __FreeBSD_version >= 502115) || defined(__Windows__)
1394 SOCKBUF_LOCK(&so->so_rcv);
1395 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
1396 SOCKBUF_UNLOCK(&so->so_rcv);
1398 so->so_state &= ~SS_CANTRCVMORE;
1400 /* This proc will wakeup for read and do nothing (I hope) */
1401 SCTP_INP_RUNLOCK(inp);
1402 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1403 return (EOPNOTSUPP);
1406 * Ok if we reach here its the TCP model and it is either a SHUT_WR
1407 * or SHUT_RDWR. This means we put the shutdown flag against it.
1410 struct sctp_tcb *stcb;
1411 struct sctp_association *asoc;
1414 (SS_ISCONNECTED|SS_ISCONNECTING|SS_ISDISCONNECTING)) == 0) {
1415 SCTP_INP_RUNLOCK(inp);
1420 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1423 * Ok we hit the case that the shutdown call was
1424 * made after an abort or something. Nothing to do
1427 SCTP_INP_RUNLOCK(inp);
1430 SCTP_TCB_LOCK(stcb);
1432 if (TAILQ_EMPTY(&asoc->send_queue) &&
1433 TAILQ_EMPTY(&asoc->sent_queue) &&
1434 (asoc->stream_queue_cnt == 0)) {
1435 if (asoc->locked_on_sending) {
1438 /* there is nothing queued to send, so I'm done... */
1439 if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) {
1440 /* only send SHUTDOWN the first time through */
1441 struct sctp_nets *netp;
1443 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
1444 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
1445 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1447 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
1448 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
1449 sctp_stop_timers_for_shutdown(stcb);
1450 if (stcb->asoc.alternate) {
1451 netp = stcb->asoc.alternate;
1453 netp = stcb->asoc.primary_destination;
1455 sctp_send_shutdown(stcb, netp);
1456 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1457 stcb->sctp_ep, stcb, netp);
1458 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1459 stcb->sctp_ep, stcb, netp);
1460 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
1464 * we still got (or just got) data to send, so set
1467 struct sctp_nets *netp;
1468 if (stcb->asoc.alternate) {
1469 netp = stcb->asoc.alternate;
1471 netp = stcb->asoc.primary_destination;
1474 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1475 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
1478 if (asoc->locked_on_sending) {
1479 /* Locked to send out the data */
1480 struct sctp_stream_queue_pending *sp;
1481 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
1483 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
1484 asoc->locked_on_sending->stream_no);
1486 if ((sp->length == 0) && (sp-> msg_is_complete == 0)) {
1487 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
1491 if (TAILQ_EMPTY(&asoc->send_queue) &&
1492 TAILQ_EMPTY(&asoc->sent_queue) &&
1493 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1494 struct mbuf *op_err;
1496 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
1497 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ+SCTP_LOC_6;
1498 sctp_abort_an_association(stcb->sctp_ep, stcb,
1499 op_err, SCTP_SO_LOCKED);
1502 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1505 SCTP_TCB_UNLOCK(stcb);
1508 SCTP_INP_RUNLOCK(inp);
1513 * copies a "user" presentable address and removes embedded scope, etc.
1514 * returns 0 on success, 1 on error
1517 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1520 #if defined(SCTP_EMBEDDED_V6_SCOPE)
1521 struct sockaddr_in6 lsa6;
1523 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1528 memcpy(ss, sa, sa->sa_len);
1530 switch (sa->sa_family) {
1533 memcpy(ss, sa, sizeof(struct sockaddr_in));
1538 memcpy(ss, sa, sizeof(struct sockaddr_in6));
1541 #if defined(__Userspace__)
1543 memcpy(ss, sa, sizeof(struct sockaddr_conn));
1557 * NOTE: assumes addr lock is held
1560 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1561 struct sctp_tcb *stcb,
1563 struct sockaddr_storage *sas,
1566 struct sctp_ifn *sctp_ifn;
1567 struct sctp_ifa *sctp_ifa;
1571 int ipv4_local_scope, ipv4_addr_legal;
1574 int local_scope, site_scope, ipv6_addr_legal;
1576 #if defined(__Userspace__)
1577 int conn_addr_legal;
1579 struct sctp_vrf *vrf;
1586 /* Turn on all the appropriate scope */
1587 loopback_scope = stcb->asoc.scope.loopback_scope;
1589 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1590 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1593 local_scope = stcb->asoc.scope.local_scope;
1594 site_scope = stcb->asoc.scope.site_scope;
1595 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1597 #if defined(__Userspace__)
1598 conn_addr_legal = stcb->asoc.scope.conn_addr_legal;
1601 /* Use generic values for endpoints. */
1604 ipv4_local_scope = 1;
1610 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1612 ipv6_addr_legal = 1;
1615 if (SCTP_IPV6_V6ONLY(inp)) {
1616 ipv4_addr_legal = 0;
1618 ipv4_addr_legal = 1;
1621 #if defined(__Userspace__)
1622 conn_addr_legal = 0;
1626 ipv6_addr_legal = 0;
1628 #if defined(__Userspace__)
1629 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_CONN) {
1630 conn_addr_legal = 1;
1632 ipv4_addr_legal = 0;
1635 conn_addr_legal = 0;
1637 ipv4_addr_legal = 1;
1642 ipv4_addr_legal = 1;
1647 vrf = sctp_find_vrf(vrf_id);
1651 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1652 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1653 if ((loopback_scope == 0) &&
1654 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1655 /* Skip loopback if loopback_scope not set */
1658 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1661 * For the BOUND-ALL case, the list
1662 * associated with a TCB is Always
1663 * considered a reverse list.. i.e.
1664 * it lists addresses that are NOT
1665 * part of the association. If this
1666 * is one of those we must skip it.
1668 if (sctp_is_addr_restricted(stcb,
1673 switch (sctp_ifa->address.sa.sa_family) {
1676 if (ipv4_addr_legal) {
1677 struct sockaddr_in *sin;
1679 sin = (struct sockaddr_in *)&sctp_ifa->address.sa;
1680 if (sin->sin_addr.s_addr == 0) {
1682 * we skip unspecifed
1687 #if defined(__FreeBSD__)
1688 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1689 &sin->sin_addr) != 0) {
1693 if ((ipv4_local_scope == 0) &&
1694 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1698 if (sctp_is_feature_on(inp,SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1699 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1700 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1701 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1702 actual += sizeof(struct sockaddr_in6);
1705 memcpy(sas, sin, sizeof(*sin));
1706 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1707 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1708 actual += sizeof(*sin);
1712 if (actual >= limit) {
1722 if (ipv6_addr_legal) {
1723 struct sockaddr_in6 *sin6;
1725 #if defined(SCTP_EMBEDDED_V6_SCOPE) && !defined(SCTP_KAME)
1726 struct sockaddr_in6 lsa6;
1728 sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sa;
1729 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1731 * we skip unspecifed
1736 #if defined(__FreeBSD__)
1737 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1738 &sin6->sin6_addr) != 0) {
1742 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1743 if (local_scope == 0)
1745 #if defined(SCTP_EMBEDDED_V6_SCOPE)
1746 if (sin6->sin6_scope_id == 0) {
1748 if (sa6_recoverscope(sin6) != 0)
1757 if (in6_recoverscope(&lsa6,
1767 #endif /* SCTP_KAME */
1769 #endif /* SCTP_EMBEDDED_V6_SCOPE */
1771 if ((site_scope == 0) &&
1772 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1775 memcpy(sas, sin6, sizeof(*sin6));
1776 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1777 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1778 actual += sizeof(*sin6);
1779 if (actual >= limit) {
1787 #if defined(__Userspace__)
1789 if (conn_addr_legal) {
1790 memcpy(sas, &sctp_ifa->address.sconn, sizeof(struct sockaddr_conn));
1791 ((struct sockaddr_conn *)sas)->sconn_port = inp->sctp_lport;
1792 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_conn));
1793 actual += sizeof(struct sockaddr_conn);
1794 if (actual >= limit) {
1808 struct sctp_laddr *laddr;
1810 uint32_t sa_len = 0;
1813 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1815 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1819 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1821 switch (laddr->ifa->address.sa.sa_family) {
1824 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1829 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1832 #if defined(__Userspace__)
1834 ((struct sockaddr_conn *)sas)->sconn_port = inp->sctp_lport;
1842 sas = (struct sockaddr_storage *)((caddr_t)sas +
1843 laddr->ifa->address.sa.sa_len);
1844 actual += laddr->ifa->address.sa.sa_len;
1846 switch (laddr->ifa->address.sa.sa_family) {
1849 sa_len = sizeof(struct sockaddr_in);
1854 sa_len = sizeof(struct sockaddr_in6);
1857 #if defined(__Userspace__)
1859 sa_len = sizeof(struct sockaddr_conn);
1866 sas = (struct sockaddr_storage *)((caddr_t)sas + sa_len);
1869 if (actual >= limit) {
1878 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1879 struct sctp_tcb *stcb,
1881 struct sockaddr_storage *sas)
1888 SCTP_IPI_ADDR_RLOCK();
1891 * FIX ME: ?? this WILL report duplicate addresses if they appear
1892 * in more than one VRF.
1894 /* fill up addresses for all VRFs on the endpoint */
1895 for (id = 0; (id < inp->num_vrfs) && (size < limit); id++) {
1896 size += sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1897 inp->m_vrf_ids[id]);
1898 sas = (struct sockaddr_storage *)((caddr_t)sas + size);
1901 /* fill up addresses for the endpoint's default vrf */
1902 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1905 SCTP_IPI_ADDR_RUNLOCK();
1910 * NOTE: assumes addr lock is held
1913 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1916 struct sctp_vrf *vrf = NULL;
1919 * In both sub-set bound an bound_all cases we return the MAXIMUM
1920 * number of addresses that you COULD get. In reality the sub-set
1921 * bound may have an exclusion list for a given TCB OR in the
1922 * bound-all case a TCB may NOT include the loopback or other
1923 * addresses as well.
1925 vrf = sctp_find_vrf(vrf_id);
1929 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1930 struct sctp_ifn *sctp_ifn;
1931 struct sctp_ifa *sctp_ifa;
1933 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1934 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1935 /* Count them if they are the right type */
1936 switch (sctp_ifa->address.sa.sa_family) {
1939 if (sctp_is_feature_on(inp,SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1940 cnt += sizeof(struct sockaddr_in6);
1942 cnt += sizeof(struct sockaddr_in);
1947 cnt += sizeof(struct sockaddr_in6);
1950 #if defined(__Userspace__)
1952 cnt += sizeof(struct sockaddr_conn);
1961 struct sctp_laddr *laddr;
1963 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1964 switch (laddr->ifa->address.sa.sa_family) {
1967 if (sctp_is_feature_on(inp,SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1968 cnt += sizeof(struct sockaddr_in6);
1970 cnt += sizeof(struct sockaddr_in);
1975 cnt += sizeof(struct sockaddr_in6);
1978 #if defined(__Userspace__)
1980 cnt += sizeof(struct sockaddr_conn);
1992 sctp_count_max_addresses(struct sctp_inpcb *inp)
1999 SCTP_IPI_ADDR_RLOCK();
2002 * FIX ME: ?? this WILL count duplicate addresses if they appear
2003 * in more than one VRF.
2005 /* count addresses for all VRFs on the endpoint */
2006 for (id = 0; id < inp->num_vrfs; id++) {
2007 cnt += sctp_count_max_addresses_vrf(inp, inp->m_vrf_ids[id]);
2010 /* count addresses for the endpoint's default VRF */
2011 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
2013 SCTP_IPI_ADDR_RUNLOCK();
2018 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
2019 size_t optsize, void *p, int delay)
2022 int creat_lock_on = 0;
2023 struct sctp_tcb *stcb = NULL;
2024 struct sockaddr *sa;
2025 int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
2027 int bad_addresses = 0;
2030 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
2032 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
2033 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
2034 /* We are already connected AND the TCP model */
2035 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
2036 return (EADDRINUSE);
2039 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
2040 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
2041 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2045 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
2046 SCTP_INP_RLOCK(inp);
2047 stcb = LIST_FIRST(&inp->sctp_asoc_list);
2048 SCTP_INP_RUNLOCK(inp);
2051 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
2054 SCTP_INP_INCR_REF(inp);
2055 SCTP_ASOC_CREATE_LOCK(inp);
2057 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
2058 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
2059 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
2063 totaddrp = (int *)optval;
2064 totaddr = *totaddrp;
2065 sa = (struct sockaddr *)(totaddrp + 1);
2066 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (optsize - sizeof(int)), &bad_addresses);
2067 if ((stcb != NULL) || bad_addresses) {
2068 /* Already have or am bring up an association */
2069 SCTP_ASOC_CREATE_UNLOCK(inp);
2072 SCTP_TCB_UNLOCK(stcb);
2073 if (bad_addresses == 0) {
2074 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
2080 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
2085 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2087 struct in6pcb *inp6;
2089 inp6 = (struct in6pcb *)inp;
2090 if (SCTP_IPV6_V6ONLY(inp6)) {
2092 * if IPV6_V6ONLY flag, ignore connections destined
2093 * to a v4 addr or v4-mapped addr
2095 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2101 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
2102 SCTP_PCB_FLAGS_UNBOUND) {
2103 /* Bind a ephemeral port */
2104 error = sctp_inpcb_bind(so, NULL, NULL, p);
2110 /* FIX ME: do we want to pass in a vrf on the connect call? */
2111 vrf_id = inp->def_vrf_id;
2114 /* We are GOOD to go */
2115 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
2116 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
2118 #elif defined(__Windows__)
2125 /* Gak! no memory */
2128 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
2129 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
2130 /* Set the connected flag so we can queue data */
2133 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
2134 /* move to second address */
2135 switch (sa->sa_family) {
2138 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
2143 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
2151 sctp_connectx_helper_add(stcb, sa, (totaddr-1), &error);
2152 /* Fill in the return id */
2154 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE, SCTP_FROM_SCTP_USRREQ+SCTP_LOC_6);
2157 a_id = (sctp_assoc_t *)optval;
2158 *a_id = sctp_get_associd(stcb);
2160 /* initialize authentication parameters for the assoc */
2161 sctp_initialize_auth_params(inp, stcb);
2164 /* doing delayed connection */
2165 stcb->asoc.delayed_connection = 1;
2166 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
2168 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
2169 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
2171 SCTP_TCB_UNLOCK(stcb);
2172 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
2173 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
2174 /* Set the connected flag so we can queue data */
2178 if (creat_lock_on) {
2179 SCTP_ASOC_CREATE_UNLOCK(inp);
2181 SCTP_INP_DECR_REF(inp);
2185 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
2186 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
2187 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
2188 SCTP_INP_RLOCK(inp); \
2189 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
2191 SCTP_TCB_LOCK(stcb); \
2193 SCTP_INP_RUNLOCK(inp); \
2194 } else if (assoc_id > SCTP_ALL_ASSOC) { \
2195 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
2196 if (stcb == NULL) { \
2197 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
2207 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
2208 if (size < sizeof(type)) { \
2209 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
2213 destp = (type *)srcp; \
2217 #if defined(__Panda__) || defined(__Userspace__)
2222 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
2224 struct sctp_inpcb *inp = NULL;
2226 struct sctp_tcb *stcb = NULL;
2228 if (optval == NULL) {
2229 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2233 inp = (struct sctp_inpcb *)so->so_pcb;
2235 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2242 case SCTP_AUTOCLOSE:
2243 case SCTP_EXPLICIT_EOR:
2244 case SCTP_AUTO_ASCONF:
2245 case SCTP_DISABLE_FRAGMENTS:
2246 case SCTP_I_WANT_MAPPED_V4_ADDR:
2247 case SCTP_USE_EXT_RCVINFO:
2248 SCTP_INP_RLOCK(inp);
2250 case SCTP_DISABLE_FRAGMENTS:
2251 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
2253 case SCTP_I_WANT_MAPPED_V4_ADDR:
2254 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
2256 case SCTP_AUTO_ASCONF:
2257 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
2258 /* only valid for bound all sockets */
2259 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
2261 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2266 case SCTP_EXPLICIT_EOR:
2267 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
2270 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
2272 case SCTP_USE_EXT_RCVINFO:
2273 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
2275 case SCTP_AUTOCLOSE:
2276 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
2277 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
2283 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
2284 error = ENOPROTOOPT;
2285 } /* end switch (sopt->sopt_name) */
2286 if (*optsize < sizeof(val)) {
2287 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2291 SCTP_INP_RUNLOCK(inp);
2293 /* return the option value */
2294 *(int *)optval = val;
2295 *optsize = sizeof(val);
2298 case SCTP_GET_PACKET_LOG:
2300 #ifdef SCTP_PACKET_LOGGING
2304 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
2305 ret = sctp_copy_out_packet_log(target , (int)*optsize);
2308 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
2313 case SCTP_REUSE_PORT:
2317 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
2318 /* Can't do this for a 1-m socket */
2322 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2323 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
2324 *optsize = sizeof(uint32_t);
2327 case SCTP_PARTIAL_DELIVERY_POINT:
2331 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2332 *value = inp->partial_delivery_point;
2333 *optsize = sizeof(uint32_t);
2336 case SCTP_FRAGMENT_INTERLEAVE:
2340 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2341 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
2342 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
2343 *value = SCTP_FRAG_LEVEL_2;
2345 *value = SCTP_FRAG_LEVEL_1;
2348 *value = SCTP_FRAG_LEVEL_0;
2350 *optsize = sizeof(uint32_t);
2353 case SCTP_CMT_ON_OFF:
2355 struct sctp_assoc_value *av;
2357 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2358 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2360 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
2361 SCTP_TCB_UNLOCK(stcb);
2363 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2364 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2365 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2366 SCTP_INP_RLOCK(inp);
2367 av->assoc_value = inp->sctp_cmt_on_off;
2368 SCTP_INP_RUNLOCK(inp);
2370 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2375 *optsize = sizeof(struct sctp_assoc_value);
2379 case SCTP_PLUGGABLE_CC:
2381 struct sctp_assoc_value *av;
2383 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2384 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2386 av->assoc_value = stcb->asoc.congestion_control_module;
2387 SCTP_TCB_UNLOCK(stcb);
2389 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2390 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2391 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2392 SCTP_INP_RLOCK(inp);
2393 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
2394 SCTP_INP_RUNLOCK(inp);
2396 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2401 *optsize = sizeof(struct sctp_assoc_value);
2405 case SCTP_CC_OPTION:
2407 struct sctp_cc_option *cc_opt;
2409 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
2410 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
2414 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
2417 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option)(stcb, 0, cc_opt);
2418 *optsize = sizeof(struct sctp_cc_option);
2420 SCTP_TCB_UNLOCK(stcb);
2424 case SCTP_PLUGGABLE_SS:
2426 struct sctp_assoc_value *av;
2428 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2429 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2431 av->assoc_value = stcb->asoc.stream_scheduling_module;
2432 SCTP_TCB_UNLOCK(stcb);
2434 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2435 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2436 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2437 SCTP_INP_RLOCK(inp);
2438 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
2439 SCTP_INP_RUNLOCK(inp);
2441 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2446 *optsize = sizeof(struct sctp_assoc_value);
2452 struct sctp_stream_value *av;
2454 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
2455 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2457 if (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
2458 &av->stream_value) < 0) {
2459 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2462 *optsize = sizeof(struct sctp_stream_value);
2464 SCTP_TCB_UNLOCK(stcb);
2466 /* Can't get stream value without association */
2467 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2472 case SCTP_GET_ADDR_LEN:
2474 struct sctp_assoc_value *av;
2476 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2479 if (av->assoc_value == AF_INET) {
2480 av->assoc_value = sizeof(struct sockaddr_in);
2485 if (av->assoc_value == AF_INET6) {
2486 av->assoc_value = sizeof(struct sockaddr_in6);
2490 #if defined(__Userspace__)
2491 if (av->assoc_value == AF_CONN) {
2492 av->assoc_value = sizeof(struct sockaddr_conn);
2497 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2499 *optsize = sizeof(struct sctp_assoc_value);
2503 case SCTP_GET_ASSOC_NUMBER:
2505 uint32_t *value, cnt;
2507 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2509 SCTP_INP_RLOCK(inp);
2510 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
2513 SCTP_INP_RUNLOCK(inp);
2515 *optsize = sizeof(uint32_t);
2518 case SCTP_GET_ASSOC_ID_LIST:
2520 struct sctp_assoc_ids *ids;
2521 unsigned int at, limit;
2523 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
2525 limit = (*optsize-sizeof(uint32_t))/ sizeof(sctp_assoc_t);
2526 SCTP_INP_RLOCK(inp);
2527 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
2529 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
2532 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2536 SCTP_INP_RUNLOCK(inp);
2538 ids->gaids_number_of_ids = at;
2539 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
2545 struct sctp_assoc_value *av;
2547 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2548 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2551 av->assoc_value = stcb->asoc.context;
2552 SCTP_TCB_UNLOCK(stcb);
2554 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2555 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2556 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2557 SCTP_INP_RLOCK(inp);
2558 av->assoc_value = inp->sctp_context;
2559 SCTP_INP_RUNLOCK(inp);
2561 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2566 *optsize = sizeof(struct sctp_assoc_value);
2572 uint32_t *default_vrfid;
2574 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
2575 *default_vrfid = inp->def_vrf_id;
2576 *optsize = sizeof(uint32_t);
2579 case SCTP_GET_ASOC_VRF:
2581 struct sctp_assoc_value *id;
2583 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
2584 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
2587 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2589 id->assoc_value = stcb->asoc.vrf_id;
2590 *optsize = sizeof(struct sctp_assoc_value);
2594 case SCTP_GET_VRF_IDS:
2600 SCTP_CHECK_AND_CAST(vrf_ids, optval, uint32_t, *optsize);
2601 siz_needed = inp->num_vrfs * sizeof(uint32_t);
2602 if (*optsize < siz_needed) {
2604 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2606 memcpy(vrf_ids, inp->m_vrf_ids, siz_needed);
2607 *optsize = siz_needed;
2610 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
2615 case SCTP_GET_NONCE_VALUES:
2617 struct sctp_get_nonce_values *gnv;
2619 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
2620 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
2623 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
2624 gnv->gn_local_tag = stcb->asoc.my_vtag;
2625 SCTP_TCB_UNLOCK(stcb);
2626 *optsize = sizeof(struct sctp_get_nonce_values);
2628 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2633 case SCTP_DELAYED_SACK:
2635 struct sctp_sack_info *sack;
2637 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2638 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2640 sack->sack_delay = stcb->asoc.delayed_ack;
2641 sack->sack_freq = stcb->asoc.sack_freq;
2642 SCTP_TCB_UNLOCK(stcb);
2644 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2645 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2646 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2647 SCTP_INP_RLOCK(inp);
2648 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2649 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2650 SCTP_INP_RUNLOCK(inp);
2652 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2657 *optsize = sizeof(struct sctp_sack_info);
2661 case SCTP_GET_SNDBUF_USE:
2663 struct sctp_sockstat *ss;
2665 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2666 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2669 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2670 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2671 stcb->asoc.size_on_all_streams);
2672 SCTP_TCB_UNLOCK(stcb);
2673 *optsize = sizeof(struct sctp_sockstat);
2675 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2680 case SCTP_MAX_BURST:
2682 #if defined(__FreeBSD__) && __FreeBSD_version < 900000
2685 SCTP_CHECK_AND_CAST(value, optval, uint8_t, *optsize);
2687 SCTP_INP_RLOCK(inp);
2688 if (inp->sctp_ep.max_burst < 256) {
2689 *value = inp->sctp_ep.max_burst;
2693 SCTP_INP_RUNLOCK(inp);
2694 *optsize = sizeof(uint8_t);
2696 struct sctp_assoc_value *av;
2698 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2699 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2702 av->assoc_value = stcb->asoc.max_burst;
2703 SCTP_TCB_UNLOCK(stcb);
2705 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2706 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2707 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2708 SCTP_INP_RLOCK(inp);
2709 av->assoc_value = inp->sctp_ep.max_burst;
2710 SCTP_INP_RUNLOCK(inp);
2712 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2717 *optsize = sizeof(struct sctp_assoc_value);
2724 struct sctp_assoc_value *av;
2727 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2728 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2731 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2732 SCTP_TCB_UNLOCK(stcb);
2734 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2735 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2736 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2737 SCTP_INP_RLOCK(inp);
2738 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2739 ovh = SCTP_MED_OVERHEAD;
2741 ovh = SCTP_MED_V4_OVERHEAD;
2743 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2744 av->assoc_value = 0;
2746 av->assoc_value = inp->sctp_frag_point - ovh;
2747 SCTP_INP_RUNLOCK(inp);
2749 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2754 *optsize = sizeof(struct sctp_assoc_value);
2758 case SCTP_GET_STAT_LOG:
2759 error = sctp_fill_stat_log(optval, optsize);
2763 struct sctp_event_subscribe *events;
2765 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2766 memset(events, 0, sizeof(struct sctp_event_subscribe));
2767 SCTP_INP_RLOCK(inp);
2768 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2769 events->sctp_data_io_event = 1;
2771 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2772 events->sctp_association_event = 1;
2774 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2775 events->sctp_address_event = 1;
2777 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2778 events->sctp_send_failure_event = 1;
2780 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2781 events->sctp_peer_error_event = 1;
2783 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2784 events->sctp_shutdown_event = 1;
2786 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2787 events->sctp_partial_delivery_event = 1;
2789 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2790 events->sctp_adaptation_layer_event = 1;
2792 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2793 events->sctp_authentication_event = 1;
2795 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2796 events->sctp_sender_dry_event = 1;
2798 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2799 events->sctp_stream_reset_event = 1;
2800 SCTP_INP_RUNLOCK(inp);
2801 *optsize = sizeof(struct sctp_event_subscribe);
2804 case SCTP_ADAPTATION_LAYER:
2808 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2810 SCTP_INP_RLOCK(inp);
2811 *value = inp->sctp_ep.adaptation_layer_indicator;
2812 SCTP_INP_RUNLOCK(inp);
2813 *optsize = sizeof(uint32_t);
2816 case SCTP_SET_INITIAL_DBG_SEQ:
2820 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2821 SCTP_INP_RLOCK(inp);
2822 *value = inp->sctp_ep.initial_sequence_debug;
2823 SCTP_INP_RUNLOCK(inp);
2824 *optsize = sizeof(uint32_t);
2827 case SCTP_GET_LOCAL_ADDR_SIZE:
2831 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2832 SCTP_INP_RLOCK(inp);
2833 *value = sctp_count_max_addresses(inp);
2834 SCTP_INP_RUNLOCK(inp);
2835 *optsize = sizeof(uint32_t);
2838 case SCTP_GET_REMOTE_ADDR_SIZE:
2842 struct sctp_nets *net;
2844 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2845 /* FIXME MT: change to sctp_assoc_value? */
2846 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) *value);
2850 /* Count the sizes */
2851 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2852 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2853 size += sizeof(struct sockaddr_in6);
2855 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2858 size += sizeof(struct sockaddr_in);
2863 size += sizeof(struct sockaddr_in6);
2866 #if defined(__Userspace__)
2868 size += sizeof(struct sockaddr_conn);
2876 SCTP_TCB_UNLOCK(stcb);
2877 *value = (uint32_t) size;
2878 *optsize = sizeof(uint32_t);
2880 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2885 case SCTP_GET_PEER_ADDRESSES:
2887 * Get the address information, an array is passed in to
2888 * fill up we pack it.
2892 struct sockaddr_storage *sas;
2893 struct sctp_nets *net;
2894 struct sctp_getaddresses *saddr;
2896 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2897 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2900 left = (*optsize) - sizeof(struct sctp_getaddresses);
2901 *optsize = sizeof(struct sctp_getaddresses);
2902 sas = (struct sockaddr_storage *)&saddr->addr[0];
2904 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2905 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2906 cpsz = sizeof(struct sockaddr_in6);
2908 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2911 cpsz = sizeof(struct sockaddr_in);
2916 cpsz = sizeof(struct sockaddr_in6);
2919 #if defined(__Userspace__)
2921 cpsz = sizeof(struct sockaddr_conn);
2933 /* not enough room. */
2936 #if defined(INET) && defined(INET6)
2937 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2938 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
2939 /* Must map the address */
2940 in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
2941 (struct sockaddr_in6 *)sas);
2944 memcpy(sas, &net->ro._l_addr, cpsz);
2945 #if defined(INET) && defined(INET6)
2948 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2950 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2954 SCTP_TCB_UNLOCK(stcb);
2956 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2961 case SCTP_GET_LOCAL_ADDRESSES:
2963 size_t limit, actual;
2964 struct sockaddr_storage *sas;
2965 struct sctp_getaddresses *saddr;
2967 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2968 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2970 sas = (struct sockaddr_storage *)&saddr->addr[0];
2971 limit = *optsize - sizeof(sctp_assoc_t);
2972 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2974 SCTP_TCB_UNLOCK(stcb);
2976 *optsize = sizeof(struct sockaddr_storage) + actual;
2979 case SCTP_PEER_ADDR_PARAMS:
2981 struct sctp_paddrparams *paddrp;
2982 struct sctp_nets *net;
2984 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2985 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2989 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2991 /* We increment here since sctp_findassociation_ep_addr() wil
2992 * do a decrement if it finds the stcb as long as the locked
2993 * tcb (last argument) is NOT a TCB.. aka NULL.
2995 SCTP_INP_INCR_REF(inp);
2996 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddrp->spp_address, &net, NULL, NULL);
2998 SCTP_INP_DECR_REF(inp);
3001 if (stcb && (net == NULL)) {
3002 struct sockaddr *sa;
3004 sa = (struct sockaddr *)&paddrp->spp_address;
3006 if (sa->sa_family == AF_INET) {
3007 struct sockaddr_in *sin;
3009 sin = (struct sockaddr_in *)sa;
3010 if (sin->sin_addr.s_addr) {
3012 SCTP_TCB_UNLOCK(stcb);
3013 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3019 if (sa->sa_family == AF_INET6) {
3020 struct sockaddr_in6 *sin6;
3022 sin6 = (struct sockaddr_in6 *)sa;
3023 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3025 SCTP_TCB_UNLOCK(stcb);
3026 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3031 #if defined(__Userspace__)
3032 if (sa->sa_family == AF_CONN) {
3033 struct sockaddr_conn *sconn;
3035 sconn = (struct sockaddr_conn *)sa;
3036 if (sconn->sconn_addr != NULL) {
3038 SCTP_TCB_UNLOCK(stcb);
3039 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3045 error = EAFNOSUPPORT;
3046 SCTP_TCB_UNLOCK(stcb);
3047 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3053 /* Applies to the specific association */
3054 paddrp->spp_flags = 0;
3057 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3058 ovh = SCTP_MED_OVERHEAD;
3060 ovh = SCTP_MED_V4_OVERHEAD;
3063 paddrp->spp_hbinterval = net->heart_beat_delay;
3064 paddrp->spp_pathmaxrxt = net->failure_threshold;
3065 paddrp->spp_pathmtu = net->mtu - ovh;
3066 /* get flags for HB */
3067 if (net->dest_state & SCTP_ADDR_NOHB) {
3068 paddrp->spp_flags |= SPP_HB_DISABLE;
3070 paddrp->spp_flags |= SPP_HB_ENABLE;
3072 /* get flags for PMTU */
3073 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
3074 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
3076 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
3078 if (net->dscp & 0x01) {
3079 paddrp->spp_dscp = net->dscp & 0xfc;
3080 paddrp->spp_flags |= SPP_DSCP;
3083 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
3084 (net->flowlabel & 0x80000000)) {
3085 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
3086 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
3091 * No destination so return default
3094 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
3095 paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
3096 if (stcb->asoc.default_dscp & 0x01) {
3097 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
3098 paddrp->spp_flags |= SPP_DSCP;
3101 if (stcb->asoc.default_flowlabel & 0x80000000) {
3102 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
3103 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
3106 /* default settings should be these */
3107 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
3108 paddrp->spp_flags |= SPP_HB_DISABLE;
3110 paddrp->spp_flags |= SPP_HB_ENABLE;
3112 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
3113 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
3115 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
3117 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
3119 paddrp->spp_assoc_id = sctp_get_associd(stcb);
3120 SCTP_TCB_UNLOCK(stcb);
3122 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3123 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3124 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
3125 /* Use endpoint defaults */
3126 SCTP_INP_RLOCK(inp);
3127 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
3128 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
3129 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
3130 /* get inp's default */
3131 if (inp->sctp_ep.default_dscp & 0x01) {
3132 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
3133 paddrp->spp_flags |= SPP_DSCP;
3136 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
3137 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
3138 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
3139 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
3142 /* can't return this */
3143 paddrp->spp_pathmtu = 0;
3145 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
3146 paddrp->spp_flags |= SPP_HB_ENABLE;
3148 paddrp->spp_flags |= SPP_HB_DISABLE;
3150 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
3151 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
3153 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
3155 SCTP_INP_RUNLOCK(inp);
3157 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3162 *optsize = sizeof(struct sctp_paddrparams);
3166 case SCTP_GET_PEER_ADDR_INFO:
3168 struct sctp_paddrinfo *paddri;
3169 struct sctp_nets *net;
3171 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
3172 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
3176 net = sctp_findnet(stcb, (struct sockaddr *)&paddri->spinfo_address);
3178 /* We increment here since sctp_findassociation_ep_addr() wil
3179 * do a decrement if it finds the stcb as long as the locked
3180 * tcb (last argument) is NOT a TCB.. aka NULL.
3182 SCTP_INP_INCR_REF(inp);
3183 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddri->spinfo_address, &net, NULL, NULL);
3185 SCTP_INP_DECR_REF(inp);
3189 if ((stcb) && (net)) {
3190 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
3191 /* It's unconfirmed */
3192 paddri->spinfo_state = SCTP_UNCONFIRMED;
3193 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
3195 paddri->spinfo_state = SCTP_ACTIVE;
3198 paddri->spinfo_state = SCTP_INACTIVE;
3200 paddri->spinfo_cwnd = net->cwnd;
3201 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
3202 paddri->spinfo_rto = net->RTO;
3203 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
3204 paddri->spinfo_mtu = net->mtu;
3205 SCTP_TCB_UNLOCK(stcb);
3206 *optsize = sizeof(struct sctp_paddrinfo);
3209 SCTP_TCB_UNLOCK(stcb);
3211 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3216 case SCTP_PCB_STATUS:
3218 struct sctp_pcbinfo *spcb;
3220 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
3221 sctp_fill_pcbinfo(spcb);
3222 *optsize = sizeof(struct sctp_pcbinfo);
3227 struct sctp_nets *net;
3228 struct sctp_status *sstat;
3230 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
3231 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
3234 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3239 * I think passing the state is fine since
3240 * sctp_constants.h will be available to the user
3243 sstat->sstat_state = stcb->asoc.state;
3244 sstat->sstat_assoc_id = sctp_get_associd(stcb);
3245 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
3246 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
3248 * We can't include chunks that have been passed to
3249 * the socket layer. Only things in queue.
3251 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
3252 stcb->asoc.cnt_on_all_streams);
3255 sstat->sstat_instrms = stcb->asoc.streamincnt;
3256 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
3257 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
3259 memcpy(&sstat->sstat_primary.spinfo_address,
3260 &stcb->asoc.primary_destination->ro._l_addr,
3261 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
3263 if (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family == AF_INET) {
3264 memcpy(&sstat->sstat_primary.spinfo_address,
3265 &stcb->asoc.primary_destination->ro._l_addr,
3266 sizeof(struct sockaddr_in));
3268 memcpy(&sstat->sstat_primary.spinfo_address,
3269 &stcb->asoc.primary_destination->ro._l_addr,
3270 sizeof(struct sockaddr_in6));
3273 net = stcb->asoc.primary_destination;
3274 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
3276 * Again the user can get info from sctp_constants.h
3277 * for what the state of the network is.
3279 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
3280 /* It's unconfirmed */
3281 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
3282 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
3284 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
3287 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
3289 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
3290 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
3291 sstat->sstat_primary.spinfo_rto = net->RTO;
3292 sstat->sstat_primary.spinfo_mtu = net->mtu;
3293 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
3294 SCTP_TCB_UNLOCK(stcb);
3295 *optsize = sizeof(struct sctp_status);
3300 struct sctp_rtoinfo *srto;
3302 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
3303 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
3306 srto->srto_initial = stcb->asoc.initial_rto;
3307 srto->srto_max = stcb->asoc.maxrto;
3308 srto->srto_min = stcb->asoc.minrto;
3309 SCTP_TCB_UNLOCK(stcb);
3311 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3312 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3313 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
3314 SCTP_INP_RLOCK(inp);
3315 srto->srto_initial = inp->sctp_ep.initial_rto;
3316 srto->srto_max = inp->sctp_ep.sctp_maxrto;
3317 srto->srto_min = inp->sctp_ep.sctp_minrto;
3318 SCTP_INP_RUNLOCK(inp);
3320 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3325 *optsize = sizeof(struct sctp_rtoinfo);
3331 struct sctp_timeouts *stimo;
3333 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
3334 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
3337 stimo->stimo_init= stcb->asoc.timoinit;
3338 stimo->stimo_data= stcb->asoc.timodata;
3339 stimo->stimo_sack= stcb->asoc.timosack;
3340 stimo->stimo_shutdown= stcb->asoc.timoshutdown;
3341 stimo->stimo_heartbeat= stcb->asoc.timoheartbeat;
3342 stimo->stimo_cookie= stcb->asoc.timocookie;
3343 stimo->stimo_shutdownack= stcb->asoc.timoshutdownack;
3344 SCTP_TCB_UNLOCK(stcb);
3345 *optsize = sizeof(struct sctp_timeouts);
3347 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3352 case SCTP_ASSOCINFO:
3354 struct sctp_assocparams *sasoc;
3356 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
3357 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
3360 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
3361 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
3362 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
3363 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
3364 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
3365 SCTP_TCB_UNLOCK(stcb);
3367 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3368 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3369 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
3370 SCTP_INP_RLOCK(inp);
3371 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
3372 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
3373 sasoc->sasoc_number_peer_destinations = 0;
3374 sasoc->sasoc_peer_rwnd = 0;
3375 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
3376 SCTP_INP_RUNLOCK(inp);
3378 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3383 *optsize = sizeof(struct sctp_assocparams);
3387 case SCTP_DEFAULT_SEND_PARAM:
3389 struct sctp_sndrcvinfo *s_info;
3391 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
3392 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
3395 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
3396 SCTP_TCB_UNLOCK(stcb);
3398 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3399 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3400 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
3401 SCTP_INP_RLOCK(inp);
3402 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
3403 SCTP_INP_RUNLOCK(inp);
3405 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3410 *optsize = sizeof(struct sctp_sndrcvinfo);
3416 struct sctp_initmsg *sinit;
3418 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
3419 SCTP_INP_RLOCK(inp);
3420 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
3421 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
3422 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
3423 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
3424 SCTP_INP_RUNLOCK(inp);
3425 *optsize = sizeof(struct sctp_initmsg);
3428 case SCTP_PRIMARY_ADDR:
3429 /* we allow a "get" operation on this */
3431 struct sctp_setprim *ssp;
3433 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
3434 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
3437 /* simply copy out the sockaddr_storage... */
3442 if (len > stcb->asoc.primary_destination->ro._l_addr.sa.sa_len)
3443 len = stcb->asoc.primary_destination->ro._l_addr.sa.sa_len;
3445 if (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family == AF_INET &&
3446 len > sizeof(struct sockaddr_in))
3447 len = sizeof(struct sockaddr_in);
3449 stcb->asoc.primary_destination->ro._l_addr.sa.sa_family == AF_INET6 &&
3450 len > sizeof(struct sockaddr_in6))
3451 len = sizeof(struct sockaddr_in6);
3454 memcpy(&ssp->ssp_addr,
3455 &stcb->asoc.primary_destination->ro._l_addr,
3457 SCTP_TCB_UNLOCK(stcb);
3458 *optsize = sizeof(struct sctp_setprim);
3460 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3465 case SCTP_HMAC_IDENT:
3467 struct sctp_hmacalgo *shmac;
3468 sctp_hmaclist_t *hmaclist;
3472 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
3474 SCTP_INP_RLOCK(inp);
3475 hmaclist = inp->sctp_ep.local_hmacs;
3476 if (hmaclist == NULL) {
3477 /* no HMACs to return */
3478 *optsize = sizeof(*shmac);
3479 SCTP_INP_RUNLOCK(inp);
3482 /* is there room for all of the hmac ids? */
3483 size = sizeof(*shmac) + (hmaclist->num_algo *
3484 sizeof(shmac->shmac_idents[0]));
3485 if ((size_t)(*optsize) < size) {
3486 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3488 SCTP_INP_RUNLOCK(inp);
3491 /* copy in the list */
3492 shmac->shmac_number_of_idents = hmaclist->num_algo;
3493 for (i = 0; i < hmaclist->num_algo; i++) {
3494 shmac->shmac_idents[i] = hmaclist->hmac[i];
3496 SCTP_INP_RUNLOCK(inp);
3500 case SCTP_AUTH_ACTIVE_KEY:
3502 struct sctp_authkeyid *scact;
3504 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
3505 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
3508 /* get the active key on the assoc */
3509 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
3510 SCTP_TCB_UNLOCK(stcb);
3512 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3513 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3514 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
3515 /* get the endpoint active key */
3516 SCTP_INP_RLOCK(inp);
3517 scact->scact_keynumber = inp->sctp_ep.default_keyid;
3518 SCTP_INP_RUNLOCK(inp);
3520 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3525 *optsize = sizeof(struct sctp_authkeyid);
3529 case SCTP_LOCAL_AUTH_CHUNKS:
3531 struct sctp_authchunks *sac;
3532 sctp_auth_chklist_t *chklist = NULL;
3535 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
3536 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
3539 /* get off the assoc */
3540 chklist = stcb->asoc.local_auth_chunks;
3541 /* is there enough space? */
3542 size = sctp_auth_get_chklist_size(chklist);
3543 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
3545 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3547 /* copy in the chunks */
3548 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
3549 sac->gauth_number_of_chunks = (uint32_t)size;
3550 *optsize = sizeof(struct sctp_authchunks) + size;
3552 SCTP_TCB_UNLOCK(stcb);
3554 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3555 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3556 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
3557 /* get off the endpoint */
3558 SCTP_INP_RLOCK(inp);
3559 chklist = inp->sctp_ep.local_auth_chunks;
3560 /* is there enough space? */
3561 size = sctp_auth_get_chklist_size(chklist);
3562 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
3564 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3566 /* copy in the chunks */
3567 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
3568 sac->gauth_number_of_chunks = (uint32_t)size;
3569 *optsize = sizeof(struct sctp_authchunks) + size;
3571 SCTP_INP_RUNLOCK(inp);
3573 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3579 case SCTP_PEER_AUTH_CHUNKS:
3581 struct sctp_authchunks *sac;
3582 sctp_auth_chklist_t *chklist = NULL;
3585 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
3586 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
3589 /* get off the assoc */
3590 chklist = stcb->asoc.peer_auth_chunks;
3591 /* is there enough space? */
3592 size = sctp_auth_get_chklist_size(chklist);
3593 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
3595 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3597 /* copy in the chunks */
3598 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
3599 sac->gauth_number_of_chunks = (uint32_t)size;
3600 *optsize = sizeof(struct sctp_authchunks) + size;
3602 SCTP_TCB_UNLOCK(stcb);
3604 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3609 #if defined(HAVE_SCTP_PEELOFF_SOCKOPT)
3612 struct sctp_peeloff_opt *peeloff;
3614 SCTP_CHECK_AND_CAST(peeloff, optval, struct sctp_peeloff_opt, *optsize);
3615 /* do the peeloff */
3616 error = sctp_peeloff_option(p, peeloff);
3618 *optsize = sizeof(struct sctp_peeloff_opt);
3622 #endif /* HAVE_SCTP_PEELOFF_SOCKOPT */
3625 struct sctp_event *event;
3626 uint32_t event_type;
3628 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3629 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3631 switch (event->se_type) {
3632 case SCTP_ASSOC_CHANGE:
3633 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3635 case SCTP_PEER_ADDR_CHANGE:
3636 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3638 case SCTP_REMOTE_ERROR:
3639 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3641 case SCTP_SEND_FAILED:
3642 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3644 case SCTP_SHUTDOWN_EVENT:
3645 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3647 case SCTP_ADAPTATION_INDICATION:
3648 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3650 case SCTP_PARTIAL_DELIVERY_EVENT:
3651 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3653 case SCTP_AUTHENTICATION_EVENT:
3654 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3656 case SCTP_STREAM_RESET_EVENT:
3657 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3659 case SCTP_SENDER_DRY_EVENT:
3660 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3662 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3664 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3667 case SCTP_ASSOC_RESET_EVENT:
3668 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3670 case SCTP_STREAM_CHANGE_EVENT:
3671 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3673 case SCTP_SEND_FAILED_EVENT:
3674 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3678 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3682 if (event_type > 0) {
3684 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3685 SCTP_TCB_UNLOCK(stcb);
3687 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3688 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3689 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3690 SCTP_INP_RLOCK(inp);
3691 event->se_on = sctp_is_feature_on(inp, event_type);
3692 SCTP_INP_RUNLOCK(inp);
3694 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3700 *optsize = sizeof(struct sctp_event);
3704 case SCTP_RECVRCVINFO:
3708 if (*optsize < sizeof(int)) {
3709 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3712 SCTP_INP_RLOCK(inp);
3713 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3714 SCTP_INP_RUNLOCK(inp);
3717 /* return the option value */
3718 *(int *)optval = onoff;
3719 *optsize = sizeof(int);
3723 case SCTP_RECVNXTINFO:
3727 if (*optsize < sizeof(int)) {
3728 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3731 SCTP_INP_RLOCK(inp);
3732 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3733 SCTP_INP_RUNLOCK(inp);
3736 /* return the option value */
3737 *(int *)optval = onoff;
3738 *optsize = sizeof(int);
3742 case SCTP_DEFAULT_SNDINFO:
3744 struct sctp_sndinfo *info;
3746 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3747 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3750 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3751 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3752 info->snd_flags &= 0xfff0;
3753 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3754 info->snd_context = stcb->asoc.def_send.sinfo_context;
3755 SCTP_TCB_UNLOCK(stcb);
3757 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3758 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3759 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3760 SCTP_INP_RLOCK(inp);
3761 info->snd_sid = inp->def_send.sinfo_stream;
3762 info->snd_flags = inp->def_send.sinfo_flags;
3763 info->snd_flags &= 0xfff0;
3764 info->snd_ppid = inp->def_send.sinfo_ppid;
3765 info->snd_context = inp->def_send.sinfo_context;
3766 SCTP_INP_RUNLOCK(inp);
3768 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3773 *optsize = sizeof(struct sctp_sndinfo);
3777 case SCTP_DEFAULT_PRINFO:
3779 struct sctp_default_prinfo *info;
3781 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3782 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3785 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3786 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3787 SCTP_TCB_UNLOCK(stcb);
3789 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3790 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3791 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3792 SCTP_INP_RLOCK(inp);
3793 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3794 info->pr_value = inp->def_send.sinfo_timetolive;
3795 SCTP_INP_RUNLOCK(inp);
3797 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3802 *optsize = sizeof(struct sctp_default_prinfo);
3806 case SCTP_PEER_ADDR_THLDS:
3808 struct sctp_paddrthlds *thlds;
3809 struct sctp_nets *net;
3811 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3812 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3816 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_address);
3818 /* We increment here since sctp_findassociation_ep_addr() wil
3819 * do a decrement if it finds the stcb as long as the locked
3820 * tcb (last argument) is NOT a TCB.. aka NULL.
3822 SCTP_INP_INCR_REF(inp);
3823 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&thlds->spt_address, &net, NULL, NULL);
3825 SCTP_INP_DECR_REF(inp);
3828 if (stcb && (net == NULL)) {
3829 struct sockaddr *sa;
3831 sa = (struct sockaddr *)&thlds->spt_address;
3833 if (sa->sa_family == AF_INET) {
3834 struct sockaddr_in *sin;
3836 sin = (struct sockaddr_in *)sa;
3837 if (sin->sin_addr.s_addr) {
3839 SCTP_TCB_UNLOCK(stcb);
3840 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3846 if (sa->sa_family == AF_INET6) {
3847 struct sockaddr_in6 *sin6;
3849 sin6 = (struct sockaddr_in6 *)sa;
3850 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3852 SCTP_TCB_UNLOCK(stcb);
3853 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3858 #if defined(__Userspace__)
3859 if (sa->sa_family == AF_CONN) {
3860 struct sockaddr_conn *sconn;
3862 sconn = (struct sockaddr_conn *)sa;
3863 if (sconn->sconn_addr != NULL) {
3865 SCTP_TCB_UNLOCK(stcb);
3866 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3872 error = EAFNOSUPPORT;
3873 SCTP_TCB_UNLOCK(stcb);
3874 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3881 thlds->spt_pathmaxrxt = net->failure_threshold;
3882 thlds->spt_pathpfthld = net->pf_threshold;
3884 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3885 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3887 thlds->spt_assoc_id = sctp_get_associd(stcb);
3888 SCTP_TCB_UNLOCK(stcb);
3890 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3891 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3892 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3893 /* Use endpoint defaults */
3894 SCTP_INP_RLOCK(inp);
3895 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3896 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3897 SCTP_INP_RUNLOCK(inp);
3899 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3904 *optsize = sizeof(struct sctp_paddrthlds);
3908 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3910 struct sctp_udpencaps *encaps;
3911 struct sctp_nets *net;
3913 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3914 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3917 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
3919 /* We increment here since sctp_findassociation_ep_addr() wil
3920 * do a decrement if it finds the stcb as long as the locked
3921 * tcb (last argument) is NOT a TCB.. aka NULL.
3924 SCTP_INP_INCR_REF(inp);
3925 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
3927 SCTP_INP_DECR_REF(inp);
3930 if (stcb && (net == NULL)) {
3931 struct sockaddr *sa;
3933 sa = (struct sockaddr *)&encaps->sue_address;
3935 if (sa->sa_family == AF_INET) {
3936 struct sockaddr_in *sin;
3938 sin = (struct sockaddr_in *)sa;
3939 if (sin->sin_addr.s_addr) {
3941 SCTP_TCB_UNLOCK(stcb);
3942 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3948 if (sa->sa_family == AF_INET6) {
3949 struct sockaddr_in6 *sin6;
3951 sin6 = (struct sockaddr_in6 *)sa;
3952 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3954 SCTP_TCB_UNLOCK(stcb);
3955 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3960 #if defined(__Userspace__)
3961 if (sa->sa_family == AF_CONN) {
3962 struct sockaddr_conn *sconn;
3964 sconn = (struct sockaddr_conn *)sa;
3965 if (sconn->sconn_addr != NULL) {
3967 SCTP_TCB_UNLOCK(stcb);
3968 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3974 error = EAFNOSUPPORT;
3975 SCTP_TCB_UNLOCK(stcb);
3976 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3983 encaps->sue_port = net->port;
3985 encaps->sue_port = stcb->asoc.port;
3987 SCTP_TCB_UNLOCK(stcb);
3989 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3990 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3991 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3992 SCTP_INP_RLOCK(inp);
3993 encaps->sue_port = inp->sctp_ep.port;
3994 SCTP_INP_RUNLOCK(inp);
3996 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4001 *optsize = sizeof(struct sctp_udpencaps);
4005 case SCTP_ENABLE_STREAM_RESET:
4007 struct sctp_assoc_value *av;
4009 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
4010 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4013 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
4014 SCTP_TCB_UNLOCK(stcb);
4016 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4017 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4018 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4019 SCTP_INP_RLOCK(inp);
4020 av->assoc_value = (uint32_t)inp->local_strreset_support;
4021 SCTP_INP_RUNLOCK(inp);
4023 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4028 *optsize = sizeof(struct sctp_assoc_value);
4033 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
4034 error = ENOPROTOOPT;
4036 } /* end switch (sopt->sopt_name) */
4043 #if defined(__Panda__) || defined(__Userspace__)
4048 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
4053 struct sctp_tcb *stcb = NULL;
4054 struct sctp_inpcb *inp = NULL;
4057 if (optval == NULL) {
4058 SCTP_PRINTF("optval is NULL\n");
4059 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4062 inp = (struct sctp_inpcb *)so->so_pcb;
4064 SCTP_PRINTF("inp is NULL?\n");
4065 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4068 vrf_id = inp->def_vrf_id;
4073 case SCTP_AUTOCLOSE:
4074 case SCTP_AUTO_ASCONF:
4075 case SCTP_EXPLICIT_EOR:
4076 case SCTP_DISABLE_FRAGMENTS:
4077 case SCTP_USE_EXT_RCVINFO:
4078 case SCTP_I_WANT_MAPPED_V4_ADDR:
4079 /* copy in the option value */
4080 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
4085 case SCTP_DISABLE_FRAGMENTS:
4086 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
4088 case SCTP_AUTO_ASCONF:
4090 * NOTE: we don't really support this flag
4092 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
4093 /* only valid for bound all sockets */
4094 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
4096 /* forbidden by admin */
4097 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
4100 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
4102 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4106 case SCTP_EXPLICIT_EOR:
4107 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
4109 case SCTP_USE_EXT_RCVINFO:
4110 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
4112 case SCTP_I_WANT_MAPPED_V4_ADDR:
4113 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4114 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
4116 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4121 set_opt = SCTP_PCB_FLAGS_NODELAY;
4123 case SCTP_AUTOCLOSE:
4124 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4125 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
4126 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4129 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
4131 * The value is in ticks. Note this does not effect
4132 * old associations, only new ones.
4134 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
4137 SCTP_INP_WLOCK(inp);
4139 sctp_feature_on(inp, set_opt);
4141 sctp_feature_off(inp, set_opt);
4143 SCTP_INP_WUNLOCK(inp);
4145 case SCTP_REUSE_PORT:
4147 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
4148 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
4149 /* Can't set it after we are bound */
4153 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
4154 /* Can't do this for a 1-m socket */
4159 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
4161 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
4164 case SCTP_PARTIAL_DELIVERY_POINT:
4168 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4169 if (*value > SCTP_SB_LIMIT_RCV(so)) {
4170 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4174 inp->partial_delivery_point = *value;
4177 case SCTP_FRAGMENT_INTERLEAVE:
4178 /* not yet until we re-write sctp_recvmsg() */
4182 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
4183 if (*level == SCTP_FRAG_LEVEL_2) {
4184 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
4185 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
4186 } else if (*level == SCTP_FRAG_LEVEL_1) {
4187 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
4188 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
4189 } else if (*level == SCTP_FRAG_LEVEL_0) {
4190 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
4191 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
4194 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4199 case SCTP_CMT_ON_OFF:
4200 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
4201 struct sctp_assoc_value *av;
4203 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4204 if (av->assoc_value > SCTP_CMT_MAX) {
4205 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4209 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4211 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
4212 SCTP_TCB_UNLOCK(stcb);
4214 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4215 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4216 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4217 (av->assoc_id == SCTP_ALL_ASSOC)) {
4218 SCTP_INP_WLOCK(inp);
4219 inp->sctp_cmt_on_off = av->assoc_value;
4220 SCTP_INP_WUNLOCK(inp);
4222 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4223 (av->assoc_id == SCTP_ALL_ASSOC)) {
4224 SCTP_INP_RLOCK(inp);
4225 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4226 SCTP_TCB_LOCK(stcb);
4227 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
4228 SCTP_TCB_UNLOCK(stcb);
4230 SCTP_INP_RUNLOCK(inp);
4234 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
4235 error = ENOPROTOOPT;
4238 case SCTP_PLUGGABLE_CC:
4240 struct sctp_assoc_value *av;
4241 struct sctp_nets *net;
4243 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4244 if ((av->assoc_value != SCTP_CC_RFC2581) &&
4245 (av->assoc_value != SCTP_CC_HSTCP) &&
4246 (av->assoc_value != SCTP_CC_HTCP) &&
4247 (av->assoc_value != SCTP_CC_RTCC)) {
4248 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4252 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4254 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4255 stcb->asoc.congestion_control_module = av->assoc_value;
4256 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4257 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4258 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4261 SCTP_TCB_UNLOCK(stcb);
4263 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4264 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4265 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4266 (av->assoc_id == SCTP_ALL_ASSOC)) {
4267 SCTP_INP_WLOCK(inp);
4268 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
4269 SCTP_INP_WUNLOCK(inp);
4271 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4272 (av->assoc_id == SCTP_ALL_ASSOC)) {
4273 SCTP_INP_RLOCK(inp);
4274 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4275 SCTP_TCB_LOCK(stcb);
4276 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4277 stcb->asoc.congestion_control_module = av->assoc_value;
4278 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4279 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4280 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4283 SCTP_TCB_UNLOCK(stcb);
4285 SCTP_INP_RUNLOCK(inp);
4290 case SCTP_CC_OPTION:
4292 struct sctp_cc_option *cc_opt;
4294 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4295 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4297 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
4298 SCTP_INP_RLOCK(inp);
4299 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4300 SCTP_TCB_LOCK(stcb);
4301 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4302 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option)(stcb, 1, cc_opt);
4304 SCTP_TCB_UNLOCK(stcb);
4306 SCTP_INP_RUNLOCK(inp);
4311 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4314 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option)(stcb, 1,
4317 SCTP_TCB_UNLOCK(stcb);
4321 case SCTP_PLUGGABLE_SS:
4323 struct sctp_assoc_value *av;
4325 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4326 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4327 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4328 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4329 (av->assoc_value != SCTP_SS_PRIORITY) &&
4330 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4331 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4332 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4336 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4338 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4339 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4340 stcb->asoc.stream_scheduling_module = av->assoc_value;
4341 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4342 SCTP_TCB_UNLOCK(stcb);
4344 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4345 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4346 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4347 (av->assoc_id == SCTP_ALL_ASSOC)) {
4348 SCTP_INP_WLOCK(inp);
4349 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4350 SCTP_INP_WUNLOCK(inp);
4352 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4353 (av->assoc_id == SCTP_ALL_ASSOC)) {
4354 SCTP_INP_RLOCK(inp);
4355 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4356 SCTP_TCB_LOCK(stcb);
4357 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4358 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4359 stcb->asoc.stream_scheduling_module = av->assoc_value;
4360 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4361 SCTP_TCB_UNLOCK(stcb);
4363 SCTP_INP_RUNLOCK(inp);
4370 struct sctp_stream_value *av;
4372 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4373 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4375 if (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4376 av->stream_value) < 0) {
4377 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4380 SCTP_TCB_UNLOCK(stcb);
4382 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4383 SCTP_INP_RLOCK(inp);
4384 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4385 SCTP_TCB_LOCK(stcb);
4386 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4388 &stcb->asoc.strmout[av->stream_id],
4390 SCTP_TCB_UNLOCK(stcb);
4392 SCTP_INP_RUNLOCK(inp);
4395 /* Can't set stream value without association */
4396 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4402 case SCTP_CLR_STAT_LOG:
4403 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4408 struct sctp_assoc_value *av;
4410 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4411 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4414 stcb->asoc.context = av->assoc_value;
4415 SCTP_TCB_UNLOCK(stcb);
4417 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4418 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4419 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4420 (av->assoc_id == SCTP_ALL_ASSOC)) {
4421 SCTP_INP_WLOCK(inp);
4422 inp->sctp_context = av->assoc_value;
4423 SCTP_INP_WUNLOCK(inp);
4425 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4426 (av->assoc_id == SCTP_ALL_ASSOC)) {
4427 SCTP_INP_RLOCK(inp);
4428 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4429 SCTP_TCB_LOCK(stcb);
4430 stcb->asoc.context = av->assoc_value;
4431 SCTP_TCB_UNLOCK(stcb);
4433 SCTP_INP_RUNLOCK(inp);
4440 uint32_t *default_vrfid;
4444 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4445 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4446 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4451 for (i = 0; i < inp->num_vrfs; i++) {
4452 /* The VRF must be in the VRF list */
4453 if (*default_vrfid == inp->m_vrf_ids[i]) {
4454 SCTP_INP_WLOCK(inp);
4455 inp->def_vrf_id = *default_vrfid;
4456 SCTP_INP_WUNLOCK(inp);
4460 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4463 inp->def_vrf_id = *default_vrfid;
4470 case SCTP_DEL_VRF_ID:
4473 uint32_t *del_vrfid;
4476 SCTP_CHECK_AND_CAST(del_vrfid, optval, uint32_t, optsize);
4477 if (*del_vrfid > SCTP_MAX_VRF_ID) {
4478 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4482 if (inp->num_vrfs == 1) {
4483 /* Can't delete last one */
4484 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4488 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
4489 /* Can't add more once you are bound */
4490 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4494 SCTP_INP_WLOCK(inp);
4495 for (i = 0; i < inp->num_vrfs; i++) {
4496 if (*del_vrfid == inp->m_vrf_ids[i]) {
4502 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4506 if (i != (inp->num_vrfs - 1)) {
4507 /* Take bottom one and move to this slot */
4508 inp->m_vrf_ids[i] = inp->m_vrf_ids[(inp->num_vrfs-1)];
4510 if (*del_vrfid == inp->def_vrf_id) {
4511 /* Take the first one as the new default */
4512 inp->def_vrf_id = inp->m_vrf_ids[0];
4514 /* Drop the number by one killing last one */
4517 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4522 case SCTP_ADD_VRF_ID:
4525 uint32_t *add_vrfid;
4528 SCTP_CHECK_AND_CAST(add_vrfid, optval, uint32_t, optsize);
4529 if (*add_vrfid > SCTP_MAX_VRF_ID) {
4530 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4534 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
4535 /* Can't add more once you are bound */
4536 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4540 SCTP_INP_WLOCK(inp);
4541 /* Verify its not already here */
4542 for (i = 0; i < inp->num_vrfs; i++) {
4543 if (*add_vrfid == inp->m_vrf_ids[i]) {
4544 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4546 SCTP_INP_WUNLOCK(inp);
4550 if ((inp->num_vrfs + 1) > inp->vrf_size) {
4551 /* need to grow array */
4553 SCTP_MALLOC(tarray, uint32_t *,
4554 (sizeof(uint32_t) * (inp->vrf_size + SCTP_DEFAULT_VRF_SIZE)),
4556 if (tarray == NULL) {
4557 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4559 SCTP_INP_WUNLOCK(inp);
4562 memcpy(tarray, inp->m_vrf_ids, (sizeof(uint32_t) * inp->vrf_size));
4563 SCTP_FREE(inp->m_vrf_ids, SCTP_M_MVRF);
4564 inp->m_vrf_ids = tarray;
4565 inp->vrf_size += SCTP_DEFAULT_VRF_SIZE;
4567 inp->m_vrf_ids[inp->num_vrfs] = *add_vrfid;
4569 SCTP_INP_WUNLOCK(inp);
4571 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4576 case SCTP_DELAYED_SACK:
4578 struct sctp_sack_info *sack;
4580 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4581 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4582 if (sack->sack_delay) {
4583 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4584 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4585 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4586 sack->sack_delay = TICKS_TO_MSEC(1);
4590 if (sack->sack_delay) {
4591 stcb->asoc.delayed_ack = sack->sack_delay;
4593 if (sack->sack_freq) {
4594 stcb->asoc.sack_freq = sack->sack_freq;
4596 SCTP_TCB_UNLOCK(stcb);
4598 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4599 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4600 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4601 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4602 SCTP_INP_WLOCK(inp);
4603 if (sack->sack_delay) {
4604 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4606 if (sack->sack_freq) {
4607 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4609 SCTP_INP_WUNLOCK(inp);
4611 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4612 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4613 SCTP_INP_RLOCK(inp);
4614 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4615 SCTP_TCB_LOCK(stcb);
4616 if (sack->sack_delay) {
4617 stcb->asoc.delayed_ack = sack->sack_delay;
4619 if (sack->sack_freq) {
4620 stcb->asoc.sack_freq = sack->sack_freq;
4622 SCTP_TCB_UNLOCK(stcb);
4624 SCTP_INP_RUNLOCK(inp);
4629 case SCTP_AUTH_CHUNK:
4631 struct sctp_authchunk *sauth;
4633 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4635 SCTP_INP_WLOCK(inp);
4636 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4637 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4640 SCTP_INP_WUNLOCK(inp);
4645 struct sctp_authkey *sca;
4646 struct sctp_keyhead *shared_keys;
4647 sctp_sharedkey_t *shared_key;
4648 sctp_key_t *key = NULL;
4651 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4652 if (sca->sca_keylength == 0) {
4653 size = optsize - sizeof(struct sctp_authkey);
4655 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4656 size = sca->sca_keylength;
4658 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4663 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4666 shared_keys = &stcb->asoc.shared_keys;
4667 /* clear the cached keys for this key id */
4668 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4670 * create the new shared key and
4674 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4676 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4678 SCTP_TCB_UNLOCK(stcb);
4682 shared_key = sctp_alloc_sharedkey();
4683 if (shared_key == NULL) {
4685 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4687 SCTP_TCB_UNLOCK(stcb);
4690 shared_key->key = key;
4691 shared_key->keyid = sca->sca_keynumber;
4692 error = sctp_insert_sharedkey(shared_keys, shared_key);
4693 SCTP_TCB_UNLOCK(stcb);
4695 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4696 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4697 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4698 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4699 SCTP_INP_WLOCK(inp);
4700 shared_keys = &inp->sctp_ep.shared_keys;
4702 * clear the cached keys on all assocs for
4705 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4707 * create the new shared key and
4711 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4713 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4715 SCTP_INP_WUNLOCK(inp);
4719 shared_key = sctp_alloc_sharedkey();
4720 if (shared_key == NULL) {
4722 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4724 SCTP_INP_WUNLOCK(inp);
4727 shared_key->key = key;
4728 shared_key->keyid = sca->sca_keynumber;
4729 error = sctp_insert_sharedkey(shared_keys, shared_key);
4730 SCTP_INP_WUNLOCK(inp);
4732 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4733 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4734 SCTP_INP_RLOCK(inp);
4735 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4736 SCTP_TCB_LOCK(stcb);
4737 shared_keys = &stcb->asoc.shared_keys;
4738 /* clear the cached keys for this key id */
4739 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4741 * create the new shared key and
4745 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4747 SCTP_TCB_UNLOCK(stcb);
4751 shared_key = sctp_alloc_sharedkey();
4752 if (shared_key == NULL) {
4754 SCTP_TCB_UNLOCK(stcb);
4757 shared_key->key = key;
4758 shared_key->keyid = sca->sca_keynumber;
4759 error = sctp_insert_sharedkey(shared_keys, shared_key);
4760 SCTP_TCB_UNLOCK(stcb);
4762 SCTP_INP_RUNLOCK(inp);
4767 case SCTP_HMAC_IDENT:
4769 struct sctp_hmacalgo *shmac;
4770 sctp_hmaclist_t *hmaclist;
4774 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4775 if (optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) {
4776 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4781 hmaclist = sctp_alloc_hmaclist(shmac->shmac_number_of_idents);
4782 if (hmaclist == NULL) {
4783 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4787 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4788 hmacid = shmac->shmac_idents[i];
4789 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4790 /* invalid HMACs were found */;
4791 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4793 sctp_free_hmaclist(hmaclist);
4794 goto sctp_set_hmac_done;
4797 for (i = 0; i < hmaclist->num_algo; i++) {
4798 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4799 /* already in list */
4803 if (i == hmaclist->num_algo) {
4804 /* not found in list */
4805 sctp_free_hmaclist(hmaclist);
4806 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4810 /* set it on the endpoint */
4811 SCTP_INP_WLOCK(inp);
4812 if (inp->sctp_ep.local_hmacs)
4813 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4814 inp->sctp_ep.local_hmacs = hmaclist;
4815 SCTP_INP_WUNLOCK(inp);
4819 case SCTP_AUTH_ACTIVE_KEY:
4821 struct sctp_authkeyid *scact;
4823 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4824 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4826 /* set the active key on the right place */
4828 /* set the active key on the assoc */
4829 if (sctp_auth_setactivekey(stcb,
4830 scact->scact_keynumber)) {
4831 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4832 SCTP_FROM_SCTP_USRREQ,
4836 SCTP_TCB_UNLOCK(stcb);
4838 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4839 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4840 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4841 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4842 SCTP_INP_WLOCK(inp);
4843 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4844 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4847 SCTP_INP_WUNLOCK(inp);
4849 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4850 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4851 SCTP_INP_RLOCK(inp);
4852 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4853 SCTP_TCB_LOCK(stcb);
4854 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4855 SCTP_TCB_UNLOCK(stcb);
4857 SCTP_INP_RUNLOCK(inp);
4862 case SCTP_AUTH_DELETE_KEY:
4864 struct sctp_authkeyid *scdel;
4866 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4867 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4869 /* delete the key from the right place */
4871 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4872 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4875 SCTP_TCB_UNLOCK(stcb);
4877 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4878 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4879 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4880 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4881 SCTP_INP_WLOCK(inp);
4882 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4883 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4886 SCTP_INP_WUNLOCK(inp);
4888 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4889 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4890 SCTP_INP_RLOCK(inp);
4891 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4892 SCTP_TCB_LOCK(stcb);
4893 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4894 SCTP_TCB_UNLOCK(stcb);
4896 SCTP_INP_RUNLOCK(inp);
4901 case SCTP_AUTH_DEACTIVATE_KEY:
4903 struct sctp_authkeyid *keyid;
4905 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4906 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4908 /* deactivate the key from the right place */
4910 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4911 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4914 SCTP_TCB_UNLOCK(stcb);
4916 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4917 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4918 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4919 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4920 SCTP_INP_WLOCK(inp);
4921 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4922 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4925 SCTP_INP_WUNLOCK(inp);
4927 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4928 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4929 SCTP_INP_RLOCK(inp);
4930 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4931 SCTP_TCB_LOCK(stcb);
4932 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4933 SCTP_TCB_UNLOCK(stcb);
4935 SCTP_INP_RUNLOCK(inp);
4940 case SCTP_ENABLE_STREAM_RESET:
4942 struct sctp_assoc_value *av;
4944 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4945 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4946 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4950 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4952 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4953 SCTP_TCB_UNLOCK(stcb);
4955 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4956 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4957 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4958 (av->assoc_id == SCTP_ALL_ASSOC)) {
4959 SCTP_INP_WLOCK(inp);
4960 inp->local_strreset_support = (uint8_t)av->assoc_value;
4961 SCTP_INP_WUNLOCK(inp);
4963 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4964 (av->assoc_id == SCTP_ALL_ASSOC)) {
4965 SCTP_INP_RLOCK(inp);
4966 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4967 SCTP_TCB_LOCK(stcb);
4968 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4969 SCTP_TCB_UNLOCK(stcb);
4971 SCTP_INP_RUNLOCK(inp);
4977 case SCTP_RESET_STREAMS:
4979 struct sctp_reset_streams *strrst;
4980 int i, send_out = 0;
4983 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4984 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4986 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4990 if (stcb->asoc.peer_supports_strreset == 0) {
4992 * Peer does not support the chunk type.
4994 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4996 SCTP_TCB_UNLOCK(stcb);
4999 if (stcb->asoc.stream_reset_outstanding) {
5000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
5002 SCTP_TCB_UNLOCK(stcb);
5005 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
5008 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
5011 if ((send_in == 0) && (send_out == 0)) {
5012 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5014 SCTP_TCB_UNLOCK(stcb);
5017 for (i = 0; i < strrst->srs_number_streams; i++) {
5019 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
5020 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5025 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
5026 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5032 SCTP_TCB_UNLOCK(stcb);
5035 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
5036 strrst->srs_stream_list,
5037 send_out, send_in, 0, 0, 0, 0, 0);
5039 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
5040 SCTP_TCB_UNLOCK(stcb);
5043 case SCTP_ADD_STREAMS:
5045 struct sctp_add_streams *stradd;
5046 uint8_t addstream = 0;
5047 uint16_t add_o_strmcnt = 0;
5048 uint16_t add_i_strmcnt = 0;
5050 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
5051 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
5053 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
5057 if (stcb->asoc.peer_supports_strreset == 0) {
5059 * Peer does not support the chunk type.
5061 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
5063 SCTP_TCB_UNLOCK(stcb);
5066 if (stcb->asoc.stream_reset_outstanding) {
5067 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
5069 SCTP_TCB_UNLOCK(stcb);
5072 if ((stradd->sas_outstrms == 0) &&
5073 (stradd->sas_instrms == 0)) {
5077 if (stradd->sas_outstrms) {
5079 /* We allocate here */
5080 add_o_strmcnt = stradd->sas_outstrms;
5081 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
5082 /* You can't have more than 64k */
5087 if (stradd->sas_instrms) {
5091 /* We allocate inside sctp_send_str_reset_req() */
5092 add_i_strmcnt = stradd->sas_instrms;
5093 cnt = add_i_strmcnt;
5094 cnt += stcb->asoc.streamincnt;
5095 if (cnt > 0x0000ffff) {
5096 /* You can't have more than 64k */
5100 if (cnt > (int)stcb->asoc.max_inbound_streams) {
5101 /* More than you are allowed */
5106 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
5107 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
5109 SCTP_TCB_UNLOCK(stcb);
5112 case SCTP_RESET_ASSOC:
5116 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
5117 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) *value);
5119 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
5123 if (stcb->asoc.peer_supports_strreset == 0) {
5125 * Peer does not support the chunk type.
5127 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
5129 SCTP_TCB_UNLOCK(stcb);
5132 if (stcb->asoc.stream_reset_outstanding) {
5133 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
5135 SCTP_TCB_UNLOCK(stcb);
5138 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 1, 0, 0, 0, 0);
5139 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
5140 SCTP_TCB_UNLOCK(stcb);
5143 case SCTP_CONNECT_X:
5144 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
5145 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5149 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
5151 case SCTP_CONNECT_X_DELAYED:
5152 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
5153 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5157 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
5159 case SCTP_CONNECT_X_COMPLETE:
5161 struct sockaddr *sa;
5162 struct sctp_nets *net;
5164 /* FIXME MT: check correct? */
5165 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
5168 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
5169 SCTP_INP_RLOCK(inp);
5170 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5172 SCTP_TCB_LOCK(stcb);
5173 net = sctp_findnet(stcb, sa);
5175 SCTP_INP_RUNLOCK(inp);
5177 /* We increment here since sctp_findassociation_ep_addr() wil
5178 * do a decrement if it finds the stcb as long as the locked
5179 * tcb (last argument) is NOT a TCB.. aka NULL.
5181 SCTP_INP_INCR_REF(inp);
5182 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
5184 SCTP_INP_DECR_REF(inp);
5189 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
5193 if (stcb->asoc.delayed_connection == 1) {
5194 stcb->asoc.delayed_connection = 0;
5195 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
5196 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
5197 stcb->asoc.primary_destination,
5198 SCTP_FROM_SCTP_USRREQ+SCTP_LOC_9);
5199 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
5202 * already expired or did not use delayed
5205 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
5208 SCTP_TCB_UNLOCK(stcb);
5211 case SCTP_MAX_BURST:
5213 #if defined(__FreeBSD__) && __FreeBSD_version < 900000
5216 SCTP_CHECK_AND_CAST(burst, optval, uint8_t, optsize);
5218 SCTP_INP_WLOCK(inp);
5219 inp->sctp_ep.max_burst = *burst;
5220 SCTP_INP_WUNLOCK(inp);
5222 struct sctp_assoc_value *av;
5224 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
5225 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
5228 stcb->asoc.max_burst = av->assoc_value;
5229 SCTP_TCB_UNLOCK(stcb);
5231 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5232 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5233 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
5234 (av->assoc_id == SCTP_ALL_ASSOC)) {
5235 SCTP_INP_WLOCK(inp);
5236 inp->sctp_ep.max_burst = av->assoc_value;
5237 SCTP_INP_WUNLOCK(inp);
5239 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
5240 (av->assoc_id == SCTP_ALL_ASSOC)) {
5241 SCTP_INP_RLOCK(inp);
5242 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5243 SCTP_TCB_LOCK(stcb);
5244 stcb->asoc.max_burst = av->assoc_value;
5245 SCTP_TCB_UNLOCK(stcb);
5247 SCTP_INP_RUNLOCK(inp);
5255 struct sctp_assoc_value *av;
5258 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
5259 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
5261 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5262 ovh = SCTP_MED_OVERHEAD;
5264 ovh = SCTP_MED_V4_OVERHEAD;
5267 if (av->assoc_value) {
5268 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
5270 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
5272 SCTP_TCB_UNLOCK(stcb);
5274 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5275 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5276 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
5277 SCTP_INP_WLOCK(inp);
5278 /* FIXME MT: I think this is not in tune with the API ID */
5279 if (av->assoc_value) {
5280 inp->sctp_frag_point = (av->assoc_value + ovh);
5282 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
5284 SCTP_INP_WUNLOCK(inp);
5286 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5294 struct sctp_event_subscribe *events;
5296 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
5298 SCTP_INP_WLOCK(inp);
5299 if (events->sctp_data_io_event) {
5300 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5302 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5305 if (events->sctp_association_event) {
5306 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5308 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5311 if (events->sctp_address_event) {
5312 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5314 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5317 if (events->sctp_send_failure_event) {
5318 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5320 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5323 if (events->sctp_peer_error_event) {
5324 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5326 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5329 if (events->sctp_shutdown_event) {
5330 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5332 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5335 if (events->sctp_partial_delivery_event) {
5336 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5338 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5341 if (events->sctp_adaptation_layer_event) {
5342 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5344 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5347 if (events->sctp_authentication_event) {
5348 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5350 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5353 if (events->sctp_sender_dry_event) {
5354 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5356 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5359 if (events->sctp_stream_reset_event) {
5360 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5362 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5364 SCTP_INP_WUNLOCK(inp);
5366 SCTP_INP_RLOCK(inp);
5367 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5368 SCTP_TCB_LOCK(stcb);
5369 if (events->sctp_association_event) {
5370 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5372 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5374 if (events->sctp_address_event) {
5375 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5377 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5379 if (events->sctp_send_failure_event) {
5380 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5382 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5384 if (events->sctp_peer_error_event) {
5385 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5387 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5389 if (events->sctp_shutdown_event) {
5390 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5392 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5394 if (events->sctp_partial_delivery_event) {
5395 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5397 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5399 if (events->sctp_adaptation_layer_event) {
5400 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5402 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5404 if (events->sctp_authentication_event) {
5405 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5407 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5409 if (events->sctp_sender_dry_event) {
5410 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5412 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5414 if (events->sctp_stream_reset_event) {
5415 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5417 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5419 SCTP_TCB_UNLOCK(stcb);
5421 /* Send up the sender dry event only for 1-to-1 style sockets. */
5422 if (events->sctp_sender_dry_event) {
5423 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5424 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5425 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5427 SCTP_TCB_LOCK(stcb);
5428 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5429 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5430 (stcb->asoc.stream_queue_cnt == 0)) {
5431 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5433 SCTP_TCB_UNLOCK(stcb);
5437 SCTP_INP_RUNLOCK(inp);
5440 case SCTP_ADAPTATION_LAYER:
5442 struct sctp_setadaptation *adap_bits;
5444 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5445 SCTP_INP_WLOCK(inp);
5446 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5447 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5448 SCTP_INP_WUNLOCK(inp);
5452 case SCTP_SET_INITIAL_DBG_SEQ:
5456 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5457 SCTP_INP_WLOCK(inp);
5458 inp->sctp_ep.initial_sequence_debug = *vvv;
5459 SCTP_INP_WUNLOCK(inp);
5463 case SCTP_DEFAULT_SEND_PARAM:
5465 struct sctp_sndrcvinfo *s_info;
5467 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5468 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5471 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5472 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5474 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5477 SCTP_TCB_UNLOCK(stcb);
5479 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5480 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5481 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5482 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5483 SCTP_INP_WLOCK(inp);
5484 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5485 SCTP_INP_WUNLOCK(inp);
5487 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5488 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5489 SCTP_INP_RLOCK(inp);
5490 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5491 SCTP_TCB_LOCK(stcb);
5492 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5493 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5495 SCTP_TCB_UNLOCK(stcb);
5497 SCTP_INP_RUNLOCK(inp);
5502 case SCTP_PEER_ADDR_PARAMS:
5504 struct sctp_paddrparams *paddrp;
5505 struct sctp_nets *net;
5507 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5508 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5511 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
5513 /* We increment here since sctp_findassociation_ep_addr() wil
5514 * do a decrement if it finds the stcb as long as the locked
5515 * tcb (last argument) is NOT a TCB.. aka NULL.
5517 SCTP_INP_INCR_REF(inp);
5518 stcb = sctp_findassociation_ep_addr(&inp,
5519 (struct sockaddr *)&paddrp->spp_address,
5522 SCTP_INP_DECR_REF(inp);
5525 if (stcb && (net == NULL)) {
5526 struct sockaddr *sa;
5528 sa = (struct sockaddr *)&paddrp->spp_address;
5530 if (sa->sa_family == AF_INET) {
5532 struct sockaddr_in *sin;
5533 sin = (struct sockaddr_in *)sa;
5534 if (sin->sin_addr.s_addr) {
5535 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5536 SCTP_TCB_UNLOCK(stcb);
5543 if (sa->sa_family == AF_INET6) {
5544 struct sockaddr_in6 *sin6;
5546 sin6 = (struct sockaddr_in6 *)sa;
5547 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5548 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5549 SCTP_TCB_UNLOCK(stcb);
5555 #if defined(__Userspace__)
5556 if (sa->sa_family == AF_CONN) {
5557 struct sockaddr_conn *sconn;
5559 sconn = (struct sockaddr_conn *)sa;
5560 if (sconn->sconn_addr != NULL) {
5561 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5562 SCTP_TCB_UNLOCK(stcb);
5569 error = EAFNOSUPPORT;
5570 SCTP_TCB_UNLOCK(stcb);
5571 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5576 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5578 SCTP_TCB_UNLOCK(stcb);
5579 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5583 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5585 SCTP_TCB_UNLOCK(stcb);
5586 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5591 /************************TCB SPECIFIC SET ******************/
5593 * do we change the timer for HB, we run
5598 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5599 ovh = SCTP_MED_OVERHEAD;
5601 ovh = SCTP_MED_V4_OVERHEAD;
5604 /* network sets ? */
5606 /************************NET SPECIFIC SET ******************/
5607 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5608 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5609 !(net->dest_state & SCTP_ADDR_NOHB)) {
5610 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5611 SCTP_FROM_SCTP_USRREQ+SCTP_LOC_10);
5613 net->dest_state |= SCTP_ADDR_NOHB;
5615 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5616 if (paddrp->spp_hbinterval) {
5617 net->heart_beat_delay = paddrp->spp_hbinterval;
5618 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5619 net->heart_beat_delay = 0;
5621 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5622 SCTP_FROM_SCTP_USRREQ+SCTP_LOC_10);
5623 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5624 net->dest_state &= ~SCTP_ADDR_NOHB;
5626 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5628 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5629 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5630 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5632 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5633 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5634 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5635 SCTP_FROM_SCTP_USRREQ+SCTP_LOC_10);
5637 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5638 net->mtu = paddrp->spp_pathmtu + ovh;
5639 if (net->mtu < stcb->asoc.smallest_mtu) {
5640 sctp_pathmtu_adjustment(stcb, net->mtu);
5643 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5644 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5645 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5647 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5649 if (paddrp->spp_pathmaxrxt) {
5650 if (net->dest_state & SCTP_ADDR_PF) {
5651 if (net->error_count > paddrp->spp_pathmaxrxt) {
5652 net->dest_state &= ~SCTP_ADDR_PF;
5655 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5656 (net->error_count > net->pf_threshold)) {
5657 net->dest_state |= SCTP_ADDR_PF;
5658 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5659 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5660 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5663 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5664 if (net->error_count > paddrp->spp_pathmaxrxt) {
5665 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5666 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5669 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5670 net->dest_state |= SCTP_ADDR_REACHABLE;
5671 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5674 net->failure_threshold = paddrp->spp_pathmaxrxt;
5676 if (paddrp->spp_flags & SPP_DSCP) {
5677 net->dscp = paddrp->spp_dscp & 0xfc;
5681 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5682 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5683 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5684 net->flowlabel |= 0x80000000;
5689 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5690 if (paddrp->spp_pathmaxrxt) {
5691 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5692 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5693 if (net->dest_state & SCTP_ADDR_PF) {
5694 if (net->error_count > paddrp->spp_pathmaxrxt) {
5695 net->dest_state &= ~SCTP_ADDR_PF;
5698 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5699 (net->error_count > net->pf_threshold)) {
5700 net->dest_state |= SCTP_ADDR_PF;
5701 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5702 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5703 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5706 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5707 if (net->error_count > paddrp->spp_pathmaxrxt) {
5708 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5709 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5712 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5713 net->dest_state |= SCTP_ADDR_REACHABLE;
5714 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5717 net->failure_threshold = paddrp->spp_pathmaxrxt;
5721 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5722 if (paddrp->spp_hbinterval) {
5723 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5724 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5725 stcb->asoc.heart_beat_delay = 0;
5727 /* Turn back on the timer */
5728 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5729 if (paddrp->spp_hbinterval) {
5730 net->heart_beat_delay = paddrp->spp_hbinterval;
5731 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5732 net->heart_beat_delay = 0;
5734 if (net->dest_state & SCTP_ADDR_NOHB) {
5735 net->dest_state &= ~SCTP_ADDR_NOHB;
5737 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5738 SCTP_FROM_SCTP_USRREQ+SCTP_LOC_10);
5739 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5741 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5743 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5744 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5745 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5746 net->dest_state |= SCTP_ADDR_NOHB;
5747 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5748 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, SCTP_FROM_SCTP_USRREQ+SCTP_LOC_10);
5752 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5754 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5755 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5756 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5757 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5758 SCTP_FROM_SCTP_USRREQ+SCTP_LOC_10);
5760 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5761 net->mtu = paddrp->spp_pathmtu + ovh;
5762 if (net->mtu < stcb->asoc.smallest_mtu) {
5763 sctp_pathmtu_adjustment(stcb, net->mtu);
5766 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5768 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5769 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5770 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5771 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5773 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5775 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5777 if (paddrp->spp_flags & SPP_DSCP) {
5778 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5779 net->dscp = paddrp->spp_dscp & 0xfc;
5782 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5783 stcb->asoc.default_dscp |= 0x01;
5786 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5787 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5788 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5789 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5790 net->flowlabel |= 0x80000000;
5793 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5794 stcb->asoc.default_flowlabel |= 0x80000000;
5798 SCTP_TCB_UNLOCK(stcb);
5800 /************************NO TCB, SET TO default stuff ******************/
5801 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5802 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5803 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5804 SCTP_INP_WLOCK(inp);
5806 * For the TOS/FLOWLABEL stuff you set it
5807 * with the options on the socket
5809 if (paddrp->spp_pathmaxrxt) {
5810 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5813 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5814 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5815 else if (paddrp->spp_hbinterval) {
5816 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5817 paddrp->spp_hbinterval= SCTP_MAX_HB_INTERVAL;
5818 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5821 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5822 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5823 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5824 } else if (paddrp->spp_hbinterval) {
5825 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5827 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5828 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5829 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5831 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5832 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5833 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5834 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5836 if (paddrp->spp_flags & SPP_DSCP) {
5837 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5838 inp->sctp_ep.default_dscp |= 0x01;
5841 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5842 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5843 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5844 inp->sctp_ep.default_flowlabel |= 0x80000000;
5848 SCTP_INP_WUNLOCK(inp);
5850 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5858 struct sctp_rtoinfo *srto;
5859 uint32_t new_init, new_min, new_max;
5861 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5862 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5865 if (srto->srto_initial)
5866 new_init = srto->srto_initial;
5868 new_init = stcb->asoc.initial_rto;
5870 new_max = srto->srto_max;
5872 new_max = stcb->asoc.maxrto;
5874 new_min = srto->srto_min;
5876 new_min = stcb->asoc.minrto;
5877 if ((new_min <= new_init) && (new_init <= new_max)) {
5878 stcb->asoc.initial_rto = new_init;
5879 stcb->asoc.maxrto = new_max;
5880 stcb->asoc.minrto = new_min;
5882 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5885 SCTP_TCB_UNLOCK(stcb);
5887 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5888 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5889 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5890 SCTP_INP_WLOCK(inp);
5891 if (srto->srto_initial)
5892 new_init = srto->srto_initial;
5894 new_init = inp->sctp_ep.initial_rto;
5896 new_max = srto->srto_max;
5898 new_max = inp->sctp_ep.sctp_maxrto;
5900 new_min = srto->srto_min;
5902 new_min = inp->sctp_ep.sctp_minrto;
5903 if ((new_min <= new_init) && (new_init <= new_max)) {
5904 inp->sctp_ep.initial_rto = new_init;
5905 inp->sctp_ep.sctp_maxrto = new_max;
5906 inp->sctp_ep.sctp_minrto = new_min;
5908 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5911 SCTP_INP_WUNLOCK(inp);
5913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5919 case SCTP_ASSOCINFO:
5921 struct sctp_assocparams *sasoc;
5923 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5924 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5925 if (sasoc->sasoc_cookie_life) {
5926 /* boundary check the cookie life */
5927 if (sasoc->sasoc_cookie_life < 1000)
5928 sasoc->sasoc_cookie_life = 1000;
5929 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5930 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5934 if (sasoc->sasoc_asocmaxrxt)
5935 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5936 if (sasoc->sasoc_cookie_life) {
5937 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5939 SCTP_TCB_UNLOCK(stcb);
5941 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5942 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5943 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5944 SCTP_INP_WLOCK(inp);
5945 if (sasoc->sasoc_asocmaxrxt)
5946 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5947 if (sasoc->sasoc_cookie_life) {
5948 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5950 SCTP_INP_WUNLOCK(inp);
5952 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5960 struct sctp_initmsg *sinit;
5962 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5963 SCTP_INP_WLOCK(inp);
5964 if (sinit->sinit_num_ostreams)
5965 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5967 if (sinit->sinit_max_instreams)
5968 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5970 if (sinit->sinit_max_attempts)
5971 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5973 if (sinit->sinit_max_init_timeo)
5974 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5975 SCTP_INP_WUNLOCK(inp);
5978 case SCTP_PRIMARY_ADDR:
5980 struct sctp_setprim *spa;
5981 struct sctp_nets *net;
5983 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5984 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5988 net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
5990 /* We increment here since sctp_findassociation_ep_addr() wil
5991 * do a decrement if it finds the stcb as long as the locked
5992 * tcb (last argument) is NOT a TCB.. aka NULL.
5994 SCTP_INP_INCR_REF(inp);
5995 stcb = sctp_findassociation_ep_addr(&inp,
5996 (struct sockaddr *)&spa->ssp_addr,
5999 SCTP_INP_DECR_REF(inp);
6003 if ((stcb) && (net)) {
6004 if ((net != stcb->asoc.primary_destination) &&
6005 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
6006 /* Ok we need to set it */
6007 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
6008 if ((stcb->asoc.alternate) &&
6009 (!(net->dest_state & SCTP_ADDR_PF)) &&
6010 (net->dest_state & SCTP_ADDR_REACHABLE)) {
6011 sctp_free_remote_addr(stcb->asoc.alternate);
6012 stcb->asoc.alternate = NULL;
6017 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6021 SCTP_TCB_UNLOCK(stcb);
6025 case SCTP_SET_DYNAMIC_PRIMARY:
6027 union sctp_sockstore *ss;
6031 #if !defined(__Windows__) && !defined(__Userspace__)
6032 #if defined(__APPLE__)
6036 #if __FreeBSD_version > 602000
6037 error = priv_check(curthread,
6038 PRIV_NETINET_RESERVEDPORT);
6039 #elif __FreeBSD_version >= 500000
6040 error = suser((struct thread *)p);
6044 #elif defined(__APPLE__)
6045 proc = (struct proc *)p;
6047 error = suser(proc->p_ucred, &proc->p_acflag);
6052 error = suser(p, 0);
6058 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
6059 /* SUPER USER CHECK? */
6061 for (i = 0; i < inp->num_vrfs; i++) {
6062 if (vrf_id == inp->m_vrf_ids[i]) {
6068 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6073 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
6076 case SCTP_SET_PEER_PRIMARY_ADDR:
6078 struct sctp_setpeerprim *sspp;
6080 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
6081 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
6083 struct sctp_ifa *ifa;
6084 ifa = sctp_find_ifa_by_addr((struct sockaddr *)&sspp->sspp_addr,
6085 stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
6087 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6091 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
6092 /* Must validate the ifa found is in our ep */
6093 struct sctp_laddr *laddr;
6095 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6096 if (laddr->ifa == NULL) {
6097 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
6101 if (laddr->ifa == ifa) {
6107 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6111 #if defined(__FreeBSD__)
6113 switch (sspp->sspp_addr.ss_family) {
6117 struct sockaddr_in *sin;
6119 sin = (struct sockaddr_in *)&sspp->sspp_addr;
6120 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
6121 &sin->sin_addr) != 0) {
6122 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6132 struct sockaddr_in6 *sin6;
6134 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
6135 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
6136 &sin6->sin6_addr) != 0) {
6137 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6145 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6151 if (sctp_set_primary_ip_address_sa(stcb,
6152 (struct sockaddr *)&sspp->sspp_addr) != 0) {
6153 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6157 SCTP_TCB_UNLOCK(stcb);
6159 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6164 case SCTP_BINDX_ADD_ADDR:
6166 struct sctp_getaddresses *addrs;
6167 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
6170 td = (struct thread *)p;
6172 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
6175 if (addrs->addr->sa_family == AF_INET) {
6176 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
6177 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6181 #if defined(__FreeBSD__) && __FreeBSD_version >= 800000
6182 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
6183 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6190 if (addrs->addr->sa_family == AF_INET6) {
6191 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
6192 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6196 #if defined(__FreeBSD__) && __FreeBSD_version >= 800000
6197 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
6198 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6199 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6206 error = EAFNOSUPPORT;
6209 sctp_bindx_add_address(so, inp, addrs->addr,
6210 addrs->sget_assoc_id, vrf_id,
6214 case SCTP_BINDX_REM_ADDR:
6216 struct sctp_getaddresses *addrs;
6217 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
6219 td = (struct thread *)p;
6222 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
6224 if (addrs->addr->sa_family == AF_INET) {
6225 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
6226 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6230 #if defined(__FreeBSD__) && __FreeBSD_version >= 800000
6231 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
6232 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6239 if (addrs->addr->sa_family == AF_INET6) {
6240 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
6241 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6245 #if defined(__FreeBSD__) && __FreeBSD_version >= 800000
6247 (error = prison_local_ip6(td->td_ucred,
6248 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
6249 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6250 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6257 error = EAFNOSUPPORT;
6260 sctp_bindx_delete_address(inp, addrs->addr,
6261 addrs->sget_assoc_id, vrf_id,
6266 case SCTP_LISTEN_FIX:
6267 /* only applies to one-to-many sockets */
6268 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6269 /* make sure the ACCEPTCONN flag is OFF */
6270 so->so_options &= ~SO_ACCEPTCONN;
6272 /* otherwise, not allowed */
6273 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6277 #endif /* __APPLE__ */
6280 struct sctp_event *event;
6281 uint32_t event_type;
6283 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6284 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6285 switch (event->se_type) {
6286 case SCTP_ASSOC_CHANGE:
6287 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6289 case SCTP_PEER_ADDR_CHANGE:
6290 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6292 case SCTP_REMOTE_ERROR:
6293 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6295 case SCTP_SEND_FAILED:
6296 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6298 case SCTP_SHUTDOWN_EVENT:
6299 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6301 case SCTP_ADAPTATION_INDICATION:
6302 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6304 case SCTP_PARTIAL_DELIVERY_EVENT:
6305 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6307 case SCTP_AUTHENTICATION_EVENT:
6308 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6310 case SCTP_STREAM_RESET_EVENT:
6311 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6313 case SCTP_SENDER_DRY_EVENT:
6314 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6316 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6318 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6321 case SCTP_ASSOC_RESET_EVENT:
6322 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6324 case SCTP_STREAM_CHANGE_EVENT:
6325 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6327 case SCTP_SEND_FAILED_EVENT:
6328 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6332 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6336 if (event_type > 0) {
6339 sctp_stcb_feature_on(inp, stcb, event_type);
6340 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6341 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6342 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6343 (stcb->asoc.stream_queue_cnt == 0)) {
6344 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6348 sctp_stcb_feature_off(inp, stcb, event_type);
6350 SCTP_TCB_UNLOCK(stcb);
6353 * We don't want to send up a storm of events,
6354 * so return an error for sender dry events
6356 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6357 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6358 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6359 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6360 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6361 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6365 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6366 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6367 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6368 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6369 SCTP_INP_WLOCK(inp);
6371 sctp_feature_on(inp, event_type);
6373 sctp_feature_off(inp, event_type);
6375 SCTP_INP_WUNLOCK(inp);
6377 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6378 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6379 SCTP_INP_RLOCK(inp);
6380 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6381 SCTP_TCB_LOCK(stcb);
6383 sctp_stcb_feature_on(inp, stcb, event_type);
6385 sctp_stcb_feature_off(inp, stcb, event_type);
6387 SCTP_TCB_UNLOCK(stcb);
6389 SCTP_INP_RUNLOCK(inp);
6395 case SCTP_RECVRCVINFO:
6399 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6400 SCTP_INP_WLOCK(inp);
6402 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6404 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6406 SCTP_INP_WUNLOCK(inp);
6409 case SCTP_RECVNXTINFO:
6413 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6414 SCTP_INP_WLOCK(inp);
6416 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6418 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6420 SCTP_INP_WUNLOCK(inp);
6423 case SCTP_DEFAULT_SNDINFO:
6425 struct sctp_sndinfo *info;
6428 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6429 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6432 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6433 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6434 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6435 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6436 stcb->asoc.def_send.sinfo_flags |= policy;
6437 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6438 stcb->asoc.def_send.sinfo_context = info->snd_context;
6440 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6443 SCTP_TCB_UNLOCK(stcb);
6445 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6446 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6447 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6448 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6449 SCTP_INP_WLOCK(inp);
6450 inp->def_send.sinfo_stream = info->snd_sid;
6451 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6452 inp->def_send.sinfo_flags = info->snd_flags;
6453 inp->def_send.sinfo_flags |= policy;
6454 inp->def_send.sinfo_ppid = info->snd_ppid;
6455 inp->def_send.sinfo_context = info->snd_context;
6456 SCTP_INP_WUNLOCK(inp);
6458 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6459 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6460 SCTP_INP_RLOCK(inp);
6461 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6462 SCTP_TCB_LOCK(stcb);
6463 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6464 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6465 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6466 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6467 stcb->asoc.def_send.sinfo_flags |= policy;
6468 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6469 stcb->asoc.def_send.sinfo_context = info->snd_context;
6471 SCTP_TCB_UNLOCK(stcb);
6473 SCTP_INP_RUNLOCK(inp);
6478 case SCTP_DEFAULT_PRINFO:
6480 struct sctp_default_prinfo *info;
6482 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6483 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6485 if (PR_SCTP_INVALID_POLICY(info->pr_policy)) {
6486 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6491 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6492 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6493 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6494 SCTP_TCB_UNLOCK(stcb);
6496 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6497 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6498 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6499 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6500 SCTP_INP_WLOCK(inp);
6501 inp->def_send.sinfo_flags &= 0xfff0;
6502 inp->def_send.sinfo_flags |= info->pr_policy;
6503 inp->def_send.sinfo_timetolive = info->pr_value;
6504 SCTP_INP_WUNLOCK(inp);
6506 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6507 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6508 SCTP_INP_RLOCK(inp);
6509 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6510 SCTP_TCB_LOCK(stcb);
6511 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6512 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6513 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6514 SCTP_TCB_UNLOCK(stcb);
6516 SCTP_INP_RUNLOCK(inp);
6521 case SCTP_PEER_ADDR_THLDS:
6522 /* Applies to the specific association */
6524 struct sctp_paddrthlds *thlds;
6525 struct sctp_nets *net;
6527 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6528 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6531 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_address);
6533 /* We increment here since sctp_findassociation_ep_addr() wil
6534 * do a decrement if it finds the stcb as long as the locked
6535 * tcb (last argument) is NOT a TCB.. aka NULL.
6537 SCTP_INP_INCR_REF(inp);
6538 stcb = sctp_findassociation_ep_addr(&inp,
6539 (struct sockaddr *)&thlds->spt_address,
6542 SCTP_INP_DECR_REF(inp);
6545 if (stcb && (net == NULL)) {
6546 struct sockaddr *sa;
6548 sa = (struct sockaddr *)&thlds->spt_address;
6550 if (sa->sa_family == AF_INET) {
6552 struct sockaddr_in *sin;
6553 sin = (struct sockaddr_in *)sa;
6554 if (sin->sin_addr.s_addr) {
6555 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6556 SCTP_TCB_UNLOCK(stcb);
6563 if (sa->sa_family == AF_INET6) {
6564 struct sockaddr_in6 *sin6;
6566 sin6 = (struct sockaddr_in6 *)sa;
6567 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6568 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6569 SCTP_TCB_UNLOCK(stcb);
6575 #if defined(__Userspace__)
6576 if (sa->sa_family == AF_CONN) {
6577 struct sockaddr_conn *sconn;
6579 sconn = (struct sockaddr_conn *)sa;
6580 if (sconn->sconn_addr != NULL) {
6581 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6582 SCTP_TCB_UNLOCK(stcb);
6589 error = EAFNOSUPPORT;
6590 SCTP_TCB_UNLOCK(stcb);
6591 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6597 if (net->dest_state & SCTP_ADDR_PF) {
6598 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
6599 (net->failure_threshold <= thlds->spt_pathpfthld)) {
6600 net->dest_state &= ~SCTP_ADDR_PF;
6603 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
6604 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
6605 net->dest_state |= SCTP_ADDR_PF;
6606 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6607 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
6608 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6611 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6612 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
6613 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6614 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6617 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
6618 net->dest_state |= SCTP_ADDR_REACHABLE;
6619 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6622 net->failure_threshold = thlds->spt_pathmaxrxt;
6623 net->pf_threshold = thlds->spt_pathpfthld;
6625 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6626 if (net->dest_state & SCTP_ADDR_PF) {
6627 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
6628 (net->failure_threshold <= thlds->spt_pathpfthld)) {
6629 net->dest_state &= ~SCTP_ADDR_PF;
6632 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
6633 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
6634 net->dest_state |= SCTP_ADDR_PF;
6635 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6636 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
6637 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6640 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6641 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
6642 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6643 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6646 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
6647 net->dest_state |= SCTP_ADDR_REACHABLE;
6648 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6651 net->failure_threshold = thlds->spt_pathmaxrxt;
6652 net->pf_threshold = thlds->spt_pathpfthld;
6654 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6655 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6658 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6659 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6660 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6661 SCTP_INP_WLOCK(inp);
6662 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6663 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6664 SCTP_INP_WUNLOCK(inp);
6666 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6672 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6674 struct sctp_udpencaps *encaps;
6675 struct sctp_nets *net;
6677 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6678 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6680 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
6682 /* We increment here since sctp_findassociation_ep_addr() wil
6683 * do a decrement if it finds the stcb as long as the locked
6684 * tcb (last argument) is NOT a TCB.. aka NULL.
6687 SCTP_INP_INCR_REF(inp);
6688 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
6690 SCTP_INP_DECR_REF(inp);
6693 if (stcb && (net == NULL)) {
6694 struct sockaddr *sa;
6696 sa = (struct sockaddr *)&encaps->sue_address;
6698 if (sa->sa_family == AF_INET) {
6700 struct sockaddr_in *sin;
6701 sin = (struct sockaddr_in *)sa;
6702 if (sin->sin_addr.s_addr) {
6703 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6704 SCTP_TCB_UNLOCK(stcb);
6711 if (sa->sa_family == AF_INET6) {
6712 struct sockaddr_in6 *sin6;
6714 sin6 = (struct sockaddr_in6 *)sa;
6715 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6716 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6717 SCTP_TCB_UNLOCK(stcb);
6723 #if defined(__Userspace__)
6724 if (sa->sa_family == AF_CONN) {
6725 struct sockaddr_conn *sconn;
6727 sconn = (struct sockaddr_conn *)sa;
6728 if (sconn->sconn_addr != NULL) {
6729 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6730 SCTP_TCB_UNLOCK(stcb);
6737 error = EAFNOSUPPORT;
6738 SCTP_TCB_UNLOCK(stcb);
6739 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6746 net->port = encaps->sue_port;
6748 stcb->asoc.port = encaps->sue_port;
6750 SCTP_TCB_UNLOCK(stcb);
6752 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6753 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6754 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6755 SCTP_INP_WLOCK(inp);
6756 inp->sctp_ep.port = encaps->sue_port;
6757 SCTP_INP_WUNLOCK(inp);
6759 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6766 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6767 error = ENOPROTOOPT;
6769 } /* end switch (opt) */
6773 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
6775 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6777 void *optval = NULL;
6782 if (sopt->sopt_level != IPPROTO_SCTP) {
6783 /* wrong proto level... send back up to IP */
6785 if (INP_CHECK_SOCKAF(so, AF_INET6))
6786 error = ip6_ctloutput(so, sopt);
6788 #if defined(INET) && defined(INET6)
6792 error = ip_ctloutput(so, sopt);
6796 optsize = sopt->sopt_valsize;
6798 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6799 if (optval == NULL) {
6800 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6803 error = sooptcopyin(sopt, optval, optsize, optsize);
6805 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6809 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__Windows__)
6810 p = (void *)sopt->sopt_td;
6812 p = (void *)sopt->sopt_p;
6814 if (sopt->sopt_dir == SOPT_SET) {
6815 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6816 } else if (sopt->sopt_dir == SOPT_GET) {
6817 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6819 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6822 if ((error == 0) && (optval != NULL)) {
6823 error = sooptcopyout(sopt, optval, optsize);
6824 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6825 } else if (optval != NULL) {
6826 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6834 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
6836 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6839 #if defined(__FreeBSD__) || defined(__APPLE__)
6841 sctp_connect(struct socket *so, struct sockaddr *addr, struct proc *p)
6843 #elif defined(__Panda__) || defined(__Userspace__)
6845 sctp_connect(struct socket *so, struct sockaddr *addr)
6848 #elif defined(__Windows__)
6850 sctp_connect(struct socket *so, struct sockaddr *addr, PKTHREAD p)
6854 sctp_connect(struct socket *so, struct mbuf *nam, struct proc *p)
6856 struct sockaddr *addr = mtod(nam, struct sockaddr *);
6864 int create_lock_on = 0;
6866 struct sctp_inpcb *inp;
6867 struct sctp_tcb *stcb = NULL;
6869 inp = (struct sctp_inpcb *)so->so_pcb;
6871 /* I made the same as TCP since we are not setup? */
6872 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6873 return (ECONNRESET);
6876 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6880 #if defined(__Userspace__)
6881 /* TODO __Userspace__ falls into this code for IPv6 stuff at the moment... */
6883 #if !defined(__Windows__) && !defined(__Userspace_os_Linux) && !defined(__Userspace_os_Windows)
6884 switch (addr->sa_family) {
6888 #if defined(__FreeBSD__) && __FreeBSD_version >= 800000
6889 struct sockaddr_in6 *sin6p;
6892 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6893 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6896 #if defined(__FreeBSD__) && __FreeBSD_version >= 800000
6897 sin6p = (struct sockaddr_in6 *)addr;
6898 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6899 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6909 #if defined(__FreeBSD__) && __FreeBSD_version >= 800000
6910 struct sockaddr_in *sinp;
6913 #if !defined(__Userspace_os_Windows)
6914 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6915 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6919 #if defined(__FreeBSD__) && __FreeBSD_version >= 800000
6920 sinp = (struct sockaddr_in *)addr;
6921 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6922 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6930 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6931 return (EAFNOSUPPORT);
6934 SCTP_INP_INCR_REF(inp);
6935 SCTP_ASOC_CREATE_LOCK(inp);
6939 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6940 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6941 /* Should I really unlock ? */
6942 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6947 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6948 (addr->sa_family == AF_INET6)) {
6949 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6954 #if defined(__Userspace__)
6955 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_CONN) &&
6956 (addr->sa_family != AF_CONN)) {
6957 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6962 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6963 SCTP_PCB_FLAGS_UNBOUND) {
6964 /* Bind a ephemeral port */
6965 error = sctp_inpcb_bind(so, NULL, NULL, p);
6970 /* Now do we connect? */
6971 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6972 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6973 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6977 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6978 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6979 /* We are already connected AND the TCP model */
6980 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6984 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6985 SCTP_INP_RLOCK(inp);
6986 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6987 SCTP_INP_RUNLOCK(inp);
6989 /* We increment here since sctp_findassociation_ep_addr() will
6990 * do a decrement if it finds the stcb as long as the locked
6991 * tcb (last argument) is NOT a TCB.. aka NULL.
6993 SCTP_INP_INCR_REF(inp);
6994 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6996 SCTP_INP_DECR_REF(inp);
6998 SCTP_TCB_UNLOCK(stcb);
7002 /* Already have or am bring up an association */
7003 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7008 vrf_id = inp->def_vrf_id;
7010 for (i = 0; i < inp->num_vrfs; i++) {
7011 if (vrf_id == inp->m_vrf_ids[i]) {
7017 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7022 /* We are GOOD to go */
7023 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
7025 /* Gak! no memory */
7028 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
7029 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
7030 /* Set the connected flag so we can queue data */
7033 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
7034 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7036 /* initialize authentication parameters for the assoc */
7037 sctp_initialize_auth_params(inp, stcb);
7039 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7040 SCTP_TCB_UNLOCK(stcb);
7042 if (create_lock_on) {
7043 SCTP_ASOC_CREATE_UNLOCK(inp);
7046 SCTP_INP_DECR_REF(inp);
7051 #if defined(__Userspace__)
7053 sctpconn_connect(struct socket *so, struct sockaddr *addr)
7060 int create_lock_on = 0;
7062 struct sctp_inpcb *inp;
7063 struct sctp_tcb *stcb = NULL;
7065 inp = (struct sctp_inpcb *)so->so_pcb;
7067 /* I made the same as TCP since we are not setup? */
7068 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7069 return (ECONNRESET);
7072 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7075 switch (addr->sa_family) {
7079 if (addr->sa_len != sizeof(struct sockaddr_in)) {
7080 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7089 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
7090 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7098 if (addr->sa_len != sizeof(struct sockaddr_conn)) {
7099 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7105 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
7106 return (EAFNOSUPPORT);
7108 SCTP_INP_INCR_REF(inp);
7109 SCTP_ASOC_CREATE_LOCK(inp);
7113 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
7114 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
7115 /* Should I really unlock ? */
7116 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
7121 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
7122 (addr->sa_family == AF_INET6)) {
7123 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7128 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == SCTP_PCB_FLAGS_UNBOUND) {
7129 /* Bind a ephemeral port */
7130 error = sctp_inpcb_bind(so, NULL, NULL, p);
7135 /* Now do we connect? */
7136 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
7137 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
7138 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7142 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7143 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7144 /* We are already connected AND the TCP model */
7145 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7149 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7150 SCTP_INP_RLOCK(inp);
7151 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7152 SCTP_INP_RUNLOCK(inp);
7154 /* We increment here since sctp_findassociation_ep_addr() will
7155 * do a decrement if it finds the stcb as long as the locked
7156 * tcb (last argument) is NOT a TCB.. aka NULL.
7158 SCTP_INP_INCR_REF(inp);
7159 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
7161 SCTP_INP_DECR_REF(inp);
7163 SCTP_TCB_UNLOCK(stcb);
7167 /* Already have or am bring up an association */
7168 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7173 vrf_id = inp->def_vrf_id;
7175 for (i = 0; i < inp->num_vrfs; i++) {
7176 if (vrf_id == inp->m_vrf_ids[i]) {
7182 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7187 /* We are GOOD to go */
7188 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
7190 /* Gak! no memory */
7193 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
7194 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
7195 /* Set the connected flag so we can queue data */
7198 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
7199 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7201 /* initialize authentication parameters for the assoc */
7202 sctp_initialize_auth_params(inp, stcb);
7204 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7205 SCTP_TCB_UNLOCK(stcb);
7207 if (create_lock_on) {
7208 SCTP_ASOC_CREATE_UNLOCK(inp);
7211 SCTP_INP_DECR_REF(inp);
7216 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
7217 #if __FreeBSD_version >= 700000
7218 sctp_listen(struct socket *so, int backlog, struct thread *p)
7220 sctp_listen(struct socket *so, struct thread *p)
7222 #elif defined(__Windows__)
7223 sctp_listen(struct socket *so, int backlog, PKTHREAD p)
7224 #elif defined(__Userspace__)
7225 sctp_listen(struct socket *so, int backlog, struct proc *p)
7227 sctp_listen(struct socket *so, struct proc *p)
7231 * Note this module depends on the protocol processing being called
7232 * AFTER any socket level flags and backlog are applied to the
7233 * socket. The traditional way that the socket flags are applied is
7234 * AFTER protocol processing. We have made a change to the
7235 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7236 * place if the socket API for SCTP is to work properly.
7240 struct sctp_inpcb *inp;
7242 inp = (struct sctp_inpcb *)so->so_pcb;
7244 /* I made the same as TCP since we are not setup? */
7245 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7246 return (ECONNRESET);
7248 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7249 /* See if we have a listener */
7250 struct sctp_inpcb *tinp;
7251 union sctp_sockstore store;
7253 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7255 struct sctp_laddr *laddr;
7257 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7258 memcpy(&store, &laddr->ifa->address, sizeof(store));
7259 switch (store.sa.sa_family) {
7262 store.sin.sin_port = inp->sctp_lport;
7267 store.sin6.sin6_port = inp->sctp_lport;
7270 #if defined(__Userspace__)
7272 store.sconn.sconn_port = inp->sctp_lport;
7278 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7279 if (tinp && (tinp != inp) &&
7280 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7281 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7282 (tinp->sctp_socket->so_qlimit)) {
7283 /* we have a listener already and its not this inp. */
7284 SCTP_INP_DECR_REF(tinp);
7285 return (EADDRINUSE);
7287 SCTP_INP_DECR_REF(tinp);
7291 /* Setup a local addr bound all */
7292 memset(&store, 0, sizeof(store));
7294 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7295 store.sa.sa_family = AF_INET6;
7297 store.sa.sa_len = sizeof(struct sockaddr_in6);
7301 #if defined(__Userspace__)
7302 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_CONN) {
7303 store.sa.sa_family = AF_CONN;
7305 store.sa.sa_len = sizeof(struct sockaddr_conn);
7310 #if defined(__Userspace__)
7311 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
7312 ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_CONN) == 0)) {
7314 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7316 store.sa.sa_family = AF_INET;
7318 store.sa.sa_len = sizeof(struct sockaddr_in);
7322 switch (store.sa.sa_family) {
7325 store.sin.sin_port = inp->sctp_lport;
7330 store.sin6.sin6_port = inp->sctp_lport;
7333 #if defined(__Userspace__)
7335 store.sconn.sconn_port = inp->sctp_lport;
7341 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7342 if (tinp && (tinp != inp) &&
7343 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7344 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7345 (tinp->sctp_socket->so_qlimit)) {
7346 /* we have a listener already and its not this inp. */
7347 SCTP_INP_DECR_REF(tinp);
7348 return (EADDRINUSE);
7350 SCTP_INP_DECR_REF(inp);
7354 SCTP_INP_RLOCK(inp);
7355 #ifdef SCTP_LOCK_LOGGING
7356 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7357 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7361 #if (defined(__FreeBSD__) && __FreeBSD_version > 500000) || defined(__Userspace__)
7362 error = solisten_proto_check(so);
7365 SCTP_INP_RUNLOCK(inp);
7369 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7370 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7372 * - We are in the tcp pool with this guy.
7373 * - Someone else is in the main inp slot.
7374 * - We must move this guy (the listener) to the main slot
7375 * - We must then move the guy that was listener to the TCP Pool.
7377 if (sctp_swap_inpcb_for_listen(inp)) {
7382 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7383 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7384 /* We are already connected AND the TCP model */
7386 SCTP_INP_RUNLOCK(inp);
7388 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7389 return (EADDRINUSE);
7391 SCTP_INP_RUNLOCK(inp);
7392 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7393 /* We must do a bind. */
7395 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7396 /* bind error, probably perm */
7401 #if (defined(__FreeBSD__) && __FreeBSD_version > 500000) || defined(__Windows__) || defined(__Userspace__)
7402 #if __FreeBSD_version >= 700000 || defined(__Windows__) || defined(__Userspace__)
7403 /* It appears for 7.0 and on, we must always call this. */
7404 solisten_proto(so, backlog);
7406 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7411 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7412 /* remove the ACCEPTCONN flag for one-to-many sockets */
7413 #if defined(__Userspace__)
7414 so->so_options &= ~SCTP_SO_ACCEPTCONN;
7416 so->so_options &= ~SO_ACCEPTCONN;
7420 #if __FreeBSD_version >= 700000 || defined(__Windows__) || defined(__Userspace__)
7422 /* turning off listen */
7423 #if defined(__Userspace__)
7424 so->so_options &= ~SCTP_SO_ACCEPTCONN;
7426 so->so_options &= ~SO_ACCEPTCONN;
7434 static int sctp_defered_wakeup_cnt = 0;
7437 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__)
7438 sctp_accept(struct socket *so, struct sockaddr **addr)
7440 #elif defined(__Panda__)
7441 sctp_accept(struct socket *so, struct sockaddr *addr, int *namelen,
7442 void *accept_info, int *accept_info_len)
7445 sctp_accept(struct socket *so, struct mbuf *nam)
7447 struct sockaddr *addr = mtod(nam, struct sockaddr *);
7449 struct sctp_tcb *stcb;
7450 struct sctp_inpcb *inp;
7451 union sctp_sockstore store;
7455 #endif /* SCTP_KAME */
7457 inp = (struct sctp_inpcb *)so->so_pcb;
7460 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7461 return (ECONNRESET);
7463 SCTP_INP_RLOCK(inp);
7464 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7465 SCTP_INP_RUNLOCK(inp);
7466 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7467 return (EOPNOTSUPP);
7469 if (so->so_state & SS_ISDISCONNECTED) {
7470 SCTP_INP_RUNLOCK(inp);
7471 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7472 return (ECONNABORTED);
7474 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7476 SCTP_INP_RUNLOCK(inp);
7477 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7478 return (ECONNRESET);
7480 SCTP_TCB_LOCK(stcb);
7481 SCTP_INP_RUNLOCK(inp);
7482 store = stcb->asoc.primary_destination->ro._l_addr;
7483 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
7484 SCTP_TCB_UNLOCK(stcb);
7485 switch (store.sa.sa_family) {
7489 struct sockaddr_in *sin;
7491 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__)
7492 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7496 sin = (struct sockaddr_in *)addr;
7497 bzero((caddr_t)sin, sizeof(*sin));
7499 sin->sin_family = AF_INET;
7501 sin->sin_len = sizeof(*sin);
7503 sin->sin_port = store.sin.sin_port;
7504 sin->sin_addr = store.sin.sin_addr;
7505 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__)
7506 *addr = (struct sockaddr *)sin;
7507 #elif !defined(__Panda__)
7508 SCTP_BUF_LEN(nam) = sizeof(*sin);
7516 struct sockaddr_in6 *sin6;
7518 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__)
7519 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7523 sin6 = (struct sockaddr_in6 *)addr;
7524 bzero((caddr_t)sin6, sizeof(*sin6));
7526 sin6->sin6_family = AF_INET6;
7527 #ifdef HAVE_SIN6_LEN
7528 sin6->sin6_len = sizeof(*sin6);
7530 sin6->sin6_port = store.sin6.sin6_port;
7531 sin6->sin6_addr = store.sin6.sin6_addr;
7532 #if defined(SCTP_EMBEDDED_V6_SCOPE)
7534 if ((error = sa6_recoverscope(sin6)) != 0) {
7535 SCTP_FREE_SONAME(sin6);
7539 if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr))
7541 * sin6->sin6_scope_id =
7542 * ntohs(sin6->sin6_addr.s6_addr16[1]);
7544 in6_recoverscope(sin6, &sin6->sin6_addr, NULL); /* skip ifp check */
7546 sin6->sin6_scope_id = 0; /* XXX */
7547 #endif /* SCTP_KAME */
7548 #endif /* SCTP_EMBEDDED_V6_SCOPE */
7549 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__)
7550 *addr = (struct sockaddr *)sin6;
7551 #elif !defined(__Panda__)
7552 SCTP_BUF_LEN(nam) = sizeof(*sin6);
7557 #if defined(__Userspace__)
7560 struct sockaddr_conn *sconn;
7562 SCTP_MALLOC_SONAME(sconn, struct sockaddr_conn *, sizeof(struct sockaddr_conn));
7563 if (sconn == NULL) {
7566 sconn->sconn_family = AF_CONN;
7567 #ifdef HAVE_SCONN_LEN
7568 sconn->sconn_len = sizeof(struct sockaddr_conn);
7570 sconn->sconn_port = store.sconn.sconn_port;
7571 sconn->sconn_addr = store.sconn.sconn_addr;
7572 *addr = (struct sockaddr *)sconn;
7580 /* Wake any delayed sleep action */
7581 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7582 SCTP_INP_WLOCK(inp);
7583 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7584 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7585 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7586 SCTP_INP_WUNLOCK(inp);
7587 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7588 if (sowriteable(inp->sctp_socket)) {
7589 #if defined(__Userspace__)
7590 /*__Userspace__ calling sowwakup_locked because of SOCKBUF_LOCK above. */
7592 #if defined(__FreeBSD__) || defined(__Windows__) || defined(__Userspace__)
7593 sowwakeup_locked(inp->sctp_socket);
7595 #if defined(__APPLE__)
7596 /* socket is locked */
7598 sowwakeup(inp->sctp_socket);
7601 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7603 SCTP_INP_WLOCK(inp);
7605 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7606 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7607 SCTP_INP_WUNLOCK(inp);
7608 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7609 if (soreadable(inp->sctp_socket)) {
7610 sctp_defered_wakeup_cnt++;
7611 #if defined(__Userspace__)
7612 /*__Userspace__ calling sorwakup_locked because of SOCKBUF_LOCK above */
7614 #if defined(__FreeBSD__) || defined(__Windows__) || defined(__Userspace__)
7615 sorwakeup_locked(inp->sctp_socket);
7617 #if defined(__APPLE__)
7618 /* socket is locked */
7620 sorwakeup(inp->sctp_socket);
7623 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7625 SCTP_INP_WLOCK(inp);
7627 SCTP_INP_WUNLOCK(inp);
7629 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7630 SCTP_TCB_LOCK(stcb);
7631 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ+SCTP_LOC_7);
7638 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
7639 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7641 struct sockaddr_in *sin;
7642 #elif defined(__Panda__)
7643 sctp_ingetaddr(struct socket *so, struct sockaddr *addr)
7645 struct sockaddr_in *sin = (struct sockaddr_in *)addr;
7647 sctp_ingetaddr(struct socket *so, struct mbuf *nam)
7649 struct sockaddr_in *sin = mtod(nam, struct sockaddr_in *);
7652 struct sctp_inpcb *inp;
7653 struct sctp_ifa *sctp_ifa;
7656 * Do the malloc first in case it blocks.
7658 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
7659 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7662 #elif defined(__Panda__)
7663 bzero(sin, sizeof(*sin));
7665 SCTP_BUF_LEN(nam) = sizeof(*sin);
7666 memset(sin, 0, sizeof(*sin));
7668 sin->sin_family = AF_INET;
7670 sin->sin_len = sizeof(*sin);
7672 inp = (struct sctp_inpcb *)so->so_pcb;
7674 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
7675 SCTP_FREE_SONAME(sin);
7677 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7678 return (ECONNRESET);
7680 SCTP_INP_RLOCK(inp);
7681 sin->sin_port = inp->sctp_lport;
7682 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7683 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7684 struct sctp_tcb *stcb;
7685 struct sockaddr_in *sin_a;
7686 struct sctp_nets *net;
7689 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7695 SCTP_TCB_LOCK(stcb);
7696 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7697 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7699 /* this will make coverity happy */
7702 if (sin_a->sin_family == AF_INET) {
7707 if ((!fnd) || (sin_a == NULL)) {
7709 SCTP_TCB_UNLOCK(stcb);
7713 vrf_id = inp->def_vrf_id;
7714 sctp_ifa = sctp_source_address_selection(inp,
7716 (sctp_route_t *)&net->ro,
7719 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7720 sctp_free_ifa(sctp_ifa);
7722 SCTP_TCB_UNLOCK(stcb);
7724 /* For the bound all case you get back 0 */
7726 sin->sin_addr.s_addr = 0;
7730 /* Take the first IPv4 address in the list */
7731 struct sctp_laddr *laddr;
7734 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7735 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7736 struct sockaddr_in *sin_a;
7738 sin_a = (struct sockaddr_in *)&laddr->ifa->address.sa;
7739 sin->sin_addr = sin_a->sin_addr;
7745 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
7746 SCTP_FREE_SONAME(sin);
7748 SCTP_INP_RUNLOCK(inp);
7749 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7753 SCTP_INP_RUNLOCK(inp);
7754 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
7755 (*addr) = (struct sockaddr *)sin;
7761 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
7762 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7764 struct sockaddr_in *sin;
7765 #elif defined(__Panda__)
7766 sctp_peeraddr(struct socket *so, struct sockaddr *addr)
7768 struct sockaddr_in *sin = (struct sockaddr_in *)addr;
7770 sctp_peeraddr(struct socket *so, struct mbuf *nam)
7772 struct sockaddr_in *sin = mtod(nam, struct sockaddr_in *);
7776 struct sockaddr_in *sin_a;
7777 struct sctp_inpcb *inp;
7778 struct sctp_tcb *stcb;
7779 struct sctp_nets *net;
7781 /* Do the malloc first in case it blocks. */
7782 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
7783 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7786 #elif defined(__Panda__)
7787 memset(sin, 0, sizeof(*sin));
7789 SCTP_BUF_LEN(nam) = sizeof(*sin);
7790 memset(sin, 0, sizeof(*sin));
7792 sin->sin_family = AF_INET;
7794 sin->sin_len = sizeof(*sin);
7797 inp = (struct sctp_inpcb *)so->so_pcb;
7798 if ((inp == NULL) ||
7799 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7800 /* UDP type and listeners will drop out here */
7801 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
7802 SCTP_FREE_SONAME(sin);
7804 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7807 SCTP_INP_RLOCK(inp);
7808 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7810 SCTP_TCB_LOCK(stcb);
7812 SCTP_INP_RUNLOCK(inp);
7814 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
7815 SCTP_FREE_SONAME(sin);
7817 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7818 return (ECONNRESET);
7821 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7822 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7823 if (sin_a->sin_family == AF_INET) {
7825 sin->sin_port = stcb->rport;
7826 sin->sin_addr = sin_a->sin_addr;
7830 SCTP_TCB_UNLOCK(stcb);
7832 /* No IPv4 address */
7833 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
7834 SCTP_FREE_SONAME(sin);
7836 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7839 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
7840 (*addr) = (struct sockaddr *)sin;
7845 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
7846 struct pr_usrreqs sctp_usrreqs = {
7847 #if defined(__FreeBSD__)
7848 .pru_abort = sctp_abort,
7849 .pru_accept = sctp_accept,
7850 .pru_attach = sctp_attach,
7851 .pru_bind = sctp_bind,
7852 .pru_connect = sctp_connect,
7853 .pru_control = in_control,
7854 #if __FreeBSD_version >= 690000
7855 .pru_close = sctp_close,
7856 .pru_detach = sctp_close,
7857 .pru_sopoll = sopoll_generic,
7858 .pru_flush = sctp_flush,
7860 .pru_detach = sctp_detach,
7861 .pru_sopoll = sopoll,
7863 .pru_disconnect = sctp_disconnect,
7864 .pru_listen = sctp_listen,
7865 .pru_peeraddr = sctp_peeraddr,
7866 .pru_send = sctp_sendm,
7867 .pru_shutdown = sctp_shutdown,
7868 .pru_sockaddr = sctp_ingetaddr,
7869 .pru_sosend = sctp_sosend,
7870 .pru_soreceive = sctp_soreceive
7871 #elif defined(__APPLE__)
7872 .pru_abort = sctp_abort,
7873 .pru_accept = sctp_accept,
7874 .pru_attach = sctp_attach,
7875 .pru_bind = sctp_bind,
7876 .pru_connect = sctp_connect,
7877 .pru_connect2 = pru_connect2_notsupp,
7878 .pru_control = in_control,
7879 .pru_detach = sctp_detach,
7880 .pru_disconnect = sctp_disconnect,
7881 .pru_listen = sctp_listen,
7882 .pru_peeraddr = sctp_peeraddr,
7884 .pru_rcvoob = pru_rcvoob_notsupp,
7885 .pru_send = sctp_sendm,
7886 .pru_sense = pru_sense_null,
7887 .pru_shutdown = sctp_shutdown,
7888 .pru_sockaddr = sctp_ingetaddr,
7889 .pru_sosend = sctp_sosend,
7890 .pru_soreceive = sctp_soreceive,
7891 .pru_sopoll = sopoll
7892 #elif defined(__Windows__)
7898 pru_connect2_notsupp,
7918 #elif !defined(__Panda__) && !defined(__Userspace__)
7920 sctp_usrreq(so, req, m, nam, control)
7923 struct mbuf *m, *nam, *control;
7925 struct proc *p = curproc;
7927 struct sctp_vrf *vrf;
7930 struct sctp_inpcb *inp = (struct sctp_inpcb *)so->so_pcb;
7933 family = so->so_proto->pr_domain->dom_family;
7934 if (req == PRU_CONTROL) {
7937 error = in_control(so, (long)m, (caddr_t)nam,
7938 (struct ifnet *)control);
7942 error = in6_control(so, (long)m, (caddr_t)nam,
7943 (struct ifnet *)control, p);
7947 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
7948 error = EAFNOSUPPORT;
7954 error = sctp_attach(so, family, p);
7957 error = sctp_detach(so);
7961 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7964 error = sctp_bind(so, nam, p);
7967 error = sctp_listen(so, p);
7971 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7974 error = sctp_connect(so, nam, p);
7976 case PRU_DISCONNECT:
7977 error = sctp_disconnect(so);
7981 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7984 error = sctp_accept(so, nam);
7987 error = sctp_shutdown(so);
7992 * For Open and Net BSD, this is real ugly. The mbuf *nam
7993 * that is passed (by soreceive()) is the int flags c ast as
7999 /* Flags are ignored */
8001 struct sockaddr *addr;
8006 addr = mtod(nam, struct sockaddr *);
8008 error = sctp_sendm(so, 0, m, addr, control, p);
8012 error = sctp_abort(so);
8019 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
8020 error = EAFNOSUPPORT;
8023 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
8024 error = EAFNOSUPPORT;
8027 error = sctp_peeraddr(so, nam);
8030 error = sctp_ingetaddr(so, nam);
8044 #if defined(__Userspace__)
8046 register_recv_cb(struct socket *so,
8047 int (*receive_cb)(struct socket *sock, union sctp_sockstore addr, void *data,
8048 size_t datalen, struct sctp_rcvinfo, int flags, void *ulp_info))
8050 struct sctp_inpcb *inp;
8052 inp = (struct sctp_inpcb *) so->so_pcb;
8056 SCTP_INP_WLOCK(inp);
8057 inp->recv_callback = receive_cb;
8058 SCTP_INP_WUNLOCK(inp);
8063 register_send_cb(struct socket *so, uint32_t sb_threshold, int (*send_cb)(struct socket *sock, uint32_t sb_free))
8065 struct sctp_inpcb *inp;
8067 inp = (struct sctp_inpcb *) so->so_pcb;
8071 SCTP_INP_WLOCK(inp);
8072 inp->send_callback = send_cb;
8073 inp->send_sb_threshold = sb_threshold;
8074 SCTP_INP_WUNLOCK(inp);
8075 /* FIXME change to current amount free. This will be the full buffer
8076 * the first time this is registered but it could be only a portion
8077 * of the send buffer if this is called a second time e.g. if the
8078 * threshold changes.
8084 register_ulp_info (struct socket *so, void *ulp_info)
8086 struct sctp_inpcb *inp;
8088 inp = (struct sctp_inpcb *) so->so_pcb;
8092 SCTP_INP_WLOCK(inp);
8093 inp->ulp_info = ulp_info;
8094 SCTP_INP_WUNLOCK(inp);