From 1195f882b92e8f65f14d350bf4c36bcc867885a9 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Sat, 8 Mar 2014 14:35:56 +0100 Subject: [PATCH] ipv6: add support for PAD1 Support PAD1 in IPv6 HOP options header and DST options header. --- src/decode-ipv6.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++ src/decode-ipv6.h | 1 + 2 files changed, 63 insertions(+) diff --git a/src/decode-ipv6.c b/src/decode-ipv6.c index 7e08c0eb27..1504ae2a8d 100644 --- a/src/decode-ipv6.c +++ b/src/decode-ipv6.c @@ -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 */ } diff --git a/src/decode-ipv6.h b/src/decode-ipv6.h index 61d2c37a48..9833e831a0 100644 --- a/src/decode-ipv6.h +++ b/src/decode-ipv6.h @@ -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