got rid of deprecated create_iterator_locked()
authorMartin Willi <martin@strongswan.org>
Wed, 5 Nov 2008 08:32:38 +0000 (08:32 -0000)
committerMartin Willi <martin@strongswan.org>
Wed, 5 Nov 2008 08:32:38 +0000 (08:32 -0000)
16 files changed:
src/charon/plugins/kernel_netlink/kernel_netlink_ipsec.c
src/charon/plugins/kernel_netlink/kernel_netlink_net.c
src/charon/plugins/kernel_netlink/kernel_netlink_shared.c
src/charon/plugins/load_tester/load_tester_ipsec.c
src/charon/plugins/stroke/stroke_list.c
src/charon/plugins/stroke/stroke_socket.c
src/charon/processing/jobs/callback_job.c
src/charon/sa/child_sa.c
src/charon/sa/ike_sa.c
src/charon/sa/tasks/ike_auth_lifetime.c
src/libstrongswan/fetcher/fetcher_manager.c
src/libstrongswan/plugins/x509/x509_ac.c
src/libstrongswan/plugins/x509/x509_cert.c
src/libstrongswan/plugins/x509/x509_crl.c
src/libstrongswan/utils/linked_list.c
src/libstrongswan/utils/linked_list.h

index 4d6211b..c53ce3c 100644 (file)
@@ -1623,7 +1623,7 @@ static status_t del_policy(private_kernel_netlink_ipsec_t *this,
        unsigned char request[NETLINK_BUFFER_SIZE];
        struct nlmsghdr *hdr;
        struct xfrm_userpolicy_id *policy_id;
-       iterator_t *iterator;
+       enumerator_t *enumerator;
        
        DBG2(DBG_KNL, "deleting policy %R === %R %N", src_ts, dst_ts,
                                   policy_dir_names, direction);
@@ -1634,8 +1634,9 @@ static status_t del_policy(private_kernel_netlink_ipsec_t *this,
        policy.direction = direction;
        
        /* find the policy */
-       iterator = this->policies->create_iterator_locked(this->policies, &this->mutex);
-       while (iterator->iterate(iterator, (void**)&current))
+       pthread_mutex_lock(&this->mutex);
+       enumerator = this->policies->create_enumerator(this->policies);
+       while (enumerator->enumerate(enumerator, &current))
        {
                if (memeq(&current->sel, &policy.sel, sizeof(struct xfrm_selector)) &&
                        policy.direction == current->direction)
@@ -1645,15 +1646,17 @@ 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");
-                               iterator->destroy(iterator);
+                               pthread_mutex_unlock(&this->mutex);
+                               enumerator->destroy(enumerator);
                                return SUCCESS;
                        }
                        /* remove if last reference */
-                       iterator->remove(iterator);
+                       this->policies->remove_at(this->policies, enumerator);
                        break;
                }
        }
