Generate a new mid only after we start a new task (and exchange)
authorMartin Willi <martin@revosec.ch>
Wed, 23 Nov 2011 13:31:17 +0000 (14:31 +0100)
committerMartin Willi <martin@revosec.ch>
Tue, 20 Mar 2012 16:30:50 +0000 (17:30 +0100)
src/libcharon/sa/task_manager_v1.c

index c415b4e..55bc8b7 100644 (file)
@@ -236,6 +236,7 @@ METHOD(task_manager_t, initiate, status_t,
        host_t *me, *other;
        status_t status;
        exchange_type_t exchange = EXCHANGE_TYPE_UNDEFINED;
+       bool new_mid = FALSE;
 
        if (!this->rng)
        {
@@ -266,11 +267,14 @@ METHOD(task_manager_t, initiate, status_t,
                                if (activate_task(this, TASK_QUICK_MODE))
                                {
                                        exchange = QUICK_MODE;
+                                       new_mid = TRUE;
+                                       break;
                                }
-
                                if (activate_task(this, TASK_XAUTH_REQUEST))
                                {
                                        exchange = TRANSACTION;
+                                       new_mid = TRUE;
+                                       break;
                                }
                                break;
                        default:
@@ -311,12 +315,12 @@ METHOD(task_manager_t, initiate, status_t,
        other = this->ike_sa->get_other_host(this->ike_sa);
 
        message = message_create(IKEV1_MAJOR_VERSION, IKEV1_MINOR_VERSION);
-       if (exchange != ID_PROT)
+       if (new_mid)
        {
                this->rng->get_bytes(this->rng, sizeof(this->initiating.mid),
                                                         (void*)&this->initiating.mid);
-               message->set_message_id(message, this->initiating.mid);
        }
+       message->set_message_id(message, this->initiating.mid);
        message->set_source(message, me->clone(me));
        message->set_destination(message, other->clone(other));
        message->set_exchange_type(message, exchange);