Use a generic encoding type for all variable length chunks
authorMartin Willi <martin@revosec.ch>
Thu, 17 Nov 2011 14:20:16 +0000 (14:20 +0000)
committerMartin Willi <martin@revosec.ch>
Tue, 20 Mar 2012 16:30:42 +0000 (17:30 +0100)
18 files changed:
src/libcharon/encoding/generator.c
src/libcharon/encoding/parser.c
src/libcharon/encoding/payloads/auth_payload.c
src/libcharon/encoding/payloads/cert_payload.c
src/libcharon/encoding/payloads/certreq_payload.c
src/libcharon/encoding/payloads/configuration_attribute.c
src/libcharon/encoding/payloads/delete_payload.c
src/libcharon/encoding/payloads/eap_payload.c
src/libcharon/encoding/payloads/encodings.c
src/libcharon/encoding/payloads/encodings.h
src/libcharon/encoding/payloads/encryption_payload.c
src/libcharon/encoding/payloads/hash_payload.c
src/libcharon/encoding/payloads/id_payload.c
src/libcharon/encoding/payloads/ke_payload.c
src/libcharon/encoding/payloads/nonce_payload.c
src/libcharon/encoding/payloads/notify_payload.c
src/libcharon/encoding/payloads/unknown_payload.c
src/libcharon/encoding/payloads/vendor_id_payload.c

index 9cb1cdc..d6828e7 100644 (file)
@@ -448,21 +448,7 @@ METHOD(generator_t, generate_payload, void,
                                break;
                        case ADDRESS:
                        case SPI:
-                       case KEY_EXCHANGE_DATA:
-                       case KEY_EXCHANGE_DATA_V1:
-                       case NOTIFICATION_DATA:
-                       case NONCE_DATA:
-                       case HASH_DATA:
-                       case ID_DATA:
-                       case AUTH_DATA:
-                       case CERT_DATA:
-                       case CERTREQ_DATA:
-                       case SPIS:
-                       case CONFIGURATION_ATTRIBUTE_VALUE:
-                       case VID_DATA:
-                       case EAP_DATA:
-                       case ENCRYPTED_DATA:
-                       case UNKNOWN_DATA:
+                       case CHUNK_DATA:
                                generate_from_chunk(this, rules[i].offset);
                                break;
                        case PROPOSALS:
index 77923e7..1876212 100644 (file)
@@ -532,22 +532,7 @@ METHOD(parser_t, parse_payload, status_t,
                                }
                                break;
                        }
