|
|
|
@ -166,11 +166,16 @@ int DecodeICMPV4(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt,
|
|
|
|
|
SCLogDebug("ICMPV4 TYPE %" PRIu32 " CODE %" PRIu32 "", p->icmpv4h->type, p->icmpv4h->code);
|
|
|
|
|
|
|
|
|
|
p->proto = IPPROTO_ICMP;
|
|
|
|
|
p->type = p->icmpv4h->type;
|
|
|
|
|
p->code = p->icmpv4h->code;
|
|
|
|
|
p->icmp_s.type = p->icmpv4h->type;
|
|
|
|
|
p->icmp_s.code = p->icmpv4h->code;
|
|
|
|
|
p->payload = pkt + ICMPV4_HEADER_LEN;
|
|
|
|
|
p->payload_len = len - ICMPV4_HEADER_LEN;
|
|
|
|
|
|
|
|
|
|
int ctype = ICMPv4GetCounterpart(p->icmp_s.type);
|
|
|
|
|
if (ctype != -1) {
|
|
|
|
|
p->icmp_d.type = (uint8_t)ctype;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ICMPV4ExtHdr* icmp4eh = (ICMPV4ExtHdr*) p->icmpv4h;
|
|
|
|
|
|
|
|
|
|
switch (p->icmpv4h->type)
|
|
|
|
@ -189,18 +194,10 @@ int DecodeICMPV4(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt,
|
|
|
|
|
} else {
|
|
|
|
|
/* parse IP header plus 64 bytes */
|
|
|
|
|
if (len > ICMPV4_HEADER_PKT_OFFSET) {
|
|
|
|
|
if (DecodePartialIPV4(p, (uint8_t *)(pkt + ICMPV4_HEADER_PKT_OFFSET),
|
|
|
|
|
len - ICMPV4_HEADER_PKT_OFFSET ) == 0)
|
|
|
|
|
{
|
|
|
|
|
/* ICMP ICMP_DEST_UNREACH influence TCP/UDP flows */
|
|
|
|
|
if (ICMPV4_DEST_UNREACH_IS_VALID(p)) {
|
|
|
|
|
FlowSetupPacket(p);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
(void)DecodePartialIPV4(p, (uint8_t *)(pkt + ICMPV4_HEADER_PKT_OFFSET),
|
|
|
|
|
len - ICMPV4_HEADER_PKT_OFFSET );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ICMP_SOURCE_QUENCH:
|
|
|
|
@ -304,9 +301,26 @@ int DecodeICMPV4(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt,
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FlowSetupPacket(p);
|
|
|
|
|
return TM_ECODE_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \retval type counterpart type or -1 */
|
|
|
|
|
int ICMPv4GetCounterpart(uint8_t type)
|
|
|
|
|
{
|
|
|
|
|
#define CASE_CODE(t,r) case (t): return r; case (r): return t;
|
|
|
|
|
switch (type) {
|
|
|
|
|
CASE_CODE(ICMP_ECHO, ICMP_ECHOREPLY);
|
|
|
|
|
CASE_CODE(ICMP_TIMESTAMP, ICMP_TIMESTAMPREPLY);
|
|
|
|
|
CASE_CODE(ICMP_INFO_REQUEST, ICMP_INFO_REPLY);
|
|
|
|
|
CASE_CODE(ICMP_ROUTERSOLICIT, ICMP_ROUTERADVERT);
|
|
|
|
|
CASE_CODE(ICMP_ADDRESS, ICMP_ADDRESSREPLY);
|
|
|
|
|
default:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
#undef CASE_CODE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef UNITTESTS
|
|
|
|
|
|
|
|
|
|
/** DecodeICMPV4test01
|
|
|
|
|