Lookip plugin additionally reports the IKE_SA unique identifier

This commit is contained in:
Martin Willi
2012-11-29 10:00:45 +01:00
parent f0d4756eb0
commit 2685020ace
5 changed files with 21 additions and 10 deletions
+3 -2
View File
@@ -78,7 +78,7 @@ static int send_request(int fd, int type, char *vip)
static int receive(int fd, int block, int loop) static int receive(int fd, int block, int loop)
{ {
lookip_response_t resp; lookip_response_t resp;
char *label; char *label, name[32];
int res; int res;
do do
@@ -120,8 +120,9 @@ static int receive(int fd, int block, int loop)
resp.id[sizeof(resp.id) - 1] = '\0'; resp.id[sizeof(resp.id) - 1] = '\0';
resp.name[sizeof(resp.name) - 1] = '\0'; resp.name[sizeof(resp.name) - 1] = '\0';
snprintf(name, sizeof(name), "%s[%u]", resp.name, resp.unique_id);
printf("%-12s %16s %16s %20s %s\n", printf("%-12s %16s %16s %20s %s\n",
label, resp.vip, resp.ip, resp.name, resp.id); label, resp.vip, resp.ip, name, resp.id);
} }
while (loop); while (loop);
@@ -70,6 +70,8 @@ typedef struct {
identification_t *id; identification_t *id;
/** associated connection name */ /** associated connection name */
char *name; char *name;
/** IKE_SA unique identifier */
u_int unique_id;
} entry_t; } entry_t;
/** /**
@@ -106,7 +108,7 @@ static bool equals(host_t *a, host_t *b)
static bool notify_up(listener_entry_t *listener, entry_t *entry) static bool notify_up(listener_entry_t *listener, entry_t *entry)
{ {
if (!listener->cb(listener->user, TRUE, entry->vip, entry->other, if (!listener->cb(listener->user, TRUE, entry->vip, entry->other,
entry->id, entry->name)) entry->id, entry->name, entry->unique_id))
{ {
free(listener); free(listener);
return TRUE; return TRUE;
@@ -120,7 +122,7 @@ static bool notify_up(listener_entry_t *listener, entry_t *entry)
static bool notify_down(listener_entry_t *listener, entry_t *entry) static bool notify_down(listener_entry_t *listener, entry_t *entry)
{ {
if (!listener->cb(listener->user, FALSE, entry->vip, entry->other, if (!listener->cb(listener->user, FALSE, entry->vip, entry->other,
entry->id, entry->name)) entry->id, entry->name, entry->unique_id))
{ {
free(listener); free(listener);
return TRUE; return TRUE;
@@ -149,6 +151,7 @@ static void add_entry(private_lookip_listener_t *this, ike_sa_t *ike_sa)
.other = other->clone(other), .other = other->clone(other),
.id = id->clone(id), .id = id->clone(id),
.name = strdup(ike_sa->get_name(ike_sa)), .name = strdup(ike_sa->get_name(ike_sa)),
.unique_id = ike_sa->get_unique_id(ike_sa),
); );
this->lock->read_lock(this->lock); this->lock->read_lock(this->lock);
@@ -237,7 +240,8 @@ METHOD(lookip_listener_t, lookup, int,
entry = this->entries->get(this->entries, vip); entry = this->entries->get(this->entries, vip);
if (entry) if (entry)
{ {
cb(user, TRUE, entry->vip, entry->other, entry->id, entry->name); cb(user, TRUE, entry->vip, entry->other, entry->id,
entry->name, entry->unique_id);
matches ++; matches ++;
} }
} }
@@ -248,7 +252,8 @@ METHOD(lookip_listener_t, lookup, int,
enumerator = this->entries->create_enumerator(this->entries); enumerator = this->entries->create_enumerator(this->entries);
while (enumerator->enumerate(enumerator, &vip, &entry)) while (enumerator->enumerate(enumerator, &vip, &entry))
{ {
cb(user, TRUE, entry->vip, entry->other, entry->id, entry->name); cb(user, TRUE, entry->vip, entry->other, entry->id,
entry->name, entry->unique_id);
matches++; matches++;
} }
enumerator->destroy(enumerator); enumerator->destroy(enumerator);
@@ -34,10 +34,12 @@ typedef struct lookip_listener_t lookip_listener_t;
* @param other peer external IP * @param other peer external IP
* @param id peer identity * @param id peer identity
* @param name associated connection name * @param name associated connection name
* @param unique_id unique IKE_SA identifier
* @return TRUE to receive more results, FALSE to cancel * @return TRUE to receive more results, FALSE to cancel
*/ */
typedef bool (*lookip_callback_t)(void *user, bool up, host_t *vip, typedef bool (*lookip_callback_t)(void *user, bool up, host_t *vip,
host_t *other, identification_t *id, char *name); host_t *other, identification_t *id,
char *name, u_int unique_id);
/** /**
* Listener collecting virtual IPs. * Listener collecting virtual IPs.
+4 -2
View File
@@ -87,8 +87,10 @@ struct lookip_response_t {
char ip[40]; char ip[40];
/** null terminated peer identity */ /** null terminated peer identity */
char id[128]; char id[128];
/** null connection name */ /** null terminated connection name */
char name[44]; char name[40];
/** unique connection id */
unsigned int unique_id;
}; };
#endif /** LOOKIP_MSG_H_ @}*/ #endif /** LOOKIP_MSG_H_ @}*/
+2 -1
View File
@@ -135,7 +135,8 @@ static void entry_destroy(entry_t *this)
* Callback function for listener * Callback function for listener
*/ */
static bool listener_cb(entry_t *entry, bool up, host_t *vip, static bool listener_cb(entry_t *entry, bool up, host_t *vip,
host_t *other, identification_t *id, char *name) host_t *other, identification_t *id,
char *name, u_int unique_id)
{ {
lookip_response_t resp = { lookip_response_t resp = {
.type = entry->type, .type = entry->type,