netwerk/sctp/src/user_environment.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/sctp/src/user_environment.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,96 @@
     1.4 +/*-
     1.5 + * Copyright (c) 2009-2010 Brad Penoff
     1.6 + * Copyright (c) 2009-2010 Humaira Kamal
     1.7 + * Copyright (c) 2011-2012 Irene Ruengeler
     1.8 + * Copyright (c) 2011-2012 Michael Tuexen
     1.9 + *
    1.10 + * All rights reserved.
    1.11 + *
    1.12 + * Redistribution and use in source and binary forms, with or without
    1.13 + * modification, are permitted provided that the following conditions
    1.14 + * are met:
    1.15 + * 1. Redistributions of source code must retain the above copyright
    1.16 + *    notice, this list of conditions and the following disclaimer.
    1.17 + * 2. Redistributions in binary form must reproduce the above copyright
    1.18 + *    notice, this list of conditions and the following disclaimer in the
    1.19 + *    documentation and/or other materials provided with the distribution.
    1.20 + *
    1.21 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
    1.22 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.23 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.24 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
    1.25 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    1.26 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    1.27 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    1.28 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    1.29 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    1.30 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    1.31 + * SUCH DAMAGE.
    1.32 + */
    1.33 +
    1.34 +/* __Userspace__ */
    1.35 +
    1.36 +#include <stdlib.h>
    1.37 +#if !defined (__Userspace_os_Windows)
    1.38 +#include <stdint.h>
    1.39 +#include <netinet/sctp_os_userspace.h>
    1.40 +#endif
    1.41 +#include <user_environment.h>
    1.42 +#include <sys/types.h>
    1.43 +/* #include <sys/param.h> defines MIN */
    1.44 +#if !defined(MIN)
    1.45 +#define MIN(arg1,arg2) ((arg1) < (arg2) ? (arg1) : (arg2))
    1.46 +#endif
    1.47 +#include <string.h>
    1.48 +
    1.49 +#define uHZ 1000
    1.50 +
    1.51 +/* See user_include/user_environment.h for comments about these variables */
    1.52 +int maxsockets = 25600;
    1.53 +int hz = uHZ;
    1.54 +int ip_defttl = 64;
    1.55 +int ipport_firstauto = 49152, ipport_lastauto = 65535;
    1.56 +int nmbclusters = 65536;
    1.57 +
    1.58 +/* Source ip_output.c. extern'd in ip_var.h */
    1.59 +u_short ip_id = 0; /*__Userspace__ TODO Should it be initialized to zero? */
    1.60 +
    1.61 +/* used in user_include/user_atomic.h in order to make the operations
    1.62 + * defined there truly atomic
    1.63 + */
    1.64 +userland_mutex_t atomic_mtx;
    1.65 +
    1.66 +/* Source: /usr/src/sys/dev/random/harvest.c */
    1.67 +static int read_random_phony(void *, int);
    1.68 +
    1.69 +static int (*read_func)(void *, int) = read_random_phony;
    1.70 +
    1.71 +/* Userland-visible version of read_random */
    1.72 +int
    1.73 +read_random(void *buf, int count)
    1.74 +{
    1.75 +	return ((*read_func)(buf, count));
    1.76 +}
    1.77 +
    1.78 +/* If the entropy device is not loaded, make a token effort to
    1.79 + * provide _some_ kind of randomness. This should only be used
    1.80 + * inside other RNG's, like arc4random(9).
    1.81 + */
    1.82 +static int
    1.83 +read_random_phony(void *buf, int count)
    1.84 +{
    1.85 +	uint32_t randval;
    1.86 +	int size, i;
    1.87 +
    1.88 +	/* srandom() is called in kern/init_main.c:proc0_post() */
    1.89 +
    1.90 +	/* Fill buf[] with random(9) output */
    1.91 +	for (i = 0; i < count; i+= (int)sizeof(uint32_t)) {
    1.92 +		randval = random();
    1.93 +		size = MIN(count - i, (int)sizeof(uint32_t));
    1.94 +		memcpy(&((char *)buf)[i], &randval, (size_t)size);
    1.95 +	}
    1.96 +
    1.97 +	return (count);
    1.98 +}
    1.99 +

mercurial