aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2012-10-03 17:13:37 +0200
committerMartin Willi <martin@revosec.ch>2012-10-24 11:43:34 +0200
commit9c54b445e276e60739860e5d2e54ca8ed13b0dcb (patch)
tree9fcd63f47581a9946a9dc71c02c6f904cbe1d95b /src
parent2caa27d42ee5696bae8baac20c914f5b08c272c6 (diff)
downloadstrongswan-9c54b445e276e60739860e5d2e54ca8ed13b0dcb.tar.bz2
strongswan-9c54b445e276e60739860e5d2e54ca8ed13b0dcb.tar.xz
Add a lookup method to lookip plugin, using a callback to invoke
Diffstat (limited to 'src')
-rw-r--r--src/libcharon/plugins/lookip/lookip_listener.c30
-rw-r--r--src/libcharon/plugins/lookip/lookip_listener.h23
2 files changed, 53 insertions, 0 deletions
diff --git a/src/libcharon/plugins/lookip/lookip_listener.c b/src/libcharon/plugins/lookip/lookip_listener.c
index c1cdf5e3f..77ad78ea7 100644
--- a/src/libcharon/plugins/lookip/lookip_listener.c
+++ b/src/libcharon/plugins/lookip/lookip_listener.c
@@ -172,6 +172,35 @@ METHOD(listener_t, ike_updown, bool,
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)
{
@@ -193,6 +222,7 @@ lookip_listener_t *lookip_listener_create()
.message = _message_hook,
.ike_updown = _ike_updown,
},
+ .lookup = _lookup,
.destroy = _destroy,
},
.lock = rwlock_create(RWLOCK_TYPE_DEFAULT),
diff --git a/src/libcharon/plugins/lookip/lookip_listener.h b/src/libcharon/plugins/lookip/lookip_listener.h
index daf979e37..eeb955ec6 100644
--- a/src/libcharon/plugins/lookip/lookip_listener.h
+++ b/src/libcharon/plugins/lookip/lookip_listener.h
@@ -26,6 +26,19 @@
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.
*/
struct lookip_listener_t {
@@ -36,6 +49,16 @@ struct lookip_listener_t {
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.
*/
void (*destroy)(lookip_listener_t *this);