2 * Copyright (c) 2009-2010 Brad Penoff
3 * Copyright (c) 2009-2010 Humaira Kamal
4 * Copyright (c) 2011-2012 Irene Ruengeler
5 * Copyright (c) 2011-2012 Michael Tuexen
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <netinet/sctp_os_userspace.h>
38 #include <user_environment.h>
39 #include <sys/types.h>
40 /* #include <sys/param.h> defines MIN */
42 #define MIN(arg1,arg2) ((arg1) < (arg2) ? (arg1) : (arg2))
48 /* See user_include/user_environment.h for comments about these variables */
49 int maxsockets = 25600;
52 int ipport_firstauto = 49152, ipport_lastauto = 65535;
53 int nmbclusters = 65536;
55 /* Source ip_output.c. extern'd in ip_var.h */
56 u_short ip_id = 0; /*__Userspace__ TODO Should it be initialized to zero? */
58 /* used in user_include/user_atomic.h in order to make the operations
59 * defined there truly atomic
61 userland_mutex_t atomic_mtx;
63 /* If the entropy device is not loaded, make a token effort to
64 * provide _some_ kind of randomness. This should only be used
65 * inside other RNG's, like arc4random(9).
67 #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
75 read_random(void *buf, int count)
77 memset(buf, 'A', count);
80 #elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
88 read_random(void *buf, int count)
91 arc4random_buf(buf, count);
102 (void)SCTP_GETTIME_TIMEVAL(&now);
104 seed |= (unsigned int)now.tv_sec;
105 seed |= (unsigned int)now.tv_usec;
106 #if !defined(_WIN32) &&! defined(__native_client__)
109 #if defined(_WIN32) || defined(__native_client__)
118 read_random(void *buf, int count)
123 /* Fill buf[] with random(9) output */
124 for (i = 0; i < count; i+= (int)sizeof(uint32_t)) {
126 size = MIN(count - i, (int)sizeof(uint32_t));
127 memcpy(&((char *)buf)[i], &randval, (size_t)size);