diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/charon/message.h | 48 | ||||
-rw-r--r-- | Source/charon/payloads/ike_header.c | 43 | ||||
-rw-r--r-- | Source/charon/payloads/ike_header.h | 60 |
3 files changed, 96 insertions, 55 deletions
diff --git a/Source/charon/message.h b/Source/charon/message.h index 1d29cbf54..62ab11d02 100644 --- a/Source/charon/message.h +++ b/Source/charon/message.h @@ -26,53 +26,7 @@ #include "types.h" #include "packet.h" #include "ike_sa_id.h" - - -/** - * Major version of IKEv2-Protocol. Always 2 - */ -#define IKE_V2_MAJOR_VERSION 2 - -/** - * Minor version of IKEv2-Protocol. Always 0 - */ -#define IKE_V2_MINOR_VERSION 0 - -/** - * Flag in IKEv2-Header. Always 0 - */ -#define HIGHER_VERSION_SUPPORTED_FLAG 0 -/** - * @brief Different types of IKE-Exchanges. - * - * See RFC for different types. - */ -typedef enum exchange_type_e exchange_type_t; - -enum exchange_type_e{ - - /** - * NOT_SET, not a official message type :-) - */ - NOT_SET = 0, - - /** - * IKE_SA_INIT - */ - IKE_SA_INIT = 34, - /** - * IKE_AUTH - */ - IKE_AUTH = 35, - /** - * CREATE_CHILD_SA - */ - CREATE_CHILD_SA = 36, - /** - * INFORMATIONAL - */ - INFORMATIONAL = 37 -}; +#include "payloads/ike_header.h" /** * @brief This class is used to represent an IKEv2-Message. diff --git a/Source/charon/payloads/ike_header.c b/Source/charon/payloads/ike_header.c index f02caf9bf..da42a37cc 100644 --- a/Source/charon/payloads/ike_header.c +++ b/Source/charon/payloads/ike_header.c @@ -32,7 +32,7 @@ /** * Encoding rules to parse or generate a IKEv2-Header * - * The defined offsets are the positions in a struct of type + * The defined offsets are the positions in a object of type * ike_header_t. * */ @@ -67,14 +67,21 @@ encoding_rule_t ike_header_encodings[] = { }; - +/** + * Implements payload_t's and ike_header_t's destroy function. + * See #payload_s.destroy or ike_header_s.destroy for description. + */ static status_t destroy(ike_header_t *this) { allocator_free(this); return SUCCESS; } - + +/** + * Implements payload_t's get_encoding_rules function. + * See #payload_s.get_encoding_rules for description. + */ static status_t get_encoding_rules(payload_t *this, encoding_rule_t **rules, size_t *rule_count) { *rules = ike_header_encodings; @@ -83,22 +90,36 @@ static status_t get_encoding_rules(payload_t *this, encoding_rule_t **rules, siz return SUCCESS; } +/** + * Implements payload_t's get_type function. + * See #payload_s.get_type for description. + */ static payload_type_t get_type(payload_t *this) { return HEADER; } +/** + * Implements payload_t's get_next_type function. + * See #payload_s.get_next_type for description. + */ static payload_type_t get_next_type(payload_t *this) { return (((ike_header_t*)this)->next_payload); } +/** + * Implements payload_t's get_length function. + * See #payload_s.get_length for description. + */ static size_t get_length(payload_t *this) { return sizeof(ike_header_t); } - +/* + * Described in header + */ ike_header_t *ike_header_create() { ike_header_t *this = allocator_alloc_thing(ike_header_t); @@ -114,6 +135,20 @@ ike_header_t *ike_header_create() this->payload_interface.destroy = (status_t (*) (payload_t *))destroy; this->destroy = destroy; + /* set default values of the fields */ + this->initiator_spi = 0; + this->responder_spi = 0; + this->next_payload = 0; + this->maj_version = IKE_MAJOR_VERSION; + this->min_version = IKE_MINOR_VERSION; + this->exchange_type = NOT_SET; + this->flags.initiator = TRUE; + this->flags.version = HIGHER_VERSION_SUPPORTED_FLAG; + this->flags.response = FALSE; + this->message_id = 0; + this->length = IKE_HEADER_LENGTH; + + return this; } diff --git a/Source/charon/payloads/ike_header.h b/Source/charon/payloads/ike_header.h index 57a0d637d..03ce9d595 100644 --- a/Source/charon/payloads/ike_header.h +++ b/Source/charon/payloads/ike_header.h @@ -29,7 +29,59 @@ #include "payload.h" /** - * Data structure to hold the data of an IKEv2-Header + * Major Version of IKEv2 + */ +#define IKE_MAJOR_VERSION 2 + +/** + * Minor Version of IKEv2 + */ +#define IKE_MINOR_VERSION 0 + +/** + * Flag in IKEv2-Header. Always 0 + */ +#define HIGHER_VERSION_SUPPORTED_FLAG 0 + +/** + * Length of IKE Header in Bytes + */ +#define IKE_HEADER_LENGTH 28 + +/** + * @brief Different types of IKE-Exchanges. + * + * See RFC for different types. + */ +typedef enum exchange_type_e exchange_type_t; + +enum exchange_type_e{ + + /** + * NOT_SET, not a official message type :-) + */ + NOT_SET = 0, + + /** + * IKE_SA_INIT + */ + IKE_SA_INIT = 34, + /** + * IKE_AUTH + */ + IKE_AUTH = 35, + /** + * CREATE_CHILD_SA + */ + CREATE_CHILD_SA = 36, + /** + * INFORMATIONAL + */ + INFORMATIONAL = 37 +}; + +/** + * Object representing an IKEv2-Header * * The header format of an IKEv2-Message is compatible to the * ISAKMP-Header format to allow implementations supporting @@ -98,9 +150,9 @@ struct ike_header_s { u_int32_t length; /** - * @brief Destroys a ike_haeder payload and all included substructures. + * @brief Destroys a ike_header_t object. * - * @param this payload to destroy + * @param this ike_header_t object to destroy * @return * SUCCESS in any case */ @@ -108,7 +160,7 @@ struct ike_header_s { }; /** - * @brief Create an empty ike_header + * @brief Create an ike_header_t object * * @return * - created ike_header, or |