50 static int DecodePartialIPV4(
Packet*
p, uint8_t* partial_packet, uint16_t
len)
54 SCLogDebug(
"DecodePartialIPV4: ICMPV4_IPV4_TRUNC_PKT");
64 SCLogDebug(
"DecodePartialIPV4: ICMPv4 contains Unknown IPV4 version "
65 "ICMPV4_IPV4_UNKNOWN_VER");
84 SCLogDebug(
"DecodePartialIPV4: ICMPV4->IPV4->TCP header sport: "
85 "%" PRIu16
" dport %" PRIu16
"",
94 SCLogDebug(
"DecodePartialIPV4: ICMPV4->IPV4->TCP partial header sport: "
95 "%" PRIu16
" dport %" PRIu16
"",
98 SCLogDebug(
"DecodePartialIPV4: Warning, ICMPV4->IPV4->TCP "
99 "header Didn't fit in the packet!");
113 SCLogDebug(
"DecodePartialIPV4: ICMPV4->IPV4->UDP header sport: "
114 "%" PRIu16
" dport %" PRIu16
"",
117 SCLogDebug(
"DecodePartialIPV4: Warning, ICMPV4->IPV4->UDP "
118 "header Didn't fit in the packet!");
130 SCLogDebug(
"DecodePartialIPV4: ICMPV4->IPV4->ICMP header");
157 const uint8_t code =
p->
icmp_s.code = icmpv4h->
code;
161 p->
icmp_d.type = (uint8_t)ctype;
305 ICMPV4RtrAdvert *icmpv4_router_advert = (ICMPV4RtrAdvert *)(pkt +
sizeof(
ICMPV4Hdr));
306 uint32_t advert_len = icmpv4_router_advert->naddr *
307 (icmpv4_router_advert->addr_sz *
sizeof(uint32_t));
346 #define CASE_CODE(t,r) case (t): return r; case (r): return t;
365 static int DecodeICMPV4test01(
void)
367 uint8_t raw_icmpv4[] = {
368 0x08, 0x00, 0x78, 0x47, 0xfc, 0x55, 0x00, 0x04,
369 0x52, 0xab, 0x86, 0x4a, 0x84, 0x50, 0x0e, 0x00,
370 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
371 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
372 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
373 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
381 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
383 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
393 ip4h.s_ip_src.s_addr =
p->
src.addr_data32[0];
394 ip4h.s_ip_dst.s_addr =
p->
dst.addr_data32[0];
400 const ICMPV4Hdr *icmpv4h = PacketGetICMPv4(
p);
415 static int DecodeICMPV4test02(
void)
417 uint8_t raw_icmpv4[] = {
418 0x00, 0x00, 0x57, 0x64, 0xfb, 0x55, 0x00, 0x03,
419 0x43, 0xab, 0x86, 0x4a, 0xf6, 0x49, 0x02, 0x00,
420 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
421 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
422 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
423 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
424 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f };
431 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
442 ip4h.s_ip_src.s_addr =
p->
src.addr_data32[0];
443 ip4h.s_ip_dst.s_addr =
p->
dst.addr_data32[0];
449 const ICMPV4Hdr *icmpv4h = PacketGetICMPv4(
p);
464 static int DecodeICMPV4test03(
void)
466 uint8_t raw_icmpv4[] = {
467 0x0b, 0x00, 0x6a, 0x3d, 0x00, 0x00, 0x00, 0x00,
468 0x45, 0x00, 0x00, 0x3c, 0x64, 0x15, 0x00, 0x00,
469 0x01, 0x11, 0xde, 0xfd, 0xc0, 0xa8, 0x01, 0x0d,
470 0xd1, 0x55, 0xe3, 0x93, 0x8b, 0x12, 0x82, 0xaa,
471 0x00, 0x28, 0x7c, 0xdd };
478 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
489 ip4h.s_ip_src.s_addr =
p->
src.addr_data32[0];
490 ip4h.s_ip_dst.s_addr =
p->
dst.addr_data32[0];
496 const ICMPV4Hdr *icmpv4h = PacketGetICMPv4(
p);
511 PrintInet(AF_INET, &src_ip, s,
sizeof(s));
512 PrintInet(AF_INET, &dst_ip, d,
sizeof(d));
527 static int DecodeICMPV4test04(
void)
529 uint8_t raw_icmpv4[] = {
530 0x03, 0x0a, 0x36, 0xc3, 0x00, 0x00, 0x00, 0x00,
531 0x45, 0x00, 0x00, 0x3c, 0x62, 0xee, 0x40, 0x00,
532 0x33, 0x06, 0xb4, 0x8f, 0xc0, 0xa8, 0x01, 0x0d,
533 0x58, 0x60, 0x16, 0x29, 0xb1, 0x0a, 0x00, 0x32,
534 0x3e, 0x36, 0x38, 0x7c, 0x00, 0x00, 0x00, 0x00,
535 0xa0, 0x02, 0x16, 0xd0, 0x72, 0x04, 0x00, 0x00,
536 0x02, 0x04, 0x05, 0x8a, 0x04, 0x02, 0x08, 0x0a };
545 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
556 ip4h.s_ip_src.s_addr =
p->
src.addr_data32[0];
557 ip4h.s_ip_dst.s_addr =
p->
dst.addr_data32[0];
563 const ICMPV4Hdr *icmpv4h = PacketGetICMPv4(
p);
579 PrintInet(AF_INET, &src_ip, s,
sizeof(s));
580 PrintInet(AF_INET, &dst_ip, d,
sizeof(d));
583 if (strcmp(s,
"192.168.1.13") == 0 && strcmp(d,
"88.96.22.41") == 0) {
597 static int DecodeICMPV4test05(
void)
599 uint8_t raw_icmpv4[] = {
600 0x0b, 0x00, 0x5c, 0x46, 0x00, 0x00, 0x00, 0x00, 0x45,
601 0x00, 0x00, 0x30, 0x02, 0x17, 0x40, 0x00, 0x01, 0x06,
602 0xd6, 0xbd, 0xc0, 0xa8, 0x02, 0x05, 0x3d, 0x23, 0xa1,
603 0x23, 0x04, 0x18, 0x00, 0x50, 0xd2, 0x08, 0xc2, 0x48,
613 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
624 ip4h.s_ip_src.s_addr =
p->
src.addr_data32[0];
625 ip4h.s_ip_dst.s_addr =
p->
dst.addr_data32[0];
631 const ICMPV4Hdr *icmpv4h = PacketGetICMPv4(
p);
647 PrintInet(AF_INET, &src_ip, s,
sizeof(s));
648 PrintInet(AF_INET, &dst_ip, d,
sizeof(d));
651 if (strcmp(s,
"192.168.2.5") == 0 && strcmp(d,
"61.35.161.35") == 0) {
661 static int ICMPV4CalculateValidChecksumtest05(
void)
665 uint8_t raw_icmpv4[] = {
666 0x08, 0x00, 0xab, 0x9b, 0x7f, 0x2b, 0x05, 0x2c,
667 0x3f, 0x72, 0x93, 0x4a, 0x00, 0x4d, 0x0a, 0x00,
668 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
669 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
670 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
671 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
672 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
673 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37};
675 csum = *( ((uint16_t *)raw_icmpv4) + 1);
676 return (csum == ICMPV4CalculateChecksum((uint16_t *)raw_icmpv4,
sizeof(raw_icmpv4)));
679 static int ICMPV4CalculateInvalidChecksumtest06(
void)
683 uint8_t raw_icmpv4[] = {
684 0x08, 0x00, 0xab, 0x9b, 0x7f, 0x2b, 0x05, 0x2c,
685 0x3f, 0x72, 0x93, 0x4a, 0x00, 0x4d, 0x0a, 0x00,
686 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
687 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
688 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
689 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
690 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
691 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x38};
693 csum = *( ((uint16_t *)raw_icmpv4) + 1);
694 return (csum != ICMPV4CalculateChecksum((uint16_t *)raw_icmpv4,
sizeof(raw_icmpv4)));
697 static int ICMPV4InvalidType07(
void)
700 uint8_t raw_icmpv4[] = {
701 0xff, 0x00, 0xab, 0x9b, 0x7f, 0x2b, 0x05, 0x2c,
702 0x3f, 0x72, 0x93, 0x4a, 0x00, 0x4d, 0x0a, 0x00,
703 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
704 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
705 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
706 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
707 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
708 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x38};
718 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
729 ip4h.s_ip_src.s_addr =
p->
src.addr_data32[0];
730 ip4h.s_ip_dst.s_addr =
p->
dst.addr_data32[0];
748 static int DecodeICMPV4test08(
void)
750 uint8_t raw_icmpv4[] = {
751 0x08, 0x00, 0x78, 0x47, 0xfc, 0x55, 0x00, 0x00
759 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
770 ip4h.s_ip_src.s_addr =
p->
src.addr_data32[0];
771 ip4h.s_ip_dst.s_addr =
p->
dst.addr_data32[0];
777 const ICMPV4Hdr *icmpv4h = PacketGetICMPv4(
p);
801 ICMPV4CalculateValidChecksumtest05);
803 ICMPV4CalculateInvalidChecksumtest06);