- defined data struct and encoding rules for the ikev2-header
This commit is contained in:
@@ -0,0 +1,63 @@
|
|||||||
|
/**
|
||||||
|
* @file ike_header.c
|
||||||
|
*
|
||||||
|
* @brief Definition of the encoding rules used when parsing or generating
|
||||||
|
* an IKEv2-Header
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2005 Jan Hutter, Martin Willi
|
||||||
|
* Hochschule fuer Technik Rapperswil
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* offsetof macro */
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "../encodings.h"
|
||||||
|
#include "ike_header.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encoding rules to parse or generate a IKEv2-Header
|
||||||
|
*
|
||||||
|
* The defined offsets are the positions in a struct of type
|
||||||
|
* ike_header_t.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
encoding_rule_t ike_header_encodings[] = {
|
||||||
|
/* 8 Byte SPI, stored in the field initiator_spi */
|
||||||
|
{ U_INT_64, offsetof(ike_header_t, initiator_spi) },
|
||||||
|
/* 8 Byte SPI, stored in the field responder_spi */
|
||||||
|
{ U_INT_64, offsetof(ike_header_t, responder_spi) },
|
||||||
|
/* 1 Byte next payload type, stored in the field next_payload */
|
||||||
|
{ U_INT_8, offsetof(ike_header_t, next_payload) },
|
||||||
|
/* 4 Bit major version, stored in the field maj_version */
|
||||||
|
{ U_INT_4, offsetof(ike_header_t, maj_version) },
|
||||||
|
/* 4 Bit minor version, stored in the field min_version */
|
||||||
|
{ U_INT_4, offsetof(ike_header_t, min_version) },
|
||||||
|
/* 2 Bit reserved bits, nowhere stored */
|
||||||
|
{ RESERVED_BIT, 0 },
|
||||||
|
{ RESERVED_BIT, 0 },
|
||||||
|
/* 3 Bit flags, stored in the fields response, version and initiator */
|
||||||
|
{ FLAG, offsetof(ike_header_t, flags.response) },
|
||||||
|
{ FLAG, offsetof(ike_header_t, flags.version) },
|
||||||
|
{ FLAG, offsetof(ike_header_t, flags.initiator) },
|
||||||
|
/* 3 Bit reserved bits, nowhere stored */
|
||||||
|
{ RESERVED_BIT, 0 },
|
||||||
|
{ RESERVED_BIT, 0 },
|
||||||
|
{ RESERVED_BIT, 0 },
|
||||||
|
/* 4 Byte message id, stored in the field message_id */
|
||||||
|
{ U_INT_32, offsetof(ike_header_t, message_id) },
|
||||||
|
/* 4 Byte length fied, stored in the field length */
|
||||||
|
{ LENGTH, offsetof(ike_header_t, length) }
|
||||||
|
};
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
/**
|
||||||
|
* @file ike_header.h
|
||||||
|
*
|
||||||
|
* @brief Declaration of the data struct ike_header_t.
|
||||||
|
*
|
||||||
|
* The data of a parsed header are stored in a struct of this type.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2005 Jan Hutter, Martin Willi
|
||||||
|
* Hochschule fuer Technik Rapperswil
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef IKE_HEADER_H_
|
||||||
|
#define IKE_HEADER_H_
|
||||||
|
|
||||||
|
#include <freeswan.h>
|
||||||
|
#include <pluto/constants.h>
|
||||||
|
#include <pluto/defs.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data structure to hold the data of an IKEv2-Header
|
||||||
|
*
|
||||||
|
* The header format of an IKEv2-Message is compatible to the
|
||||||
|
* ISAKMP-Header format to allow implementations supporting
|
||||||
|
* both versions of the IKE-protocol.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
typedef struct ike_header_s ike_header_t;
|
||||||
|
|
||||||
|
struct ike_header_s{
|
||||||
|
/**
|
||||||
|
* SPI of the initiator
|
||||||
|
*/
|
||||||
|
u_int32_t initiator_spi;
|
||||||
|
/**
|
||||||
|
* SPI of the responder
|
||||||
|
*/
|
||||||
|
u_int32_t responder_spi;
|
||||||
|
/**
|
||||||
|
* next payload type
|
||||||
|
*/
|
||||||
|
u_int8_t next_payload;
|
||||||
|
/**
|
||||||
|
* IKE major version
|
||||||
|
*/
|
||||||
|
u_int8_t maj_version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IKE minor version
|
||||||
|
*/
|
||||||
|
u_int8_t min_version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exchange type
|
||||||
|
*/
|
||||||
|
u_int8_t exchange_type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flags of the Message
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
struct {
|
||||||
|
/**
|
||||||
|
* Sender is initiator of the associated IKE_SA_INIT-Exchange
|
||||||
|
*/
|
||||||
|
bool initiator;
|
||||||
|
/**
|
||||||
|
* is protocol supporting higher version?
|
||||||
|
*/
|
||||||
|
bool version;
|
||||||
|
/**
|
||||||
|
* TRUE, if this is a response, FALSE if its a Request
|
||||||
|
*/
|
||||||
|
bool response;
|
||||||
|
} flags;
|
||||||
|
/**
|
||||||
|
* Associated Message-ID
|
||||||
|
*/
|
||||||
|
u_int32_t message_id;
|
||||||
|
/**
|
||||||
|
* Length of the whole IKEv2-Message (header and all payloads)
|
||||||
|
*/
|
||||||
|
u_int32_t length;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /*IKE_HEADER_H_*/
|
||||||
Reference in New Issue
Block a user