Add a lookup method to lookip plugin, using a callback to invoke
This commit is contained in:
@@ -172,6 +172,35 @@ METHOD(listener_t, ike_updown, bool,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
METHOD(lookip_listener_t, lookup, void,
|
||||||
|
private_lookip_listener_t *this, host_t *vip,
|
||||||
|
lookip_callback_t cb, void *user)
|
||||||
|
{
|
||||||
|
entry_t *entry;
|
||||||
|
|
||||||
|
this->lock->read_lock(this->lock);
|
||||||
|
if (vip)
|
||||||
|
{
|
||||||
|
entry = this->entries->get(this->entries, vip);
|
||||||
|
if (entry)
|
||||||
|
{
|
||||||
|
cb(user, entry->vip, entry->other, entry->id, entry->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
enumerator_t *enumerator;
|
||||||
|
|
||||||
|
enumerator = this->entries->create_enumerator(this->entries);
|
||||||
|
while (enumerator->enumerate(enumerator, &vip, &entry))
|
||||||
|
{
|
||||||
|
cb(user, entry->vip, entry->other, entry->id, entry->name);
|
||||||
|
}
|
||||||
|
enumerator->destroy(enumerator);
|
||||||
|
}
|
||||||
|
this->lock->unlock(this->lock);
|
||||||
|
}
|
||||||
|
|
||||||
METHOD(lookip_listener_t, destroy, void,
|
METHOD(lookip_listener_t, destroy, void,
|
||||||
private_lookip_listener_t *this)
|
private_lookip_listener_t *this)
|
||||||
{
|
{
|
||||||
@@ -193,6 +222,7 @@ lookip_listener_t *lookip_listener_create()
|
|||||||
.message = _message_hook,
|
.message = _message_hook,
|
||||||
.ike_updown = _ike_updown,
|
.ike_updown = _ike_updown,
|
||||||
},
|
},
|
||||||
|
.lookup = _lookup,
|
||||||
.destroy = _destroy,
|
.destroy = _destroy,
|
||||||
},
|
},
|
||||||
.lock = rwlock_create(RWLOCK_TYPE_DEFAULT),
|
.lock = rwlock_create(RWLOCK_TYPE_DEFAULT),
|
||||||
|
|||||||
@@ -25,6 +25,19 @@
|
|||||||
|
|
||||||
typedef struct lookip_listener_t lookip_listener_t;
|
typedef struct lookip_listener_t lookip_listener_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback function to query virtual IP entries
|
||||||
|
*
|
||||||
|
* @param user user supplied pointer
|
||||||
|
* @param vip virtual IP of remote peer
|
||||||
|
* @param other peer external IP
|
||||||
|
* @param id peer identity
|
||||||
|
* @param name associated connection name
|
||||||
|
* @return TRUE to receive more results, FALSE to cancel
|
||||||
|
*/
|
||||||
|
typedef bool (*lookip_callback_t)(void *user, host_t *vip, host_t *other,
|
||||||
|
identification_t *id, char *name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listener collecting virtual IPs.
|
* Listener collecting virtual IPs.
|
||||||
*/
|
*/
|
||||||
@@ -35,6 +48,16 @@ struct lookip_listener_t {
|
|||||||
*/
|
*/
|
||||||
listener_t listener;
|
listener_t listener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform a lookup for a given virtual IP, invoke callback for matches.
|
||||||
|
*
|
||||||
|
* @param vip virtual IP to look up, NULL to get all entries
|
||||||
|
* @param cb callback function to invoke
|
||||||
|
* @param user user data to pass to callback function
|
||||||
|
*/
|
||||||
|
void (*lookup)(lookip_listener_t *this, host_t *vip,
|
||||||
|
lookip_callback_t cb, void *user);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy a lookip_listener_t.
|
* Destroy a lookip_listener_t.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user