Added IKEv1 payload identifiers
[strongswan.git] / src / libcharon / encoding / payloads / payload.h
1 /*
2 * Copyright (C) 2007 Tobias Brunner
3 * Copyright (C) 2005-2006 Martin Willi
4 * Copyright (C) 2005 Jan Hutter
5 * Hochschule fuer Technik Rapperswil
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18 /**
19 * @defgroup payload payload
20 * @{ @ingroup payloads
21 */
22
23 #ifndef PAYLOAD_H_
24 #define PAYLOAD_H_
25
26 typedef enum payload_type_t payload_type_t;
27 typedef struct payload_t payload_t;
28
29 #include <library.h>
30 #include <encoding/payloads/encodings.h>
31
32
33 /**
34 * Payload-Types of an IKE message.
35 *
36 * Header and substructures are also defined as
37 * payload types with values from PRIVATE USE space.
38 */
39 enum payload_type_t {
40
41 /**
42 * End of payload list in next_payload
43 */
44 NO_PAYLOAD = 0,
45
46 /**
47 * The security association (SA) payload containing proposals.
48 */
49 SECURITY_ASSOCIATION_V1 = 1,
50
51 /**
52 * The proposal payload, containing transforms.
53 */
54 PROPOSAL_V1 = 2,
55
56 /**
57 * The transform payload.
58 */
59 TRANSFORM_V1 = 3,
60
61 /**
62 * The key exchange (KE) payload containing diffie-hellman values.
63 */
64 KEY_EXCHANGE_V1 = 4,
65
66 /**
67 * ID payload.
68 */
69 ID_V1 = 5,
70
71 /**
72 * Certificate payload with certificates (CERT).
73 */
74 CERTIFICATE_V1 = 6,
75
76 /**
77 * Certificate request payload.
78 */
79 CERTIFICATE_REQUEST_V1 = 7,
80
81 /**
82 * Hash payload.
83 */
84 HASH_V1 = 8,
85
86 /**
87 * Signature payload
88 */
89 SIGNATURE_V1 = 9,
90
91 /**
92 * Nonce payload.
93 */
94 NONCE_V1 = 10,
95
96 /**
97 * Notification payload.
98 */
99 NOTIFICATION_V1 = 11,
100
101 /**
102 * Delete payload.
103 */
104 DELETE_V1 = 12,
105
106 /**
107 * Vendor id payload.
108 */
109 VENDOR_ID_V1 = 13,
110
111 /**
112 * The security association (SA) payload containing proposals.
113 */
114 SECURITY_ASSOCIATION = 33,
115
116 /**
117 * The key exchange (KE) payload containing diffie-hellman values.
118 */
119 KEY_EXCHANGE = 34,
120
121 /**
122 * Identification for the original initiator (IDi).
123 */
124 ID_INITIATOR = 35,
125
126 /**
127 * Identification for the original responder (IDr).
128 */
129 ID_RESPONDER = 36,
130
131 /**
132 * Certificate payload with certificates (CERT).
133 */
134 CERTIFICATE = 37,
135
136 /**
137 * Certificate request payload (CERTREQ).
138 */
139 CERTIFICATE_REQUEST = 38,
140
141 /**
142 * Authentication payload contains auth data (AUTH).
143 */
144 AUTHENTICATION = 39,
145
146 /**
147 * Nonces, for initiator and responder (Ni, Nr, N)
148 */
149 NONCE = 40,
150
151 /**
152 * Notify paylaod (N).
153 */
154 NOTIFY = 41,
155
156 /**
157 * Delete payload (D)
158 */
159 DELETE = 42,
160
161 /**
162 * Vendor id paylpoad (V).
163 */
164 VENDOR_ID = 43,
165
166 /**
167 * Traffic selector for the original initiator (TSi).
168 */
169 TRAFFIC_SELECTOR_INITIATOR = 44,
170
171 /**
172 * Traffic selector for the original responser (TSr).
173 */
174 TRAFFIC_SELECTOR_RESPONDER = 45,
175
176 /**
177 * Encryption payload, contains other payloads (E).
178 */
179 ENCRYPTED = 46,
180
181 /**
182 * Configuration payload (CP).
183 */
184 CONFIGURATION = 47,
185
186 /**
187 * Extensible authentication payload (EAP).
188 */
189 EXTENSIBLE_AUTHENTICATION = 48,
190
191 #ifdef ME
192 /**
193 * Identification payload for peers has a value from
194 * the PRIVATE USE space.
195 */
196 ID_PEER = 128,
197 #endif /* ME */
198
199 /**
200 * Header has a value of PRIVATE USE space.
201 *
202 * This payload type is not sent over wire and just
203 * used internally to handle IKEv2-Header like a payload.
204 */
205 HEADER = 256,
206
207 /**
208 * PROPOSAL_SUBSTRUCTURE has a value of PRIVATE USE space.
209 *
210 * This payload type is not sent over wire and just
211 * used internally to handle a proposal substructure like a payload.
212 */
213 PROPOSAL_SUBSTRUCTURE = 257,
214
215 /**
216 * TRANSFORM_SUBSTRUCTURE has a value of PRIVATE USE space.
217 *
218 * This payload type is not sent over wire and just
219 * used internally to handle a transform substructure like a payload.
220 */
221 TRANSFORM_SUBSTRUCTURE = 258,
222
223 /**
224 * TRANSFORM_ATTRIBUTE has a value of PRIVATE USE space.
225 *
226 * This payload type is not sent over wire and just
227 * used internally to handle a transform attribute like a payload.
228 */
229 TRANSFORM_ATTRIBUTE = 259,
230
231 /**
232 * TRAFFIC_SELECTOR_SUBSTRUCTURE has a value of PRIVATE USE space.
233 *
234 * This payload type is not sent over wire and just
235 * used internally to handle a transform selector like a payload.
236 */
237 TRAFFIC_SELECTOR_SUBSTRUCTURE = 260,
238
239 /**
240 * CONFIGURATION_ATTRIBUTE has a value of PRIVATE USE space.
241 *
242 * This payload type is not sent over wire and just
243 * used internally to handle a transform attribute like a payload.
244 */
245 CONFIGURATION_ATTRIBUTE = 261,
246 };
247
248 /**
249 * enum names for payload_type_t.
250 */
251 extern enum_name_t *payload_type_names;
252
253 /**
254 * enum names for payload_type_t in a short form.
255 */
256 extern enum_name_t *payload_type_short_names;
257
258 /**
259 * Generic interface for all payload types (incl.header and substructures).
260 *
261 * To handle all kinds of payloads on a generic way, this interface must
262 * be implemented by every payload. This allows parser_t/generator_t a simple
263 * handling of all payloads.
264 */
265 struct payload_t {
266
267 /**
268 * Get encoding rules for this payload.
269 *
270 * @param rules location to store pointer of first rule
271 * @param rule_count location to store number of rules
272 */
273 void (*get_encoding_rules) (payload_t *this, encoding_rule_t **rules, size_t *rule_count);
274
275 /**
276 * Get type of payload.
277 *
278 * @return type of this payload
279 */
280 payload_type_t (*get_type) (payload_t *this);
281
282 /**
283 * Get type of next payload or NO_PAYLOAD (0) if this is the last one.
284 *
285 * @return type of next payload
286 */
287 payload_type_t (*get_next_type) (payload_t *this);
288
289 /**
290 * Set type of next payload.
291 *
292 * @param type type of next payload
293 */
294 void (*set_next_type) (payload_t *this,payload_type_t type);
295
296 /**
297 * Get length of payload.
298 *
299 * @return length of this payload
300 */
301 size_t (*get_length) (payload_t *this);
302
303 /**
304 * Verifies payload structure and makes consistence check.
305 *
306 * @return SUCCESS, FAILED if consistence not given
307 */
308 status_t (*verify) (payload_t *this);
309
310 /**
311 * Destroys a payload and all included substructures.
312 */
313 void (*destroy) (payload_t *this);
314 };
315
316 /**
317 * Create an empty payload.
318 *
319 * Useful for the parser, who wants a generic constructor for all payloads.
320 * It supports all payload_t methods. If a payload type is not known,
321 * an unknwon_paylod is created with the chunk of data in it.
322 *
323 * @param type type of the payload to create
324 * @return payload_t object
325 */
326 payload_t *payload_create(payload_type_t type);
327
328 /**
329 * Check if a specific payload is implemented, or handled as unknown payload.
330 *
331 * @param type type of the payload to check
332 * @return FALSE if payload type handled as unknown payload
333 */
334 bool payload_is_known(payload_type_t type);
335
336 /**
337 * Get the value field in a payload using encoding rules.
338 *
339 * @param payload payload to look up a field
340 * @param type encoding rule type to look up
341 * @param skip number rules of type to skip, 0 to get first
342 * @return type specific value pointer, NULL if not found
343 */
344 void* payload_get_field(payload_t *payload, encoding_type_t type, u_int skip);
345
346 #endif /** PAYLOAD_H_ @}*/