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
183 void (*add_payload
) (message_t
*this, payload_t
*payload
);
186 * @brief Parses header of message
188 * @param this message_t object
190 * - SUCCESS if header could be parsed
191 * - PARSE_ERROR if corrupted/invalid data found
192 * - FAILED if consistence check of header failed
194 status_t (*parse_header
) (message_t
*this);
197 * @brief Parses body of message.
199 * The body gets not only parsed, but rather it gets verified.
200 * All payloads are verified if they are allowed to exist in the message
201 * of this type and if their own structure is ok.
203 * @param this message_t object
205 * - SUCCESS if header could be parsed
206 * - NOT_SUPPORTED if unsupported payload are contained in body
207 * - FAILED if message type is not suppported!
208 * - PARSE_ERROR if corrupted/invalid data found
209 * - VERIFY_ERROR if verification of some payload failed
211 status_t (*parse_body
) (message_t
*this, crypter_t
*crypter
, signer_t
*signer
);
214 * @brief Generates the UDP packet of specific message
216 * @param this message_t object
218 * - SUCCESS if packet could be generated
219 * - EXCHANGE_TYPE_NOT_SET if exchange type is currently not set
222 status_t (*generate
) (message_t
*this, crypter_t
*crypter
, signer_t
*signer
, packet_t
**packet
);
224 status_t (*verify
) (message_t
*this);
225 void (*get_source
) (message_t
*this, host_t
**host
);
226 void (*set_source
) (message_t
*this, host_t
*host
);
227 void (*get_destination
) (message_t
*this, host_t
**host
);
228 void (*set_destination
) (message_t
*this, host_t
*host
);
229 void (*get_payload_iterator
) (message_t
*this, iterator_t
**iterator
);
232 * @brief Destroys a message and all including objects
234 * @param this message_t object
236 void (*destroy
) (message_t
*this);
240 * Creates an message_t object from a incoming UDP Packet.
242 * @warning the given packet_t object is not copied and gets
243 * destroyed in message_t's destroy call.
245 * @warning Packet is not parsed in here!
247 * - exchange_type is set to NOT_SET
248 * - original_initiator is set to TRUE
249 * - is_request is set to TRUE
251 * @param packet packet_t object which is assigned to message
253 * @return created message_t object
257 message_t
* message_create_from_packet(packet_t
*packet
);
261 * Creates an empty message_t object.
263 * - exchange_type is set to NOT_SET
264 * - original_initiator is set to TRUE
265 * - is_request is set to TRUE
267 * @return created message_t object
271 message_t
* message_create();
273 #endif /*MESSAGE_H_*/