diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/include/ndpi_api.h | 4 | ||||
-rw-r--r-- | src/include/ndpi_private.h | 2 | ||||
-rw-r--r-- | src/include/ndpi_typedefs.h | 2 | ||||
-rw-r--r-- | src/lib/ndpi_main.c | 20 |
4 files changed, 20 insertions, 8 deletions
diff --git a/src/include/ndpi_api.h b/src/include/ndpi_api.h index d2ba9816e..edfb497d4 100644 --- a/src/include/ndpi_api.h +++ b/src/include/ndpi_api.h @@ -334,7 +334,7 @@ extern "C" { const unsigned char *packet, const unsigned short packetlen, const u_int64_t packet_time_ms, - const struct ndpi_flow_input_info *input_info); + struct ndpi_flow_input_info *input_info); /** * Processes one packet and returns the ID of the detected protocol. @@ -354,7 +354,7 @@ extern "C" { const unsigned char *packet, const unsigned short packetlen, const u_int64_t packet_time_ms, - const struct ndpi_flow_input_info *input_info); + struct ndpi_flow_input_info *input_info); /** * Get the main protocol of the passed flows for the detected module * diff --git a/src/include/ndpi_private.h b/src/include/ndpi_private.h index 3aa17ed3c..c7eef1e0b 100644 --- a/src/include/ndpi_private.h +++ b/src/include/ndpi_private.h @@ -404,7 +404,7 @@ struct ndpi_detection_module_struct { /* Current packet */ struct ndpi_packet_struct packet; - const struct ndpi_flow_input_info *input_info; + struct ndpi_flow_input_info *input_info; #ifdef HAVE_NBPF u_int8_t num_nbpf_custom_proto; diff --git a/src/include/ndpi_typedefs.h b/src/include/ndpi_typedefs.h index fc0a2cf16..1973bd981 100644 --- a/src/include/ndpi_typedefs.h +++ b/src/include/ndpi_typedefs.h @@ -645,7 +645,7 @@ struct ndpi_gre_basehdr { * Optional information about flow management (per packet) */ struct ndpi_flow_input_info { - unsigned char in_pkt_dir; + unsigned char in_pkt_dir; /* If unknown, the library might *returns* to the application the direction calculated internally */ unsigned char seen_flow_beginning; }; diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index 3e16ca5c1..ef5bab840 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -6804,7 +6804,7 @@ static int ndpi_init_packet(struct ndpi_detection_module_struct *ndpi_str, const u_int64_t current_time_ms, const unsigned char *packet_data, unsigned short packetlen, - const struct ndpi_flow_input_info *input_info) { + struct ndpi_flow_input_info *input_info) { struct ndpi_packet_struct *packet = &ndpi_str->packet; const struct ndpi_iphdr *decaps_iph = NULL; u_int16_t l3len; @@ -7261,6 +7261,14 @@ static void ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_s ndpi_unset_risk(flow, NDPI_UNIDIRECTIONAL_TRAFFIC); /* Clear bit */ } } + + if(ndpi_str->input_info && + ndpi_str->input_info->in_pkt_dir == NDPI_IN_PKT_DIR_UNKNOWN) { + if(current_pkt_from_client_to_server(ndpi_str, flow)) + ndpi_str->input_info->in_pkt_dir = NDPI_IN_PKT_DIR_C_TO_S; + else + ndpi_str->input_info->in_pkt_dir = NDPI_IN_PKT_DIR_S_TO_C; + } } /* ************************************************ */ @@ -7959,7 +7967,7 @@ void ndpi_process_extra_packet(struct ndpi_detection_module_struct *ndpi_str, struct ndpi_flow_struct *flow, const unsigned char *packet_data, const unsigned short packetlen, const u_int64_t current_time_ms, - const struct ndpi_flow_input_info *input_info) { + struct ndpi_flow_input_info *input_info) { if(flow == NULL) return; @@ -8562,7 +8570,7 @@ static ndpi_protocol ndpi_internal_detection_process_packet(struct ndpi_detectio const unsigned char *packet_data, const unsigned short packetlen, const u_int64_t current_time_ms, - const struct ndpi_flow_input_info *input_info) { + struct ndpi_flow_input_info *input_info) { struct ndpi_packet_struct *packet; NDPI_SELECTION_BITMASK_PROTOCOL_SIZE ndpi_selection_packet; u_int32_t num_calls = 0; @@ -8593,6 +8601,10 @@ static ndpi_protocol ndpi_internal_detection_process_packet(struct ndpi_detectio if(ndpi_str->cfg.max_packets_to_process > 0 && flow->num_processed_pkts >= ndpi_str->cfg.max_packets_to_process) { flow->extra_packets_func = NULL; /* To allow ndpi_extra_dissection_possible() to fail */ flow->fail_with_unknown = 1; + /* Let's try to update ndpi_str->input_info->in_pkt_dir even in this case. + * It is quite uncommon, so we are not going to spend a lot of resources here... */ + if(ndpi_init_packet(ndpi_str, flow, current_time_ms, packet_data, packetlen, input_info) == 0) + ndpi_connection_tracking(ndpi_str, flow); return(ret); /* Avoid spending too much time with this flow */ } @@ -8892,7 +8904,7 @@ static ndpi_protocol ndpi_internal_detection_process_packet(struct ndpi_detectio ndpi_protocol ndpi_detection_process_packet(struct ndpi_detection_module_struct *ndpi_str, struct ndpi_flow_struct *flow, const unsigned char *packet_data, const unsigned short packetlen, const u_int64_t current_time_ms, - const struct ndpi_flow_input_info *input_info) { + struct ndpi_flow_input_info *input_info) { ndpi_protocol p = ndpi_internal_detection_process_packet(ndpi_str, flow, packet_data, packetlen, current_time_ms, input_info); |