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