bus: Add a handle_vips() hook invoked after handling configuration attributes
Similar to assign_vips() used by a peer assigning virtual IPs to the other peer, the handle_vips() hook gets invoked on a peers after receiving attributes. On release of the same attributes the hook gets invoked again. This is useful to inspect handled attributes, as the ike_updown() hook is invoked after authentication, when attributes have not been handled yet.
This commit is contained in:
@@ -879,6 +879,33 @@ METHOD(bus_t, assign_vips, void,
|
|||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
METHOD(bus_t, handle_vips, void,
|
||||||
|
private_bus_t *this, ike_sa_t *ike_sa, bool handle)
|
||||||
|
{
|
||||||
|
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->handle_vips)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
entry->calling++;
|
||||||
|
keep = entry->listener->handle_vips(entry->listener, ike_sa, handle);
|
||||||
|
entry->calling--;
|
||||||
|
if (!keep)
|
||||||
|
{
|
||||||
|
unregister_listener(this, entry, enumerator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
enumerator->destroy(enumerator);
|
||||||
|
this->mutex->unlock(this->mutex);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Credential manager hook function to forward bus alerts
|
* Credential manager hook function to forward bus alerts
|
||||||
*/
|
*/
|
||||||
@@ -955,6 +982,7 @@ bus_t *bus_create()
|
|||||||
.authorize = _authorize,
|
.authorize = _authorize,
|
||||||
.narrow = _narrow,
|
.narrow = _narrow,
|
||||||
.assign_vips = _assign_vips,
|
.assign_vips = _assign_vips,
|
||||||
|
.handle_vips = _handle_vips,
|
||||||
.destroy = _destroy,
|
.destroy = _destroy,
|
||||||
},
|
},
|
||||||
.listeners = linked_list_create(),
|
.listeners = linked_list_create(),
|
||||||
|
|||||||
@@ -411,6 +411,14 @@ struct bus_t {
|
|||||||
*/
|
*/
|
||||||
void (*assign_vips)(bus_t *this, ike_sa_t *ike_sa, bool assign);
|
void (*assign_vips)(bus_t *this, ike_sa_t *ike_sa, bool assign);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Virtual IP handler hook.
|
||||||
|
*
|
||||||
|
* @param ike_sa IKE_SA the VIPs/attributes got handled on
|
||||||
|
* @param assign TRUE after installing attributes, FALSE on release
|
||||||
|
*/
|
||||||
|
void (*handle_vips)(bus_t *this, ike_sa_t *ike_sa, bool handle);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy the event bus.
|
* Destroy the event bus.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -203,6 +203,18 @@ struct listener_t {
|
|||||||
*/
|
*/
|
||||||
bool (*assign_vips)(listener_t *this, ike_sa_t *ike_sa, bool assign);
|
bool (*assign_vips)(listener_t *this, ike_sa_t *ike_sa, bool assign);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Virtual IP and configuration attribute handler hook.
|
||||||
|
*
|
||||||
|
* This hook gets invoked after virtual IP and other configuration
|
||||||
|
* attributes just got installed or are about to get uninstalled on a peer
|
||||||
|
* receiving them.
|
||||||
|
*
|
||||||
|
* @param ike_sa IKE_SA the VIPs/attributes are handled on
|
||||||
|
* @param handle TRUE if handled by IKE_SA, FALSE on release
|
||||||
|
* @return TRUE to stay registered, FALSE to unregister
|
||||||
|
*/
|
||||||
|
bool (*handle_vips)(listener_t *this, ike_sa_t *ike_sa, bool handle);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /** LISTENER_H_ @}*/
|
#endif /** LISTENER_H_ @}*/
|
||||||
|
|||||||
@@ -2168,6 +2168,7 @@ METHOD(ike_sa_t, destroy, void,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* remove attributes first, as we pass the IKE_SA to the handler */
|
/* remove attributes first, as we pass the IKE_SA to the handler */
|
||||||
|
charon->bus->handle_vips(charon->bus, &this->public, FALSE);
|
||||||
while (array_remove(this->attributes, ARRAY_TAIL, &entry))
|
while (array_remove(this->attributes, ARRAY_TAIL, &entry))
|
||||||
{
|
{
|
||||||
if (entry.handler)
|
if (entry.handler)
|
||||||
|
|||||||
@@ -441,6 +441,8 @@ static void install_vips(private_mode_config_t *this)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
enumerator->destroy(enumerator);
|
enumerator->destroy(enumerator);
|
||||||
|
|
||||||
|
charon->bus->handle_vips(charon->bus, this->ike_sa, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
METHOD(task_t, process_r, status_t,
|
METHOD(task_t, process_r, status_t,
|
||||||
|
|||||||
@@ -446,6 +446,8 @@ METHOD(task_t, process_i, status_t,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
enumerator->destroy(enumerator);
|
enumerator->destroy(enumerator);
|
||||||
|
|
||||||
|
charon->bus->handle_vips(charon->bus, this->ike_sa, TRUE);
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
return NEED_MORE;
|
return NEED_MORE;
|
||||||
|
|||||||
Reference in New Issue
Block a user