4 * @brief Interface of message_t.
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
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>.
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
27 #include <sa/ike_sa_id.h>
28 #include <network/packet.h>
29 #include <encoding/payloads/ike_header.h>
30 #include <utils/linked_list.h>
31 #include <transforms/crypters/crypter.h>
32 #include <transforms/signers/signer.h>
35 typedef struct message_t message_t
;
38 * @brief This class is used to represent an IKEv2-Message.
40 * An IKEv2-Message is either a request or response.
47 * @brief Sets the IKE major version of the message.
49 * @param this message_t object
50 * @param major_version major version to set
52 void (*set_major_version
) (message_t
*this,u_int8_t major_version
);
55 * @brief Gets the IKE major version of the message.
57 * @param this message_t object
58 * @return major version of the message
60 u_int8_t (*get_major_version
) (message_t
*this);
63 * @brief Sets the IKE minor version of the message.
65 * @param this message_t object
66 * @param minor_version minor version to set
68 void (*set_minor_version
) (message_t
*this,u_int8_t minor_version
);
71 * @brief Gets the IKE minor version of the message.
73 * @param this message_t object
74 * @return minor version of the message
76 u_int8_t (*get_minor_version
) (message_t
*this);
79 * @brief Sets the Message ID of the message.
81 * @param this message_t object
82 * @param message_id message_id to set
84 void (*set_message_id
) (message_t
*this,u_int32_t message_id
);
87 * @brief Gets the Message ID of the message.
89 * @param this message_t object
90 * @return message_id type of the message
92 u_int32_t (*get_message_id
) (message_t
*this);
95 * @brief Gets the responder SPI of the message.
97 * @param this message_t object
98 * @return responder spi of the message
100 u_int64_t (*get_responder_spi
) (message_t
*this);
103 * @brief Sets the IKE_SA ID of the message.
105 * @warning ike_sa_id gets cloned internaly and
106 * so can be destroyed afterwards.
108 * @param this message_t object
109 * @param ike_sa_id ike_sa_id to set
111 void (*set_ike_sa_id
) (message_t
*this,ike_sa_id_t
* ike_sa_id
);
114 * @brief Gets the IKE_SA ID of the message.
116 * @warning The returned ike_sa_id is a clone of the internal one.
117 * So it has to be destroyed by the caller.
119 * @param this message_t object
120 * @param ike_sa_id pointer to ike_sa_id pointer which will be set
123 * - FAILED if no ike_sa_id is set
125 status_t (*get_ike_sa_id
) (message_t
*this,ike_sa_id_t
**ike_sa_id
);
128 * @brief Sets the exchange type of the message.
130 * @param this message_t object
131 * @param exchange_type exchange_type to set
133 void (*set_exchange_type
) (message_t
*this,exchange_type_t exchange_type
);
136 * @brief Gets the exchange type of the message.
138 * @param this message_t object
139 * @return exchange type of the message
141 exchange_type_t (*get_exchange_type
) (message_t
*this);
144 * @brief Sets the original initiator flag.
146 * @param this message_t object
147 * @param original_initiator TRUE if message is from original initiator
149 void (*set_original_initiator
) (message_t
*this,bool original_initiator
);
152 * @brief Gets original initiator flag.
154 * @param this message_t object
155 * @return TRUE if message is from original initiator, FALSE otherwise
157 bool (*get_original_initiator
) (message_t
*this);
160 * @brief Sets the request flag.
162 * @param this message_t object
163 * @param original_initiator TRUE if message is a request, FALSE if it is a reply
165 void (*set_request
) (message_t
*this,bool request
);
168 * @brief Gets request flag.
170 * @param this message_t object
171 * @return TRUE if message is a request, FALSE if it is a reply
173 bool (*get_request
) (message_t
*this);
176 * @brief Append a payload to the message.
178 * @param this message_t object
179 * @param payload payload to append
181 void (*add_payload
) (message_t
*this, payload_t
*payload
);
184 * @brief Parses header of message
186 * @param this message_t object
188 * - SUCCESS if header could be parsed
189 * - PARSE_ERROR if corrupted/invalid data found
190 * - FAILED if consistence check of header failed
192 status_t (*parse_header
) (message_t
*this);
195 * @brief Parses body of message.
197 * The body gets not only parsed, but rather it gets verified.
198 * All payloads are verified if they are allowed to exist in the message
199 * of this type and if their own structure is ok.
201 * @param this message_t object
203 * - SUCCESS if header could be parsed
204 * - NOT_SUPPORTED if unsupported payload are contained in body
205 * - FAILED if message type is not suppported!
206 * - PARSE_ERROR if corrupted/invalid data found
207 * - VERIFY_ERROR if verification of some payload failed
209 status_t (*parse_body
) (message_t
*this, crypter_t
*crypter
, signer_t
*signer
);
212 * @brief Generates the UDP packet of specific message
214 * @param this message_t object
216 * - SUCCESS if packet could be generated
217 * - EXCHANGE_TYPE_NOT_SET if exchange type is currently not set
220 status_t (*generate
) (message_t
*this, crypter_t
*crypter
, signer_t
*signer
, packet_t
**packet
);
223 * Verifies the structure of the message_t object.
225 * The payloads are checked for the correct occurence count.
227 * @param this message_t object
229 status_t (*verify
) (message_t
*this);
232 * Gets the source host informations.
234 * @warning Returned host_t object is not getting cloned.
236 * @param this message_t object
237 * @return host_t object representing source host
239 host_t
* (*get_source
) (message_t
*this);
242 * Sets the source host informations.
244 * @warning host_t object is not getting cloned and gets destroyed by
245 * message_t.destroy or next call of message_t.set_source.
247 * @param this message_t object
248 * @param host host_t object representing source host
250 void (*set_source
) (message_t
*this, host_t
*host
);
253 * Gets the destination host informations.
255 * @warning Returned host_t object is not getting cloned.
257 * @param this message_t object
258 * @return host_t object representing destination host
260 host_t
* (*get_destination
) (message_t
*this);
263 * Sets the destination host informations.
265 * @warning host_t object is not getting cloned and gets destroyed by
266 * message_t.destroy or next call of message_t.set_destination.
268 * @param this message_t object
269 * @param host host_t object representing destination host
271 void (*set_destination
) (message_t
*this, host_t
*host
);
274 * Returns an iterator on all stored payloads.
276 * @warning Don't insert payloads over this iterator.
277 * Use message_t.add_payload instead.
279 * @param this message_t object
280 * @return iterator_t object which has to get destroyd by the caller
282 iterator_t
* (*get_payload_iterator
) (message_t
*this);
285 * @brief Destroys a message and all including objects.
287 * @param this message_t object
289 void (*destroy
) (message_t
*this);
293 * Creates an message_t object from a incoming UDP Packet.
295 * @warning the given packet_t object is not copied and gets
296 * destroyed in message_t's destroy call.
298 * @warning Packet is not parsed in here!
300 * - exchange_type is set to NOT_SET
301 * - original_initiator is set to TRUE
302 * - is_request is set to TRUE
304 * @param packet packet_t object which is assigned to message
306 * @return created message_t object
310 message_t
* message_create_from_packet(packet_t
*packet
);
314 * Creates an empty message_t object.
316 * - exchange_type is set to NOT_SET
317 * - original_initiator is set to TRUE
318 * - is_request is set to TRUE
320 * @return created message_t object
324 message_t
* message_create();
326 #endif /*MESSAGE_H_*/