Support IKEv1 SPIs in IKEv1 delete payload
authorMartin Willi <martin@revosec.ch>
Tue, 13 Dec 2011 10:08:53 +0000 (11:08 +0100)
committerMartin Willi <martin@revosec.ch>
Tue, 20 Mar 2012 16:31:19 +0000 (17:31 +0100)
src/libcharon/encoding/payloads/delete_payload.c
src/libcharon/encoding/payloads/delete_payload.h

index 79070a7..3222e9f 100644 (file)
@@ -272,6 +272,16 @@ METHOD(delete_payload_t, add_spi, void,
        }
 }
 
+METHOD(delete_payload_t, set_ike_spi, void,
+       private_delete_payload_t *this, u_int64_t spi_i, u_int64_t spi_r)
+{
+       free(this->spis.ptr);
+       this->spis = chunk_cat("cc", chunk_from_thing(spi_i),
+                                                                chunk_from_thing(spi_r));
+       this->spi_count = 1;
+       this->payload_length = get_header_length(this) + this->spi_size;
+}
+
 /**
  * SPI enumerator implementation
  */
@@ -342,16 +352,27 @@ delete_payload_t *delete_payload_create(payload_type_t type,
                        },
                        .get_protocol_id = _get_protocol_id,
                        .add_spi = _add_spi,
+                       .set_ike_spi = _set_ike_spi,
                        .create_spi_enumerator = _create_spi_enumerator,
                        .destroy = _destroy,
                },
                .next_payload = NO_PAYLOAD,
-               .doi = IKEV1_DOI_IPSEC,
                .protocol_id = protocol_id,
-               .spi_size = protocol_id == PROTO_AH || protocol_id == PROTO_ESP ? 4 : 0,
                .type = type,
        );
        this->payload_length = get_header_length(this);
 
+       if (type == DELETE_V1)
+       {
+               if (protocol_id == PROTO_IKE)
+               {
+                       this->spi_size = 16;
+               }
+               else
+               {
+                       this->doi = IKEV1_DOI_IPSEC,
+                       this->spi_size = 4;
+               }
+       }
        return &this->public;
 }
index 0ee0d4f..afce1ec 100644 (file)
@@ -53,6 +53,14 @@ struct delete_payload_t {
        void (*add_spi) (delete_payload_t *this, u_int32_t spi);
 
        /**
+        * Set the IKE SPIs for an IKEv1 delete.
+        *
+        * @param spi_i                 initiator SPI
+        * @param spi_r                 responder SPI
+        */
+       void (*set_ike_spi)(delete_payload_t *this, u_int64_t spi_i, u_int64_t spi_r);
+
+       /**
         * Get an enumerator over the SPIs in network order.
         *
         * @return                              enumerator over SPIs, u_int32_t