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 
45 
46 #ifndef ERR_H
47 #define ERR_H
48 
49 #include "datatypes.h"
50 
51 /**
52  * @defgroup Error Error Codes
53  *
54  * Error status codes are represented by the enumeration err_status_t.
55  *
56  * @{
57  */
58 
59 
60 /*
61  * @brief err_status_t defines error codes.
62  *
63  * The enumeration err_status_t defines error codes.  Note that the
64  * value of err_status_ok is equal to zero, which can simplify error
65  * checking somewhat.
66  *
67  */
68 typedef enum {
69   err_status_ok           = 0,  /**< nothing to report                       */
70   err_status_fail         = 1,  /**< unspecified failure                     */
71   err_status_bad_param    = 2,  /**< unsupported parameter                   */
72   err_status_alloc_fail   = 3,  /**< couldn't allocate memory                */
73   err_status_dealloc_fail = 4,  /**< couldn't deallocate properly            */
74   err_status_init_fail    = 5,  /**< couldn't initialize                     */
75   err_status_terminus     = 6,  /**< can't process as much data as requested */
76   err_status_auth_fail    = 7,  /**< authentication failure                  */
77   err_status_cipher_fail  = 8,  /**< cipher failure                          */
78   err_status_replay_fail  = 9,  /**< replay check failed (bad index)         */
79   err_status_replay_old   = 10, /**< replay check failed (index too old)     */
80   err_status_algo_fail    = 11, /**< algorithm failed test routine           */
81   err_status_no_such_op   = 12, /**< unsupported operation                   */
82   err_status_no_ctx       = 13, /**< no appropriate context found            */
83   err_status_cant_check   = 14, /**< unable to perform desired validation    */
84   err_status_key_expired  = 15, /**< can't use key any more                  */
85   err_status_socket_err   = 16, /**< error in use of socket                  */
86   err_status_signal_err   = 17, /**< error in use POSIX signals              */
87   err_status_nonce_bad    = 18, /**< nonce check failed                      */
88   err_status_read_fail    = 19, /**< couldn't read data                      */
89   err_status_write_fail   = 20, /**< couldn't write data                     */
90   err_status_parse_err    = 21, /**< error pasring data                      */
91   err_status_encode_err   = 22, /**< error encoding data                     */
92   err_status_semaphore_err = 23,/**< error while using semaphores            */
93   err_status_pfkey_err    = 24  /**< error while using pfkey                 */
94 } err_status_t;
95 
96 /**
97  * @}
98  */
99 
100 typedef enum {
101   err_level_emergency = 0,
102   err_level_alert,
103   err_level_critical,
104   err_level_error,
105   err_level_warning,
106   err_level_notice,
107   err_level_info,
108   err_level_debug,
109   err_level_none
110 } err_reporting_level_t;
111 
112 /*
113  * err_reporting_init prepares the error system.  If
114  * ERR_REPORTING_SYSLOG is defined, it will open syslog.
115  *
116  * The ident argument is a string that will be prepended to
117  * all syslog messages.  It is conventionally argv[0].
118  */
119 
120 err_status_t
121 err_reporting_init(char *ident);
122 
123 #ifdef SRTP_KERNEL_LINUX
124 extern err_reporting_level_t err_level;
125 #else
126 
127 /*
128  * keydaemon_report_error reports a 'printf' formatted error
129  * string, followed by a an arg list.  The priority argument
130  * is equivalent to that defined for syslog.
131  *
132  * Errors will be reported to ERR_REPORTING_FILE, if defined, and to
133  * syslog, if ERR_REPORTING_SYSLOG is defined.
134  *
135  */
136 
137 void
138 err_report(int priority, char *format, ...);
139 #endif /* ! SRTP_KERNEL_LINUX */
140 
141 
142 /*
143  * debug_module_t defines a debug module
144  */
145 
146 typedef struct {
147   int   on;          /* 1 if debugging is on, 0 if it is off */
148   char *name;        /* printable name for debug module      */
149 } debug_module_t;
150 
151 #ifdef ENABLE_DEBUGGING
152 
153 #define debug_on(mod)  (mod).on = 1
154 
155 #define debug_off(mod) (mod).on = 0
156 
157 /* use err_report() to report debug message */
158 #define debug_print(mod, format, arg)                  \
159   if (mod.on) err_report(err_level_debug, ("%s: " format "\n"), mod.name, arg)
160 #define debug_print2(mod, format, arg1,arg2)                  \
161   if (mod.on) err_report(err_level_debug, ("%s: " format "\n"), mod.name, arg1,arg2)
162 
163 #else
164 
165 /* define macros to do nothing */
166 #define debug_print(mod, format, arg)
167 
168 #define debug_on(mod)
169 
170 #define debug_off(mod)
171 
172 #endif
173 
174 #endif /* ERR_H */
175