Use a generic list encoding rule we can use to specify the wrapped payload type
This commit is contained in:
@@ -451,14 +451,14 @@ METHOD(generator_t, generate_payload, void,
|
||||
case CHUNK_DATA:
|
||||
generate_from_chunk(this, rules[i].offset);
|
||||
break;
|
||||
case PROPOSALS:
|
||||
case PROPOSALS_V1:
|
||||
case TRANSFORMS:
|
||||
case TRANSFORMS_V1:
|
||||
case TRANSFORM_ATTRIBUTES:
|
||||
case TRANSFORM_ATTRIBUTES_V1:
|
||||
case CONFIGURATION_ATTRIBUTES:
|
||||
case TRAFFIC_SELECTORS:
|
||||
case PAYLOAD_LIST + PROPOSAL_SUBSTRUCTURE:
|
||||
case PAYLOAD_LIST + PROPOSAL_SUBSTRUCTURE_V1:
|
||||
case PAYLOAD_LIST + TRANSFORM_SUBSTRUCTURE:
|
||||
case PAYLOAD_LIST + TRANSFORM_SUBSTRUCTURE_V1:
|
||||
case PAYLOAD_LIST + TRANSFORM_ATTRIBUTE:
|
||||
case PAYLOAD_LIST + TRANSFORM_ATTRIBUTE_V1:
|
||||
case PAYLOAD_LIST + CONFIGURATION_ATTRIBUTE:
|
||||
case PAYLOAD_LIST + TRAFFIC_SELECTOR_SUBSTRUCTURE:
|
||||
{
|
||||
linked_list_t *proposals;
|
||||
enumerator_t *enumerator;
|
||||
|
||||
@@ -358,34 +358,6 @@ static bool parse_chunk(private_parser_t *this, int rule_number,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a encoding type to a encoded payload
|
||||
*/
|
||||
static payload_type_t map_wrapped_payload(encoding_type_t type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case PROPOSALS:
|
||||
return PROPOSAL_SUBSTRUCTURE;
|
||||
case PROPOSALS_V1:
|
||||
return PROPOSAL_SUBSTRUCTURE_V1;
|
||||
case TRANSFORMS:
|
||||
return TRANSFORM_SUBSTRUCTURE;
|
||||
case TRANSFORMS_V1:
|
||||
return TRANSFORM_SUBSTRUCTURE_V1;
|
||||
case TRANSFORM_ATTRIBUTES:
|
||||
return TRANSFORM_ATTRIBUTE;
|
||||
case TRANSFORM_ATTRIBUTES_V1:
|
||||
return TRANSFORM_ATTRIBUTE_V1;
|
||||
case CONFIGURATION_ATTRIBUTES:
|
||||
return CONFIGURATION_ATTRIBUTE;
|
||||
case TRAFFIC_SELECTORS:
|
||||
return TRAFFIC_SELECTOR_SUBSTRUCTURE;
|
||||
default:
|
||||
return NO_PAYLOAD;
|
||||
}
|
||||
}
|
||||
|
||||
METHOD(parser_t, parse_payload, status_t,
|
||||
private_parser_t *this, payload_type_t payload_type, payload_t **payload)
|
||||
{
|
||||
@@ -513,18 +485,18 @@ METHOD(parser_t, parse_payload, status_t,
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* lists */
|
||||
case PROPOSALS:
|
||||
case PROPOSALS_V1:
|
||||
case TRANSFORMS:
|
||||
case TRANSFORMS_V1:
|
||||
case TRANSFORM_ATTRIBUTES:
|
||||
case TRANSFORM_ATTRIBUTES_V1:
|
||||
case TRAFFIC_SELECTORS:
|
||||
case PAYLOAD_LIST + PROPOSAL_SUBSTRUCTURE:
|
||||
case PAYLOAD_LIST + PROPOSAL_SUBSTRUCTURE_V1:
|
||||
case PAYLOAD_LIST + TRANSFORM_SUBSTRUCTURE:
|
||||
case PAYLOAD_LIST + TRANSFORM_SUBSTRUCTURE_V1:
|
||||
case PAYLOAD_LIST + TRANSFORM_ATTRIBUTE:
|
||||
case PAYLOAD_LIST + TRANSFORM_ATTRIBUTE_V1:
|
||||
case PAYLOAD_LIST + CONFIGURATION_ATTRIBUTE:
|
||||
case PAYLOAD_LIST + TRAFFIC_SELECTOR_SUBSTRUCTURE:
|
||||
{
|
||||
if (payload_length < header_length ||
|
||||
!parse_list(this, rule_number, output + rule->offset,
|
||||
map_wrapped_payload(rule->type),
|
||||
rule->type - PAYLOAD_LIST,
|
||||
payload_length - header_length))
|
||||
{
|
||||
pld->destroy(pld);
|
||||
|
||||
@@ -85,27 +85,27 @@ struct private_cp_payload_t {
|
||||
*/
|
||||
static encoding_rule_t encodings[] = {
|
||||
/* 1 Byte next payload type, stored in the field next_payload */
|
||||
{ U_INT_8, offsetof(private_cp_payload_t, next_payload) },
|
||||
{ U_INT_8, offsetof(private_cp_payload_t, next_payload) },
|
||||
/* the critical bit */
|
||||
{ FLAG, offsetof(private_cp_payload_t, critical) },
|
||||
{ FLAG, offsetof(private_cp_payload_t, critical) },
|
||||
/* 7 Bit reserved bits */
|
||||
{ RESERVED_BIT, offsetof(private_cp_payload_t, reserved_bit[0]) },
|
||||
{ RESERVED_BIT, offsetof(private_cp_payload_t, reserved_bit[1]) },
|
||||
{ RESERVED_BIT, offsetof(private_cp_payload_t, reserved_bit[2]) },
|
||||
{ RESERVED_BIT, offsetof(private_cp_payload_t, reserved_bit[3]) },
|
||||
{ RESERVED_BIT, offsetof(private_cp_payload_t, reserved_bit[4]) },
|
||||
{ RESERVED_BIT, offsetof(private_cp_payload_t, reserved_bit[5]) },
|
||||
{ RESERVED_BIT, offsetof(private_cp_payload_t, reserved_bit[6]) },
|
||||
{ RESERVED_BIT, offsetof(private_cp_payload_t, reserved_bit[0]) },
|
||||
{ RESERVED_BIT, offsetof(private_cp_payload_t, reserved_bit[1]) },
|
||||
{ RESERVED_BIT, offsetof(private_cp_payload_t, reserved_bit[2]) },
|
||||
{ RESERVED_BIT, offsetof(private_cp_payload_t, reserved_bit[3]) },
|
||||
{ RESERVED_BIT, offsetof(private_cp_payload_t, reserved_bit[4]) },
|
||||
{ RESERVED_BIT, offsetof(private_cp_payload_t, reserved_bit[5]) },
|
||||
{ RESERVED_BIT, offsetof(private_cp_payload_t, reserved_bit[6]) },
|
||||
/* Length of the whole CP payload*/
|
||||
{ PAYLOAD_LENGTH, offsetof(private_cp_payload_t, payload_length) },
|
||||
/* Proposals are stored in a proposal substructure,
|
||||
offset points to a linked_list_t pointer */
|
||||
{ U_INT_8, offsetof(private_cp_payload_t, type) },
|
||||
{ PAYLOAD_LENGTH, offsetof(private_cp_payload_t, payload_length) },
|
||||
{ U_INT_8, offsetof(private_cp_payload_t, type) },
|
||||
/* 3 reserved bytes */
|
||||
{ RESERVED_BYTE, offsetof(private_cp_payload_t, reserved_byte[0])},
|
||||
{ RESERVED_BYTE, offsetof(private_cp_payload_t, reserved_byte[1])},
|
||||
{ RESERVED_BYTE, offsetof(private_cp_payload_t, reserved_byte[2])},
|
||||
{ CONFIGURATION_ATTRIBUTES, offsetof(private_cp_payload_t, attributes) }
|
||||
{ RESERVED_BYTE, offsetof(private_cp_payload_t, reserved_byte[0])},
|
||||
{ RESERVED_BYTE, offsetof(private_cp_payload_t, reserved_byte[1])},
|
||||
{ RESERVED_BYTE, offsetof(private_cp_payload_t, reserved_byte[2])},
|
||||
/* list of configuration attributes in a list */
|
||||
{ PAYLOAD_LIST + CONFIGURATION_ATTRIBUTE,
|
||||
offsetof(private_cp_payload_t, attributes) },
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@@ -29,19 +29,11 @@ ENUM(encoding_type_names, U_INT_4, IKE_SPI,
|
||||
"HEADER_LENGTH",
|
||||
"SPI_SIZE",
|
||||
"SPI",
|
||||
"PROPOSALS",
|
||||
"PROPOSALS_V1",
|
||||
"TRANSFORMS",
|
||||
"TRANSFORMS_V1",
|
||||
"TRANSFORM_ATTRIBUTES",
|
||||
"TRANSFORM_ATTRIBUTES_V1",
|
||||
"CONFIGURATION_ATTRIBUTES",
|
||||
"ATTRIBUTE_FORMAT",
|
||||
"ATTRIBUTE_TYPE",
|
||||
"ATTRIBUTE_LENGTH_OR_VALUE",
|
||||
"CONFIGURATION_ATTRIBUTE_LENGTH",
|
||||
"ATTRIBUTE_VALUE",
|
||||
"TRAFFIC_SELECTORS",
|
||||
"TS_TYPE",
|
||||
"ADDRESS",
|
||||
"CHUNK_DATA",
|
||||
|
||||
@@ -186,73 +186,6 @@ enum encoding_type_t {
|
||||
*/
|
||||
SPI,
|
||||
|
||||
/**
|
||||
* Representating one or more proposal substructures.
|
||||
*
|
||||
* The offset points to a linked_list_t pointer.
|
||||
*
|
||||
* When generating the proposal_substructure_t objects are stored
|
||||
* in the pointed linked_list.
|
||||
*
|
||||
* When parsing the parsed proposal_substructure_t objects have
|
||||
* to be stored in the pointed linked_list.
|
||||
*/
|
||||
PROPOSALS,
|
||||
|
||||
/**
|
||||
* Same as PROPOSALS, but for IKEv1 in a SECURITY_ASSOCIATION_V1
|
||||
*/
|
||||
PROPOSALS_V1,
|
||||
|
||||
/**
|
||||
* Representating one or more transform substructures.
|
||||
*
|
||||
* The offset points to a linked_list_t pointer.
|
||||
*
|
||||
* When generating the transform_substructure_t objects are stored
|
||||
* in the pointed linked_list.
|
||||
*
|
||||
* When parsing the parsed transform_substructure_t objects have
|
||||
* to be stored in the pointed linked_list.
|
||||
*/
|
||||
TRANSFORMS,
|
||||
|
||||
/**
|
||||
* Same as TRANSFORMS, but for IKEv1 in a PROPOSAL_SUBSTRUCTURE_V1.
|
||||
*/
|
||||
TRANSFORMS_V1,
|
||||
|
||||
/**
|
||||
* Representating one or more Attributes of a transform substructure.
|
||||
*
|
||||
* The offset points to a linked_list_t pointer.
|
||||
*
|
||||
* When generating the transform_attribute_t objects are stored
|
||||
* in the pointed linked_list.
|
||||
*
|
||||
* When parsing the parsed transform_attribute_t objects have
|
||||
* to be stored in the pointed linked_list.
|
||||
*/
|
||||
TRANSFORM_ATTRIBUTES,
|
||||
|
||||
/**
|
||||
* Same as TRANSFORM_ATTRIBUTES, but for IKEv1 in TRANSFORMS_V1.
|
||||
*/
|
||||
TRANSFORM_ATTRIBUTES_V1,
|
||||
|
||||
/**
|
||||
* Representating one or more Attributes of a configuration payload.
|
||||
*
|
||||
* The offset points to a linked_list_t pointer.
|
||||
*
|
||||
* When generating the configuration_attribute_t objects are stored
|
||||
* in the pointed linked_list.
|
||||
*
|
||||
* When parsing the parsed configuration_attribute_t objects have
|
||||
* to be stored in the pointed linked_list.
|
||||
*/
|
||||
CONFIGURATION_ATTRIBUTES,
|
||||
|
||||
/**
|
||||
* Representing a 1 Bit flag specifying the format of a transform attribute.
|
||||
*
|
||||
@@ -322,19 +255,6 @@ enum encoding_type_t {
|
||||
*/
|
||||
ATTRIBUTE_VALUE,
|
||||
|
||||
/**
|
||||
* Representating one or more Traffic selectors of a TS payload.
|
||||
*
|
||||
* The offset points to a linked_list_t pointer.
|
||||
*
|
||||
* When generating the traffic_selector_substructure_t objects are stored
|
||||
* in the pointed linked_list.
|
||||
*
|
||||
* When parsing the parsed traffic_selector_substructure_t objects have
|
||||
* to be stored in the pointed linked_list.
|
||||
*/
|
||||
TRAFFIC_SELECTORS,
|
||||
|
||||
/**
|
||||
* Representating a Traffic selector type field.
|
||||
*
|
||||
@@ -375,6 +295,17 @@ enum encoding_type_t {
|
||||
* When parsing 8 bytes are read and written into the u_int64_t pointing to.
|
||||
*/
|
||||
IKE_SPI,
|
||||
|
||||
/**
|
||||
* Reprensenting a field containing a set of wrapped payloads.
|
||||
*
|
||||
* This type is not used directly, but as an offset to the wrapped payloads.
|
||||
* The type of the wrapped payload is added to this encoding type.
|
||||
*
|
||||
* @note As payload types are added to this encoding type, it has
|
||||
* to be the last in encoding_type_t.
|
||||
*/
|
||||
PAYLOAD_LIST = 1000 /* no comma, read above! */
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -112,9 +112,9 @@ static encoding_rule_t encodings_v1[] = {
|
||||
{ U_INT_8, offsetof(private_proposal_substructure_t, transforms_count) },
|
||||
/* SPI is a chunk of variable size*/
|
||||
{ SPI, offsetof(private_proposal_substructure_t, spi) },
|
||||
/* Transforms are stored in a transform substructure,
|
||||
offset points to a linked_list_t pointer */
|
||||
{ TRANSFORMS_V1, offsetof(private_proposal_substructure_t, transforms) }
|
||||
/* Transforms are stored in a transform substructure list */
|
||||
{ PAYLOAD_LIST + TRANSFORM_SUBSTRUCTURE_V1,
|
||||
offsetof(private_proposal_substructure_t, transforms) },
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -137,9 +137,9 @@ static encoding_rule_t encodings_v2[] = {
|
||||
{ U_INT_8, offsetof(private_proposal_substructure_t, transforms_count) },
|
||||
/* SPI is a chunk of variable size*/
|
||||
{ SPI, offsetof(private_proposal_substructure_t, spi) },
|
||||
/* Transforms are stored in a transform substructure,
|
||||
offset points to a linked_list_t pointer */
|
||||
{ TRANSFORMS, offsetof(private_proposal_substructure_t, transforms) }
|
||||
/* Transforms are stored in a transform substructure list */
|
||||
{ PAYLOAD_LIST + TRANSFORM_SUBSTRUCTURE,
|
||||
offsetof(private_proposal_substructure_t, transforms) },
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@@ -99,9 +99,9 @@ static encoding_rule_t encodings_v1[] = {
|
||||
{ U_INT_32, offsetof(private_sa_payload_t, doi) },
|
||||
/* Situation*/
|
||||
{ U_INT_32, offsetof(private_sa_payload_t, situation) },
|
||||
/* Proposals are stored in a proposal substructure,
|
||||
offset points to a linked_list_t pointer */
|
||||
{ PROPOSALS_V1, offsetof(private_sa_payload_t, proposals) },
|
||||
/* Proposals are stored in a proposal substructure list */
|
||||
{ PAYLOAD_LIST + PROPOSAL_SUBSTRUCTURE_V1,
|
||||
offsetof(private_sa_payload_t, proposals) },
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -138,9 +138,9 @@ static encoding_rule_t encodings_v2[] = {
|
||||
{ RESERVED_BIT, offsetof(private_sa_payload_t, reserved[6]) },
|
||||
/* Length of the whole SA payload*/
|
||||
{ PAYLOAD_LENGTH, offsetof(private_sa_payload_t, payload_length) },
|
||||
/* Proposals are stored in a proposal substructure,
|
||||
offset points to a linked_list_t pointer */
|
||||
{ PROPOSALS, offsetof(private_sa_payload_t, proposals) },
|
||||
/* Proposals are stored in a proposal substructure list */
|
||||
{ PAYLOAD_LIST + PROPOSAL_SUBSTRUCTURE,
|
||||
offsetof(private_sa_payload_t, proposals) },
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@@ -83,19 +83,20 @@ struct private_transform_substructure_t {
|
||||
*/
|
||||
static encoding_rule_t encodings_v2[] = {
|
||||
/* 1 Byte next payload type, stored in the field next_payload */
|
||||
{ U_INT_8, offsetof(private_transform_substructure_t, next_payload) },
|
||||
{ U_INT_8, offsetof(private_transform_substructure_t, next_payload) },
|
||||
/* 1 Reserved Byte */
|
||||
{ RESERVED_BYTE, offsetof(private_transform_substructure_t, reserved[0]) },
|
||||
{ RESERVED_BYTE, offsetof(private_transform_substructure_t, reserved[0]) },
|
||||
/* Length of the whole transform substructure*/
|
||||
{ PAYLOAD_LENGTH, offsetof(private_transform_substructure_t, transform_length)},
|
||||
{ PAYLOAD_LENGTH, offsetof(private_transform_substructure_t, transform_length)},
|
||||
/* transform type */
|
||||
{ U_INT_8, offsetof(private_transform_substructure_t, transform_ton) },
|
||||
{ U_INT_8, offsetof(private_transform_substructure_t, transform_ton) },
|
||||
/* transform identifier, as used by IKEv1 */
|
||||
{ RESERVED_BYTE, offsetof(private_transform_substructure_t, reserved[1]) },
|
||||
{ RESERVED_BYTE, offsetof(private_transform_substructure_t, reserved[1]) },
|
||||
/* transform identifier, as used by IKEv2 */
|
||||
{ U_INT_16, offsetof(private_transform_substructure_t, transform_id_v2) },
|
||||
{ U_INT_16, offsetof(private_transform_substructure_t, transform_id_v2) },
|
||||
/* Attributes in a transform attribute list */
|
||||
{ TRANSFORM_ATTRIBUTES, offsetof(private_transform_substructure_t, attributes) }
|
||||
{ PAYLOAD_LIST + TRANSFORM_ATTRIBUTE,
|
||||
offsetof(private_transform_substructure_t, attributes) }
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -103,20 +104,21 @@ static encoding_rule_t encodings_v2[] = {
|
||||
*/
|
||||
static encoding_rule_t encodings_v1[] = {
|
||||
/* 1 Byte next payload type, stored in the field next_payload */
|
||||
{ U_INT_8, offsetof(private_transform_substructure_t, next_payload) },
|
||||
{ U_INT_8, offsetof(private_transform_substructure_t, next_payload) },
|
||||
/* 1 Reserved Byte */
|
||||
{ RESERVED_BYTE, offsetof(private_transform_substructure_t, reserved[0]) },
|
||||
{ RESERVED_BYTE, offsetof(private_transform_substructure_t, reserved[0]) },
|
||||
/* Length of the whole transform substructure*/
|
||||
{ PAYLOAD_LENGTH, offsetof(private_transform_substructure_t, transform_length)},
|
||||
{ PAYLOAD_LENGTH, offsetof(private_transform_substructure_t, transform_length)},
|
||||
/* transform number */
|
||||
{ U_INT_8, offsetof(private_transform_substructure_t, transform_ton)},
|
||||
{ U_INT_8, offsetof(private_transform_substructure_t, transform_ton)},
|
||||
/* transform identifier, as used by IKEv1 */
|
||||
{ U_INT_8, offsetof(private_transform_substructure_t, transform_id_v1) },
|
||||
{ U_INT_8, offsetof(private_transform_substructure_t, transform_id_v1) },
|
||||
/* transform identifier, as used by IKEv2 */
|
||||
{ RESERVED_BYTE, offsetof(private_transform_substructure_t, reserved[1]) },
|
||||
{ RESERVED_BYTE, offsetof(private_transform_substructure_t, reserved[2]) },
|
||||
{ RESERVED_BYTE, offsetof(private_transform_substructure_t, reserved[1]) },
|
||||
{ RESERVED_BYTE, offsetof(private_transform_substructure_t, reserved[2]) },
|
||||
/* Attributes in a transform attribute list */
|
||||
{ TRANSFORM_ATTRIBUTES_V1, offsetof(private_transform_substructure_t, attributes) }
|
||||
{ PAYLOAD_LIST + TRANSFORM_ATTRIBUTE_V1,
|
||||
offsetof(private_transform_substructure_t, attributes) }
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@@ -102,8 +102,9 @@ static encoding_rule_t encodings[] = {
|
||||
{ RESERVED_BYTE, offsetof(private_ts_payload_t, reserved_byte[0])},
|
||||
{ RESERVED_BYTE, offsetof(private_ts_payload_t, reserved_byte[1])},
|
||||
{ RESERVED_BYTE, offsetof(private_ts_payload_t, reserved_byte[2])},
|
||||
/* some ts data bytes, length is defined in PAYLOAD_LENGTH */
|
||||
{ TRAFFIC_SELECTORS,offsetof(private_ts_payload_t, substrs) }
|
||||
/* wrapped list of traffic selectors substructures */
|
||||
{ PAYLOAD_LIST + TRAFFIC_SELECTOR_SUBSTRUCTURE,
|
||||
offsetof(private_ts_payload_t, substrs) },
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user