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:
|
case CHUNK_DATA:
|
||||||
generate_from_chunk(this, rules[i].offset);
|
generate_from_chunk(this, rules[i].offset);
|
||||||
break;
|
break;
|
||||||
case PROPOSALS:
|
case PAYLOAD_LIST + PROPOSAL_SUBSTRUCTURE:
|
||||||
case PROPOSALS_V1:
|
case PAYLOAD_LIST + PROPOSAL_SUBSTRUCTURE_V1:
|
||||||
case TRANSFORMS:
|
case PAYLOAD_LIST + TRANSFORM_SUBSTRUCTURE:
|
||||||
case TRANSFORMS_V1:
|
case PAYLOAD_LIST + TRANSFORM_SUBSTRUCTURE_V1:
|
||||||
case TRANSFORM_ATTRIBUTES:
|
case PAYLOAD_LIST + TRANSFORM_ATTRIBUTE:
|
||||||
case TRANSFORM_ATTRIBUTES_V1:
|
case PAYLOAD_LIST + TRANSFORM_ATTRIBUTE_V1:
|
||||||
case CONFIGURATION_ATTRIBUTES:
|
case PAYLOAD_LIST + CONFIGURATION_ATTRIBUTE:
|
||||||
case TRAFFIC_SELECTORS:
|
case PAYLOAD_LIST + TRAFFIC_SELECTOR_SUBSTRUCTURE:
|
||||||
{
|
{
|
||||||
linked_list_t *proposals;
|
linked_list_t *proposals;
|
||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
|
|||||||
@@ -358,34 +358,6 @@ static bool parse_chunk(private_parser_t *this, int rule_number,
|
|||||||
return TRUE;
|
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,
|
METHOD(parser_t, parse_payload, status_t,
|
||||||
private_parser_t *this, payload_type_t payload_type, payload_t **payload)
|
private_parser_t *this, payload_type_t payload_type, payload_t **payload)
|
||||||
{
|
{
|
||||||
@@ -513,18 +485,18 @@ METHOD(parser_t, parse_payload, status_t,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* lists */
|
case PAYLOAD_LIST + PROPOSAL_SUBSTRUCTURE:
|
||||||
case PROPOSALS:
|
case PAYLOAD_LIST + PROPOSAL_SUBSTRUCTURE_V1:
|
||||||
case PROPOSALS_V1:
|
case PAYLOAD_LIST + TRANSFORM_SUBSTRUCTURE:
|
||||||
case TRANSFORMS:
|
case PAYLOAD_LIST + TRANSFORM_SUBSTRUCTURE_V1:
|
||||||
case TRANSFORMS_V1:
|
case PAYLOAD_LIST + TRANSFORM_ATTRIBUTE:
|
||||||
case TRANSFORM_ATTRIBUTES:
|
case PAYLOAD_LIST + TRANSFORM_ATTRIBUTE_V1:
|
||||||
case TRANSFORM_ATTRIBUTES_V1:
|
case PAYLOAD_LIST + CONFIGURATION_ATTRIBUTE:
|
||||||
case TRAFFIC_SELECTORS:
|
case PAYLOAD_LIST + TRAFFIC_SELECTOR_SUBSTRUCTURE:
|
||||||
{
|
{
|
||||||
if (payload_length < header_length ||
|
if (payload_length < header_length ||
|
||||||
!parse_list(this, rule_number, output + rule->offset,
|
!parse_list(this, rule_number, output + rule->offset,
|
||||||
map_wrapped_payload(rule->type),
|
rule->type - PAYLOAD_LIST,
|
||||||
payload_length - header_length))
|
payload_length - header_length))
|
||||||
{
|
{
|
||||||
pld->destroy(pld);
|
pld->destroy(pld);
|
||||||
|
|||||||
@@ -98,14 +98,14 @@ static encoding_rule_t encodings[] = {
|
|||||||
{ RESERVED_BIT, offsetof(private_cp_payload_t, reserved_bit[6]) },
|
{ RESERVED_BIT, offsetof(private_cp_payload_t, reserved_bit[6]) },
|
||||||
/* Length of the whole CP payload*/
|
/* Length of the whole CP payload*/
|
||||||
{ PAYLOAD_LENGTH, offsetof(private_cp_payload_t, payload_length) },
|
{ 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) },
|
{ U_INT_8, offsetof(private_cp_payload_t, type) },
|
||||||
/* 3 reserved bytes */
|
/* 3 reserved bytes */
|
||||||
{ RESERVED_BYTE, offsetof(private_cp_payload_t, reserved_byte[0])},
|
{ 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[1])},
|
||||||
{ RESERVED_BYTE, offsetof(private_cp_payload_t, reserved_byte[2])},
|
{ RESERVED_BYTE, offsetof(private_cp_payload_t, reserved_byte[2])},
|
||||||
{ CONFIGURATION_ATTRIBUTES, offsetof(private_cp_payload_t, attributes) }
|
/* 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",
|
"HEADER_LENGTH",
|
||||||
"SPI_SIZE",
|
"SPI_SIZE",
|
||||||
"SPI",
|
"SPI",
|
||||||
"PROPOSALS",
|
|
||||||
"PROPOSALS_V1",
|
|
||||||
"TRANSFORMS",
|
|
||||||
"TRANSFORMS_V1",
|
|
||||||
"TRANSFORM_ATTRIBUTES",
|
|
||||||
"TRANSFORM_ATTRIBUTES_V1",
|
|
||||||
"CONFIGURATION_ATTRIBUTES",
|
|
||||||
"ATTRIBUTE_FORMAT",
|
"ATTRIBUTE_FORMAT",
|
||||||
"ATTRIBUTE_TYPE",
|
"ATTRIBUTE_TYPE",
|
||||||
"ATTRIBUTE_LENGTH_OR_VALUE",
|
"ATTRIBUTE_LENGTH_OR_VALUE",
|
||||||
"CONFIGURATION_ATTRIBUTE_LENGTH",
|
"CONFIGURATION_ATTRIBUTE_LENGTH",
|
||||||
"ATTRIBUTE_VALUE",
|
"ATTRIBUTE_VALUE",
|
||||||
"TRAFFIC_SELECTORS",
|
|
||||||
"TS_TYPE",
|
"TS_TYPE",
|
||||||
"ADDRESS",
|
"ADDRESS",
|
||||||
"CHUNK_DATA",
|
"CHUNK_DATA",
|
||||||
|
|||||||
@@ -186,73 +186,6 @@ enum encoding_type_t {
|
|||||||
*/
|
*/
|
||||||
SPI,
|
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.
|
* Representing a 1 Bit flag specifying the format of a transform attribute.
|
||||||
*
|
*
|
||||||
@@ -322,19 +255,6 @@ enum encoding_type_t {
|
|||||||
*/
|
*/
|
||||||
ATTRIBUTE_VALUE,
|
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.
|
* 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.
|
* When parsing 8 bytes are read and written into the u_int64_t pointing to.
|
||||||
*/
|
*/
|
||||||
IKE_SPI,
|
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) },
|
{ U_INT_8, offsetof(private_proposal_substructure_t, transforms_count) },
|
||||||
/* SPI is a chunk of variable size*/
|
/* SPI is a chunk of variable size*/
|
||||||
{ SPI, offsetof(private_proposal_substructure_t, spi) },
|
{ SPI, offsetof(private_proposal_substructure_t, spi) },
|
||||||
/* Transforms are stored in a transform substructure,
|
/* Transforms are stored in a transform substructure list */
|
||||||
offset points to a linked_list_t pointer */
|
{ PAYLOAD_LIST + TRANSFORM_SUBSTRUCTURE_V1,
|
||||||
{ TRANSFORMS_V1, offsetof(private_proposal_substructure_t, transforms) }
|
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) },
|
{ U_INT_8, offsetof(private_proposal_substructure_t, transforms_count) },
|
||||||
/* SPI is a chunk of variable size*/
|
/* SPI is a chunk of variable size*/
|
||||||
{ SPI, offsetof(private_proposal_substructure_t, spi) },
|
{ SPI, offsetof(private_proposal_substructure_t, spi) },
|
||||||
/* Transforms are stored in a transform substructure,
|
/* Transforms are stored in a transform substructure list */
|
||||||
offset points to a linked_list_t pointer */
|
{ PAYLOAD_LIST + TRANSFORM_SUBSTRUCTURE,
|
||||||
{ TRANSFORMS, offsetof(private_proposal_substructure_t, transforms) }
|
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) },
|
{ U_INT_32, offsetof(private_sa_payload_t, doi) },
|
||||||
/* Situation*/
|
/* Situation*/
|
||||||
{ U_INT_32, offsetof(private_sa_payload_t, situation) },
|
{ U_INT_32, offsetof(private_sa_payload_t, situation) },
|
||||||
/* Proposals are stored in a proposal substructure,
|
/* Proposals are stored in a proposal substructure list */
|
||||||
offset points to a linked_list_t pointer */
|
{ PAYLOAD_LIST + PROPOSAL_SUBSTRUCTURE_V1,
|
||||||
{ PROPOSALS_V1, offsetof(private_sa_payload_t, proposals) },
|
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]) },
|
{ RESERVED_BIT, offsetof(private_sa_payload_t, reserved[6]) },
|
||||||
/* Length of the whole SA payload*/
|
/* Length of the whole SA payload*/
|
||||||
{ PAYLOAD_LENGTH, offsetof(private_sa_payload_t, payload_length) },
|
{ PAYLOAD_LENGTH, offsetof(private_sa_payload_t, payload_length) },
|
||||||
/* Proposals are stored in a proposal substructure,
|
/* Proposals are stored in a proposal substructure list */
|
||||||
offset points to a linked_list_t pointer */
|
{ PAYLOAD_LIST + PROPOSAL_SUBSTRUCTURE,
|
||||||
{ PROPOSALS, offsetof(private_sa_payload_t, proposals) },
|
offsetof(private_sa_payload_t, proposals) },
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -95,7 +95,8 @@ static encoding_rule_t encodings_v2[] = {
|
|||||||
/* transform identifier, as used by IKEv2 */
|
/* 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 */
|
/* Attributes in a transform attribute list */
|
||||||
{ TRANSFORM_ATTRIBUTES, offsetof(private_transform_substructure_t, attributes) }
|
{ PAYLOAD_LIST + TRANSFORM_ATTRIBUTE,
|
||||||
|
offsetof(private_transform_substructure_t, attributes) }
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -116,7 +117,8 @@ static encoding_rule_t encodings_v1[] = {
|
|||||||
{ RESERVED_BYTE, offsetof(private_transform_substructure_t, reserved[1]) },
|
{ 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[2]) },
|
||||||
/* Attributes in a transform attribute list */
|
/* 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[0])},
|
||||||
{ RESERVED_BYTE, offsetof(private_ts_payload_t, reserved_byte[1])},
|
{ RESERVED_BYTE, offsetof(private_ts_payload_t, reserved_byte[1])},
|
||||||
{ RESERVED_BYTE, offsetof(private_ts_payload_t, reserved_byte[2])},
|
{ RESERVED_BYTE, offsetof(private_ts_payload_t, reserved_byte[2])},
|
||||||
/* some ts data bytes, length is defined in PAYLOAD_LENGTH */
|
/* wrapped list of traffic selectors substructures */
|
||||||
{ TRAFFIC_SELECTORS,offsetof(private_ts_payload_t, substrs) }
|
{ PAYLOAD_LIST + TRAFFIC_SELECTOR_SUBSTRUCTURE,
|
||||||
|
offsetof(private_ts_payload_t, substrs) },
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user