Added reserved bit mangling wrapper functions to message
authorMartin Willi <martin@revosec.ch>
Wed, 24 Nov 2010 15:56:46 +0000 (16:56 +0100)
committerMartin Willi <martin@revosec.ch>
Wed, 5 Jan 2011 15:45:51 +0000 (16:45 +0100)
src/libcharon/encoding/message.c
src/libcharon/encoding/message.h

index 6d4d458..9d66df5 100644 (file)
@@ -491,6 +491,11 @@ struct private_message_t {
        bool is_request;
 
        /**
+        * Reserved bits in IKE header
+        */
+       bool reserved[5];
+
+       /**
         * Sorting of message disabled?
         */
        bool sort_disabled;
@@ -653,6 +658,25 @@ METHOD(message_t, get_request, bool,
        return this->is_request;
 }
 
+METHOD(message_t, get_reserved_header_bit, bool,
+       private_message_t *this, u_int nr)
+{
+       if (nr < countof(this->reserved))
+       {
+               return this->reserved[nr];
+       }
+       return FALSE;
+}
+
+METHOD(message_t, set_reserved_header_bit, void,
+       private_message_t *this, u_int nr)
+{
+       if (nr < countof(this->reserved))
+       {
+               this->reserved[nr] = TRUE;
+       }
+}
+
 /**
  * Is this message in an encoded form?
  */
@@ -1030,6 +1054,8 @@ METHOD(message_t, generate, status_t,
        chunk_t chunk;
        char str[256];
        u_int32_t *lenpos;
+       bool *reserved;
+       int i;
 
        if (is_encoded(this))
        {       /* already generated, return a new packet clone */
@@ -1086,6 +1112,16 @@ METHOD(message_t, generate, status_t,
        ike_header->set_responder_spi(ike_header,
                                                this->ike_sa_id->get_responder_spi(this->ike_sa_id));
 
+       for (i = 0; i < countof(this->reserved); i++)
+       {
+               reserved = payload_get_field(&ike_header->payload_interface,
+                                                                        RESERVED_BIT, i);
+               if (reserved)
+               {
+                       *reserved = this->reserved[i];
+               }
+       }
+
        generator = generator_create();
 
        /* generate all payloads with proper next type */
@@ -1154,6 +1190,8 @@ METHOD(message_t, parse_header, status_t,
 {
        ike_header_t *ike_header;
        status_t status;
+       bool *reserved;
+       int i;
 
        DBG2(DBG_ENC, "parsing header of message");
 
@@ -1188,7 +1226,15 @@ METHOD(message_t, parse_header, status_t,
        this->minor_version = ike_header->get_min_version(ike_header);
        this->first_payload = ike_header->payload_interface.get_next_type(
                                                                                                &ike_header->payload_interface);
-
+       for (i = 0; i < countof(this->reserved); i++)
+       {
+               reserved = payload_get_field(&ike_header->payload_interface,
+                                                                        RESERVED_BIT, i);
+               if (reserved)
+               {
+                       this->reserved[i] = *reserved;
+               }
+       }
        DBG2(DBG_ENC, "parsed a %N %s", exchange_type_names, this->exchange_type,
                 this->is_request ? "request" : "response");
 
@@ -1451,6 +1497,8 @@ message_t *message_create_from_packet(packet_t *packet)
                        .get_first_payload_type = _get_first_payload_type,
                        .set_request = _set_request,
                        .get_request = _get_request,
+                       .get_reserved_header_bit = _get_reserved_header_bit,
+                       .set_reserved_header_bit = _set_reserved_header_bit,
                        .add_payload = _add_payload,
                        .add_notify = _add_notify,
                        .disable_sort = _disable_sort,
index 7db9e01..0cc00ac 100644 (file)
@@ -154,6 +154,21 @@ struct message_t {
        bool (*get_request) (message_t *this);
 
        /**
+        * Get a reserved bit in the IKE header.
+        *
+        * @param nr                    reserved bit to get in IKE header, 0-4
+        * @return                              TRUE if bit is set
+        */
+       bool (*get_reserved_header_bit)(message_t *this, u_int nr);
+
+       /**
+        * Set a reserved bit in the IKE header.
+        *
+        * @param nr                    reserved bit to set in IKE header, 0-4
+        */
+       void (*set_reserved_header_bit)(message_t *this, u_int nr);
+
+       /**
         * Append a payload to the message.
         *
         * If the payload must be encrypted is not specified here. Encryption