err.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * err.h
  3. *
  4. * error status codes
  5. *
  6. * David A. McGrew
  7. * Cisco Systems, Inc.
  8. */
  9. /*
  10. *
  11. * Copyright (c) 2001-2006, Cisco Systems, Inc.
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions
  16. * are met:
  17. *
  18. * Redistributions of source code must retain the above copyright
  19. * notice, this list of conditions and the following disclaimer.
  20. *
  21. * Redistributions in binary form must reproduce the above
  22. * copyright notice, this list of conditions and the following
  23. * disclaimer in the documentation and/or other materials provided
  24. * with the distribution.
  25. *
  26. * Neither the name of the Cisco Systems, Inc. nor the names of its
  27. * contributors may be used to endorse or promote products derived
  28. * from this software without specific prior written permission.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  33. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  34. * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  35. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  36. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  37. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  41. * OF THE POSSIBILITY OF SUCH DAMAGE.
  42. *
  43. */
  44. #ifndef ERR_H
  45. #define ERR_H
  46. #include "datatypes.h"
  47. /**
  48. * @defgroup Error Error Codes
  49. *
  50. * Error status codes are represented by the enumeration err_status_t.
  51. *
  52. * @{
  53. */
  54. /*
  55. * @brief err_status_t defines error codes.
  56. *
  57. * The enumeration err_status_t defines error codes. Note that the
  58. * value of err_status_ok is equal to zero, which can simplify error
  59. * checking somewhat.
  60. *
  61. */
  62. typedef enum {
  63. err_status_ok = 0, /**< nothing to report */
  64. err_status_fail = 1, /**< unspecified failure */
  65. err_status_bad_param = 2, /**< unsupported parameter */
  66. err_status_alloc_fail = 3, /**< couldn't allocate memory */
  67. err_status_dealloc_fail = 4, /**< couldn't deallocate properly */
  68. err_status_init_fail = 5, /**< couldn't initialize */
  69. err_status_terminus = 6, /**< can't process as much data as requested */
  70. err_status_auth_fail = 7, /**< authentication failure */
  71. err_status_cipher_fail = 8, /**< cipher failure */
  72. err_status_replay_fail = 9, /**< replay check failed (bad index) */
  73. err_status_replay_old = 10, /**< replay check failed (index too old) */
  74. err_status_algo_fail = 11, /**< algorithm failed test routine */
  75. err_status_no_such_op = 12, /**< unsupported operation */
  76. err_status_no_ctx = 13, /**< no appropriate context found */
  77. err_status_cant_check = 14, /**< unable to perform desired validation */
  78. err_status_key_expired = 15, /**< can't use key any more */
  79. err_status_socket_err = 16, /**< error in use of socket */
  80. err_status_signal_err = 17, /**< error in use POSIX signals */
  81. err_status_nonce_bad = 18, /**< nonce check failed */
  82. err_status_read_fail = 19, /**< couldn't read data */
  83. err_status_write_fail = 20, /**< couldn't write data */
  84. err_status_parse_err = 21, /**< error parsing data */
  85. err_status_encode_err = 22, /**< error encoding data */
  86. err_status_semaphore_err = 23,/**< error while using semaphores */
  87. err_status_pfkey_err = 24 /**< error while using pfkey */
  88. } err_status_t;
  89. /**
  90. * @}
  91. */
  92. typedef enum {
  93. err_level_emergency = 0,
  94. err_level_alert,
  95. err_level_critical,
  96. err_level_error,
  97. err_level_warning,
  98. err_level_notice,
  99. err_level_info,
  100. err_level_debug,
  101. err_level_none
  102. } err_reporting_level_t;
  103. /*
  104. * err_reporting_init prepares the error system. If
  105. * ERR_REPORTING_SYSLOG is defined, it will open syslog.
  106. *
  107. * The ident argument is a string that will be prepended to
  108. * all syslog messages. It is conventionally argv[0].
  109. */
  110. err_status_t
  111. err_reporting_init(char *ident);
  112. #ifdef SRTP_KERNEL_LINUX
  113. extern err_reporting_level_t err_level;
  114. #else
  115. /*
  116. * keydaemon_report_error reports a 'printf' formatted error
  117. * string, followed by a an arg list. The priority argument
  118. * is equivalent to that defined for syslog.
  119. *
  120. * Errors will be reported to ERR_REPORTING_FILE, if defined, and to
  121. * syslog, if ERR_REPORTING_SYSLOG is defined.
  122. *
  123. */
  124. void
  125. err_report(int priority, char *format, ...);
  126. #endif /* ! SRTP_KERNEL_LINUX */
  127. /*
  128. * debug_module_t defines a debug module
  129. */
  130. typedef struct {
  131. int on; /* 1 if debugging is on, 0 if it is off */
  132. char *name; /* printable name for debug module */
  133. } debug_module_t;
  134. #ifdef ENABLE_DEBUGGING
  135. #define debug_on(mod) (mod).on = 1
  136. #define debug_off(mod) (mod).on = 0
  137. /* use err_report() to report debug message */
  138. #define debug_print(mod, format, arg) \
  139. if (mod.on) err_report(err_level_debug, ("%s: " format "\n"), mod.name, arg)
  140. #define debug_print2(mod, format, arg1,arg2) \
  141. if (mod.on) err_report(err_level_debug, ("%s: " format "\n"), mod.name, arg1,arg2)
  142. #else
  143. /* define macros to do nothing */
  144. #define debug_print(mod, format, arg)
  145. #define debug_on(mod)
  146. #define debug_off(mod)
  147. #endif
  148. #endif /* ERR_H */