Moved check if packet already encoded to ike_sa, avoids message() hook invocation...
authorMartin Willi <martin@revosec.ch>
Wed, 24 Nov 2010 17:09:06 +0000 (18:09 +0100)
committerMartin Willi <martin@revosec.ch>
Wed, 5 Jan 2011 15:45:52 +0000 (16:45 +0100)
src/libcharon/encoding/message.c
src/libcharon/encoding/message.h
src/libcharon/sa/ike_sa.c

index c9959ab..860ef62 100644 (file)
@@ -688,18 +688,10 @@ METHOD(message_t, set_reserved_header_bit, void,
        }
 }
 
-/**
- * Is this message in an encoded form?
- */
-static bool is_encoded(private_message_t *this)
+METHOD(message_t, is_encoded, bool,
+       private_message_t *this)
 {
-       chunk_t data = this->packet->get_data(this->packet);
-
-       if (data.ptr == NULL)
-       {
-               return FALSE;
-       }
-       return TRUE;
+       return this->packet->get_data(this->packet).ptr != NULL;
 }
 
 METHOD(message_t, add_payload, void,
@@ -1068,12 +1060,6 @@ METHOD(message_t, generate, status_t,
        bool *reserved;
        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)
        {
                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,
                        .disable_sort = _disable_sort,
                        .generate = _generate,
+                       .is_encoded = _is_encoded,
                        .set_source = _set_source,
                        .get_source = _get_source,
                        .set_destination = _set_destination,
index a04048e..5119730 100644 (file)
@@ -258,6 +258,13 @@ struct message_t {
        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.
         *
         * @warning Returned host_t object is not getting cloned,
index b012c3d..d6d880d 100644 (file)
@@ -891,6 +891,11 @@ METHOD(ike_sa_t, update_hosts, void,
 METHOD(ike_sa_t, generate_message, status_t,
        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);
        message->set_ike_sa_id(message, this->ike_sa_id);
        charon->bus->message(charon->bus, message, FALSE);