aboutsummaryrefslogtreecommitdiffstats
path: root/Source/charon/threads
diff options
context:
space:
mode:
Diffstat (limited to 'Source/charon/threads')
-rw-r--r--Source/charon/threads/kernel_interface.c23
-rw-r--r--Source/charon/threads/receiver.c9
-rw-r--r--Source/charon/threads/scheduler.c9
-rw-r--r--Source/charon/threads/sender.c9
-rwxr-xr-xSource/charon/threads/stroke_interface.c51
-rw-r--r--Source/charon/threads/thread_pool.c40
6 files changed, 76 insertions, 65 deletions
diff --git a/Source/charon/threads/kernel_interface.c b/Source/charon/threads/kernel_interface.c
index 87238d079..180ea55a5 100644
--- a/Source/charon/threads/kernel_interface.c
+++ b/Source/charon/threads/kernel_interface.c
@@ -35,7 +35,6 @@
#include "kernel_interface.h"
#include <daemon.h>
-#include <utils/allocator.h>
#include <utils/linked_list.h>
@@ -239,7 +238,7 @@ static status_t get_spi(private_kernel_interface_t *this,
}
*spi = response->sa.id.spi;
- allocator_free(response);
+ free(response);
return status;
}
@@ -329,7 +328,7 @@ static status_t add_sa( private_kernel_interface_t *this,
status = FAILED;
}
- allocator_free(response);
+ free(response);
return SUCCESS;
}
@@ -366,7 +365,7 @@ static status_t del_sa( private_kernel_interface_t *this,
status = FAILED;
}
- allocator_free(response);
+ free(response);
return SUCCESS;
}
@@ -458,7 +457,7 @@ static status_t add_policy(private_kernel_interface_t *this,
status = FAILED;
}
- allocator_free(response);
+ free(response);
return status;
}
@@ -506,7 +505,7 @@ static status_t del_policy(private_kernel_interface_t *this,
status = FAILED;
}
- allocator_free(response);
+ free(response);
return status;
}
@@ -623,7 +622,7 @@ static void receive_messages(private_kernel_interface_t *this)
else
{
/* add response to queue */
- listed_response = allocator_alloc(sizeof(response));
+ listed_response = malloc(sizeof(response));
memcpy(listed_response, &response, sizeof(response));
pthread_mutex_lock(&(this->mutex));
@@ -645,7 +644,7 @@ static void destroy(private_kernel_interface_t *this)
pthread_join(this->thread, NULL);
close(this->socket);
this->responses->destroy(this->responses);
- allocator_free(this);
+ free(this);
}
/*
@@ -653,7 +652,7 @@ static void destroy(private_kernel_interface_t *this)
*/
kernel_interface_t *kernel_interface_create()
{
- private_kernel_interface_t *this = allocator_alloc_thing(private_kernel_interface_t);
+ private_kernel_interface_t *this = malloc_thing(private_kernel_interface_t);
/* public functions */
this->public.get_spi = (status_t(*)(kernel_interface_t*,host_t*,host_t*,protocol_id_t,u_int32_t,u_int32_t*))get_spi;
@@ -675,17 +674,17 @@ kernel_interface_t *kernel_interface_create()
this->socket = socket(PF_NETLINK, SOCK_RAW, NETLINK_XFRM);
if (this->socket <= 0)
{
- allocator_free(this);
+ free(this);
charon->kill(charon, "Unable to create netlink socket");
}
if (pthread_create(&(this->thread), NULL, (void*(*)(void*))this->receive_messages, this) != 0)
{
close(this->socket);
- allocator_free(this);
+ free(this);
charon->kill(charon, "Unable to create netlink thread");
}
- charon->logger_manager->enable_log_level(charon->logger_manager, TESTER, FULL);
+ logger_manager->enable_log_level(logger_manager, TESTER, FULL);
return (&this->public);
}
diff --git a/Source/charon/threads/receiver.c b/Source/charon/threads/receiver.c
index 9058ecbc4..0cf8b7bde 100644
--- a/Source/charon/threads/receiver.c
+++ b/Source/charon/threads/receiver.c
@@ -31,7 +31,6 @@
#include <queues/job_queue.h>
#include <queues/jobs/job.h>
#include <queues/jobs/incoming_packet_job.h>
-#include <utils/allocator.h>
#include <utils/logger_manager.h>
@@ -103,7 +102,7 @@ static void destroy(private_receiver_t *this)
pthread_join(this->assigned_thread, NULL);
this->logger->log(this->logger, CONTROL | LEVEL1, "Receiver thread terminated");
- allocator_free(this);
+ free(this);
}
/*
@@ -111,17 +110,17 @@ static void destroy(private_receiver_t *this)
*/
receiver_t * receiver_create()
{
- private_receiver_t *this = allocator_alloc_thing(private_receiver_t);
+ private_receiver_t *this = malloc_thing(private_receiver_t);
this->public.destroy = (void(*)(receiver_t*)) destroy;
this->receive_packets = receive_packets;
- this->logger = charon->logger_manager->get_logger(charon->logger_manager, RECEIVER);
+ this->logger = logger_manager->get_logger(logger_manager, RECEIVER);
if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))this->receive_packets, this) != 0)
{
this->logger->log(this->logger, ERROR, "Receiver thread could not be started");
- allocator_free(this);
+ free(this);
charon->kill(charon, "Unable to create receiver thread");
}
diff --git a/Source/charon/threads/scheduler.c b/Source/charon/threads/scheduler.c
index 8750cdae9..47c5d6fb9 100644
--- a/Source/charon/threads/scheduler.c
+++ b/Source/charon/threads/scheduler.c
@@ -27,7 +27,6 @@
#include <daemon.h>
#include <definitions.h>
-#include <utils/allocator.h>
#include <utils/logger_manager.h>
#include <queues/job_queue.h>
@@ -98,7 +97,7 @@ static void destroy(private_scheduler_t *this)
pthread_join(this->assigned_thread, NULL);
this->logger->log(this->logger, CONTROL | LEVEL1, "Scheduler thread terminated");
- allocator_free(this);
+ free(this);
}
/*
@@ -106,18 +105,18 @@ static void destroy(private_scheduler_t *this)
*/
scheduler_t * scheduler_create()
{
- private_scheduler_t *this = allocator_alloc_thing(private_scheduler_t);
+ private_scheduler_t *this = malloc_thing(private_scheduler_t);
this->public.destroy = (void(*)(scheduler_t*)) destroy;
this->get_events = get_events;
- this->logger = charon->logger_manager->get_logger(charon->logger_manager, SCHEDULER);
+ this->logger = logger_manager->get_logger(logger_manager, SCHEDULER);
if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))this->get_events, this) != 0)
{
/* thread could not be created */
this->logger->log(this->logger, ERROR, "Scheduler thread could not be created!");
- allocator_free(this);
+ free(this);
charon->kill(charon, "Unable to create scheduler thread");
}
diff --git a/Source/charon/threads/sender.c b/Source/charon/threads/sender.c
index 90d9e409c..42d11beb9 100644
--- a/Source/charon/threads/sender.c
+++ b/Source/charon/threads/sender.c
@@ -29,7 +29,6 @@
#include <network/socket.h>
#include <network/packet.h>
#include <queues/send_queue.h>
-#include <utils/allocator.h>
#include <utils/logger_manager.h>
@@ -101,7 +100,7 @@ static void destroy(private_sender_t *this)
pthread_join(this->assigned_thread, NULL);
this->logger->log(this->logger, CONTROL | LEVEL1, "Sender thread terminated");
- allocator_free(this);
+ free(this);
}
/*
@@ -109,17 +108,17 @@ static void destroy(private_sender_t *this)
*/
sender_t * sender_create()
{
- private_sender_t *this = allocator_alloc_thing(private_sender_t);
+ private_sender_t *this = malloc_thing(private_sender_t);
this->send_packets = send_packets;
this->public.destroy = (void(*)(sender_t*)) destroy;
- this->logger = charon->logger_manager->get_logger(charon->logger_manager, SENDER);
+ this->logger = logger_manager->get_logger(logger_manager, SENDER);
if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))this->send_packets, this) != 0)
{
this->logger->log(this->logger, ERROR, "Sender thread could not be created");
- allocator_free(this);
+ free(this);
charon->kill(charon, "Unable to create sender thread");
}
diff --git a/Source/charon/threads/stroke_interface.c b/Source/charon/threads/stroke_interface.c
index 4468a37cf..b95884c03 100755
--- a/Source/charon/threads/stroke_interface.c
+++ b/Source/charon/threads/stroke_interface.c
@@ -37,7 +37,6 @@
#include <types.h>
#include <daemon.h>
#include <crypto/certificate.h>
-#include <utils/allocator.h>
#include <queues/jobs/initiate_ike_sa_job.h>
@@ -97,8 +96,8 @@ static void configuration_entry_destroy (configuration_entry_t *this)
{
this->public_key->destroy(this->public_key);
}
- allocator_free(this->name);
- allocator_free(this);
+ free(this->name);
+ free(this);
}
/**
@@ -107,7 +106,7 @@ static void configuration_entry_destroy (configuration_entry_t *this)
static configuration_entry_t * configuration_entry_create(char *name, connection_t* connection, policy_t *policy,
rsa_private_key_t *private_key, rsa_public_key_t *public_key)
{
- configuration_entry_t *entry = allocator_alloc_thing(configuration_entry_t);
+ configuration_entry_t *entry = malloc_thing(configuration_entry_t);
/* functions */
entry->destroy = configuration_entry_destroy;
@@ -117,7 +116,7 @@ static configuration_entry_t * configuration_entry_create(char *name, connection
entry->policy = policy;
entry->public_key = public_key;
entry->private_key = private_key;
- entry->name = allocator_alloc(strlen(name) + 1);
+ entry->name = malloc(strlen(name) + 1);
strcpy(entry->name, name);
return entry;
@@ -627,13 +626,11 @@ static void stroke_logtype(private_stroke_t *this, stroke_msg_t *msg)
if (msg->logtype.enable)
{
- charon->logger_manager->enable_log_level(charon->logger_manager,
- context, level);
+ logger_manager->enable_log_level(logger_manager, context, level);
}
else
{
- charon->logger_manager->disable_log_level(charon->logger_manager,
- context, level);
+ logger_manager->disable_log_level(logger_manager, context, level);
}
}
@@ -677,7 +674,7 @@ static void stroke_loglevel(private_stroke_t *this, stroke_msg_t *msg)
return;
}
- charon->logger_manager->enable_log_level(charon->logger_manager, context, level);
+ logger_manager->enable_log_level(logger_manager, context, level);
}
/**
@@ -692,11 +689,18 @@ static void stroke_receive(private_stroke_t *this)
ssize_t bytes_read;
int strokefd;
FILE *strokefile;
+ int oldstate;
+
+ /* disable cancellation by default */
+ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
while (1)
{
+ /* wait for connections, but allow thread to terminate */
+ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
strokefd = accept(this->socket, (struct sockaddr *)&strokeaddr, &strokeaddrlen);
-
+ pthread_setcancelstate(oldstate, NULL);
+
if (strokefd < 0)
{
this->logger->log(this->logger, ERROR, "accepting stroke connection failed: %s", strerror(errno));
@@ -713,7 +717,7 @@ static void stroke_receive(private_stroke_t *this)
}
/* read message */
- msg = allocator_alloc(msg_length);
+ msg = malloc(msg_length);
bytes_read = recv(strokefd, msg, msg_length, 0);
if (bytes_read != msg_length)
{
@@ -727,7 +731,7 @@ static void stroke_receive(private_stroke_t *this)
{
this->logger->log(this->logger, ERROR, "opening stroke output channel failed:", strerror(errno));
close(strokefd);
- allocator_free(msg);
+ free(msg);
continue;
}
@@ -773,7 +777,7 @@ static void stroke_receive(private_stroke_t *this)
this->stroke_logger->destroy(this->stroke_logger);
fclose(strokefile);
close(strokefd);
- allocator_free(msg);
+ free(msg);
}
}
@@ -972,7 +976,7 @@ static status_t get_shared_secret(credential_store_t *this, identification_t *id
preshared_secret->ptr = secret;
preshared_secret->len = strlen(secret) + 1;
- *preshared_secret = allocator_clone_chunk(*preshared_secret);
+ *preshared_secret = chunk_clone(*preshared_secret);
return SUCCESS;
}
@@ -1046,6 +1050,9 @@ static void destroy(private_stroke_t *this)
configuration_entry_t *entry;
rsa_private_key_t *priv_key;
+ pthread_cancel(this->assigned_thread);
+ pthread_join(this->assigned_thread, NULL);
+
while (this->configurations->remove_first(this->configurations, (void **)&entry) == SUCCESS)
{
entry->destroy(entry);
@@ -1060,7 +1067,7 @@ static void destroy(private_stroke_t *this)
close(this->socket);
unlink(socket_addr.sun_path);
- allocator_free(this);
+ free(this);
}
/**
@@ -1078,7 +1085,7 @@ void do_nothing(void *nothing)
*/
stroke_t *stroke_create()
{
- private_stroke_t *this = allocator_alloc_thing(private_stroke_t);
+ private_stroke_t *this = malloc_thing(private_stroke_t);
mode_t old;
/* public functions */
@@ -1097,14 +1104,14 @@ stroke_t *stroke_create()
this->stroke_receive = stroke_receive;
this->get_connection_by_name = get_connection_by_name;
- this->logger = charon->logger_manager->get_logger(charon->logger_manager, CONFIG);
+ this->logger = logger_manager->get_logger(logger_manager, CONFIG);
/* set up unix socket */
this->socket = socket(AF_UNIX, SOCK_STREAM, 0);
if (this->socket == -1)
{
this->logger->log(this->logger, ERROR, "could not create whack socket");
- allocator_free(this);
+ free(this);
return NULL;
}
@@ -1113,7 +1120,7 @@ stroke_t *stroke_create()
{
this->logger->log(this->logger, ERROR, "could not bind stroke socket: %s", strerror(errno));
close(this->socket);
- allocator_free(this);
+ free(this);
return NULL;
}
umask(old);
@@ -1123,7 +1130,7 @@ stroke_t *stroke_create()
this->logger->log(this->logger, ERROR, "could not listen on stroke socket: %s", strerror(errno));
close(this->socket);
unlink(socket_addr.sun_path);
- allocator_free(this);
+ free(this);
return NULL;
}
@@ -1133,7 +1140,7 @@ stroke_t *stroke_create()
this->logger->log(this->logger, ERROR, "Could not spawn stroke thread");
close(this->socket);
unlink(socket_addr.sun_path);
- allocator_free(this);
+ free(this);
return NULL;
}
diff --git a/Source/charon/threads/thread_pool.c b/Source/charon/threads/thread_pool.c
index 1f1584ec3..4482e795f 100644
--- a/Source/charon/threads/thread_pool.c
+++ b/Source/charon/threads/thread_pool.c
@@ -35,7 +35,6 @@
#include <queues/jobs/initiate_ike_sa_job.h>
#include <queues/jobs/retransmit_request_job.h>
#include <encoding/payloads/notify_payload.h>
-#include <utils/allocator.h>
#include <utils/logger.h>
@@ -292,8 +291,10 @@ static void process_incoming_packet_job(private_thread_pool_t *this, incoming_pa
if (status == CREATED)
{
- this->worker_logger->log(this->worker_logger, CONTROL|LEVEL3, "Create Job to delete half open IKE_SA.");
- this->create_delete_half_open_ike_sa_job(this,ike_sa_id,charon->configuration->get_half_open_ike_sa_timeout(charon->configuration));
+ this->worker_logger->log(this->worker_logger, CONTROL|LEVEL3,
+ "Create Job to delete half open IKE_SA.");
+ this->create_delete_half_open_ike_sa_job(this,ike_sa_id,
+ charon->configuration->get_half_open_ike_sa_timeout(charon->configuration));
}
status = ike_sa->process_message(ike_sa, message);
@@ -349,7 +350,8 @@ static void process_initiate_ike_sa_job(private_thread_pool_t *this, initiate_ik
}
this->worker_logger->log(this->worker_logger, CONTROL|LEVEL3, "Create Job to delete half open IKE_SA.");
- this->create_delete_half_open_ike_sa_job(this,ike_sa->get_id(ike_sa),charon->configuration->get_half_open_ike_sa_timeout(charon->configuration));
+ this->create_delete_half_open_ike_sa_job(this,ike_sa->get_id(ike_sa),
+ charon->configuration->get_half_open_ike_sa_timeout(charon->configuration));
this->worker_logger->log(this->worker_logger, CONTROL|LEVEL2, "Checking in IKE SA");
status = charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
@@ -543,19 +545,25 @@ static void destroy(private_thread_pool_t *this)
int current;
/* flag thread for termination */
for (current = 0; current < this->pool_size; current++) {
- this->pool_logger->log(this->pool_logger, CONTROL, "cancelling worker a thread #%d", current+1);
+ this->pool_logger->log(this->pool_logger, CONTROL, "cancelling worker thread #%d", current+1);
pthread_cancel(this->threads[current]);
}
/* wait for all threads */
for (current = 0; current < this->pool_size; current++) {
- pthread_join(this->threads[current], NULL);
- this->pool_logger->log(this->pool_logger, CONTROL, "worker thread #%d terminated", current+1);
- }
+ if (pthread_join(this->threads[current], NULL) == 0)
+ {
+ this->pool_logger->log(this->pool_logger, CONTROL, "worker thread #%d terminated", current+1);
+ }
+ else
+ {
+ this->pool_logger->log(this->pool_logger, ERROR, "could not terminate worker thread #%d", current+1);
+ }
+ }
/* free mem */
- allocator_free(this->threads);
- allocator_free(this);
+ free(this->threads);
+ free(this);
}
/*
@@ -565,7 +573,7 @@ thread_pool_t *thread_pool_create(size_t pool_size)
{
int current;
- private_thread_pool_t *this = allocator_alloc_thing(private_thread_pool_t);
+ private_thread_pool_t *this = malloc_thing(private_thread_pool_t);
/* fill in public fields */
this->public.destroy = (void(*)(thread_pool_t*))destroy;
@@ -581,11 +589,11 @@ thread_pool_t *thread_pool_create(size_t pool_size)
this->pool_size = pool_size;
- this->threads = allocator_alloc(sizeof(pthread_t) * pool_size);
+ this->threads = malloc(sizeof(pthread_t) * pool_size);
- this->pool_logger = charon->logger_manager->get_logger(charon->logger_manager, THREAD_POOL);
+ this->pool_logger = logger_manager->get_logger(logger_manager, THREAD_POOL);
- this->worker_logger = charon->logger_manager->get_logger(charon->logger_manager, WORKER);
+ this->worker_logger = logger_manager->get_logger(logger_manager, WORKER);
/* try to create as many threads as possible, up tu pool_size */
for (current = 0; current < pool_size; current++)
@@ -600,8 +608,8 @@ thread_pool_t *thread_pool_create(size_t pool_size)
if (current == 0)
{
this->pool_logger->log(this->pool_logger, ERROR, "Could not create any thread");
- allocator_free(this->threads);
- allocator_free(this);
+ free(this->threads);
+ free(this);
return NULL;
}
/* not all threads could be created, but at least one :-/ */