diff options
Diffstat (limited to 'Source/charon/encoding/payloads')
-rw-r--r-- | Source/charon/encoding/payloads/payload.c | 6 | ||||
-rw-r--r-- | Source/charon/encoding/payloads/payload.h | 82 | ||||
-rw-r--r-- | Source/charon/encoding/payloads/unknown_payload.c | 66 | ||||
-rw-r--r-- | Source/charon/encoding/payloads/unknown_payload.h | 57 |
4 files changed, 74 insertions, 137 deletions
diff --git a/Source/charon/encoding/payloads/payload.c b/Source/charon/encoding/payloads/payload.c index bd94eaa5f..b89e80a53 100644 --- a/Source/charon/encoding/payloads/payload.c +++ b/Source/charon/encoding/payloads/payload.c @@ -1,7 +1,7 @@ /** * @file payload.c * - * @brief Generic payload interface + * @brief Generic constructor to the payload_t interface. * * */ @@ -122,12 +122,10 @@ payload_t *payload_create(payload_type_t type) return (payload_t*)configuration_attribute_create(); case EXTENSIBLE_AUTHENTICATION: return (payload_t*)eap_payload_create(); - case UNKNOWN_PAYLOAD: - return (payload_t*)unknown_payload_create(); case ENCRYPTED: return (payload_t*)encryption_payload_create(); default: - return NULL; + return (payload_t*)unknown_payload_create(); } } diff --git a/Source/charon/encoding/payloads/payload.h b/Source/charon/encoding/payloads/payload.h index 6fbd94969..a3300656b 100644 --- a/Source/charon/encoding/payloads/payload.h +++ b/Source/charon/encoding/payloads/payload.h @@ -1,7 +1,7 @@ /** * @file payload.h * - * @brief Generic payload interface. + * @brief Interface payload_t. * * */ @@ -32,8 +32,7 @@ typedef enum payload_type_t payload_type_t; /** - * Payload-Types of a IKEv2-Message. - * + * @brief Payload-Types of a IKEv2-Message. * * Header and substructures are also defined as * payload types with values from PRIVATE USE space. @@ -43,87 +42,87 @@ typedef enum payload_type_t payload_type_t; enum payload_type_t{ /** - * NO_PAYLOAD + * End of payload list in next_payload */ NO_PAYLOAD = 0, /** - * SA + * The security association (SA) payload containing proposals. */ SECURITY_ASSOCIATION = 33, /** - * KE + * The key exchange (KE) payload containing diffie-hellman values. */ KEY_EXCHANGE = 34, /** - * IDi + * Identification for the original initiator (IDi). */ ID_INITIATOR = 35, /** - * IDr + * Identification for the original responder (IDr). */ ID_RESPONDER = 36, /** - * CERT + * Certificate payload with certificates (CERT). */ CERTIFICATE = 37, /** - * CERTREQ + * Certificate request payload (CERTREQ). */ CERTIFICATE_REQUEST = 38, /** - * AUTH + * Authentication payload contains auth data (AUTH). */ AUTHENTICATION = 39, /** - * Ni, Nr + * Nonces, for initator and responder (Ni, Nr, N) */ NONCE = 40, /** - * N + * Notif paylaod (N). */ NOTIFY = 41, /** - * D + * Delete payload (D) */ DELETE = 42, /** - * V + * Vendor id paylpoad (V). */ VENDOR_ID = 43, /** - * TSi + * Traffic selector for the original initiator (TSi). */ TRAFFIC_SELECTOR_INITIATOR = 44, /** - * TSr + * Traffic selector for the original responser (TSr). */ TRAFFIC_SELECTOR_RESPONDER = 45, /** - * E + * Encryption payload, contains other payloads (E). */ ENCRYPTED = 46, /** - * CP + * Configuration payload (CP). */ CONFIGURATION = 47, /** - * EAP + * Extensible authentication payload (EAP). */ EXTENSIBLE_AUTHENTICATION = 48, @@ -185,8 +184,8 @@ enum payload_type_t{ }; -/* - * Build string mapping array for payload_type_t. +/** + * String mappings for payload_type_t. */ extern mapping_t payload_type_m[]; @@ -194,21 +193,21 @@ extern mapping_t payload_type_m[]; typedef struct payload_t payload_t; /** - * @brief Generic interface for all payload types (inclusive - * header and substructures). + * @brief Generic interface for all payload types (incl.header and substructures). + * + * To handle all kinds of payloads on a generic way, this interface must + * be implemented by every payload. This allows parser_t/generator_t a simple + * handling of all payloads. + * + * @b Constructors: + * - payload_create() with the payload to instanciate. * * @ingroup payloads */ struct payload_t { - /** - * @brief Destroys a payload and all included substructures. - * - * @param this payload to destroy - */ - void (*destroy) (payload_t *this); /** - * @brief Get encoding rules for this payload + * @brief Get encoding rules for this payload. * * @param this calling object * @param[out] rules location to store pointer of first rule @@ -217,7 +216,7 @@ struct payload_t { void (*get_encoding_rules) (payload_t *this, encoding_rule_t **rules, size_t *rule_count); /** - * @brief get type of payload + * @brief Get type of payload. * * @param this calling object * @return type of this payload @@ -225,7 +224,7 @@ struct payload_t { payload_type_t (*get_type) (payload_t *this); /** - * @brief get type of next payload or zero if this is the last one + * @brief Get type of next payload or NO_PAYLOAD (0) if this is the last one. * * @param this calling object * @return type of next payload @@ -233,7 +232,7 @@ struct payload_t { payload_type_t (*get_next_type) (payload_t *this); /** - * @brief set type of next payload + * @brief Set type of next payload. * * @param this calling object * @param type type of next payload @@ -241,7 +240,7 @@ struct payload_t { void (*set_next_type) (payload_t *this,payload_type_t type); /** - * @brief get length of payload + * @brief Get length of payload. * * @param this calling object * @return length of this payload @@ -249,7 +248,7 @@ struct payload_t { size_t (*get_length) (payload_t *this); /** - * @brief Verifies payload structure and makes consistence check + * @brief Verifies payload structure and makes consistence check. * * @param this calling object * @return @@ -257,18 +256,25 @@ struct payload_t { * - FAILED if consistence not given */ status_t (*verify) (payload_t *this); + + /** + * @brief Destroys a payload and all included substructures. + * + * @param this payload to destroy + */ + void (*destroy) (payload_t *this); }; /** * @brief Create an empty payload. * * Useful for the parser, who wants a generic constructor for all payloads. - * It supports all payload_t methods. + * It supports all payload_t methods. If a payload type is not known, + * an unknwon_paylod is created with the chunk of data in it. * * @param type type of the payload to create * @return created payload */ - payload_t *payload_create(payload_type_t type); #endif /*PAYLOAD_H_*/ diff --git a/Source/charon/encoding/payloads/unknown_payload.c b/Source/charon/encoding/payloads/unknown_payload.c index 3e910ba8d..c162edc30 100644 --- a/Source/charon/encoding/payloads/unknown_payload.c +++ b/Source/charon/encoding/payloads/unknown_payload.c @@ -29,9 +29,9 @@ typedef struct private_unknown_payload_t private_unknown_payload_t; /** * Private data of an unknown_payload_t object. - * */ struct private_unknown_payload_t { + /** * Public unknown_payload_t interface. */ @@ -40,7 +40,7 @@ struct private_unknown_payload_t { /** * Next payload type. */ - u_int8_t next_payload; + u_int8_t next_payload; /** * Critical flag. @@ -53,18 +53,13 @@ struct private_unknown_payload_t { u_int16_t payload_length; /** - * Type of this payload. - */ - payload_type_t payload_type; - - /** * The contained data. */ chunk_t data; }; /** - * Encoding rules to parse or generate a EAP payload. + * Encoding rules to parse an payload which is not further specified. * * The defined offsets are the positions in a object of type * private_unknown_payload_t. @@ -86,7 +81,7 @@ encoding_rule_t unknown_payload_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) } + { UNKNOWN_DATA, offsetof(private_unknown_payload_t, data) } }; /* @@ -110,7 +105,7 @@ static status_t verify(private_unknown_payload_t *this) } /** - * Implementation of unknown_payload_t.get_encoding_rules. + * Implementation of payload_t.get_encoding_rules. */ static void get_encoding_rules(private_unknown_payload_t *this, encoding_rule_t **rules, size_t *rule_count) { @@ -143,22 +138,6 @@ static void set_next_type(private_unknown_payload_t *this,payload_type_t type) } /** - * Implementation of unknown_payload_t.set_real_type. - */ -static void set_real_type(private_unknown_payload_t *this,payload_type_t type) -{ - this->payload_type = type; -} - -/** - * Implementation of unknown_payload_t.get_real_type. - */ -static payload_type_t get_real_type(private_unknown_payload_t *this) -{ - return this->payload_type; -} - -/** * Implementation of payload_t.get_length. */ static size_t get_length(private_unknown_payload_t *this) @@ -167,17 +146,11 @@ static size_t get_length(private_unknown_payload_t *this) } /** - * Implementation of unknown_payload_t.set_data. + * Implementation of unknown_payload_t.get_data. */ -static void set_data (private_unknown_payload_t *this, chunk_t data) +static bool is_critical(private_unknown_payload_t *this) { - if (this->data.ptr != NULL) - { - allocator_free_chunk(&(this->data)); - } - this->data.ptr = allocator_clone_bytes(data.ptr,data.len); - this->data.len = data.len; - this->payload_length = DEFAULT_PAYLOAD_HEADER_LENGTH + this->data.len; + return this->critical; } /** @@ -189,21 +162,6 @@ static chunk_t get_data (private_unknown_payload_t *this) } /** - * Implementation of unknown_payload_t.get_data_clone. - */ -static chunk_t get_data_clone (private_unknown_payload_t *this) -{ - chunk_t cloned_data; - if (this->data.ptr == NULL) - { - return (this->data); - } - cloned_data.ptr = allocator_clone_bytes(this->data.ptr,this->data.len); - cloned_data.len = this->data.len; - return cloned_data; -} - -/** * Implementation of payload_t.destroy and unknown_payload_t.destroy. */ static void destroy(private_unknown_payload_t *this) @@ -234,17 +192,13 @@ unknown_payload_t *unknown_payload_create() /* public functions */ this->public.destroy = (void (*) (unknown_payload_t *)) destroy; - this->public.set_real_type = (void (*) (unknown_payload_t *,payload_type_t)) set_real_type; - this->public.get_real_type = (payload_type_t (*) (unknown_payload_t *)) get_real_type; - this->public.set_data = (void (*) (unknown_payload_t *,chunk_t)) set_data; - this->public.get_data_clone = (chunk_t (*) (unknown_payload_t *)) get_data_clone; + this->public.is_critical = (bool (*) (unknown_payload_t *)) is_critical; this->public.get_data = (chunk_t (*) (unknown_payload_t *)) get_data; /* private variables */ this->critical = FALSE; this->next_payload = NO_PAYLOAD; - this->payload_type = NO_PAYLOAD; - this->payload_length = DEFAULT_PAYLOAD_HEADER_LENGTH; + this->payload_length = UNKNOWN_PAYLOAD_HEADER_LENGTH; this->data = CHUNK_INITIALIZER; return (&(this->public)); diff --git a/Source/charon/encoding/payloads/unknown_payload.h b/Source/charon/encoding/payloads/unknown_payload.h index ea365871b..2558ce719 100644 --- a/Source/charon/encoding/payloads/unknown_payload.h +++ b/Source/charon/encoding/payloads/unknown_payload.h @@ -27,73 +27,52 @@ #include <encoding/payloads/payload.h> /** - * Length of a default payload header. + * Header length of the unknown payload. * * @ingroup payloads */ -#define DEFAULT_PAYLOAD_HEADER_LENGTH 4 +#define UNKNOWN_PAYLOAD_HEADER_LENGTH 4 typedef struct unknown_payload_t unknown_payload_t; /** - * Object representing an unknown IKEv2 payload. + * @brief Payload which can't be processed further. * - * @ingroup payloads + * When the parser finds an unknown payload, he builds an instance of + * this class. This allows further processing of this payload, such as + * a check for the critical bit in the header. + * + * @b Constructors: + * - unknown_payload_create() * + * @ingroup payloads */ struct unknown_payload_t { + /** * The payload_t interface. */ payload_t payload_interface; /** - * @brief Set the Data of the unknown payload. - * - * Data are getting cloned. - * - * @param this calling unknown_payload_t object - * @param data data following the header as chunk_t - */ - void (*set_data) (unknown_payload_t *this, chunk_t data); - - /** - * @brief Get the data of the message. - * - * Returned data are a copy of the internal one. - * - * @param this calling unknown_payload_t object - * @return data as chunk_t - */ - chunk_t (*get_data_clone) (unknown_payload_t *this); - - /** - * @brief Get the data of the message. + * @brief Get the raw data of this payload, without + * the generic payload header. * - * Returned data are NOT copied. + * Returned data are NOT copied and must not be freed. * * @param this calling unknown_payload_t object * @return data as chunk_t */ chunk_t (*get_data) (unknown_payload_t *this); - - /** - * @brief Set the real Type of this payload. - * - * @param this calling unknown_payload_t object - * @param type real type of this payload. - */ - - void (*set_real_type) (unknown_payload_t *this,payload_type_t type); /** - * @brief Get the real Type of this payload. + * @brief Get the critical flag. * - * @param this calling unknown_payload_t object - * @return real type of this payload. + * @param this calling unknown_payload_t object + * @return TRUE if payload is critical, FALSE if not */ - payload_type_t (*get_real_type) (unknown_payload_t *this); + bool (*is_critical) (unknown_payload_t *this); /** * @brief Destroys an unknown_payload_t object. |