This commit is contained in:
Jan Hutter 2005-11-21 14:48:18 +00:00
parent e4b809a3a3
commit a2a10f2562
10 changed files with 438 additions and 0 deletions

View File

@ -0,0 +1,4 @@
#ifndef IKE_SA_INIT_REQUESTED_H_
#define IKE_SA_INIT_REQUESTED_H_
#endif /*IKE_SA_INIT_REQUESTED_H_*/

View File

@ -0,0 +1,4 @@
#ifndef IKE_SA_INIT_RESPONDED_H_
#define IKE_SA_INIT_RESPONDED_H_
#endif /*IKE_SA_INIT_RESPONDED_H_*/

View File

@ -0,0 +1,92 @@
/**
* @file initiator_init.c
*
* @brief Start state of a IKE_SA as initiator
*
*/
/*
* 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 "initiator_init.h"
#include "../utils/allocator.h"
/**
* Private data of a initiator_init_t object.
*
*/
typedef struct private_initiator_init_s private_initiator_init_t;
struct private_initiator_init_s {
/**
* methods of the state_t interface
*/
initiator_init_t public;
};
static status_t initiate_connection (private_initiator_init_t *this, char *name, state_t **new_state)
{
return SUCCESS;
}
/**
* Implements state_t.get_state
*/
static status_t process_message(private_initiator_init_t *this, message_t *message, state_t **new_state)
{
*new_state = (state_t *) this;
return FAILED;
}
/**
* Implements state_t.get_state
*/
static ike_sa_state_t get_state(private_initiator_init_t *this)
{
return INITIATOR_INIT;
}
/**
* Implements state_t.get_state
*/
static status_t destroy(private_initiator_init_t *this)
{
allocator_free(this);
return SUCCESS;
}
/*
* Described in header.
*/
initiator_init_t *initiator_init_create()
{
private_initiator_init_t *this = allocator_alloc_thing(private_initiator_init_t);
if (this == NULL)
{
return NULL;
}
/* interface functions */
this->public.state_interface.process_message = (status_t (*) (state_t *,message_t *,state_t **)) process_message;
this->public.state_interface.get_state = (ike_sa_state_t (*) (state_t *)) get_state;
this->public.state_interface.destroy = (status_t (*) (state_t *)) destroy;
/* public functions */
this->public.initiate_connection = (status_t (*)(initiator_init_t *, char *, state_t **)) initiate_connection;
return &(this->public);
}

View File

@ -0,0 +1,59 @@
/**
* @file initiator_init.h
*
* @brief Start state of a IKE_SA as initiator
*
*/
/*
* 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 INITIATOR_INIT_H_
#define INITIATOR_INIT_H_
#include "state.h"
/**
* @brief This class represents an IKE_SA state when initializing
* a connection as initiator
*
*/
typedef struct initiator_init_s initiator_init_t;
struct initiator_init_s {
/**
* methods of the state_t interface
*/
state_t state_interface;
/**
* Initiate a new connection with given configuration name
*
* @param this calling object
* @param name name of the configuration
* @param new_state new state if call succeeded
* @return TODO
*/
status_t (*initiate_connection) (initiator_init_t *this, char *name, state_t **new_state);
};
/**
* Constructor of class initiator_init_t
*/
initiator_init_t *initiator_init_create();
#endif /*INITIATOR_INIT_H_*/

View File

