adapted state_machine for retry batches
authorAndreas Steffen <andreas.steffen@strongswan.org>
Sun, 8 May 2011 22:49:36 +0000 (00:49 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Sun, 8 May 2011 22:49:36 +0000 (00:49 +0200)
src/libcharon/plugins/tnccs_20/state_machine/pb_tnc_state_machine.c
src/libcharon/plugins/tnccs_20/tnccs_20.c

index a46dc0a..f0cf14a 100644 (file)
@@ -107,7 +107,8 @@ METHOD(pb_tnc_state_machine_t, receive_batch, bool,
                        }
                        return FALSE;
                case PB_STATE_SERVER_WORKING:
-                       if (!this->is_server && type == PB_BATCH_SDATA)
+                       if (!this->is_server && (type == PB_BATCH_SDATA ||
+                                                                        type == PB_BATCH_SRETRY))
                        {
                                this->state = PB_STATE_CLIENT_WORKING;
                                break;
@@ -117,8 +118,7 @@ METHOD(pb_tnc_state_machine_t, receive_batch, bool,
                                this->state = PB_STATE_DECIDED;
                                break;
                        }
-                       if ((this->is_server && type == PB_BATCH_CRETRY) ||
-                          (!this->is_server && type == PB_BATCH_SRETRY))
+                       if (this->is_server && type == PB_BATCH_CRETRY)
                        {
                                break;
                        }
@@ -198,7 +198,8 @@ METHOD(pb_tnc_state_machine_t, send_batch, bool,
                        }
                        return FALSE;
                case PB_STATE_SERVER_WORKING:
-                       if (this->is_server && type == PB_BATCH_SDATA)
+                       if (this->is_server && (type == PB_BATCH_SDATA ||
+                                                                       type == PB_BATCH_SRETRY))
                        {
                                this->state = PB_STATE_CLIENT_WORKING;
                                break;
@@ -208,7 +209,7 @@ METHOD(pb_tnc_state_machine_t, send_batch, bool,
                                this->state = PB_STATE_DECIDED;
                                break;
                        }
-                       if (this->is_server && type == PB_BATCH_SRETRY)
+                       if (!this->is_server && type == PB_BATCH_CRETRY)
                        {
                                break;
                        }
@@ -219,11 +220,16 @@ METHOD(pb_tnc_state_machine_t, send_batch, bool,
                        }
                        return FALSE;
                case PB_STATE_CLIENT_WORKING:
-                       if (!this->is_server && type == PB_BATCH_CDATA)
+                       if (!this->is_server && (type == PB_BATCH_CDATA ||
+                                                                        type == PB_BATCH_CRETRY))
                        {
                                this->state = PB_STATE_SERVER_WORKING;
                                break;
                        }
+                       if (this->is_server && type == PB_BATCH_SRETRY)
+                       {
+                               break;
+                       }
                        if (type == PB_BATCH_CLOSE)
                        {
                                this->state = PB_STATE_END;
index 0bf2419..636f525 100644 (file)
@@ -289,14 +289,21 @@ static void handle_message(private_tnccs_20_t *this, pb_tnc_msg_t *msg)
  */
 static void build_retry_batch(private_tnccs_20_t *this)
 {
+       pb_tnc_batch_type_t batch_retry_type;
+
+       batch_retry_type = this->is_server ? PB_BATCH_SRETRY : PB_BATCH_CRETRY;
        if (this->batch)
        {
+               if (this->batch->get_type(this->batch) == batch_retry_type)
+               {
+                       /* retry batch has already been created */
+                       return;
+               }
                DBG1(DBG_TNC, "cancelling PB-TNC %N batch",
                        pb_tnc_batch_type_names, this->batch->get_type(this->batch));
                this->batch->destroy(this->batch);
         }
-       this->batch = pb_tnc_batch_create(this->is_server,
-                                               this->is_server ? PB_BATCH_SRETRY : PB_BATCH_CRETRY);
+       this->batch = pb_tnc_batch_create(this->is_server, batch_retry_type);
 }
 
 METHOD(tls_t, process, status_t,
@@ -465,6 +472,7 @@ METHOD(tls_t, build, status_t,
        private_tnccs_20_t *this, void *buf, size_t *buflen, size_t *msglen)
 {
        status_t status;
+       pb_tnc_state_t state;
 
        /* Initialize the connection */
        if (!this->is_server && !this->connection_id)
@@ -496,8 +504,9 @@ METHOD(tls_t, build, status_t,
                charon->imcs->begin_handshake(charon->imcs, this->connection_id);
        }
 
-       if (this->is_server && this->fatal_error &&
-               this->state_machine->get_state(this->state_machine) == PB_STATE_END)
+       state = this->state_machine->get_state(this->state_machine);
+
+       if (this->is_server && this->fatal_error && state == PB_STATE_END)
        {
                DBG1(DBG_TNC, "a fatal PB-TNC error occurred, terminating connection");
                return FAILED;
@@ -508,7 +517,10 @@ METHOD(tls_t, build, status_t,
 
        if (this->request_handshake_retry)
        {
-               build_retry_batch(this);
+               if (state != PB_STATE_INIT)
+               {
+                       build_retry_batch(this);
+               }
 
                /* Reset the flag for the next handshake retry request */
                this->request_handshake_retry = FALSE;
@@ -516,9 +528,6 @@ METHOD(tls_t, build, status_t,
 
        if (!this->batch)
        {
-               pb_tnc_state_t state;
-
-               state = this->state_machine->get_state(this->state_machine);
                if (this->is_server)
                {
                        if (state == PB_STATE_SERVER_WORKING)