summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am1
-rw-r--r--Makefile.nmake6
-rwxr-xr-xnetinet/sctp_auth.c8
-rwxr-xr-xnetinet/sctp_auth.h4
-rwxr-xr-xnetinet/sctp_bsd_addr.c6
-rwxr-xr-xnetinet/sctp_callout.c89
-rwxr-xr-xnetinet/sctp_callout.h6
-rwxr-xr-xnetinet/sctp_cc_functions.c14
-rwxr-xr-xnetinet/sctp_header.h8
-rwxr-xr-xnetinet/sctp_input.c37
-rwxr-xr-xnetinet/sctp_input.h4
-rwxr-xr-xnetinet/sctp_os_userspace.h144
-rwxr-xr-xnetinet/sctp_output.c83
-rwxr-xr-xnetinet/sctp_output.h6
-rwxr-xr-xnetinet/sctp_pcb.c6
-rwxr-xr-xnetinet/sctp_structs.h6
-rwxr-xr-xnetinet/sctp_userspace.c27
-rwxr-xr-xnetinet/sctp_usrreq.c19
-rwxr-xr-xnetinet/sctputil.c6
-rwxr-xr-xuser_route.h2
-rwxr-xr-xuser_sctp_timer_iterate.c119
-rwxr-xr-xuser_socket.c8
-rwxr-xr-xuser_socketvar.h4
23 files changed, 300 insertions, 313 deletions
diff --git a/Makefile.am b/Makefile.am
index d7f4f4a..85240b7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -42,7 +42,6 @@ libusrsctp_la_SOURCES = user_atomic.h \
user_queue.h \
user_recv_thread.c user_recv_thread.h \
user_route.h \
- user_sctp_timer_iterate.c \
user_socket.c \
user_socketvar.h \
user_uma.h \
diff --git a/Makefile.nmake b/Makefile.nmake
index a564fd4..48d2bd1 100644
--- a/Makefile.nmake
+++ b/Makefile.nmake
@@ -28,7 +28,7 @@
# SUCH DAMAGE.
#
-CFLAGS=/I. /W3
+CFLAGS=/I. /W3 /WX
CVARSDLL=-DSCTP_DEBUG -DSCTP_SIMPLE_ALLOCATOR -DSCTP_PROCESS_LEVEL_LOCKS
CVARSDLL=$(CVARSDLL) -D__Userspace__ -D__Userspace_os_Windows
@@ -41,7 +41,6 @@ usrsctp_OBJECTS = \
user_environment.obj \
user_mbuf.obj \
user_recv_thread.obj \
- user_sctp_timer_iterate.obj \
user_socket.obj \
sctp_asconf.obj \
sctp_auth.obj \
@@ -115,9 +114,6 @@ user_mbuf.obj : user_mbuf.c $(usrsctp_HEADERS)
user_recv_thread.obj: user_recv_thread.c $(usrsctp_HEADERS)
cl $(CVARSDLL) $(CFLAGS) -c user_recv_thread.c
-user_sctp_timer_iterate.obj : user_sctp_timer_iterate.c $(usrsctp_HEADERS)
- cl $(CVARSDLL) $(CFLAGS) -c user_sctp_timer_iterate.c
-
user_socket.obj : user_socket.c $(usrsctp_HEADERS)
cl $(CVARSDLL) $(CFLAGS) -c user_socket.c
diff --git a/netinet/sctp_auth.c b/netinet/sctp_auth.c
index 00ff978..50432ad 100755
--- a/netinet/sctp_auth.c
+++ b/netinet/sctp_auth.c
@@ -32,7 +32,7 @@
#ifdef __FreeBSD__
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/sctp_auth.c 269858 2014-08-12 11:30:16Z tuexen $");
+__FBSDID("$FreeBSD: head/sys/netinet/sctp_auth.c 271673 2014-09-16 14:20:33Z tuexen $");
#endif
#include <netinet/sctp_os.h>
@@ -633,7 +633,7 @@ sctp_copy_skeylist(const struct sctp_keyhead *src, struct sctp_keyhead *dest)
sctp_hmaclist_t *
-sctp_alloc_hmaclist(uint8_t num_hmacs)
+sctp_alloc_hmaclist(uint16_t num_hmacs)
{
sctp_hmaclist_t *new_list;
int alloc_size;
@@ -1464,8 +1464,8 @@ sctp_auth_get_cookie_params(struct sctp_tcb *stcb, struct mbuf *m,
p_random = (struct sctp_auth_random *)phdr;
random_len = plen - sizeof(*p_random);
} else if (ptype == SCTP_HMAC_LIST) {
- int num_hmacs;
- int i;
+ uint16_t num_hmacs;
+ uint16_t i;
if (plen > sizeof(hmacs_store))
break;
diff --git a/netinet/sctp_auth.h b/netinet/sctp_auth.h
index 04649ad..9973893 100755
--- a/netinet/sctp_auth.h
+++ b/netinet/sctp_auth.h
@@ -32,7 +32,7 @@
#ifdef __FreeBSD__
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/sctp_auth.h 269858 2014-08-12 11:30:16Z tuexen $");
+__FBSDID("$FreeBSD: head/sys/netinet/sctp_auth.h 271673 2014-09-16 14:20:33Z tuexen $");
#endif
#ifndef _NETINET_SCTP_AUTH_H_
@@ -149,7 +149,7 @@ extern void sctp_auth_key_release(struct sctp_tcb *stcb, uint16_t keyid,
/* hmac list handling */
-extern sctp_hmaclist_t *sctp_alloc_hmaclist(uint8_t num_hmacs);
+extern sctp_hmaclist_t *sctp_alloc_hmaclist(uint16_t num_hmacs);
extern void sctp_free_hmaclist(sctp_hmaclist_t *list);
extern int sctp_auth_add_hmacid(sctp_hmaclist_t *list, uint16_t hmac_id);
extern sctp_hmaclist_t *sctp_copy_hmaclist(sctp_hmaclist_t *list);
diff --git a/netinet/sctp_bsd_addr.c b/netinet/sctp_bsd_addr.c
index fe20ea9..b9ddb48 100755
--- a/netinet/sctp_bsd_addr.c
+++ b/netinet/sctp_bsd_addr.c
@@ -355,7 +355,7 @@ sctp_init_ifns_for_vrf(int vrfid)
continue;
}
ifa = (struct ifaddrs*)malloc(sizeof(struct ifaddrs));
- ifa->ifa_name = strdup(pAdapt->AdapterName);
+ ifa->ifa_name = _strdup(pAdapt->AdapterName);
ifa->ifa_flags = pAdapt->Flags;
ifa->ifa_addr = (struct sockaddr *)malloc(sizeof(struct sockaddr_in));
memcpy(ifa->ifa_addr, pUnicast->Address.lpSockaddr, sizeof(struct sockaddr_in));
@@ -403,7 +403,7 @@ sctp_init_ifns_for_vrf(int vrfid)
if (pAdapt->IfType == IF_TYPE_IEEE80211 || pAdapt->IfType == IF_TYPE_ETHERNET_CSMACD) {
for (pUnicast = pAdapt->FirstUnicastAddress; pUnicast; pUnicast = pUnicast->Next) {
ifa = (struct ifaddrs*)malloc(sizeof(struct ifaddrs));
- ifa->ifa_name = strdup(pAdapt->AdapterName);
+ ifa->ifa_name = _strdup(pAdapt->AdapterName);
ifa->ifa_flags = pAdapt->Flags;
ifa->ifa_addr = (struct sockaddr *)malloc(sizeof(struct sockaddr_in6));
memcpy(ifa->ifa_addr, pUnicast->Address.lpSockaddr, sizeof(struct sockaddr_in6));
@@ -745,7 +745,7 @@ sctp_addr_change(struct ifaddr *ifa, int cmd)
ifa->ifa_ifp->if_index,
ifa->ifa_ifp->if_xname);
#endif
-
+
/* We don't bump refcount here so when it completes
* the final delete will happen.
*/
diff --git a/netinet/sctp_callout.c b/netinet/sctp_callout.c
index 67b7566..3174e3f 100755
--- a/netinet/sctp_callout.c
+++ b/netinet/sctp_callout.c
@@ -30,9 +30,27 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#if defined(__Userspace__)
+#include <sys/types.h>
+#if !defined (__Userspace_os_Windows)
+#include <sys/wait.h>
+#include <unistd.h>
+#include <pthread.h>
+#endif
+#if defined(__Userspace_os_NaCl)
+#include <sys/select.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <netinet/sctp_sysctl.h>
+#include <netinet/sctp_pcb.h>
+#else
#include <netinet/sctp_os.h>
#include <netinet/sctp_callout.h>
#include <netinet/sctp_pcb.h>
+#endif
/*
* Callout/Timer routines for OS that doesn't have them
@@ -46,10 +64,8 @@ extern int ticks;
/*
* SCTP_TIMERQ_LOCK protects:
* - SCTP_BASE_INFO(callqueue)
- * - sctp_os_timer_current: current timer in process
* - sctp_os_timer_next: next timer to check
*/
-static sctp_os_timer_t *sctp_os_timer_current = NULL;
static sctp_os_timer_t *sctp_os_timer_next = NULL;
void
@@ -117,24 +133,16 @@ sctp_os_timer_stop(sctp_os_timer_t *c)
return (1);
}
-#if defined(__APPLE__)
-/*
- * For __APPLE__, use a single main timer at a faster resolution than
- * fastim. The timer just calls this existing callout infrastructure.
- */
-#endif
-void
-sctp_timeout(void *arg SCTP_UNUSED)
+static void
+sctp_handle_tick(int delta)
{
sctp_os_timer_t *c;
void (*c_func)(void *);
void *c_arg;
SCTP_TIMERQ_LOCK();
-#if defined(__APPLE__)
/* update our tick count */
- ticks += SCTP_BASE_VAR(sctp_main_timer_ticks);
-#endif
+ ticks += delta;
c = TAILQ_FIRST(&SCTP_BASE_INFO(callqueue));
while (c) {
if (c->c_time <= ticks) {
@@ -143,11 +151,9 @@ sctp_timeout(void *arg SCTP_UNUSED)
c_func = c->c_func;
c_arg = c->c_arg;
c->c_flags &= ~SCTP_CALLOUT_PENDING;
- sctp_os_timer_current = c;
SCTP_TIMERQ_UNLOCK();
c_func(c_arg);
SCTP_TIMERQ_LOCK();
- sctp_os_timer_current = NULL;
c = sctp_os_timer_next;
} else {
c = TAILQ_NEXT(c, tqe);
@@ -155,9 +161,60 @@ sctp_timeout(void *arg SCTP_UNUSED)
}
sctp_os_timer_next = NULL;
SCTP_TIMERQ_UNLOCK();
+}
#if defined(__APPLE__)
- /* restart the main timer */
+void
+sctp_timeout(void *arg SCTP_UNUSED)
+{
+ sctp_handle_tick(SCTP_BASE_VAR(sctp_main_timer_ticks));
sctp_start_main_timer();
+}
#endif
+
+#if defined(__Userspace__)
+#define TIMEOUT_INTERVAL 10
+
+void *
+user_sctp_timer_iterate(void *arg)
+{
+ for (;;) {
+#if defined (__Userspace_os_Windows)
+ Sleep(TIMEOUT_INTERVAL);
+#else
+ struct timeval timeout;
+
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 1000 * TIMEOUT_INTERVAL;
+ select(0, NULL, NULL, NULL, &timeout);
+#endif
+ if (SCTP_BASE_VAR(timer_thread_should_exit)) {
+ break;
+ }
+ sctp_handle_tick(MSEC_TO_TICKS(TIMEOUT_INTERVAL));
+ }
+ return (NULL);
}
+
+void
+sctp_start_timer(void)
+{
+ /*
+ * No need to do SCTP_TIMERQ_LOCK_INIT();
+ * here, it is being done in sctp_pcb_init()
+ */
+#if defined (__Userspace_os_Windows)
+ if ((SCTP_BASE_VAR(timer_thread) = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)user_sctp_timer_iterate, NULL, 0, NULL)) == NULL) {
+ SCTP_PRINTF("ERROR; Creating ithread failed\n");
+ }
+#else
+ int rc;
+
+ rc = pthread_create(&SCTP_BASE_VAR(timer_thread), NULL, user_sctp_timer_iterate, NULL);
+ if (rc) {
+ SCTP_PRINTF("ERROR; return code from pthread_create() is %d\n", rc);
+ }
+#endif
+}
+
+#endif
diff --git a/netinet/sctp_callout.h b/netinet/sctp_callout.h
index 2782945..c53c5a4 100755
--- a/netinet/sctp_callout.h
+++ b/netinet/sctp_callout.h
@@ -64,7 +64,6 @@ __FBSDID("$FreeBSD$");
#endif
extern int ticks;
-extern void sctp_start_timer();
#endif
TAILQ_HEAD(calloutlist, sctp_callout);
@@ -94,6 +93,11 @@ int sctp_os_timer_stop(sctp_os_timer_t *);
#define SCTP_OS_TIMER_ACTIVE(tmr) ((tmr)->c_flags & SCTP_CALLOUT_ACTIVE)
#define SCTP_OS_TIMER_DEACTIVATE(tmr) ((tmr)->c_flags &= ~SCTP_CALLOUT_ACTIVE)
+#if defined(__Userspace__)
+void sctp_start_timer(void);
+#endif
+#if defined(__APPLE__)
void sctp_timeout(void *);
+#endif
#endif
diff --git a/netinet/sctp_cc_functions.c b/netinet/sctp_cc_functions.c
index 6c6c946..3027e46 100755
--- a/netinet/sctp_cc_functions.c
+++ b/netinet/sctp_cc_functions.c
@@ -32,7 +32,7 @@
#ifdef __FreeBSD__
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/sctp_cc_functions.c 240158 2012-09-06 07:03:56Z tuexen $");
+__FBSDID("$FreeBSD: head/sys/netinet/sctp_cc_functions.c 271672 2014-09-16 13:48:46Z tuexen $");
#endif
#include <netinet/sctp_os.h>
@@ -1218,12 +1218,9 @@ sctp_cwnd_update_after_packet_dropped(struct sctp_tcb *stcb,
uint32_t *bottle_bw, uint32_t *on_queue)
{
uint32_t bw_avail;
- int rtt;
unsigned int incr;
int old_cwnd = net->cwnd;
- /* need real RTT in msd for this calc */
- rtt = net->rtt / 1000;
/* get bottle neck bw */
*bottle_bw = ntohl(cp->bottle_bw);
/* and whats on queue */
@@ -1232,10 +1229,11 @@ sctp_cwnd_update_after_packet_dropped(struct sctp_tcb *stcb,
* adjust the on-queue if our flight is more it could be
* that the router has not yet gotten data "in-flight" to it
*/
- if (*on_queue < net->flight_size)
+ if (*on_queue < net->flight_size) {
*on_queue = net->flight_size;
- /* calculate the available space */
- bw_avail = (*bottle_bw * rtt) / 1000;
+ }
+ /* rtt is measured in micro seconds, bottle_bw in bytes per second */
+ bw_avail = (uint32_t)(((uint64_t)(*bottle_bw) * net->rtt) / (uint64_t)1000000);
if (bw_avail > *bottle_bw) {
/*
* Cap the growth to no more than the bottle neck.
@@ -1253,8 +1251,8 @@ sctp_cwnd_update_after_packet_dropped(struct sctp_tcb *stcb,
* else to be "added to the fire".
*/
int seg_inflight, seg_onqueue, my_portion;
- net->partial_bytes_acked = 0;
+ net->partial_bytes_acked = 0;
/* how much are we over queue size? */
incr = *on_queue - bw_avail;
if (stcb->asoc.seen_a_sack_this_pkt) {
diff --git a/netinet/sctp_header.h b/netinet/sctp_header.h
index a860c18..f62181f 100755
--- a/netinet/sctp_header.h
+++ b/netinet/sctp_header.h
@@ -32,7 +32,7 @@
#ifdef __FreeBSD__
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/sctp_header.h 269376 2014-08-01 12:42:37Z tuexen $");
+__FBSDID("$FreeBSD: head/sys/netinet/sctp_header.h 273168 2014-10-16 15:36:04Z tuexen $");
#endif
#ifndef _NETINET_SCTP_HEADER_H_
@@ -468,6 +468,11 @@ struct sctp_pktdrop_chunk {
/**********STREAM RESET STUFF ******************/
+struct sctp_stream_reset_request {
+ struct sctp_paramhdr ph;
+ uint32_t request_seq;
+} SCTP_PACKED;
+
struct sctp_stream_reset_out_request {
struct sctp_paramhdr ph;
uint32_t request_seq; /* monotonically increasing seq no */
@@ -482,7 +487,6 @@ struct sctp_stream_reset_in_request {
uint16_t list_of_streams[]; /* if not all list of streams */
} SCTP_PACKED;
-
struct sctp_stream_reset_tsn_request {
struct sctp_paramhdr ph;
uint32_t request_seq;
diff --git a/netinet/sctp_input.c b/netinet/sctp_input.c
index cb7968f..da9c625 100755
--- a/netinet/sctp_input.c
+++ b/netinet/sctp_input.c
@@ -32,7 +32,7 @@
#ifdef __FreeBSD__
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/sctp_input.c 271230 2014-09-07 18:05:37Z tuexen $");
+__FBSDID("$FreeBSD: head/sys/netinet/sctp_input.c 273168 2014-10-16 15:36:04Z tuexen $");
#endif
#include <netinet/sctp_os.h>
@@ -3626,12 +3626,12 @@ sctp_reset_out_streams(struct sctp_tcb *stcb, uint32_t number_entries, uint16_t
}
-struct sctp_stream_reset_out_request *
+struct sctp_stream_reset_request *
sctp_find_stream_reset(struct sctp_tcb *stcb, uint32_t seq, struct sctp_tmit_chunk **bchk)
{
struct sctp_association *asoc;
struct sctp_chunkhdr *ch;
- struct sctp_stream_reset_out_request *r;
+ struct sctp_stream_reset_request *r;
struct sctp_tmit_chunk *chk;
int len, clen;
@@ -3654,7 +3654,7 @@ sctp_find_stream_reset(struct sctp_tcb *stcb, uint32_t seq, struct sctp_tmit_chu
}
clen = chk->send_size;
ch = mtod(chk->data, struct sctp_chunkhdr *);
- r = (struct sctp_stream_reset_out_request *)(ch + 1);
+ r = (struct sctp_stream_reset_request *)(ch + 1);
if (ntohl(r->request_seq) == seq) {
/* found it */
return (r);
@@ -3662,7 +3662,7 @@ sctp_find_stream_reset(struct sctp_tcb *stcb, uint32_t seq, struct sctp_tmit_chu
len = SCTP_SIZE32(ntohs(r->ph.param_length));
if (clen > (len + (int)sizeof(struct sctp_chunkhdr))) {
/* move to the next one, there can only be a max of two */
- r = (struct sctp_stream_reset_out_request *)((caddr_t)r + len);
+ r = (struct sctp_stream_reset_request *)((caddr_t)r + len);
if (ntohl(r->request_seq) == seq) {
return (r);
}
@@ -3706,7 +3706,9 @@ sctp_handle_stream_reset_response(struct sctp_tcb *stcb,
int lparm_len;
struct sctp_association *asoc = &stcb->asoc;
struct sctp_tmit_chunk *chk;
- struct sctp_stream_reset_out_request *srparam;
+ struct sctp_stream_reset_request *req_param;
+ struct sctp_stream_reset_out_request *req_out_param;
+ struct sctp_stream_reset_in_request *req_in_param;
uint32_t number_entries;
if (asoc->stream_reset_outstanding == 0) {
@@ -3714,35 +3716,36 @@ sctp_handle_stream_reset_response(struct sctp_tcb *stcb,
return (0);
}
if (seq == stcb->asoc.str_reset_seq_out) {
- srparam = sctp_find_stream_reset(stcb, seq, &chk);
- if (srparam) {
+ req_param = sctp_find_stream_reset(stcb, seq, &chk);
+ if (req_param != NULL) {
stcb->asoc.str_reset_seq_out++;
- type = ntohs(srparam->ph.param_type);
- lparm_len = ntohs(srparam->ph.param_length);
+ type = ntohs(req_param->ph.param_type);
+ lparm_len = ntohs(req_param->ph.param_length);
if (type == SCTP_STR_RESET_OUT_REQUEST) {
+ req_out_param = (struct sctp_stream_reset_out_request *)req_param;
number_entries = (lparm_len - sizeof(struct sctp_stream_reset_out_request)) / sizeof(uint16_t);
asoc->stream_reset_out_is_outstanding = 0;
if (asoc->stream_reset_outstanding)
asoc->stream_reset_outstanding--;
if (action == SCTP_STREAM_RESET_RESULT_PERFORMED) {
/* do it */
- sctp_reset_out_streams(stcb, number_entries, srparam->list_of_streams);
+ sctp_reset_out_streams(stcb, number_entries, req_out_param->list_of_streams);
} else if (action == SCTP_STREAM_RESET_RESULT_DENIED) {
- sctp_ulp_notify(SCTP_NOTIFY_STR_RESET_DENIED_OUT, stcb, number_entries, srparam->list_of_streams, SCTP_SO_NOT_LOCKED);
+ sctp_ulp_notify(SCTP_NOTIFY_STR_RESET_DENIED_OUT, stcb, number_entries, req_out_param->list_of_streams, SCTP_SO_NOT_LOCKED);
} else {
- sctp_ulp_notify(SCTP_NOTIFY_STR_RESET_FAILED_OUT, stcb, number_entries, srparam->list_of_streams, SCTP_SO_NOT_LOCKED);
+ sctp_ulp_notify(SCTP_NOTIFY_STR_RESET_FAILED_OUT, stcb, number_entries, req_out_param->list_of_streams, SCTP_SO_NOT_LOCKED);
}
} else if (type == SCTP_STR_RESET_IN_REQUEST) {
- /* Answered my request */
+ req_in_param = (struct sctp_stream_reset_in_request *)req_param;
number_entries = (lparm_len - sizeof(struct sctp_stream_reset_in_request)) / sizeof(uint16_t);
if (asoc->stream_reset_outstanding)
asoc->stream_reset_outstanding--;
if (action == SCTP_STREAM_RESET_RESULT_DENIED) {
sctp_ulp_notify(SCTP_NOTIFY_STR_RESET_DENIED_IN, stcb,
- number_entries, srparam->list_of_streams, SCTP_SO_NOT_LOCKED);
+ number_entries, req_in_param->list_of_streams, SCTP_SO_NOT_LOCKED);
} else if (action != SCTP_STREAM_RESET_RESULT_PERFORMED) {
sctp_ulp_notify(SCTP_NOTIFY_STR_RESET_FAILED_IN, stcb,
- number_entries, srparam->list_of_streams, SCTP_SO_NOT_LOCKED);
+ number_entries, req_in_param->list_of_streams, SCTP_SO_NOT_LOCKED);
}
} else if (type == SCTP_STR_RESET_ADD_OUT_STREAMS) {
/* Ok we now may have more streams */
@@ -4202,8 +4205,10 @@ sctp_handle_stream_reset(struct sctp_tcb *stcb, struct mbuf *m, int offset,
if (chk == NULL) {
return (ret_code);
}
+ chk->copy_by_ref = 0;
chk->rec.chunk_id.id = SCTP_STREAM_RESET;
chk->rec.chunk_id.can_take_data = 0;
+ chk->flags = 0;
chk->asoc = &stcb->asoc;
chk->no_fr_allowed = 0;
chk->book_size = chk->send_size = sizeof(struct sctp_chunkhdr);
diff --git a/netinet/sctp_input.h b/netinet/sctp_input.h
index 4756780..5d45fef 100755
--- a/netinet/sctp_input.h
+++ b/netinet/sctp_input.h
@@ -32,7 +32,7 @@
#ifdef __FreeBSD__
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/sctp_input.h 240198 2012-09-07 13:36:42Z tuexen $");
+__FBSDID("$FreeBSD: head/sys/netinet/sctp_input.h 273168 2014-10-16 15:36:04Z tuexen $");
#endif
#ifndef _NETINET_SCTP_INPUT_H_
@@ -52,7 +52,7 @@ sctp_common_input_processing(struct mbuf **, int, int, int,
#endif
uint32_t, uint16_t);
-struct sctp_stream_reset_out_request *
+struct sctp_stream_reset_request *
sctp_find_stream_reset(struct sctp_tcb *stcb, uint32_t seq,
struct sctp_tmit_chunk **bchk);
diff --git a/netinet/sctp_os_userspace.h b/netinet/sctp_os_userspace.h
index eca3e18..a8d1f08 100755
--- a/netinet/sctp_os_userspace.h
+++ b/netinet/sctp_os_userspace.h
@@ -103,7 +103,6 @@ typedef HANDLE userland_thread_t;
#define n_time unsigned __int32
#define sa_family_t unsigned __int8
#define ssize_t __int64
-#define IFNAMSIZ 64
#define __func__ __FUNCTION__
#ifndef EWOULDBLOCK
@@ -222,8 +221,6 @@ typedef char* caddr_t;
#define snprintf(data, size, format, ...) _snprintf_s(data, size, _TRUNCATE, format, __VA_ARGS__)
#define inline __inline
#define __inline__ __inline
-#define random() rand()
-#define srandom(s) srand(s)
#define MSG_EOR 0x8 /* data completes record */
#define MSG_DONTWAIT 0x80 /* this message should be nonblocking */
@@ -265,6 +262,32 @@ typedef char* caddr_t;
#define SCTP_GET_IF_INDEX_FROM_ROUTE(ro) 1 /* compiles... TODO use routing socket to determine */
+#define BIG_ENDIAN 1
+#define LITTLE_ENDIAN 0
+#ifdef WORDS_BIGENDIAN
+#define BYTE_ORDER BIG_ENDIAN
+#else
+#define BYTE_ORDER LITTLE_ENDIAN
+#endif
+
+#else /* !defined(Userspace_os_Windows) */
+#include <sys/cdefs.h> /* needed? added from old __FreeBSD__ */
+#include <sys/socket.h>
+#if defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_Linux) || defined(__Userspace_os_NetBSD) || defined(__Userspace_os_OpenBSD) || defined(__Userspace_os_NaCl)
+#include <pthread.h>
+#endif
+typedef pthread_mutex_t userland_mutex_t;
+typedef pthread_cond_t userland_cond_t;
+typedef pthread_t userland_thread_t;
+#endif
+
+#if defined(__Userspace_os_Windows) || defined(__Userspace_os_NaCl)
+
+#define IFNAMSIZ 64
+
+#define random() rand()
+#define srandom(s) srand(s)
+
#define timeradd(tvp, uvp, vvp) \
do { \
(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
@@ -285,30 +308,57 @@ typedef char* caddr_t;
} \
} while (0)
-#define BIG_ENDIAN 1
-#define LITTLE_ENDIAN 0
-#ifdef WORDS_BIGENDIAN
-#define BYTE_ORDER BIG_ENDIAN
-#else
-#define BYTE_ORDER LITTLE_ENDIAN
-#endif
+/*#include <packon.h>
+#pragma pack(push, 1)*/
+struct ip {
+ u_char ip_hl:4, ip_v:4;
+ u_char ip_tos;
+ u_short ip_len;
+ u_short ip_id;
+ u_short ip_off;
+#define IP_RP 0x8000
+#define IP_DF 0x4000
+#define IP_MF 0x2000
+#define IP_OFFMASK 0x1fff
+ u_char ip_ttl;
+ u_char ip_p;
+ u_short ip_sum;
+ struct in_addr ip_src, ip_dst;
+};
+
+struct ifaddrs {
+ struct ifaddrs *ifa_next;
+ char *ifa_name;
+ unsigned int ifa_flags;
+ struct sockaddr *ifa_addr;
+ struct sockaddr *ifa_netmask;
+ struct sockaddr *ifa_dstaddr;
+ void *ifa_data;
+};
+
+struct udphdr {
+ uint16_t uh_sport;
+ uint16_t uh_dport;
+ uint16_t uh_ulen;
+ uint16_t uh_sum;
+};
struct iovec {
- ULONG len;
- CHAR FAR *buf;
+ unsigned long len;
+ char *buf;
};
#define iov_base buf
#define iov_len len
struct ifa_msghdr {
- unsigned __int16 ifam_msglen;
+ uint16_t ifam_msglen;
unsigned char ifam_version;
unsigned char ifam_type;
- __int32 ifam_addrs;
- __int32 ifam_flags;
- unsigned __int16 ifam_index;
- __int32 ifam_metric;
+ uint32_t ifam_addrs;
+ uint32_t ifam_flags;
+ uint16_t ifam_index;
+ uint32_t ifam_metric;
};
struct ifdevmtu {
@@ -341,7 +391,7 @@ struct ifreq {
char* ifru_data;
struct ifdevmtu ifru_devmtu;
struct ifkpi ifru_kpi;
- unsigned __int32 ifru_wake_flags;
+ uint32_t ifru_wake_flags;
} ifr_ifru;
#define ifr_addr ifr_ifru.ifru_addr
#define ifr_dstaddr ifr_ifru.ifru_dstaddr
@@ -359,55 +409,13 @@ struct ifreq {
#define ifr_wake_flags ifr_ifru.ifru_wake_flags
};
-/*#include <packon.h>
-#pragma pack(push, 1)*/
-struct ip {
- u_char ip_hl:4, ip_v:4;
- u_char ip_tos;
- u_short ip_len;
- u_short ip_id;
- u_short ip_off;
-#define IP_RP 0x8000
-#define IP_DF 0x4000
-#define IP_MF 0x2000
-#define IP_OFFMASK 0x1fff
- u_char ip_ttl;
- u_char ip_p;
- u_short ip_sum;
- struct in_addr ip_src, ip_dst;
-};
-
-struct ifaddrs {
- struct ifaddrs *ifa_next;
- char *ifa_name;
- unsigned int ifa_flags;
- struct sockaddr *ifa_addr;
- struct sockaddr *ifa_netmask;
- struct sockaddr *ifa_dstaddr;
- void *ifa_data;
-};
-
-struct udphdr {
- unsigned __int16 uh_sport;
- unsigned __int16 uh_dport;
- unsigned __int16 uh_ulen;
- unsigned __int16 uh_sum;
-};
+#endif
+#if defined(__Userspace_os_Windows)
int Win_getifaddrs(struct ifaddrs**);
#define getifaddrs(interfaces) (int)Win_getifaddrs(interfaces)
int win_if_nametoindex(const char *);
#define if_nametoindex(x) win_if_nametoindex(x)
-
-#else /* !defined(Userspace_os_Windows) */
-#include <sys/cdefs.h> /* needed? added from old __FreeBSD__ */
-#include <sys/socket.h>
-#if defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_Linux) || defined(__Userspace_os_NetBSD) || defined(__Userspace_os_OpenBSD)
-#include <pthread.h>
-#endif
-typedef pthread_mutex_t userland_mutex_t;
-typedef pthread_cond_t userland_cond_t;
-typedef pthread_t userland_thread_t;
#endif
#define mtx_lock(arg1)
@@ -469,7 +477,7 @@ struct sx {int dummy;};
* userspace as well? */
/* on FreeBSD, this results in a redefintion of struct route */
/* #include <net/route.h> */
-#if !defined(__Userspace_os_Windows)
+#if !defined(__Userspace_os_Windows) && !defined(__Userspace_os_NaCl)
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
@@ -1095,7 +1103,7 @@ sctp_get_mbuf_for_msg(unsigned int space_needed, int want_header, int how, int a
/* with the current included files, this is defined in Linux but
* in FreeBSD, it is behind a _KERNEL in sys/socket.h ...
*/
-#if defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_OpenBSD)
+#if defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_OpenBSD) || defined(__Userspace_os_NaCl)
/* stolen from /usr/include/sys/socket.h */
#define CMSG_ALIGN(n) _ALIGN(n)
#elif defined(__Userspace_os_NetBSD)
@@ -1153,4 +1161,12 @@ sctp_get_mbuf_for_msg(unsigned int space_needed, int want_header, int how, int a
#define TAILQ_FOREACH_SAFE TAILQ_FOREACH_MUTABLE
#define LIST_FOREACH_SAFE LIST_FOREACH_MUTABLE
#endif
+
+#if defined(__Userspace_os_NaCl)
+#define timercmp(tvp, uvp, cmp) \
+ (((tvp)->tv_sec == (uvp)->tv_sec) ? \
+ ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
+ ((tvp)->tv_sec cmp (uvp)->tv_sec))
+#endif
+
#endif
diff --git a/netinet/sctp_output.c b/netinet/sctp_output.c
index a305ea5..57cc8c6 100755
--- a/netinet/sctp_output.c
+++ b/netinet/sctp_output.c
@@ -32,7 +32,7 @@
#ifdef __FreeBSD__
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/sctp_output.c 271230 2014-09-07 18:05:37Z tuexen $");
+__FBSDID("$FreeBSD: head/sys/netinet/sctp_output.c 273634 2014-10-25 09:25:29Z tuexen $");
#endif
#include <netinet/sctp_os.h>
@@ -3477,7 +3477,12 @@ sctp_source_address_selection(struct sctp_inpcb *inp,
if (ro->ro_rt == NULL) {
return (NULL);
}
+#if defined(__Userspace_os_Windows)
+ /* On Windows the sa_family is U_SHORT or ADDRESS_FAMILY */
+ fam = (sa_family_t)ro->ro_dst.sa_family;
+#else
fam = ro->ro_dst.sa_family;
+#endif
dest_is_priv = dest_is_loop = 0;
/* Setup our scopes for the destination */
switch (fam) {
@@ -7160,9 +7165,10 @@ sctp_sendall_iterator(struct sctp_inpcb *inp, struct sctp_tcb *stcb, void *ptr,
if (do_chunk_output)
sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_USR_SEND, SCTP_SO_NOT_LOCKED);
else if (added_control) {
- int num_out = 0, reason = 0, now_filled = 0;
+ int num_out, reason, now_filled = 0;
struct timeval now;
int frag_point;
+
frag_point = sctp_get_frag_point(stcb, &stcb->asoc);
(void)sctp_med_chunk_output(inp, stcb, &stcb->asoc, &num_out,
&reason, 1, 1, &now, &now_filled, frag_point, SCTP_SO_NOT_LOCKED);
@@ -7195,13 +7201,6 @@ sctp_sendall_completes(void *ptr, uint32_t val SCTP_UNUSED)
SCTP_FREE(ca, SCTP_M_COPYAL);
}
-
-#define MC_ALIGN(m, len) do { \
- SCTP_BUF_RESV_UF(m, ((MCLBYTES - (len)) & ~(sizeof(long) - 1)); \
-} while (0)
-
-
-
static struct mbuf *
sctp_copy_out_all(struct uio *uio, int len)
{
@@ -8249,6 +8248,7 @@ sctp_med_chunk_output(struct sctp_inpcb *inp,
}
#endif
*num_out = 0;
+ *reason_code = 0;
auth_keyid = stcb->asoc.authinfo.active_keyid;
if ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) ||
(asoc->state & SCTP_STATE_SHUTDOWN_RECEIVED) ||
@@ -9372,16 +9372,11 @@ sctp_queue_op_err(struct sctp_tcb *stcb, struct mbuf *op_err)
return;
}
chk->send_size = 0;
- mat = op_err;
- while (mat != NULL) {
+ for (mat = op_err; mat != NULL; mat = SCTP_BUF_NEXT(mat)) {
chk->send_size += SCTP_BUF_LEN(mat);
- mat = SCTP_BUF_NEXT(mat);
}
- chk->rec.chunk_id.id = SCTP_OPERATION_ERROR;
- chk->rec.chunk_id.can_take_data = 1;
chk->sent = SCTP_DATAGRAM_UNSENT;
chk->snd_count = 0;
- chk->flags = 0;
chk->asoc = &stcb->asoc;
chk->data = op_err;
chk->whoTo = NULL;
@@ -9469,12 +9464,12 @@ sctp_send_cookie_echo(struct mbuf *m,
return (-5);
}
chk->copy_by_ref = 0;
- chk->send_size = plen;
chk->rec.chunk_id.id = SCTP_COOKIE_ECHO;
chk->rec.chunk_id.can_take_data = 0;
+ chk->flags = CHUNK_FLAGS_FRAGMENT_OK;
+ chk->send_size = plen;
chk->sent = SCTP_DATAGRAM_UNSENT;
chk->snd_count = 0;
- chk->flags = CHUNK_FLAGS_FRAGMENT_OK;
chk->asoc = &stcb->asoc;
chk->data = cookie;
chk->whoTo = net;
@@ -9537,12 +9532,12 @@ sctp_send_heartbeat_ack(struct sctp_tcb *stcb,
return;
}
chk->copy_by_ref = 0;
- chk->send_size = chk_length;
chk->rec.chunk_id.id = SCTP_HEARTBEAT_ACK;
chk->rec.chunk_id.can_take_data = 1;
+ chk->flags = 0;
+ chk->send_size = chk_length;
chk->sent = SCTP_DATAGRAM_UNSENT;
chk->snd_count = 0;
- chk->flags = 0;
chk->asoc = &stcb->asoc;
chk->data = outchain;
chk->whoTo = net;
@@ -9574,12 +9569,12 @@ sctp_send_cookie_ack(struct sctp_tcb *stcb)
return;
}
chk->copy_by_ref = 0;
- chk->send_size = sizeof(struct sctp_chunkhdr);
chk->rec.chunk_id.id = SCTP_COOKIE_ACK;
chk->rec.chunk_id.can_take_data = 1;
+ chk->flags = 0;
+ chk->send_size = sizeof(struct sctp_chunkhdr);
chk->sent = SCTP_DATAGRAM_UNSENT;
chk->snd_count = 0;
- chk->flags = 0;
chk->asoc = &stcb->asoc;
chk->data = cookie_ack;
if (chk->asoc->last_control_chunk_from != NULL) {
@@ -9620,9 +9615,10 @@ sctp_send_shutdown_ack(struct sctp_tcb *stcb, struct sctp_nets *net)
return;
}
chk->copy_by_ref = 0;
- chk->send_size = sizeof(struct sctp_chunkhdr);
chk->rec.chunk_id.id = SCTP_SHUTDOWN_ACK;
chk->rec.chunk_id.can_take_data = 1;
+ chk->flags = 0;
+ chk->send_size = sizeof(struct sctp_chunkhdr);
chk->sent = SCTP_DATAGRAM_UNSENT;
chk->snd_count = 0;
chk->flags = 0;
@@ -9663,9 +9659,10 @@ sctp_send_shutdown(struct sctp_tcb *stcb, struct sctp_nets *net)
return;
}
chk->copy_by_ref = 0;
- chk->send_size = sizeof(struct sctp_shutdown_chunk);
chk->rec.chunk_id.id = SCTP_SHUTDOWN;
chk->rec.chunk_id.can_take_data = 1;
+ chk->flags = 0;
+ chk->send_size = sizeof(struct sctp_shutdown_chunk);
chk->sent = SCTP_DATAGRAM_UNSENT;
chk->snd_count = 0;
chk->flags = 0;
@@ -9719,13 +9716,13 @@ sctp_send_asconf(struct sctp_tcb *stcb, struct sctp_nets *net, int addr_locked)
}
chk->copy_by_ref = 0;
- chk->data = m_asconf;
- chk->send_size = len;
chk->rec.chunk_id.id = SCTP_ASCONF;
chk->rec.chunk_id.can_take_data = 0;
+ chk->flags = CHUNK_FLAGS_FRAGMENT_OK;
+ chk->data = m_asconf;
+ chk->send_size = len;
chk->sent = SCTP_DATAGRAM_UNSENT;
chk->snd_count = 0;
- chk->flags = CHUNK_FLAGS_FRAGMENT_OK;
chk->asoc = &stcb->asoc;
chk->whoTo = net;
if (chk->whoTo) {
@@ -9815,7 +9812,9 @@ sctp_send_asconf_ack(struct sctp_tcb *stcb)
return;
}
chk->copy_by_ref = 0;
-
+ chk->rec.chunk_id.id = SCTP_ASCONF_ACK;
+ chk->rec.chunk_id.can_take_data = 1;
+ chk->flags = CHUNK_FLAGS_FRAGMENT_OK;
chk->whoTo = net;
if (chk->whoTo) {
atomic_add_int(&chk->whoTo->ref_count, 1);
@@ -9824,11 +9823,8 @@ sctp_send_asconf_ack(struct sctp_tcb *stcb)
chk->send_size = 0;
/* Get size */
chk->send_size = ack->len;
- chk->rec.chunk_id.id = SCTP_ASCONF_ACK;
- chk->rec.chunk_id.can_take_data = 1;
chk->sent = SCTP_DATAGRAM_UNSENT;
chk->snd_count = 0;
- chk->flags |= CHUNK_FLAGS_FRAGMENT_OK; /* XXX */
chk->asoc = &stcb->asoc;
TAILQ_INSERT_TAIL(&chk->asoc->control_send_queue, chk, sctp_next);
@@ -10411,7 +10407,7 @@ sctp_chunk_output (struct sctp_inpcb *inp,
*/
struct sctp_association *asoc;
struct sctp_nets *net;
- int error = 0, num_out = 0, tot_out = 0, ret = 0, reason_code = 0;
+ int error = 0, num_out, tot_out = 0, ret = 0, reason_code;
unsigned int burst_cnt = 0;
struct timeval now;
int now_filled = 0;
@@ -10741,6 +10737,7 @@ send_forward_tsn(struct sctp_tcb *stcb,
chk->copy_by_ref = 0;
chk->rec.chunk_id.id = SCTP_FORWARD_CUM_TSN;
chk->rec.chunk_id.can_take_data = 0;
+ chk->flags = 0;
chk->asoc = asoc;
chk->whoTo = NULL;
chk->data = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA);
@@ -10974,6 +10971,7 @@ sctp_send_sack(struct sctp_tcb *stcb, int so_locked
/* Clear our pkt counts */
asoc->data_pkts_seen = 0;
+ a_chk->flags = 0;
a_chk->asoc = asoc;
a_chk->snd_count = 0;
a_chk->send_size = 0; /* fill in later */
@@ -11897,6 +11895,7 @@ sctp_send_hb(struct sctp_tcb *stcb, struct sctp_nets *net,int so_locked
chk->copy_by_ref = 0;
chk->rec.chunk_id.id = SCTP_HEARTBEAT_REQUEST;
chk->rec.chunk_id.can_take_data = 1;
+ chk->flags = 0;
chk->asoc = &stcb->asoc;
chk->send_size = sizeof(struct sctp_heartbeat_chunk);
@@ -11924,7 +11923,7 @@ sctp_send_hb(struct sctp_tcb *stcb, struct sctp_nets *net,int so_locked
hb->heartbeat.hb_info.time_value_1 = now.tv_sec;
hb->heartbeat.hb_info.time_value_2 = now.tv_usec;
/* Did our user request this one, put it in */
- hb->heartbeat.hb_info.addr_family = net->ro._l_addr.sa.sa_family;
+ hb->heartbeat.hb_info.addr_family = (uint8_t)net->ro._l_addr.sa.sa_family;
#ifdef HAVE_SA_LEN
hb->heartbeat.hb_info.addr_len = net->ro._l_addr.sa.sa_len;
#else
@@ -12027,10 +12026,11 @@ sctp_send_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net,
if (chk == NULL) {
return;
}
- chk->copy_by_ref = 0;
SCTP_STAT_INCR(sctps_queue_upd_ecne);
+ chk->copy_by_ref = 0;
chk->rec.chunk_id.id = SCTP_ECN_ECHO;
chk->rec.chunk_id.can_take_data = 0;
+ chk->flags = 0;
chk->asoc = &stcb->asoc;
chk->send_size = sizeof(struct sctp_ecne_chunk);
chk->data = sctp_get_mbuf_for_msg(chk->send_size, 0, M_NOWAIT, 1, MT_HEADER);
@@ -12090,6 +12090,9 @@ sctp_send_packet_dropped(struct sctp_tcb *stcb, struct sctp_nets *net,
return;
}
chk->copy_by_ref = 0;
+ chk->rec.chunk_id.id = SCTP_PACKET_DROPPED;
+ chk->rec.chunk_id.can_take_data = 1;
+ chk->flags = 0;
len -= iphlen;
chk->send_size = len;
/* Validate that we do not have an ABORT in here. */
@@ -12175,8 +12178,6 @@ jump_out:
} else {
chk->whoTo = NULL;
}
- chk->rec.chunk_id.id = SCTP_PACKET_DROPPED;
- chk->rec.chunk_id.can_take_data = 1;
drp->ch.chunk_type = SCTP_PACKET_DROPPED;
drp->ch.chunk_length = htons(chk->send_size);
spc = SCTP_SB_LIMIT_RCV(stcb->sctp_socket);
@@ -12238,6 +12239,7 @@ sctp_send_cwr(struct sctp_tcb *stcb, struct sctp_nets *net, uint32_t high_tsn, u
chk->copy_by_ref = 0;
chk->rec.chunk_id.id = SCTP_ECN_CWR;
chk->rec.chunk_id.can_take_data = 1;
+ chk->flags = 0;
chk->asoc = &stcb->asoc;
chk->send_size = sizeof(struct sctp_cwr_chunk);
chk->data = sctp_get_mbuf_for_msg(chk->send_size, 0, M_NOWAIT, 1, MT_HEADER);
@@ -12500,7 +12502,7 @@ sctp_add_an_in_stream(struct sctp_tmit_chunk *chk,
int
sctp_send_str_reset_req(struct sctp_tcb *stcb,
- int number_entries, uint16_t *list,
+ uint16_t number_entries, uint16_t *list,
uint8_t send_out_req,
uint8_t send_in_req,
uint8_t send_tsn_req,
@@ -12533,6 +12535,14 @@ sctp_send_str_reset_req(struct sctp_tcb *stcb,
SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, EINVAL);
return (EINVAL);
}
+ if (number_entries > (MCLBYTES -
+ SCTP_MIN_OVERHEAD -
+ sizeof(struct sctp_chunkhdr) -
+ sizeof(struct sctp_stream_reset_out_request)) /
+ sizeof(uint16_t)) {
+ SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM);
+ return (ENOMEM);
+ }
sctp_alloc_a_chunk(stcb, chk);
if (chk == NULL) {
SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTP_OUTPUT, ENOMEM);
@@ -12541,6 +12551,7 @@ sctp_send_str_reset_req(struct sctp_tcb *stcb,
chk->copy_by_ref = 0;
chk->rec.chunk_id.id = SCTP_STREAM_RESET;
chk->rec.chunk_id.can_take_data = 0;
+ chk->flags = 0;
chk->asoc = &stcb->asoc;
chk->book_size = sizeof(struct sctp_chunkhdr);
chk->send_size = SCTP_SIZE32(chk->book_size);
diff --git a/netinet/sctp_output.h b/netinet/sctp_output.h
index 808af1b..d03bead 100755
--- a/netinet/sctp_output.h
+++ b/netinet/sctp_output.h
@@ -32,7 +32,7 @@
#ifdef __FreeBSD__
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/sctp_output.h 246595 2013-02-09 17:26:14Z tuexen $");
+__FBSDID("$FreeBSD: head/sys/netinet/sctp_output.h 272751 2014-10-08 15:30:59Z tuexen $");
#endif
#ifndef _NETINET_SCTP_OUTPUT_H_
@@ -208,8 +208,8 @@ sctp_add_stream_reset_result_tsn(struct sctp_tmit_chunk *,
uint32_t, uint32_t, uint32_t, uint32_t);
int
-sctp_send_str_reset_req(struct sctp_tcb *, int , uint16_t *, uint8_t, uint8_t,
- uint8_t, uint8_t, uint16_t, uint16_t, uint8_t);
+sctp_send_str_reset_req(struct sctp_tcb *, uint16_t , uint16_t *, uint8_t,
+ uint8_t, uint8_t, uint8_t, uint16_t, uint16_t, uint8_t);
void
sctp_send_abort(struct mbuf *, int, struct sockaddr *, struct sockaddr *,
diff --git a/netinet/sctp_pcb.c b/netinet/sctp_pcb.c
index ffe8f62..9e0145e 100755
--- a/netinet/sctp_pcb.c
+++ b/netinet/sctp_pcb.c
@@ -32,7 +32,7 @@
#ifdef __FreeBSD__
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/sctp_pcb.c 271230 2014-09-07 18:05:37Z tuexen $");
+__FBSDID("$FreeBSD: head/sys/netinet/sctp_pcb.c 271673 2014-09-16 14:20:33Z tuexen $");
#endif
#include <netinet/sctp_os.h>
@@ -7528,8 +7528,8 @@ sctp_load_addresses_from_init(struct sctp_tcb *stcb, struct mbuf *m,
}
got_random = 1;
} else if (ptype == SCTP_HMAC_LIST) {
- int num_hmacs;
- int i;
+ uint16_t num_hmacs;
+ uint16_t i;
if (plen > sizeof(hmacs_store))
break;
diff --git a/netinet/sctp_structs.h b/netinet/sctp_structs.h
index 7214d8d..eadd44e 100755
--- a/netinet/sctp_structs.h
+++ b/netinet/sctp_structs.h
@@ -32,7 +32,7 @@
#ifdef __FreeBSD__
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/sctp_structs.h 269945 2014-08-13 15:50:16Z tuexen $");
+__FBSDID("$FreeBSD: head/sys/netinet/sctp_structs.h 271643 2014-09-15 19:38:34Z tuexen $");
#endif
#ifndef _NETINET_SCTP_STRUCTS_H_
@@ -468,8 +468,8 @@ TAILQ_HEAD(sctpchunk_listhead, sctp_tmit_chunk);
#define CHUNK_FLAGS_FRAGMENT_OK 0x0100
struct chk_id {
- uint16_t id;
- uint16_t can_take_data;
+ uint8_t id;
+ uint8_t can_take_data;
};
diff --git a/netinet/sctp_userspace.c b/netinet/sctp_userspace.c
index 7763f30..7841a89 100755
--- a/netinet/sctp_userspace.c
+++ b/netinet/sctp_userspace.c
@@ -35,7 +35,7 @@
#endif
#include <netinet/sctp_os_userspace.h>
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__Userspace_os_NaCl)
int
sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af)
{
@@ -55,6 +55,14 @@ sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af)
}
#endif
+#if defined(__Userspace_os_NaCl)
+int
+sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af)
+{
+ return 1280;
+}
+#endif
+
#ifdef _WIN32
int
sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af)
@@ -90,8 +98,8 @@ getwintimeofday(struct timeval *tv)
struct timeb tb;
ftime(&tb);
- tv->tv_sec = tb.time;
- tv->tv_usec = tb.millitm * 1000;
+ tv->tv_sec = (long)tb.time;
+ tv->tv_usec = (long)(tb.millitm) * 1000L;
}
int
@@ -138,7 +146,7 @@ Win_getifaddrs(struct ifaddrs** interfaces)
SCTPDBG(SCTP_DEBUG_USR, "Can't allocate memory\n");
return (-1);
}
- ifa->ifa_name = strdup(pAdapt->AdapterName);
+ ifa->ifa_name = _strdup(pAdapt->AdapterName);
ifa->ifa_flags = pAdapt->Flags;
ifa->ifa_addr = (struct sockaddr *)addr;
memcpy(addr, &pAdapt->FirstUnicastAddress->Address.lpSockaddr, sizeof(struct sockaddr_in));
@@ -172,7 +180,7 @@ Win_getifaddrs(struct ifaddrs** interfaces)
SCTPDBG(SCTP_DEBUG_USR, "Can't allocate memory\n");
return (-1);
}
- ifa->ifa_name = strdup(pAdapt->AdapterName);
+ ifa->ifa_name = _strdup(pAdapt->AdapterName);
ifa->ifa_flags = pAdapt->Flags;
ifa->ifa_addr = (struct sockaddr *)addr6;
memcpy(addr6, &pAdapt->FirstUnicastAddress->Address.lpSockaddr, sizeof(struct sockaddr_in6));
@@ -215,11 +223,11 @@ win_if_nametoindex(const char *ifname)
}
#if WINVER < 0x0600
-/* These functions are written based on the code at
+/* These functions are written based on the code at
* http://www.cs.wustl.edu/~schmidt/win32-cv-1.html
* Therefore, for the rest of the file the following applies:
*
- *
+ *
* Copyright and Licensing Information for ACE(TM), TAO(TM), CIAO(TM),
* DAnCE(TM), and CoSMIC(TM)
*
@@ -326,7 +334,7 @@ win_if_nametoindex(const char *ifname)
* 22. http://www.dre.vanderbilt.edu/~schmidt/
* 23. http://www.cs.wustl.edu/ACE.html
*/
-
+
void
InitializeXPConditionVariable(userland_cond_t *cv)
{
@@ -359,8 +367,7 @@ SleepXPConditionVariable(userland_cond_t *cv, userland_mutex_t *mtx)
}
EnterCriticalSection(&cv->waiters_count_lock);
cv->waiters_count--;
- last_waiter =
- result == (C_SIGNAL + C_BROADCAST && (cv->waiters_count == 0));
+ last_waiter = result == (C_SIGNAL + C_BROADCAST && (cv->waiters_count == 0));
LeaveCriticalSection(&cv->waiters_count_lock);
if (last_waiter)
ResetEvent(cv->events_[C_BROADCAST]);
diff --git a/netinet/sctp_usrreq.c b/netinet/sctp_usrreq.c
index 296b9f3..362d353 100755
--- a/netinet/sctp_usrreq.c
+++ b/netinet/sctp_usrreq.c
@@ -32,7 +32,7 @@
#ifdef __FreeBSD__
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/sctp_usrreq.c 271221 2014-09-07 09:06:26Z tuexen $");
+__FBSDID("$FreeBSD: head/sys/netinet/sctp_usrreq.c 272750 2014-10-08 15:29:49Z tuexen $");
#endif
#include <netinet/sctp_os.h>
@@ -56,7 +56,9 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_usrreq.c 271221 2014-09-07 09:06:26Z t
#include <netinet/sctp_timer.h>
#include <netinet/sctp_auth.h>
#include <netinet/sctp_bsd_addr.h>
-#if !defined(__Userspace__)
+#if defined(__Userspace__)
+#include <netinet/sctp_callout.h>
+#else
#include <netinet/udp.h>
#endif
@@ -106,7 +108,7 @@ sctp_init(void)
/* Initialize and modify the sysctled variables */
sctp_init_sysctls();
#if defined(__Userspace__)
-#if defined(__Userspace_os_Windows)
+#if defined(__Userspace_os_Windows) || defined(__Userspace_os_NaCl)
srand((unsigned int)time(NULL));
#else
srandom(getpid()); /* so inp->sctp_ep.random_numbers are truly random... */
@@ -5027,13 +5029,14 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
uint32_t i;
SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
- if (optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) {
+ if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
+ (shmac->shmac_number_of_idents > 0xffff)) {
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
error = EINVAL;
break;
}
- hmaclist = sctp_alloc_hmaclist(shmac->shmac_number_of_idents);
+ hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
if (hmaclist == NULL) {
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
error = ENOMEM;
@@ -5251,6 +5254,12 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
SCTP_TCB_UNLOCK(stcb);
break;
}
+ if (sizeof(struct sctp_reset_streams) +
+ strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
+ error = EINVAL;
+ SCTP_TCB_UNLOCK(stcb);
+ break;
+ }
if (stcb->asoc.stream_reset_outstanding) {
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
error = EALREADY;
diff --git a/netinet/sctputil.c b/netinet/sctputil.c
index 87e770d..bf2d212 100755
--- a/netinet/sctputil.c
+++ b/netinet/sctputil.c
@@ -32,7 +32,7 @@
#ifdef __FreeBSD__
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/sctputil.c 271221 2014-09-07 09:06:26Z tuexen $");
+__FBSDID("$FreeBSD: head/sys/netinet/sctputil.c 271674 2014-09-16 14:39:24Z tuexen $");
#endif
#include <netinet/sctp_os.h>
@@ -2524,8 +2524,8 @@ sctp_calculate_rto(struct sctp_tcb *stcb,
/* store the current RTT in us */
net->rtt = (uint64_t)1000000 * (uint64_t)now.tv_sec +
(uint64_t)now.tv_usec;
- /* computer rtt in ms */
- rtt = net->rtt / 1000;
+ /* compute rtt in ms */
+ rtt = (int32_t)(net->rtt / 1000);
if ((asoc->cc_functions.sctp_rtt_calculated) && (rtt_from_sack == SCTP_RTT_FROM_DATA)) {
/* Tell the CC module that a new update has just occurred from a sack */
(*asoc->cc_functions.sctp_rtt_calculated)(stcb, net, &now);
diff --git a/user_route.h b/user_route.h
index d0841d7..82b07d7 100755
--- a/user_route.h
+++ b/user_route.h
@@ -54,7 +54,7 @@ struct sctp_route {
* retransmission behavior and are included in the routing structure.
*/
struct sctp_rt_metrics_lite {
- u_long rmx_mtu; /* MTU for this path */
+ uint32_t rmx_mtu; /* MTU for this path */
#if 0
u_long rmx_expire; /* lifetime for route, e.g. redirect */
u_long rmx_pksent; /* packets sent using this route */
diff --git a/user_sctp_timer_iterate.c b/user_sctp_timer_iterate.c
deleted file mode 100755
index 0a9dbce..0000000
--- a/user_sctp_timer_iterate.c
+++ /dev/null
@@ -1,119 +0,0 @@
-/*-
- * Copyright (c) 2012 Michael Tuexen
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- */
-
-#include <sys/types.h>
-#if !defined (__Userspace_os_Windows)
-#include <sys/wait.h>
-#include <unistd.h>
-#include <pthread.h>
-#endif
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-#include <netinet/sctp_pcb.h>
-#include <netinet/sctp_sysctl.h>
-#include "netinet/sctp_callout.h"
-
-/* This is the polling time of callqueue in milliseconds
- * 10ms seems to work well. 1ms was giving erratic behavior
- */
-#define TIMEOUT_INTERVAL 10
-
-extern int ticks;
-
-void *
-user_sctp_timer_iterate(void *arg)
-{
- sctp_os_timer_t *c;
- void (*c_func)(void *);
- void *c_arg;
- sctp_os_timer_t *sctp_os_timer_next;
- /*
- * The MSEC_TO_TICKS conversion depends on hz. The to_ticks in
- * sctp_os_timer_start also depends on hz. E.g. if hz=1000 then
- * for multiple INIT the to_ticks is 2000, 4000, 8000, 16000, 32000, 60000
- * and further to_ticks level off at 60000 i.e. 60 seconds.
- * If hz=100 then for multiple INIT the to_ticks are 200, 400, 800 and so-on.
- */
- for (;;) {
-#if defined (__Userspace_os_Windows)
- Sleep(TIMEOUT_INTERVAL);
-#else
- struct timeval timeout;
-
- timeout.tv_sec = 0;
- timeout.tv_usec = 1000 * TIMEOUT_INTERVAL;
- select(0, NULL, NULL, NULL, &timeout);
-#endif
- if (SCTP_BASE_VAR(timer_thread_should_exit)) {
- break;
- }
- SCTP_TIMERQ_LOCK();
- /* update our tick count */
- ticks += MSEC_TO_TICKS(TIMEOUT_INTERVAL);
- c = TAILQ_FIRST(&SCTP_BASE_INFO(callqueue));
- while (c) {
- if (c->c_time <= ticks) {
- sctp_os_timer_next = TAILQ_NEXT(c, tqe);
- TAILQ_REMOVE(&SCTP_BASE_INFO(callqueue), c, tqe);
- c_func = c->c_func;
- c_arg = c->c_arg;
- c->c_flags &= ~SCTP_CALLOUT_PENDING;
- SCTP_TIMERQ_UNLOCK();
- c_func(c_arg);
- SCTP_TIMERQ_LOCK();
- c = sctp_os_timer_next;
- } else {
- c = TAILQ_NEXT(c, tqe);
- }
- }
- SCTP_TIMERQ_UNLOCK();
- }
- return (NULL);
-}
-
-void
-sctp_start_timer(void)
-{
- /*
- * No need to do SCTP_TIMERQ_LOCK_INIT();
- * here, it is being done in sctp_pcb_init()
- */
-#if defined (__Userspace_os_Windows)
- if ((SCTP_BASE_VAR(timer_thread) = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)user_sctp_timer_iterate, NULL, 0, NULL)) == NULL) {
- SCTP_PRINTF("ERROR; Creating ithread failed\n");
- }
-#else
- int rc;
-
- rc = pthread_create(&SCTP_BASE_VAR(timer_thread), NULL, user_sctp_timer_iterate, NULL);
- if (rc) {
- SCTP_PRINTF("ERROR; return code from pthread_create() is %d\n", rc);
- }
-#endif
-}
diff --git a/user_socket.c b/user_socket.c
index 9a0e0c7..d92aac6 100755
--- a/user_socket.c
+++ b/user_socket.c
@@ -1380,7 +1380,7 @@ sbreserve_locked(struct sockbuf *sb, u_long cc, struct socket *so)
{
SOCKBUF_LOCK_ASSERT(sb);
sb->sb_mbmax = (u_int)min(cc * sb_efficiency, sb_max);
- sb->sb_hiwat = cc;
+ sb->sb_hiwat = (u_int)cc;
if (sb->sb_lowat > (int)sb->sb_hiwat)
sb->sb_lowat = (int)sb->sb_hiwat;
return (1);
@@ -2449,7 +2449,7 @@ usrsctp_bindx(struct socket *so, struct sockaddr *addrs, int addrcnt, int flags)
for (i = 0; i < addrcnt; i++) {
#ifndef HAVE_SA_LEN
size_t sa_len;
-#endif
+#endif
memset(gaddrs, 0, argsz);
gaddrs->sget_assoc_id = 0;
#ifdef HAVE_SA_LEN
@@ -2987,7 +2987,7 @@ void sctp_userspace_ip6_output(int *result, struct mbuf *o_pak,
memset((void *)&dst, 0, sizeof(struct sockaddr_in6));
dst.sin6_family = AF_INET6;
dst.sin6_addr = ip6->ip6_dst;
-#ifdef HAVE_SIN6_LEN
+#ifdef HAVE_SIN6_LEN
dst.sin6_len = sizeof(struct sockaddr_in6);
#endif
@@ -3157,7 +3157,7 @@ usrsctp_dumppacket(void *buf, size_t len, int outbound)
strncpy_s(dump_buf + pos, strlen(HEADER) + 1, HEADER, strlen(HEADER));
#else
strcpy(dump_buf + pos, HEADER);
-#endif
+#endif
pos += strlen(HEADER);
packet = (char *)buf;
for (i = 0; i < len; i++) {
diff --git a/user_socketvar.h b/user_socketvar.h
index dd4ff10..5c3d9ee 100755
--- a/user_socketvar.h
+++ b/user_socketvar.h
@@ -42,7 +42,7 @@
/* #include <sys/_lock.h> was 0 byte file */
/* #include <sys/_mutex.h> was 0 byte file */
/* #include <sys/_sx.h> */ /*__Userspace__ alternative?*/
-#if !defined(__Userspace_os_DragonFly) && !defined(__Userspace_os_FreeBSD) && !defined(__Userspace_os_NetBSD) && !defined(__Userspace_os_Windows)
+#if !defined(__Userspace_os_DragonFly) && !defined(__Userspace_os_FreeBSD) && !defined(__Userspace_os_NetBSD) && !defined(__Userspace_os_Windows) && !defined(__Userspace_os_NaCl)
#include <sys/uio.h>
#endif
#define SOCK_MAXADDRLEN 255
@@ -54,7 +54,7 @@
#define SS_CANTRCVMORE 0x020
#define SS_CANTSENDMORE 0x010
-#if defined(__Userspace_os_Darwin) || defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_OpenBSD) || defined (__Userspace_os_Windows)
+#if defined(__Userspace_os_Darwin) || defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_OpenBSD) || defined (__Userspace_os_Windows) || defined(__Userspace_os_NaCl)
#define UIO_MAXIOV 1024
#define ERESTART (-1)
#endif