-                       /* chunks */
-                       case NONCE_DATA:
-                       case HASH_DATA:
-                       case ID_DATA:
-                       case AUTH_DATA:
-                       case CERT_DATA:
-                       case CERTREQ_DATA:
-                       case EAP_DATA:
-                       case SPIS:
-                       case VID_DATA:
-                       case CONFIGURATION_ATTRIBUTE_VALUE:
-                       case KEY_EXCHANGE_DATA:
-                       case KEY_EXCHANGE_DATA_V1:
-                       case NOTIFICATION_DATA:
-                       case ENCRYPTED_DATA:
-                       case UNKNOWN_DATA:
+                       case CHUNK_DATA:
                        {
                                if (payload_length < header_length ||
                                        !parse_chunk(this, rule_number, output + rule->offset,
index 57dc58f..2410a1a 100644 (file)
@@ -96,7 +96,7 @@ static encoding_rule_t encodings[] = {
        { RESERVED_BYTE,        offsetof(private_auth_payload_t, reserved_byte[1])      },
        { RESERVED_BYTE,        offsetof(private_auth_payload_t, reserved_byte[2])      },
        /* some auth data bytes, length is defined in PAYLOAD_LENGTH */
-       { AUTH_DATA,            offsetof(private_auth_payload_t, auth_data)     }
+       { CHUNK_DATA,           offsetof(private_auth_payload_t, auth_data)     }
 };
 
 /*
index 565be7f..1ef93b7 100644 (file)
@@ -113,7 +113,7 @@ static encoding_rule_t encodings[] = {
        /* 1 Byte CERT type*/
        { U_INT_8,                      offsetof(private_cert_payload_t, encoding)              },
        /* some cert data bytes, length is defined in PAYLOAD_LENGTH */
-       { CERT_DATA,            offsetof(private_cert_payload_t, data)                  }
+       { CHUNK_DATA,           offsetof(private_cert_payload_t, data)                  }
 };
 
 /*
index dc685e6..69e80ad 100644 (file)
@@ -90,7 +90,7 @@ static encoding_rule_t encodings[] = {
        /* 1 Byte CERTREQ type*/
        { U_INT_8,                      offsetof(private_certreq_payload_t, encoding)           },
        /* some certreq data bytes, length is defined in PAYLOAD_LENGTH */
-       { CERTREQ_DATA,         offsetof(private_certreq_payload_t, data)                       }
+       { CHUNK_DATA,           offsetof(private_certreq_payload_t, data)                       }
 };
 
 /*
index 8746b9b..88e43fa 100644 (file)
@@ -70,7 +70,7 @@ static encoding_rule_t encodings[] = {
        /* Length of attribute value */
        { CONFIGURATION_ATTRIBUTE_LENGTH,       offsetof(private_configuration_attribute_t, length)     },
        /* Value of attribute if attribute format flag is zero */
-       { CONFIGURATION_ATTRIBUTE_VALUE,        offsetof(private_configuration_attribute_t, value)      }
+       { CHUNK_DATA,                                           offsetof(private_configuration_attribute_t, value)      }
 };
 
 /*
index 5f0af8c..425bde0 100644 (file)
@@ -98,7 +98,7 @@ static encoding_rule_t encodings[] = {
        { U_INT_8,                      offsetof(private_delete_payload_t, spi_size)            },
        { U_INT_16,                     offsetof(private_delete_payload_t, spi_count)           },
        /* some delete data bytes, length is defined in PAYLOAD_LENGTH */
-       { SPIS,                         offsetof(private_delete_payload_t, spis)                        }
+       { CHUNK_DATA,           offsetof(private_delete_payload_t, spis)                        }
 };
 
 /*
index 47a9b16..9982f05 100644 (file)
@@ -81,7 +81,7 @@ static encoding_rule_t encodings[] = {
        /* Length of the whole payload*/
        { PAYLOAD_LENGTH,       offsetof(private_eap_payload_t, payload_length) },
        /* chunt to data, starting at "code" */
