]> git.ipfire.org Git - people/ms/strongswan.git/blob - src/charon/encoding/payloads/encodings.h
(no commit message)
[people/ms/strongswan.git] / src / charon / encoding / payloads / encodings.h
1 /**
2 * @file encodings.h
3 *
4 * @brief Definition of encoding_type_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #ifndef ENCODINGS_H_
24 #define ENCODINGS_H_
25
26 #include <types.h>
27 #include <definitions.h>
28
29
30 typedef enum encoding_type_t encoding_type_t;
31
32 /**
33 * @brief All different kinds of encoding types.
34 *
35 * Each field of an IKEv2-Message (in header or payload)
36 * which has to be parsed or generated differently has its own
37 * type defined here.
38 *
39 * Header is parsed like a payload and gets its one payload_id
40 * from PRIVATE USE space. Also the substructures
41 * of specific payload types get their own payload_id
42 * from PRIVATE_USE space. See IKEv2-Draft for more informations.
43 *
44 * @ingroup payloads
45 */
46 enum encoding_type_t {
47
48 /**
49 * Representing a 4 Bit unsigned int value.
50 *
51 *
52 * When generating it must be changed from host to network order.
53 * The value is read from the associated data struct.
54 * The current write position is moved 4 bit forward afterwards.
55 *
56 * When parsing it must be changed from network to host order.
57 * The value is written to the associated data struct.
58 * The current read pointer is moved 4 bit forward afterwards.
59 */
60 U_INT_4,
61
62 /**
63 * Representing a 8 Bit unsigned int value.
64 *
65 *
66 * When generating it must be changed from host to network order.
67 * The value is read from the associated data struct.
68 * The current write position is moved 8 bit forward afterwards.
69 *
70 * When parsing it must be changed from network to host order.
71 * The value is written to the associated data struct.
72 * The current read pointer is moved 8 bit forward afterwards.
73 */
74 U_INT_8,
75
76 /**
77 * Representing a 16 Bit unsigned int value.
78 *
79 *
80 * When generating it must be changed from host to network order.
81 * The value is read from the associated data struct.
82 * The current write position is moved 16 bit forward afterwards.
83 *
84 * When parsing it must be changed from network to host order.
85 * The value is written to the associated data struct.
86 * The current read pointer is moved 16 bit forward afterwards.
87 */
88 U_INT_16,
89
90 /**
91 * Representing a 32 Bit unsigned int value.
92 *
93 * When generating it must be changed from host to network order.
94 * The value is read from the associated data struct.
95 * The current write position is moved 32 bit forward afterwards.
96 *
97 * When parsing it must be changed from network to host order.
98 * The value is written to the associated data struct.
99 * The current read pointer is moved 32 bit forward afterwards.
100 */
101 U_INT_32,
102
103 /**
104 * Representing a 64 Bit unsigned int value.
105 *
106 * When generating it must be changed from host to network order.
107 * The value is read from the associated data struct.
108 * The current write position is moved 64 bit forward afterwards.
109 *
110 * When parsing it must be changed from network to host order.
111 * The value is written to the associated data struct.
112 * The current read pointer is moved 64 bit forward afterwards.
113 */
114 U_INT_64,
115
116 /**
117 * @brief represents a RESERVED_BIT used in FLAG-Bytes.
118 *
119 * When generating, the next bit is set to zero and the current write
120 * position is moved one bit forward.
121 * No value is read from the associated data struct.
122 * The current write position is moved 1 bit forward afterwards.
123 *
124 * When parsing, the current read pointer is moved one bit forward.
125 * No value is written to the associated data struct.
126 * The current read pointer is moved 1 bit forward afterwards.
127 */
128 RESERVED_BIT,
129
130 /**
131 * @brief represents a RESERVED_BYTE.
132 *
133 * When generating, the next byte is set to zero and the current write
134 * position is moved one byte forward.
135 * No value is read from the associated data struct.
136 * The current write position is moved 1 byte forward afterwards.
137 *
138 * When parsing, the current read pointer is moved one byte forward.
139 * No value is written to the associated data struct.
140 * The current read pointer is moved 1 byte forward afterwards.
141 */
142 RESERVED_BYTE,
143
144 /**
145 * Representing a 1 Bit flag.
146 *
147 * When generation, the next bit is set to 1 if the associated value
148 * in the data struct is TRUE, 0 otherwise. The current write position
149 * is moved 1 bit forward afterwards.
150 *
151 * When parsing, the next bit is read and stored in the associated data
152 * struct. 0 means FALSE, 1 means TRUE, The current read pointer
153 * is moved 1 bit forward afterwards
154 */
155 FLAG,
156
157 /**
158 * Representating a length field of a payload.
159 *
160 * When generating it must be changed from host to network order.
161 * The value is read from the associated data struct.
162 * The current write position is moved 16 bit forward afterwards.
163 *
164 * When parsing it must be changed from network to host order.
165 * The value is written to the associated data struct.
166 * The current read pointer is moved 16 bit forward afterwards.
167 */
168 PAYLOAD_LENGTH,
169
170 /**
171 * Representating a length field of a header.
172 *
173 * When generating it must be changed from host to network order.
174 * The value is read from the associated data struct.
175 * The current write position is moved 32 bit forward afterwards.
176 *
177 * When parsing it must be changed from network to host order.
178 * The value is written to the associated data struct.
179 * The current read pointer is moved 32 bit forward afterwards.
180 */
181 HEADER_LENGTH,
182
183 /**
184 * Representating a spi size field.
185 *
186 * When generating it must be changed from host to network order.
187 * The value is read from the associated data struct.
188 * The current write position is moved 8 bit forward afterwards.
189 *
190 * When parsing it must be changed from network to host order.
191 * The value is written to the associated data struct.
192 * The current read pointer is moved 8 bit forward afterwards.
193 */
194 SPI_SIZE,
195
196 /**
197 * Representating a spi field.
198 *
199 * When generating the content of the chunkt pointing to
200 * is written.
201 *
202 * When parsing SPI_SIZE bytes are read and written into the chunk pointing to.
203 */
204 SPI,
205
206 /**
207 * Representating a Key Exchange Data field.
208 *
209 * When generating the content of the chunkt pointing to
210 * is written.
211 *
212 * When parsing (Payload Length - 8) bytes are read and written into the chunk pointing to.
213 */
214 KEY_EXCHANGE_DATA,
215
216 /**
217 * Representating a Notification field.
218 *
219 * When generating the content of the chunkt pointing to
220 * is written.
221 *
222 * When parsing (Payload Length - spi size - 8) bytes are read and written into the chunk pointing to.
223 */
224 NOTIFICATION_DATA,
225
226 /**
227 * Representating one or more proposal substructures.
228 *
229 * The offset points to a linked_list_t pointer.
230 *
231 * When generating the proposal_substructure_t objects are stored
232 * in the pointed linked_list.
233 *
234 * When parsing the parsed proposal_substructure_t objects have
235 * to be stored in the pointed linked_list.
236 */
237 PROPOSALS,
238
239 /**
240 * Representating one or more transform substructures.
241 *
242 * The offset points to a linked_list_t pointer.
243 *
244 * When generating the transform_substructure_t objects are stored
245 * in the pointed linked_list.
246 *
247 * When parsing the parsed transform_substructure_t objects have
248 * to be stored in the pointed linked_list.
249 */
250 TRANSFORMS,
251
252 /**
253 * Representating one or more Attributes of a transform substructure.
254 *
255 * The offset points to a linked_list_t pointer.
256 *
257 * When generating the transform_attribute_t objects are stored
258 * in the pointed linked_list.
259 *
260 * When parsing the parsed transform_attribute_t objects have
261 * to be stored in the pointed linked_list.
262 */
263 TRANSFORM_ATTRIBUTES,
264
265 /**
266 * Representating one or more Attributes of a configuration payload.
267 *
268 * The offset points to a linked_list_t pointer.
269 *
270 * When generating the configuration_attribute_t objects are stored
271 * in the pointed linked_list.
272 *
273 * When parsing the parsed configuration_attribute_t objects have
274 * to be stored in the pointed linked_list.
275 */
276 CONFIGURATION_ATTRIBUTES,
277
278 /**
279 *
280 * When generating the content of the chunkt pointing to
281 * is written.
282 *
283 * When parsing (Payload Length - 4) bytes are read and written into the chunk pointing to.
284 */
285 CONFIGURATION_ATTRIBUTE_VALUE,
286
287 /**
288 * Representing a 1 Bit flag specifying the format of a transform attribute.
289 *
290 * When generation, the next bit is set to 1 if the associated value
291 * in the data struct is TRUE, 0 otherwise. The current write position
292 * is moved 1 bit forward afterwards.
293 *
294 * When parsing, the next bit is read and stored in the associated data
295 * struct. 0 means FALSE, 1 means TRUE, The current read pointer
296 * is moved 1 bit forward afterwards.
297 */
298 ATTRIBUTE_FORMAT,
299 /**
300 * Representing a 15 Bit unsigned int value used as attribute type
301 * in an attribute transform.
302 *
303 *
304 * When generating it must be changed from host to network order.
305 * The value is read from the associated data struct.
306 * The current write position is moved 15 bit forward afterwards.
307 *
308 * When parsing it must be changed from network to host order.
309 * The value is written to the associated data struct.
310 * The current read pointer is moved 15 bit forward afterwards.
311 */
312 ATTRIBUTE_TYPE,
313
314 /**
315 * Depending on the field of type ATTRIBUTE_FORMAT
316 * this field contains the length or the value of an transform attribute.
317 * Its stored in a 16 unsigned integer field.
318 *
319 * When generating it must be changed from host to network order.
320 * The value is read from the associated data struct.
321 * The current write position is moved 16 bit forward afterwards.
322 *
323 * When parsing it must be changed from network to host order.
324 * The value is written to the associated data struct.
325 * The current read pointer is moved 16 bit forward afterwards.
326 */
327 ATTRIBUTE_LENGTH_OR_VALUE,
328
329 /**
330 * This field contains the length or the value of an configuration attribute.
331 * Its stored in a 16 unsigned integer field.
332 *
333 * When generating it must be changed from host to network order.
334 * The value is read from the associated data struct.
335 * The current write position is moved 16 bit forward afterwards.
336 *
337 * When parsing it must be changed from network to host order.
338 * The value is written to the associated data struct.
339 * The current read pointer is moved 16 bit forward afterwards.
340 */
341 CONFIGURATION_ATTRIBUTE_LENGTH,
342
343 /**
344 * Depending on the field of type ATTRIBUTE_FORMAT
345 * this field is available or missing and so parsed/generated
346 * or not parsed/not generated.
347 *
348 * When generating the content of the chunkt pointing to
349 * is written.
350 *
351 * When parsing SPI_SIZE bytes are read and written into the chunk pointing to.
352 */
353 ATTRIBUTE_VALUE,
354
355 /**
356 * Representating one or more Traffic selectors of a TS payload.
357 *
358 * The offset points to a linked_list_t pointer.
359 *
360 * When generating the traffic_selector_substructure_t objects are stored
361 * in the pointed linked_list.
362 *
363 * When parsing the parsed traffic_selector_substructure_t objects have
364 * to be stored in the pointed linked_list.
365 */
366 TRAFFIC_SELECTORS,
367
368 /**
369 * Representating a Traffic selector type field.
370 *
371 * When generating it must be changed from host to network order.
372 * The value is read from the associated data struct.
373 * The current write position is moved 16 bit forward afterwards.
374 *
375 * When parsing it must be changed from network to host order.
376 * The value is written to the associated data struct.
377 * The current read pointer is moved 16 bit forward afterwards.
378 */
379 TS_TYPE,
380
381 /**
382 * Representating an address field in a traffic selector.
383 *
384 * Depending on the last field of type TS_TYPE
385 * this field is either 4 or 16 byte long.
386 *
387 * When generating the content of the chunkt pointing to
388 * is written.
389 *
390 * When parsing 4 or 16 bytes are read and written into the chunk pointing to.
391 */
392 ADDRESS,
393
394 /**
395 * Representating a Nonce Data field.
396 *
397 * When generating the content of the chunkt pointing to
398 * is written.
399 *
400 * When parsing (Payload Length - 4) bytes are read and written into the chunk pointing to.
401 */
402 NONCE_DATA,
403
404 /**
405 * Representating a ID Data field.
406 *
407 * When generating the content of the chunkt pointing to
408 * is written.
409 *
410 * When parsing (Payload Length - 8) bytes are read and written into the chunk pointing to.
411 */
412 ID_DATA,
413
414 /**
415 * Representating a AUTH Data field.
416 *
417 * When generating the content of the chunkt pointing to
418 * is written.
419 *
420 * When parsing (Payload Length - 8) bytes are read and written into the chunk pointing to.
421 */
422 AUTH_DATA,
423
424 /**
425 * Representating a CERT Data field.
426 *
427 * When generating the content of the chunkt pointing to
428 * is written.
429 *
430 * When parsing (Payload Length - 5) bytes are read and written into the chunk pointing to.
431 */
432 CERT_DATA,
433
434 /**
435 * Representating a CERTREQ Data field.
436 *
437 * When generating the content of the chunkt pointing to
438 * is written.
439 *
440 * When parsing (Payload Length - 5) bytes are read and written into the chunk pointing to.
441 */
442 CERTREQ_DATA,
443
444 /**
445 * Representating an EAP message field.
446 *
447 * When generating the content of the chunkt pointing to
448 * is written.
449 *
450 * When parsing (Payload Length - 4) bytes are read and written into the chunk pointing to.
451 */
452 EAP_MESSAGE,
453
454 /**
455 * Representating the SPIS field in a DELETE payload.
456 *
457 * When generating the content of the chunkt pointing to
458 * is written.
459 *
460 * When parsing (Payload Length - 8) bytes are read and written into the chunk pointing to.
461 */
462 SPIS,
463
464 /**
465 * Representating the VID DATA field in a VENDOR ID payload.
466 *
467 * When generating the content of the chunkt pointing to
468 * is written.
469 *
470 * When parsing (Payload Length - 4) bytes are read and written into the chunk pointing to.
471 */
472 VID_DATA,
473
474 /**
475 * Representating the DATA of an unknown payload.
476 *
477 * When generating the content of the chunkt pointing to
478 * is written.
479 *
480 * When parsing (Payload Length - 4) bytes are read and written into the chunk pointing to.
481 */
482 UNKNOWN_DATA,
483
484 /**
485 * Representating an IKE_SPI field in an IKEv2 Header.
486 *
487 * When generating the value of the u_int64_t pointing to
488 * is written (host and networ order is not changed).
489 *
490 * When parsing 8 bytes are read and written into the u_int64_t pointing to.
491 */
492 IKE_SPI,
493
494 /**
495 * Representing the encrypted data body of a encryption payload.
496 */
497 ENCRYPTED_DATA,
498 };
499
500 /**
501 * mappings to map encoding_type_t's to strings
502 *
503 * @ingroup payloads
504 */
505 extern mapping_t encoding_type_m[];
506
507
508 typedef struct encoding_rule_t encoding_rule_t;
509
510 /**
511 * An encoding rule is a mapping of a specific encoding type to
512 * a location in the data struct where the current field is stored to
513 * or read from.
514 *
515 * For examples see files in this directory.
516 *
517 * This rules are used by parser and generator.
518 *
519 * @ingroup payloads
520 */
521 struct encoding_rule_t {
522
523 /**
524 * Encoding type.
525 */
526 encoding_type_t type;
527
528 /**
529 * Offset in the data struct.
530 *
531 * When parsing, data are written to this offset of the
532 * data struct.
533 *
534 * When generating, data are read from this offset in the
535 * data struct.
536 */
537 u_int32_t offset;
538 };
539
540 #endif /*ENCODINGS_H_*/