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");
72 const uint8_t *icmpv4_ptr = (
const uint8_t *)p->
l4.
hdrs.
icmpv4h;
85 SCLogDebug(
"DecodePartialIPV4: ICMPV4->IPV4->TCP header sport: "
86 "%" PRIu16
" dport %" PRIu16
"",
95 SCLogDebug(
"DecodePartialIPV4: ICMPV4->IPV4->TCP partial header sport: "
96 "%" PRIu16
" dport %" PRIu16
"",
99 SCLogDebug(
"DecodePartialIPV4: Warning, ICMPV4->IPV4->TCP "
100 "header Didn't fit in the packet!");
114 SCLogDebug(
"DecodePartialIPV4: ICMPV4->IPV4->UDP header sport: "
115 "%" PRIu16
" dport %" PRIu16
"",
118 SCLogDebug(
"DecodePartialIPV4: Warning, ICMPV4->IPV4->UDP "
119 "header Didn't fit in the packet!");
131 SCLogDebug(
"DecodePartialIPV4: ICMPV4->IPV4->ICMP header");
152 ICMPV4Hdr *icmpv4h = PacketSetICMPv4(p, pkt);
156 p->
proto = IPPROTO_ICMP;
158 const uint8_t code = p->
icmp_s.code = icmpv4h->
code;
162 p->
icmp_d.type = (uint8_t)ctype;
306 ICMPV4RtrAdvert *icmpv4_router_advert = (ICMPV4RtrAdvert *)(pkt +
sizeof(
ICMPV4Hdr));
307 uint32_t advert_len = icmpv4_router_advert->naddr *
308 (icmpv4_router_advert->addr_sz *
sizeof(uint32_t));
347 #define CASE_CODE(t,r) case (t): return r; case (r): return t;
366 static int DecodeICMPV4test01(
void)
368 uint8_t raw_icmpv4[] = {
369 0x08, 0x00, 0x78, 0x47, 0xfc, 0x55, 0x00, 0x04,
370 0x52, 0xab, 0x86, 0x4a, 0x84, 0x50, 0x0e, 0x00,
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,
374 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
382 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
384 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
394 ip4h.s_ip_src.s_addr = p->
src.addr_data32[0];
395 ip4h.s_ip_dst.s_addr = p->
dst.addr_data32[0];
401 const ICMPV4Hdr *icmpv4h = PacketGetICMPv4(p);
416 static int DecodeICMPV4test02(
void)
418 uint8_t raw_icmpv4[] = {
419 0x00, 0x00, 0x57, 0x64, 0xfb, 0x55, 0x00, 0x03,
420 0x43, 0xab, 0x86, 0x4a, 0xf6, 0x49, 0x02, 0x00,
421 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
422 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
423 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
424 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
425 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f };
432 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
443 ip4h.s_ip_src.s_addr = p->
src.addr_data32[0];
444 ip4h.s_ip_dst.s_addr = p->
dst.addr_data32[0];
450 const ICMPV4Hdr *icmpv4h = PacketGetICMPv4(p);
465 static int DecodeICMPV4test03(
void)
467 uint8_t raw_icmpv4[] = {
468 0x0b, 0x00, 0x6a, 0x3d, 0x00, 0x00, 0x00, 0x00,
469 0x45, 0x00, 0x00, 0x3c, 0x64, 0x15, 0x00, 0x00,
470 0x01, 0x11, 0xde, 0xfd, 0xc0, 0xa8, 0x01, 0x0d,
471 0xd1, 0x55, 0xe3, 0x93, 0x8b, 0x12, 0x82, 0xaa,
472 0x00, 0x28, 0x7c, 0xdd };
479 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
490 ip4h.s_ip_src.s_addr = p->
src.addr_data32[0];
491 ip4h.s_ip_dst.s_addr = p->
dst.addr_data32[0];
497 const ICMPV4Hdr *icmpv4h = PacketGetICMPv4(p);
512 PrintInet(AF_INET, &src_ip, s,
sizeof(s));
513 PrintInet(AF_INET, &dst_ip, d,
sizeof(d));
528 static int DecodeICMPV4test04(
void)
530 uint8_t raw_icmpv4[] = {
531 0x03, 0x0a, 0x36, 0xc3, 0x00, 0x00, 0x00, 0x00,
532 0x45, 0x00, 0x00, 0x3c, 0x62, 0xee, 0x40, 0x00,
533 0x33, 0x06, 0xb4, 0x8f, 0xc0, 0xa8, 0x01, 0x0d,
534 0x58, 0x60, 0x16, 0x29, 0xb1, 0x0a, 0x00, 0x32,
535 0x3e, 0x36, 0x38, 0x7c, 0x00, 0x00, 0x00, 0x00,
536 0xa0, 0x02, 0x16, 0xd0, 0x72, 0x04, 0x00, 0x00,
537 0x02, 0x04, 0x05, 0x8a, 0x04, 0x02, 0x08, 0x0a };
546 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
557 ip4h.s_ip_src.s_addr = p->
src.addr_data32[0];
558 ip4h.s_ip_dst.s_addr = p->
dst.addr_data32[0];
564 const ICMPV4Hdr *icmpv4h = PacketGetICMPv4(p);
580 PrintInet(AF_INET, &src_ip, s,
sizeof(s));
581 PrintInet(AF_INET, &dst_ip, d,
sizeof(d));
584 if (strcmp(s,
"192.168.1.13") == 0 && strcmp(d,
"88.96.22.41") == 0) {
598 static int DecodeICMPV4test05(
void)
600 uint8_t raw_icmpv4[] = {
601 0x0b, 0x00, 0x5c, 0x46, 0x00, 0x00, 0x00, 0x00, 0x45,
602 0x00, 0x00, 0x30, 0x02, 0x17, 0x40, 0x00, 0x01, 0x06,
603 0xd6, 0xbd, 0xc0, 0xa8, 0x02, 0x05, 0x3d, 0x23, 0xa1,
604 0x23, 0x04, 0x18, 0x00, 0x50, 0xd2, 0x08, 0xc2, 0x48,
614 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
625 ip4h.s_ip_src.s_addr = p->
src.addr_data32[0];
626 ip4h.s_ip_dst.s_addr = p->
dst.addr_data32[0];
632 const ICMPV4Hdr *icmpv4h = PacketGetICMPv4(p);
648 PrintInet(AF_INET, &src_ip, s,
sizeof(s));
649 PrintInet(AF_INET, &dst_ip, d,
sizeof(d));
652 if (strcmp(s,
"192.168.2.5") == 0 && strcmp(d,
"61.35.161.35") == 0) {
662 static int ICMPV4CalculateValidChecksumtest05(
void)
666 uint8_t raw_icmpv4[] = {
667 0x08, 0x00, 0xab, 0x9b, 0x7f, 0x2b, 0x05, 0x2c,
668 0x3f, 0x72, 0x93, 0x4a, 0x00, 0x4d, 0x0a, 0x00,
669 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
670 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
671 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
672 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
673 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
674 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37};
676 csum = *( ((uint16_t *)raw_icmpv4) + 1);
677 return (csum == ICMPV4CalculateChecksum((uint16_t *)raw_icmpv4,
sizeof(raw_icmpv4)));
680 static int ICMPV4CalculateInvalidChecksumtest06(
void)
684 uint8_t raw_icmpv4[] = {
685 0x08, 0x00, 0xab, 0x9b, 0x7f, 0x2b, 0x05, 0x2c,
686 0x3f, 0x72, 0x93, 0x4a, 0x00, 0x4d, 0x0a, 0x00,
687 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
688 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
689 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
690 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
691 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
692 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x38};
694 csum = *( ((uint16_t *)raw_icmpv4) + 1);
695 return (csum != ICMPV4CalculateChecksum((uint16_t *)raw_icmpv4,
sizeof(raw_icmpv4)));
698 static int ICMPV4InvalidType07(
void)
701 uint8_t raw_icmpv4[] = {
702 0xff, 0x00, 0xab, 0x9b, 0x7f, 0x2b, 0x05, 0x2c,
703 0x3f, 0x72, 0x93, 0x4a, 0x00, 0x4d, 0x0a, 0x00,
704 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
705 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
706 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
707 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
708 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
709 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x38};
719 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
730 ip4h.s_ip_src.s_addr = p->
src.addr_data32[0];
731 ip4h.s_ip_dst.s_addr = p->
dst.addr_data32[0];
749 static int DecodeICMPV4test08(
void)
751 uint8_t raw_icmpv4[] = {
752 0x08, 0x00, 0x78, 0x47, 0xfc, 0x55, 0x00, 0x00
760 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
771 ip4h.s_ip_src.s_addr = p->
src.addr_data32[0];
772 ip4h.s_ip_dst.s_addr = p->
dst.addr_data32[0];
778 const ICMPV4Hdr *icmpv4h = PacketGetICMPv4(p);
802 ICMPV4CalculateValidChecksumtest05);
804 ICMPV4CalculateInvalidChecksumtest06);