]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Lookip plugin additionally reports the IKE_SA unique identifier
authorMartin Willi <martin@revosec.ch>
Thu, 29 Nov 2012 08:53:10 +0000 (09:53 +0100)
committerMartin Willi <martin@revosec.ch>
Thu, 29 Nov 2012 09:00:45 +0000 (10:00 +0100)
src/libcharon/plugins/lookip/lookip.c
src/libcharon/plugins/lookip/lookip_listener.c
src/libcharon/plugins/lookip/lookip_listener.h
src/libcharon/plugins/lookip/lookip_msg.h
src/libcharon/plugins/lookip/lookip_socket.c

index 98c1379eb90b26250dc08d492e8ee3abe197550a..d5d8d0a635c5967010f018976b7af1ccacd8401c 100644 (file)
@@ -78,7 +78,7 @@ static int send_request(int fd, int type, char *vip)
 static int receive(int fd, int block, int loop)
 {
        lookip_response_t resp;
-       char *label;
+       char *label, name[32];
        int res;
 
        do
@@ -120,8 +120,9 @@ static int receive(int fd, int block, int loop)
                resp.id[sizeof(resp.id) - 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",
-                          label, resp.vip, resp.ip, resp.name, resp.id);
+                          label, resp.vip, resp.ip, name, resp.id);
        }
        while (loop);
 
index d2388f6b58fcfa3d8711b7b0d69dcb3135df1281..3a67eae083583a22235a482a0ebcb20273f66ff6 100644 (file)
@@ -70,6 +70,8 @@ typedef struct {
        identification_t *id;
        /** associated connection name */
        char *name;
+       /** IKE_SA unique identifier */
+       u_int unique_id;
 } 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)
 {
        if (!listener->cb(listener->user, TRUE, entry->vip, entry->other,
-                                         entry->id, entry->name))
+                                         entry->id, entry->name, entry->unique_id))
        {
                free(listener);
                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)
 {
        if (!listener->cb(listener->user, FALSE, entry->vip, entry->other,
-                                                entry->id, entry->name))
+                                         entry->id, entry->name, entry->unique_id))
        {
                free(listener);
                return TRUE;
@@ -149,6 +151,7 @@ static void add_entry(private_lookip_listener_t *this, ike_sa_t *ike_sa)
                        .other = other->clone(other),
                        .id = id->clone(id),
                        .name = strdup(ike_sa->get_name(ike_sa)),
+                       .unique_id = ike_sa->get_unique_id(ike_sa),
                );
 
                this->lock->read_lock(this->lock);
@@ -237,7 +240,8 @@ METHOD(lookip_listener_t, lookup, int,
                entry = this->entries->get(this->entries, vip);
                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 ++;
                }
        }
@@ -248,7 +252,8 @@ METHOD(lookip_listener_t, lookup, int,
                enumerator = this->entries->create_enumerator(this->entries);
                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++;
                }
                enumerator->destroy(enumerator);
index 8d1278a5f33f9a9d37affde3540b20cbf1121af9..56f74ed480f0301c449d8de4fe9d1936264f962f 100644 (file)
@@ -34,10 +34,12 @@ typedef struct lookip_listener_t lookip_listener_t;
  * @param other                peer external IP
  * @param id           peer identity
  * @param name         associated connection name
+ * @param unique_id    unique IKE_SA identifier
  * @return                     TRUE to receive more results, FALSE to cancel
  */
 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.
index 337d1c49f4287424df265b3a5c8bda6e04e61e4c..d5789c29fad88d9f2ab795bdb4eda549ec4af4ce 100644 (file)
@@ -87,8 +87,10 @@ struct lookip_response_t {
        char ip[40];
        /** null terminated peer identity */
        char id[128];
-       /** null connection name */
-       char name[44];
+       /** null terminated connection name */
+       char name[40];
+       /** unique connection id */
+       unsigned int unique_id;
 };
 
 #endif /** LOOKIP_MSG_H_ @}*/
index dc1a80b83656327d2126ba57f6dbda7a8debb918..a326aae711182a0ecbfff5abc478761ac1c3c098 100644 (file)
@@ -135,7 +135,8 @@ static void entry_destroy(entry_t *this)
  * Callback function for listener
  */
 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 = {
                .type = entry->type,