-       iterator->destroy(iterator);
+       pthread_mutex_unlock(&this->mutex);
+       enumerator->destroy(enumerator);
        if (!to_delete)
        {
                DBG1(DBG_KNL, "deleting policy %R === %R %N failed, not found", src_ts,
index 2a166d0..af26038 100644 (file)
@@ -233,7 +233,7 @@ static void process_link(private_kernel_netlink_net_t *this,
        struct ifinfomsg* msg = (struct ifinfomsg*)(NLMSG_DATA(hdr));
        struct rtattr *rta = IFLA_RTA(msg);
        size_t rtasize = IFLA_PAYLOAD (hdr);
-       iterator_t *iterator;
+       enumerator_t *enumerator;
        iface_entry_t *current, *entry = NULL;
        char *name = NULL;
        bool update = FALSE;
@@ -253,6 +253,7 @@ static void process_link(private_kernel_netlink_net_t *this,
                name = "(unknown)";
        }
        
+       pthread_mutex_lock(&this->mutex);
        switch (hdr->nlmsg_type)
        {
                case RTM_NEWLINK:
@@ -261,9 +262,8 @@ static void process_link(private_kernel_netlink_net_t *this,
                        {       /* ignore loopback interfaces */
                                break;
                        }
-                       iterator = this->ifaces->create_iterator_locked(this->ifaces,
-                                                                                                                       &this->mutex);
-                       while (iterator->iterate(iterator, (void**)&current))
+                       enumerator = this->ifaces->create_enumerator(this->ifaces);
+                       while (enumerator->enumerate(enumerator, &current))
                        {
                                if (current->ifindex == msg->ifi_index)
                                {
@@ -271,6 +271,7 @@ static void process_link(private_kernel_netlink_net_t *this,
                                        break;
                                }
                        }
+                       enumerator->destroy(enumerator);
                        if (!entry)
                        {
                                entry = malloc_thing(iface_entry_t);
@@ -295,14 +296,12 @@ static void process_link(private_kernel_netlink_net_t *this,
                                }
                        }
                        entry->flags = msg->ifi_flags;
-                       iterator->destroy(iterator);
                        break;
                }
                case RTM_DELLINK:
                {
-                       iterator = this->ifaces->create_iterator_locked(this->ifaces,
-                                                                                                                       &this->mutex);
-                       while (iterator->iterate(iterator, (void**)&current))
+                       enumerator = this->ifaces->create_enumerator(this->ifaces);
+                       while (enumerator->enumerate(enumerator, &current))
                        {
                                if (current->ifindex == msg->ifi_index)
                                {
@@ -312,10 +311,11 @@ static void process_link(private_kernel_netlink_net_t *this,
                                        break;
                                }
                        }
-                       iterator->destroy(iterator);
+                       enumerator->destroy(enumerator);
                        break;
                }
        }
+       pthread_mutex_unlock(&this->mutex);
        
        /* send an update to all IKE_SAs */
        if (update && event)
@@ -334,7 +334,7 @@ static void process_addr(private_kernel_netlink_net_t *this,
        struct rtattr *rta = IFA_RTA(msg);
        size_t rtasize = IFA_PAYLOAD (hdr);
        host_t *host = NULL;
-       iterator_t *ifaces, *addrs;
+       enumerator_t *ifaces, *addrs;
        iface_entry_t *iface;
        addr_entry_t *addr;
        chunk_t local = chunk_empty, address = chunk_empty;
@@ -373,20 +373,21 @@ static void process_addr(private_kernel_netlink_net_t *this,
                return;
        }
        
-       ifaces = this->ifaces->create_iterator_locked(this->ifaces, &this->mutex);
-       while (ifaces->iterate(ifaces, (void**)&iface))
+       pthread_mutex_lock(&this->mutex);
+       ifaces = this->ifaces->create_enumerator(this->ifaces);
+       while (ifaces->enumerate(ifaces, &iface))
        {
                if (iface->ifindex == msg->ifa_index)
                {
-                       addrs = iface->addrs->create_iterator(iface->addrs, TRUE);
-                       while (addrs->iterate(addrs, (void**)&addr))
+                       addrs = iface->addrs->create_enumerator(iface->addrs);
+                       while (addrs->enumerate(addrs, &addr))
                        {
                                if (host->ip_equals(host, addr->ip))
                                {
                                        found = TRUE;
                                        if (hdr->nlmsg_type == RTM_DELADDR)
                                        {
-                                               addrs->remove(addrs);
+                                               iface->addrs->remove_at(iface->addrs, addrs);
                                                if (!addr->virtual)
                                                {
                                                        changed = TRUE;
@@ -430,6 +431,7 @@ static void process_addr(private_kernel_netlink_net_t *this,
                }
        }
        ifaces->destroy(ifaces);
+       pthread_mutex_unlock(&this->mutex);
        host->destroy(host);
        
        /* send an update to all IKE_SAs */
@@ -624,18 +626,19 @@ static enumerator_t *create_address_enumerator(private_kernel_netlink_net_t *thi
  */
 static char *get_interface_name(private_kernel_netlink_net_t *this, host_t* ip)
 {
-       iterator_t *ifaces, *addrs;
+       enumerator_t *ifaces, *addrs;
        iface_entry_t *iface;
        addr_entry_t *addr;
        char *name = NULL;
        
        DBG2(DBG_KNL, "getting interface name for %H", ip);
        
-       ifaces = this->ifaces->create_iterator_locked(this->ifaces, &this->mutex);
-       while (ifaces->iterate(ifaces, (void**)&iface))
+       pthread_mutex_lock(&this->mutex);
+       ifaces = this->ifaces->create_enumerator(this->ifaces);
+       while (ifaces->enumerate(ifaces, &iface))
        {
-               addrs = iface->addrs->create_iterator(iface->addrs, TRUE);
-               while (addrs->iterate(addrs, (void**)&addr))
+               addrs = iface->addrs->create_enumerator(iface->addrs);
+               while (addrs->enumerate(addrs, &addr))
                {
                        if (ip->ip_equals(ip, addr->ip))
                        {
@@ -650,6 +653,7 @@ static char *get_interface_name(private_kernel_netlink_net_t *this, host_t* ip)
                }
        }
        ifaces->destroy(ifaces);
+       pthread_mutex_unlock(&this->mutex);
        
        if (name)
        {
@@ -667,14 +671,15 @@ static char *get_interface_name(private_kernel_netlink_net_t *this, host_t* ip)
  */
 static int get_interface_index(private_kernel_netlink_net_t *this, char* name)
 {
-       iterator_t *ifaces;
+       enumerator_t *ifaces;
        iface_entry_t *iface;
        int ifindex = 0;
        
        DBG2(DBG_KNL, "getting iface index for %s", name);
        
-       ifaces = this->ifaces->create_iterator_locked(this->ifaces,     &this->mutex);
-       while (ifaces->iterate(ifaces, (void**)&iface))
+       pthread_mutex_lock(&this->mutex);
+       ifaces = this->ifaces->create_enumerator(this->ifaces);
+       while (ifaces->enumerate(ifaces, &iface))
        {
                if (streq(name, iface->ifname))
                {
@@ -683,6 +688,7 @@ static int get_interface_index(private_kernel_netlink_net_t *this, char* name)
                }
        }
        ifaces->destroy(ifaces);
+       pthread_mutex_unlock(&this->mutex);
 
        if (ifindex == 0)
        {
@@ -815,7 +821,7 @@ static host_t *get_route(private_kernel_netlink_net_t *this, host_t *dest,
                                        && (msg->rtm_dst_len == 0 || /* default route */
                                        (rta_dst.ptr && addr_in_subnet(chunk, rta_dst, msg->rtm_dst_len))))
                                {
-                                       iterator_t *ifaces, *addrs;
+                                       enumerator_t *ifaces, *addrs;
                                        iface_entry_t *iface;
                                        addr_entry_t *addr;
                                        
@@ -840,15 +846,14 @@ static host_t *get_route(private_kernel_netlink_net_t *this, host_t *dest,
                                        else
                                        {
                                                /* no source addr, get one from the interfaces */
-                                               ifaces = this->ifaces->create_iterator_locked(
-                                                                                                       this->ifaces, &this->mutex);
-                                               while (ifaces->iterate(ifaces, (void**)&iface))
+                                               pthread_mutex_lock(&this->mutex);
+                                               ifaces = this->ifaces->create_enumerator(this->ifaces);
+                                               while (ifaces->enumerate(ifaces, &iface))
                                                {
                                                        if (iface->ifindex == rta_oif)
                                                        {
-                                                               addrs = iface->addrs->create_iterator(
-                                                                                                                       iface->addrs, TRUE);
-                                                               while (addrs->iterate(addrs, (void**)&addr))
+                                                               addrs = iface->addrs->create_enumerator(iface->addrs);
+                                                               while (addrs->enumerate(addrs, &addr))
                                                                {
                                                                        chunk_t ip = addr->ip->get_address(addr->ip);
                                                                        if ((msg->rtm_dst_len == 0 && 
@@ -865,6 +870,7 @@ static host_t *get_route(private_kernel_netlink_net_t *this, host_t *dest,
                                                        }
                                                }
                                                ifaces->destroy(ifaces);
+                                               pthread_mutex_unlock(&this->mutex);
                                        }
                                }
                                /* FALL through */
@@ -946,18 +952,19 @@ static status_t add_ip(private_kernel_netlink_net_t *this,
 {
        iface_entry_t *iface;
        addr_entry_t *addr;
-       iterator_t *addrs, *ifaces;
+       enumerator_t *addrs, *ifaces;
        int ifindex;
 
        DBG2(DBG_KNL, "adding virtual IP %H", virtual_ip);
        
-       ifaces = this->ifaces->create_iterator_locked(this->ifaces, &this->mutex);
-       while (ifaces->iterate(ifaces, (void**)&iface))
+       pthread_mutex_lock(&this->mutex);
+       ifaces = this->ifaces->create_enumerator(this->ifaces);
+       while (ifaces->enumerate(ifaces, &iface))
        {
                bool iface_found = FALSE;
        
-               addrs = iface->addrs->create_iterator(iface->addrs, TRUE);
-               while (addrs->iterate(addrs, (void**)&addr))
+               addrs = iface->addrs->create_enumerator(iface->addrs);
+               while (addrs->enumerate(addrs, &addr))
                {
                        if (iface_ip->ip_equals(iface_ip, addr->ip))
                        {
@@ -970,6 +977,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);
                                return SUCCESS;
                        }
                }
@@ -993,14 +1001,17 @@ static status_t add_ip(private_kernel_netlink_net_t *this,
                                        pthread_cond_wait(&this->cond, &this->mutex);
                                }
                                ifaces->destroy(ifaces);
+                               pthread_mutex_unlock(&this->mutex);
                                return SUCCESS;
                        }
                        ifaces->destroy(ifaces);
+                       pthread_mutex_unlock(&this->mutex);
                        DBG1(DBG_KNL, "adding virtual IP %H failed", virtual_ip);
                        return FAILED;
                }
        }
        ifaces->destroy(ifaces);
+       pthread_mutex_unlock(&this->mutex);
        
        DBG1(DBG_KNL, "interface address %H not found, unable to install"
                 "virtual IP %H", iface_ip, virtual_ip);
@@ -1014,17 +1025,18 @@ static status_t del_ip(private_kernel_netlink_net_t *this, host_t *virtual_ip)
 {
        iface_entry_t *iface;
        addr_entry_t *addr;
-       iterator_t *addrs, *ifaces;
+       enumerator_t *addrs, *ifaces;
        status_t status;
        int ifindex;
 
        DBG2(DBG_KNL, "deleting virtual IP %H", virtual_ip);
        
-       ifaces = this->ifaces->create_iterator_locked(this->ifaces, &this->mutex);
-       while (ifaces->iterate(ifaces, (void**)&iface))
+       pthread_mutex_lock(&this->mutex);
+       ifaces = this->ifaces->create_enumerator(this->ifaces);
+       while (ifaces->enumerate(ifaces, &iface))
        {
-               addrs = iface->addrs->create_iterator(iface->addrs, TRUE);
-               while (addrs->iterate(addrs, (void**)&addr))
+               addrs = iface->addrs->create_enumerator(iface->addrs);
+               while (addrs->enumerate(addrs, &addr))
                {
                        if (virtual_ip->ip_equals(virtual_ip, addr->ip))
                        {
@@ -1042,6 +1054,7 @@ static status_t del_ip(private_kernel_netlink_net_t *this, host_t *virtual_ip)
                                        }
                                        addrs->destroy(addrs);
                                        ifaces->destroy(ifaces);
+                                       pthread_mutex_unlock(&this->mutex);
                                        return status;
                                }
                                else
@@ -1052,12 +1065,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);
                                return SUCCESS;
                        }
                }
                addrs->destroy(addrs);
        }
        ifaces->destroy(ifaces);
+       pthread_mutex_unlock(&this->mutex);
        
        DBG2(DBG_KNL, "virtual IP %H not cached, unable to delete", virtual_ip);
        return FAILED;
@@ -1155,7 +1170,7 @@ static status_t init_address_list(private_kernel_netlink_net_t *this)
        struct nlmsghdr *out, *current, *in;
        struct rtgenmsg *msg;
        size_t len;
-       iterator_t *ifaces, *addrs;
+       enumerator_t *ifaces, *addrs;
        iface_entry_t *iface;
        addr_entry_t *addr;
        
@@ -1217,14 +1232,15 @@ static status_t init_address_list(private_kernel_netlink_net_t *this)
        }
        free(out);
        
-       ifaces = this->ifaces->create_iterator_locked(this->ifaces, &this->mutex);
-       while (ifaces->iterate(ifaces, (void**)&iface))
+       pthread_mutex_lock(&this->mutex);
+       ifaces = this->ifaces->create_enumerator(this->ifaces);
+       while (ifaces->enumerate(ifaces, &iface))
        {
                if (iface->flags & IFF_UP)
                {
                        DBG1(DBG_KNL, "  %s", iface->ifname);
-                       addrs = iface->addrs->create_iterator(iface->addrs, TRUE);
-                       while (addrs->iterate(addrs, (void**)&addr))
+                       addrs = iface->addrs->create_enumerator(iface->addrs);
+                       while (addrs->enumerate(addrs, (void**)&addr))
                        {
                                DBG1(DBG_KNL, "    %H", addr->ip);
                        }
@@ -1232,6 +1248,7 @@ static status_t init_address_list(private_kernel_netlink_net_t *this)
                }
        }
        ifaces->destroy(ifaces);
+       pthread_mutex_unlock(&this->mutex);
        return SUCCESS;
 }
 
index dd90453..f4af941 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/rtnetlink.h>
 #include <errno.h>
 #include <unistd.h>
+#include <pthread.h>
 
 #include "kernel_netlink_shared.h"
 
index bcbab00..ddb72ac 100644 (file)
@@ -17,6 +17,8 @@
 
 #include "load_tester_ipsec.h"
 
+#include <time.h>
+
 typedef struct private_load_tester_ipsec_t private_load_tester_ipsec_t;
 
 /**
index 7d5c86a..675ef83 100644 (file)
@@ -17,6 +17,8 @@
 
 #include "stroke_list.h"
 
+#include <time.h>
+
 #include <daemon.h>
 #include <utils/linked_list.h>
 #include <credentials/certificates/x509.h>
index 70f12ea..850b94b 100644 (file)
@@ -25,6 +25,7 @@
 #include <sys/fcntl.h>
 #include <unistd.h>
 #include <errno.h>
+#include <pthread.h>
 
 #include <processing/jobs/callback_job.h>
 #include <daemon.h>
index cd5764a..9cc4eea 100644 (file)
@@ -17,6 +17,8 @@
  
 #include "callback_job.h"
 
+#include <pthread.h>
+
 #include <daemon.h>
 
 typedef struct private_callback_job_t private_callback_job_t;
index 1cc2ad0..f60ea3f 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <time.h>
 
 #include <daemon.h>
 
index 5b359bb..6af92e1 100644 (file)
@@ -23,6 +23,7 @@
 #include <printf.h>
 #include <sys/stat.h>
 #include <errno.h>
+#include <time.h>
 
 #include "ike_sa.h"
 
index 6be893c..328f11d 100644 (file)
@@ -17,6 +17,8 @@
 
 #include "ike_auth_lifetime.h"
 
+#include <time.h>
+
 #include <daemon.h>
 #include <encoding/payloads/notify_payload.h>
 
index 3a9e632..bdcaf82 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #define _GNU_SOURCE
+#include <pthread.h>
 
 #include "fetcher_manager.h"
 
index caae5e0..257a903 100644 (file)
@@ -21,6 +21,8 @@
 #include "x509_ac.h"
 #include "ietf_attr_list.h"
 
+#include <time.h>
+
 #include <library.h>
 #include <debug.h>
 #include <asn1/oid.h>
index d403386..9cdd7ff 100644 (file)
@@ -25,6 +25,7 @@
 #include "x509_cert.h"
 
 #include <sys/stat.h>
+#include <time.h>
 #include <unistd.h>
 #include <string.h>
 #include <stdio.h>
index 4977934..62a4064 100644 (file)
@@ -20,6 +20,8 @@
 typedef struct private_x509_crl_t private_x509_crl_t;
 typedef struct revoked_t revoked_t;
 
+#include <time.h>
+
 #include <debug.h>
 #include <library.h>
 #include <asn1/oid.h>
index 9508e9a..12dfa23 100644 (file)
@@ -121,11 +121,6 @@ struct private_iterator_t {
        bool forward;
        
        /**
-        * Mutex to use to synchronize access
-        */
-       pthread_mutex_t *mutex;
-       
-       /**
         * iteration hook
         */
        iterator_hook_t *hook;
@@ -428,10 +423,6 @@ static void insert_after(private_iterator_t *iterator, void *item)
  */
 static void iterator_destroy(private_iterator_t *this)
 {
-       if (this->mutex)
-       {
-               pthread_mutex_unlock(this->mutex);
-       }
        free(this);
 }
 
@@ -806,26 +797,11 @@ static iterator_t *create_iterator(private_linked_list_t *linked_list, bool forw
        this->forward = forward;
        this->current = NULL;
        this->list = linked_list;
-       this->mutex = NULL;
        this->hook = iterator_hook;
        
        return &this->public;
 }
 
-/**
- * Implementation of linked_list_t.create_iterator_locked.
- */
-static iterator_t *create_iterator_locked(private_linked_list_t *linked_list,
-                                                                                 pthread_mutex_t *mutex)
-{
-       private_iterator_t *this = (private_iterator_t*)create_iterator(linked_list, TRUE);
-       this->mutex = mutex;
-       
-       pthread_mutex_lock(mutex);
-       
-       return &this->public;
-}
-
 /*
  * Described in header.
  */
@@ -835,7 +811,6 @@ linked_list_t *linked_list_create()
 
        this->public.get_count = (int (*) (linked_list_t *)) get_count;
        this->public.create_iterator = (iterator_t * (*) (linked_list_t *,bool))create_iterator;
-       this->public.create_iterator_locked = (iterator_t * (*) (linked_list_t *,pthread_mutex_t*))create_iterator_locked;
        this->public.create_enumerator = (enumerator_t*(*)(linked_list_t*))create_enumerator;
        this->public.get_first = (status_t (*) (linked_list_t *, void **item))get_first;
        this->public.get_last = (status_t (*) (linked_list_t *, void **item))get_last;
index 183f93f..41ca06a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2007-2008 Tobias Brunner
- * Copyright (C) 2005-2006 Martin Willi
+ * Copyright (C) 2005-2008 Martin Willi
  * Copyright (C) 2005 Jan Hutter
  * Hochschule fuer Technik Rapperswil
  *
 
 typedef struct linked_list_t linked_list_t;
 
-#include <pthread.h>
-
 #include <library.h>
 #include <utils/iterator.h>
 #include <utils/enumerator.h>
 
-
 /**
  * Method to match elements in a linked list (used in find_* functions)
  *
@@ -81,18 +78,6 @@ struct linked_list_t {
        iterator_t *(*create_iterator) (linked_list_t *this, bool forward);
        
        /**
-        * Creates a iterator, locking a mutex.
-        *
-        * The supplied mutex is acquired immediately, and released
-        * when the iterator gets destroyed.
-        * 
-        * @param mutex         mutex to use for exclusive access
-        * @return                      new iterator_t object
-        */
-       iterator_t *(*create_iterator_locked) (linked_list_t *this,
-                                                                                  pthread_mutex_t *mutex);
-       
-       /**
         * Create an enumerator over the list.
         *
         * The enumerator is a "lightweight" iterator. It only has two methods