- class ike_sa_t partly implemented

This commit is contained in:
Jan Hutter 2005-11-08 13:33:28 +00:00
parent e3dd1393d5
commit 7ba3876169
2 changed files with 255 additions and 0 deletions

172
Source/charon/ike_sa.c Normal file
View file

@ -0,0 +1,172 @@
/**
* @file ike_sa.c
*
* @brief Class ike_sa_t. An object of this type is managed by an
* ike_sa_manager_t-object and represents an IKE_SA
*
*/
/*
* 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.
*/
#include "types.h"
#include "linked_list.h"
#include "ike_sa.h"
/**
* States in which a IKE_SA can actually be
*/
typedef enum ike_sa_state_e ike_sa_state_t;
enum ike_sa_state_e{
/**
* IKE_SA is is not in a state
*/
NO_STATE,
/**
* A IKE_SA_INIT-message was sent: role initiator
*/
IKE_SA_INIT_REQUESTED,
/**
* A IKE_SA_INIT-message was replied: role responder
*/
IKE_SA_INIT_RESPONDED,
/**
* An IKE_AUTH-message was sent after a successful
* IKE_SA_INIT-exchange: role initiator
*/
IKE_AUTH_REQUESTED,
/**
* An IKE_AUTH-message was replied: role responder.
* In this state, all the informations for an IKE_SA
* and one CHILD_SA are known.
*/
IKE_SA_INITIALIZED
};
/**
* Private data of an message_t object
*/
typedef struct private_ike_sa_s private_ike_sa_t;
struct private_ike_sa_s {
/**
* Public part of a ike_sa_t object
*/
ike_sa_t public;
/* Private values */
/**
* Identifier for the current IKE_SA
*/
ike_sa_id_t *ike_sa_id;
/**
* Linked List containing the child sa's of the current IKE_SA
*/
linked_list_t *child_sas;
/**
* Current state of the IKE_SA
*/
ike_sa_state_t current_state;
};
/**
* @brief implements function process_message of private_ike_sa_t
*/
static status_t process_message (private_ike_sa_t *this, message_t *message)
{
/* @TODO Add Message Processing here */
return SUCCESS;
}
/**
* @brief implements function process_configuration of private_ike_sa_t
*/
static status_t process_configuration (private_ike_sa_t *this,configuration_t *configuration)
{
/*
* @TODO Add configuration processing here
*/
return SUCCESS;
}
/**
* @brief implements function destroy of private_ike_sa_t
*/
static status_t destroy (private_ike_sa_t *this)
{
if (this == NULL)
{
return FAILED;
}
this->ike_sa_id->destroy(this->ike_sa_id);
this->child_sas->destroy(this->child_sas);
pfree(this);
return SUCCESS;
}
/*
* Described in Header
*/
ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
{
private_ike_sa_t *this = alloc_thing(private_ike_sa_t, "private_ike_sa_t");
if (this == NULL)
{
return NULL;
}
/* Public functions */
this->public.process_message = (status_t(*)(ike_sa_t*, message_t*)) process_message;
this->public.process_configuration = (status_t(*)(ike_sa_t*, configuration_t*)) process_configuration;
this->public.destroy = (status_t(*)(ike_sa_t*))destroy;
/* initialize private fields */
if (ike_sa_id->clone(ike_sa_id,&(this->ike_sa_id)) != SUCCESS)
{
pfree(this);
return NULL;
}
this->child_sas = linked_list_create();
if (this->child_sas == NULL)
{
this->ike_sa_id->destroy(this->ike_sa_id);
pfree(this);
return NULL;
}
/* at creation time, IKE_SA isn't in a specific state */
this->current_state = NO_STATE;
return (&this->public);
}

83
Source/charon/ike_sa.h Normal file
View file

@ -0,0 +1,83 @@
/**
* @file ike_sa.h
*
* @brief Class ike_sa_t. An object of this type is managed by an
* ike_sa_manager_t-object and represents an IKE_SA
*
*/
/*
* 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_SA_H_
#define IKE_SA_H_
#include "types.h"
#include "message.h"
#include "configuration.h"
#include "ike_sa_id.h"
/**
* @brief This class is used to represent an IKE_SA
*
*/
typedef struct ike_sa_s ike_sa_t;
struct ike_sa_s {
/**
* @brief Processes a incoming IKEv2-Message of type message_t
*
* @param this ike_sa_t-object object
* @param[in] message message_t-object to process
* @return SUCCESSFUL if succeeded, FAILED otherwise
*/
status_t (*process_message) (ike_sa_t *this,message_t *message);
/**
* @brief Processes a specific configuration
*
* This function is called when a new IKE_SA is created
*
* @param this ike_sa_t-message_t object object
* @param[in] message message_t-object to process
* @return SUCCESSFUL if succeeded, FAILED otherwise
*/
status_t (*process_configuration) (ike_sa_t *this,configuration_t *configuration);
/**
* @brief Destroys a ike_sa_t object
*
* @param this ike_sa_t object
* @return SUCCESSFUL if succeeded, FAILED otherwise
*/
status_t (*destroy) (ike_sa_t *this);
};
/**
* Creates an ike_sa_t-object with a specific ike_sa_id_t-object
*
* @param[in] ike_sa_id ike_sa_id_t-object to associate with new IKE_SA.
* The object is internal getting cloned
* and so has to be destroyed by the caller.
*
* @warning the Content of internal ike_sa_id_t-Object can change over time
* e.g. when a IKE_SA_INIT has been finished
*
* @return created ike_sa_t object
*/
ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id);
#endif /*IKE_SA_H_*/