| 1 |
/*- |
| 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 |
| 6 |
* |
| 7 |
* All rights reserved. |
| 8 |
* |
| 9 |
* Redistribution and use in source and binary forms, with or without |
| 10 |
* modification, are permitted provided that the following conditions |
| 11 |
* are met: |
| 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. |
| 17 |
* |
| 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 |
| 28 |
* SUCH DAMAGE. |
| 29 |
*/ |
| 30 |
|
| 31 |
#ifndef _USER_ENVIRONMENT_H_ |
| 32 |
#define _USER_ENVIRONMENT_H_ |
| 33 |
/* __Userspace__ */ |
| 34 |
#include <sys/types.h> |
| 35 |
|
| 36 |
#ifdef __FreeBSD__ |
| 37 |
#ifndef _SYS_MUTEX_H_ |
| 38 |
#include <sys/mutex.h> |
| 39 |
#endif |
| 40 |
#endif |
| 41 |
#if defined(_WIN32) |
| 42 |
#include "netinet/sctp_os_userspace.h" |
| 43 |
#endif |
| 44 |
|
| 45 |
/* maxsockets is used in SCTP_ZONE_INIT call. It refers to |
| 46 |
* kern.ipc.maxsockets kernel environment variable. |
| 47 |
*/ |
| 48 |
extern int maxsockets; |
| 49 |
|
| 50 |
/* int hz; is declared in sys/kern/subr_param.c and refers to kernel timer frequency. |
| 51 |
* See http://ivoras.sharanet.org/freebsd/vmware.html for additional info about kern.hz |
| 52 |
* hz is initialized in void init_param1(void) in that file. |
| 53 |
*/ |
| 54 |
extern int hz; |
| 55 |
|
| 56 |
|
| 57 |
/* The following two ints define a range of available ephemeral ports. */ |
| 58 |
extern int ipport_firstauto, ipport_lastauto; |
| 59 |
|
| 60 |
/* nmbclusters is used in sctp_usrreq.c (e.g., sctp_init). In the FreeBSD kernel, |
| 61 |
* this is 1024 + maxusers * 64. |
| 62 |
*/ |
| 63 |
extern int nmbclusters; |
| 64 |
|
| 65 |
#if !defined(_MSC_VER) && !defined(__MINGW32__) |
| 66 |
#define min(a,b) (((a)>(b))?(b):(a)) |
| 67 |
#define max(a,b) (((a)>(b))?(a):(b)) |
| 68 |
#endif |
| 69 |
|
| 70 |
void init_random(void); |
| 71 |
int read_random(void *, int); |
| 72 |
|
| 73 |
/* errno's may differ per OS. errno.h now included in sctp_os_userspace.h */ |
| 74 |
/* Source: /usr/src/sys/sys/errno.h */ |
| 75 |
/* #define ENOSPC 28 */ /* No space left on device */ |
| 76 |
/* #define ENOBUFS 55 */ /* No buffer space available */ |
| 77 |
/* #define ENOMEM 12 */ /* Cannot allocate memory */ |
| 78 |
/* #define EACCES 13 */ /* Permission denied */ |
| 79 |
/* #define EFAULT 14 */ /* Bad address */ |
| 80 |
/* #define EHOSTDOWN 64 */ /* Host is down */ |
| 81 |
/* #define EHOSTUNREACH 65 */ /* No route to host */ |
| 82 |
|
| 83 |
/* Source ip_output.c. extern'd in ip_var.h */ |
| 84 |
extern u_short ip_id; |
| 85 |
|
| 86 |
#if defined(__linux__) |
| 87 |
#define IPV6_VERSION 0x60 |
| 88 |
#endif |
| 89 |
|
| 90 |
#if defined(INVARIANTS) |
| 91 |
#include <stdlib.h> |
| 92 |
|
| 93 |
static inline void |
| 94 |
terminate_non_graceful(void) { |
| 95 |
abort(); |
| 96 |
} |
| 97 |
|
| 98 |
#define panic(...) \ |
| 99 |
do { \ |
| 100 |
SCTP_PRINTF("%s(): ", __func__); \ |
| 101 |
SCTP_PRINTF(__VA_ARGS__); \ |
| 102 |
SCTP_PRINTF("\n"); \ |
| 103 |
terminate_non_graceful(); \ |
| 104 |
} while (0) |
| 105 |
|
| 106 |
#define KASSERT(cond, args) \ |
| 107 |
do { \ |
| 108 |
if (!(cond)) { \ |
| 109 |
panic args ; \ |
| 110 |
} \ |
| 111 |
} while (0) |
| 112 |
#else |
| 113 |
#define KASSERT(cond, args) |
| 114 |
#endif |
| 115 |
|
| 116 |
/* necessary for sctp_pcb.c */ |
| 117 |
extern int ip_defttl; |
| 118 |
#endif |