publish all IKE_SA metadata after tnc-ifmap plugin reload

This commit is contained in:
Andreas Steffen 2011-08-08 09:49:35 +02:00
parent 8c78772a05
commit 5144463634
3 changed files with 56 additions and 6 deletions

View File

@ -38,8 +38,11 @@ struct private_tnc_ifmap_listener_t {
};
METHOD(listener_t, ike_updown, bool,
private_tnc_ifmap_listener_t *this, ike_sa_t *ike_sa, bool up)
/**
* Publish metadata of a single IKE_SA
*/
static bool publish_ike_sa(private_tnc_ifmap_listener_t *this,
ike_sa_t *ike_sa, bool up)
{
u_int32_t ike_sa_id;
identification_t *id;
@ -53,7 +56,43 @@ METHOD(listener_t, ike_updown, bool,
if (!this->ifmap->publish(this->ifmap, ike_sa_id, id, host, up))
{
DBG1(DBG_TNC, "ifmap->publish with MAP server failed");
return FALSE;
}
return TRUE;
}
/**
* Publish all IKE_SA metadata
*/
static bool reload_metadata(private_tnc_ifmap_listener_t *this)
{
enumerator_t *enumerator;
ike_sa_t *ike_sa;
bool success = TRUE;
enumerator = charon->controller->create_ike_sa_enumerator(
charon->controller, FALSE);
while (enumerator->enumerate(enumerator, &ike_sa))
{
if (ike_sa->get_state(ike_sa) != IKE_ESTABLISHED)
{
continue;
}
if (!publish_ike_sa(this, ike_sa, TRUE))
{
success = FALSE;
break;
}
}
enumerator->destroy(enumerator);
return success;
}
METHOD(listener_t, ike_updown, bool,
private_tnc_ifmap_listener_t *this, ike_sa_t *ike_sa, bool up)
{
publish_ike_sa(this, ike_sa, up);
return TRUE;
}
@ -68,7 +107,7 @@ METHOD(tnc_ifmap_listener_t, destroy, void,
/**
* See header
*/
tnc_ifmap_listener_t *tnc_ifmap_listener_create()
tnc_ifmap_listener_t *tnc_ifmap_listener_create(bool reload)
{
private_tnc_ifmap_listener_t *this;
@ -104,6 +143,15 @@ tnc_ifmap_listener_t *tnc_ifmap_listener_create()
return NULL;
}
if (reload)
{
if (!reload_metadata(this))
{
destroy(this);
return NULL;
}
}
return &this->public;
}

View File

@ -43,7 +43,9 @@ struct tnc_ifmap_listener_t {
/**
* Create a tnc_ifmap_listener instance.
*
* @param reload reload all IKE_SA metadata
*/
tnc_ifmap_listener_t *tnc_ifmap_listener_create();
tnc_ifmap_listener_t *tnc_ifmap_listener_create(bool reload);
#endif /** TNC_IFMAP_LISTENER_H_ @}*/

View File

@ -51,7 +51,7 @@ METHOD(plugin_t, reload, bool,
this->listener->destroy(this->listener);
}
this->listener = tnc_ifmap_listener_create();
this->listener = tnc_ifmap_listener_create(TRUE);
if (!this->listener)
{
return FALSE;
@ -87,7 +87,7 @@ plugin_t *tnc_ifmap_plugin_create()
.destroy = _destroy,
},
},
.listener = tnc_ifmap_listener_create(),
.listener = tnc_ifmap_listener_create(FALSE),
);
if (this->listener)