@ -0,0 +1,84 @@
/**
* @file responder_init.c
*
* @brief Start state of a IKE_SA as responder
*
*/
/*
* 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 "responder_init.h"
#include "../utils/allocator.h"
/**
* Private data of a responder_init_t object.
*
*/
typedef struct private_responder_init_s private_responder_init_t;
struct private_responder_init_s {
/**
* methods of the state_t interface
*/
responder_init_t public;
};
/**
* Implements state_t.get_state
*/
static status_t process_message(private_responder_init_t *this, message_t *message, state_t **new_state)
{
*new_state = (state_t *) this;
return SUCCESS;
}
/**
* Implements state_t.get_state
*/
static ike_sa_state_t get_state(private_responder_init_t *this)
{
return INITIATOR_INIT;
}
/**
* Implements state_t.get_state
*/
static status_t destroy(private_responder_init_t *this)
{
allocator_free(this);
return SUCCESS;
}
/*
* Described in header.
*/
responder_init_t *responder_init_create()
{
private_responder_init_t *this = allocator_alloc_thing(private_responder_init_t);
if (this == NULL)
{
return NULL;
}
/* interface functions */
this->public.state_interface.process_message = (status_t (*) (state_t *,message_t *,state_t **)) process_message;
this->public.state_interface.get_state = (ike_sa_state_t (*) (state_t *)) get_state;
this->public.state_interface.destroy = (status_t (*) (state_t *)) destroy;
return &(this->public);
}

View File

@ -0,0 +1,48 @@
/**
* @file responder_init.h
*
* @brief Start state of a IKE_SA as responder
*
*/
/*
* 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 RESPONDER_INIT_H_
#define RESPONDER_INIT_H_
#include "state.h"
/**
* @brief This class represents an IKE_SA state when initializing
* a connection as responder
*
*/
typedef struct responder_init_s responder_init_t;
struct responder_init_s {
/**
* methods of the state_t interface
*/
state_t state_interface;
};
/**
* Constructor of class responder_init_t
*/
responder_init_t *responder_init_create();
#endif /*RESPONDER_INIT_H_*/

View File

@ -0,0 +1,37 @@
/**
* @file state.c
*
* @brief Interface for a specific IKE_SA state
*
*/
/*
* 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 "state.h"
/**
* string mappings for ike_sa_state
*/
mapping_t ike_sa_state_m[] = {
{INITIATOR_INIT, "INITIATOR_INIT"},
{RESPONDER_INIT, "RESPONDER_INIT"},
{IKE_SA_INIT_REQUESTED, "IKE_SA_INIT_REQUESTED"},
{IKE_SA_INIT_RESPONDED, "IKE_SA_INIT_RESPONDED"},
{IKE_AUTH_REQUESTED, "IKE_AUTH_REQUESTED"},
{IKE_SA_INITIALIZED, "IKE_SA_INITIALIZED"},
{MAPPING_END, NULL}
};

View File

@ -0,0 +1,110 @@
/**
* @file state.h
*
* @brief Interface for a specific IKE_SA state
*
*/
/*
* 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 STATE_H_
#define STATE_H_
#include "../definitions.h"
#include "../types.h"
#include "../message.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 as initiator
*/
INITIATOR_INIT = 1,
/**
* IKE_SA is is not in a state as responder
*/
RESPONDER_INIT = 2,
/**
* A IKE_SA_INIT-message was sent: role initiator
*/
IKE_SA_INIT_REQUESTED = 3,
/**
* A IKE_SA_INIT-message was replied: role responder
*/
IKE_SA_INIT_RESPONDED = 4,
/**
* An IKE_AUTH-message was sent after a successful
* IKE_SA_INIT-exchange: role initiator
*/
IKE_AUTH_REQUESTED = 5,
/**
* 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 = 6
};
/**
* @brief This interface represents an IKE_SA state
*
*/
typedef struct state_s state_t;
struct state_s {
/**
* @brief Processes a incoming IKEv2-Message of type message_t
*
* @param this state_t object
* @param[in] message message_t object to process
* @param this state_t pointer to the new state_t object
* @return
* - SUCCESSFUL if succeeded
* - FAILED otherwise
*/
status_t (*process_message) (state_t *this,message_t *message,state_t **new_state);
/**
* @brief Get the current state
*
* @param this state_t object
* @return state
*/
ike_sa_state_t (*get_state) (state_t *this);
/**
* @brief Destroys a state_t object
*
* @param this state_t object
* @return SUCCESS in any case
*/
status_t (*destroy) (state_t *this);
};
#endif /*STATE_H_*/