aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/charon/encoding/message.c36
-rw-r--r--src/charon/encoding/message.h25
-rw-r--r--src/charon/queues/jobs/incoming_packet_job.c23
3 files changed, 46 insertions, 38 deletions
diff --git a/src/charon/encoding/message.c b/src/charon/encoding/message.c
index 031382cee..4f5f3b899 100644
--- a/src/charon/encoding/message.c
+++ b/src/charon/encoding/message.c
@@ -711,6 +711,20 @@ static chunk_t get_packet_data (private_message_t *this)
}
/**
+ * Implementation of message_t.is_encoded.
+ */
+static bool is_encoded(private_message_t *this)
+{
+ chunk_t data = this->packet->get_data(this->packet);
+
+ if (data.ptr == NULL)
+ {
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/**
* Implementation of message_t.parse_header.
*/
static status_t parse_header(private_message_t *this)
@@ -1232,6 +1246,7 @@ message_t *message_create_from_packet(packet_t *packet)
this->public.parse_body = (status_t (*) (message_t *,crypter_t*,signer_t*)) parse_body;
this->public.get_packet = (packet_t * (*) (message_t*)) get_packet;
this->public.get_packet_data = (chunk_t (*) (message_t *this)) get_packet_data;
+ this->public.is_encoded = (bool (*) (message_t *this)) is_encoded;
this->public.destroy = (void(*)(message_t*))destroy;
/* private values */
@@ -1272,24 +1287,3 @@ message_t *message_create()
{
return message_create_from_packet(NULL);
}
-
-/*
- * Described in Header.
- */
-message_t *message_create_notify_reply(host_t *source, host_t *destination, exchange_type_t exchange_type, bool original_initiator,ike_sa_id_t *ike_sa_id,notify_message_type_t notify_type)
-{
- message_t *message = message_create_from_packet(NULL);
- notify_payload_t *payload;
-
- message->set_source(message, source->clone(source));
- message->set_destination(message, destination->clone(destination));
- message->set_exchange_type(message, exchange_type);
- message->set_request(message, FALSE);
- message->set_message_id(message,0);
- message->set_ike_sa_id(message, ike_sa_id);
-
- payload = notify_payload_create_from_protocol_and_type(PROTO_NONE, notify_type);
- message->add_payload(message,(payload_t *) payload);
-
- return message;
-}
diff --git a/src/charon/encoding/message.h b/src/charon/encoding/message.h
index e32cf68d4..8c105e597 100644
--- a/src/charon/encoding/message.h
+++ b/src/charon/encoding/message.h
@@ -306,7 +306,7 @@ struct message_t {
iterator_t * (*get_payload_iterator) (message_t *this);
/**
- * Returns a clone of the internal stored packet_t object.
+ * @brief Returns a clone of the internal stored packet_t object.
*
* @param this message_t object
* @return packet_t object as clone of internal one
@@ -314,13 +314,25 @@ struct message_t {
packet_t * (*get_packet) (message_t *this);
/**
- * Returns a clone of the internal stored packet_t data.
+ * @brief Returns a clone of the internal stored packet_t data.
*
* @param this message_t object
* @return clone of the internal stored packet_t data.
*/
chunk_t (*get_packet_data) (message_t *this);
+ /**
+ * @brief Check if a message is encoded.
+ *
+ * Check if the packet is in a generated (and encrypted) form available
+ * and can be passed down to the socket. If not, it has to be generated
+ * first.
+ *
+ * @param this message_t object
+ * @return TRUE if encoded, FALSE if not
+ */
+ bool (*is_encoded) (message_t *this);
+
/**
* @brief Destroys a message and all including objects.
@@ -364,13 +376,4 @@ message_t * message_create_from_packet(packet_t *packet);
*/
message_t * message_create(void);
-/**
- * @brief Creates an message_t object of type reply containing a notify payload.
- *
- * @return message_t object
- *
- * @ingroup encoding
- */
-message_t *message_create_notify_reply(host_t *source, host_t *destination, exchange_type_t exchange_type, bool original_initiator,ike_sa_id_t *ike_sa_id,notify_message_type_t notify_type);
-
#endif /*MESSAGE_H_*/
diff --git a/src/charon/queues/jobs/incoming_packet_job.c b/src/charon/queues/jobs/incoming_packet_job.c
index 6043b03ca..fbd52b7a6 100644
--- a/src/charon/queues/jobs/incoming_packet_job.c
+++ b/src/charon/queues/jobs/incoming_packet_job.c
@@ -89,15 +89,26 @@ static status_t execute(private_incoming_packet_job_t *this)
message->get_minor_version(message));
if ((message->get_exchange_type(message) == IKE_SA_INIT) && (message->get_request(message)))
{
+ notify_payload_t *notify;
message_t *response;
+ host_t *src, *dst;
+
message->get_ike_sa_id(message, &ike_sa_id);
ike_sa_id->switch_initiator(ike_sa_id);
- response = message_create_notify_reply(message->get_destination(message),
- message->get_source(message),
- IKE_SA_INIT, FALSE, ike_sa_id,
- INVALID_MAJOR_VERSION);
- message->destroy(message);
- ike_sa_id->destroy(ike_sa_id);
+
+ response = message_create();
+ src = message->get_source(message);
+ dst = message->get_destination(message);
+ response->set_source(response, src->clone(src));
+ response->set_destination(response, dst->clone(dst));
+ response->set_exchange_type(response, IKE_SA_INIT);
+ response->set_request(response, FALSE);
+ response->set_message_id(response, 0);
+ response->set_ike_sa_id(response, ike_sa_id);
+
+ notify = notify_payload_create_from_protocol_and_type(PROTO_NONE, INVALID_MAJOR_VERSION);
+ response->add_payload(response, (payload_t *)notify);
+
status = response->generate(response, NULL, NULL, &packet);
if (status != SUCCESS)
{