publish all IKE_SA metadata after tnc-ifmap plugin reload
authorAndreas Steffen <andreas.steffen@strongswan.org>
Mon, 8 Aug 2011 07:49:35 +0000 (09:49 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Wed, 10 Aug 2011 07:29:34 +0000 (09:29 +0200)
src/libcharon/plugins/tnc_ifmap/tnc_ifmap_listener.c
src/libcharon/plugins/tnc_ifmap/tnc_ifmap_listener.h
src/libcharon/plugins/tnc_ifmap/tnc_ifmap_plugin.c

index 36dec39..4a76fc6 100644 (file)
@@ -38,8 +38,11 @@ struct private_tnc_ifmap_listener_t {
 
 };
 
-METHOD(listener_t, ike_updown, bool,
-       private_tnc_ifmap_listener_t *this, ike_sa_t *ike_sa, bool up)
+/**
+ * Publish metadata of a single IKE_SA
+ */
+static bool publish_ike_sa(private_tnc_ifmap_listener_t *this,
+                                                  ike_sa_t *ike_sa, bool up)
 {
        u_int32_t ike_sa_id;
        identification_t *id;
@@ -53,7 +56,43 @@ METHOD(listener_t, ike_updown, bool,
        if (!this->ifmap->publish(this->ifmap, ike_sa_id, id, host, up))
        {
                DBG1(DBG_TNC, "ifmap->publish with MAP server failed");
+               return FALSE;
        }
+       return TRUE;
+}
+
+/**
+ * Publish all IKE_SA metadata
+ */
+static bool reload_metadata(private_tnc_ifmap_listener_t *this)
+{
+       enumerator_t *enumerator;
+       ike_sa_t *ike_sa;
+       bool success = TRUE;
+
+       enumerator = charon->controller->create_ike_sa_enumerator(
+                                                                                               charon->controller, FALSE);
+       while (enumerator->enumerate(enumerator, &ike_sa))
+       {
+               if (ike_sa->get_state(ike_sa) != IKE_ESTABLISHED)
+               {
+                       continue;
+               }
+               if (!publish_ike_sa(this, ike_sa, TRUE))
+               {
+                       success = FALSE;
+                       break;
+               }
+       }
+       enumerator->destroy(enumerator);
+       
+       return success;
+}
+
+METHOD(listener_t, ike_updown, bool,
+       private_tnc_ifmap_listener_t *this, ike_sa_t *ike_sa, bool up)
+{
+       publish_ike_sa(this, ike_sa, up);
 
        return TRUE;
 }
@@ -68,7 +107,7 @@ METHOD(tnc_ifmap_listener_t, destroy, void,
 /**
  * See header
  */
-tnc_ifmap_listener_t *tnc_ifmap_listener_create()
+tnc_ifmap_listener_t *tnc_ifmap_listener_create(bool reload)
 {
        private_tnc_ifmap_listener_t *this;
 
@@ -104,6 +143,15 @@ tnc_ifmap_listener_t *tnc_ifmap_listener_create()
                return NULL;
        }
 
+       if (reload)
+       {
+               if (!reload_metadata(this))
+               {
+                       destroy(this);
+                       return NULL;
+               }
+       }
+
        return &this->public;
 }
 
index 4a2c5e8..878505b 100644 (file)
@@ -43,7 +43,9 @@ struct tnc_ifmap_listener_t {
 
 /**
  * Create a tnc_ifmap_listener instance.
+ *
+ * @param reload       reload all IKE_SA metadata
  */
-tnc_ifmap_listener_t *tnc_ifmap_listener_create();
+tnc_ifmap_listener_t *tnc_ifmap_listener_create(bool reload);
 
 #endif /** TNC_IFMAP_LISTENER_H_ @}*/
index 6c97a5a..de4d12e 100644 (file)
@@ -51,7 +51,7 @@ METHOD(plugin_t, reload, bool,
                this->listener->destroy(this->listener);
        }
 
-       this->listener = tnc_ifmap_listener_create();
+       this->listener = tnc_ifmap_listener_create(TRUE);
        if (!this->listener)
        {
                return FALSE;
@@ -87,7 +87,7 @@ plugin_t *tnc_ifmap_plugin_create()
                                .destroy = _destroy,
                        },
                },
-               .listener = tnc_ifmap_listener_create(),
+               .listener = tnc_ifmap_listener_create(FALSE),
        );
 
        if (this->listener)