2626#include <netinet/ip.h>
2727#endif
2828
29+
2930#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_UNKNOWN
3031
3132#include "ndpi_config.h"
@@ -7715,8 +7716,14 @@ static void ndpi_enabled_callbacks_init(struct ndpi_detection_module_struct *ndp
77157716 * nxt_hdr: first byte of the layer 4 packet
77167717 * returns 0 upon success and 1 upon failure
77177718 */
7718- int ndpi_handle_ipv6_extension_headers (u_int16_t l3len , const u_int8_t * * l4ptr ,
7719+ int ndpi_handle_ipv6_extension_headers (struct ndpi_detection_module_struct * ndpi_str ,
7720+ const struct ndpi_ipv6hdr * ip6h ,
7721+ u_int16_t l3len , const u_int8_t * * l4ptr ,
77197722 u_int16_t * l4len , u_int8_t * nxt_hdr ) {
7723+ #ifndef HAVE_USDT
7724+ __ndpi_unused_param (ip6h );
7725+ #endif
7726+
77207727 while (l3len > 1 && (* nxt_hdr == 0 || * nxt_hdr == 43 || * nxt_hdr == 44 || * nxt_hdr == 60 || * nxt_hdr == 135 || * nxt_hdr == 59 )) {
77217728 u_int16_t ehdr_len , frag_offset ;
77227729
@@ -7736,6 +7743,16 @@ int ndpi_handle_ipv6_extension_headers(u_int16_t l3len, const u_int8_t **l4ptr,
77367743 }
77377744 l3len -= 5 ;
77387745
7746+ if (ndpi_str ) {
7747+ uint16_t offlg = ntohs (* (u_int16_t * )((* l4ptr ) + 2 ));
7748+ if ((offlg & 0xfff8 ) != 0 || (offlg & 0x0001 ) != 0 ) {
7749+ NDPI_LOG_DBG (ndpi_str , "IP(v6) fragment\n" );
7750+
7751+ NDPI_DTRACE1 (fragment_ipv6 ,
7752+ ip6h /* IPV6 header */ );
7753+ }
7754+ }
7755+
77397756 * nxt_hdr = (* l4ptr )[0 ];
77407757 frag_offset = ntohs (* (u_int16_t * )((* l4ptr ) + 2 )) >> 3 ;
77417758 // Handle ipv6 fragments as the ipv4 ones: keep the first fragment, drop the others
@@ -7777,12 +7794,22 @@ int ndpi_handle_ipv6_extension_headers(u_int16_t l3len, const u_int8_t **l4ptr,
77777794/* ******************************************************************** */
77787795
77797796/* Used by dns.c */
7780- u_int8_t iph_is_valid_and_not_fragmented (const struct ndpi_iphdr * iph , const u_int16_t ipsize ) {
7797+ u_int8_t iph_is_valid_and_not_fragmented (struct ndpi_detection_module_struct * ndpi_str ,
7798+ const struct ndpi_iphdr * iph , const u_int16_t ipsize ) {
77817799 /*
77827800 returned value:
77837801 0: fragmented
77847802 1: not fragmented
77857803 */
7804+
7805+ if ((ntohs (iph -> frag_off ) & 0x2000 ) ||
7806+ (ntohs (iph -> frag_off ) & 0x1fff )) {
7807+ NDPI_LOG_DBG (ndpi_str , "IP(v4) fragment\n" );
7808+
7809+ NDPI_DTRACE1 (fragment_ipv4 ,
7810+ iph /* IPV4 header */ );
7811+ }
7812+
77867813 //#ifdef REQUIRE_FULL_PACKETS
77877814
77887815 if (iph -> protocol == IPPROTO_UDP ) {
@@ -7844,7 +7871,7 @@ static u_int8_t ndpi_detection_get_l4_internal(struct ndpi_detection_module_stru
78447871 }
78457872
78467873 /* 0: fragmented; 1: not fragmented */
7847- if (iph != NULL && iph_is_valid_and_not_fragmented (iph , l3_len )) {
7874+ if (iph != NULL && iph_is_valid_and_not_fragmented (ndpi_str , iph , l3_len )) {
78487875 u_int16_t len = ndpi_min (ntohs (iph -> tot_len ), l3_len );
78497876 u_int16_t hlen = (iph -> ihl * 4 );
78507877
@@ -7863,7 +7890,7 @@ static u_int8_t ndpi_detection_get_l4_internal(struct ndpi_detection_module_stru
78637890 l4protocol = iph_v6 -> ip6_hdr .ip6_un1_nxt ;
78647891
78657892 // we need to handle IPv6 extension headers if present
7866- if (ndpi_handle_ipv6_extension_headers (l3_len - sizeof (struct ndpi_ipv6hdr ), & l4ptr , & l4len , & l4protocol ) != 0 ) {
7893+ if (ndpi_handle_ipv6_extension_headers (ndpi_str , iph_v6 , l3_len - sizeof (struct ndpi_ipv6hdr ), & l4ptr , & l4len , & l4protocol ) != 0 ) {
78677894 return (1 );
78687895 }
78697896
0 commit comments