attribute-manager: Pass the full IKE_SA to provider methods

This commit is contained in:
Martin Willi
2015-02-20 13:34:56 +01:00
parent 124490a8e0
commit a16058a491
5 changed files with 32 additions and 23 deletions
+16 -7
View File
@@ -53,20 +53,23 @@ struct private_attribute_manager_t {
typedef struct { typedef struct {
/** attribute group pools */ /** attribute group pools */
linked_list_t *pools; linked_list_t *pools;
/** server/peer identity */ /** associated IKE_SA */
identification_t *id; ike_sa_t *ike_sa;
/** requesting/assigned virtual IPs */ /** requesting/assigned virtual IPs */
linked_list_t *vips; linked_list_t *vips;
} enum_data_t; } enum_data_t;
METHOD(attribute_manager_t, acquire_address, host_t*, METHOD(attribute_manager_t, acquire_address, host_t*,
private_attribute_manager_t *this, linked_list_t *pools, private_attribute_manager_t *this, linked_list_t *pools,
identification_t *id, host_t *requested) ike_sa_t *ike_sa, host_t *requested)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
attribute_provider_t *current; attribute_provider_t *current;
identification_t *id;
host_t *host = NULL; host_t *host = NULL;
id = ike_sa->get_other_eap_id(ike_sa);
this->lock->read_lock(this->lock); this->lock->read_lock(this->lock);
enumerator = this->providers->create_enumerator(this->providers); enumerator = this->providers->create_enumerator(this->providers);
while (enumerator->enumerate(enumerator, &current)) while (enumerator->enumerate(enumerator, &current))
@@ -85,12 +88,15 @@ METHOD(attribute_manager_t, acquire_address, host_t*,
METHOD(attribute_manager_t, release_address, bool, METHOD(attribute_manager_t, release_address, bool,
private_attribute_manager_t *this, linked_list_t *pools, host_t *address, private_attribute_manager_t *this, linked_list_t *pools, host_t *address,
identification_t *id) ike_sa_t *ike_sa)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
attribute_provider_t *current; attribute_provider_t *current;
identification_t *id;
bool found = FALSE; bool found = FALSE;
id = ike_sa->get_other_eap_id(ike_sa);
this->lock->read_lock(this->lock); this->lock->read_lock(this->lock);
enumerator = this->providers->create_enumerator(this->providers); enumerator = this->providers->create_enumerator(this->providers);
while (enumerator->enumerate(enumerator, &current)) while (enumerator->enumerate(enumerator, &current))
@@ -113,19 +119,22 @@ METHOD(attribute_manager_t, release_address, bool,
static enumerator_t *responder_enum_create(attribute_provider_t *provider, static enumerator_t *responder_enum_create(attribute_provider_t *provider,
enum_data_t *data) enum_data_t *data)
{ {
identification_t *id;
id = data->ike_sa->get_other_eap_id(data->ike_sa);
return provider->create_attribute_enumerator(provider, data->pools, return provider->create_attribute_enumerator(provider, data->pools,
data->id, data->vips); id, data->vips);
} }
METHOD(attribute_manager_t, create_responder_enumerator, enumerator_t*, METHOD(attribute_manager_t, create_responder_enumerator, enumerator_t*,
private_attribute_manager_t *this, linked_list_t *pools, private_attribute_manager_t *this, linked_list_t *pools,
identification_t *id, linked_list_t *vips) ike_sa_t *ike_sa, linked_list_t *vips)
{ {
enum_data_t *data; enum_data_t *data;
INIT(data, INIT(data,
.pools = pools, .pools = pools,
.id = id, .ike_sa = ike_sa,
.vips = vips, .vips = vips,
); );
this->lock->read_lock(this->lock); this->lock->read_lock(this->lock);
+8 -6
View File
@@ -24,6 +24,8 @@
#include "attribute_provider.h" #include "attribute_provider.h"
#include "attribute_handler.h" #include "attribute_handler.h"
#include <sa/ike_sa.h>
typedef struct attribute_manager_t attribute_manager_t; typedef struct attribute_manager_t attribute_manager_t;
/** /**
@@ -40,12 +42,12 @@ struct attribute_manager_t {
* Acquire a virtual IP address to assign to a peer. * Acquire a virtual IP address to assign to a peer.
* *
* @param pools list of pool names (char*) to acquire from * @param pools list of pool names (char*) to acquire from
* @param id peer identity to get address forua * @param ike_sa associated IKE_SA for which an address is requested
* @param requested IP in configuration request * @param requested IP in configuration request
* @return allocated address, NULL to serve none * @return allocated address, NULL to serve none
*/ */
host_t* (*acquire_address)(attribute_manager_t *this, host_t* (*acquire_address)(attribute_manager_t *this,
linked_list_t *pool, identification_t *id, linked_list_t *pool, ike_sa_t *ike_sa,
host_t *requested); host_t *requested);
/** /**
@@ -53,23 +55,23 @@ struct attribute_manager_t {
* *
* @param pools list of pool names (char*) to release to * @param pools list of pool names (char*) to release to
* @param address address to release * @param address address to release
* @param id peer identity to get address for * @param ike_sa associated IKE_SA for which an address is released
* @return TRUE if address released to pool * @return TRUE if address released to pool
*/ */
bool (*release_address)(attribute_manager_t *this, bool (*release_address)(attribute_manager_t *this,
linked_list_t *pools, host_t *address, linked_list_t *pools, host_t *address,
identification_t *id); ike_sa_t *ike_sa);
/** /**
* Create an enumerator over attributes to hand out to a peer. * Create an enumerator over attributes to hand out to a peer.
* *
* @param pool list of pools names (char*) to query attributes from * @param pool list of pools names (char*) to query attributes from
* @param id peer identity to hand out attributes to * @param ike_sa associated IKE_SA for which attributes are requested
* @param vip list of virtual IPs (host_t*) to assign to peer * @param vip list of virtual IPs (host_t*) to assign to peer
* @return enumerator (configuration_attribute_type_t, chunk_t) * @return enumerator (configuration_attribute_type_t, chunk_t)
*/ */
enumerator_t* (*create_responder_enumerator)(attribute_manager_t *this, enumerator_t* (*create_responder_enumerator)(attribute_manager_t *this,
linked_list_t *pool, identification_t *id, linked_list_t *pool, ike_sa_t *ike_sa,
linked_list_t *vips); linked_list_t *vips);
/** /**
+1 -3
View File
@@ -2372,13 +2372,11 @@ METHOD(ike_sa_t, destroy, void,
if (this->peer_cfg) if (this->peer_cfg)
{ {
linked_list_t *pools; linked_list_t *pools;
identification_t *id;
id = get_other_eap_id(this);
pools = linked_list_create_from_enumerator( pools = linked_list_create_from_enumerator(
this->peer_cfg->create_pool_enumerator(this->peer_cfg)); this->peer_cfg->create_pool_enumerator(this->peer_cfg));
charon->attributes->release_address(charon->attributes, charon->attributes->release_address(charon->attributes,
pools, vip, id); pools, vip, &this->public);
pools->destroy(pools); pools->destroy(pools);
} }
vip->destroy(vip); vip->destroy(vip);
+5 -5
View File
@@ -372,11 +372,11 @@ static status_t build_set(private_mode_config_t *this, message_t *message)
pools = linked_list_create_with_items(name, NULL); pools = linked_list_create_with_items(name, NULL);
/* try IPv4, then IPv6 */ /* try IPv4, then IPv6 */
found = charon->attributes->acquire_address(charon->attributes, found = charon->attributes->acquire_address(charon->attributes,
pools, id, any4); pools, this->ike_sa, any4);
if (!found) if (!found)
{ {
found = charon->attributes->acquire_address(charon->attributes, found = charon->attributes->acquire_address(charon->attributes,
pools, id, any6); pools, this->ike_sa, any6);
} }
pools->destroy(pools); pools->destroy(pools);
if (found) if (found)
@@ -398,7 +398,7 @@ static status_t build_set(private_mode_config_t *this, message_t *message)
pools = linked_list_create_from_enumerator( pools = linked_list_create_from_enumerator(
config->create_pool_enumerator(config)); config->create_pool_enumerator(config));
enumerator = charon->attributes->create_responder_enumerator( enumerator = charon->attributes->create_responder_enumerator(
charon->attributes, pools, id, this->vips); charon->attributes, pools, this->ike_sa, this->vips);
while (enumerator->enumerate(enumerator, &type, &value)) while (enumerator->enumerate(enumerator, &type, &value))
{ {
add_attribute(this, cp, type, value, NULL); add_attribute(this, cp, type, value, NULL);
@@ -489,7 +489,7 @@ static status_t build_reply(private_mode_config_t *this, message_t *message)
DBG1(DBG_IKE, "peer requested virtual IP %H", requested); DBG1(DBG_IKE, "peer requested virtual IP %H", requested);
found = charon->attributes->acquire_address(charon->attributes, found = charon->attributes->acquire_address(charon->attributes,
pools, id, requested); pools, this->ike_sa, requested);
if (found) if (found)
{ {
DBG1(DBG_IKE, "assigning virtual IP %H to peer '%Y'", found, id); DBG1(DBG_IKE, "assigning virtual IP %H to peer '%Y'", found, id);
@@ -509,7 +509,7 @@ static status_t build_reply(private_mode_config_t *this, message_t *message)
/* query registered providers for additional attributes to include */ /* query registered providers for additional attributes to include */
enumerator = charon->attributes->create_responder_enumerator( enumerator = charon->attributes->create_responder_enumerator(
charon->attributes, pools, id, vips); charon->attributes, pools, this->ike_sa, vips);
while (enumerator->enumerate(enumerator, &type, &value)) while (enumerator->enumerate(enumerator, &type, &value))
{ {
cp->add_attribute(cp, cp->add_attribute(cp,
+2 -2
View File
@@ -352,7 +352,7 @@ METHOD(task_t, build_r, status_t,
DBG1(DBG_IKE, "peer requested virtual IP %H", requested); DBG1(DBG_IKE, "peer requested virtual IP %H", requested);
found = charon->attributes->acquire_address(charon->attributes, found = charon->attributes->acquire_address(charon->attributes,
pools, id, requested); pools, this->ike_sa, requested);
if (found) if (found)
{ {
DBG1(DBG_IKE, "assigning virtual IP %H to peer '%Y'", found, id); DBG1(DBG_IKE, "assigning virtual IP %H to peer '%Y'", found, id);
@@ -398,7 +398,7 @@ METHOD(task_t, build_r, status_t,
/* query registered providers for additional attributes to include */ /* query registered providers for additional attributes to include */
enumerator = charon->attributes->create_responder_enumerator( enumerator = charon->attributes->create_responder_enumerator(
charon->attributes, pools, id, vips); charon->attributes, pools, this->ike_sa, vips);
while (enumerator->enumerate(enumerator, &type, &value)) while (enumerator->enumerate(enumerator, &type, &value))
{ {
if (!cp) if (!cp)