diff options
Diffstat (limited to 'src/charon/plugins')
4 files changed, 85 insertions, 76 deletions
diff --git a/src/charon/plugins/kernel_netlink/kernel_netlink_ipsec.c b/src/charon/plugins/kernel_netlink/kernel_netlink_ipsec.c index c53ce3c75..4d0e67b54 100644 --- a/src/charon/plugins/kernel_netlink/kernel_netlink_ipsec.c +++ b/src/charon/plugins/kernel_netlink/kernel_netlink_ipsec.c @@ -37,6 +37,7 @@ #include "kernel_netlink_shared.h" #include <daemon.h> +#include <utils/mutex.h> #include <utils/linked_list.h> #include <processing/jobs/callback_job.h> #include <processing/jobs/acquire_job.h> @@ -252,7 +253,7 @@ struct private_kernel_netlink_ipsec_t { /** * mutex to lock access to various lists */ - pthread_mutex_t mutex; + mutex_t *mutex; /** * List of installed policies (policy_entry_t) @@ -1374,7 +1375,7 @@ static status_t add_policy(private_kernel_netlink_ipsec_t *this, policy->direction = direction; /* find the policy, which matches EXACTLY */ - pthread_mutex_lock(&this->mutex); + this->mutex->lock(this->mutex); iterator = this->policies->create_iterator(this->policies, TRUE); while (iterator->iterate(iterator, (void**)¤t)) { @@ -1418,7 +1419,7 @@ static status_t add_policy(private_kernel_netlink_ipsec_t *this, policy_info->priority -= policy->sel.sport_mask ? 1 : 0; policy_info->action = XFRM_POLICY_ALLOW; policy_info->share = XFRM_SHARE_ANY; - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); /* policies don't expire */ policy_info->lft.soft_byte_limit = XFRM_INF; @@ -1634,7 +1635,7 @@ static status_t del_policy(private_kernel_netlink_ipsec_t *this, policy.direction = direction; /* find the policy */ - pthread_mutex_lock(&this->mutex); + this->mutex->lock(this->mutex); enumerator = this->policies->create_enumerator(this->policies); while (enumerator->enumerate(enumerator, ¤t)) { @@ -1646,7 +1647,7 @@ static status_t del_policy(private_kernel_netlink_ipsec_t *this, { /* is used by more SAs, keep in kernel */ DBG2(DBG_KNL, "policy still used by another CHILD_SA, not removed"); - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); enumerator->destroy(enumerator); return SUCCESS; } @@ -1655,7 +1656,7 @@ static status_t del_policy(private_kernel_netlink_ipsec_t *this, break; } } - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); enumerator->destroy(enumerator); if (!to_delete) { @@ -1709,6 +1710,7 @@ static void destroy(private_kernel_netlink_ipsec_t *this) close(this->socket_xfrm_events); this->socket_xfrm->destroy(this->socket_xfrm); this->policies->destroy(this->policies); + this->mutex->destroy(this->mutex); free(this); } @@ -1733,7 +1735,7 @@ kernel_netlink_ipsec_t *kernel_netlink_ipsec_create() /* private members */ this->policies = linked_list_create(); - pthread_mutex_init(&this->mutex, NULL); + this->mutex = mutex_create(MUTEX_DEFAULT); this->install_routes = lib->settings->get_bool(lib->settings, "charon.install_routes", TRUE); diff --git a/src/charon/plugins/kernel_netlink/kernel_netlink_net.c b/src/charon/plugins/kernel_netlink/kernel_netlink_net.c index af26038b7..6efba857c 100644 --- a/src/charon/plugins/kernel_netlink/kernel_netlink_net.c +++ b/src/charon/plugins/kernel_netlink/kernel_netlink_net.c @@ -29,6 +29,7 @@ #include "kernel_netlink_shared.h" #include <daemon.h> +#include <utils/mutex.h> #include <utils/linked_list.h> #include <processing/jobs/callback_job.h> #include <processing/jobs/roam_job.h> @@ -116,12 +117,12 @@ struct private_kernel_netlink_net_t { /** * mutex to lock access to various lists */ - pthread_mutex_t mutex; + mutex_t *mutex; /** * condition variable to signal virtual IP add/removal */ - pthread_cond_t cond; + condvar_t *condvar; /** * Cached list of interfaces and its addresses (iface_entry_t) @@ -253,7 +254,7 @@ static void process_link(private_kernel_netlink_net_t *this, name = "(unknown)"; } - pthread_mutex_lock(&this->mutex); + this->mutex->lock(this->mutex); switch (hdr->nlmsg_type) { case RTM_NEWLINK: @@ -315,7 +316,7 @@ static void process_link(private_kernel_netlink_net_t *this, break; } } - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); /* send an update to all IKE_SAs */ if (update && event) @@ -373,7 +374,7 @@ static void process_addr(private_kernel_netlink_net_t *this, return; } - pthread_mutex_lock(&this->mutex); + this->mutex->lock(this->mutex); ifaces = this->ifaces->create_enumerator(this->ifaces); while (ifaces->enumerate(ifaces, &iface)) { @@ -431,7 +432,7 @@ static void process_addr(private_kernel_netlink_net_t *this, } } ifaces->destroy(ifaces); - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); host->destroy(host); /* send an update to all IKE_SAs */ @@ -470,10 +471,12 @@ static void process_route(private_kernel_netlink_net_t *this, struct nlmsghdr *h } if (host) { + this->mutex->lock(this->mutex); if (!get_vip_refcount(this, host)) { /* ignore routes added for virtual IPs */ fire_roam_job(this, FALSE); } + this->mutex->unlock(this->mutex); host->destroy(host); } } @@ -524,12 +527,12 @@ static job_requeue_t receive_events(private_kernel_netlink_net_t *this) case RTM_NEWADDR: case RTM_DELADDR: process_addr(this, hdr, TRUE); - pthread_cond_broadcast(&this->cond); + this->condvar->broadcast(this->condvar); break; case RTM_NEWLINK: case RTM_DELLINK: process_link(this, hdr, TRUE); - pthread_cond_broadcast(&this->cond); + this->condvar->broadcast(this->condvar); break; case RTM_NEWROUTE: case RTM_DELROUTE: @@ -560,7 +563,7 @@ typedef struct { */ static void address_enumerator_destroy(address_enumerator_t *data) { - pthread_mutex_unlock(&data->this->mutex); + data->this->mutex->unlock(data->this->mutex); free(data); } @@ -614,7 +617,7 @@ static enumerator_t *create_address_enumerator(private_kernel_netlink_net_t *thi data->include_down_ifaces = include_down_ifaces; data->include_virtual_ips = include_virtual_ips; - pthread_mutex_lock(&this->mutex); + this->mutex->lock(this->mutex); return enumerator_create_nested( enumerator_create_filter(this->ifaces->create_enumerator(this->ifaces), (void*)filter_interfaces, data, NULL), @@ -633,7 +636,7 @@ static char *get_interface_name(private_kernel_netlink_net_t *this, host_t* ip) DBG2(DBG_KNL, "getting interface name for %H", ip); - pthread_mutex_lock(&this->mutex); + this->mutex->lock(this->mutex); ifaces = this->ifaces->create_enumerator(this->ifaces); while (ifaces->enumerate(ifaces, &iface)) { @@ -653,7 +656,7 @@ static char *get_interface_name(private_kernel_netlink_net_t *this, host_t* ip) } } ifaces->destroy(ifaces); - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); if (name) { @@ -677,7 +680,7 @@ static int get_interface_index(private_kernel_netlink_net_t *this, char* name) DBG2(DBG_KNL, "getting iface index for %s", name); - pthread_mutex_lock(&this->mutex); + this->mutex->lock(this->mutex); ifaces = this->ifaces->create_enumerator(this->ifaces); while (ifaces->enumerate(ifaces, &iface)) { @@ -688,7 +691,7 @@ static int get_interface_index(private_kernel_netlink_net_t *this, char* name) } } ifaces->destroy(ifaces); - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); if (ifindex == 0) { @@ -769,6 +772,7 @@ static host_t *get_route(private_kernel_netlink_net_t *this, host_t *dest, DBG1(DBG_KNL, "getting address to %H failed", dest); return NULL; } + this->mutex->lock(this->mutex); current = out; while (NLMSG_OK(current, len)) { @@ -846,7 +850,6 @@ static host_t *get_route(private_kernel_netlink_net_t *this, host_t *dest, else { /* no source addr, get one from the interfaces */ - pthread_mutex_lock(&this->mutex); ifaces = this->ifaces->create_enumerator(this->ifaces); while (ifaces->enumerate(ifaces, &iface)) { @@ -870,7 +873,6 @@ static host_t *get_route(private_kernel_netlink_net_t *this, host_t *dest, } } ifaces->destroy(ifaces); - pthread_mutex_unlock(&this->mutex); } } /* FALL through */ @@ -882,6 +884,7 @@ static host_t *get_route(private_kernel_netlink_net_t *this, host_t *dest, break; } free(out); + this->mutex->unlock(this->mutex); if (nexthop) { @@ -957,7 +960,7 @@ static status_t add_ip(private_kernel_netlink_net_t *this, DBG2(DBG_KNL, "adding virtual IP %H", virtual_ip); - pthread_mutex_lock(&this->mutex); + this->mutex->lock(this->mutex); ifaces = this->ifaces->create_enumerator(this->ifaces); while (ifaces->enumerate(ifaces, &iface)) { @@ -977,7 +980,7 @@ static status_t add_ip(private_kernel_netlink_net_t *this, virtual_ip, iface->ifname); addrs->destroy(addrs); ifaces->destroy(ifaces); - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); return SUCCESS; } } @@ -998,20 +1001,20 @@ static status_t add_ip(private_kernel_netlink_net_t *this, { while (get_vip_refcount(this, virtual_ip) == 0) { /* wait until address appears */ - pthread_cond_wait(&this->cond, &this->mutex); + this->condvar->wait(this->condvar, this->mutex); } ifaces->destroy(ifaces); - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); return SUCCESS; } ifaces->destroy(ifaces); - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); DBG1(DBG_KNL, "adding virtual IP %H failed", virtual_ip); return FAILED; } } ifaces->destroy(ifaces); - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); DBG1(DBG_KNL, "interface address %H not found, unable to install" "virtual IP %H", iface_ip, virtual_ip); @@ -1031,7 +1034,7 @@ static status_t del_ip(private_kernel_netlink_net_t *this, host_t *virtual_ip) DBG2(DBG_KNL, "deleting virtual IP %H", virtual_ip); - pthread_mutex_lock(&this->mutex); + this->mutex->lock(this->mutex); ifaces = this->ifaces->create_enumerator(this->ifaces); while (ifaces->enumerate(ifaces, &iface)) { @@ -1049,12 +1052,12 @@ static status_t del_ip(private_kernel_netlink_net_t *this, host_t *virtual_ip) { /* wait until the address is really gone */ while (get_vip_refcount(this, virtual_ip) > 0) { - pthread_cond_wait(&this->cond, &this->mutex); + this->condvar->wait(this->condvar, this->mutex); } } addrs->destroy(addrs); ifaces->destroy(ifaces); - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); return status; } else @@ -1065,14 +1068,14 @@ static status_t del_ip(private_kernel_netlink_net_t *this, host_t *virtual_ip) virtual_ip); addrs->destroy(addrs); ifaces->destroy(ifaces); - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); return SUCCESS; } } addrs->destroy(addrs); } ifaces->destroy(ifaces); - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); DBG2(DBG_KNL, "virtual IP %H not cached, unable to delete", virtual_ip); return FAILED; @@ -1232,7 +1235,7 @@ static status_t init_address_list(private_kernel_netlink_net_t *this) } free(out); - pthread_mutex_lock(&this->mutex); + this->mutex->lock(this->mutex); ifaces = this->ifaces->create_enumerator(this->ifaces); while (ifaces->enumerate(ifaces, &iface)) { @@ -1248,7 +1251,7 @@ static status_t init_address_list(private_kernel_netlink_net_t *this) } } ifaces->destroy(ifaces); - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); return SUCCESS; } @@ -1301,6 +1304,8 @@ static void destroy(private_kernel_netlink_net_t *this) close(this->socket_events); this->socket->destroy(this->socket); this->ifaces->destroy_function(this->ifaces, (void*)iface_entry_destroy); + this->condvar->destroy(this->condvar); + this->mutex->destroy(this->mutex); free(this); } @@ -1325,8 +1330,8 @@ kernel_netlink_net_t *kernel_netlink_net_create() /* private members */ this->ifaces = linked_list_create(); - pthread_mutex_init(&this->mutex, NULL); - pthread_cond_init(&this->cond, NULL); + this->mutex = mutex_create(MUTEX_DEFAULT); + this->condvar = condvar_create(CONDVAR_DEFAULT); timerclear(&this->last_roam); this->routing_table = lib->settings->get_int(lib->settings, "charon.routing_table", IPSEC_ROUTING_TABLE); diff --git a/src/charon/plugins/kernel_netlink/kernel_netlink_shared.c b/src/charon/plugins/kernel_netlink/kernel_netlink_shared.c index f4af94150..c3715967b 100644 --- a/src/charon/plugins/kernel_netlink/kernel_netlink_shared.c +++ b/src/charon/plugins/kernel_netlink/kernel_netlink_shared.c @@ -20,11 +20,11 @@ #include <linux/rtnetlink.h> #include <errno.h> #include <unistd.h> -#include <pthread.h> #include "kernel_netlink_shared.h" #include <daemon.h> +#include <utils/mutex.h> typedef struct private_netlink_socket_t private_netlink_socket_t; @@ -40,7 +40,7 @@ struct private_netlink_socket_t { /** * mutex to lock access to netlink socket */ - pthread_mutex_t mutex; + mutex_t *mutex; /** * current sequence number for netlink request @@ -64,7 +64,7 @@ static status_t netlink_send(private_netlink_socket_t *this, struct nlmsghdr *in chunk_t result = chunk_empty, tmp; struct nlmsghdr *msg, peek; - pthread_mutex_lock(&this->mutex); + this->mutex->lock(this->mutex); in->nlmsg_seq = ++this->seq; in->nlmsg_pid = getpid(); @@ -86,7 +86,7 @@ static status_t netlink_send(private_netlink_socket_t *this, struct nlmsghdr *in /* interrupted, try again */ continue; } - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); DBG1(DBG_KNL, "error sending to netlink socket: %s", strerror(errno)); return FAILED; } @@ -118,14 +118,14 @@ static status_t netlink_send(private_netlink_socket_t *this, struct nlmsghdr *in continue; } DBG1(DBG_KNL, "error reading from netlink socket: %s", strerror(errno)); - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); free(result.ptr); return FAILED; } if (!NLMSG_OK(msg, len)) { DBG1(DBG_KNL, "received corrupted netlink message"); - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); free(result.ptr); return FAILED; } @@ -136,7 +136,7 @@ static status_t netlink_send(private_netlink_socket_t *this, struct nlmsghdr *in { continue; } - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); free(result.ptr); return FAILED; } @@ -162,7 +162,7 @@ static status_t netlink_send(private_netlink_socket_t *this, struct nlmsghdr *in *out_len = result.len; *out = (struct nlmsghdr*)result.ptr; - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); return SUCCESS; } @@ -222,6 +222,7 @@ static status_t netlink_send_ack(private_netlink_socket_t *this, struct nlmsghdr static void destroy(private_netlink_socket_t *this) { close(this->socket); + this->mutex->destroy(this->mutex); free(this); } @@ -239,7 +240,7 @@ netlink_socket_t *netlink_socket_create(int protocol) { /* private members */ this->seq = 200; - pthread_mutex_init(&this->mutex, NULL); + this->mutex = mutex_create(MUTEX_DEFAULT); memset(&addr, 0, sizeof(addr)); addr.nl_family = AF_NETLINK; diff --git a/src/charon/plugins/kernel_pfkey/kernel_pfkey_ipsec.c b/src/charon/plugins/kernel_pfkey/kernel_pfkey_ipsec.c index de6927b11..560654e14 100644 --- a/src/charon/plugins/kernel_pfkey/kernel_pfkey_ipsec.c +++ b/src/charon/plugins/kernel_pfkey/kernel_pfkey_ipsec.c @@ -30,6 +30,7 @@ #include <daemon.h> #include <utils/host.h> +#include <utils/mutex.h> #include <processing/jobs/callback_job.h> #include <processing/jobs/acquire_job.h> #include <processing/jobs/migrate_job.h> @@ -83,7 +84,7 @@ struct private_kernel_pfkey_ipsec_t /** * mutex to lock access to various lists */ - pthread_mutex_t mutex; + mutex_t *mutex; /** * List of installed policies (policy_entry_t) @@ -103,21 +104,18 @@ struct private_kernel_pfkey_ipsec_t /** * mutex to lock access to the PF_KEY socket */ - pthread_mutex_t mutex_pfkey; - + mutex_t *mutex_pfkey; /** * PF_KEY socket to communicate with the kernel */ int socket; - /** * PF_KEY socket to receive acquire and expire events */ int socket_events; - /** * sequence number for messages sent to the kernel */ @@ -635,7 +633,7 @@ static status_t pfkey_send_socket(private_kernel_pfkey_ipsec_t *this, int socket struct sadb_msg *msg; int in_len, len; - pthread_mutex_lock(&this->mutex_pfkey); + this->mutex_pfkey->lock(this->mutex_pfkey); in->sadb_msg_seq = ++this->seq; in->sadb_msg_pid = getpid(); @@ -653,7 +651,7 @@ static status_t pfkey_send_socket(private_kernel_pfkey_ipsec_t *this, int socket /* interrupted, try again */ continue; } - pthread_mutex_unlock(&this->mutex_pfkey); + this->mutex_pfkey->unlock(this->mutex_pfkey); DBG1(DBG_KNL, "error sending to PF_KEY socket: %s", strerror(errno)); return FAILED; } @@ -675,20 +673,20 @@ static status_t pfkey_send_socket(private_kernel_pfkey_ipsec_t *this, int socket continue; } DBG1(DBG_KNL, "error reading from PF_KEY socket: %s", strerror(errno)); - pthread_mutex_unlock(&this->mutex_pfkey); + this->mutex_pfkey->unlock(this->mutex_pfkey); return FAILED; } if (len < sizeof(struct sadb_msg) || msg->sadb_msg_len < PFKEY_LEN(sizeof(struct sadb_msg))) { DBG1(DBG_KNL, "received corrupted PF_KEY message"); - pthread_mutex_unlock(&this->mutex_pfkey); + this->mutex_pfkey->unlock(this->mutex_pfkey); return FAILED; } if (msg->sadb_msg_len > len / PFKEY_ALIGNMENT) { DBG1(DBG_KNL, "buffer was too small to receive the complete PF_KEY message"); - pthread_mutex_unlock(&this->mutex_pfkey); + this->mutex_pfkey->unlock(this->mutex_pfkey); return FAILED; } if (msg->sadb_msg_pid != in->sadb_msg_pid) @@ -704,7 +702,7 @@ static status_t pfkey_send_socket(private_kernel_pfkey_ipsec_t *this, int socket { continue; } - pthread_mutex_unlock(&this->mutex_pfkey); + this->mutex_pfkey->unlock(this->mutex_pfkey); return FAILED; } if (msg->sadb_msg_type != in->sadb_msg_type) @@ -720,7 +718,7 @@ static status_t pfkey_send_socket(private_kernel_pfkey_ipsec_t *this, int socket *out = (struct sadb_msg*)malloc(len); memcpy(*out, buf, len); - pthread_mutex_unlock(&this->mutex_pfkey); + this->mutex_pfkey->unlock(this->mutex_pfkey); return SUCCESS; } @@ -764,7 +762,7 @@ static void process_acquire(private_kernel_pfkey_ipsec_t *this, struct sadb_msg* } index = response.x_policy->sadb_x_policy_id; - pthread_mutex_lock(&this->mutex); + this->mutex->lock(this->mutex); if (this->policies->find_first(this->policies, (linked_list_match_t)policy_entry_match_byindex, (void**)&policy, &index) == SUCCESS) { @@ -777,7 +775,7 @@ static void process_acquire(private_kernel_pfkey_ipsec_t *this, struct sadb_msg* } src_ts = sadb_address2ts(response.src); dst_ts = sadb_address2ts(response.dst); - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); DBG1(DBG_KNL, "creating acquire job for policy %R === %R with reqid {%u}", src_ts, dst_ts, reqid); @@ -1428,7 +1426,7 @@ static status_t add_policy(private_kernel_pfkey_ipsec_t *this, policy = create_policy_entry(src_ts, dst_ts, direction, reqid); /* find a matching policy */ - pthread_mutex_lock(&this->mutex); + this->mutex->lock(this->mutex); if (this->policies->find_first(this->policies, (linked_list_match_t)policy_entry_equals, (void**)&found, policy) == SUCCESS) { @@ -1507,7 +1505,7 @@ static status_t add_policy(private_kernel_pfkey_ipsec_t *this, host2ext(policy->dst.net, addr); PFKEY_EXT_ADD(msg, addr); - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); if (pfkey_send(this, msg, &out, &len) != SUCCESS) { @@ -1531,14 +1529,14 @@ static status_t add_policy(private_kernel_pfkey_ipsec_t *this, return FAILED; } - pthread_mutex_lock(&this->mutex); + this->mutex->lock(this->mutex); /* we try to find the policy again and update the kernel index */ if (this->policies->find_last(this->policies, NULL, (void**)&policy) != SUCCESS) { DBG2(DBG_KNL, "unable to update index, the policy %R === %R %N is " "already gone, ignoring", src_ts, dst_ts, policy_dir_names, direction); - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); free(out); return SUCCESS; } @@ -1593,7 +1591,7 @@ static status_t add_policy(private_kernel_pfkey_ipsec_t *this, } } - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); return SUCCESS; } @@ -1621,14 +1619,14 @@ static status_t query_policy(private_kernel_pfkey_ipsec_t *this, policy = create_policy_entry(src_ts, dst_ts, direction, 0); /* find a matching policy */ - pthread_mutex_lock(&this->mutex); + this->mutex->lock(this->mutex); if (this->policies->find_first(this->policies, (linked_list_match_t)policy_entry_equals, (void**)&found, policy) != SUCCESS) { DBG1(DBG_KNL, "querying policy %R === %R %N failed, not found", src_ts, dst_ts, policy_dir_names, direction); policy_entry_destroy(policy); - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); return NOT_FOUND; } policy_entry_destroy(policy); @@ -1664,7 +1662,7 @@ static status_t query_policy(private_kernel_pfkey_ipsec_t *this, host2ext(policy->dst.net, addr); PFKEY_EXT_ADD(msg, addr); - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); if (pfkey_send(this, msg, &out, &len) != SUCCESS) { @@ -1718,7 +1716,7 @@ static status_t del_policy(private_kernel_pfkey_ipsec_t *this, policy = create_policy_entry(src_ts, dst_ts, direction, 0); /* find a matching policy */ - pthread_mutex_lock(&this->mutex); + this->mutex->lock(this->mutex); if (this->policies->find_first(this->policies, (linked_list_match_t)policy_entry_equals, (void**)&found, policy) == SUCCESS) { @@ -1727,7 +1725,7 @@ static status_t del_policy(private_kernel_pfkey_ipsec_t *this, /* is used by more SAs, keep in kernel */ DBG2(DBG_KNL, "policy still used by another CHILD_SA, not removed"); policy_entry_destroy(policy); - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); return SUCCESS; } /* remove if last reference */ @@ -1740,10 +1738,10 @@ static status_t del_policy(private_kernel_pfkey_ipsec_t *this, DBG1(DBG_KNL, "deleting policy %R === %R %N failed, not found", src_ts, dst_ts, policy_dir_names, direction); policy_entry_destroy(policy); - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); return NOT_FOUND; } - pthread_mutex_unlock(&this->mutex); + this->mutex->unlock(this->mutex); memset(&request, 0, sizeof(request)); @@ -1852,6 +1850,8 @@ static void destroy(private_kernel_pfkey_ipsec_t *this) close(this->socket); close(this->socket_events); this->policies->destroy_function(this->policies, (void*)policy_entry_destroy); + this->mutex->destroy(this->mutex); + this->mutex_pfkey->destroy(this->mutex_pfkey); free(this); } @@ -1876,9 +1876,10 @@ kernel_pfkey_ipsec_t *kernel_pfkey_ipsec_create() /* private members */ this->policies = linked_list_create(); - pthread_mutex_init(&this->mutex, NULL); - this->install_routes = lib->settings->get_bool(lib->settings, "charon.install_routes", TRUE); - pthread_mutex_init(&this->mutex_pfkey, NULL); + this->mutex = mutex_create(MUTEX_DEFAULT); + this->mutex_pfkey = mutex_create(MUTEX_DEFAULT); + this->install_routes = lib->settings->get_bool(lib->settings, + "charon.install_routes", TRUE); this->seq = 0; /* create a PF_KEY socket to communicate with the kernel */ |