Extended nonce payload for IKEv1 support
[strongswan.git] / src / libcharon / encoding / payloads / nonce_payload.c
index 0d582fa..684bddc 100644 (file)
@@ -44,6 +44,11 @@ struct private_nonce_payload_t {
        bool critical;
 
        /**
+        * Reserved bits
+        */
+       bool reserved[7];
+
+       /**
         * Length of this payload.
         */
        u_int16_t payload_length;
@@ -52,6 +57,11 @@ struct private_nonce_payload_t {
         * The contained nonce value.
         */
        chunk_t nonce;
+
+       /**
+        * Payload type, NONCE or NONCE_V1
+        */
+       payload_type_t type;
 };
 
 /**
@@ -65,14 +75,14 @@ encoding_rule_t nonce_payload_encodings[] = {
        { U_INT_8,                      offsetof(private_nonce_payload_t, next_payload)         },
        /* the critical bit */
        { FLAG,                         offsetof(private_nonce_payload_t, critical)                     },
-       /* 7 Bit reserved bits, nowhere stored */
-       { RESERVED_BIT,         0                                                                                                       },
-       { RESERVED_BIT,         0                                                                                                       },
-       { RESERVED_BIT,         0                                                                                                       },
-       { RESERVED_BIT,         0                                                                                                       },
-       { RESERVED_BIT,         0                                                                                                       },
-       { RESERVED_BIT,         0                                                                                                       },
-       { RESERVED_BIT,         0                                                                                                       },
+       /* 7 Bit reserved bits */
+       { RESERVED_BIT,         offsetof(private_nonce_payload_t, reserved[0])          },
+       { RESERVED_BIT,         offsetof(private_nonce_payload_t, reserved[1])          },
+       { RESERVED_BIT,         offsetof(private_nonce_payload_t, reserved[2])          },
+       { RESERVED_BIT,         offsetof(private_nonce_payload_t, reserved[3])          },
+       { RESERVED_BIT,         offsetof(private_nonce_payload_t, reserved[4])          },
+       { RESERVED_BIT,         offsetof(private_nonce_payload_t, reserved[5])          },
+       { RESERVED_BIT,         offsetof(private_nonce_payload_t, reserved[6])          },
        /* Length of the whole nonce payload*/
        { PAYLOAD_LENGTH,       offsetof(private_nonce_payload_t, payload_length)       },
        /* some nonce bytes, lenth is defined in PAYLOAD_LENGTH */
@@ -110,7 +120,7 @@ METHOD(payload_t, get_encoding_rules, void,
 METHOD(payload_t, get_type, payload_type_t,
        private_nonce_payload_t *this)
 {
-       return NONCE;
+       return this->type;
 }
 
 METHOD(payload_t, get_next_type, payload_type_t,
@@ -154,7 +164,7 @@ METHOD2(payload_t, nonce_payload_t, destroy, void,
 /*
  * Described in header
  */
-nonce_payload_t *nonce_payload_create()
+nonce_payload_t *nonce_payload_create(payload_type_t type)
 {
        private_nonce_payload_t *this;
 
@@ -175,6 +185,7 @@ nonce_payload_t *nonce_payload_create()
                },
                .next_payload = NO_PAYLOAD,
                .payload_length = NONCE_PAYLOAD_HEADER_LENGTH,
+               .type = type,
        );
        return &this->public;
 }