2 * Copyright (c) 1982, 1986, 1988, 1990, 1993
3 * The Regents of the University of California.
4 * Copyright (c) 2004 The FreeBSD Foundation
5 * Copyright (c) 2004-2008 Robert N. M. Watson
6 * Copyright (c) 2009-2010 Brad Penoff
7 * Copyright (c) 2009-2010 Humaira Kamal
8 * Copyright (c) 2011-2012 Irene Ruengeler
9 * Copyright (c) 2011-2012 Michael Tuexen
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <netinet/sctp_os.h>
36 #include <netinet/sctp_pcb.h>
37 #include <netinet/sctputil.h>
38 #include <netinet/sctp_var.h>
39 #include <netinet/sctp_sysctl.h>
40 #include <netinet/sctp_input.h>
41 #include <netinet/sctp_peeloff.h>
42 #include <netinet/sctp_callout.h>
43 #include <netinet/sctp_crc32.h>
45 #include <netinet6/sctp6_var.h>
47 #if defined(__FreeBSD__)
48 #include <sys/param.h>
50 #if defined(__linux__)
51 #define __FAVOR_BSD /* (on Ubuntu at least) enables UDP header field names like BSD in RFC 768 */
54 #if defined INET || defined INET6
55 #include <netinet/udp.h>
57 #include <arpa/inet.h>
59 #include <user_socketvar.h>
61 userland_mutex_t accept_mtx;
62 userland_cond_t accept_cond;
65 #include <sys/timeb.h>
68 MALLOC_DEFINE(M_PCB, "sctp_pcb", "sctp pcb");
69 MALLOC_DEFINE(M_SONAME, "sctp_soname", "sctp soname");
70 #define MAXLEN_MBUF_CHAIN 32
73 extern int sctp_sosend(struct socket *so, struct sockaddr *addr, struct uio *uio,
74 struct mbuf *top, struct mbuf *control, int flags,
75 /* proc is a dummy in __Userspace__ and will not be passed to sctp_lower_sosend */
78 extern int sctp_attach(struct socket *so, int proto, uint32_t vrf_id);
79 extern int sctpconn_attach(struct socket *so, int proto, uint32_t vrf_id);
81 static void init_sync(void) {
83 #if defined(INET) || defined(INET6)
86 if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
87 SCTP_PRINTF("WSAStartup failed\n");
91 InitializeConditionVariable(&accept_cond);
92 InitializeCriticalSection(&accept_mtx);
94 pthread_mutexattr_t mutex_attr;
96 pthread_mutexattr_init(&mutex_attr);
98 pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_ERRORCHECK);
100 pthread_mutex_init(&accept_mtx, &mutex_attr);
101 pthread_mutexattr_destroy(&mutex_attr);
102 pthread_cond_init(&accept_cond, NULL);
107 usrsctp_init(uint16_t port,
108 int (*conn_output)(void *addr, void *buffer, size_t length, uint8_t tos, uint8_t set_df),
109 void (*debug_printf)(const char *format, ...))
112 sctp_init(port, conn_output, debug_printf, 1);
117 usrsctp_init_nothreads(uint16_t port,
118 int (*conn_output)(void *addr, void *buffer, size_t length, uint8_t tos, uint8_t set_df),
119 void (*debug_printf)(const char *format, ...))
122 sctp_init(port, conn_output, debug_printf, 0);
126 /* Taken from usr/src/sys/kern/uipc_sockbuf.c and modified for __Userspace__*/
128 * Socantsendmore indicates that no more data will be sent on the socket; it
129 * would normally be applied to a socket when the user informs the system
130 * that no more data is to be sent, by the protocol code (in case
131 * PRU_SHUTDOWN). Socantrcvmore indicates that no more data will be
132 * received, and will normally be applied to the socket by a protocol when it
133 * detects that the peer will send no more data. Data queued for reading in
134 * the socket may yet be read.
137 void socantrcvmore_locked(struct socket *so)
139 SOCKBUF_LOCK_ASSERT(&so->so_rcv);
140 so->so_rcv.sb_state |= SBS_CANTRCVMORE;
141 sorwakeup_locked(so);
144 void socantrcvmore(struct socket *so)
146 SOCKBUF_LOCK(&so->so_rcv);
147 socantrcvmore_locked(so);
151 socantsendmore_locked(struct socket *so)
153 SOCKBUF_LOCK_ASSERT(&so->so_snd);
154 so->so_snd.sb_state |= SBS_CANTSENDMORE;
155 sowwakeup_locked(so);
159 socantsendmore(struct socket *so)
161 SOCKBUF_LOCK(&so->so_snd);
162 socantsendmore_locked(so);
167 /* Taken from usr/src/sys/kern/uipc_sockbuf.c and called within sctp_lower_sosend.
170 sbwait(struct sockbuf *sb)
172 SOCKBUF_LOCK_ASSERT(sb);
174 sb->sb_flags |= SB_WAIT;
176 if (SleepConditionVariableCS(&(sb->sb_cond), &(sb->sb_mtx), INFINITE))
181 return (pthread_cond_wait(&(sb->sb_cond), &(sb->sb_mtx)));
188 /* Taken from /src/sys/kern/uipc_socket.c
189 * and modified for __Userspace__
191 static struct socket *
197 * soalloc() sets of socket layer state for a socket,
198 * called only by socreate() and sonewconn().
200 * sodealloc() tears down socket layer state for a socket,
201 * called only by sofree() and sonewconn().
202 * __Userspace__ TODO : Make sure so is properly deallocated
203 * when tearing down the connection.
206 so = (struct socket *)malloc(sizeof(struct socket));
211 memset(so, 0, sizeof(struct socket));
213 /* __Userspace__ Initializing the socket locks here */
214 SOCKBUF_LOCK_INIT(&so->so_snd, "so_snd");
215 SOCKBUF_LOCK_INIT(&so->so_rcv, "so_rcv");
216 SOCKBUF_COND_INIT(&so->so_snd);
217 SOCKBUF_COND_INIT(&so->so_rcv);
218 SOCK_COND_INIT(so); /* timeo_cond */
220 /* __Userspace__ Any ref counting required here? Will we have any use for aiojobq?
221 What about gencnt and numopensockets?*/
222 TAILQ_INIT(&so->so_aiojobq);
227 sodealloc(struct socket *so)
230 KASSERT(so->so_count == 0, ("sodealloc(): so_count %d", so->so_count));
231 KASSERT(so->so_pcb == NULL, ("sodealloc(): so_pcb != NULL"));
233 SOCKBUF_COND_DESTROY(&so->so_snd);
234 SOCKBUF_COND_DESTROY(&so->so_rcv);
236 SOCK_COND_DESTROY(so);
238 SOCKBUF_LOCK_DESTROY(&so->so_snd);
239 SOCKBUF_LOCK_DESTROY(&so->so_rcv);
244 /* Taken from /src/sys/kern/uipc_socket.c
245 * and modified for __Userspace__
248 sofree(struct socket *so)
252 ACCEPT_LOCK_ASSERT();
253 SOCK_LOCK_ASSERT(so);
254 /* SS_NOFDREF unset in accept call. this condition seems irrelevent
255 * for __Userspace__...
257 if (so->so_count != 0 ||
258 (so->so_state & SS_PROTOREF) || (so->so_qstate & SQ_COMP)) {
265 KASSERT((so->so_qstate & SQ_COMP) != 0 ||
266 (so->so_qstate & SQ_INCOMP) != 0,
267 ("sofree: so_head != NULL, but neither SQ_COMP nor "
269 KASSERT((so->so_qstate & SQ_COMP) == 0 ||
270 (so->so_qstate & SQ_INCOMP) == 0,
271 ("sofree: so->so_qstate is SQ_COMP and also SQ_INCOMP"));
272 TAILQ_REMOVE(&head->so_incomp, so, so_list);
274 so->so_qstate &= ~SQ_INCOMP;
277 KASSERT((so->so_qstate & SQ_COMP) == 0 &&
278 (so->so_qstate & SQ_INCOMP) == 0,
279 ("sofree: so_head == NULL, but still SQ_COMP(%d) or SQ_INCOMP(%d)",
280 so->so_qstate & SQ_COMP, so->so_qstate & SQ_INCOMP));
281 if (so->so_options & SCTP_SO_ACCEPTCONN) {
282 KASSERT((TAILQ_EMPTY(&so->so_comp)), ("sofree: so_comp populated"));
283 KASSERT((TAILQ_EMPTY(&so->so_incomp)), ("sofree: so_comp populated"));
287 sctp_close(so); /* was... sctp_detach(so); */
289 * From this point on, we assume that no other references to this
290 * socket exist anywhere else in the stack. Therefore, no locks need
291 * to be acquired or held.
293 * We used to do a lot of socket buffer and socket locking here, as
294 * well as invoke sorflush() and perform wakeups. The direct call to
295 * dom_dispose() and sbrelease_internal() are an inlining of what was
296 * necessary from sorflush().
298 * Notice that the socket buffer and kqueue state are torn down
299 * before calling pru_detach. This means that protocols shold not
300 * assume they can perform socket wakeups, etc, in their detach code.
307 /* Taken from /src/sys/kern/uipc_socket.c */
309 soabort(struct socket *so)
312 struct sctp_inpcb *inp;
316 inp = (struct sctp_inpcb *)so->so_pcb;
317 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
333 /* Taken from usr/src/sys/kern/uipc_socket.c and called within sctp_connect (sctp_usrreq.c).
334 * We use sctp_connect for send_one_init_real in ms1.
337 soisconnecting(struct socket *so)
341 so->so_state &= ~(SS_ISCONNECTED|SS_ISDISCONNECTING);
342 so->so_state |= SS_ISCONNECTING;
346 /* Taken from usr/src/sys/kern/uipc_socket.c and called within sctp_disconnect (sctp_usrreq.c).
347 * TODO Do we use sctp_disconnect?
350 soisdisconnecting(struct socket *so)
354 * Note: This code assumes that SOCK_LOCK(so) and
355 * SOCKBUF_LOCK(&so->so_rcv) are the same.
357 SOCKBUF_LOCK(&so->so_rcv);
358 so->so_state &= ~SS_ISCONNECTING;
359 so->so_state |= SS_ISDISCONNECTING;
360 so->so_rcv.sb_state |= SBS_CANTRCVMORE;
361 sorwakeup_locked(so);
362 SOCKBUF_LOCK(&so->so_snd);
363 so->so_snd.sb_state |= SBS_CANTSENDMORE;
364 sowwakeup_locked(so);
366 /* requires 2 args but this was in orig */
367 /* wakeup(&so->so_timeo); */
371 /* Taken from sys/kern/kern_synch.c and
372 modified for __Userspace__
376 * Make all threads sleeping on the specified identifier runnable.
377 * Associating wakeup with so_timeo identifier and timeo_cond
378 * condition variable. TODO. If we use iterator thread then we need to
379 * modify wakeup so it can distinguish between iterator identifier and
383 wakeup(void *ident, struct socket *so)
387 WakeAllConditionVariable(&(so)->timeo_cond);
389 pthread_cond_broadcast(&(so)->timeo_cond);
396 * Make a thread sleeping on the specified identifier runnable.
397 * May wake more than one thread if a target thread is currently
401 wakeup_one(void *ident)
403 /* __Userspace__ Check: We are using accept_cond for wakeup_one.
404 It seems that wakeup_one is only called within
405 soisconnected() and sonewconn() with ident &head->so_timeo
406 head is so->so_head, which is back pointer to listen socket
407 This seems to indicate that the use of accept_cond is correct
408 since socket where accepts occur is so_head in all
413 WakeAllConditionVariable(&accept_cond);
415 pthread_cond_broadcast(&accept_cond);
421 /* Called within sctp_process_cookie_[existing/new] */
423 soisconnected(struct socket *so)
429 so->so_state &= ~(SS_ISCONNECTING|SS_ISDISCONNECTING|SS_ISCONFIRMING);
430 so->so_state |= SS_ISCONNECTED;
432 if (head != NULL && (so->so_qstate & SQ_INCOMP)) {
434 TAILQ_REMOVE(&head->so_incomp, so, so_list);
436 so->so_qstate &= ~SQ_INCOMP;
437 TAILQ_INSERT_TAIL(&head->so_comp, so, so_list);
439 so->so_qstate |= SQ_COMP;
442 wakeup_one(&head->so_timeo);
447 wakeup(&so->so_timeo, so);
453 /* called within sctp_handle_cookie_echo */
456 sonewconn(struct socket *head, int connstatus)
462 over = (head->so_qlen > 3 * head->so_qlimit / 2);
465 if (regression_sonewconn_earlytest && over)
474 so->so_type = head->so_type;
475 so->so_options = head->so_options &~ SCTP_SO_ACCEPTCONN;
476 so->so_linger = head->so_linger;
477 so->so_state = head->so_state | SS_NOFDREF;
478 so->so_dom = head->so_dom;
481 mac_create_socket_from_socket(head, so);
484 if (soreserve(so, head->so_snd.sb_hiwat, head->so_rcv.sb_hiwat)) {
488 switch (head->so_dom) {
491 if (sctp_attach(so, IPPROTO_SCTP, SCTP_DEFAULT_VRFID)) {
499 if (sctp6_attach(so, IPPROTO_SCTP, SCTP_DEFAULT_VRFID)) {
506 if (sctpconn_attach(so, IPPROTO_SCTP, SCTP_DEFAULT_VRFID)) {
516 so->so_rcv.sb_lowat = head->so_rcv.sb_lowat;
517 so->so_snd.sb_lowat = head->so_snd.sb_lowat;
518 so->so_rcv.sb_timeo = head->so_rcv.sb_timeo;
519 so->so_snd.sb_timeo = head->so_snd.sb_timeo;
520 so->so_rcv.sb_flags |= head->so_rcv.sb_flags & SB_AUTOSIZE;
521 so->so_snd.sb_flags |= head->so_snd.sb_flags & SB_AUTOSIZE;
522 so->so_state |= connstatus;
525 TAILQ_INSERT_TAIL(&head->so_comp, so, so_list);
526 so->so_qstate |= SQ_COMP;
530 * Keep removing sockets from the head until there's room for
531 * us to insert on the tail. In pre-locking revisions, this
532 * was a simple if (), but as we could be racing with other
533 * threads and soabort() requires dropping locks, we must
534 * loop waiting for the condition to be true.
536 while (head->so_incqlen > head->so_qlimit) {
538 sp = TAILQ_FIRST(&head->so_incomp);
539 TAILQ_REMOVE(&head->so_incomp, sp, so_list);
541 sp->so_qstate &= ~SQ_INCOMP;
547 TAILQ_INSERT_TAIL(&head->so_incomp, so, so_list);
548 so->so_qstate |= SQ_INCOMP;
554 wakeup_one(&head->so_timeo);
561 Source: /src/sys/gnu/fs/xfs/FreeBSD/xfs_ioctl.c
563 static __inline__ int
564 copy_to_user(void *dst, void *src, size_t len) {
565 memcpy(dst, src, len);
569 static __inline__ int
570 copy_from_user(void *dst, void *src, size_t len) {
571 memcpy(dst, src, len);
577 src/sys/dev/lmc/if_lmc.h:
578 src/sys/powerpc/powerpc/copyinout.c
581 # define copyin(u, k, len) copy_from_user(k, u, len)
584 src/sys/powerpc/powerpc/copyinout.c
587 # define copyout(k, u, len) copy_to_user(u, k, len)
590 /* copyiniov definition copied/modified from src/sys/kern/kern_subr.c */
592 copyiniov(struct iovec *iovp, u_int iovcnt, struct iovec **iov, int error)
597 if (iovcnt > UIO_MAXIOV)
599 iovlen = iovcnt * sizeof (struct iovec);
600 *iov = malloc(iovlen); /*, M_IOV, M_WAITOK); */
601 error = copyin(iovp, *iov, iovlen);
603 free(*iov); /*, M_IOV); */
609 /* (__Userspace__) version of uiomove */
611 uiomove(void *cp, int n, struct uio *uio)
617 if ((uio->uio_rw != UIO_READ) &&
618 (uio->uio_rw != UIO_WRITE)) {
622 while (n > 0 && uio->uio_resid) {
633 switch (uio->uio_segflg) {
636 if (uio->uio_rw == UIO_READ)
637 error = copyout(cp, iov->iov_base, cnt);
639 error = copyin(iov->iov_base, cp, cnt);
645 if (uio->uio_rw == UIO_READ)
646 memcpy(iov->iov_base, cp, cnt);
648 memcpy(cp, iov->iov_base, cnt);
651 iov->iov_base = (char *)iov->iov_base + cnt;
653 uio->uio_resid -= cnt;
654 uio->uio_offset += (off_t)cnt;
655 cp = (char *)cp + cnt;
663 /* Source: src/sys/kern/uipc_syscalls.c */
665 getsockaddr(struct sockaddr **namp, caddr_t uaddr, size_t len)
670 if (len > SOCK_MAXADDRLEN)
671 return (ENAMETOOLONG);
672 if (len < offsetof(struct sockaddr, sa_data))
674 MALLOC(sa, struct sockaddr *, len, M_SONAME, M_WAITOK);
675 error = copyin(uaddr, sa, len);
688 usrsctp_getsockopt(struct socket *so, int level, int option_name,
689 void *option_value, socklen_t *option_len);
692 usrsctp_getassocid(struct socket *sock, struct sockaddr *sa)
694 struct sctp_paddrinfo sp;
700 /* First get the assoc id */
702 memset(&sp, 0, sizeof(sp));
704 memcpy((caddr_t)&sp.spinfo_address, sa, sa->sa_len);
706 switch (sa->sa_family) {
709 sa_len = sizeof(struct sockaddr_in);
714 sa_len = sizeof(struct sockaddr_in6);
718 sa_len = sizeof(struct sockaddr_conn);
724 memcpy((caddr_t)&sp.spinfo_address, sa, sa_len);
726 if (usrsctp_getsockopt(sock, IPPROTO_SCTP, SCTP_GET_PEER_ADDR_INFO, &sp, &siz) != 0) {
727 /* We depend on the fact that 0 can never be returned */
728 return ((sctp_assoc_t) 0);
730 return (sp.spinfo_assoc_id);
734 /* Taken from /src/lib/libc/net/sctp_sys_calls.c
735 * and modified for __Userspace__
736 * calling sctp_generic_sendmsg from this function
739 userspace_sctp_sendmsg(struct socket *so,
750 struct sctp_sndrcvinfo sndrcvinfo, *sinfo = &sndrcvinfo;
754 memset(sinfo, 0, sizeof(struct sctp_sndrcvinfo));
755 sinfo->sinfo_ppid = ppid;
756 sinfo->sinfo_flags = flags;
757 sinfo->sinfo_stream = stream_no;
758 sinfo->sinfo_timetolive = timetolive;
759 sinfo->sinfo_context = context;
760 sinfo->sinfo_assoc_id = 0;
763 /* Perform error checks on destination (to) */
764 if (tolen > SOCK_MAXADDRLEN) {
765 errno = ENAMETOOLONG;
769 ((to == NULL) || (tolen < (socklen_t)sizeof(struct sockaddr)))) {
777 /* Adding the following as part of defensive programming, in case the application
778 does not do it when preparing the destination address.*/
785 iov[0].iov_base = (caddr_t)data;
786 iov[0].iov_len = len;
790 auio.uio_segflg = UIO_USERSPACE;
791 auio.uio_rw = UIO_WRITE;
792 auio.uio_offset = 0; /* XXX */
793 auio.uio_resid = len;
794 errno = sctp_lower_sosend(so, to, &auio, NULL, NULL, 0, sinfo);
796 return (len - auio.uio_resid);
804 usrsctp_sendv(struct socket *so,
811 unsigned int infotype,
814 struct sctp_sndrcvinfo sinfo;
818 sctp_assoc_t *assoc_id;
828 memset(&sinfo, 0, sizeof(struct sctp_sndrcvinfo));
832 case SCTP_SENDV_NOINFO:
833 if ((infolen != 0) || (info != NULL)) {
838 case SCTP_SENDV_SNDINFO:
839 if ((info == NULL) || (infolen != sizeof(struct sctp_sndinfo))) {
843 sinfo.sinfo_stream = ((struct sctp_sndinfo *)info)->snd_sid;
844 sinfo.sinfo_flags = ((struct sctp_sndinfo *)info)->snd_flags;
845 sinfo.sinfo_ppid = ((struct sctp_sndinfo *)info)->snd_ppid;
846 sinfo.sinfo_context = ((struct sctp_sndinfo *)info)->snd_context;
847 sinfo.sinfo_assoc_id = ((struct sctp_sndinfo *)info)->snd_assoc_id;
848 assoc_id = &(((struct sctp_sndinfo *)info)->snd_assoc_id);
851 case SCTP_SENDV_PRINFO:
852 if ((info == NULL) || (infolen != sizeof(struct sctp_prinfo))) {
856 sinfo.sinfo_stream = 0;
857 sinfo.sinfo_flags = PR_SCTP_POLICY(((struct sctp_prinfo *)info)->pr_policy);
858 sinfo.sinfo_timetolive = ((struct sctp_prinfo *)info)->pr_value;
861 case SCTP_SENDV_AUTHINFO:
865 if ((info == NULL) || (infolen != sizeof(struct sctp_sendv_spa))) {
869 if (((struct sctp_sendv_spa *)info)->sendv_flags & SCTP_SEND_SNDINFO_VALID) {
870 sinfo.sinfo_stream = ((struct sctp_sendv_spa *)info)->sendv_sndinfo.snd_sid;
871 sinfo.sinfo_flags = ((struct sctp_sendv_spa *)info)->sendv_sndinfo.snd_flags;
872 sinfo.sinfo_ppid = ((struct sctp_sendv_spa *)info)->sendv_sndinfo.snd_ppid;
873 sinfo.sinfo_context = ((struct sctp_sendv_spa *)info)->sendv_sndinfo.snd_context;
874 sinfo.sinfo_assoc_id = ((struct sctp_sendv_spa *)info)->sendv_sndinfo.snd_assoc_id;
875 assoc_id = &(((struct sctp_sendv_spa *)info)->sendv_sndinfo.snd_assoc_id);
877 sinfo.sinfo_flags = 0;
878 sinfo.sinfo_stream = 0;
880 if (((struct sctp_sendv_spa *)info)->sendv_flags & SCTP_SEND_PRINFO_VALID) {
881 sinfo.sinfo_flags |= PR_SCTP_POLICY(((struct sctp_sendv_spa *)info)->sendv_prinfo.pr_policy);
882 sinfo.sinfo_timetolive = ((struct sctp_sendv_spa *)info)->sendv_prinfo.pr_value;
884 if (((struct sctp_sendv_spa *)info)->sendv_flags & SCTP_SEND_AUTHINFO_VALID) {
895 /* Perform error checks on destination (to) */
901 iov[0].iov_base = (caddr_t)data;
902 iov[0].iov_len = len;
906 auio.uio_segflg = UIO_USERSPACE;
907 auio.uio_rw = UIO_WRITE;
908 auio.uio_offset = 0; /* XXX */
909 auio.uio_resid = len;
910 errno = sctp_lower_sosend(so, to, &auio, NULL, NULL, flags, use_sinfo ? &sinfo : NULL);
912 if ((to != NULL) && (assoc_id != NULL)) {
913 *assoc_id = usrsctp_getassocid(so, to);
915 return (len - auio.uio_resid);
923 userspace_sctp_sendmbuf(struct socket *so,
924 struct mbuf* mbufdata,
935 struct sctp_sndrcvinfo sndrcvinfo, *sinfo = &sndrcvinfo;
937 struct iovec iov[1]; */
942 sinfo->sinfo_ppid = ppid;
943 sinfo->sinfo_flags = flags;
944 sinfo->sinfo_stream = stream_no;
945 sinfo->sinfo_timetolive = timetolive;
946 sinfo->sinfo_context = context;
947 sinfo->sinfo_assoc_id = 0;
949 /* Perform error checks on destination (to) */
950 if (tolen > SOCK_MAXADDRLEN){
951 error = (ENAMETOOLONG);
954 if (tolen < (socklen_t)offsetof(struct sockaddr, sa_data)){
958 /* Adding the following as part of defensive programming, in case the application
959 does not do it when preparing the destination address.*/
964 error = sctp_lower_sosend(so, to, NULL/*uio*/,
965 (struct mbuf *)mbufdata, (struct mbuf *)NULL,
968 /* TODO: Needs a condition for non-blocking when error is EWOULDBLOCK */
971 else if (error == EWOULDBLOCK) {
975 SCTP_PRINTF("%s: error = %d\n", __func__, error);
983 /* taken from usr.lib/sctp_sys_calls.c and needed here */
984 #define SCTP_SMALL_IOVEC_SIZE 2
986 /* Taken from /src/lib/libc/net/sctp_sys_calls.c
987 * and modified for __Userspace__
988 * calling sctp_generic_recvmsg from this function
991 userspace_sctp_recvmsg(struct socket *so,
994 struct sockaddr *from,
996 struct sctp_sndrcvinfo *sinfo,
1000 struct iovec iov[SCTP_SMALL_IOVEC_SIZE];
1008 iov[0].iov_base = dbuf;
1009 iov[0].iov_len = len;
1012 auio.uio_iovcnt = iovlen;
1013 auio.uio_segflg = UIO_USERSPACE;
1014 auio.uio_rw = UIO_READ;
1015 auio.uio_offset = 0; /* XXX */
1018 for (i = 0; i <iovlen; i++, tiov++) {
1019 if ((auio.uio_resid += tiov->iov_len) < 0) {
1021 SCTP_PRINTF("%s: error = %d\n", __func__, error);
1025 ulen = auio.uio_resid;
1026 if (fromlenp != NULL) {
1027 fromlen = *fromlenp;
1031 error = sctp_sorecvmsg(so, &auio, (struct mbuf **)NULL,
1032 from, fromlen, msg_flags,
1033 (struct sctp_sndrcvinfo *)sinfo, 1);
1036 if ((auio.uio_resid != ulen) &&
1038 #if !defined(__NetBSD__)
1039 error == ERESTART ||
1041 error == EWOULDBLOCK)) {
1045 if ((fromlenp != NULL) && (fromlen > 0) && (from != NULL)) {
1046 switch (from->sa_family) {
1049 *fromlenp = sizeof(struct sockaddr_in);
1054 *fromlenp = sizeof(struct sockaddr_in6);
1058 *fromlenp = sizeof(struct sockaddr_conn);
1064 if (*fromlenp > fromlen) {
1065 *fromlenp = fromlen;
1069 /* ready return value */
1070 return (ulen - auio.uio_resid);
1072 SCTP_PRINTF("%s: error = %d\n", __func__, error);
1078 usrsctp_recvv(struct socket *so,
1081 struct sockaddr *from,
1082 socklen_t *fromlenp,
1085 unsigned int *infotype,
1089 struct iovec iov[SCTP_SMALL_IOVEC_SIZE];
1095 struct sctp_rcvinfo *rcv;
1096 struct sctp_recvv_rn *rn;
1097 struct sctp_extrcvinfo seinfo;
1103 iov[0].iov_base = dbuf;
1104 iov[0].iov_len = len;
1107 auio.uio_iovcnt = iovlen;
1108 auio.uio_segflg = UIO_USERSPACE;
1109 auio.uio_rw = UIO_READ;
1110 auio.uio_offset = 0; /* XXX */
1113 for (i = 0; i <iovlen; i++, tiov++) {
1114 if ((auio.uio_resid += tiov->iov_len) < 0) {
1119 ulen = auio.uio_resid;
1120 if (fromlenp != NULL) {
1121 fromlen = *fromlenp;
1125 errno = sctp_sorecvmsg(so, &auio, (struct mbuf **)NULL,
1126 from, fromlen, msg_flags,
1127 (struct sctp_sndrcvinfo *)&seinfo, 1);
1129 if ((auio.uio_resid != ulen) &&
1131 #if !defined(__NetBSD__)
1132 errno == ERESTART ||
1134 errno == EWOULDBLOCK)) {
1141 if ((*msg_flags & MSG_NOTIFICATION) == 0) {
1142 struct sctp_inpcb *inp;
1144 inp = (struct sctp_inpcb *)so->so_pcb;
1145 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO) &&
1146 sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO) &&
1147 *infolen >= (socklen_t)sizeof(struct sctp_recvv_rn) &&
1148 seinfo.sreinfo_next_flags & SCTP_NEXT_MSG_AVAIL) {
1149 rn = (struct sctp_recvv_rn *)info;
1150 rn->recvv_rcvinfo.rcv_sid = seinfo.sinfo_stream;
1151 rn->recvv_rcvinfo.rcv_ssn = seinfo.sinfo_ssn;
1152 rn->recvv_rcvinfo.rcv_flags = seinfo.sinfo_flags;
1153 rn->recvv_rcvinfo.rcv_ppid = seinfo.sinfo_ppid;
1154 rn->recvv_rcvinfo.rcv_context = seinfo.sinfo_context;
1155 rn->recvv_rcvinfo.rcv_tsn = seinfo.sinfo_tsn;
1156 rn->recvv_rcvinfo.rcv_cumtsn = seinfo.sinfo_cumtsn;
1157 rn->recvv_rcvinfo.rcv_assoc_id = seinfo.sinfo_assoc_id;
1158 rn->recvv_nxtinfo.nxt_sid = seinfo.sreinfo_next_stream;
1159 rn->recvv_nxtinfo.nxt_flags = 0;
1160 if (seinfo.sreinfo_next_flags & SCTP_NEXT_MSG_IS_UNORDERED) {
1161 rn->recvv_nxtinfo.nxt_flags |= SCTP_UNORDERED;
1163 if (seinfo.sreinfo_next_flags & SCTP_NEXT_MSG_IS_NOTIFICATION) {
1164 rn->recvv_nxtinfo.nxt_flags |= SCTP_NOTIFICATION;
1166 if (seinfo.sreinfo_next_flags & SCTP_NEXT_MSG_ISCOMPLETE) {
1167 rn->recvv_nxtinfo.nxt_flags |= SCTP_COMPLETE;
1169 rn->recvv_nxtinfo.nxt_ppid = seinfo.sreinfo_next_ppid;
1170 rn->recvv_nxtinfo.nxt_length = seinfo.sreinfo_next_length;
1171 rn->recvv_nxtinfo.nxt_assoc_id = seinfo.sreinfo_next_aid;
1172 *infolen = (socklen_t)sizeof(struct sctp_recvv_rn);
1173 *infotype = SCTP_RECVV_RN;
1174 } else if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO) &&
1175 *infolen >= (socklen_t)sizeof(struct sctp_rcvinfo)) {
1176 rcv = (struct sctp_rcvinfo *)info;
1177 rcv->rcv_sid = seinfo.sinfo_stream;
1178 rcv->rcv_ssn = seinfo.sinfo_ssn;
1179 rcv->rcv_flags = seinfo.sinfo_flags;
1180 rcv->rcv_ppid = seinfo.sinfo_ppid;
1181 rcv->rcv_context = seinfo.sinfo_context;
1182 rcv->rcv_tsn = seinfo.sinfo_tsn;
1183 rcv->rcv_cumtsn = seinfo.sinfo_cumtsn;
1184 rcv->rcv_assoc_id = seinfo.sinfo_assoc_id;
1185 *infolen = (socklen_t)sizeof(struct sctp_rcvinfo);
1186 *infotype = SCTP_RECVV_RCVINFO;
1188 *infotype = SCTP_RECVV_NOINFO;
1192 if ((fromlenp != NULL) &&
1195 (ulen > auio.uio_resid)) {
1196 switch (from->sa_family) {
1199 *fromlenp = sizeof(struct sockaddr_in);
1204 *fromlenp = sizeof(struct sockaddr_in6);
1208 *fromlenp = sizeof(struct sockaddr_conn);
1214 if (*fromlenp > fromlen) {
1215 *fromlenp = fromlen;
1220 /* ready return value */
1221 return (ulen - auio.uio_resid);
1230 /* Taken from /src/sys/kern/uipc_socket.c
1231 * and modified for __Userspace__
1232 * socreate returns a socket. The socket should be
1233 * closed with soclose().
1236 socreate(int dom, struct socket **aso, int type, int proto)
1241 if ((dom != AF_CONN) && (dom != AF_INET) && (dom != AF_INET6)) {
1244 if ((type != SOCK_STREAM) && (type != SOCK_SEQPACKET)) {
1247 if (proto != IPPROTO_SCTP) {
1257 * so_incomp represents a queue of connections that
1258 * must be completed at protocol level before being
1259 * returned. so_comp field heads a list of sockets
1260 * that are ready to be returned to the listening process
1261 *__Userspace__ These queues are being used at a number of places like accept etc.
1263 TAILQ_INIT(&so->so_incomp);
1264 TAILQ_INIT(&so->so_comp);
1269 * Auto-sizing of socket buffers is managed by the protocols and
1270 * the appropriate flags must be set in the pru_attach function.
1271 * For __Userspace__ The pru_attach function in this case is sctp_attach.
1276 error = sctp_attach(so, proto, SCTP_DEFAULT_VRFID);
1281 error = sctp6_attach(so, proto, SCTP_DEFAULT_VRFID);
1285 error = sctpconn_attach(so, proto, SCTP_DEFAULT_VRFID);
1288 error = EAFNOSUPPORT;
1292 KASSERT(so->so_count == 1, ("socreate: so_count %d", so->so_count));
1302 /* Taken from /src/sys/kern/uipc_syscalls.c
1303 * and modified for __Userspace__
1304 * Removing struct thread td.
1307 userspace_socket(int domain, int type, int protocol)
1309 struct socket *so = NULL;
1311 errno = socreate(domain, &so, type, protocol);
1316 * The original socket call returns the file descriptor fd.
1317 * td->td_retval[0] = fd.
1318 * We are returning struct socket *so.
1324 usrsctp_socket(int domain, int type, int protocol,
1325 int (*receive_cb)(struct socket *sock, union sctp_sockstore addr, void *data,
1326 size_t datalen, struct sctp_rcvinfo, int flags, void *ulp_info),
1327 int (*send_cb)(struct socket *sock, uint32_t sb_free),
1328 uint32_t sb_threshold,
1333 if ((protocol == IPPROTO_SCTP) && (SCTP_BASE_VAR(sctp_pcb_initialized) == 0)) {
1334 errno = EPROTONOSUPPORT;
1337 if ((receive_cb == NULL) &&
1338 ((send_cb != NULL) || (sb_threshold != 0) || (ulp_info != NULL))) {
1342 if ((domain == AF_CONN) && (SCTP_BASE_VAR(conn_output) == NULL)) {
1343 errno = EAFNOSUPPORT;
1346 errno = socreate(domain, &so, type, protocol);
1351 * The original socket call returns the file descriptor fd.
1352 * td->td_retval[0] = fd.
1353 * We are returning struct socket *so.
1355 register_recv_cb(so, receive_cb);
1356 register_send_cb(so, sb_threshold, send_cb);
1357 register_ulp_info(so, ulp_info);
1362 u_long sb_max = SB_MAX;
1364 SB_MAX * MCLBYTES / (MSIZE + MCLBYTES); /* adjusted sb_max */
1366 static u_long sb_efficiency = 8; /* parameter for sbreserve() */
1369 * Allot mbufs to a sockbuf. Attempt to scale mbmax so that mbcnt doesn't
1370 * become limiting if buffering efficiency is near the normal case.
1373 sbreserve_locked(struct sockbuf *sb, u_long cc, struct socket *so)
1375 SOCKBUF_LOCK_ASSERT(sb);
1376 sb->sb_mbmax = (u_int)min(cc * sb_efficiency, sb_max);
1377 sb->sb_hiwat = (u_int)cc;
1378 if (sb->sb_lowat > (int)sb->sb_hiwat)
1379 sb->sb_lowat = (int)sb->sb_hiwat;
1384 sbreserve(struct sockbuf *sb, u_long cc, struct socket *so)
1389 error = sbreserve_locked(sb, cc, so);
1395 soreserve(struct socket *so, u_long sndcc, u_long rcvcc)
1397 SOCKBUF_LOCK(&so->so_snd);
1398 SOCKBUF_LOCK(&so->so_rcv);
1399 so->so_snd.sb_hiwat = (uint32_t)sndcc;
1400 so->so_rcv.sb_hiwat = (uint32_t)rcvcc;
1402 if (sbreserve_locked(&so->so_snd, sndcc, so) == 0) {
1405 if (sbreserve_locked(&so->so_rcv, rcvcc, so) == 0) {
1408 if (so->so_rcv.sb_lowat == 0)
1409 so->so_rcv.sb_lowat = 1;
1410 if (so->so_snd.sb_lowat == 0)
1411 so->so_snd.sb_lowat = MCLBYTES;
1412 if (so->so_snd.sb_lowat > (int)so->so_snd.sb_hiwat)
1413 so->so_snd.sb_lowat = (int)so->so_snd.sb_hiwat;
1414 SOCKBUF_UNLOCK(&so->so_rcv);
1415 SOCKBUF_UNLOCK(&so->so_snd);
1419 SOCKBUF_UNLOCK(&so->so_rcv);
1420 SOCKBUF_UNLOCK(&so->so_snd);
1425 /* Taken from /src/sys/kern/uipc_sockbuf.c
1426 * and modified for __Userspace__
1430 sowakeup(struct socket *so, struct sockbuf *sb)
1433 SOCKBUF_LOCK_ASSERT(sb);
1435 sb->sb_flags &= ~SB_SEL;
1436 if (sb->sb_flags & SB_WAIT) {
1437 sb->sb_flags &= ~SB_WAIT;
1439 WakeAllConditionVariable(&(sb)->sb_cond);
1441 pthread_cond_broadcast(&(sb)->sb_cond);
1448 /* Taken from /src/sys/kern/uipc_socket.c
1449 * and modified for __Userspace__
1453 sobind(struct socket *so, struct sockaddr *nam)
1455 switch (nam->sa_family) {
1458 return (sctp_bind(so, nam));
1462 return (sctp6_bind(so, nam, NULL));
1465 return (sctpconn_bind(so, nam));
1467 return EAFNOSUPPORT;
1471 /* Taken from /src/sys/kern/uipc_syscalls.c
1472 * and modified for __Userspace__
1476 usrsctp_bind(struct socket *so, struct sockaddr *name, int namelen)
1478 struct sockaddr *sa;
1484 if ((errno = getsockaddr(&sa, (caddr_t)name, namelen)) != 0)
1487 errno = sobind(so, sa);
1497 userspace_bind(struct socket *so, struct sockaddr *name, int namelen)
1499 return (usrsctp_bind(so, name, namelen));
1502 /* Taken from /src/sys/kern/uipc_socket.c
1503 * and modified for __Userspace__
1507 solisten(struct socket *so, int backlog)
1512 return (sctp_listen(so, backlog, NULL));
1518 solisten_proto_check(struct socket *so)
1521 SOCK_LOCK_ASSERT(so);
1523 if (so->so_state & (SS_ISCONNECTED | SS_ISCONNECTING |
1524 SS_ISDISCONNECTING))
1529 static int somaxconn = SOMAXCONN;
1532 solisten_proto(struct socket *so, int backlog)
1535 SOCK_LOCK_ASSERT(so);
1537 if (backlog < 0 || backlog > somaxconn)
1538 backlog = somaxconn;
1539 so->so_qlimit = backlog;
1540 so->so_options |= SCTP_SO_ACCEPTCONN;
1546 /* Taken from /src/sys/kern/uipc_syscalls.c
1547 * and modified for __Userspace__
1551 usrsctp_listen(struct socket *so, int backlog)
1553 errno = solisten(so, backlog);
1562 userspace_listen(struct socket *so, int backlog)
1564 return (usrsctp_listen(so, backlog));
1567 /* Taken from /src/sys/kern/uipc_socket.c
1568 * and modified for __Userspace__
1572 soaccept(struct socket *so, struct sockaddr **nam)
1577 KASSERT((so->so_state & SS_NOFDREF) != 0, ("soaccept: !NOFDREF"));
1578 so->so_state &= ~SS_NOFDREF;
1580 error = sctp_accept(so, nam);
1586 /* Taken from /src/sys/kern/uipc_syscalls.c
1587 * kern_accept modified for __Userspace__
1590 user_accept(struct socket *head, struct sockaddr **name, socklen_t *namelen, struct socket **ptr_accept_ret_sock)
1592 struct sockaddr *sa = NULL;
1594 struct socket *so = NULL;
1601 if ((head->so_options & SCTP_SO_ACCEPTCONN) == 0) {
1607 if ((head->so_state & SS_NBIO) && TAILQ_EMPTY(&head->so_comp)) {
1609 error = EWOULDBLOCK;
1612 while (TAILQ_EMPTY(&head->so_comp) && head->so_error == 0) {
1613 if (head->so_rcv.sb_state & SBS_CANTRCVMORE) {
1614 head->so_error = ECONNABORTED;
1618 if (SleepConditionVariableCS(&accept_cond, &accept_mtx, INFINITE))
1621 error = GetLastError();
1623 error = pthread_cond_wait(&accept_cond, &accept_mtx);
1630 if (head->so_error) {
1631 error = head->so_error;
1636 so = TAILQ_FIRST(&head->so_comp);
1637 KASSERT(!(so->so_qstate & SQ_INCOMP), ("accept1: so SQ_INCOMP"));
1638 KASSERT(so->so_qstate & SQ_COMP, ("accept1: so not SQ_COMP"));
1641 * Before changing the flags on the socket, we have to bump the
1642 * reference count. Otherwise, if the protocol calls sofree(),
1643 * the socket will be released due to a zero refcount.
1645 SOCK_LOCK(so); /* soref() and so_state update */
1646 soref(so); /* file descriptor reference */
1648 TAILQ_REMOVE(&head->so_comp, so, so_list);
1650 so->so_state |= (head->so_state & SS_NBIO);
1651 so->so_qstate &= ~SQ_COMP;
1658 * The original accept returns fd value via td->td_retval[0] = fd;
1659 * we will return the socket for accepted connection.
1662 error = soaccept(so, &sa);
1665 * return a namelen of zero for older code which might
1666 * ignore the return value from accept.
1679 /* check sa_len before it is destroyed */
1680 if (*namelen > sa->sa_len) {
1681 *namelen = sa->sa_len;
1686 switch (sa->sa_family) {
1689 sa_len = sizeof(struct sockaddr_in);
1694 sa_len = sizeof(struct sockaddr_in6);
1698 sa_len = sizeof(struct sockaddr_conn);
1704 if (*namelen > sa_len) {
1717 *ptr_accept_ret_sock = so;
1723 /* Taken from /src/sys/kern/uipc_syscalls.c
1724 * and modified for __Userspace__
1730 accept1(struct socket *so, struct sockaddr *aname, socklen_t *anamelen, struct socket **ptr_accept_ret_sock)
1732 struct sockaddr *name;
1739 if (aname == NULL) {
1740 return (user_accept(so, NULL, NULL, ptr_accept_ret_sock));
1743 error = copyin(anamelen, &namelen, sizeof (namelen));
1747 error = user_accept(so, &name, &namelen, ptr_accept_ret_sock);
1750 * return a namelen of zero for older code which might
1751 * ignore the return value from accept.
1754 (void) copyout(&namelen,
1755 anamelen, sizeof(*anamelen));
1759 if (error == 0 && name != NULL) {
1760 error = copyout(name, aname, namelen);
1763 error = copyout(&namelen, anamelen, sizeof(namelen));
1767 FREE(name, M_SONAME);
1773 usrsctp_accept(struct socket *so, struct sockaddr *aname, socklen_t *anamelen)
1775 struct socket *accept_return_sock = NULL;
1777 errno = accept1(so, aname, anamelen, &accept_return_sock);
1781 return (accept_return_sock);
1786 userspace_accept(struct socket *so, struct sockaddr *aname, socklen_t *anamelen)
1788 return (usrsctp_accept(so, aname, anamelen));
1792 usrsctp_peeloff(struct socket *head, sctp_assoc_t id)
1796 if ((errno = sctp_can_peel_off(head, id)) != 0) {
1799 if ((so = sonewconn(head, SS_ISCONNECTED)) == NULL) {
1805 TAILQ_REMOVE(&head->so_comp, so, so_list);
1807 so->so_state |= (head->so_state & SS_NBIO);
1808 so->so_qstate &= ~SQ_COMP;
1812 if ((errno = sctp_do_peeloff(head, so, id)) != 0) {
1821 sodisconnect(struct socket *so)
1825 if ((so->so_state & SS_ISCONNECTED) == 0)
1827 if (so->so_state & SS_ISDISCONNECTING)
1829 error = sctp_disconnect(so);
1834 usrsctp_set_non_blocking(struct socket *so, int onoff)
1842 so->so_state |= SS_NBIO;
1844 so->so_state &= ~SS_NBIO;
1851 usrsctp_get_non_blocking(struct socket *so)
1860 if (so->so_state & SS_NBIO) {
1870 soconnect(struct socket *so, struct sockaddr *nam)
1874 if (so->so_options & SCTP_SO_ACCEPTCONN)
1875 return (EOPNOTSUPP);
1877 * If protocol is connection-based, can only connect once.
1878 * Otherwise, if connected, try to disconnect first. This allows
1879 * user to disconnect by connecting to, e.g., a null address.
1881 if (so->so_state & (SS_ISCONNECTED|SS_ISCONNECTING) && (error = sodisconnect(so))) {
1885 * Prevent accumulated error from previous connection from
1889 switch (nam->sa_family) {
1892 error = sctp_connect(so, nam);
1897 error = sctp6_connect(so, nam);
1901 error = sctpconn_connect(so, nam);
1904 error = EAFNOSUPPORT;
1913 int user_connect(struct socket *so, struct sockaddr *sa)
1916 int interrupted = 0;
1922 if (so->so_state & SS_ISCONNECTING) {
1927 error = soconnect(so, sa);
1931 if ((so->so_state & SS_NBIO) && (so->so_state & SS_ISCONNECTING)) {
1932 error = EINPROGRESS;
1937 while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) {
1939 if (SleepConditionVariableCS(SOCK_COND(so), SOCK_MTX(so), INFINITE))
1944 error = pthread_cond_wait(SOCK_COND(so), SOCK_MTX(so));
1947 #if defined(__NetBSD__)
1948 if (error == EINTR) {
1950 if (error == EINTR || error == ERESTART) {
1958 error = so->so_error;
1965 so->so_state &= ~SS_ISCONNECTING;
1967 #if !defined(__NetBSD__)
1968 if (error == ERESTART) {
1976 int usrsctp_connect(struct socket *so, struct sockaddr *name, int namelen)
1978 struct sockaddr *sa = NULL;
1980 errno = getsockaddr(&sa, (caddr_t)name, namelen);
1984 errno = user_connect(so, sa);
1993 int userspace_connect(struct socket *so, struct sockaddr *name, int namelen)
1995 return (usrsctp_connect(so, name, namelen));
1998 #define SCTP_STACK_BUF_SIZE 2048
2001 usrsctp_close(struct socket *so) {
2003 if (so->so_options & SCTP_SO_ACCEPTCONN) {
2007 while ((sp = TAILQ_FIRST(&so->so_comp)) != NULL) {
2008 TAILQ_REMOVE(&so->so_comp, sp, so_list);
2010 sp->so_qstate &= ~SQ_COMP;
2025 userspace_close(struct socket *so)
2031 usrsctp_shutdown(struct socket *so, int how)
2033 if (!(how == SHUT_RD || how == SHUT_WR || how == SHUT_RDWR)) {
2041 sctp_flush(so, how);
2044 if (how != SHUT_RD) {
2045 errno = sctp_shutdown(so);
2056 userspace_shutdown(struct socket *so, int how)
2058 return (usrsctp_shutdown(so, how));
2062 usrsctp_finish(void)
2064 if (SCTP_BASE_VAR(sctp_pcb_initialized) == 0) {
2067 if (SCTP_INP_INFO_TRYLOCK()) {
2068 if (!LIST_EMPTY(&SCTP_BASE_INFO(listhead))) {
2069 SCTP_INP_INFO_RUNLOCK();
2072 SCTP_INP_INFO_RUNLOCK();
2078 DeleteConditionVariable(&accept_cond);
2079 DeleteCriticalSection(&accept_mtx);
2080 #if defined(INET) || defined(INET6)
2084 pthread_cond_destroy(&accept_cond);
2085 pthread_mutex_destroy(&accept_mtx);
2091 userspace_finish(void)
2093 return (usrsctp_finish());
2096 /* needed from sctp_usrreq.c */
2098 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, void *p);
2101 usrsctp_setsockopt(struct socket *so, int level, int option_name,
2102 const void *option_value, socklen_t option_len)
2111 switch (option_name) {
2113 if (option_len < (socklen_t)sizeof(int)) {
2119 buf_size = (int *)option_value;
2120 if (*buf_size < 1) {
2124 sbreserve(&so->so_rcv, (u_long)*buf_size, so);
2129 if (option_len < (socklen_t)sizeof(int)) {
2135 buf_size = (int *)option_value;
2136 if (*buf_size < 1) {
2140 sbreserve(&so->so_snd, (u_long)*buf_size, so);
2145 if (option_len < (socklen_t)sizeof(struct linger)) {
2151 l = (struct linger *)option_value;
2152 so->so_linger = l->l_linger;
2154 so->so_options |= SCTP_SO_LINGER;
2156 so->so_options &= ~SCTP_SO_LINGER;
2166 errno = sctp_setopt(so, option_name, (void *) option_value, (size_t)option_len, NULL);
2173 errno = ENOPROTOOPT;
2179 userspace_setsockopt(struct socket *so, int level, int option_name,
2180 const void *option_value, socklen_t option_len)
2182 return (usrsctp_setsockopt(so, level, option_name, option_value, option_len));
2185 /* needed from sctp_usrreq.c */
2187 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
2191 usrsctp_getsockopt(struct socket *so, int level, int option_name,
2192 void *option_value, socklen_t *option_len)
2198 if (option_len == NULL) {
2204 switch (option_name) {
2206 if (*option_len < (socklen_t)sizeof(int)) {
2212 buf_size = (int *)option_value;
2213 *buf_size = so->so_rcv.sb_hiwat;;
2214 *option_len = (socklen_t)sizeof(int);
2219 if (*option_len < (socklen_t)sizeof(int)) {
2225 buf_size = (int *)option_value;
2226 *buf_size = so->so_snd.sb_hiwat;
2227 *option_len = (socklen_t)sizeof(int);
2232 if (*option_len < (socklen_t)sizeof(struct linger)) {
2238 l = (struct linger *)option_value;
2239 l->l_linger = so->so_linger;
2240 if (so->so_options & SCTP_SO_LINGER) {
2245 *option_len = (socklen_t)sizeof(struct linger);
2250 if (*option_len < (socklen_t)sizeof(int)) {
2256 intval = (int *)option_value;
2257 *intval = so->so_error;
2258 *option_len = (socklen_t)sizeof(int);
2270 len = (size_t)*option_len;
2271 errno = sctp_getopt(so, option_name, option_value, &len, NULL);
2272 *option_len = (socklen_t)len;
2280 errno = ENOPROTOOPT;
2286 userspace_getsockopt(struct socket *so, int level, int option_name,
2287 void *option_value, socklen_t *option_len)
2289 return (usrsctp_getsockopt(so, level, option_name, option_value, option_len));
2293 usrsctp_opt_info(struct socket *so, sctp_assoc_t id, int opt, void *arg, socklen_t *size)
2299 if ((id == SCTP_CURRENT_ASSOC) ||
2300 (id == SCTP_ALL_ASSOC)) {
2306 ((struct sctp_rtoinfo *)arg)->srto_assoc_id = id;
2308 case SCTP_ASSOCINFO:
2309 ((struct sctp_assocparams *)arg)->sasoc_assoc_id = id;
2311 case SCTP_DEFAULT_SEND_PARAM:
2312 ((struct sctp_assocparams *)arg)->sasoc_assoc_id = id;
2314 case SCTP_PRIMARY_ADDR:
2315 ((struct sctp_setprim *)arg)->ssp_assoc_id = id;
2317 case SCTP_PEER_ADDR_PARAMS:
2318 ((struct sctp_paddrparams *)arg)->spp_assoc_id = id;
2321 ((struct sctp_assoc_value *)arg)->assoc_id = id;
2324 ((struct sctp_authkey *)arg)->sca_assoc_id = id;
2326 case SCTP_AUTH_ACTIVE_KEY:
2327 ((struct sctp_authkeyid *)arg)->scact_assoc_id = id;
2329 case SCTP_DELAYED_SACK:
2330 ((struct sctp_sack_info *)arg)->sack_assoc_id = id;
2333 ((struct sctp_assoc_value *)arg)->assoc_id = id;
2336 ((struct sctp_status *)arg)->sstat_assoc_id = id;
2338 case SCTP_GET_PEER_ADDR_INFO:
2339 ((struct sctp_paddrinfo *)arg)->spinfo_assoc_id = id;
2341 case SCTP_PEER_AUTH_CHUNKS:
2342 ((struct sctp_authchunks *)arg)->gauth_assoc_id = id;
2344 case SCTP_LOCAL_AUTH_CHUNKS:
2345 ((struct sctp_authchunks *)arg)->gauth_assoc_id = id;
2348 ((struct sctp_timeouts *)arg)->stimo_assoc_id = id;
2351 ((struct sctp_event *)arg)->se_assoc_id = id;
2353 case SCTP_DEFAULT_SNDINFO:
2354 ((struct sctp_sndinfo *)arg)->snd_assoc_id = id;
2356 case SCTP_DEFAULT_PRINFO:
2357 ((struct sctp_default_prinfo *)arg)->pr_assoc_id = id;
2359 case SCTP_PEER_ADDR_THLDS:
2360 ((struct sctp_paddrthlds *)arg)->spt_assoc_id = id;
2362 case SCTP_REMOTE_UDP_ENCAPS_PORT:
2363 ((struct sctp_udpencaps *)arg)->sue_assoc_id = id;
2365 case SCTP_ECN_SUPPORTED:
2366 ((struct sctp_assoc_value *)arg)->assoc_id = id;
2368 case SCTP_PR_SUPPORTED:
2369 ((struct sctp_assoc_value *)arg)->assoc_id = id;
2371 case SCTP_AUTH_SUPPORTED:
2372 ((struct sctp_assoc_value *)arg)->assoc_id = id;
2374 case SCTP_ASCONF_SUPPORTED:
2375 ((struct sctp_assoc_value *)arg)->assoc_id = id;
2377 case SCTP_RECONFIG_SUPPORTED:
2378 ((struct sctp_assoc_value *)arg)->assoc_id = id;
2380 case SCTP_NRSACK_SUPPORTED:
2381 ((struct sctp_assoc_value *)arg)->assoc_id = id;
2383 case SCTP_PKTDROP_SUPPORTED:
2384 ((struct sctp_assoc_value *)arg)->assoc_id = id;
2386 case SCTP_MAX_BURST:
2387 ((struct sctp_assoc_value *)arg)->assoc_id = id;
2389 case SCTP_ENABLE_STREAM_RESET:
2390 ((struct sctp_assoc_value *)arg)->assoc_id = id;
2392 case SCTP_PR_STREAM_STATUS:
2393 ((struct sctp_prstatus *)arg)->sprstat_assoc_id = id;
2395 case SCTP_PR_ASSOC_STATUS:
2396 ((struct sctp_prstatus *)arg)->sprstat_assoc_id = id;
2399 ((struct sctp_assoc_value *)arg)->assoc_id = id;
2404 return (usrsctp_getsockopt(so, IPPROTO_SCTP, opt, arg, size));
2408 usrsctp_set_ulpinfo(struct socket *so, void *ulp_info)
2410 return (register_ulp_info(so, ulp_info));
2415 usrsctp_get_ulpinfo(struct socket *so, void **pulp_info)
2417 return (retrieve_ulp_info(so, pulp_info));
2421 usrsctp_bindx(struct socket *so, struct sockaddr *addrs, int addrcnt, int flags)
2423 struct sockaddr *sa;
2425 struct sockaddr_in *sin;
2428 struct sockaddr_in6 *sin6;
2431 #if defined(INET) || defined(INET6)
2436 /* validate the flags */
2437 if ((flags != SCTP_BINDX_ADD_ADDR) &&
2438 (flags != SCTP_BINDX_REM_ADDR)) {
2442 /* validate the address count and list */
2443 if ((addrcnt <= 0) || (addrs == NULL)) {
2447 #if defined(INET) || defined(INET6)
2451 /* First pre-screen the addresses */
2453 for (i = 0; i < addrcnt; i++) {
2454 switch (sa->sa_family) {
2458 if (sa->sa_len != sizeof(struct sockaddr_in)) {
2463 sin = (struct sockaddr_in *)sa;
2464 if (sin->sin_port) {
2465 /* non-zero port, check or save */
2467 /* Check against our port */
2468 if (sport != sin->sin_port) {
2473 /* save off the port */
2474 sport = sin->sin_port;
2479 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
2486 if (sa->sa_len != sizeof(struct sockaddr_in6)) {
2491 sin6 = (struct sockaddr_in6 *)sa;
2492 if (sin6->sin6_port) {
2493 /* non-zero port, check or save */
2495 /* Check against our port */
2496 if (sport != sin6->sin6_port) {
2501 /* save off the port */
2502 sport = sin6->sin6_port;
2507 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
2512 /* Invalid address family specified. */
2513 errno = EAFNOSUPPORT;
2517 sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len);
2521 for (i = 0; i < addrcnt; i++) {
2527 #if defined(INET) || defined(INET6)
2529 switch (sa->sa_family) {
2532 ((struct sockaddr_in *)sa)->sin_port = sport;
2537 ((struct sockaddr_in6 *)sa)->sin6_port = sport;
2543 if (usrsctp_setsockopt(so, IPPROTO_SCTP, flags, sa, sa->sa_len) != 0) {
2546 sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len);
2548 switch (sa->sa_family) {
2551 sa_len = sizeof(struct sockaddr_in);
2556 sa_len = sizeof(struct sockaddr_in6);
2564 * Now, if there was a port mentioned, assure that the
2565 * first address has that port to make sure it fails or
2566 * succeeds correctly.
2568 #if defined(INET) || defined(INET6)
2570 switch (sa->sa_family) {
2573 ((struct sockaddr_in *)sa)->sin_port = sport;
2578 ((struct sockaddr_in6 *)sa)->sin6_port = sport;
2584 if (usrsctp_setsockopt(so, IPPROTO_SCTP, flags, sa, (socklen_t)sa_len) != 0) {
2587 sa = (struct sockaddr *)((caddr_t)sa + sa_len);
2594 usrsctp_connectx(struct socket *so,
2595 const struct sockaddr *addrs, int addrcnt,
2598 #if defined(INET) || defined(INET6)
2599 char buf[SCTP_STACK_BUF_SIZE];
2600 int i, ret, cnt, *aa;
2602 const struct sockaddr *at;
2604 size_t len = sizeof(int);
2606 /* validate the address count and list */
2607 if ((addrs == NULL) || (addrcnt <= 0)) {
2613 cpto = ((caddr_t)buf + sizeof(int));
2614 /* validate all the addresses and get the size */
2615 for (i = 0; i < addrcnt; i++) {
2616 switch (at->sa_family) {
2620 if (at->sa_len != sizeof(struct sockaddr_in)) {
2625 len += sizeof(struct sockaddr_in);
2626 if (len > SCTP_STACK_BUF_SIZE) {
2630 memcpy(cpto, at, sizeof(struct sockaddr_in));
2631 cpto = ((caddr_t)cpto + sizeof(struct sockaddr_in));
2632 at = (struct sockaddr *)((caddr_t)at + sizeof(struct sockaddr_in));
2638 if (at->sa_len != sizeof(struct sockaddr_in6)) {
2644 if (IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)at)->sin6_addr)) {
2645 len += sizeof(struct sockaddr_in);
2646 if (len > SCTP_STACK_BUF_SIZE) {
2650 in6_sin6_2_sin((struct sockaddr_in *)cpto, (struct sockaddr_in6 *)at);
2651 cpto = ((caddr_t)cpto + sizeof(struct sockaddr_in));
2653 len += sizeof(struct sockaddr_in6);
2654 if (len > SCTP_STACK_BUF_SIZE) {
2658 memcpy(cpto, at, sizeof(struct sockaddr_in6));
2659 cpto = ((caddr_t)cpto + sizeof(struct sockaddr_in6));
2662 len += sizeof(struct sockaddr_in6);
2663 if (len > SCTP_STACK_BUF_SIZE) {
2667 memcpy(cpto, at, sizeof(struct sockaddr_in6));
2668 cpto = ((caddr_t)cpto + sizeof(struct sockaddr_in6));
2670 at = (struct sockaddr *)((caddr_t)at + sizeof(struct sockaddr_in6));
2681 ret = usrsctp_setsockopt(so, IPPROTO_SCTP, SCTP_CONNECT_X, (void *)buf, (socklen_t)len);
2682 if ((ret == 0) && id) {
2683 p_id = (sctp_assoc_t *)buf;
2694 usrsctp_getpaddrs(struct socket *so, sctp_assoc_t id, struct sockaddr **raddrs)
2696 struct sctp_getaddresses *addrs;
2697 struct sockaddr *sa;
2703 if (raddrs == NULL) {
2708 opt_len = (socklen_t)sizeof(sctp_assoc_t);
2709 if (usrsctp_getsockopt(so, IPPROTO_SCTP, SCTP_GET_REMOTE_ADDR_SIZE, &asoc, &opt_len) != 0) {
2712 /* size required is returned in 'asoc' */
2713 opt_len = (socklen_t)((size_t)asoc + sizeof(struct sctp_getaddresses));
2714 addrs = calloc(1, (size_t)opt_len);
2715 if (addrs == NULL) {
2719 addrs->sget_assoc_id = id;
2720 /* Now lets get the array of addresses */
2721 if (usrsctp_getsockopt(so, IPPROTO_SCTP, SCTP_GET_PEER_ADDRESSES, addrs, &opt_len) != 0) {
2725 *raddrs = &addrs->addr[0].sa;
2727 sa = &addrs->addr[0].sa;
2728 lim = (caddr_t)addrs + opt_len;
2730 while (((caddr_t)sa < lim) && (sa->sa_len > 0)) {
2731 sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len);
2733 while ((caddr_t)sa < lim) {
2734 switch (sa->sa_family) {
2737 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
2742 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
2746 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_conn));
2759 usrsctp_freepaddrs(struct sockaddr *addrs)
2761 /* Take away the hidden association id */
2764 fr_addr = (void *)((caddr_t)addrs - offsetof(struct sctp_getaddresses, addr));
2770 usrsctp_getladdrs(struct socket *so, sctp_assoc_t id, struct sockaddr **raddrs)
2772 struct sctp_getaddresses *addrs;
2774 struct sockaddr *sa;
2775 size_t size_of_addresses;
2779 if (raddrs == NULL) {
2783 size_of_addresses = 0;
2784 opt_len = (socklen_t)sizeof(int);
2785 if (usrsctp_getsockopt(so, IPPROTO_SCTP, SCTP_GET_LOCAL_ADDR_SIZE, &size_of_addresses, &opt_len) != 0) {
2789 if (size_of_addresses == 0) {
2793 opt_len = (socklen_t)(size_of_addresses + sizeof(struct sctp_getaddresses));
2794 addrs = calloc(1, (size_t)opt_len);
2795 if (addrs == NULL) {
2799 addrs->sget_assoc_id = id;
2800 /* Now lets get the array of addresses */
2801 if (usrsctp_getsockopt(so, IPPROTO_SCTP, SCTP_GET_LOCAL_ADDRESSES, addrs, &opt_len) != 0) {
2806 *raddrs = &addrs->addr[0].sa;
2808 sa = &addrs->addr[0].sa;
2809 lim = (caddr_t)addrs + opt_len;
2811 while (((caddr_t)sa < lim) && (sa->sa_len > 0)) {
2812 sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len);
2814 while ((caddr_t)sa < lim) {
2815 switch (sa->sa_family) {
2818 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
2823 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
2827 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_conn));
2840 usrsctp_freeladdrs(struct sockaddr *addrs)
2842 /* Take away the hidden association id */
2845 fr_addr = (void *)((caddr_t)addrs - offsetof(struct sctp_getaddresses, addr));
2852 sctp_userspace_ip_output(int *result, struct mbuf *o_pak,
2853 sctp_route_t *ro, void *stcb,
2857 struct mbuf *m_orig;
2863 struct sockaddr_in dst;
2867 WSABUF send_iovec[MAXLEN_MBUF_CHAIN];
2870 struct iovec send_iovec[MAXLEN_MBUF_CHAIN];
2871 struct msghdr msg_hdr;
2873 int use_udp_tunneling;
2877 m = SCTP_HEADER_TO_CHAIN(o_pak);
2880 len = sizeof(struct ip);
2881 if (SCTP_BUF_LEN(m) < len) {
2882 if ((m = m_pullup(m, len)) == 0) {
2883 SCTP_PRINTF("Can not get the IP header in the first mbuf.\n");
2887 ip = mtod(m, struct ip *);
2888 use_udp_tunneling = (ip->ip_p == IPPROTO_UDP);
2890 if (use_udp_tunneling) {
2891 len = sizeof(struct ip) + sizeof(struct udphdr);
2892 if (SCTP_BUF_LEN(m) < len) {
2893 if ((m = m_pullup(m, len)) == 0) {
2894 SCTP_PRINTF("Can not get the UDP/IP header in the first mbuf.\n");
2897 ip = mtod(m, struct ip *);
2899 udp = (struct udphdr *)(ip + 1);
2904 if (!use_udp_tunneling) {
2905 if (ip->ip_src.s_addr == INADDR_ANY) {
2906 /* TODO get addr of outgoing interface */
2907 SCTP_PRINTF("Why did the SCTP implementation did not choose a source address?\n");
2909 /* TODO need to worry about ro->ro_dst as in ip_output? */
2910 #if defined(__linux__) || defined(_WIN32) || (defined(__FreeBSD__) && (__FreeBSD_version >= 1100030))
2911 /* need to put certain fields into network order for Linux */
2912 ip->ip_len = htons(ip->ip_len);
2916 memset((void *)&dst, 0, sizeof(struct sockaddr_in));
2917 dst.sin_family = AF_INET;
2918 dst.sin_addr.s_addr = ip->ip_dst.s_addr;
2920 dst.sin_len = sizeof(struct sockaddr_in);
2922 if (use_udp_tunneling) {
2923 dst.sin_port = udp->uh_dport;
2928 /* tweak the mbuf chain */
2929 if (use_udp_tunneling) {
2930 m_adj(m, sizeof(struct ip) + sizeof(struct udphdr));
2934 for (iovcnt = 0; m != NULL && iovcnt < MAXLEN_MBUF_CHAIN; m = m->m_next, iovcnt++) {
2935 #if !defined(_WIN32)
2936 send_iovec[iovcnt].iov_base = (caddr_t)m->m_data;
2937 send_iovec[iovcnt].iov_len = SCTP_BUF_LEN(m);
2938 send_count += send_iovec[iovcnt].iov_len;
2940 send_iovec[iovcnt].buf = (caddr_t)m->m_data;
2941 send_iovec[iovcnt].len = SCTP_BUF_LEN(m);
2942 send_count += send_iovec[iovcnt].len;
2947 SCTP_PRINTF("mbuf chain couldn't be copied completely\n");
2951 #if !defined(_WIN32)
2952 msg_hdr.msg_name = (struct sockaddr *) &dst;
2953 msg_hdr.msg_namelen = sizeof(struct sockaddr_in);
2954 msg_hdr.msg_iov = send_iovec;
2955 msg_hdr.msg_iovlen = iovcnt;
2956 msg_hdr.msg_control = NULL;
2957 msg_hdr.msg_controllen = 0;
2958 msg_hdr.msg_flags = 0;
2960 if ((!use_udp_tunneling) && (SCTP_BASE_VAR(userspace_rawsctp) != -1)) {
2961 if (sendmsg(SCTP_BASE_VAR(userspace_rawsctp), &msg_hdr, MSG_DONTWAIT) < 0) {
2965 if ((use_udp_tunneling) && (SCTP_BASE_VAR(userspace_udpsctp) != -1)) {
2966 if (sendmsg(SCTP_BASE_VAR(userspace_udpsctp), &msg_hdr, MSG_DONTWAIT) < 0) {
2971 win_msg_hdr.name = (struct sockaddr *) &dst;
2972 win_msg_hdr.namelen = sizeof(struct sockaddr_in);
2973 win_msg_hdr.lpBuffers = (LPWSABUF)send_iovec;
2974 win_msg_hdr.dwBufferCount = iovcnt;
2977 win_msg_hdr.Control = winbuf;
2978 win_msg_hdr.dwFlags = 0;
2980 if ((!use_udp_tunneling) && (SCTP_BASE_VAR(userspace_rawsctp) != -1)) {
2981 if (WSASendTo(SCTP_BASE_VAR(userspace_rawsctp), (LPWSABUF) send_iovec, iovcnt, &win_sent_len, win_msg_hdr.dwFlags, win_msg_hdr.name, (int) win_msg_hdr.namelen, NULL, NULL) != 0) {
2982 *result = WSAGetLastError();
2985 if ((use_udp_tunneling) && (SCTP_BASE_VAR(userspace_udpsctp) != -1)) {
2986 if (WSASendTo(SCTP_BASE_VAR(userspace_udpsctp), (LPWSABUF) send_iovec, iovcnt, &win_sent_len, win_msg_hdr.dwFlags, win_msg_hdr.name, (int) win_msg_hdr.namelen, NULL, NULL) != 0) {
2987 *result = WSAGetLastError();
2992 sctp_m_freem(m_orig);
2997 void sctp_userspace_ip6_output(int *result, struct mbuf *o_pak,
2998 struct route_in6 *ro, void *stcb,
3002 struct mbuf *m_orig;
3006 struct ip6_hdr *ip6;
3008 struct sockaddr_in6 dst;
3012 WSABUF send_iovec[MAXLEN_MBUF_CHAIN];
3015 struct iovec send_iovec[MAXLEN_MBUF_CHAIN];
3016 struct msghdr msg_hdr;
3018 int use_udp_tunneling;
3022 m = SCTP_HEADER_TO_CHAIN(o_pak);
3025 len = sizeof(struct ip6_hdr);
3027 if (SCTP_BUF_LEN(m) < len) {
3028 if ((m = m_pullup(m, len)) == 0) {
3029 SCTP_PRINTF("Can not get the IP header in the first mbuf.\n");
3034 ip6 = mtod(m, struct ip6_hdr *);
3035 use_udp_tunneling = (ip6->ip6_nxt == IPPROTO_UDP);
3037 if (use_udp_tunneling) {
3038 len = sizeof(struct ip6_hdr) + sizeof(struct udphdr);
3039 if (SCTP_BUF_LEN(m) < len) {
3040 if ((m = m_pullup(m, len)) == 0) {
3041 SCTP_PRINTF("Can not get the UDP/IP header in the first mbuf.\n");
3044 ip6 = mtod(m, struct ip6_hdr *);
3046 udp = (struct udphdr *)(ip6 + 1);
3051 if (!use_udp_tunneling) {
3052 if (ip6->ip6_src.s6_addr == in6addr_any.s6_addr) {
3053 /* TODO get addr of outgoing interface */
3054 SCTP_PRINTF("Why did the SCTP implementation did not choose a source address?\n");
3056 /* TODO need to worry about ro->ro_dst as in ip_output? */
3059 memset((void *)&dst, 0, sizeof(struct sockaddr_in6));
3060 dst.sin6_family = AF_INET6;
3061 dst.sin6_addr = ip6->ip6_dst;
3062 #ifdef HAVE_SIN6_LEN
3063 dst.sin6_len = sizeof(struct sockaddr_in6);
3066 if (use_udp_tunneling) {
3067 dst.sin6_port = udp->uh_dport;
3072 /* tweak the mbuf chain */
3073 if (use_udp_tunneling) {
3074 m_adj(m, sizeof(struct ip6_hdr) + sizeof(struct udphdr));
3076 m_adj(m, sizeof(struct ip6_hdr));
3080 for (iovcnt = 0; m != NULL && iovcnt < MAXLEN_MBUF_CHAIN; m = m->m_next, iovcnt++) {
3081 #if !defined(_WIN32)
3082 send_iovec[iovcnt].iov_base = (caddr_t)m->m_data;
3083 send_iovec[iovcnt].iov_len = SCTP_BUF_LEN(m);
3084 send_count += send_iovec[iovcnt].iov_len;
3086 send_iovec[iovcnt].buf = (caddr_t)m->m_data;
3087 send_iovec[iovcnt].len = SCTP_BUF_LEN(m);
3088 send_count += send_iovec[iovcnt].len;
3092 SCTP_PRINTF("mbuf chain couldn't be copied completely\n");
3096 #if !defined(_WIN32)
3097 msg_hdr.msg_name = (struct sockaddr *) &dst;
3098 msg_hdr.msg_namelen = sizeof(struct sockaddr_in6);
3099 msg_hdr.msg_iov = send_iovec;
3100 msg_hdr.msg_iovlen = iovcnt;
3101 msg_hdr.msg_control = NULL;
3102 msg_hdr.msg_controllen = 0;
3103 msg_hdr.msg_flags = 0;
3105 if ((!use_udp_tunneling) && (SCTP_BASE_VAR(userspace_rawsctp6) != -1)) {
3106 if (sendmsg(SCTP_BASE_VAR(userspace_rawsctp6), &msg_hdr, MSG_DONTWAIT)< 0) {
3110 if ((use_udp_tunneling) && (SCTP_BASE_VAR(userspace_udpsctp6) != -1)) {
3111 if (sendmsg(SCTP_BASE_VAR(userspace_udpsctp6), &msg_hdr, MSG_DONTWAIT) < 0) {
3116 win_msg_hdr.name = (struct sockaddr *) &dst;
3117 win_msg_hdr.namelen = sizeof(struct sockaddr_in6);
3118 win_msg_hdr.lpBuffers = (LPWSABUF)send_iovec;
3119 win_msg_hdr.dwBufferCount = iovcnt;
3122 win_msg_hdr.Control = winbuf;
3123 win_msg_hdr.dwFlags = 0;
3125 if ((!use_udp_tunneling) && (SCTP_BASE_VAR(userspace_rawsctp6) != -1)) {
3126 if (WSASendTo(SCTP_BASE_VAR(userspace_rawsctp6), (LPWSABUF) send_iovec, iovcnt, &win_sent_len, win_msg_hdr.dwFlags, win_msg_hdr.name, (int) win_msg_hdr.namelen, NULL, NULL) != 0) {
3127 *result = WSAGetLastError();
3130 if ((use_udp_tunneling) && (SCTP_BASE_VAR(userspace_udpsctp6) != -1)) {
3131 if (WSASendTo(SCTP_BASE_VAR(userspace_udpsctp6), (LPWSABUF) send_iovec, iovcnt, &win_sent_len, win_msg_hdr.dwFlags, win_msg_hdr.name, (int) win_msg_hdr.namelen, NULL, NULL) != 0) {
3132 *result = WSAGetLastError();
3137 sctp_m_freem(m_orig);
3142 usrsctp_register_address(void *addr)
3144 struct sockaddr_conn sconn;
3146 memset(&sconn, 0, sizeof(struct sockaddr_conn));
3147 sconn.sconn_family = AF_CONN;
3148 #ifdef HAVE_SCONN_LEN
3149 sconn.sconn_len = sizeof(struct sockaddr_conn);
3151 sconn.sconn_port = 0;
3152 sconn.sconn_addr = addr;
3153 sctp_add_addr_to_vrf(SCTP_DEFAULT_VRFID,
3159 (struct sockaddr *)&sconn,
3165 usrsctp_deregister_address(void *addr)
3167 struct sockaddr_conn sconn;
3169 memset(&sconn, 0, sizeof(struct sockaddr_conn));
3170 sconn.sconn_family = AF_CONN;
3171 #ifdef HAVE_SCONN_LEN
3172 sconn.sconn_len = sizeof(struct sockaddr_conn);
3174 sconn.sconn_port = 0;
3175 sconn.sconn_addr = addr;
3176 sctp_del_addr_from_vrf(SCTP_DEFAULT_VRFID,
3177 (struct sockaddr *)&sconn,
3182 #define PREAMBLE_FORMAT "\n%c %02d:%02d:%02d.%06ld "
3183 #define PREAMBLE_LENGTH 19
3184 #define HEADER "0000 "
3185 #define TRAILER "# SCTP_PACKET\n"
3188 usrsctp_dumppacket(const void *buf, size_t len, int outbound)
3191 char *dump_buf, *packet;
3200 if ((len == 0) || (buf == NULL)) {
3203 if ((dump_buf = malloc(PREAMBLE_LENGTH + strlen(HEADER) + 3 * len + strlen(TRAILER) + 1)) == NULL) {
3209 localtime_s(&t, &tb.time);
3210 #if defined(__MINGW32__)
3211 if (snprintf(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_FORMAT,
3212 outbound ? 'O' : 'I',
3213 t.tm_hour, t.tm_min, t.tm_sec, (long)(1000 * tb.millitm)) < 0) {
3218 if (_snprintf_s(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_LENGTH, PREAMBLE_FORMAT,
3219 outbound ? 'O' : 'I',
3220 t.tm_hour, t.tm_min, t.tm_sec, (long)(1000 * tb.millitm)) < 0) {
3226 gettimeofday(&tv, NULL);
3227 sec = (time_t)tv.tv_sec;
3228 localtime_r((const time_t *)&sec, &t);
3229 if (snprintf(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_FORMAT,
3230 outbound ? 'O' : 'I',
3231 t.tm_hour, t.tm_min, t.tm_sec, (long)tv.tv_usec) < 0) {
3236 pos += PREAMBLE_LENGTH;
3237 #if defined(_WIN32) && !defined(__MINGW32__)
3238 strncpy_s(dump_buf + pos, strlen(HEADER) + 1, HEADER, strlen(HEADER));
3240 strcpy(dump_buf + pos, HEADER);
3242 pos += strlen(HEADER);
3243 packet = (char *)buf;
3244 for (i = 0; i < len; i++) {
3245 uint8_t byte, low, high;
3247 byte = (uint8_t)packet[i];
3250 dump_buf[pos++] = high < 10 ? '0' + high : 'a' + (high - 10);
3251 dump_buf[pos++] = low < 10 ? '0' + low : 'a' + (low - 10);
3252 dump_buf[pos++] = ' ';
3254 #if defined(_WIN32) && !defined(__MINGW32__)
3255 strncpy_s(dump_buf + pos, strlen(TRAILER) + 1, TRAILER, strlen(TRAILER));
3257 strcpy(dump_buf + pos, TRAILER);
3259 pos += strlen(TRAILER);
3260 dump_buf[pos++] = '\0';
3265 usrsctp_freedumpbuffer(char *buf)
3271 usrsctp_enable_crc32c_offload(void)
3273 SCTP_BASE_VAR(crc32c_offloaded) = 1;
3277 usrsctp_disable_crc32c_offload(void)
3279 SCTP_BASE_VAR(crc32c_offloaded) = 0;
3282 /* Compute the CRC32C in network byte order */
3284 usrsctp_crc32c(void *buffer, size_t length)
3286 uint32_t base = 0xffffffff;
3288 base = calculate_crc32c(0xffffffff, (unsigned char *)buffer, (unsigned int) length);
3289 base = sctp_finalize_crc32c(base);
3294 usrsctp_conninput(void *addr, const void *buffer, size_t length, uint8_t ecn_bits)
3296 struct sockaddr_conn src, dst;
3297 struct mbuf *m, *mm;
3299 struct sctp_chunkhdr *ch;
3302 SCTP_STAT_INCR(sctps_recvpackets);
3303 SCTP_STAT_INCR_COUNTER64(sctps_inpackets);
3304 memset(&src, 0, sizeof(struct sockaddr_conn));
3305 src.sconn_family = AF_CONN;
3306 #ifdef HAVE_SCONN_LEN
3307 src.sconn_len = sizeof(struct sockaddr_conn);
3309 src.sconn_addr = addr;
3310 memset(&dst, 0, sizeof(struct sockaddr_conn));
3311 dst.sconn_family = AF_CONN;
3312 #ifdef HAVE_SCONN_LEN
3313 dst.sconn_len = sizeof(struct sockaddr_conn);
3315 dst.sconn_addr = addr;
3316 if ((m = sctp_get_mbuf_for_msg((unsigned int)length, 1, M_NOWAIT, 0, MT_DATA)) == NULL) {
3319 /* Set the lengths fields of the mbuf chain.
3320 * This is expected by m_copyback().
3322 remaining = (int)length;
3323 for (mm = m; mm != NULL; mm = mm->m_next) {
3324 mm->m_len = min((int)M_SIZE(mm), remaining);
3325 m->m_pkthdr.len += mm->m_len;
3326 remaining -= mm->m_len;
3328 KASSERT(remaining == 0, ("usrsctp_conninput: %zu bytes left", remaining));
3329 m_copyback(m, 0, (int)length, (caddr_t)buffer);
3330 if (SCTP_BUF_LEN(m) < (int)(sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr))) {
3331 if ((m = m_pullup(m, sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr))) == NULL) {
3332 SCTP_STAT_INCR(sctps_hdrops);
3336 sh = mtod(m, struct sctphdr *);;
3337 ch = (struct sctp_chunkhdr *)((caddr_t)sh + sizeof(struct sctphdr));
3338 src.sconn_port = sh->src_port;
3339 dst.sconn_port = sh->dest_port;
3340 sctp_common_input_processing(&m, 0, sizeof(struct sctphdr), (int)length,
3341 (struct sockaddr *)&src,
3342 (struct sockaddr *)&dst,
3344 SCTP_BASE_VAR(crc32c_offloaded) == 1 ? 0 : 1,
3346 SCTP_DEFAULT_VRFID, 0);
3353 void usrsctp_handle_timers(uint32_t elapsed_milliseconds)
3355 sctp_handle_tick(sctp_msecs_to_ticks(elapsed_milliseconds));
3359 usrsctp_get_events(struct socket *so)
3369 if (soreadable(so)) {
3370 events |= SCTP_EVENT_READ;
3372 if (sowriteable(so)) {
3373 events |= SCTP_EVENT_WRITE;
3376 events |= SCTP_EVENT_ERROR;
3384 usrsctp_set_upcall(struct socket *so, void (*upcall)(struct socket *, void *, int), void *arg)
3392 so->so_upcall = upcall;
3393 so->so_upcallarg = arg;
3394 so->so_snd.sb_flags |= SB_UPCALL;
3395 so->so_rcv.sb_flags |= SB_UPCALL;
3401 #define USRSCTP_TUNABLE_SET_DEF(__field, __prefix) \
3402 int usrsctp_tunable_set_ ## __field(uint32_t value) \
3404 if ((value < __prefix##_MIN) || \
3405 (value > __prefix##_MAX)) { \
3409 SCTP_BASE_SYSCTL(__field) = value; \
3414 USRSCTP_TUNABLE_SET_DEF(sctp_hashtblsize, SCTPCTL_TCBHASHSIZE)
3415 USRSCTP_TUNABLE_SET_DEF(sctp_pcbtblsize, SCTPCTL_PCBHASHSIZE)
3416 USRSCTP_TUNABLE_SET_DEF(sctp_chunkscale, SCTPCTL_CHUNKSCALE)
3418 #define USRSCTP_SYSCTL_SET_DEF(__field, __prefix) \
3419 int usrsctp_sysctl_set_ ## __field(uint32_t value) \
3421 if ((value < __prefix##_MIN) || \
3422 (value > __prefix##_MAX)) { \
3426 SCTP_BASE_SYSCTL(__field) = value; \
3431 #if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || defined(__clang__)
3432 #pragma GCC diagnostic push
3433 #pragma GCC diagnostic ignored "-Wtype-limits"
3435 USRSCTP_SYSCTL_SET_DEF(sctp_sendspace, SCTPCTL_MAXDGRAM)
3436 USRSCTP_SYSCTL_SET_DEF(sctp_recvspace, SCTPCTL_RECVSPACE)
3437 USRSCTP_SYSCTL_SET_DEF(sctp_auto_asconf, SCTPCTL_AUTOASCONF)
3438 USRSCTP_SYSCTL_SET_DEF(sctp_ecn_enable, SCTPCTL_ECN_ENABLE)
3439 USRSCTP_SYSCTL_SET_DEF(sctp_pr_enable, SCTPCTL_PR_ENABLE)
3440 USRSCTP_SYSCTL_SET_DEF(sctp_auth_enable, SCTPCTL_AUTH_ENABLE)
3441 USRSCTP_SYSCTL_SET_DEF(sctp_asconf_enable, SCTPCTL_ASCONF_ENABLE)
3442 USRSCTP_SYSCTL_SET_DEF(sctp_reconfig_enable, SCTPCTL_RECONFIG_ENABLE)
3443 USRSCTP_SYSCTL_SET_DEF(sctp_nrsack_enable, SCTPCTL_NRSACK_ENABLE)
3444 USRSCTP_SYSCTL_SET_DEF(sctp_pktdrop_enable, SCTPCTL_PKTDROP_ENABLE)
3445 USRSCTP_SYSCTL_SET_DEF(sctp_no_csum_on_loopback, SCTPCTL_LOOPBACK_NOCSUM)
3446 USRSCTP_SYSCTL_SET_DEF(sctp_peer_chunk_oh, SCTPCTL_PEER_CHKOH)
3447 USRSCTP_SYSCTL_SET_DEF(sctp_max_burst_default, SCTPCTL_MAXBURST)
3448 USRSCTP_SYSCTL_SET_DEF(sctp_max_chunks_on_queue, SCTPCTL_MAXCHUNKS)
3449 USRSCTP_SYSCTL_SET_DEF(sctp_min_split_point, SCTPCTL_MIN_SPLIT_POINT)
3450 USRSCTP_SYSCTL_SET_DEF(sctp_delayed_sack_time_default, SCTPCTL_DELAYED_SACK_TIME)
3451 USRSCTP_SYSCTL_SET_DEF(sctp_sack_freq_default, SCTPCTL_SACK_FREQ)
3452 USRSCTP_SYSCTL_SET_DEF(sctp_system_free_resc_limit, SCTPCTL_SYS_RESOURCE)
3453 USRSCTP_SYSCTL_SET_DEF(sctp_asoc_free_resc_limit, SCTPCTL_ASOC_RESOURCE)
3454 USRSCTP_SYSCTL_SET_DEF(sctp_heartbeat_interval_default, SCTPCTL_HEARTBEAT_INTERVAL)
3455 USRSCTP_SYSCTL_SET_DEF(sctp_pmtu_raise_time_default, SCTPCTL_PMTU_RAISE_TIME)
3456 USRSCTP_SYSCTL_SET_DEF(sctp_shutdown_guard_time_default, SCTPCTL_SHUTDOWN_GUARD_TIME)
3457 USRSCTP_SYSCTL_SET_DEF(sctp_secret_lifetime_default, SCTPCTL_SECRET_LIFETIME)
3458 USRSCTP_SYSCTL_SET_DEF(sctp_rto_max_default, SCTPCTL_RTO_MAX)
3459 USRSCTP_SYSCTL_SET_DEF(sctp_rto_min_default, SCTPCTL_RTO_MIN)
3460 USRSCTP_SYSCTL_SET_DEF(sctp_rto_initial_default, SCTPCTL_RTO_INITIAL)
3461 USRSCTP_SYSCTL_SET_DEF(sctp_init_rto_max_default, SCTPCTL_INIT_RTO_MAX)
3462 USRSCTP_SYSCTL_SET_DEF(sctp_valid_cookie_life_default, SCTPCTL_VALID_COOKIE_LIFE)
3463 USRSCTP_SYSCTL_SET_DEF(sctp_init_rtx_max_default, SCTPCTL_INIT_RTX_MAX)
3464 USRSCTP_SYSCTL_SET_DEF(sctp_assoc_rtx_max_default, SCTPCTL_ASSOC_RTX_MAX)
3465 USRSCTP_SYSCTL_SET_DEF(sctp_path_rtx_max_default, SCTPCTL_PATH_RTX_MAX)
3466 USRSCTP_SYSCTL_SET_DEF(sctp_add_more_threshold, SCTPCTL_ADD_MORE_ON_OUTPUT)
3467 USRSCTP_SYSCTL_SET_DEF(sctp_nr_incoming_streams_default, SCTPCTL_INCOMING_STREAMS)
3468 USRSCTP_SYSCTL_SET_DEF(sctp_nr_outgoing_streams_default, SCTPCTL_OUTGOING_STREAMS)
3469 USRSCTP_SYSCTL_SET_DEF(sctp_cmt_on_off, SCTPCTL_CMT_ON_OFF)
3470 USRSCTP_SYSCTL_SET_DEF(sctp_cmt_use_dac, SCTPCTL_CMT_USE_DAC)
3471 USRSCTP_SYSCTL_SET_DEF(sctp_use_cwnd_based_maxburst, SCTPCTL_CWND_MAXBURST)
3472 USRSCTP_SYSCTL_SET_DEF(sctp_nat_friendly, SCTPCTL_NAT_FRIENDLY)
3473 USRSCTP_SYSCTL_SET_DEF(sctp_L2_abc_variable, SCTPCTL_ABC_L_VAR)
3474 USRSCTP_SYSCTL_SET_DEF(sctp_mbuf_threshold_count, SCTPCTL_MAX_CHAINED_MBUFS)
3475 USRSCTP_SYSCTL_SET_DEF(sctp_do_drain, SCTPCTL_DO_SCTP_DRAIN)
3476 USRSCTP_SYSCTL_SET_DEF(sctp_hb_maxburst, SCTPCTL_HB_MAX_BURST)
3477 USRSCTP_SYSCTL_SET_DEF(sctp_abort_if_one_2_one_hits_limit, SCTPCTL_ABORT_AT_LIMIT)
3478 USRSCTP_SYSCTL_SET_DEF(sctp_min_residual, SCTPCTL_MIN_RESIDUAL)
3479 USRSCTP_SYSCTL_SET_DEF(sctp_max_retran_chunk, SCTPCTL_MAX_RETRAN_CHUNK)
3480 USRSCTP_SYSCTL_SET_DEF(sctp_logging_level, SCTPCTL_LOGGING_LEVEL)
3481 USRSCTP_SYSCTL_SET_DEF(sctp_default_cc_module, SCTPCTL_DEFAULT_CC_MODULE)
3482 USRSCTP_SYSCTL_SET_DEF(sctp_default_frag_interleave, SCTPCTL_DEFAULT_FRAG_INTERLEAVE)
3483 USRSCTP_SYSCTL_SET_DEF(sctp_mobility_base, SCTPCTL_MOBILITY_BASE)
3484 USRSCTP_SYSCTL_SET_DEF(sctp_mobility_fasthandoff, SCTPCTL_MOBILITY_FASTHANDOFF)
3485 USRSCTP_SYSCTL_SET_DEF(sctp_inits_include_nat_friendly, SCTPCTL_NAT_FRIENDLY_INITS)
3486 USRSCTP_SYSCTL_SET_DEF(sctp_udp_tunneling_port, SCTPCTL_UDP_TUNNELING_PORT)
3487 USRSCTP_SYSCTL_SET_DEF(sctp_enable_sack_immediately, SCTPCTL_SACK_IMMEDIATELY_ENABLE)
3488 USRSCTP_SYSCTL_SET_DEF(sctp_vtag_time_wait, SCTPCTL_TIME_WAIT)
3489 USRSCTP_SYSCTL_SET_DEF(sctp_blackhole, SCTPCTL_BLACKHOLE)
3490 USRSCTP_SYSCTL_SET_DEF(sctp_diag_info_code, SCTPCTL_DIAG_INFO_CODE)
3491 USRSCTP_SYSCTL_SET_DEF(sctp_fr_max_burst_default, SCTPCTL_FRMAXBURST)
3492 USRSCTP_SYSCTL_SET_DEF(sctp_path_pf_threshold, SCTPCTL_PATH_PF_THRESHOLD)
3493 USRSCTP_SYSCTL_SET_DEF(sctp_default_ss_module, SCTPCTL_DEFAULT_SS_MODULE)
3494 USRSCTP_SYSCTL_SET_DEF(sctp_rttvar_bw, SCTPCTL_RTTVAR_BW)
3495 USRSCTP_SYSCTL_SET_DEF(sctp_rttvar_rtt, SCTPCTL_RTTVAR_RTT)
3496 USRSCTP_SYSCTL_SET_DEF(sctp_rttvar_eqret, SCTPCTL_RTTVAR_EQRET)
3497 USRSCTP_SYSCTL_SET_DEF(sctp_steady_step, SCTPCTL_RTTVAR_STEADYS)
3498 USRSCTP_SYSCTL_SET_DEF(sctp_use_dccc_ecn, SCTPCTL_RTTVAR_DCCCECN)
3499 USRSCTP_SYSCTL_SET_DEF(sctp_buffer_splitting, SCTPCTL_BUFFER_SPLITTING)
3500 USRSCTP_SYSCTL_SET_DEF(sctp_initial_cwnd, SCTPCTL_INITIAL_CWND)
3502 USRSCTP_SYSCTL_SET_DEF(sctp_debug_on, SCTPCTL_DEBUG)
3504 #if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || defined(__clang__)
3505 #pragma GCC diagnostic pop
3508 #define USRSCTP_SYSCTL_GET_DEF(__field) \
3509 uint32_t usrsctp_sysctl_get_ ## __field(void) { \
3510 return SCTP_BASE_SYSCTL(__field); \
3513 USRSCTP_SYSCTL_GET_DEF(sctp_sendspace)
3514 USRSCTP_SYSCTL_GET_DEF(sctp_recvspace)
3515 USRSCTP_SYSCTL_GET_DEF(sctp_auto_asconf)
3516 USRSCTP_SYSCTL_GET_DEF(sctp_multiple_asconfs)
3517 USRSCTP_SYSCTL_GET_DEF(sctp_ecn_enable)
3518 USRSCTP_SYSCTL_GET_DEF(sctp_pr_enable)
3519 USRSCTP_SYSCTL_GET_DEF(sctp_auth_enable)
3520 USRSCTP_SYSCTL_GET_DEF(sctp_asconf_enable)
3521 USRSCTP_SYSCTL_GET_DEF(sctp_reconfig_enable)
3522 USRSCTP_SYSCTL_GET_DEF(sctp_nrsack_enable)
3523 USRSCTP_SYSCTL_GET_DEF(sctp_pktdrop_enable)
3524 USRSCTP_SYSCTL_GET_DEF(sctp_no_csum_on_loopback)
3525 USRSCTP_SYSCTL_GET_DEF(sctp_peer_chunk_oh)
3526 USRSCTP_SYSCTL_GET_DEF(sctp_max_burst_default)
3527 USRSCTP_SYSCTL_GET_DEF(sctp_max_chunks_on_queue)
3528 USRSCTP_SYSCTL_GET_DEF(sctp_hashtblsize)
3529 USRSCTP_SYSCTL_GET_DEF(sctp_pcbtblsize)
3530 USRSCTP_SYSCTL_GET_DEF(sctp_min_split_point)
3531 USRSCTP_SYSCTL_GET_DEF(sctp_chunkscale)
3532 USRSCTP_SYSCTL_GET_DEF(sctp_delayed_sack_time_default)
3533 USRSCTP_SYSCTL_GET_DEF(sctp_sack_freq_default)
3534 USRSCTP_SYSCTL_GET_DEF(sctp_system_free_resc_limit)
3535 USRSCTP_SYSCTL_GET_DEF(sctp_asoc_free_resc_limit)
3536 USRSCTP_SYSCTL_GET_DEF(sctp_heartbeat_interval_default)
3537 USRSCTP_SYSCTL_GET_DEF(sctp_pmtu_raise_time_default)
3538 USRSCTP_SYSCTL_GET_DEF(sctp_shutdown_guard_time_default)
3539 USRSCTP_SYSCTL_GET_DEF(sctp_secret_lifetime_default)
3540 USRSCTP_SYSCTL_GET_DEF(sctp_rto_max_default)
3541 USRSCTP_SYSCTL_GET_DEF(sctp_rto_min_default)
3542 USRSCTP_SYSCTL_GET_DEF(sctp_rto_initial_default)
3543 USRSCTP_SYSCTL_GET_DEF(sctp_init_rto_max_default)
3544 USRSCTP_SYSCTL_GET_DEF(sctp_valid_cookie_life_default)
3545 USRSCTP_SYSCTL_GET_DEF(sctp_init_rtx_max_default)
3546 USRSCTP_SYSCTL_GET_DEF(sctp_assoc_rtx_max_default)
3547 USRSCTP_SYSCTL_GET_DEF(sctp_path_rtx_max_default)
3548 USRSCTP_SYSCTL_GET_DEF(sctp_add_more_threshold)
3549 USRSCTP_SYSCTL_GET_DEF(sctp_nr_incoming_streams_default)
3550 USRSCTP_SYSCTL_GET_DEF(sctp_nr_outgoing_streams_default)
3551 USRSCTP_SYSCTL_GET_DEF(sctp_cmt_on_off)
3552 USRSCTP_SYSCTL_GET_DEF(sctp_cmt_use_dac)
3553 USRSCTP_SYSCTL_GET_DEF(sctp_use_cwnd_based_maxburst)
3554 USRSCTP_SYSCTL_GET_DEF(sctp_nat_friendly)
3555 USRSCTP_SYSCTL_GET_DEF(sctp_L2_abc_variable)
3556 USRSCTP_SYSCTL_GET_DEF(sctp_mbuf_threshold_count)
3557 USRSCTP_SYSCTL_GET_DEF(sctp_do_drain)
3558 USRSCTP_SYSCTL_GET_DEF(sctp_hb_maxburst)
3559 USRSCTP_SYSCTL_GET_DEF(sctp_abort_if_one_2_one_hits_limit)
3560 USRSCTP_SYSCTL_GET_DEF(sctp_min_residual)
3561 USRSCTP_SYSCTL_GET_DEF(sctp_max_retran_chunk)
3562 USRSCTP_SYSCTL_GET_DEF(sctp_logging_level)
3563 USRSCTP_SYSCTL_GET_DEF(sctp_default_cc_module)
3564 USRSCTP_SYSCTL_GET_DEF(sctp_default_frag_interleave)
3565 USRSCTP_SYSCTL_GET_DEF(sctp_mobility_base)
3566 USRSCTP_SYSCTL_GET_DEF(sctp_mobility_fasthandoff)
3567 USRSCTP_SYSCTL_GET_DEF(sctp_inits_include_nat_friendly)
3568 USRSCTP_SYSCTL_GET_DEF(sctp_udp_tunneling_port)
3569 USRSCTP_SYSCTL_GET_DEF(sctp_enable_sack_immediately)
3570 USRSCTP_SYSCTL_GET_DEF(sctp_vtag_time_wait)
3571 USRSCTP_SYSCTL_GET_DEF(sctp_blackhole)
3572 USRSCTP_SYSCTL_GET_DEF(sctp_diag_info_code)
3573 USRSCTP_SYSCTL_GET_DEF(sctp_fr_max_burst_default)
3574 USRSCTP_SYSCTL_GET_DEF(sctp_path_pf_threshold)
3575 USRSCTP_SYSCTL_GET_DEF(sctp_default_ss_module)
3576 USRSCTP_SYSCTL_GET_DEF(sctp_rttvar_bw)
3577 USRSCTP_SYSCTL_GET_DEF(sctp_rttvar_rtt)
3578 USRSCTP_SYSCTL_GET_DEF(sctp_rttvar_eqret)
3579 USRSCTP_SYSCTL_GET_DEF(sctp_steady_step)
3580 USRSCTP_SYSCTL_GET_DEF(sctp_use_dccc_ecn)
3581 USRSCTP_SYSCTL_GET_DEF(sctp_buffer_splitting)
3582 USRSCTP_SYSCTL_GET_DEF(sctp_initial_cwnd)
3584 USRSCTP_SYSCTL_GET_DEF(sctp_debug_on)
3587 void usrsctp_get_stat(struct sctpstat *stat)
3589 *stat = SCTP_BASE_STATS;