4 * @brief Class message_t. Object of this type represents an IKEv2-Message.
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>
33 typedef struct message_t message_t
;
36 * @brief This class is used to represent an IKEv2-Message.
38 * An IKEv2-Message is either a request or response.
43 * @brief Sets the IKE major version of the message.
45 * @param this message_t object
46 * @param major_version major version to set
49 status_t (*set_major_version
) (message_t
*this,u_int8_t major_version
);
52 * @brief Gets the IKE major version of the message.
54 * @param this message_t object
55 * @return major version of the message
57 u_int8_t (*get_major_version
) (message_t
*this);
60 * @brief Sets the IKE minor version of the message.
62 * @param this message_t object
63 * @param minor_version minor version to set
66 status_t (*set_minor_version
) (message_t
*this,u_int8_t minor_version
);
69 * @brief Gets the IKE minor version of the message.
71 * @param this message_t object
72 * @return minor version of the message
74 u_int8_t (*get_minor_version
) (message_t
*this);
77 * @brief Sets the Message ID of the message.
79 * @param this message_t object
80 * @param message_id message_id to set
83 status_t (*set_message_id
) (message_t
*this,u_int32_t message_id
);
86 * @brief Gets the Message ID of the message.
88 * @param this message_t object
89 * @return message_id type of the message
91 u_int32_t (*get_message_id
) (message_t
*this);
94 * @brief Gets the responder SPI of the message.
96 * @param this message_t object
97 * @return responder spi of the message
99 u_int64_t (*get_responder_spi
) (message_t
*this);
102 * @brief Sets the IKE_SA ID of the message.
104 * @warning ike_sa_id gets cloned internaly and
105 * so can be destroyed afterwards.
107 * @param this message_t object
108 * @param ike_sa_id ike_sa_id to set
114 status_t (*set_ike_sa_id
) (message_t
*this,ike_sa_id_t
* ike_sa_id
);
117 * @brief Gets the IKE_SA ID of the message.
119 * @warning The returned ike_sa_id is a clone of the internal one.
120 * So it has to be destroyed by the caller.
122 * @param this message_t object
123 * @param ike_sa_id pointer to ike_sa_id pointer which will be set
127 * - FAILED if no ike_sa_id is set
129 status_t (*get_ike_sa_id
) (message_t
*this,ike_sa_id_t
**ike_sa_id
);
132 * @brief Sets the exchange type of the message.
134 * @param this message_t object
135 * @param exchange_type exchange_type to set
138 status_t (*set_exchange_type
) (message_t
*this,exchange_type_t exchange_type
);
141 * @brief Gets the exchange type of the message.
143 * @param this message_t object
144 * @return exchange type of the message
146 exchange_type_t (*get_exchange_type
) (message_t
*this);
149 * @brief Sets the original initiator flag.
151 * @param this message_t object
152 * @param original_initiator TRUE if message is from original initiator
155 status_t (*set_original_initiator
) (message_t
*this,bool original_initiator
);
158 * @brief Gets original initiator flag.
160 * @param this message_t object
161 * @return TRUE if message is from original initiator, FALSE otherwise
163 bool (*get_original_initiator
) (message_t
*this);
166 * @brief Sets the request flag.
168 * @param this message_t object
169 * @param original_initiator TRUE if message is a request, FALSE if it is a reply
172 status_t (*set_request
) (message_t
*this,bool request
);
175 * @brief Gets request flag.
177 * @param this message_t object
178 * @return TRUE if message is a request, FALSE if it is a reply
180 bool (*get_request
) (message_t
*this);
183 * @brief Append a payload to the message.
185 * @param this message_t object
186 * @param payload payload to append
191 status_t (*add_payload
) (message_t
*this, payload_t
*payload
);
194 * @brief Parses header of message
196 * @param this message_t object
198 * - SUCCESS if header could be parsed
199 * - OUT_OF_RES if out of ressources
200 * - PARSE_ERROR if corrupted/invalid data found
201 * - FAILED if consistence check of header failed
203 status_t (*parse_header
) (message_t
*this);
206 * @brief Parses body of message.
208 * The body gets not only parsed, but rather it gets verified.
209 * All payloads are verified if they are allowed to exist in the message
210 * of this type and if their own structure is ok.
212 * @param this message_t object
214 * - SUCCESS if header could be parsed
215 * - NOT_SUPPORTED if unsupported payload are contained in body
216 * - OUT_OF_RES if out of ressources
217 * - FAILED if message type is not suppported!
218 * - PARSE_ERROR if corrupted/invalid data found
219 * - VERIFY_ERROR if verification of some payload failed
221 status_t (*parse_body
) (message_t
*this);
224 * @brief Generates the UDP packet of specific message
226 * @param this message_t object
228 * - SUCCESS if packet could be generated
229 * - EXCHANGE_TYPE_NOT_SET if exchange type is currently not set
232 status_t (*generate
) (message_t
*this, packet_t
**packet
);
233 status_t (*get_source
) (message_t
*this, host_t
**host
);
234 status_t (*set_source
) (message_t
*this, host_t
*host
);
235 status_t (*get_destination
) (message_t
*this, host_t
**host
);
236 status_t (*set_destination
) (message_t
*this, host_t
*host
);
237 status_t (*get_payload_iterator
) (message_t
*this, linked_list_iterator_t
**iterator
);
240 * @brief Destroys a message and all including objects
242 * @param this message_t object
245 status_t (*destroy
) (message_t
*this);
249 * Creates an message_t object from a incoming UDP Packet.
251 * @warning the given packet_t object is not copied and gets
252 * destroyed in message_t's destroy call.
254 * @warning Packet is not parsed in here!
256 * - exchange_type is set to NOT_SET
257 * - original_initiator is set to TRUE
258 * - is_request is set to TRUE
260 * @param packet packet_t object which is assigned to message
263 * - created message_t object
264 * - NULL if out of ressources
266 message_t
* message_create_from_packet(packet_t
*packet
);
270 * Creates an empty message_t object.
272 * - exchange_type is set to NOT_SET
273 * - original_initiator is set to TRUE
274 * - is_request is set to TRUE
277 * - created message_t object
278 * - NULL if out of ressources
280 message_t
* message_create();
282 #endif /*MESSAGE_H_*/