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