eap-radius: Add method to explicitly clear unclaimed IPs
authorTobias Brunner <tobias@strongswan.org>
Tue, 11 Dec 2018 10:00:59 +0000 (11:00 +0100)
committerTobias Brunner <tobias@strongswan.org>
Tue, 18 Dec 2018 09:28:51 +0000 (10:28 +0100)
Instead of just enumerating them, removing and then destroying the entry
avoids having to keep the mutex locked.

src/libcharon/plugins/eap_radius/eap_radius_provider.c
src/libcharon/plugins/eap_radius/eap_radius_provider.h

index 8188bb7..e8ebcf6 100644 (file)
@@ -1,4 +1,7 @@
 /*
+ * Copyright (C) 2018 Tobias Brunner
+ * HSR Hochschule fuer Technik Rapperswil
+ *
  * Copyright (C) 2013 Martin Willi
  * Copyright (C) 2013 revosec AG
  *
@@ -131,7 +134,7 @@ static entry_t* get_or_create_entry(hashtable_t *hashtable, uintptr_t id)
 }
 
 /**
- * Put an entry to hashtable, or destroy it ife empty
+ * Put an entry to hashtable, or destroy it if empty
  */
 static void put_or_destroy_entry(hashtable_t *hashtable, entry_t *entry)
 {
@@ -494,6 +497,24 @@ METHOD(eap_radius_provider_t, add_attribute, void,
        this->listener.mutex->unlock(this->listener.mutex);
 }
 
+METHOD(eap_radius_provider_t, clear_unclaimed, enumerator_t*,
+       private_eap_radius_provider_t *this, uint32_t id)
+{
+       entry_t *entry;
+
+       this->listener.mutex->lock(this->listener.mutex);
+       entry = this->listener.unclaimed->remove(this->listener.unclaimed,
+                                                                                        (void*)(uintptr_t)id);
+       this->listener.mutex->unlock(this->listener.mutex);
+       if (!entry)
+       {
+               return enumerator_create_empty();
+       }
+       return enumerator_create_cleaner(
+                                       entry->addrs->create_enumerator(entry->addrs),
+                                       (void*)destroy_entry, entry);
+}
+
 METHOD(eap_radius_provider_t, destroy, void,
        private_eap_radius_provider_t *this)
 {
@@ -523,6 +544,7 @@ eap_radius_provider_t *eap_radius_provider_create()
                                },
                                .add_framed_ip = _add_framed_ip,
                                .add_attribute = _add_attribute,
+                               .clear_unclaimed = _clear_unclaimed,
                                .destroy = _destroy,
                        },
                        .listener = {
index 80971bd..9f1121c 100644 (file)
@@ -1,4 +1,7 @@
 /*
+ * Copyright (C) 2018 Tobias Brunner
+ * HSR Hochschule fuer Technik Rapperswil
+ *
  * Copyright (C) 2013 Martin Willi
  * Copyright (C) 2013 revosec AG
  *
@@ -56,6 +59,14 @@ struct eap_radius_provider_t {
                                                  configuration_attribute_type_t type, chunk_t data);
 
        /**
+        * Clears any unclaimed IP addresses and attributes for the given IKE_SA.
+        *
+        * @param id                    IKE_SA unique identifier
+        * @return                              enumerator over unclaimed IP addresses, if any
+        */
+       enumerator_t *(*clear_unclaimed)(eap_radius_provider_t *this, uint32_t id);
+
+       /**
         * Destroy a eap_radius_provider_t.
         */
        void (*destroy)(eap_radius_provider_t *this);