- parsing notify messge
authorMartin Willi <martin@strongswan.org>
Tue, 15 Nov 2005 16:18:02 +0000 (16:18 -0000)
committerMartin Willi <martin@strongswan.org>
Tue, 15 Nov 2005 16:18:02 +0000 (16:18 -0000)
- tested

Source/charon/parser.c
Source/charon/payloads/payload.c
Source/charon/testcases/parser_test.c
Source/charon/testcases/parser_test.h
Source/charon/testcases/testcases.c

index fc034c5..541ef2c 100644 (file)
@@ -750,6 +750,16 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ
                                }               
                                break;                  
                        }
+                       case NOTIFICATION_DATA:
+                       {
+                               size_t notify_length = payload_length - 8 - spi_size;
+                               if (this->parse_chunk(this, rule_number, output + rule->offset, notify_length) != SUCCESS) 
+                               {
+                                       pld->destroy(pld);
+                                       return PARSE_ERROR;
+                               }               
+                               break;                  
+                       }
                        default:
                        {
                                this->logger->log(this->logger, ERROR, "  no rule to parse rule %d %s (%d)", rule_number, mapping_find(encoding_type_t_mappings, rule->type), rule->type);
index f044138..90e8cc9 100644 (file)
@@ -28,6 +28,7 @@
 #include "sa_payload.h"
 #include "nonce_payload.h"
 #include "ke_payload.h"
+#include "notify_payload.h"
 
 
 
@@ -82,6 +83,8 @@ payload_t *payload_create(payload_type_t type)
                        return (payload_t*)nonce_payload_create();
                case KEY_EXCHANGE:
                        return (payload_t*)ke_payload_create();
+               case NOTIFY:
+                       return (payload_t*)notify_payload_create();
                default:
                        return NULL;
        }
index 27b5523..bf5cc41 100644 (file)
@@ -32,6 +32,7 @@
 #include "../payloads/sa_payload.h"
 #include "../payloads/nonce_payload.h"
 #include "../payloads/ke_payload.h"
+#include "../payloads/notify_payload.h"
 
 
 extern logger_manager_t *global_logger_manager;
@@ -258,3 +259,49 @@ void test_parser_with_ke_payload(tester_t *tester)
        tester->assert_false(tester,(memcmp(ke_bytes + 8, result.ptr, result.len)), "parsed key data");
        ke_payload->destroy(ke_payload);
 }
+
+
+/*
+ * Described in Header 
+ */
+void test_parser_with_notify_payload(tester_t *tester)
+{
+       parser_t *parser;
+       notify_payload_t *notify_payload;
+       status_t status;
+       chunk_t notify_chunk, result;
+       
+       u_int8_t notify_bytes[] = {
+               0x00,0x00,0x00,0x1C, /* payload header */
+               0x03,0x04,0x00,0x01, 
+                       0x01,0x02,0x03,0x03, /* spi */
+                       0x04,0x05,0x06,0x07, /* noti dati */
+                       0x08,0x09,0x0A,0x2B,
+                       0x0C,0x0D,0x0E,0x0F,
+                       0x0C,0x0D,0x0E,0x0F
+       };
+       
+       notify_chunk.ptr = notify_bytes;
+       notify_chunk.len = sizeof(notify_bytes);
+
+       parser = parser_create(notify_chunk); 
+       tester->assert_true(tester,(parser != NULL), "parser create check");
+       status = parser->parse_payload(parser, NOTIFY, (payload_t**)&notify_payload);
+       tester->assert_true(tester,(status == SUCCESS),"parse_payload call check");
+       tester->assert_true(tester,(parser->destroy(parser) == SUCCESS), "parser destroy call check");
+       
+       if (status != SUCCESS)
+       {
+               return; 
+       }
+       tester->assert_true(tester,(notify_payload->get_protocol_id(notify_payload) == 3), "Protocol id");
+       tester->assert_true(tester,(notify_payload->get_notify_message_type(notify_payload) == 1), "notify message type");
+       
+       result = notify_payload->get_spi(notify_payload);
+       tester->assert_false(tester,(memcmp(notify_bytes + 8, result.ptr, result.len)), "parsed spi");
+       
+       result = notify_payload->get_notification_data(notify_payload);
+       tester->assert_false(tester,(memcmp(notify_bytes + 12, result.ptr, result.len)), "parsed notification data");
+       
+       notify_payload->destroy(notify_payload);
+}
index 6a36f66..52c7ee7 100644 (file)
@@ -33,4 +33,6 @@ void test_parser_with_nonce_payload(tester_t *tester);
 
 void test_parser_with_ke_payload(tester_t *tester);
 
+void test_parser_with_notify_payload(tester_t *tester);
+
 #endif /*PARSER_TEST_H_*/
index a1549fd..7576080 100644 (file)
@@ -152,6 +152,11 @@ test_t parser_test3 = {test_parser_with_nonce_payload, "Parser: nonce payload"};
  */
 test_t parser_test4 = {test_parser_with_ke_payload, "Parser: key exchange payload"};
 
+/**
+ * Parser test for ike notify payload
+ */
+test_t parser_test5 = {test_parser_with_notify_payload, "Parser: notify payload"};
+
 
 /**
  * Test for packet_t
@@ -208,6 +213,8 @@ logger_manager_t *global_logger_manager;
        &parser_test1,
        &parser_test2,
        &parser_test3,
+       &parser_test4,
+       &parser_test5,
        &generator_test3,
        &generator_test4,
        &generator_test5,