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,
private_lookip_listener_t *this)
{
.message = _message_hook,
.ike_updown = _ike_updown,
},
+ .lookup = _lookup,
.destroy = _destroy,
},
.lock = rwlock_create(RWLOCK_TYPE_DEFAULT),
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_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.
*/