bus: Add an ike_update() hook invoked when peer endpoints change

This commit is contained in:
Martin Willi 2014-12-09 13:20:44 +01:00
parent 8c2290dcf9
commit e1fe2781b0
4 changed files with 50 additions and 0 deletions

View File

@ -755,6 +755,33 @@ METHOD(bus_t, ike_rekey, void,
this->mutex->unlock(this->mutex); this->mutex->unlock(this->mutex);
} }
METHOD(bus_t, ike_update, void,
private_bus_t *this, ike_sa_t *ike_sa, bool local, host_t *new)
{
enumerator_t *enumerator;
entry_t *entry;
bool keep;
this->mutex->lock(this->mutex);
enumerator = this->listeners->create_enumerator(this->listeners);
while (enumerator->enumerate(enumerator, &entry))
{
if (entry->calling || !entry->listener->ike_update)
{
continue;
}
entry->calling++;
keep = entry->listener->ike_update(entry->listener, ike_sa, local, new);
entry->calling--;
if (!keep)
{
unregister_listener(this, entry, enumerator);
}
}
enumerator->destroy(enumerator);
this->mutex->unlock(this->mutex);
}
METHOD(bus_t, ike_reestablish_pre, void, METHOD(bus_t, ike_reestablish_pre, void,
private_bus_t *this, ike_sa_t *old, ike_sa_t *new) private_bus_t *this, ike_sa_t *old, ike_sa_t *new)
{ {
@ -1006,6 +1033,7 @@ bus_t *bus_create()
.child_keys = _child_keys, .child_keys = _child_keys,
.ike_updown = _ike_updown, .ike_updown = _ike_updown,
.ike_rekey = _ike_rekey, .ike_rekey = _ike_rekey,
.ike_update = _ike_update,
.ike_reestablish_pre = _ike_reestablish_pre, .ike_reestablish_pre = _ike_reestablish_pre,
.ike_reestablish_post = _ike_reestablish_post, .ike_reestablish_post = _ike_reestablish_post,
.child_updown = _child_updown, .child_updown = _child_updown,

View File

@ -381,6 +381,15 @@ struct bus_t {
*/ */
void (*ike_rekey)(bus_t *this, ike_sa_t *old, ike_sa_t *new); void (*ike_rekey)(bus_t *this, ike_sa_t *old, ike_sa_t *new);
/**
* IKE_SA peer endpoint update hook.
*
* @param ike_sa updated IKE_SA, having old endpoints set
* @param local TRUE if local endpoint gets updated, FALSE for remote
* @param new new endpoint address and port
*/
void (*ike_update)(bus_t *this, ike_sa_t *ike_sa, bool local, host_t *new);
/** /**
* IKE_SA reestablishing hook (before resolving hosts). * IKE_SA reestablishing hook (before resolving hosts).
* *

View File

@ -127,6 +127,17 @@ struct listener_t {
*/ */
bool (*ike_rekey)(listener_t *this, ike_sa_t *old, ike_sa_t *new); bool (*ike_rekey)(listener_t *this, ike_sa_t *old, ike_sa_t *new);
/**
* Hook called for IKE_SA peer endpoint updates.
*
* @param ike_sa updated IKE_SA, having old endpoints set
* @param local TRUE if local endpoint gets updated, FALSE for remote
* @param new new endpoint address and port
* @return TRUE to stay registered, FALSE to unregister
*/
bool (*ike_update)(listener_t *this, ike_sa_t *ike_sa,
bool local, host_t *new);
/** /**
* Hook called when an initiator reestablishes an IKE_SA. * Hook called when an initiator reestablishes an IKE_SA.
* *

View File

@ -932,6 +932,7 @@ METHOD(ike_sa_t, update_hosts, void,
/* update our address in any case */ /* update our address in any case */
if (force && !me->equals(me, this->my_host)) if (force && !me->equals(me, this->my_host))
{ {
charon->bus->ike_update(charon->bus, &this->public, TRUE, me);
set_my_host(this, me->clone(me)); set_my_host(this, me->clone(me));
update = TRUE; update = TRUE;
} }
@ -945,6 +946,7 @@ METHOD(ike_sa_t, update_hosts, void,
(!has_condition(this, COND_NAT_HERE) || (!has_condition(this, COND_NAT_HERE) ||
!has_condition(this, COND_ORIGINAL_INITIATOR))) !has_condition(this, COND_ORIGINAL_INITIATOR)))
{ {
charon->bus->ike_update(charon->bus, &this->public, FALSE, other);
set_other_host(this, other->clone(other)); set_other_host(this, other->clone(other));
update = TRUE; update = TRUE;
} }