]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
ipv6: add support for PAD1
authorVictor Julien <victor@inliniac.net>
Sat, 8 Mar 2014 13:35:56 +0000 (14:35 +0100)
committerVictor Julien <victor@inliniac.net>
Wed, 26 Mar 2014 16:18:19 +0000 (17:18 +0100)
Support PAD1 in IPv6 HOP options header and DST options header.

src/decode-ipv6.c
src/decode-ipv6.h

index 7e08c0eb27a9e08fadea175f5aff254da7e27665..1504ae2a8d9a73b7111320ed6e01ab8c7f6bd357 100644 (file)
@@ -288,6 +288,14 @@ DecodeIPV6ExtHdrs(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt
                 uint16_t offset = 0;
                 while(offset < optslen)
                 {
+                    if (*ptr == IPV6OPT_PAD1)
+                    {
+                        padn_cnt++;
+                        offset++;
+                        ptr++;
+                        continue;
+                    }
+
                     if (*ptr == IPV6OPT_PADN) /* PadN */
                     {
                         //printf("PadN option\n");
@@ -849,6 +857,59 @@ end:
     return result;
 }
 
+/**
+ * \test HOP header decode
+ */
+static int DecodeIPV6HopTest01 (void)
+{
+    uint8_t raw_pkt1[] = {
+        0x60,0x00,0x00,0x00,0x00,0x20,0x00,0x01,0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
+        0x02,0x0f,0xfe,0xff,0xfe,0x98,0x3d,0x01,0xff,0x02,0x00,0x00,0x00,0x00,0x00,0x00,
+        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x3a,0x00,0x05,0x02,0x00,0x00,0x00,0x00,
+        0x82,0x00,0x1c,0x6f,0x27,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
+    };
+    Packet *p1 = PacketGetFromAlloc();
+    if (unlikely(p1 == NULL))
+        return 0;
+    ThreadVars tv;
+    DecodeThreadVars dtv;
+    int result = 0;
+    PacketQueue pq;
+
+    FlowInitConfig(FLOW_QUIET);
+
+    memset(&pq, 0, sizeof(PacketQueue));
+    memset(&tv, 0, sizeof(ThreadVars));
+    memset(&dtv, 0, sizeof(DecodeThreadVars));
+
+    PacketCopyData(p1, raw_pkt1, sizeof(raw_pkt1));
+
+    DecodeIPV6(&tv, &dtv, p1, GET_PKT_DATA(p1), GET_PKT_LEN(p1), &pq);
+
+    if (!(IPV6_EXTHDR_ISSET_HH(p1))) {
+        printf("ipv6 routing header not detected: ");
+        goto end;
+    }
+
+    if (p1->ip6eh.ip6_exthdrs[0].len != 8) {
+        printf("ipv6 routing length incorrect: ");
+        goto end;
+    }
+
+    if (ENGINE_ISSET_EVENT(p1, IPV6_HOPOPTS_UNKNOWN_OPT)) {
+        printf("engine event IPV6_HOPOPTS_UNKNOWN_OPT set: ");
+        goto end;
+    }
+
+    result = 1;
+end:
+    PACKET_RECYCLE(p1);
+    SCFree(p1);
+    FlowShutdown();
+    return result;
+}
+
 #endif /* UNITTESTS */
 
 /**
@@ -859,6 +920,7 @@ void DecodeIPV6RegisterTests(void) {
 #ifdef UNITTESTS
     UtRegisterTest("DecodeIPV6FragTest01", DecodeIPV6FragTest01, 1);
     UtRegisterTest("DecodeIPV6RouteTest01", DecodeIPV6RouteTest01, 1);
+    UtRegisterTest("DecodeIPV6HopTest01", DecodeIPV6HopTest01, 1);
 #endif /* UNITTESTS */
 }
 
index 61d2c37a48a54e67a431cb6b2d4acf3d3b8b727b..9833e831a0d8f14f44cee127686019109e2c45e8 100644 (file)
@@ -184,6 +184,7 @@ typedef struct IPV6RouteHdr_
 /* Hop-by-Hop header and Destination Options header use options that are
  * defined here. */
 
+#define IPV6OPT_PAD1                  0x00
 #define IPV6OPT_PADN                  0x01
 #define IPV6OPT_RA                    0x05
 #define IPV6OPT_JUMBO                 0xC2