- fixed bad bugs in kernel interface
[strongswan.git] / Source / lib / definitions.h
1 /**
2 * @file definitions.h
3 *
4 * @brief General purpose definitions and macros.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 * Copyright (C) 1998, 1999 D. Hugh Redelmeier. (Endian stuff)
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
22 */
23
24 #ifndef DEFINITIONS_H_
25 #define DEFINITIONS_H_
26
27
28
29 /* stolen from strongswan */
30 #if linux
31 # if defined(i386) && !defined(__i386__)
32 # define __i386__ 1
33 # define MYHACKFORTHIS 1
34 # endif
35 # include <endian.h>
36 # ifdef MYHACKFORTHIS
37 # undef __i386__
38 # undef MYHACKFORTHIS
39 # endif
40 #elif !(defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN) && defined(BYTE_ORDER))
41 /* we don't know how to do this, so we require the macros to be defined
42 * with compiler flags:
43 * -DBIG_ENDIAN=4321 -DLITTLE_ENDIAN=1234 -DBYTE_ORDER=BIG_ENDIAN
44 * or -DBIG_ENDIAN=4321 -DLITTLE_ENDIAN=1234 -DBYTE_ORDER=LITTLE_ENDIAN
45 * Thse match the GNU definitions
46 */
47 # include <sys/endian.h>
48 #endif
49
50 #ifndef BIG_ENDIAN
51 #error "BIG_ENDIAN must be defined"
52 #endif
53
54 #ifndef LITTLE_ENDIAN
55 #error "LITTLE_ENDIAN must be defined"
56 #endif
57
58 #ifndef BYTE_ORDER
59 #error "BYTE_ORDER must be defined"
60 #endif
61
62
63
64 /**
65 * @defgroup config config
66 *
67 * Classes implementing configuration related things.
68 */
69
70 /**
71 * @defgroup encoding encoding
72 *
73 * Classes used to encode and decode IKEv2 messages.
74 */
75
76 /**
77 * @defgroup network network
78 *
79 * Classes for network relevant stuff.
80 */
81
82 /**
83 * @defgroup payloads payloads
84 *
85 * Classes representing specific IKEv2 payloads.
86 *
87 * @ingroup encoding
88 */
89
90 /**
91 * @defgroup sa sa
92 *
93 * Security association and helper classes.
94 */
95
96
97 /**
98 * @defgroup states states
99 *
100 * Varius states in which an IKE SA can be.
101 *
102 * @ingroup sa
103 */
104
105 /**
106 * @defgroup queues queues
107 *
108 * Different kind of queues.
109 */
110
111 /**
112 * @defgroup jobs jobs
113 *
114 * Jobs used in job queue and event queue.
115 *
116 * @ingroup queues
117 */
118
119 /**
120 * @defgroup testcases testcases
121 *
122 * Testcases used to test the different classes in seperate module tests.
123 */
124
125 /**
126 * @defgroup transforms transforms
127 *
128 * Transform algorithms of different kind.
129 */
130
131 /**
132 * @defgroup rsa rsa
133 *
134 * RSA public key algorithm.
135 *
136 * @ingroup transforms
137 */
138
139 /**
140 * @defgroup prfs prfs
141 *
142 * Pseudo random functions.
143 *
144 * @ingroup transforms
145 */
146
147 /**
148 * @defgroup signers signers
149 *
150 * Symmetric signing algorithms, used to ensure message integrity.
151 *
152 * @ingroup transforms
153 */
154
155 /**
156 * @defgroup crypters crypters
157 *
158 * Symmetric encryption algorithms, used to encrypt and decrypt.
159 *
160 * @ingroup transforms
161 */
162
163 /**
164 * @defgroup hashers hashers
165 *
166 * Hashing algorithms.
167 *
168 * @ingroup transforms
169 */
170 /**
171 * @defgroup asn1 asn1
172 *
173 * ASN1 structure definition, en-/decoder of for DER
174 *
175 * @todo Implement a der_encoder_t class.
176 */
177
178 /**
179 * @defgroup utils utils
180 *
181 * Generic helper classes.
182 */
183
184 /**
185 * @defgroup threads threads
186 *
187 * Threaded classes, which will do their job alone.
188 */
189
190 /**
191 * Macro gives back larger of two values.
192 */
193 #define max(x,y) (x > y ? x : y)
194
195 /**
196 * Macro gives back smaller of two values.
197 */
198 #define min(x,y) (x < y ? x : y)
199
200 /**
201 * Debug macro to follow control flow
202 */
203 #define POS printf("%s, line %d\n", __FILE__, __LINE__)
204
205
206
207
208 /**
209 * Macro to allocate a type as chunk_t.
210 *
211 * @param thing object on which a sizeof is performed
212 * @return chunk_t pointing to allocated memory
213 */
214 #define malloc_thing(thing) ((thing*)malloc(sizeof(thing)))
215
216
217
218
219
220
221 /**
222 * Mapping entry which defines the end of a mapping_t array.
223 */
224 #define MAPPING_END (-1)
225
226 typedef struct mapping_t mapping_t;
227
228 /**
229 * @brief Mapping entry, where enum-to-string mappings are stored.
230 */
231 struct mapping_t
232 {
233 /**
234 * Enumeration value.
235 */
236 int value;
237
238 /**
239 * Mapped string.
240 */
241 char *string;
242 };
243
244
245 /**
246 * @brief Find a mapping_string in the mapping[].
247 *
248 * @param mappings mappings array
249 * @param value enum-value to get the string from
250 *
251 */
252 char *mapping_find(mapping_t *mappings, int value);
253
254 #endif /*DEFINITIONS_H_*/