-       { EAP_DATA,                     offsetof(private_eap_payload_t, data)                   },
+       { CHUNK_DATA,           offsetof(private_eap_payload_t, data)                   },
 };
 
 /*
index 303ccca..3fe2e6b 100644 (file)
@@ -17,7 +17,7 @@
 
 #include "encodings.h"
 
-ENUM(encoding_type_names, U_INT_4, ENCRYPTED_DATA,
+ENUM(encoding_type_names, U_INT_4, IKE_SPI,
        "U_INT_4",
        "U_INT_8",
        "U_INT_16",
@@ -29,9 +29,6 @@ ENUM(encoding_type_names, U_INT_4, ENCRYPTED_DATA,
        "HEADER_LENGTH",
        "SPI_SIZE",
        "SPI",
-       "KEY_EXCHANGE_DATA",
-       "KEY_EXCHANGE_DATA_V1",
-       "NOTIFICATION_DATA",
        "PROPOSALS",
        "PROPOSALS_V1",
        "TRANSFORMS",
@@ -39,7 +36,6 @@ ENUM(encoding_type_names, U_INT_4, ENCRYPTED_DATA,
        "TRANSFORM_ATTRIBUTES",
        "TRANSFORM_ATTRIBUTES_V1",
        "CONFIGURATION_ATTRIBUTES",
-       "CONFIGURATION_ATTRIBUTE_VALUE",
        "ATTRIBUTE_FORMAT",
        "ATTRIBUTE_TYPE",
        "ATTRIBUTE_LENGTH_OR_VALUE",
@@ -48,16 +44,6 @@ ENUM(encoding_type_names, U_INT_4, ENCRYPTED_DATA,
        "TRAFFIC_SELECTORS",
        "TS_TYPE",
        "ADDRESS",
-       "NONCE_DATA",
-       "HASH_DATA",
-       "ID_DATA",
-       "AUTH_DATA",
-       "CERT_DATA",
-       "CERTREQ_DATA",
-       "EAP_DATA",
-       "SPIS",
-       "VID_DATA",
-       "UNKNOWN_DATA",
+       "CHUNK_DATA",
        "IKE_SPI",
-       "ENCRYPTED_DATA",
 );
index d035522..f6208b8 100644 (file)
@@ -187,31 +187,6 @@ enum encoding_type_t {
        SPI,
 
        /**
-        * Representating a Key Exchange Data field.
-        *
-        * When generating the content of the chunkt pointing to
-        * is written.
-        *
-        * When parsing (Payload Length - 8) bytes are read and written into the chunk pointing to.
-        */
-       KEY_EXCHANGE_DATA,
-
-       /**
-        * Same as KEY_EXCHANGE_DATA, but for KEY_EXCHANGE_V1
-        */
-       KEY_EXCHANGE_DATA_V1,
-
-       /**
-        * Representating a Notification field.
-        *
-        * When generating the content of the chunkt pointing to
-        * is written.
-        *
-        * When parsing (Payload Length - spi size - 8) bytes are read and written into the chunk pointing to.
-        */
-       NOTIFICATION_DATA,
-
-       /**
         * Representating one or more proposal substructures.
         *
         * The offset points to a linked_list_t pointer.
@@ -279,15 +254,6 @@ enum encoding_type_t {
        CONFIGURATION_ATTRIBUTES,
 
        /**
-        *
-        * When generating the content of the chunkt pointing to
-        * is written.
-        *
-        * When parsing (Payload Length - 4) bytes are read and written into the chunk pointing to.
-        */
-       CONFIGURATION_ATTRIBUTE_VALUE,
-
-       /**
         * Representing a 1 Bit flag specifying the format of a transform attribute.
         *
         * When generation, the next bit is set to 1 if the associated value
@@ -299,6 +265,7 @@ enum encoding_type_t {
         * is moved 1 bit forward afterwards.
         */
        ATTRIBUTE_FORMAT,
+
        /**
         * Representing a 15 Bit unsigned int value used as attribute type
         * in an attribute transform.
@@ -395,104 +362,9 @@ enum encoding_type_t {
        ADDRESS,
 
        /**
-        * Representating a Nonce Data field.
-        *
-        * When generating the content of the chunkt pointing to
-        * is written.
-        *
-        * When parsing (Payload Length - 4) bytes are read and written into the chunk pointing to.
-        */
-       NONCE_DATA,
-
-       /**
-        * Representating a Hash Data field.
-        *
-        * When generating the content of the chunkt pointing to
-        * is written.
-        *
-        * When parsing (Payload Length - 4) bytes are read and written into the chunk pointing to.
-        */
-       HASH_DATA,
-
-       /**
-        * Representating a ID Data field.
-        *
-        * When generating the content of the chunkt pointing to
-        * is written.
-        *
-        * When parsing (Payload Length - 8) bytes are read and written into the chunk pointing to.
+        * Representing a variable length byte field.
         */
