ikev2: Don't increase expected MID after handling MID sync message
authorTobias Brunner <tobias@strongswan.org>
Tue, 4 Oct 2016 13:15:36 +0000 (15:15 +0200)
committerTobias Brunner <tobias@strongswan.org>
Wed, 8 Feb 2017 14:03:26 +0000 (15:03 +0100)
If the responder never sent a message the expected MID is 0.  While
the sent MID (M1) SHOULD be increased beyond the known value, it's
not necessarily the case.
Since M2 - 1 would then equal UINT_MAX setting that MID would get ignored
and while we'd return 0 in the notify we'd actually expect 1 afterwards.

src/libcharon/sa/ikev2/task_manager_v2.c
src/libcharon/sa/ikev2/tasks/ike_mid_sync.c

index debfe23..778349c 100644 (file)
@@ -918,6 +918,9 @@ static status_t build_response(private_task_manager_t *this, message_t *request)
                /* we don't want to resend messages to sync MIDs if requests with the
                 * previous MID arrive */
                clear_packets(this->responding.packets);
+               /* avoid increasing the expected message ID after handling a message
+                * to sync MIDs with MID 0 */
+               return NEED_MORE;
        }
 
        array_compress(this->passive_tasks);
index 9967697..d7de113 100644 (file)
@@ -180,9 +180,7 @@ METHOD(task_t, process, status_t,
        m2 = max(this->send, resp);
        if (resp != m2)
        {
-               /* after responding to this message the expected message ID is increased
-                * by one so we reduce it here */
-               this->ike_sa->set_message_id(this->ike_sa, FALSE, m2 - 1);
+               this->ike_sa->set_message_id(this->ike_sa, FALSE, m2);
        }
        init = this->ike_sa->get_message_id(this->ike_sa, TRUE);
        p2 = max(this->recv, has_active_tasks(this) ? init + 1 : init);