diff --git a/src/packet/packet_parse.cpp b/src/packet/packet_parse.cpp index 88fc6a5..d334ebf 100644 --- a/src/packet/packet_parse.cpp +++ b/src/packet/packet_parse.cpp @@ -498,7 +498,15 @@ static inline const char *parse_ipv4(struct packet *pkt, const char *data, uint1 { return data; } + const struct ip *hdr = (const struct ip *)data; + uint8_t version = ip4_hdr_get_version(hdr); + if (unlikely(version != 4)) + { + PACKET_PARSE_LOG_ERROR("packet %p ipv4 version %d != 4", pkt, version); + return data; + } + uint16_t hdr_len = ip4_hdr_get_hdr_len(hdr); if (unlikely(hdr_len > len)) { @@ -565,6 +573,13 @@ static inline const char *parse_ipv6(struct packet *pkt, const char *data, uint1 return data; } const struct ip6_hdr *hdr = (const struct ip6_hdr *)data; + uint8_t version = ip6_hdr_get_version(hdr); + if (unlikely(version != 6)) + { + PACKET_PARSE_LOG_ERROR("packet %p ipv6 version %d != 6", pkt, version); + return data; + } + uint16_t pld_len = ip6_hdr_get_payload_len(hdr); if (unlikely(pld_len + sizeof(struct ip6_hdr) > len)) {