Handle incoming delete messages
authorClavister OpenSource <opensource@clavister.com>
Wed, 7 Dec 2011 12:30:53 +0000 (13:30 +0100)
committerClavister OpenSource <opensource@clavister.com>
Tue, 20 Mar 2012 16:31:13 +0000 (17:31 +0100)
src/libcharon/encoding/message.c
src/libcharon/sa/task_manager_v1.c
src/libcharon/sa/tasks/child_delete.c [changed mode: 0644->0755]
src/libcharon/sa/tasks/ike_delete.c [changed mode: 0644->0755]

index 5b79ac7..91131ad 100755 (executable)
@@ -591,6 +591,27 @@ static payload_order_t informational_i_order_v1[] = {
 };
 
 /**
+ * Message rule for INFORMATIONAL_V1 from responder.
+ */
+static payload_rule_t informational_r_rules_v1[] = {
+/*     payload type                            min     max                                             encr    suff */
+       {NOTIFY_V1,                                     0,      MAX_NOTIFY_PAYLOADS,    FALSE,  FALSE},
+       {NOTIFY_V1,                                     0,      MAX_NOTIFY_PAYLOADS,    TRUE,   FALSE},
+       {DELETE_V1,                                     0,      MAX_DELETE_PAYLOADS,    TRUE,   FALSE},
+       {VENDOR_ID_V1,                          0,      MAX_VID_PAYLOADS,               TRUE,   FALSE},
+};
+
+/**
+ * payload order for INFORMATIONAL_V1 from responder.
+ */
+static payload_order_t informational_r_order_v1[] = {
+/*     payload type                            notify type */
+       {NOTIFY_V1,                                     0},
+       {DELETE_V1,                                     0},
+       {VENDOR_ID_V1,                          0},
+};
+
+/**
  * Message rule for QUICK_MODE from initiator.
  */
 static payload_rule_t quick_mode_i_rules[] = {
@@ -737,6 +758,10 @@ static message_rule_t message_rules[] = {
                countof(informational_i_rules_v1), informational_i_rules_v1,
                countof(informational_i_order_v1), informational_i_order_v1,
        },
+       {INFORMATIONAL_V1,      FALSE,  TRUE,
+               countof(informational_r_rules_v1), informational_r_rules_v1,
+               countof(informational_r_order_v1), informational_r_order_v1,
+       },
        {QUICK_MODE,            TRUE,   TRUE,
                countof(quick_mode_i_rules), quick_mode_i_rules,
                countof(quick_mode_i_order), quick_mode_i_order,
index 3d8229c..a196b2a 100755 (executable)
 #include <math.h>
 
 #include <daemon.h>
+#include <sa/tasks/child_delete.h>
 #include <sa/tasks/main_mode.h>
 #include <sa/tasks/quick_mode.h>
 #include <sa/tasks/xauth_request.h>
+#include <sa/tasks/ike_delete.h>
 #include <sa/tasks/ike_natd_v1.h>
 #include <sa/tasks/ike_vendor_v1.h>
 #include <sa/tasks/ike_cert_pre_v1.h>
 #include <sa/tasks/ike_cert_post_v1.h>
+#include <encoding/payloads/delete_payload.h>
 #include <processing/jobs/retransmit_job.h>
 #include <processing/jobs/delete_ike_sa_job.h>
 
@@ -546,7 +549,19 @@ static status_t process_request(private_task_manager_t *this,
                                                }
                                                case DELETE_V1:
                                                {
-                                                       /* TODO-IKEv1: Delete payload handling. */
+                                                       delete_payload_t *delete;
+                                                       delete = (delete_payload_t*)payload;
+
+                                                       if (delete->get_protocol_id(delete) == PROTO_IKE)
+                                                       {
+                                                               task = (task_t*)ike_delete_create(this->ike_sa,
+                                                                       FALSE);
+                                                       }
+                                                       else
+                                                       {
+                                                               task = (task_t*)child_delete_create(this->ike_sa,
+                                                                       PROTO_NONE, 0);
+                                                       }
                                                        break;
                                                }
                                                default:
@@ -554,7 +569,7 @@ static status_t process_request(private_task_manager_t *this,
                                        }
                                        if (task)
                                        {
-                                               break;
+                                               this->passive_tasks->insert_last(this->passive_tasks, task);
                                        }
                                }
                                enumerator->destroy(enumerator);
old mode 100644 (file)
new mode 100755 (executable)
index c5151ab..455e06b
@@ -65,6 +65,11 @@ struct private_child_delete_t {
         * CHILD_SAs which get deleted
         */
        linked_list_t *child_sas;
+
+       /**
+        * CHILD_SAs which get deleted
+        */
+       payload_type_t payload_type;
 };
 
 /**
@@ -87,7 +92,7 @@ static void build_payloads(private_child_delete_t *this, message_t *message)
                        case PROTO_ESP:
                                if (esp == NULL)
                                {
-                                       esp = delete_payload_create(DELETE, PROTO_ESP);
+                                       esp = delete_payload_create(this->payload_type, PROTO_ESP);
                                        message->add_payload(message, (payload_t*)esp);
                                }
                                esp->add_spi(esp, spi);
@@ -97,7 +102,7 @@ static void build_payloads(private_child_delete_t *this, message_t *message)
                        case PROTO_AH:
                                if (ah == NULL)
                                {
-                                       ah = delete_payload_create(DELETE, PROTO_AH);
+                                       ah = delete_payload_create(this->payload_type, PROTO_AH);
                                        message->add_payload(message, (payload_t*)ah);
                                }
                                ah->add_spi(ah, spi);
@@ -127,7 +132,7 @@ static void process_payloads(private_child_delete_t *this, message_t *message)
        payloads = message->create_payload_enumerator(message);
        while (payloads->enumerate(payloads, &payload))
        {
-               if (payload->get_type(payload) == DELETE)
+               if (payload->get_type(payload) == this->payload_type)
                {
                        delete_payload = (delete_payload_t*)payload;
                        protocol = delete_payload->get_protocol_id(delete_payload);
@@ -387,5 +392,14 @@ child_delete_t *child_delete_create(ike_sa_t *ike_sa, protocol_id_t protocol,
                this->public.task.process = _process_r;
                this->initiator = FALSE;
        }
+
+       if (ike_sa->get_version(ike_sa) == IKEV2)
+       {
+               this->payload_type = DELETE;
+       }
+       else
+       {
+               this->payload_type = DELETE_V1;
+       }
        return &this->public;
 }
old mode 100644 (file)
new mode 100755 (executable)
index 29ac872..dccd858
@@ -114,7 +114,15 @@ METHOD(task_t, process_r, status_t,
                case IKE_ESTABLISHED:
                        this->ike_sa->set_state(this->ike_sa, IKE_DELETING);
                        this->ike_sa->reestablish(this->ike_sa);
-                       return NEED_MORE;
+                       if (this->ike_sa->get_version(this->ike_sa) == IKEV2)
+                       {
+                               return NEED_MORE;
+                       }
+                       else
+                       {
+                               /* Dont send message to other side */
+                               return DESTROY_ME;
+                       }
                case IKE_REKEYING:
                        this->rekeyed = TRUE;
                        break;