/**
* @file configuration.c
- *
- * @brief Class configuration_t.
+ *
+ * @brief Class configuration_t.
* Object of this type represents a configuration for an IKE_SA
- *
+ *
*/
/*
* Private data of an configuration_t object
*/
typedef struct private_configuration_s private_configuration_t;
-
-struct private_configuration_s {
+
+struct private_configuration_s {
/**
* Public part of a configuration_t object
*/
configuration_t public;
-
-
+
+
/* Private values */
};
{
return FAILED;
}
- pfree(this);
+ allocator_free(this);
return SUCCESS;
}
*/
configuration_t * configuration_create()
{
- private_configuration_t *this = alloc_thing(private_configuration_t, "private_configuration_t");
+ private_configuration_t *this = allocator_alloc_thing(private_configuration_t, "private_configuration_t");
if (this == NULL)
{
return NULL;
}
-
+
/* Public functions */
this->public.destroy = (status_t(*)(configuration_t*))destroy;
-
- return (&this->public);
+
+ return (&this->public);
}
/**
* @file event_queue.c
- *
+ *
* @brief Event-Queue based on linked_list_t
- *
+ *
*/
/*
#include <pluto/defs.h>
#include <pthread.h>
#include <stdlib.h>
-
-
+
+
#include "types.h"
#include "event_queue.h"
#include "linked_list.h"
/**
* @brief represents an event as it is stored in the event queue
- *
+ *
* A event consists of a event time and an assigned job object
- *
+ *
*/
typedef struct event_s event_t;
/**
* @brief Destroys a event_t object
- *
+ *
* @param event_t calling object
* @returns SUCCESS if succeeded, FAILED otherwise
*/
status_t (*destroy) (event_t *event);
};
-
+
/**
* @brief implements function destroy of event_t
*/
{
return FAILED;
}
- pfree(event);
+ allocator_free(event);
return SUCCESS;
}
*
* @param time to fire the event
* @param job job to add to job-queue at specific time
- *
+ *
* @return event_t event object
*/
static event_t *event_create(timeval_t time, job_t *job)
{
- event_t *this = alloc_thing(event_t, "event_t");
+ event_t *this = allocator_alloc_thing(event_t, "event_t");
this->destroy = event_destroy;
this->time = time;
this->job = job;
-
+
return this;
}
/**
* @brief Private Variables and Functions of event_queue class
- *
+ *
*/
typedef struct private_event_queue_s private_event_queue_t;
-
+
struct private_event_queue_s {
event_queue_t public;
-
+
/**
* The events are stored in a linked list
*/
linked_list_t *list;
-
+
/**
* access to linked_list is locked through this mutex
*/
pthread_mutex_t mutex;
-
+
/**
* If the queue is empty or an event has not to be fired
* a thread has to wait
* This condvar is used to wake up such a thread
*/
- pthread_cond_t condvar;
+ pthread_cond_t condvar;
};
/**
* Returns the difference of to timeval structs in microseconds
- *
+ *
* @param end_time end time
* @param start_time start time
- *
+ *
* @warning this function is also defined in the tester class
* In later improvements, this function can be added to a general
* class type!
- *
+ *
* @return difference in microseconds
*/
static long time_difference(struct timeval *end_time, struct timeval *start_time)
{
long seconds, microseconds;
-
+
seconds = (end_time->tv_sec - start_time->tv_sec);
microseconds = (end_time->tv_usec - start_time->tv_usec);
return ((seconds * 1000000) + microseconds);
event_t * next_event;
int count;
int oldstate;
-
+
pthread_mutex_lock(&(this->mutex));
-
+
while (1)
{
this->list->get_count(this->list,&count);
/* add mutex unlock handler for cancellation, enable cancellation */
pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock, (void*)&(this->mutex));
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
-
+
pthread_cond_wait( &(this->condvar), &(this->mutex));
-
+
/* reset cancellation, remove mutex-unlock handler (without executing) */
pthread_setcancelstate(oldstate, NULL);
pthread_cleanup_pop(0);
-
+
this->list->get_count(this->list,&count);
}
-
+
this->list->get_first(this->list,(void **) &next_event);
-
+
gettimeofday(¤t_time,NULL);
long difference = time_difference(¤t_time,&(next_event->time));
if (difference <= 0)
{
/* event available */
this->list->remove_first(this->list,(void **) &next_event);
-
+
*job = next_event->job;
-
+
next_event->destroy(next_event);
break;
}
-
+
}
pthread_cond_signal( &(this->condvar));
-
+
pthread_mutex_unlock(&(this->mutex));
-
+
return SUCCESS;
}
event_t *current_event;
status_t status;
int count;
-
+
if (event == NULL)
{
return FAILED;
status = this->list->insert_first(this->list,event);
break;
}
-
+
/* check last entry */
this->list->get_last(this->list,(void **) ¤t_event);
status = this->list->insert_last(this->list,event);
break;
}
-
+
/* check first entry */
this->list->get_first(this->list,(void **) ¤t_event);
status = this->list->insert_first(this->list,event);
break;
}
-
+
linked_list_iterator_t * iterator;
-
+
status = this->list->create_iterator(this->list,&iterator,TRUE);
if (status != SUCCESS)
{
break;
}
-
-
+
+
iterator->has_next(iterator);
- /* first element has not to be checked (already done) */
-
+ /* first element has not to be checked (already done) */
+
while(iterator->has_next(iterator))
{
status = iterator->current(iterator,(void **) ¤t_event);
-
+
if (time_difference(&(event->time), &(current_event->time)) <= 0)
{
/* my event has to be fired before the current event in list */
- status = this->list->insert_before(this->list,iterator,event);
+ status = this->list->insert_before(this->list,iterator,event);
break;
}
}
{
event->destroy(event);
}
- return status;
+ return status;
}
/**
timeval_t current_time;
timeval_t time;
int micros = ms * 1000;
-
+
gettimeofday(¤t_time, NULL);
-
+
time.tv_usec = ((current_time.tv_usec + micros) % 1000000);
time.tv_sec = current_time.tv_sec + ((current_time.tv_usec + micros)/ 1000000);
-
+
return this->add_absolute(this, job, time);
}
* @brief implements function destroy of event_queue_t
*/
static status_t event_queue_destroy(private_event_queue_t *this)
-{
+{
int count;
this->list->get_count(this->list,&count);
while (count > 0)
{
- event_t *event;
-
+ event_t *event;
+
if (this->list->remove_first(this->list,(void *) &event) != SUCCESS)
{
this->list->destroy(this->list);
this->list->get_count(this->list,&count);
}
this->list->destroy(this->list);
-
+
pthread_mutex_destroy(&(this->mutex));
-
+
pthread_cond_destroy(&(this->condvar));
-
- pfree(this);
+
+ allocator_free(this);
return SUCCESS;
}
/*
- *
+ *
* Documented in header
*/
event_queue_t *event_queue_create()
{
return NULL;
}
-
- private_event_queue_t *this = alloc_thing(private_event_queue_t, "private_event_queue_t");
+
+ private_event_queue_t *this = allocator_alloc_thing(private_event_queue_t, "private_event_queue_t");
if (this == NULL)
{
linked_list->destroy(linked_list);
return NULL;
}
-
+
this->public.get_count = (status_t (*) (event_queue_t *event_queue, int *count)) get_count;
this->public.get = (status_t (*) (event_queue_t *event_queue, job_t **job)) get;
this->public.add_absolute = (status_t (*) (event_queue_t *event_queue, job_t *job, timeval_t time)) add_absolute;
this->public.add_relative = (status_t (*) (event_queue_t *event_queue, job_t *job, u_int32_t ms)) add_relative;
this->public.destroy = (status_t (*) (event_queue_t *event_queue)) event_queue_destroy;
-
+
this->list = linked_list;
pthread_mutex_init(&(this->mutex), NULL);
pthread_cond_init(&(this->condvar), NULL);
-
+
return (&this->public);
}
/**
* @file generator.c
- *
+ *
* @brief Generic generator class used to generate IKEv2-Header and Payload
- *
+ *
*/
/*
* Private data of a generator_t object
*/
typedef struct private_generator_s private_generator_t;
-
-struct private_generator_s {
+
+struct private_generator_s {
/**
* Public part of a generator object
*/
generator_t public;
-
+
/* private functions and fields */
-
+
/**
* Generates a chunk_t with specific encoding rules
- *
+ *
* items are bytewhise written
*
* @param this private_generator_t-object
* @param encoding_rules pointer to first encoding_rule of encoding rules array
* @param encoding_rules_count number of encoding rules in encoding rules array
* @param data pointer to chunk where to write the data in
- *
+ *
* @return SUCCESS if succeeded,
* OUT_OF_RES if out of ressources
*/
status_t (*generate) (private_generator_t *this,void * data_struct,encoding_rule_t *encoding_rules, size_t encoding_rules_count, chunk_t *data);
-
+
/**
* TODO
*/
status_t (*generate_u_int_type) (private_generator_t *this,encoding_type_t int_type,u_int8_t **buffer,u_int8_t **out_position,u_int8_t **roof_position,size_t *current_bit);
-
+
/**
* Pointer to the payload informations needed to automatic
* generate a specific payload type
static status_t generate_u_int_type (private_generator_t *this,encoding_type_t int_type,u_int8_t **buffer,u_int8_t **out_position,u_int8_t **roof_position,size_t *current_bit)
{
- size_t number_of_bits = 0;
-
+ size_t number_of_bits = 0;
+
switch (int_type)
{
case U_INT_4:
*/
static status_t generate (private_generator_t *this,void * data_struct,encoding_rule_t *encoding_rules, size_t encoding_rules_count, chunk_t *data)
{
- u_int8_t * buffer = alloc_bytes(GENERATOR_DATA_BUFFER_SIZE, "generator buffer");
+ u_int8_t * buffer = allocator_alloc(GENERATOR_DATA_BUFFER_SIZE, "generator buffer");
u_int8_t * out_position = buffer;
u_int8_t * roof_position = buffer + GENERATOR_DATA_BUFFER_SIZE;
size_t current_bit = 0;
}
if (status != SUCCESS)
{
- pfree(buffer);
+ allocator_free(buffer);
return status;
}
}
-
+
return SUCCESS;
}
static status_t generate_payload (private_generator_t *this,payload_type_t payload_type,void * data_struct, chunk_t *data)
{
int i;
-
+
/* check every payload info for specific type */
for (i = 0; this->payload_infos[i] != NULL; i++)
{
return FAILED;
}
- pfree(this);
+ allocator_free(this);
return SUCCESS;
}
generator_t * generator_create(payload_info_t ** payload_infos)
{
private_generator_t *this;
-
+
if (payload_infos == NULL)
{
return NULL;
}
-
- this = alloc_thing(private_generator_t,"private_generator_t");
+
+ this = allocator_alloc_thing(private_generator_t,"private_generator_t");
if (this == NULL)
{
return NULL;
}
-
+
this->public.generate_payload = (status_t(*)(generator_t*, payload_type_t, void *, chunk_t *)) generate_payload;
this->public.destroy = (status_t(*)(generator_t*)) destroy;
-
+
/* initiate private fields */
this->generate = generate;
this->generate_u_int_type = generate_u_int_type;
-
+
this->payload_infos = payload_infos;
-
+
return &(this->public);
}
/**
* @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
- *
+ *
*/
/*
* 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
+ * 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
+ * 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 {
+
+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
*/
static status_t process_configuration (private_ike_sa_t *this,configuration_t *configuration)
{
/*
- * @TODO Add configuration processing here
+ * @TODO Add configuration processing here
*/
return SUCCESS;
}
{
return FAILED;
}
-
+
this->ike_sa_id->destroy(this->ike_sa_id);
-
+
this->child_sas->destroy(this->child_sas);
- pfree(this);
-
+ allocator_free(this);
+
return SUCCESS;
}
*/
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");
+ private_ike_sa_t *this = allocator_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.get_id = (ike_sa_id_t*(*)(ike_sa_t*)) get_id;
+ this->public.process_configuration = (status_t(*)(ike_sa_t*, configuration_t*)) process_configuration;
+ this->public.get_id = (ike_sa_id_t*(*)(ike_sa_t*)) get_id;
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);
+ allocator_free(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);
+ allocator_free(this);
return NULL;
}
-
+
/* at creation time, IKE_SA isn't in a specific state */
this->current_state = NO_STATE;
-
- return (&this->public);
+
+ return (&this->public);
}
/**
* @file ike_sa_id.c
- *
+ *
* @brief Class for identification of an IKE_SA
- *
+ *
*/
/*
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
-
+
#include <stdlib.h>
#include <string.h>
#include <freeswan.h>
* Private data of an ike_sa_id object
*/
typedef struct private_ike_sa_id_s private_ike_sa_id_t;
-
-struct private_ike_sa_id_s {
+
+struct private_ike_sa_id_s {
/**
* Public part of a ike_sa_id object
*/
ike_sa_id_t public;
-
-
+
+
/* Private values */
-
+
/**
* SPI of Initiator
*/
spi_t initiator_spi;
-
+
/**
* SPI of Responder
*/
spi_t responder_spi;
-
+
/**
* Role for specific IKE_SA
*/
ike_sa_role_t role;
-
+
};
{
return FAILED;
}
- if ( (this->role == other->role) &&
+ if ( (this->role == other->role) &&
(this->initiator_spi.high == other->initiator_spi.high) &&
(this->initiator_spi.low == other->initiator_spi.low) &&
(this->responder_spi.high == other->responder_spi.high) &&
/* private_ike_sa_id's are not equal */
*are_equal = FALSE;
}
-
+
return SUCCESS;
}
{
return FAILED;
}
-
+
this->initiator_spi = other->initiator_spi;
this->responder_spi = other->responder_spi;
this->role = other->role;
-
+
return SUCCESS;
}
memcpy(initiator, &(this->initiator_spi), sizeof(initiator));
memcpy(responder, &(this->responder_spi), sizeof(responder));
*role = this->role;
-
+
return SUCCESS;
}
{
return FAILED;
}
-
+
*clone_of_this = ike_sa_id_create(this->initiator_spi, this->responder_spi, this->role);
-
+
return (*clone_of_this == NULL) ? FAILED : SUCCESS;
}
{
return FAILED;
}
- pfree(this);
+ allocator_free(this);
return SUCCESS;
}
*/
ike_sa_id_t * ike_sa_id_create(spi_t initiator_spi, spi_t responder_spi, ike_sa_role_t role)
{
- private_ike_sa_id_t *this = alloc_thing(private_ike_sa_id_t, "private_ike_sa_id_t");
+ private_ike_sa_id_t *this = allocator_alloc_thing(private_ike_sa_id_t, "private_ike_sa_id_t");
if (this == NULL)
{
return NULL;
}
-
+
/* Public functions */
this->public.set_responder_spi = (status_t(*)(ike_sa_id_t*,spi_t)) set_responder_spi;
this->public.set_initiator_spi = (status_t(*)(ike_sa_id_t*,spi_t)) set_initiator_spi;
this->initiator_spi = initiator_spi;
this->responder_spi = responder_spi;
this->role = role;
-
- return (&this->public);
+
+ return (&this->public);
}
/**
* @file ike_sa_manager.c
- *
+ *
* @brief Central point for managing IKE-SAs (creation, locking, deleting...)
- *
+ *
*/
/*
/**
* identifiaction of ike_sa (SPIs)
*/
- ike_sa_id_t *ike_sa_id;
+ ike_sa_id_t *ike_sa_id;
/**
* the contained ike_sa
*/
{
this->ike_sa->destroy(this->ike_sa);
this->ike_sa_id->destroy(this->ike_sa_id);
- pfree(this);
+ allocator_free(this);
return SUCCESS;
-
+
}
/**
* @brief creates a new entry for the ike_sa list
- *
+ *
* This constructor additionaly creates a new and empty SA
- *
+ *
* @param ike_sa_id the associated ike_sa_id_t, NOT cloned
* @return created entry, with ike_sa and ike_sa_id
*/
ike_sa_entry_t *ike_sa_entry_create(ike_sa_id_t *ike_sa_id)
{
- ike_sa_entry_t *this = alloc_thing(ike_sa_entry_t, "ike_sa_entry_t");
-
+ ike_sa_entry_t *this = allocator_alloc_thing(ike_sa_entry_t, "ike_sa_entry_t");
+
this->destroy = ike_sa_entry_destroy;
this->waiting_threads = 0;
pthread_cond_init(&(this->condvar), NULL);
/* we set checkout flag when we really give it out */
- this->checked_out = FALSE;
+ this->checked_out = FALSE;
this->ike_sa_id = ike_sa_id;
this->ike_sa = ike_sa_create(ike_sa_id);
return this;
* Public members
*/
ike_sa_manager_t public;
-
+
/**
* @brief get next spi
- *
+ *
* we give out SPIs incremental
- *
+ *
* @param this the ike_sa_manager
* @param spi[out] spi will be written here
* @return SUCCESS or,
status_t (*get_next_spi) (private_ike_sa_manager_t *this, spi_t *spi);
/**
* @brief find the ike_sa_entry in the list by SPIs
- *
+ *
* This function simply iterates over the linked list. A hash-table
* would be more efficient when storing a lot of IKE_SAs...
- *
+ *
* @param this the ike_sa_manager containing the list
* @param ike_sa_id id of the ike_sa, containing SPIs
* @param entry[out] pointer to set to the found entry
status_t (*get_entry_by_id) (private_ike_sa_manager_t *this, ike_sa_id_t *ike_sa_id, ike_sa_entry_t **entry);
/**
* @brief find the ike_sa_entry in the list by pointer to SA.
- *
+ *
* This function simply iterates over the linked list. A hash-table
* would be more efficient when storing a lot of IKE_SAs...
- *
+ *
* @param this the ike_sa_manager containing the list
* @param ike_sad pointer to the ike_sa
* @param entry[out] pointer to set to the found entry
*/
status_t (*get_entry_by_sa) (private_ike_sa_manager_t *this, ike_sa_t *ike_sa, ike_sa_entry_t **entry);
/**
- * @brief
+ * @brief
*/
status_t (*delete_entry) (private_ike_sa_manager_t *this, ike_sa_entry_t *entry);
/**
* lock for exclusivly accessing the manager
*/
pthread_mutex_t mutex;
-
+
/**
* Linked list with entries for the ike_sa
*/
/**
* Next SPI, needed for incremental creation of SPIs
*/
- spi_t next_spi;
+ spi_t next_spi;
};
{
ike_sa_entry_t *current;
iterator->current(iterator, (void**)¤t);
- if (current->ike_sa == ike_sa)
+ if (current->ike_sa == ike_sa)
{
*entry = current;
iterator->destroy(iterator);
bool responder_spi_set;
bool initiator_spi_set;
status_t retval;
-
+
pthread_mutex_lock(&(this->mutex));
-
+
responder_spi_set = ike_sa_id->responder_spi_is_set(ike_sa_id);
initiator_spi_set = ike_sa_id->initiator_spi_is_set(ike_sa_id);
-
- if (initiator_spi_set && responder_spi_set)
+
+ if (initiator_spi_set && responder_spi_set)
{
/* we SHOULD have an IKE_SA for these SPIs in the list,
* if not, we cant handle the request...
*/
ike_sa_entry_t *entry;
/* look for the entry */
- if (this->get_entry_by_id(this, ike_sa_id, &entry) == SUCCESS)
+ if (this->get_entry_by_id(this, ike_sa_id, &entry) == SUCCESS)
{
/* is this IKE_SA already checked out ?? */
- while (entry->checked_out)
- {
+ while (entry->checked_out)
+ {
/* so wait until we can get it for us.
* we register us as waiting.
*/
entry->checked_out = TRUE;
*ike_sa = entry->ike_sa;
/* DON'T use return, we must unlock the mutex! */
- retval = SUCCESS;
-
+ retval = SUCCESS;
+
}
else
{
/* looks like there is no such IKE_SA, better luck next time... */
-
+
/* DON'T use return, we must unlock the mutex! */
retval = NOT_FOUND;
}
spi_t responder_spi;
ike_sa_id_t *new_ike_sa_id;
ike_sa_entry_t *new_ike_sa_entry;
-
+
/* set SPIs, we are the responder */
ike_sa_id->clone(ike_sa_id, &new_ike_sa_id);
this->get_next_spi(this, &responder_spi);
new_ike_sa_id->set_responder_spi(new_ike_sa_id, responder_spi);
/* we also set arguments spi, so its still valid */
ike_sa_id->set_responder_spi(ike_sa_id, responder_spi);
-
+
/* create entry */
new_ike_sa_entry = ike_sa_entry_create(new_ike_sa_id);
this->list->insert_last(this->list, new_ike_sa_entry);
-
+
/* check ike_sa out */
new_ike_sa_entry->checked_out = TRUE;
*ike_sa = new_ike_sa_entry->ike_sa;
-
+
/* DON'T use return, we must unlock the mutex! */
retval = SUCCESS;
}
{
/* creation of an IKE_SA from local site,
* we are the initiator!
- */
+ */
spi_t initiator_spi, responder_spi;
ike_sa_id_t *new_ike_sa_id;
ike_sa_entry_t *new_ike_sa_entry;
-
+
/* set SPIs */
memset(&responder_spi, 0, sizeof(spi_t));
this->get_next_spi(this, &initiator_spi);
-
+
/* we also set arguments SPI, so its still valid */
ike_sa_id->set_initiator_spi(ike_sa_id, initiator_spi);
-
+
/* create entry */
new_ike_sa_id = ike_sa_id_create(initiator_spi, responder_spi, INITIATOR);
new_ike_sa_entry = ike_sa_entry_create(new_ike_sa_id);
this->list->insert_last(this->list, new_ike_sa_entry);
-
+
/* check ike_sa out */
new_ike_sa_entry->checked_out = TRUE;
*ike_sa = new_ike_sa_entry->ike_sa;
-
+
/* DON'T use return, we must unlock the mutex! */
retval = SUCCESS;
}
- else
+ else
{
/* responder set, initiator not: here is something seriously wrong! */
-
+
/* DON'T use return, we must unlock the mutex! */
retval = INVALID_ARG;
}
}
static status_t checkin_ike_sa(private_ike_sa_manager_t *this, ike_sa_t *ike_sa)
-{
- /* to check the SA back in, we look for the pointer of the ike_sa
+{
+ /* to check the SA back in, we look for the pointer of the ike_sa
* in all entries.
* We can't search by SPI's since the MAY have changed (e.g. on reception
* of a IKE_SA_INIT response). Updating of the SPI MAY be necessary...
*/
status_t retval;
ike_sa_entry_t *entry;
-
+
pthread_mutex_lock(&(this->mutex));
/* look for the entry */
- if (this->get_entry_by_sa(this, ike_sa, &entry) == SUCCESS)
+ if (this->get_entry_by_sa(this, ike_sa, &entry) == SUCCESS)
{
/* ike_sa_id must be updated */
entry->ike_sa_id->replace_values(entry->ike_sa_id, ike_sa->get_id(ike_sa));
/* signal waiting threads */
entry->checked_out = FALSE;
pthread_cond_signal(&(entry->condvar));
- retval = SUCCESS;
+ retval = SUCCESS;
}
else
{
- /* this SA is no more, this REALLY should not happen */
+ /* this SA is no more, this REALLY should not happen */
retval = NOT_FOUND;
}
pthread_mutex_unlock(&(this->mutex));
static status_t delete_ike_sa_by_sa(private_ike_sa_manager_t *this, ike_sa_t *ike_sa)
-{
- /* deletion is a bit complex, we must garant that no thread is waiting for
- * this SA.
+{
+ /* deletion is a bit complex, we must garant that no thread is waiting for
+ * this SA.
* We take this SA from the list, and start signaling while threads
- * are in the condvar.
+ * are in the condvar.
*/
linked_list_t *list = this->list;
linked_list_iterator_t *iterator;
ike_sa_entry_t *entry;
bool found = FALSE;
status_t retval;
-
+
pthread_mutex_lock(&(this->mutex));
-
+
/* remove SA from list */
list->create_iterator(list, &iterator, TRUE);
while (iterator->has_next(iterator))
}
}
iterator->destroy(iterator);
-
- if (found)
+
+ if (found)
{
/* wait until all workers have done their work */
while (entry->waiting_threads)
/* wake up all */
pthread_cond_signal(&(entry->condvar));
/* and the nice thing, they will wake us again when their work is done */
- pthread_cond_wait(&(entry->condvar), &(this->mutex));
+ pthread_cond_wait(&(entry->condvar), &(this->mutex));
}
-
+
/* ok, we are alone now, no threads waiting in the entry's condvar */
entry->destroy(entry);
retval = SUCCESS;
{
retval = NOT_FOUND;
}
-
+
pthread_mutex_unlock(&(this->mutex));
return retval;
}
static status_t delete_ike_sa_by_id(private_ike_sa_manager_t *this, ike_sa_id_t *ike_sa_id)
-{
- /* deletion is a bit complex, we must garant that no thread is waiting for
- * this SA.
+{
+ /* deletion is a bit complex, we must garant that no thread is waiting for
+ * this SA.
* We take this SA from the list, and start signaling while threads
- * are in the condvar.
+ * are in the condvar.
*/
linked_list_t *list = this->list;
linked_list_iterator_t *iterator;
ike_sa_entry_t *entry;
bool found = FALSE;
status_t retval;
-
+
pthread_mutex_lock(&(this->mutex));
-
+
/* remove SA from list */
list->create_iterator(list, &iterator, TRUE);
while (iterator->has_next(iterator))
}
}
iterator->destroy(iterator);
-
- if (found)
+
+ if (found)
{
/* wait until all workers have done their work */
while (entry->waiting_threads)
/* wake up all */
pthread_cond_signal(&(entry->condvar));
/* and the nice thing, they will wake us again when their work is done */
- pthread_cond_wait(&(entry->condvar), &(this->mutex));
+ pthread_cond_wait(&(entry->condvar), &(this->mutex));
}
-
+
/* ok, we are alone now, no threads waiting in the entry's condvar */
entry->destroy(entry);
retval = SUCCESS;
{
retval = NOT_FOUND;
}
-
+
pthread_mutex_unlock(&(this->mutex));
return retval;
}
entry->destroy(entry);
}
iterator->destroy(iterator);
-
+
list->destroy(list);
-
- pfree(this);
+
+ allocator_free(this);
return SUCCESS;
}
ike_sa_manager_t *ike_sa_manager_create()
{
- private_ike_sa_manager_t *this = alloc_thing(private_ike_sa_manager_t, "private_ike_sa_manager_t");
-
+ private_ike_sa_manager_t *this = allocator_alloc_thing(private_ike_sa_manager_t, "private_ike_sa_manager_t");
+
/* assign public functions */
this->public.destroy = (status_t(*)(ike_sa_manager_t*))destroy;
this->public.checkout_ike_sa = (status_t(*)(ike_sa_manager_t*, ike_sa_id_t *sa_id, ike_sa_t **sa))checkout_ike_sa;
this->public.checkin_ike_sa = (status_t(*)(ike_sa_manager_t*, ike_sa_t *sa))checkin_ike_sa;
this->public.delete_ike_sa_by_id = (status_t(*)(ike_sa_manager_t*, ike_sa_id_t *sa_id))delete_ike_sa_by_id;
this->public.delete_ike_sa_by_sa = (status_t(*)(ike_sa_manager_t*, ike_sa_t *ike_sa))delete_ike_sa_by_sa;
-
+
/* initialize private data */
this->get_next_spi = get_next_spi;
this->get_entry_by_sa = get_ike_sa_entry_by_sa;
this->get_entry_by_id = get_ike_sa_entry_by_id;
-
+
this->list = linked_list_create();
if (this->list == NULL)
{
- pfree(this);
- return NULL;
+ allocator_free(this);
+ return NULL;
}
-
+
pthread_mutex_init(&(this->mutex), NULL);
-
+
this->next_spi.low = 1;
this->next_spi.high = 0;
-
+
return (ike_sa_manager_t*)this;
}
/**
* @file job.c
- *
+ *
* @brief Job-Class representing a job e.g. in job_queue
- *
+ *
*/
/*
#include <freeswan.h>
#include <pluto/constants.h>
#include <pluto/defs.h>
-
+
#include "job.h"
-
+
/**
* @brief implements function destroy of job_t
*/
static status_t job_destroy(job_t *job)
{
- pfree(job);
+ allocator_free(job);
return SUCCESS;
}
*/
job_t *job_create(job_type_t type, void *assigned_data)
{
- job_t *this = alloc_thing(job_t, "job_t");
+ job_t *this = allocator_alloc_thing(job_t, "job_t");
this->destroy = job_destroy;
this->type = type;
this->assigned_data = assigned_data;
-
+
return this;
}
/**
* @file job_queue.c
- *
+ *
* @brief Job-Queue based on linked_list_t
- *
+ *
*/
/*
#include <freeswan.h>
#include <pluto/constants.h>
#include <pluto/defs.h>
-
+
#include "job_queue.h"
#include "linked_list.h"
/**
* @brief Private Variables and Functions of job_queue class
- *
+ *
*/
typedef struct private_job_queue_s private_job_queue_t;
-
+
struct private_job_queue_s {
job_queue_t public;
-
+
/**
* The jobs are stored in a linked list
*/
* access to linked_list is locked through this mutex
*/
pthread_mutex_t mutex;
-
+
/**
* If the queue is empty a thread has to wait
* This condvar is used to wake up such a thread
*/
- pthread_cond_t condvar;
+ pthread_cond_t condvar;
};
/* add mutex unlock handler for cancellation, enable cancellation */
pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock, (void*)&(this->mutex));
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
-
+
pthread_cond_wait( &(this->condvar), &(this->mutex));
-
+
/* reset cancellation, remove mutex-unlock handler (without executing) */
pthread_setcancelstate(oldstate, NULL);
pthread_cleanup_pop(0);
/**
* @brief implements function destroy of job_queue_t
- *
+ *
*/
static status_t job_queue_destroy (private_job_queue_t *this)
-{
+{
int count;
this->list->get_count(this->list,&count);
-
- while (count > 0)
+
+ while (count > 0)
{
job_t *job;
if (this->list->remove_first(this->list,(void *) &job) != SUCCESS)
this->list->get_count(this->list,&count);
}
this->list->destroy(this->list);
-
+
pthread_mutex_destroy(&(this->mutex));
-
+
pthread_cond_destroy(&(this->condvar));
-
- pfree(this);
+
+ allocator_free(this);
return SUCCESS;
}
/*
- *
+ *
* Documented in header
*/
job_queue_t *job_queue_create()
{
return NULL;
}
-
- private_job_queue_t *this = alloc_thing(private_job_queue_t, "private_job_queue_t");
+
+ private_job_queue_t *this = allocator_alloc_thing(private_job_queue_t, "private_job_queue_t");
if (this == NULL)
{
linked_list->destroy(linked_list);
return NULL;
}
-
+
this->public.get_count = (status_t(*)(job_queue_t*, int*))get_count;
this->public.get = (status_t(*)(job_queue_t*, job_t**))get;
this->public.add = (status_t(*)(job_queue_t*, job_t*))add;
this->public.destroy = (status_t(*)(job_queue_t*))job_queue_destroy;
-
+
this->list = linked_list;
pthread_mutex_init(&(this->mutex), NULL);
pthread_cond_init(&(this->condvar), NULL);
-
+
return (&this->public);
}
/**
* @file linked_list.c
- *
+ *
* @brief Generic Double Linked List
- *
+ *
*/
/*
#include <pluto/defs.h>
#include "linked_list.h"
-
+
typedef struct linked_list_element_s linked_list_element_t;
/**
* @brief Element of the linked_list.
- *
+ *
* This element holds a pointer to the value of the list item itself.
*/
struct linked_list_element_s{
* value of a list item
*/
void *value;
-
+
/**
* @brief Destroys a linked_list_element object
- *
+ *
* @param linked_list_element_t calling object
* @returns SUCCESS if succeeded, FAILED otherwise
*/
status_t (*destroy) (linked_list_element_t *this);
-
+
/**
- * previous list element
+ * previous list element
* NULL if first element in list
*/
linked_list_element_t *previous;
{
return FAILED;
}
- pfree(this);
+ allocator_free(this);
return SUCCESS;
}
* @brief Creates an empty linked list object
*
* @param[in] value value of item to be set
- *
+ *
* @warning only the pointer to the value is stored
- *
+ *
* @return linked_list_element object
*/
linked_list_element_t *linked_list_element_create(void *value)
{
- linked_list_element_t *this = alloc_thing(linked_list_element_t, "linked_list_element_t");
-
+ linked_list_element_t *this = allocator_alloc_thing(linked_list_element_t, "linked_list_element_t");
+
if (this == NULL)
{
return NULL;
}
-
+
this->destroy = linked_list_element_destroy;
-
+
this->previous=NULL;
this->next=NULL;
this->value = value;
-
+
return (this);
}
/**
* Private variables and functions of linked list
- *
+ *
*/
typedef struct private_linked_list_s private_linked_list_t;
* Public part of linked list
*/
linked_list_t public;
-
+
/**
* number of items in the list
*/
int count;
-
+
/**
* First element in list
* NULL if no elements in list
/**
* Private variables and functions of linked list iterator
- *
+ *
*/
typedef struct private_linked_list_iterator_s private_linked_list_iterator_t;
* Public part of linked list iterator
*/
linked_list_iterator_t public;
-
+
/**
* associated linked list
*/
private_linked_list_t * list;
-
+
/**
* current element of the iterator
*/
if (this->current == NULL)
{
this->current = (this->forward) ? this->list->first : this->list->last;
- return TRUE;
+ return TRUE;
}
if (this->forward)
{
return FALSE;
}
this->current = this->current->next;
- return TRUE;
+ return TRUE;
}
- /* backward */
+ /* backward */
if (this->current->previous == NULL)
{
return FALSE;
}
this->current = this->current->previous;
- return TRUE;
+ return TRUE;
}
/**
{
return FAILED;
}
- pfree(this);
+ allocator_free(this);
return SUCCESS;
}
static status_t create_iterator (private_linked_list_t *linked_list, linked_list_iterator_t **iterator,bool forward)
{
- private_linked_list_iterator_t *this = alloc_thing(private_linked_list_iterator_t, "private_linked_list_iterator_t");
-
+ private_linked_list_iterator_t *this = allocator_alloc_thing(private_linked_list_iterator_t, "private_linked_list_iterator_t");
+
if (this == NULL)
{
return FAILED;
}
-
+
this->public.has_next = (bool (*) (linked_list_iterator_t *this)) iterator_has_next;
this->public.current = (status_t (*) (linked_list_iterator_t *this, void **value)) iterator_current;
this->public.reset = (status_t (*) (linked_list_iterator_t *this)) iterator_reset;
this->public.destroy = (status_t (*) (linked_list_iterator_t *this)) iterator_destroy;
-
+
this->forward = forward;
this->current = NULL;
this->list = linked_list;
*iterator = &(this->public);
-
- return (SUCCESS);
+
+ return (SUCCESS);
}
-
+
/**
* @brief implements function insert_first of linked_list_t
*/
static status_t insert_first(private_linked_list_t *this, void *item)
{
linked_list_element_t *element;
-
+
if (this == NULL)
{
return FAILED;
}
-
+
element =(linked_list_element_t *) linked_list_element_create(item);
-
+
if (element == NULL)
{
return FAILED;
}
-
+
if (this->count == 0)
{
/* first entry in list */
old_first_element->previous = element;
this->first = element;
}
-
+
this->count++;
return SUCCESS;
* @brief implements function remove_first of linked_list_t
*/
static status_t remove_first(private_linked_list_t *this, void **item)
-{
+{
if (this == NULL)
{
return FAILED;
{
return FAILED;
}
-
+
if (this->first == NULL)
{
return FAILED;
}
-
+
linked_list_element_t *element = this->first;
-
+
if (element->next != NULL)
{
element->next->previous = NULL;
*item = element->value;
this->count--;
-
+
return (element->destroy(element));
}
* @brief implements function get_first of linked_list_t
*/
static status_t get_first(private_linked_list_t *this, void **item)
-{
+{
if (this == NULL)
{
return FAILED;
{
return FAILED;
}
-
+
if (this->first == NULL)
{
return FAILED;
}
-
+
*item = this->first->value;
return SUCCESS;
}
linked_list_element_t *element = (linked_list_element_t *) linked_list_element_create(item);
-
+
if (element == NULL)
{
return FAILED;
}
-
+
if (this->count == 0)
{
/* first entry in list */
old_last_element->next = element;
this->last = element;
}
-
+
this->count++;
-
+
return SUCCESS;
}
* @brief implements function remove_last of linked_list_t
*/
static status_t remove_last(private_linked_list_t *this, void **item)
-{
+{
if (this == NULL)
{
return FAILED;
{
return FAILED;
}
-
+
if (this->last == NULL)
{
return FAILED;
}
-
+
linked_list_element_t *element = this->last;
-
+
if (element->previous != NULL)
{
element->previous->next = NULL;
*item = element->value;
this->count--;
-
+
return (element->destroy(element));
}
{
return FAILED;
}
-
+
if (this->count == 0)
{
return FAILED;
}
-
+
if (this->last == NULL)
{
return FAILED;
}
-
+
*item = this->last->value;
return SUCCESS;
{
return FAILED;
}
-
+
if (this->count == 0)
{
return FAILED;
}
linked_list_element_t *element =(linked_list_element_t *) linked_list_element_create(item);
-
+
if (element == NULL)
{
return FAILED;
}
-
+
if (iterator->current->previous == NULL)
{
if (this->first != iterator->current)
element->destroy(element);
return FAILED;
}
-
+
iterator->current->previous = element;
element->next = iterator->current;
this->first = element;
iterator->current->previous = element;
element->next = iterator->current;
}
-
+
this->count++;
return SUCCESS;
{
return FAILED;
}
-
+
if (this->count == 0)
{
return FAILED;
}
linked_list_element_t *element =(linked_list_element_t *) linked_list_element_create(item);
-
+
if (element == NULL)
{
return FAILED;
}
-
+
if (iterator->current->next == NULL)
{
if (this->last != iterator->current)
element->destroy(element);
return FAILED;
}
-
+
iterator->current->next = element;
element->previous = iterator->current;
this->last = element;
iterator->current->next = element;
element->previous = iterator->current;
}
-
+
this->count++;
return SUCCESS;
}
static status_t linked_list_remove(private_linked_list_t *this, private_linked_list_iterator_t * iterator)
{
linked_list_element_t *new_current;
-
+
if ((this == NULL) || (iterator == NULL) || (iterator->current == NULL))
{
return FAILED;
}
-
+
if (this->count == 0)
{
return FAILED;
{
new_current = NULL;
}
-
+
/* now delete the entry :-) */
if (iterator->current->previous == NULL)
- {
+ {
if (iterator->current->next == NULL)
{
- this->first = NULL;
+ this->first = NULL;
this->last = NULL;
}
else
iterator->current->previous->next = iterator->current->next;
iterator->current->next->previous = iterator->current->previous;
}
-
+
this->count--;
iterator->current->destroy(iterator->current);
/* set the new iterator position */
{
return FAILED;
}
-
+
/* Remove all list items before destroying list */
while (this->count > 0)
{
* if list is not empty when deleting */
if (this->public.remove_first(&(this->public),&value) != SUCCESS)
{
- pfree(this);
+ allocator_free(this);
return FAILED;
}
}
- pfree(this);
+ allocator_free(this);
return SUCCESS;
}
-
+
/*
* Described in header
*/
-linked_list_t *linked_list_create()
+linked_list_t *linked_list_create()
{
- private_linked_list_t *this = alloc_thing(private_linked_list_t, "private_linked_list_t");
-
+ private_linked_list_t *this = allocator_alloc_thing(private_linked_list_t, "private_linked_list_t");
+
this->public.get_count = (status_t (*) (linked_list_t *linked_list, int *count)) get_count;
this->public.create_iterator = (status_t (*) (linked_list_t *linked_list, linked_list_iterator_t **iterator,bool forward)) create_iterator;
this->public.get_first = (status_t (*) (linked_list_t *linked_list, void **item)) get_first;
this->public.remove_first = (status_t (*) (linked_list_t *linked_list, void **item)) remove_first;
this->public.remove_last = (status_t (*) (linked_list_t *linked_list, void **item)) remove_last;
this->public.destroy = (status_t (*) (linked_list_t *linked_list)) linked_list_destroy;
-
+
this->count = 0;
this->first = NULL;
this->last = NULL;
-
+
return (&(this->public));
}
/**
* @file message.c
- *
+ *
* @brief Class message_t. Object of this type represents an IKEv2-Message
- *
+ *
*/
/*
* Private data of an message_t object
*/
typedef struct private_message_s private_message_t;
-
-struct private_message_s {
+
+struct private_message_s {
/**
* Public part of a message_t object
*/
message_t public;
-
-
+
+
/* Private values */
};
{
return FAILED;
}
- pfree(this);
+ allocator_free(this);
return SUCCESS;
}
*/
message_t * message_create()
{
- private_message_t *this = alloc_thing(private_message_t, "private_message_t");
+ private_message_t *this = allocator_alloc_thing(private_message_t, "private_message_t");
if (this == NULL)
{
return NULL;
}
-
+
/* Public functions */
this->public.destroy = (status_t(*)(message_t*))destroy;
-
- return (&this->public);
+
+ return (&this->public);
}
/**
* @file packet.h
- *
+ *
* @brief UDP-Packet, contains data, sender and receiver
- *
+ *
*/
/*
{
if (this->data.ptr != NULL)
{
- pfree(this->data.ptr);
+ allocator_free(this->data.ptr);
}
- pfree(this);
+ allocator_free(this);
return SUCCESS;
}
packet_t *packet_create(int family)
{
- packet_t *this = alloc_thing(packet_t, "packet_t");
-
+ packet_t *this = allocator_alloc_thing(packet_t, "packet_t");
+
this->destroy = destroy;
this->set_destination = set_destination;
this->set_source = set_source;
-
+
this->family = family;
switch (family)
{
this->sockaddr_len = sizeof(struct sockaddr_in);
break;
default: /* not supported */
- pfree(this);
- return NULL;
+ allocator_free(this);
+ return NULL;
}
this->data.len = 0;
- this->data.ptr = NULL;
+ this->data.ptr = NULL;
return this;
}
/**
* @file receiver.c
- *
+ *
* @brief Implements the Receiver Thread encapsulated in the receiver_t-object
- *
+ *
*/
/*
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
-
+
#include <stdlib.h>
#include <pthread.h>
#include <freeswan.h>
* Private data of a receiver object
*/
typedef struct private_receiver_s private_receiver_t;
-
-struct private_receiver_s {
+
+struct private_receiver_s {
/**
* Public part of a receiver object
*/
receiver_t public;
-
+
/**
* Assigned thread to the receiver_t-object
*/
/**
* Thread function started at creation of the receiver object
- *
+ *
* @param this assigned receiver object
* @return SUCCESS if thread_function ended successfully, FAILED otherwise
*/
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
packet_t * current_packet;
job_t * current_job;
-
+
while (1)
{
while (global_socket->receive(global_socket,¤t_packet) == SUCCESS)
if ( global_job_queue->add(global_job_queue,current_job) != SUCCESS)
{
/* Packet could not be sent */
- /* TODO LOG it */
+ /* TODO LOG it */
}
}
/* NOT GOOD !!!!!! */
- /* TODO LOG it */
+ /* TODO LOG it */
}
-
-
+
+
}
/**
static status_t destroy(private_receiver_t *this)
{
pthread_cancel(this->assigned_thread);
-
+
pthread_join(this->assigned_thread, NULL);
- pfree(this);
+ allocator_free(this);
return SUCCESS;
}
receiver_t * receiver_create()
{
- private_receiver_t *this = alloc_thing(private_receiver_t,"private_receiver_t");
-
+ private_receiver_t *this = allocator_alloc_thing(private_receiver_t,"private_receiver_t");
+
this->public.destroy = (status_t(*)(receiver_t*)) destroy;
if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))receiver_thread_function, this) != 0)
{
/* thread could not be created */
- pfree(this);
+ allocator_free(this);
return NULL;
}
-
+
return &(this->public);
}
/**
* @file scheduler.c
- *
+ *
* @brief implements the scheduler, looks for jobs in event-queue
- *
+ *
*/
/*
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
-
+
#include <stdlib.h>
#include <pthread.h>
#include <freeswan.h>
#include <pluto/constants.h>
#include <pluto/defs.h>
-
+
#include "scheduler.h"
#include "job_queue.h"
#include "globals.h"
-
+
/**
* Private data of a scheduler object
*/
typedef struct private_scheduler_s private_scheduler_t;
-
-struct private_scheduler_s {
+
+struct private_scheduler_s {
/**
* Public part of a scheduler object
*/
scheduler_t public;
-
+
/**
* Assigned thread to the scheduler_t-object
*/
/**
* Thread function started at creation of the scheduler object
- *
+ *
* @param this assigned scheduler object
* @return SUCCESS if thread_function ended successfully, FAILED otherwise
*/
/* cancellation disabled by default */
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
job_t *current_job;
-
+
for (;;)
{
/* get a job, this block until one is available */
static status_t destroy(private_scheduler_t *this)
{
pthread_cancel(this->assigned_thread);
-
+
pthread_join(this->assigned_thread, NULL);
- pfree(this);
+ allocator_free(this);
return SUCCESS;
}
scheduler_t * scheduler_create()
{
- private_scheduler_t *this = alloc_thing(private_scheduler_t,"private_scheduler_t");
-
+ private_scheduler_t *this = allocator_alloc_thing(private_scheduler_t,"private_scheduler_t");
+
this->public.destroy = (status_t(*)(scheduler_t*)) destroy;
if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))scheduler_thread_function, this) != 0)
{
/* thread could not be created */
- pfree(this);
+ allocator_free(this);
return NULL;
}
-
+
return &(this->public);
}
/**
* @file send_queue.c
- *
+ *
* @brief Send-Queue based on linked_list_t
- *
+ *
*/
/*
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
-
+
#include <pthread.h>
-
+
#include "send_queue.h"
#include "linked_list.h"
-
+
/**
* @brief Private Variables and Functions of send_queue class
- *
+ *
*/
typedef struct private_send_queue_s private_send_queue_t;
-
+
struct private_send_queue_s {
/**
* Public part of the send_queue_t object
*/
send_queue_t public;
-
+
/**
* The packets are stored in a linked list
*/
linked_list_t *list;
-
+
/**
* access to linked_list is locked through this mutex
*/
pthread_mutex_t mutex;
-
+
/**
* If the queue is empty a thread has to wait
* This condvar is used to wake up such a thread
*/
- pthread_cond_t condvar;
+ pthread_cond_t condvar;
};
-
-
+
+
/**
* @brief implements function get_count of send_queue_t
*/
pthread_mutex_unlock(&(this->mutex));
return SUCCESS;
}
-
+
/**
* @brief implements function get of send_queue_t
*/
pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock, (void*)&(this->mutex));
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
pthread_cond_wait( &(this->condvar), &(this->mutex));
-
+
/* reset cancellation, remove mutex-unlock handler (without executing) */
pthread_setcancelstate(oldstate, NULL);
pthread_cleanup_pop(0);
pthread_mutex_unlock(&(this->mutex));
return SUCCESS;
}
-
+
/**
* @brief implements function add of send_queue_t
*/
pthread_mutex_unlock(&(this->mutex));
return SUCCESS;
}
-
+
/**
* @brief implements function destroy of send_queue_t
- *
+ *
*/
static status_t destroy (private_send_queue_t *this)
{
int count;
this->list->get_count(this->list,&count);
-
+
/* destroy all packets in list before destroying list */
- while (count > 0)
+ while (count > 0)
{
packet_t *packet;
if (this->list->remove_first(this->list,(void *) &packet) != SUCCESS)
this->list->get_count(this->list,&count);
}
this->list->destroy(this->list);
-
+
pthread_mutex_destroy(&(this->mutex));
-
+
pthread_cond_destroy(&(this->condvar));
-
- pfree(this);
+
+ allocator_free(this);
return SUCCESS;
}
-
+
/*
- *
+ *
* Documented in header
*/
send_queue_t *send_queue_create()
{
return NULL;
}
-
- private_send_queue_t *this = alloc_thing(private_send_queue_t, "private_send_queue_t");
+
+ private_send_queue_t *this = allocator_alloc_thing(private_send_queue_t, "private_send_queue_t");
if (this == NULL)
{
linked_list->destroy(linked_list);
return NULL;
}
-
+
this->public.get_count = (status_t(*)(send_queue_t*, int*)) get_count;
this->public.get = (status_t(*)(send_queue_t*, packet_t**)) get;
this->public.add = (status_t(*)(send_queue_t*, packet_t*)) add;
this->public.destroy = (status_t(*)(send_queue_t*)) destroy;
-
+
this->list = linked_list;
pthread_mutex_init(&(this->mutex), NULL);
pthread_cond_init(&(this->condvar), NULL);
-
+
return (&this->public);
}
/**
* @file sender.c
- *
+ *
* @brief Implements the Sender Thread encapsulated in the sender_t-object
- *
+ *
*/
/*
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
-
+
#include <stdlib.h>
#include <pthread.h>
#include <freeswan.h>
#include <pluto/constants.h>
#include <pluto/defs.h>
-
+
#include "sender.h"
#include "socket.h"
#include "packet.h"
#include "send_queue.h"
#include "globals.h"
-
+
/**
* Private data of a sender object
*/
typedef struct private_sender_s private_sender_t;
-
-struct private_sender_s {
+
+struct private_sender_s {
/**
* Public part of a sender object
*/
sender_t public;
-
+
/**
* Assigned thread to the sender_t-object
*/
/**
* Thread function started at creation of the sender object
- *
+ *
* @param this assigned sender object
* @return SUCCESS if thread_function ended successfully, FAILED otherwise
*/
/* cancellation disabled by default */
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
packet_t * current_packet;
-
+
while (1)
{
while (global_send_queue->get(global_send_queue,¤t_packet) == SUCCESS)
{
if ( global_socket->send(global_socket,current_packet) == SUCCESS)
{
- current_packet->destroy(current_packet);
+ current_packet->destroy(current_packet);
}
else
{
/* Packet could not be sent */
- /* TODO LOG it */
+ /* TODO LOG it */
}
}
/* NOT GOOD !!!!!! */
- /* TODO LOG it */
+ /* TODO LOG it */
}
-
-
+
+
}
/**
static status_t destroy(private_sender_t *this)
{
pthread_cancel(this->assigned_thread);
-
+
pthread_join(this->assigned_thread, NULL);
- pfree(this);
+ allocator_free(this);
return SUCCESS;
}
sender_t * sender_create()
{
- private_sender_t *this = alloc_thing(private_sender_t,"private_sender_t");
-
+ private_sender_t *this = allocator_alloc_thing(private_sender_t,"private_sender_t");
+
this->public.destroy = (status_t(*)(sender_t*)) destroy;
if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))sender_thread_function, this) != 0)
{
/* thread could not be created */
- pfree(this);
+ allocator_free(this);
return NULL;
}
-
+
return &(this->public);
}
/**
* @file socket.c
- *
+ *
* @brief management of sockets
- *
+ *
* receiver reads from here, sender writes to here
- *
+ *
*/
/*
* public functions
*/
socket_t public;
-
+
/**
* currently we only have one socket, maybe more in the future ?
*/
char buffer[MAX_PACKET];
int oldstate;
packet_t *pkt = packet_create(AF_INET);
-
-
+
+
/* add packet destroy handler for cancellation, enable cancellation */
pthread_cleanup_push((void(*)(void*))pkt->destroy, (void*)pkt);
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
-
+
/* do the read */
- pkt->data.len = recvfrom(this->socket_fd, buffer, MAX_PACKET, 0,
+ pkt->data.len = recvfrom(this->socket_fd, buffer, MAX_PACKET, 0,
&(pkt->source), &(pkt->sockaddr_len));
-
+
/* reset cancellation, remove packet destroy handler (without executing) */
pthread_setcancelstate(oldstate, NULL);
pthread_cleanup_pop(0);
-
-
- /* TODO: get senders destination address, using
+
+
+ /* TODO: get senders destination address, using
* IP_PKTINFO and recvmsg */
-
+
if (pkt->data.len < 0)
{
pkt->destroy(pkt);
/* TODO: log detailed error */
return FAILED;
}
-
+
/* fill in packet */
- pkt->data.ptr = alloc_bytes(pkt->data.len, "data in packet_t");
+ pkt->data.ptr = allocator_alloc(pkt->data.len, "data in packet_t");
memcpy(pkt->data.ptr, buffer, pkt->data.len);
-
+
/* return packet */
*packet = pkt;
-
- return SUCCESS;
+
+ return SUCCESS;
}
-
+
/**
* implementation of socket_t.send
*/
-status_t sender(private_socket_t *this, packet_t *packet)
+status_t sender(private_socket_t *this, packet_t *packet)
{
ssize_t bytes_sent;
-
+
/* send data */
- bytes_sent = sendto(this->socket_fd, packet->data.ptr, packet->data.len,
+ bytes_sent = sendto(this->socket_fd, packet->data.ptr, packet->data.len,
0, &(packet->destination), packet->sockaddr_len);
-
- if (bytes_sent != packet->data.len)
+
+ if (bytes_sent != packet->data.len)
{
/* TODO: log detailed error */
return FAILED;
}
return SUCCESS;
}
-
+
/**
* implementation of socket_t.destroy
*/
status_t destroy(private_socket_t *this)
{
close(this->socket_fd);
- pfree(this);
-
+ allocator_free(this);
+
return SUCCESS;
}
socket_t *socket_create(u_int16_t port)
{
- private_socket_t *this = alloc_thing(private_socket_t, "private_socket_t");
+ private_socket_t *this = allocator_alloc_thing(private_socket_t, "private_socket_t");
struct sockaddr_in addr;
-
+
/* public functions */
this->public.send = (status_t(*)(socket_t*, packet_t*))sender;
this->public.receive = (status_t(*)(socket_t*, packet_t**))receiver;
this->public.destroy = (status_t(*)(socket_t*))destroy;
-
+
/* create default ipv4 socket */
this->socket_fd = socket(PF_INET, SOCK_DGRAM, 0);
if (this->socket_fd < 0) {
- pfree(this);
+ allocator_free(this);
/* TODO: log detailed error */
return NULL;
- }
-
+ }
+
/* bind socket to all interfaces */
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = INADDR_ANY;
addr.sin_port = htons(port);
if (bind(this->socket_fd,(struct sockaddr*)&addr, sizeof(addr)) < 0) {
- pfree(this);
+ allocator_free(this);
/* TODO: log detailed error */
return NULL;
}
-
+
return (socket_t*)this;
}
/**
* @file tester.c
- *
+ *
* @brief Test module for automatic testing
- *
+ *
*/
/*
#include <string.h>
#include <pthread.h>
#include <sys/time.h>
-
+
#include "tester.h"
#include "linked_list.h"
#include "thread_pool.h"
/**
* @brief Private Variables and Functions of tester class
- *
+ *
*/
typedef struct private_tester_s private_tester_t;
-
+
struct private_tester_s {
tester_t public;
-
+
/* Private functions */
void (*run_test) (tester_t *tester, void (*test_function) (tester_t * tester), char * test_name);
-
-
+
+
/* Private values */
FILE* output;
int tests_count;
bool display_succeeded_asserts;
pthread_mutex_t mutex;
};
-
+
/*
* Implementation of function perform_tests
*/
-static status_t perform_tests(tester_t *tester,test_t **tests)
+static status_t perform_tests(tester_t *tester,test_t **tests)
{
private_tester_t *this =(private_tester_t*) tester;
int current_test = 0;
this->run_test(tester,tests[current_test]->test_function,tests[current_test]->test_name);
current_test++;
}
-
+
fprintf(this->output,"End testing. %d of %d tests succeeded\n",this->tests_count - this->failed_tests_count,this->tests_count);
return SUCCESS;
/*
* Implementation of function perform_test
*/
-static status_t perform_test(tester_t *tester, test_t *test)
+static status_t perform_test(tester_t *tester, test_t *test)
{
test_t *tests[] = {test, NULL};
return (perform_tests(tester,tests));
/**
* Returns the difference of to timeval structs in microseconds
- *
+ *
* @param end_time end time
* @param start_time start time
- *
+ *
* @warning this function is also defined in the event queue
* in later improvements, this function can be added to a general
* class type!
- *
+ *
* @return difference in microseconds
*/
static long time_difference(struct timeval *end_time, struct timeval *start_time)
{
long seconds, microseconds;
-
+
seconds = (end_time->tv_sec - start_time->tv_sec);
microseconds = (end_time->tv_usec - start_time->tv_usec);
return ((seconds * 1000000) + microseconds);
/**
- * Implementation of function run_test
+ * Implementation of function run_test
*/
static void run_test(tester_t *tester, void (*test_function) (tester_t * tester), char * test_name)
{
test_function(tester);
gettimeofday(&end_time,NULL);
timediff = time_difference(&end_time, &start_time);
-
+
fprintf(this->output,"End Test '%s' in %ld microseconds\n", test_name,timediff);
if (this->failed_asserts_count > 0)
{
}
/**
- * Implementation of function assert_true
+ * Implementation of function assert_true
*/
static void assert_true(tester_t *tester, bool to_be_true,char * assert_name)
{
private_tester_t *this = (private_tester_t *) tester;
-
+
if (assert_name == NULL)
{
assert_name = "unknown";
}
-
+
pthread_mutex_lock(&(this->mutex));
if (!to_be_true)
{
this->failed_asserts_count++;
- fprintf(this->output," Assert '%s' failed!\n", assert_name);
+ fprintf(this->output," Assert '%s' failed!\n", assert_name);
}else
{
if (this->display_succeeded_asserts)
{
- fprintf(this->output," Assert '%s' succeeded\n", assert_name);
+ fprintf(this->output," Assert '%s' succeeded\n", assert_name);
}
}
pthread_mutex_unlock(&(this->mutex));
/**
* Implements the destroy function
*/
-static status_t destroy(tester_t *tester)
+static status_t destroy(tester_t *tester)
{
private_tester_t *this = (private_tester_t*) tester;
pthread_mutex_destroy(&(this->mutex));
- pfree(this);
+ allocator_free(this);
return SUCCESS;
}
-tester_t *tester_create(FILE *output, bool display_succeeded_asserts)
+tester_t *tester_create(FILE *output, bool display_succeeded_asserts)
{
- private_tester_t *this = alloc_thing(private_tester_t, "private_tester_t");
-
+ private_tester_t *this = allocator_alloc_thing(private_tester_t, "private_tester_t");
+
this->public.destroy = destroy;
this->public.perform_tests = perform_tests;
this->public.perform_test = perform_test;
this->public.assert_true = assert_true;
this->public.assert_false = assert_false;
-
-
+
+
this->run_test = run_test;
- this->display_succeeded_asserts = display_succeeded_asserts;
+ this->display_succeeded_asserts = display_succeeded_asserts;
this->failed_tests_count = 0;
this->tests_count = 0;
this->output = output;
pthread_mutex_init(&(this->mutex),NULL);
-
+
return &(this->public);
}
/**
* @file event_queue_test.h
- *
+ *
* @brief Tests to test the Event-Queue type event_queue_t
- *
+ *
*/
/*
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
-
+
#include <stdlib.h>
#include <pthread.h>
-
+
#include "event_queue_test.h"
#include "../tester.h"
#include "../event_queue.h"
/**
* @brief Informations for the involved test-thread used in this test
- *
+ *
*/
typedef struct event_queue_test_s event_queue_test_t;
struct event_queue_test_s{
tester_t *tester;
event_queue_t *event_queue;
-
+
/**
* number of different event times to be inserted in the event-queue by each thread
*/
- int insert_times_count;
-
+ int insert_times_count;
+
/**
* number of event to insert at one time
*/
- int entries_per_time;
+ int entries_per_time;
};
timeval_t time;
job_t * job;
int i,j;
-
+
gettimeofday(¤t_time,NULL);
for (i = 0; i < testinfos->insert_times_count;i++)
{
for (j = 0; j < testinfos->entries_per_time;j++)
{
- int *value = alloc_thing(int, "value");
+ int *value = allocator_alloc_thing(int, "value");
*value = i;
job = job_create(INCOMING_PACKET,value);
time.tv_usec = 0;
time.tv_sec = current_time.tv_sec + i;
-
+
tester->assert_true(tester,(testinfos->event_queue->add_absolute(testinfos->event_queue,job,time) == SUCCESS), "add call check");
}
- }
+ }
}
int i,j, number_of_total_events;
int count;
timeval_t current_time, start_time;
-
+
testinfos.tester = tester;
testinfos.event_queue = event_queue;
testinfos.insert_times_count = EVENT_QUEUE_TIMES;
testinfos.entries_per_time = EVENT_QUEUE_ENTRY_PER_TIME;
-
+
number_of_total_events = EVENT_QUEUE_ENTRY_PER_TIME * EVENT_QUEUE_TIMES * EVENT_QUEUE_INSERT_THREADS;
-
+
gettimeofday(&start_time,NULL);
-
+
for (i = 0; i < EVENT_QUEUE_INSERT_THREADS; i++)
{
pthread_create( &threads[i], NULL,(void*(*)(void*)) &event_queue_insert_thread, (void*) &testinfos);
}
-
-
+
+
/* wait for all threads */
for (i = 0; i < EVENT_QUEUE_INSERT_THREADS; i++)
}
tester->assert_true(tester,(event_queue->get_count(event_queue,&count) == SUCCESS), "get_count call check");
- tester->assert_true(tester,(count == number_of_total_events), "event count check");
-
+ tester->assert_true(tester,(count == number_of_total_events), "event count check");
+
for (i = 0; i < EVENT_QUEUE_TIMES;i++)
{
for (j = 0; j < (EVENT_QUEUE_ENTRY_PER_TIME * EVENT_QUEUE_INSERT_THREADS);j++)
{
job_t *job;
- tester->assert_true(tester,(event_queue->get(event_queue,&job) == SUCCESS), "get call check");
+ tester->assert_true(tester,(event_queue->get(event_queue,&job) == SUCCESS), "get call check");
gettimeofday(¤t_time,NULL);
- tester->assert_true(tester,((current_time.tv_sec - start_time.tv_sec) == i), "value of entry check");
-
- pfree(job->assigned_data);
- tester->assert_true(tester,(job->destroy(job) == SUCCESS), "job destroy call check");
+ tester->assert_true(tester,((current_time.tv_sec - start_time.tv_sec) == i), "value of entry check");
+
+ allocator_free(job->assigned_data);
+ tester->assert_true(tester,(job->destroy(job) == SUCCESS), "job destroy call check");
}
}
-
+
tester->assert_true(tester,(event_queue->destroy(event_queue) == SUCCESS), "destroy call check");
}
/**
* @file job_queue_test.c
- *
+ *
* @brief Tests to test the Job-Queue type job_queue_t
- *
+ *
*/
/*
* for more details.
*/
-
+
#include <stdlib.h>
#include <freeswan.h>
#include <pluto/constants.h>
#include <pluto/defs.h>
#include <pthread.h>
#include <unistd.h>
-
+
#include "job_queue_test.h"
#include "../tester.h"
#include "../job_queue.h"
-
-
+
+
typedef struct job_queue_test_s job_queue_test_t;
/**
* @brief Informations for the involved test-thread used in this test
- *
+ *
*/
struct job_queue_test_s{
tester_t *tester;
job_queue_t *job_queue;
/**
- * number of items to be inserted in the job-queue
+ * number of items to be inserted in the job-queue
*/
- int insert_item_count;
+ int insert_item_count;
/**
- * number of items to be removed by each
- * receiver thread from the job-queue
+ * number of items to be removed by each
+ * receiver thread from the job-queue
*/
- int remove_item_count;
+ int remove_item_count;
};
/**
* @brief sender thread used in the the job_queue test function
- *
+ *
* @param testinfo informations for the specific thread.
*/
static void test_job_queue_sender(job_queue_test_t * testinfo)
{
- int i;
+ int i;
for (i = 0; i < testinfo->insert_item_count; i++)
{
- int *value = alloc_thing(int,"int in test_job_queue_sender");
+ int *value = allocator_alloc_thing(int,"int in test_job_queue_sender");
*value = i;
job_t *job = job_create(INCOMING_PACKET,value);
testinfo->job_queue->add(testinfo->job_queue,job);
/**
* @brief receiver thread used in the the job_queue test function
- *
+ *
* @param testinfo informations for the specific thread.
*/
static void test_job_queue_receiver(job_queue_test_t * testinfo)
{
job_t *job;
testinfo->tester->assert_true(testinfo->tester,(testinfo->job_queue->get(testinfo->job_queue,&job) == SUCCESS), "get job call check");
- testinfo->tester->assert_true(testinfo->tester,(job->type == INCOMING_PACKET), "job type check");
- pfree(job->assigned_data);
+ testinfo->tester->assert_true(testinfo->tester,(job->type == INCOMING_PACKET), "job type check");
+ allocator_free(job->assigned_data);
testinfo->tester->assert_true(testinfo->tester,(job->destroy(job) == SUCCESS), "job destroy call check");
}
}
test_infos.job_queue = job_queue;
test_infos.insert_item_count = 10000;
test_infos.remove_item_count = 50000;
-
-
- desired_value = test_infos.insert_item_count * sender_count -
+
+
+ desired_value = test_infos.insert_item_count * sender_count -
test_infos.remove_item_count * receiver_count;
-
+
for (i = 0; i < receiver_count;i++)
{
pthread_create( &receiver_threads[i], NULL,(void*(*)(void*)) &test_job_queue_receiver, (void*) &test_infos);
{
pthread_create( &sender_threads[i], NULL,(void*(*)(void*)) &test_job_queue_sender, (void*) &test_infos);
}
-
-
+
+
/* Wait for all threads */
for (i = 0; i < sender_count;i++)
{
{
pthread_join(receiver_threads[i], NULL);
}
-
+
/* the job-queue has to have disered_value count entries! */
tester->assert_true(tester,(job_queue->get_count(job_queue,&value) == SUCCESS), "get count call check");
- tester->assert_true(tester,(value == desired_value), "get count value check");
-
+ tester->assert_true(tester,(value == desired_value), "get count value check");
+
tester->assert_true(tester,(job_queue->destroy(job_queue) == SUCCESS), "destroy call check");
}
/**
* @file receiver_test.c
- *
+ *
* @brief Tests to test the Receiver (type receiver_t)
- *
+ *
*/
/*
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
-
+
#include <string.h>
#include <unistd.h>
* Destination IP Address
*/
#define DESTINATION_IP "127.0.0.1"
-
+
void test_receiver(tester_t *tester)
{
int i;
job_t *job;
packet_t *received_packet;
receiver = receiver_create();
-
+
for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
{
packet = packet_create(AF_INET);
packet->set_destination(packet,DESTINATION_IP,PORT_TO_SEND);
- packet->data.ptr = alloc_thing(int, "packet data");
+ packet->data.ptr = allocator_alloc_thing(int, "packet data");
packet->data.len = ( sizeof(int));
*((int *) (packet->data.ptr)) = i;
global_socket->send(global_socket,packet);
packet->destroy(packet);
}
-
+
for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
{
- global_job_queue->get(global_job_queue,&job);
+ global_job_queue->get(global_job_queue,&job);
tester->assert_true(tester, (job->type == INCOMING_PACKET), "job type check");
received_packet = (packet_t *) job->assigned_data;
tester->assert_true(tester, (received_packet->data.len == (sizeof(int))), "received data length check");
received_packet->destroy(received_packet);
job->destroy(job);
- }
-
+ }
+
tester->assert_true(tester, (receiver->destroy(receiver) == SUCCESS), "destroy call check");
}
/**
* @file sender_test.h
- *
+ *
* @brief Tests to test the Sender (type sender_t)
- *
+ *
*/
/*
* Destination IP Address
*/
#define DESTINATION_IP "127.0.0.1"
-
+
void test_sender(tester_t *tester)
{
int i;
packet_t *packet;
packet_t *received_packet;
sender = sender_create();
-
+
for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
{
packet = packet_create(AF_INET);
packet->set_destination(packet,DESTINATION_IP,PORT_TO_SEND);
- packet->data.ptr = alloc_thing(int, "packet data");
+ packet->data.ptr = allocator_alloc_thing(int, "packet data");
packet->data.len = ( sizeof(int));
*((int *) (packet->data.ptr)) = i;
global_send_queue->add(global_send_queue,packet);
}
-
+
for (i = 0; i < NUMBER_OF_PACKETS_TO_SEND; i++)
{
global_socket->receive(global_socket,&received_packet);
tester->assert_true(tester, (received_packet->data.len == (sizeof(int))), "received data length check");
tester->assert_true(tester, (i == *((int *)(received_packet->data.ptr))), "received data value check");
received_packet->destroy(received_packet);
- }
-
+ }
+
tester->assert_true(tester, (sender->destroy(sender) == SUCCESS), "destroy call check");
}
/**
* @file thread_pool_test.c
- *
+ *
* @brief Tests to test the Socket (type socket_t)
- *
+ *
*/
/*
* Description in header file
*/
void test_socket(tester_t *tester)
-{
+{
int packet_count = 5;
int current;
socket_t *skt = socket_create(4500);
packet_t *pkt = packet_create(AF_INET);
char *test_string = "Testing functionality of socket_t";
-
-
- pkt->data.ptr = alloc_bytes(strlen(test_string) + 1,"test_string");
+
+
+ pkt->data.ptr = allocator_alloc(strlen(test_string) + 1,"test_string");
memcpy(pkt->data.ptr,test_string,strlen(test_string) + 1);
pkt->data.len = strlen(test_string) + 1;
-
+
/* send to previously bound socket */
pkt->set_destination(pkt, "127.0.0.1", 4500);
/* send packet_count packets */
for (current = 0; current < packet_count; current++)
{
- if (skt->send(skt, pkt) == FAILED)
+ if (skt->send(skt, pkt) == FAILED)
{
tester->assert_true(tester, 0, "packet send");
}
}
pkt->destroy(pkt);
-
+
/* receive packet_count packets */
for (current = 0; current < packet_count; current++)
{
tester->assert_false(tester, strcmp(test_string, pkt->data.ptr), "packet exchange");
pkt->destroy(pkt);
}
-
+
tester->assert_true(tester, (skt->destroy(skt) == SUCCESS), "socket destroy call check");
}