fixing mediation extension
authorTobias Brunner <tobias@strongswan.org>
Tue, 11 Nov 2008 13:12:05 +0000 (13:12 -0000)
committerTobias Brunner <tobias@strongswan.org>
Tue, 11 Nov 2008 13:12:05 +0000 (13:12 -0000)
src/charon/processing/jobs/initiate_mediation_job.c
src/charon/sa/ike_sa.c

index ed247e0..db9e76e 100644 (file)
@@ -54,6 +54,21 @@ static void destroy(private_initiate_mediation_job_t *this)
 }
 
 /**
+ * Callback to handle initiation of mediation connection
+ */
+static bool initiate_callback(private_initiate_mediation_job_t *this,
+                       debug_t group, level_t level, ike_sa_t *ike_sa,
+                       char *format, va_list args)
+{
+       if (ike_sa && !this->mediation_sa_id)
+       {
+               this->mediation_sa_id = ike_sa->get_id(ike_sa);
+               this->mediation_sa_id = this->mediation_sa_id->clone(this->mediation_sa_id);
+       }
+       return TRUE;
+}
+
+/**
  * Implementation of job_t.execute.
  */ 
 static void initiate(private_initiate_mediation_job_t *this)
@@ -96,13 +111,8 @@ static void initiate(private_initiate_mediation_job_t *this)
                /* we need an additional reference because initiate consumes one */
                mediation_cfg->get_ref(mediation_cfg); 
 
-               /* this function call blocks until the connection is up or failed
-                * we do not check the status, but NEED_MORE would be returned on success
-                * because the registered callback returns FALSE then
-                * this->mediation_sa_id is set in the callback */
-               charon->controller->initiate(charon->controller, mediation_cfg, NULL,
-                                                                        controller_cb_empty, this);
-               if (!this->mediation_sa_id)
+               if (charon->controller->initiate(charon->controller, mediation_cfg,
+                                       NULL, (controller_cb_t)initiate_callback, this) != SUCCESS)
                {
                        mediation_cfg->destroy(mediation_cfg);
                        mediated_cfg->destroy(mediated_cfg);
index 80e42d9..1c5953c 100644 (file)
@@ -1169,10 +1169,14 @@ static status_t initiate_with_reqid(private_ike_sa_t *this, child_cfg_t *child_c
 
 #ifdef ME
        if (this->peer_cfg->is_mediation(this->peer_cfg))
-       {       /* mediation connection is already established, retrigger state change
-                * to notify bus listeners */
-               DBG1(DBG_IKE, "mediation connection is already up");
-               set_state(this, IKE_ESTABLISHED);
+       {
+               if (this->state == IKE_ESTABLISHED)
+               {
+                       /* mediation connection is already established, retrigger state change
+                        * to notify bus listeners */
+                       DBG1(DBG_IKE, "mediation connection is already up");
+                       set_state(this, IKE_ESTABLISHED);
+               }
                DESTROY_IF(child_cfg);
        }
        else