Moved check if packet already encoded to ike_sa, avoids message() hook invocation twice

This commit is contained in:
Martin Willi
2011-01-05 16:45:52 +01:00
parent a6da3795d6
commit 9ca5d0280e
3 changed files with 16 additions and 17 deletions
+4 -17
View File
@@ -688,18 +688,10 @@ METHOD(message_t, set_reserved_header_bit, void,
} }
} }
/** METHOD(message_t, is_encoded, bool,
* Is this message in an encoded form? private_message_t *this)
*/
static bool is_encoded(private_message_t *this)
{ {
chunk_t data = this->packet->get_data(this->packet); return this->packet->get_data(this->packet).ptr != NULL;
if (data.ptr == NULL)
{
return FALSE;
}
return TRUE;
} }
METHOD(message_t, add_payload, void, METHOD(message_t, add_payload, void,
@@ -1068,12 +1060,6 @@ METHOD(message_t, generate, status_t,
bool *reserved; bool *reserved;
int i; int i;
if (is_encoded(this))
{ /* already generated, return a new packet clone */
*packet = this->packet->clone(this->packet);
return SUCCESS;
}
if (this->exchange_type == EXCHANGE_TYPE_UNDEFINED) if (this->exchange_type == EXCHANGE_TYPE_UNDEFINED)
{ {
DBG1(DBG_ENC, "exchange type is not defined"); DBG1(DBG_ENC, "exchange type is not defined");
@@ -1516,6 +1502,7 @@ message_t *message_create_from_packet(packet_t *packet)
.add_notify = _add_notify, .add_notify = _add_notify,
.disable_sort = _disable_sort, .disable_sort = _disable_sort,
.generate = _generate, .generate = _generate,
.is_encoded = _is_encoded,
.set_source = _set_source, .set_source = _set_source,
.get_source = _get_source, .get_source = _get_source,
.set_destination = _set_destination, .set_destination = _set_destination,
+7
View File
@@ -257,6 +257,13 @@ struct message_t {
*/ */
status_t (*generate) (message_t *this, aead_t *aead, packet_t **packet); status_t (*generate) (message_t *this, aead_t *aead, packet_t **packet);
/**
* Check if the message has already been encoded using generate().
*
* @return TRUE if message has been encoded
*/
bool (*is_encoded)(message_t *this);
/** /**
* Gets the source host informations. * Gets the source host informations.
* *
+5
View File
@@ -891,6 +891,11 @@ METHOD(ike_sa_t, update_hosts, void,
METHOD(ike_sa_t, generate_message, status_t, METHOD(ike_sa_t, generate_message, status_t,
private_ike_sa_t *this, message_t *message, packet_t **packet) private_ike_sa_t *this, message_t *message, packet_t **packet)
{ {
if (message->is_encoded(message))
{ /* already done */
*packet = message->get_packet(message);
return SUCCESS;
}
this->stats[STAT_OUTBOUND] = time_monotonic(NULL); this->stats[STAT_OUTBOUND] = time_monotonic(NULL);
message->set_ike_sa_id(message, this->ike_sa_id); message->set_ike_sa_id(message, this->ike_sa_id);
charon->bus->message(charon->bus, message, FALSE); charon->bus->message(charon->bus, message, FALSE);