-       ID_DATA,
-
-       /**
-        * Representating a AUTH Data field.
-        *
-        * When generating the content of the chunkt pointing to
-        * is written.
-        *
-        * When parsing (Payload Length - 8) bytes are read and written into the chunk pointing to.
-        */
-       AUTH_DATA,
-
-       /**
-        * Representating a CERT Data field.
-        *
-        * When generating the content of the chunkt pointing to
-        * is written.
-        *
-        * When parsing (Payload Length - 5) bytes are read and written into the chunk pointing to.
-        */
-       CERT_DATA,
-
-       /**
-        * Representating a CERTREQ Data field.
-        *
-        * When generating the content of the chunkt pointing to
-        * is written.
-        *
-        * When parsing (Payload Length - 5) bytes are read and written into the chunk pointing to.
-        */
-       CERTREQ_DATA,
-
-       /**
-        * Representating an EAP message field.
-        *
-        * When generating the content of the chunkt pointing to
-        * is written.
-        *
-        * When parsing (Payload Length - 4) bytes are read and written into the chunk pointing to.
-        */
-       EAP_DATA,
-
-       /**
-        * Representating the SPIS field in a DELETE payload.
-        *
-        * When generating the content of the chunkt pointing to
-        * is written.
-        *
-        * When parsing (Payload Length - 8) bytes are read and written into the chunk pointing to.
-        */
-       SPIS,
-
-       /**
-        * Representating the VID DATA field in a VENDOR ID payload.
-        *
-        * When generating the content of the chunkt pointing to
-        * is written.
-        *
-        * When parsing (Payload Length - 4) bytes are read and written into the chunk pointing to.
-        */
-       VID_DATA,
-
-       /**
-        * Representating the DATA of an unknown payload.
-        *
-        * When generating the content of the chunkt pointing to
-        * is written.
-        *
-        * When parsing (Payload Length - 4) bytes are read and written into the chunk pointing to.
-        */
-       UNKNOWN_DATA,
+       CHUNK_DATA,
 
        /**
         * Representating an IKE_SPI field in an IKEv2 Header.
@@ -503,11 +375,6 @@ enum encoding_type_t {
         * When parsing 8 bytes are read and written into the u_int64_t pointing to.
         */
        IKE_SPI,
-
-       /**
-        * Representing the encrypted data body of a encryption payload.
-        */
-       ENCRYPTED_DATA,
 };
 
 /**
index 08c64fb..bb9969d 100644 (file)
@@ -87,7 +87,7 @@ static encoding_rule_t encodings[] = {
        /* Length of the whole encryption payload*/
        { PAYLOAD_LENGTH,       offsetof(private_encryption_payload_t, payload_length)  },
        /* encrypted data, stored in a chunk. contains iv, data, padding */
-       { ENCRYPTED_DATA,       offsetof(private_encryption_payload_t, encrypted)               },
+       { CHUNK_DATA,           offsetof(private_encryption_payload_t, encrypted)               },
 };
 
 /*
index ff968ee..9542b1c 100644 (file)
@@ -62,7 +62,7 @@ static encoding_rule_t encodings[] = {
        /* Length of the whole payload*/
        { PAYLOAD_LENGTH,       offsetof(private_hash_payload_t, payload_length)        },
        /* Hash Data is from variable size */
-       { HASH_DATA,            offsetof(private_hash_payload_t, hash)                          },
+       { CHUNK_DATA,           offsetof(private_hash_payload_t, hash)                          },
 };
 
 /*
index f936e9a..108d56b 100644 (file)
@@ -112,7 +112,7 @@ static encoding_rule_t encodings_v2[] = {
        { RESERVED_BYTE,        offsetof(private_id_payload_t, reserved_byte[1])},
        { RESERVED_BYTE,        offsetof(private_id_payload_t, reserved_byte[2])},
        /* some id data bytes, length is defined in PAYLOAD_LENGTH */
