51 static int DecodePartialIPV4(
Packet* p, uint8_t* partial_packet, uint16_t
len)
55 SCLogDebug(
"DecodePartialIPV4: ICMPV4_IPV4_TRUNC_PKT");
65 SCLogDebug(
"DecodePartialIPV4: ICMPv4 contains Unknown IPV4 version "
66 "ICMPV4_IPV4_UNKNOWN_VER");
88 SCLogDebug(
"DecodePartialIPV4: ICMPV4->IPV4->TCP header sport: "
99 SCLogDebug(
"DecodePartialIPV4: ICMPV4->IPV4->TCP partial header sport: "
103 SCLogDebug(
"DecodePartialIPV4: Warning, ICMPV4->IPV4->TCP "
104 "header Didn't fit in the packet!");
117 SCLogDebug(
"DecodePartialIPV4: ICMPV4->IPV4->UDP header sport: "
121 SCLogDebug(
"DecodePartialIPV4: Warning, ICMPV4->IPV4->UDP "
122 "header Didn't fit in the packet!");
135 SCLogDebug(
"DecodePartialIPV4: ICMPV4->IPV4->ICMP header");
146 SCLogDebug(
"ICMPv4 embedding IPV4 %s->%s - PROTO: %" PRIu32
" ID: %" PRIu32
"", s,d,
169 p->
proto = IPPROTO_ICMP;
175 p->
icmp_d.type = (uint8_t)ctype;
320 ICMPV4RtrAdvert *icmpv4_router_advert = (ICMPV4RtrAdvert *)(pkt +
sizeof(ICMPV4Hdr));
321 uint32_t advert_len = icmpv4_router_advert->naddr *
322 (icmpv4_router_advert->addr_sz *
sizeof(uint32_t));
362 #define CASE_CODE(t,r) case (t): return r; case (r): return t;
381 static int DecodeICMPV4test01(
void)
383 uint8_t raw_icmpv4[] = {
384 0x08, 0x00, 0x78, 0x47, 0xfc, 0x55, 0x00, 0x04,
385 0x52, 0xab, 0x86, 0x4a, 0x84, 0x50, 0x0e, 0x00,
386 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
387 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
388 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
389 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
399 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
401 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
411 ip4h.s_ip_src.s_addr = p->
src.addr_data32[0];
412 ip4h.s_ip_dst.s_addr = p->
dst.addr_data32[0];
432 static int DecodeICMPV4test02(
void)
434 uint8_t raw_icmpv4[] = {
435 0x00, 0x00, 0x57, 0x64, 0xfb, 0x55, 0x00, 0x03,
436 0x43, 0xab, 0x86, 0x4a, 0xf6, 0x49, 0x02, 0x00,
437 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
438 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
439 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
440 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
441 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f };
450 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
461 ip4h.s_ip_src.s_addr = p->
src.addr_data32[0];
462 ip4h.s_ip_dst.s_addr = p->
dst.addr_data32[0];
482 static int DecodeICMPV4test03(
void)
484 uint8_t raw_icmpv4[] = {
485 0x0b, 0x00, 0x6a, 0x3d, 0x00, 0x00, 0x00, 0x00,
486 0x45, 0x00, 0x00, 0x3c, 0x64, 0x15, 0x00, 0x00,
487 0x01, 0x11, 0xde, 0xfd, 0xc0, 0xa8, 0x01, 0x0d,
488 0xd1, 0x55, 0xe3, 0x93, 0x8b, 0x12, 0x82, 0xaa,
489 0x00, 0x28, 0x7c, 0xdd };
498 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
509 ip4h.s_ip_src.s_addr = p->
src.addr_data32[0];
510 ip4h.s_ip_dst.s_addr = p->
dst.addr_data32[0];
516 printf(
"NULL == p->icmpv4h: ");
522 printf(
"p->icmpv4h->type %u, p->icmpv4h->code %u: ",
530 printf(
"p->icmpv4vars.emb_sport %u, p->icmpv4vars.emb_dport %u: ",
542 if (strcmp(s,
"192.168.1.13") == 0 && strcmp(d,
"209.85.227.147") == 0) {
546 printf(
"s %s, d %s: ", s, d);
559 static int DecodeICMPV4test04(
void)
561 uint8_t raw_icmpv4[] = {
562 0x03, 0x0a, 0x36, 0xc3, 0x00, 0x00, 0x00, 0x00,
563 0x45, 0x00, 0x00, 0x3c, 0x62, 0xee, 0x40, 0x00,
564 0x33, 0x06, 0xb4, 0x8f, 0xc0, 0xa8, 0x01, 0x0d,
565 0x58, 0x60, 0x16, 0x29, 0xb1, 0x0a, 0x00, 0x32,
566 0x3e, 0x36, 0x38, 0x7c, 0x00, 0x00, 0x00, 0x00,
567 0xa0, 0x02, 0x16, 0xd0, 0x72, 0x04, 0x00, 0x00,
568 0x02, 0x04, 0x05, 0x8a, 0x04, 0x02, 0x08, 0x0a };
577 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
588 ip4h.s_ip_src.s_addr = p->
src.addr_data32[0];
589 ip4h.s_ip_dst.s_addr = p->
dst.addr_data32[0];
616 if (strcmp(s,
"192.168.1.13") == 0 && strcmp(d,
"88.96.22.41") == 0) {
630 static int DecodeICMPV4test05(
void)
632 uint8_t raw_icmpv4[] = {
633 0x0b, 0x00, 0x5c, 0x46, 0x00, 0x00, 0x00, 0x00, 0x45,
634 0x00, 0x00, 0x30, 0x02, 0x17, 0x40, 0x00, 0x01, 0x06,
635 0xd6, 0xbd, 0xc0, 0xa8, 0x02, 0x05, 0x3d, 0x23, 0xa1,
636 0x23, 0x04, 0x18, 0x00, 0x50, 0xd2, 0x08, 0xc2, 0x48,
646 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
657 ip4h.s_ip_src.s_addr = p->
src.addr_data32[0];
658 ip4h.s_ip_dst.s_addr = p->
dst.addr_data32[0];
685 if (strcmp(s,
"192.168.2.5") == 0 && strcmp(d,
"61.35.161.35") == 0) {
695 static int ICMPV4CalculateValidChecksumtest05(
void)
699 uint8_t raw_icmpv4[] = {
700 0x08, 0x00, 0xab, 0x9b, 0x7f, 0x2b, 0x05, 0x2c,
701 0x3f, 0x72, 0x93, 0x4a, 0x00, 0x4d, 0x0a, 0x00,
702 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
703 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
704 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
705 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
706 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
707 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37};
709 csum = *( ((uint16_t *)raw_icmpv4) + 1);
710 return (csum == ICMPV4CalculateChecksum((uint16_t *)raw_icmpv4,
sizeof(raw_icmpv4)));
713 static int ICMPV4CalculateInvalidChecksumtest06(
void)
717 uint8_t raw_icmpv4[] = {
718 0x08, 0x00, 0xab, 0x9b, 0x7f, 0x2b, 0x05, 0x2c,
719 0x3f, 0x72, 0x93, 0x4a, 0x00, 0x4d, 0x0a, 0x00,
720 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
721 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
722 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
723 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
724 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
725 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x38};
727 csum = *( ((uint16_t *)raw_icmpv4) + 1);
728 return (csum != ICMPV4CalculateChecksum((uint16_t *)raw_icmpv4,
sizeof(raw_icmpv4)));
731 static int ICMPV4InvalidType07(
void)
734 uint8_t raw_icmpv4[] = {
735 0xff, 0x00, 0xab, 0x9b, 0x7f, 0x2b, 0x05, 0x2c,
736 0x3f, 0x72, 0x93, 0x4a, 0x00, 0x4d, 0x0a, 0x00,
737 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
738 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
739 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
740 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
741 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
742 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x38};
752 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
763 ip4h.s_ip_src.s_addr = p->
src.addr_data32[0];
764 ip4h.s_ip_dst.s_addr = p->
dst.addr_data32[0];
782 static int DecodeICMPV4test08(
void)
784 uint8_t raw_icmpv4[] = {
785 0x08, 0x00, 0x78, 0x47, 0xfc, 0x55, 0x00, 0x00
795 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
806 ip4h.s_ip_src.s_addr = p->
src.addr_data32[0];
807 ip4h.s_ip_dst.s_addr = p->
dst.addr_data32[0];
836 ICMPV4CalculateValidChecksumtest05);
838 ICMPV4CalculateInvalidChecksumtest06);