- code cleaned up
This commit is contained in:
parent
aee3eb5299
commit
f7cf9f61c4
|
@ -20,44 +20,41 @@
|
|||
* for more details.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ike_sa_id.h"
|
||||
|
||||
#include <types.h>
|
||||
#include <utils/allocator.h>
|
||||
|
||||
|
||||
typedef struct private_ike_sa_id_t private_ike_sa_id_t;
|
||||
|
||||
/**
|
||||
* Private data of an ike_sa_id object
|
||||
* Private data of an ike_sa_id_t object.
|
||||
*/
|
||||
struct private_ike_sa_id_t {
|
||||
/**
|
||||
* Public part of a ike_sa_id object
|
||||
* Public interface of ike_sa_id_t.
|
||||
*/
|
||||
ike_sa_id_t public;
|
||||
|
||||
/**
|
||||
* SPI of Initiator
|
||||
* SPI of Initiator.
|
||||
*/
|
||||
u_int64_t initiator_spi;
|
||||
|
||||
/**
|
||||
* SPI of Responder
|
||||
* SPI of Responder.
|
||||
*/
|
||||
u_int64_t responder_spi;
|
||||
|
||||
/**
|
||||
* Role for specific IKE_SA
|
||||
* Role for specific IKE_SA.
|
||||
*/
|
||||
bool is_initiator_flag;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* implements ike_sa_id_t.set_responder_spi.
|
||||
* Implementation of ike_sa_id_t.set_responder_spi.
|
||||
*/
|
||||
static void set_responder_spi (private_ike_sa_id_t *this, u_int64_t responder_spi)
|
||||
{
|
||||
|
@ -65,7 +62,7 @@ static void set_responder_spi (private_ike_sa_id_t *this, u_int64_t responder_sp
|
|||
}
|
||||
|
||||
/**
|
||||
* implements ike_sa_id_t.set_initiator_spi.
|
||||
* Implementation of ike_sa_id_t.set_initiator_spi.
|
||||
*/
|
||||
static void set_initiator_spi(private_ike_sa_id_t *this, u_int64_t initiator_spi)
|
||||
{
|
||||
|
@ -73,7 +70,7 @@ static void set_initiator_spi(private_ike_sa_id_t *this, u_int64_t initiator_spi
|
|||
}
|
||||
|
||||
/**
|
||||
* implements ike_sa_id_t.get_initiator_spi.
|
||||
* Implementation of ike_sa_id_t.get_initiator_spi.
|
||||
*/
|
||||
static u_int64_t get_initiator_spi (private_ike_sa_id_t *this)
|
||||
{
|
||||
|
@ -81,7 +78,7 @@ static u_int64_t get_initiator_spi (private_ike_sa_id_t *this)
|
|||
}
|
||||
|
||||
/**
|
||||
* implements ike_sa_id_t.get_responder_spi.
|
||||
* Implementation of ike_sa_id_t.get_responder_spi.
|
||||
*/
|
||||
static u_int64_t get_responder_spi (private_ike_sa_id_t *this)
|
||||
{
|
||||
|
@ -89,7 +86,7 @@ static u_int64_t get_responder_spi (private_ike_sa_id_t *this)
|
|||
}
|
||||
|
||||
/**
|
||||
* implements ike_sa_id_t.get_responder_spi.
|
||||
* Implementation of ike_sa_id_t.equals.
|
||||
*/
|
||||
static bool equals (private_ike_sa_id_t *this, private_ike_sa_id_t *other)
|
||||
{
|
||||
|
@ -112,7 +109,7 @@ static bool equals (private_ike_sa_id_t *this, private_ike_sa_id_t *other)
|
|||
}
|
||||
|
||||
/**
|
||||
* implements ike_sa_id_t.replace_values.
|
||||
* Implementation of ike_sa_id_t.replace_values.
|
||||
*/
|
||||
static void replace_values(private_ike_sa_id_t *this, private_ike_sa_id_t *other)
|
||||
{
|
||||
|
@ -122,7 +119,7 @@ static void replace_values(private_ike_sa_id_t *this, private_ike_sa_id_t *other
|
|||
}
|
||||
|
||||
/**
|
||||
* implements ike_sa_id_t.is_initiator.
|
||||
* Implementation of ike_sa_id_t.is_initiator.
|
||||
*/
|
||||
static bool is_initiator(private_ike_sa_id_t *this)
|
||||
{
|
||||
|
@ -130,7 +127,7 @@ static bool is_initiator(private_ike_sa_id_t *this)
|
|||
}
|
||||
|
||||
/**
|
||||
* implements ike_sa_id_t.switch_initiator.
|
||||
* Implementation of ike_sa_id_t.switch_initiator.
|
||||
*/
|
||||
static bool switch_initiator(private_ike_sa_id_t *this)
|
||||
{
|
||||
|
@ -146,7 +143,7 @@ static bool switch_initiator(private_ike_sa_id_t *this)
|
|||
}
|
||||
|
||||
/**
|
||||
* implements ike_sa_id_t.clone.
|
||||
* Implementation of ike_sa_id_t.clone.
|
||||
*/
|
||||
static ike_sa_id_t* clone(private_ike_sa_id_t *this)
|
||||
{
|
||||
|
@ -154,7 +151,7 @@ static ike_sa_id_t* clone(private_ike_sa_id_t *this)
|
|||
}
|
||||
|
||||
/**
|
||||
* implements ike_sa_id_t.clone.
|
||||
* Implementation of ike_sa_id_t.destroy.
|
||||
*/
|
||||
static void destroy(private_ike_sa_id_t *this)
|
||||
{
|
||||
|
@ -162,23 +159,21 @@ static void destroy(private_ike_sa_id_t *this)
|
|||
}
|
||||
|
||||
/*
|
||||
* Described in Header-File
|
||||
* Described in header.
|
||||
*/
|
||||
ike_sa_id_t * ike_sa_id_create(u_int64_t initiator_spi, u_int64_t responder_spi, bool is_initiator_flag)
|
||||
{
|
||||
private_ike_sa_id_t *this = allocator_alloc_thing(private_ike_sa_id_t);
|
||||
|
||||
/* Public functions */
|
||||
/* public functions */
|
||||
this->public.set_responder_spi = (void(*)(ike_sa_id_t*,u_int64_t)) set_responder_spi;
|
||||
this->public.set_initiator_spi = (void(*)(ike_sa_id_t*,u_int64_t)) set_initiator_spi;
|
||||
this->public.get_responder_spi = (u_int64_t(*)(ike_sa_id_t*)) get_responder_spi;
|
||||
this->public.get_initiator_spi = (u_int64_t(*)(ike_sa_id_t*)) get_initiator_spi;
|
||||
this->public.equals = (bool(*)(ike_sa_id_t*,ike_sa_id_t*)) equals;
|
||||
this->public.replace_values = (void(*)(ike_sa_id_t*,ike_sa_id_t*)) replace_values;
|
||||
|
||||
this->public.is_initiator = (bool(*)(ike_sa_id_t*)) is_initiator;
|
||||
this->public.switch_initiator = (bool(*)(ike_sa_id_t*)) switch_initiator;
|
||||
|
||||
this->public.clone = (ike_sa_id_t*(*)(ike_sa_id_t*)) clone;
|
||||
this->public.destroy = (void(*)(ike_sa_id_t*))destroy;
|
||||
|
||||
|
|
|
@ -21,121 +21,126 @@
|
|||
*/
|
||||
|
||||
|
||||
#ifndef IKE_SA_ID_H_
|
||||
#define IKE_SA_ID_H_
|
||||
#ifndef _IKE_SA_ID_H_
|
||||
#define _IKE_SA_ID_H_
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
typedef struct ike_sa_id_t ike_sa_id_t;
|
||||
|
||||
/**
|
||||
* @brief This class is used to identify an IKE_SA.
|
||||
* @brief An object of type ike_sa_id_t is used to identify an IKE_SA.
|
||||
*
|
||||
* An IKE_SA is identified by its initiator and responder spi's.
|
||||
* Additionaly it contains the role of the actual running IKEv2-Daemon
|
||||
* for the specific IKE_SA.
|
||||
* for the specific IKE_SA (original initiator or responder).
|
||||
*
|
||||
* @b Constructors:
|
||||
* - ike_sa_id_create()
|
||||
*
|
||||
* @ingroup sa
|
||||
*/
|
||||
struct ike_sa_id_t {
|
||||
|
||||
/**
|
||||
* @brief Sets the SPI of the responder.
|
||||
* @brief Set the SPI of the responder.
|
||||
*
|
||||
* This function is called when a request or reply of a IKE_SA_INIT is received.
|
||||
*
|
||||
* @param this ike_sa_id_t object
|
||||
* @param this calling object
|
||||
* @param responder_spi SPI of responder to set
|
||||
*/
|
||||
void (*set_responder_spi) (ike_sa_id_t *this, u_int64_t responder_spi);
|
||||
|
||||
/**
|
||||
* @brief Sets the SPI of the initiator.
|
||||
* @brief Set the SPI of the initiator.
|
||||
*
|
||||
*
|
||||
* @param this ike_sa_id_t object
|
||||
* @param this calling object
|
||||
* @param initiator_spi SPI to set
|
||||
*/
|
||||
void (*set_initiator_spi) (ike_sa_id_t *this, u_int64_t initiator_spi);
|
||||
|
||||
/**
|
||||
* @brief Returns the initiator spi.
|
||||
* @brief Get the initiator SPI.
|
||||
*
|
||||
* @param this ike_sa_id_t object
|
||||
* @return spi of the initiator
|
||||
* @param this calling object
|
||||
* @return SPI of the initiator
|
||||
*/
|
||||
u_int64_t (*get_initiator_spi) (ike_sa_id_t *this);
|
||||
|
||||
/**
|
||||
* @brief Returns the responder spi.
|
||||
* @brief Get the responder SPI.
|
||||
*
|
||||
* @param this ike_sa_id_t object
|
||||
* @return spi of the responder
|
||||
* @param this calling object
|
||||
* @return SPI of the responder
|
||||
*/
|
||||
u_int64_t (*get_responder_spi) (ike_sa_id_t *this);
|
||||
|
||||
/**
|
||||
* @brief Check if two ike_sa_ids are equal.
|
||||
* @brief Check if two ike_sa_id_t objects are equal.
|
||||
*
|
||||
* Two ike_sa_id_t objects are equal if both SPI values and the role matches.
|
||||
*
|
||||
* @param this ike_sa_id_t object
|
||||
* @param other ike_sa_id object to check if equal
|
||||
* @return TRUE if given ike_sa_ids are equal, FALSE otherwise
|
||||
* @param this calling object
|
||||
* @param other ike_sa_id_t object to check if equal
|
||||
* @return TRUE if given ike_sa_id_t are equal, FALSE otherwise
|
||||
*/
|
||||
bool (*equals) (ike_sa_id_t *this, ike_sa_id_t *other);
|
||||
|
||||
/**
|
||||
* @brief Replace the values of a given ike_sa_id_t object with values.
|
||||
* @brief Replace all values of a given ike_sa_id_t object with values.
|
||||
* from another ike_sa_id_t object.
|
||||
*
|
||||
* After calling this function, both objects are equal.
|
||||
*
|
||||
* @param this ike_sa_id_t object
|
||||
* @param other ike_sa_id_t object which values will be taken
|
||||
* @param this calling object
|
||||
* @param other ike_sa_id_t object from which values will be taken
|
||||
*/
|
||||
void (*replace_values) (ike_sa_id_t *this, ike_sa_id_t *other);
|
||||
|
||||
/**
|
||||
* @brief gets the initiator flag.
|
||||
* @brief Get the initiator flag.
|
||||
*
|
||||
* @param this ike_sa_id_t object
|
||||
* @param this calling object
|
||||
* @return TRUE if we are the original initator
|
||||
*/
|
||||
bool (*is_initiator) (ike_sa_id_t *this);
|
||||
|
||||
/**
|
||||
* @brief switches the initiator flag.
|
||||
* @brief Switche the original initiator flag.
|
||||
*
|
||||
* @param this ike_sa_id_t object
|
||||
* @return TRUE if we are the original initator after switch
|
||||
* @param this calling object
|
||||
* @return TRUE if we are the original initator after switch, FALSE otherwise
|
||||
*/
|
||||
bool (*switch_initiator) (ike_sa_id_t *this);
|
||||
|
||||
/**
|
||||
* @brief Clones a given ike_sa_id_t object.
|
||||
*
|
||||
* @param this ike_sa_id_t object
|
||||
* @return cloned ike_sa_id
|
||||
* @param this calling object
|
||||
* @return cloned ike_sa_id_t object
|
||||
*/
|
||||
ike_sa_id_t *(*clone) (ike_sa_id_t *this);
|
||||
|
||||
/**
|
||||
* @brief Destroys a ike_sa_id_tobject.
|
||||
* @brief Destroys an ike_sa_id_t object.
|
||||
*
|
||||
* @param this ike_sa_id_t object
|
||||
* @param this calling object
|
||||
*/
|
||||
void (*destroy) (ike_sa_id_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Creates an ike_sa_id_t object with specific spi's and defined role
|
||||
* @brief Creates an ike_sa_id_t object with specific SPI's and defined role.
|
||||
*
|
||||
* @warning The initiator SPI and role is not changeable after initiating a ike_sa_id object
|
||||
*
|
||||
* @param initiator_spi initiators spi
|
||||
* @param responder_spi responders spi
|
||||
* @param initiator_spi initiators SPI
|
||||
* @param responder_spi responders SPI
|
||||
* @param is_initiator TRUE if we are the original initiator
|
||||
* @return created ike_sa_id_t object
|
||||
* @return ike_sa_id_t object
|
||||
*
|
||||
* @ingroup sa
|
||||
*/
|
||||
ike_sa_id_t * ike_sa_id_create(u_int64_t initiator_spi, u_int64_t responder_spi, bool is_initiaor);
|
||||
|
||||
#endif /*IKE_SA_ID_H_*/
|
||||
#endif /*_IKE_SA_ID_H_*/
|
||||
|
|
Loading…
Reference in New Issue