Use a generic encoding type for all variable length chunks
This commit is contained in:
parent
ee50a29385
commit
95a26523af
|
@ -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:
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) }
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
@ -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) }
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
@ -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) }
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
@ -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) }
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
@ -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) }
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
@ -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) },
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
@ -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",
|
||||
);
|
||||
|
|
|
@ -186,31 +186,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.
|
||||
*
|
||||
|
@ -278,15 +253,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.
|
||||
*
|
||||
|
@ -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.
|
||||
* Representing a variable length byte field.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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,
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -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) },
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
@ -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) },
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
@ -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) },
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
@ -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)},
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) }
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
@ -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) },
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
@ -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) }
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue