9d5ba8f114708be923c2464be2b8ec5cd3c78b91
[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 a IKEv2-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 = 33,
50
51 /**
52 * The key exchange (KE) payload containing diffie-hellman values.
53 */
54 KEY_EXCHANGE = 34,
55
56 /**
57 * Identification for the original initiator (IDi).
58 */
59 ID_INITIATOR = 35,
60
61 /**
62 * Identification for the original responder (IDr).
63 */
64 ID_RESPONDER = 36,
65
66 /**
67 * Certificate payload with certificates (CERT).
68 */
69 CERTIFICATE = 37,
70
71 /**
72 * Certificate request payload (CERTREQ).
73 */
74 CERTIFICATE_REQUEST = 38,
75
76 /**
77 * Authentication payload contains auth data (AUTH).
78 */
79 AUTHENTICATION = 39,
80
81 /**
82 * Nonces, for initator and responder (Ni, Nr, N)
83 */
84 NONCE = 40,
85
86 /**
87 * Notify paylaod (N).
88 */
89 NOTIFY = 41,
90
91 /**
92 * Delete payload (D)
93 */
94 DELETE = 42,
95
96 /**
97 * Vendor id paylpoad (V).
98 */
99 VENDOR_ID = 43,
100
101 /**
102 * Traffic selector for the original initiator (TSi).
103 */
104 TRAFFIC_SELECTOR_INITIATOR = 44,
105
106 /**
107 * Traffic selector for the original responser (TSr).
108 */
109 TRAFFIC_SELECTOR_RESPONDER = 45,
110
111 /**
112 * Encryption payload, contains other payloads (E).
113 */
114 ENCRYPTED = 46,
115
116 /**
117 * Configuration payload (CP).
118 */
119 CONFIGURATION = 47,
120
121 /**
122 * Extensible authentication payload (EAP).
123 */
124 EXTENSIBLE_AUTHENTICATION = 48,
125
126 #ifdef ME
127 /**
128 * Identification payload for peers has a value from
129 * the PRIVATE USE space.
130 */
131 ID_PEER = 128,
132 #endif /* ME */
133
134 /**
135 * Header has a value of PRIVATE USE space.
136 *
137 * This payload type is not sent over wire and just
138 * used internally to handle IKEv2-Header like a payload.
139 */
140 HEADER = 256,
141
142 /**
143 * PROPOSAL_SUBSTRUCTURE has a value of PRIVATE USE space.
144 *
145 * This payload type is not sent over wire and just
146 * used internally to handle a proposal substructure like a payload.
147 */
148 PROPOSAL_SUBSTRUCTURE = 257,
149
150 /**
151 * TRANSFORM_SUBSTRUCTURE has a value of PRIVATE USE space.
152 *
153 * This payload type is not sent over wire and just
154 * used internally to handle a transform substructure like a payload.
155 */
156 TRANSFORM_SUBSTRUCTURE = 258,
157
158 /**
159 * TRANSFORM_ATTRIBUTE has a value of PRIVATE USE space.
160 *
161 * This payload type is not sent over wire and just
162 * used internally to handle a transform attribute like a payload.
163 */
164 TRANSFORM_ATTRIBUTE = 259,
165
166 /**
167 * TRAFFIC_SELECTOR_SUBSTRUCTURE has a value of PRIVATE USE space.
168 *
169 * This payload type is not sent over wire and just
170 * used internally to handle a transform selector like a payload.
171 */
172 TRAFFIC_SELECTOR_SUBSTRUCTURE = 260,
173
174 /**
175 * CONFIGURATION_ATTRIBUTE has a value of PRIVATE USE space.
176 *
177 * This payload type is not sent over wire and just
178 * used internally to handle a transform attribute like a payload.
179 */
180 CONFIGURATION_ATTRIBUTE = 261,
181 };
182
183 /**
184 * enum names for payload_type_t.
185 */
186 extern enum_name_t *payload_type_names;
187
188 /**
189 * enum names for payload_type_t in a short form.
190 */
191 extern enum_name_t *payload_type_short_names;
192
193 /**
194 * Generic interface for all payload types (incl.header and substructures).
195 *
196 * To handle all kinds of payloads on a generic way, this interface must
197 * be implemented by every payload. This allows parser_t/generator_t a simple
198 * handling of all payloads.
199 */
200 struct payload_t {
201
202 /**
203 * Get encoding rules for this payload.
204 *
205 * @param rules location to store pointer of first rule
206 * @param rule_count location to store number of rules
207 */
208 void (*get_encoding_rules) (payload_t *this, encoding_rule_t **rules, size_t *rule_count);
209
210 /**
211 * Get type of payload.
212 *
213 * @return type of this payload
214 */
215 payload_type_t (*get_type) (payload_t *this);
216
217 /**
218 * Get type of next payload or NO_PAYLOAD (0) if this is the last one.
219 *
220 * @return type of next payload
221 */
222 payload_type_t (*get_next_type) (payload_t *this);
223
224 /**
225 * Set type of next payload.
226 *
227 * @param type type of next payload
228 */
229 void (*set_next_type) (payload_t *this,payload_type_t type);
230
231 /**
232 * Get length of payload.
233 *
234 * @return length of this payload
235 */
236 size_t (*get_length) (payload_t *this);
237
238 /**
239 * Verifies payload structure and makes consistence check.
240 *
241 * @return SUCCESS, FAILED if consistence not given
242 */
243 status_t (*verify) (payload_t *this);
244
245 /**
246 * Destroys a payload and all included substructures.
247 */
248 void (*destroy) (payload_t *this);
249 };
250
251 /**
252 * Create an empty payload.
253 *
254 * Useful for the parser, who wants a generic constructor for all payloads.
255 * It supports all payload_t methods. If a payload type is not known,
256 * an unknwon_paylod is created with the chunk of data in it.
257 *
258 * @param type type of the payload to create
259 * @return payload_t object
260 */
261 payload_t *payload_create(payload_type_t type);
262
263 /**
264 * Check if a specific payload is implemented, or handled as unkown payload.
265 *
266 * @param type type of the payload to check
267 * @return FALSE if payload type handled as unkown payload
268 */
269 bool payload_is_known(payload_type_t type);
270
271 /**
272 * Get the value field in a payload using encoding rules.
273 *
274 * @param payload payload to look up a field
275 * @param type encoding rule type to look up
276 * @param skip number rules of type to skip, 0 to get first
277 * @return type specific value pointer, NULL if not found
278 */
279 void* payload_get_field(payload_t *payload, encoding_type_t type, u_int skip);
280
281 #endif /** PAYLOAD_H_ @}*/