-       { ID_DATA,                      offsetof(private_id_payload_t, id_data)                 },
+       { CHUNK_DATA,           offsetof(private_id_payload_t, id_data)                 },
 };
 
 /*
@@ -144,7 +144,7 @@ static encoding_rule_t encodings_v1[] = {
        { U_INT_8,                      offsetof(private_id_payload_t, protocol_id)             },
        { U_INT_16,                     offsetof(private_id_payload_t, port)                    },
        /* some id data bytes, length is defined in PAYLOAD_LENGTH */
-       { ID_DATA,                      offsetof(private_id_payload_t, id_data)                 },
+       { CHUNK_DATA,           offsetof(private_id_payload_t, id_data)                 },
 };
 
 /*
index a6e5217..438ea46 100644 (file)
@@ -98,7 +98,7 @@ static encoding_rule_t encodings_v2[] = {
        { RESERVED_BYTE,                offsetof(private_ke_payload_t, reserved_byte[0])},
        { RESERVED_BYTE,                offsetof(private_ke_payload_t, reserved_byte[1])},
        /* Key Exchange Data is from variable size */
-       { KEY_EXCHANGE_DATA,    offsetof(private_ke_payload_t, key_exchange_data)},
+       { CHUNK_DATA,                   offsetof(private_ke_payload_t, key_exchange_data)},
 };
 
 /*
@@ -123,7 +123,7 @@ static encoding_rule_t encodings_v1[] = {
        /* Length of the whole payload*/
        { PAYLOAD_LENGTH,               offsetof(private_ke_payload_t, payload_length)  },
        /* Key Exchange Data is from variable size */
-       { KEY_EXCHANGE_DATA_V1, offsetof(private_ke_payload_t, key_exchange_data)},
+       { CHUNK_DATA,                   offsetof(private_ke_payload_t, key_exchange_data)},
 };
 
 /*
index 1e0cf55..58ef70a 100644 (file)
@@ -86,7 +86,7 @@ static encoding_rule_t encodings[] = {
        /* Length of the whole nonce payload*/
        { PAYLOAD_LENGTH,       offsetof(private_nonce_payload_t, payload_length)       },
        /* some nonce bytes, lenth is defined in PAYLOAD_LENGTH */
-       { NONCE_DATA,           offsetof(private_nonce_payload_t, nonce)                        },
+       { CHUNK_DATA,           offsetof(private_nonce_payload_t, nonce)                        },
 };
 
 /*                           1                   2                   3
index f2e1267..7dab941 100644 (file)
@@ -287,7 +287,7 @@ static encoding_rule_t encodings[] = {
        /* SPI as variable length field*/
        { SPI,                          offsetof(private_notify_payload_t, spi)                                 },
        /* Key Exchange Data is from variable size */
-       { NOTIFICATION_DATA,offsetof(private_notify_payload_t, notification_data)       }
+       { CHUNK_DATA,           offsetof(private_notify_payload_t, notification_data)   }
 };
 
 /*
index 29dfa9d..fe7ced2 100644 (file)
@@ -84,7 +84,7 @@ static encoding_rule_t encodings[] = {
        /* Length of the whole payload*/
        { PAYLOAD_LENGTH,       offsetof(private_unknown_payload_t, payload_length)     },
        /* some unknown data bytes, length is defined in PAYLOAD_LENGTH */
-       { UNKNOWN_DATA,         offsetof(private_unknown_payload_t, data)                       },
+       { CHUNK_DATA,           offsetof(private_unknown_payload_t, data)                       },
 };
 
 /*
index 8a1d997..0c1df56 100644 (file)
@@ -84,7 +84,7 @@ static encoding_rule_t encodings[] = {
        /* Length of the whole payload*/
        { PAYLOAD_LENGTH,       offsetof(private_vendor_id_payload_t, payload_length)},
        /* some vendor_id data bytes, length is defined in PAYLOAD_LENGTH */
-       { VID_DATA,                     offsetof(private_vendor_id_payload_t, data)                     }
+       { CHUNK_DATA,           offsetof(private_vendor_id_payload_t, data)                     }
 };
 
 /*