Skip to content

Commit 0407d72

Browse files
committed
eap-radius: Add method to explicitly clear unclaimed IPs
Instead of just enumerating them, removing and then destroying the entry avoids having to keep the mutex locked.
1 parent 533efa9 commit 0407d72

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/libcharon/plugins/eap_radius/eap_radius_provider.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/*
2+
* Copyright (C) 2018 Tobias Brunner
3+
* HSR Hochschule fuer Technik Rapperswil
4+
*
25
* Copyright (C) 2013 Martin Willi
36
* Copyright (C) 2013 revosec AG
47
*
@@ -131,7 +134,7 @@ static entry_t* get_or_create_entry(hashtable_t *hashtable, uintptr_t id)
131134
}
132135

133136
/**
134-
* Put an entry to hashtable, or destroy it ife empty
137+
* Put an entry to hashtable, or destroy it if empty
135138
*/
136139
static void put_or_destroy_entry(hashtable_t *hashtable, entry_t *entry)
137140
{
@@ -494,6 +497,24 @@ METHOD(eap_radius_provider_t, add_attribute, void,
494497
this->listener.mutex->unlock(this->listener.mutex);
495498
}
496499

500+
METHOD(eap_radius_provider_t, clear_unclaimed, enumerator_t*,
501+
private_eap_radius_provider_t *this, uint32_t id)
502+
{
503+
entry_t *entry;
504+
505+
this->listener.mutex->lock(this->listener.mutex);
506+
entry = this->listener.unclaimed->remove(this->listener.unclaimed,
507+
(void*)(uintptr_t)id);
508+
this->listener.mutex->unlock(this->listener.mutex);
509+
if (!entry)
510+
{
511+
return enumerator_create_empty();
512+
}
513+
return enumerator_create_cleaner(
514+
entry->addrs->create_enumerator(entry->addrs),
515+
(void*)destroy_entry, entry);
516+
}
517+
497518
METHOD(eap_radius_provider_t, destroy, void,
498519
private_eap_radius_provider_t *this)
499520
{
@@ -523,6 +544,7 @@ eap_radius_provider_t *eap_radius_provider_create()
523544
},
524545
.add_framed_ip = _add_framed_ip,
525546
.add_attribute = _add_attribute,
547+
.clear_unclaimed = _clear_unclaimed,
526548
.destroy = _destroy,
527549
},
528550
.listener = {

src/libcharon/plugins/eap_radius/eap_radius_provider.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/*
2+
* Copyright (C) 2018 Tobias Brunner
3+
* HSR Hochschule fuer Technik Rapperswil
4+
*
25
* Copyright (C) 2013 Martin Willi
36
* Copyright (C) 2013 revosec AG
47
*
@@ -55,6 +58,14 @@ struct eap_radius_provider_t {
5558
void (*add_attribute)(eap_radius_provider_t *this, uint32_t id,
5659
configuration_attribute_type_t type, chunk_t data);
5760

61+
/**
62+
* Clears any unclaimed IP addresses and attributes for the given IKE_SA.
63+
*
64+
* @param id IKE_SA unique identifier
65+
* @return enumerator over unclaimed IP addresses, if any
66+
*/
67+
enumerator_t *(*clear_unclaimed)(eap_radius_provider_t *this, uint32_t id);
68+
5869
/**
5970
* Destroy a eap_radius_provider_t.
6071
*/

0 commit comments

Comments
 (0)