summaryrefslogtreecommitdiff
path: root/src/charon/credentials
diff options
context:
space:
mode:
authorRene Mayrhofer <rene@mayrhofer.eu.org>2008-12-05 16:15:54 +0000
committerRene Mayrhofer <rene@mayrhofer.eu.org>2008-12-05 16:15:54 +0000
commitc7f1b0530b85bc7654e68992f25ed8ced5d0a80d (patch)
tree861798cd7da646014ed6919766b053099646710d /src/charon/credentials
parent8b80ab5a6950ce6515f477624794defd7531642a (diff)
downloadvyos-strongswan-c7f1b0530b85bc7654e68992f25ed8ced5d0a80d.tar.gz
vyos-strongswan-c7f1b0530b85bc7654e68992f25ed8ced5d0a80d.zip
[svn-upgrade] Integrating new upstream version, strongswan (4.2.9)
Diffstat (limited to 'src/charon/credentials')
-rw-r--r--src/charon/credentials/credential_manager.c49
-rw-r--r--src/charon/credentials/sets/cert_cache.c28
2 files changed, 38 insertions, 39 deletions
diff --git a/src/charon/credentials/credential_manager.c b/src/charon/credentials/credential_manager.c
index b11cdc0df..309115280 100644
--- a/src/charon/credentials/credential_manager.c
+++ b/src/charon/credentials/credential_manager.c
@@ -12,16 +12,15 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: credential_manager.c 4317 2008-09-02 11:00:13Z martin $
+ * $Id: credential_manager.c 4591 2008-11-05 16:12:54Z martin $
*/
-/* some clibs need it for rwlocks */
-#define _GNU_SOURCE
#include <pthread.h>
#include "credential_manager.h"
#include <daemon.h>
+#include <utils/mutex.h>
#include <utils/linked_list.h>
#include <credentials/sets/cert_cache.h>
#include <credentials/sets/auth_info_wrapper.h>
@@ -68,7 +67,7 @@ struct private_credential_manager_t {
/**
* read-write lock to sets list
*/
- pthread_rwlock_t lock;
+ rwlock_t *lock;
};
/** data to pass to create_private_enumerator */
@@ -170,7 +169,7 @@ static enumerator_t *create_sets_enumerator(private_credential_manager_t *this)
*/
static void destroy_cert_data(cert_data_t *data)
{
- pthread_rwlock_unlock(&data->this->lock);
+ data->this->lock->unlock(data->this->lock);
free(data);
}
@@ -197,7 +196,7 @@ static enumerator_t *create_cert_enumerator(private_credential_manager_t *this,
data->id = id;
data->trusted = trusted;
- pthread_rwlock_rdlock(&this->lock);
+ this->lock->read_lock(this->lock);
return enumerator_create_nested(create_sets_enumerator(this),
(void*)create_cert, data,
(void*)destroy_cert_data);
@@ -229,7 +228,7 @@ static certificate_t *get_cert(private_credential_manager_t *this,
*/
static void destroy_cdp_data(cdp_data_t *data)
{
- pthread_rwlock_unlock(&data->this->lock);
+ data->this->lock->unlock(data->this->lock);
free(data);
}
@@ -251,7 +250,7 @@ static enumerator_t * create_cdp_enumerator(private_credential_manager_t *this,
data->type = type;
data->id = id;
- pthread_rwlock_rdlock(&this->lock);
+ this->lock->read_lock(this->lock);
return enumerator_create_nested(create_sets_enumerator(this),
(void*)create_cdp, data,
(void*)destroy_cdp_data);
@@ -262,7 +261,7 @@ static enumerator_t * create_cdp_enumerator(private_credential_manager_t *this,
*/
static void destroy_private_data(private_data_t *data)
{
- pthread_rwlock_unlock(&data->this->lock);
+ data->this->lock->unlock(data->this->lock);
free(data);
}
@@ -287,7 +286,7 @@ static enumerator_t* create_private_enumerator(
data->this = this;
data->type = key;
data->keyid = keyid;
- pthread_rwlock_rdlock(&this->lock);
+ this->lock->read_lock(this->lock);
return enumerator_create_nested(create_sets_enumerator(this),
(void*)create_private, data,
(void*)destroy_private_data);
@@ -316,7 +315,7 @@ static private_key_t *get_private_by_keyid(private_credential_manager_t *this,
*/
static void destroy_shared_data(shared_data_t *data)
{
- pthread_rwlock_unlock(&data->this->lock);
+ data->this->lock->unlock(data->this->lock);
free(data);
}
@@ -341,7 +340,7 @@ static enumerator_t *create_shared_enumerator(private_credential_manager_t *this
data->me = me;
data->other = other;
- pthread_rwlock_rdlock(&this->lock);
+ this->lock->read_lock(this->lock);
return enumerator_create_nested(create_sets_enumerator(this),
(void*)create_shared, data,
(void*)destroy_shared_data);
@@ -412,7 +411,7 @@ static void cache_cert(private_credential_manager_t *this, certificate_t *cert)
credential_set_t *set;
enumerator_t *enumerator;
- if (pthread_rwlock_trywrlock(&this->lock) == 0)
+ if (this->lock->try_write_lock(this->lock))
{
enumerator = this->sets->create_enumerator(this->sets);
while (enumerator->enumerate(enumerator, &set))
@@ -423,10 +422,10 @@ static void cache_cert(private_credential_manager_t *this, certificate_t *cert)
}
else
{ /* we can't cache now as other threads are active, queue for later */
- pthread_rwlock_rdlock(&this->lock);
+ this->lock->read_lock(this->lock);
this->cache_queue->insert_last(this->cache_queue, cert->get_ref(cert));
}
- pthread_rwlock_unlock(&this->lock);
+ this->lock->unlock(this->lock);
}
/**
@@ -439,7 +438,7 @@ static void cache_queue(private_credential_manager_t *this)
enumerator_t *enumerator;
if (this->cache_queue->get_count(this->cache_queue) > 0 &&
- pthread_rwlock_trywrlock(&this->lock) == 0)
+ this->lock->try_write_lock(this->lock))
{
while (this->cache_queue->remove_last(this->cache_queue,
(void**)&cert) == SUCCESS)
@@ -452,7 +451,7 @@ static void cache_queue(private_credential_manager_t *this)
enumerator->destroy(enumerator);
cert->destroy(cert);
}
- pthread_rwlock_unlock(&this->lock);
+ this->lock->unlock(this->lock);
}
}
@@ -1302,7 +1301,7 @@ static void public_destroy(public_enumerator_t *this)
remove_local_set(this->this, &this->wrapper->set);
this->wrapper->destroy(this->wrapper);
}
- pthread_rwlock_unlock(&this->this->lock);
+ this->this->lock->unlock(this->this->lock);
/* check for delayed certificate cache queue */
cache_queue(this->this);
@@ -1328,7 +1327,7 @@ static enumerator_t* create_public_enumerator(private_credential_manager_t *this
enumerator->wrapper = auth_info_wrapper_create(auth);
add_local_set(this, &enumerator->wrapper->set);
}
- pthread_rwlock_rdlock(&this->lock);
+ this->lock->read_lock(this->lock);
return &enumerator->public;
}
@@ -1525,9 +1524,9 @@ static void flush_cache(private_credential_manager_t *this,
static void add_set(private_credential_manager_t *this,
credential_set_t *set)
{
- pthread_rwlock_wrlock(&this->lock);
+ this->lock->write_lock(this->lock);
this->sets->insert_last(this->sets, set);
- pthread_rwlock_unlock(&this->lock);
+ this->lock->unlock(this->lock);
}
/**
@@ -1535,9 +1534,9 @@ static void add_set(private_credential_manager_t *this,
*/
static void remove_set(private_credential_manager_t *this, credential_set_t *set)
{
- pthread_rwlock_wrlock(&this->lock);
+ this->lock->write_lock(this->lock);
this->sets->remove(this->sets, set, NULL);
- pthread_rwlock_unlock(&this->lock);
+ this->lock->unlock(this->lock);
}
/**
@@ -1551,7 +1550,7 @@ static void destroy(private_credential_manager_t *this)
this->sets->destroy(this->sets);
pthread_key_delete(this->local_sets);
this->cache->destroy(this->cache);
- pthread_rwlock_destroy(&this->lock);
+ this->lock->destroy(this->lock);
free(this);
}
@@ -1580,7 +1579,7 @@ credential_manager_t *credential_manager_create()
this->cache = cert_cache_create();
this->cache_queue = linked_list_create();
this->sets->insert_first(this->sets, this->cache);
- pthread_rwlock_init(&this->lock, NULL);
+ this->lock = rwlock_create(RWLOCK_DEFAULT);
return &this->public;
}
diff --git a/src/charon/credentials/sets/cert_cache.c b/src/charon/credentials/sets/cert_cache.c
index 4a9a97149..79b5f0203 100644
--- a/src/charon/credentials/sets/cert_cache.c
+++ b/src/charon/credentials/sets/cert_cache.c
@@ -15,12 +15,12 @@
* $Id$
*/
-#define _GNU_SOURCE
-#include <pthread.h>
-
#include "cert_cache.h"
+#include <time.h>
+
#include <daemon.h>
+#include <utils/mutex.h>
#include <utils/linked_list.h>
#define CACHE_SIZE 30
@@ -56,7 +56,7 @@ struct private_cert_cache_t {
/**
* read-write lock to sets list
*/
- pthread_rwlock_t lock;
+ rwlock_t *lock;
};
/**
@@ -90,7 +90,7 @@ static void check_cache(private_cert_cache_t *this)
{
this->check_required = TRUE;
}
- else if (pthread_rwlock_trywrlock(&this->lock) == 0)
+ else if (this->lock->try_write_lock(this->lock))
{ /* never blocks, only done if lock is available */
while (this->relations->get_count(this->relations) > CACHE_SIZE)
{
@@ -110,7 +110,7 @@ static void check_cache(private_cert_cache_t *this)
relation_destroy(oldest);
}
this->check_required = FALSE;
- pthread_rwlock_unlock(&this->lock);
+ this->lock->unlock(this->lock);
}
}
@@ -124,7 +124,7 @@ static bool issued_by(private_cert_cache_t *this,
enumerator_t *enumerator;
/* lookup cache */
- pthread_rwlock_rdlock(&this->lock);
+ this->lock->read_lock(this->lock);
enumerator = this->relations->create_enumerator(this->relations);
while (enumerator->enumerate(enumerator, &current))
{
@@ -149,7 +149,7 @@ static bool issued_by(private_cert_cache_t *this,
}
}
enumerator->destroy(enumerator);
- pthread_rwlock_unlock(&this->lock);
+ this->lock->unlock(this->lock);
if (found)
{
return TRUE;
@@ -233,7 +233,7 @@ static bool certs_filter(cert_data_t *data, relation_t **in, certificate_t **out
static void certs_destroy(cert_data_t *data)
{
ref_put(&data->this->enumerating);
- pthread_rwlock_unlock(&data->this->lock);
+ data->this->lock->unlock(data->this->lock);
if (data->this->check_required)
{
check_cache(data->this);
@@ -260,7 +260,7 @@ static enumerator_t *create_enumerator(private_cert_cache_t *this,
data->id = id;
data->this = this;
- pthread_rwlock_rdlock(&this->lock);
+ this->lock->read_lock(this->lock);
ref_get(&this->enumerating);
return enumerator_create_filter(
this->relations->create_enumerator(this->relations),
@@ -275,7 +275,7 @@ static void flush(private_cert_cache_t *this, certificate_type_t type)
enumerator_t *enumerator;
relation_t *relation;
- pthread_rwlock_wrlock(&this->lock);
+ this->lock->write_lock(this->lock);
enumerator = this->relations->create_enumerator(this->relations);
while (enumerator->enumerate(enumerator, &relation))
{
@@ -287,7 +287,7 @@ static void flush(private_cert_cache_t *this, certificate_type_t type)
}
}
enumerator->destroy(enumerator);
- pthread_rwlock_unlock(&this->lock);
+ this->lock->unlock(this->lock);
}
/**
@@ -296,7 +296,7 @@ static void flush(private_cert_cache_t *this, certificate_type_t type)
static void destroy(private_cert_cache_t *this)
{
this->relations->destroy_function(this->relations, (void*)relation_destroy);
- pthread_rwlock_destroy(&this->lock);
+ this->lock->destroy(this->lock);
free(this);
}
@@ -319,7 +319,7 @@ cert_cache_t *cert_cache_create()
this->relations = linked_list_create();
this->enumerating = 0;
this->check_required = FALSE;
- pthread_rwlock_init(&this->lock, NULL);
+ this->lock = rwlock_create(RWLOCK_DEFAULT);
return &this->public;
}