user_environment.h 3.9 KB

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