ndpiReader: print an error msg if we found an unsupported datalink type (#1157)

This commit is contained in:
Ivan Nardi
2021-03-23 11:47:29 +01:00
committed by GitHub
parent b040407683
commit a6029d250d
3 changed files with 32 additions and 2 deletions
+7 -1
View File
@@ -3321,9 +3321,15 @@ static void ndpi_process_packet(u_char *args,
* @brief Call pcap_loop() to process packets from a live capture or savefile
*/
static void runPcapLoop(u_int16_t thread_id) {
if((!shutdown_app) && (ndpi_thread_info[thread_id].workflow->pcap_handle != NULL))
if((!shutdown_app) && (ndpi_thread_info[thread_id].workflow->pcap_handle != NULL)) {
int datalink_type = pcap_datalink(ndpi_thread_info[thread_id].workflow->pcap_handle);
if(!ndpi_is_datalink_supported(datalink_type)) {
printf("Unsupported datalink %d. Skip pcap\n", datalink_type);
return;
}
if(pcap_loop(ndpi_thread_info[thread_id].workflow->pcap_handle, -1, &ndpi_process_packet, (u_char*)&thread_id) < 0)
printf("Error while reading pcap file: '%s'\n", pcap_geterr(ndpi_thread_info[thread_id].workflow->pcap_handle));
}
}
/**
+24 -1
View File
@@ -1541,6 +1541,26 @@ static struct ndpi_proto packet_processing(struct ndpi_workflow * workflow,
return(flow->detected_protocol);
}
int ndpi_is_datalink_supported(int datalink_type)
{
/* Keep in sync with the similar switch in ndpi_workflow_process_packet */
switch(datalink_type) {
case DLT_NULL:
case DLT_PPP_SERIAL:
case DLT_C_HDLC:
case DLT_PPP:
case DLT_IPV4:
case DLT_IPV6:
case DLT_EN10MB:
case DLT_LINUX_SLL:
case DLT_IEEE802_11_RADIO:
case DLT_RAW:
return 1;
default:
return 0;
}
}
/* ****************************************************** */
struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow,
@@ -1623,6 +1643,7 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow,
if(header->caplen < eth_offset + 28)
return(nproto); /* Too short */
/* Keep in sync with ndpi_is_datalink_supported() */
switch(datalink_type) {
case DLT_NULL:
if(ntohl(*((u_int32_t*)&packet[eth_offset])) == 2)
@@ -1737,7 +1758,9 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow,
break;
default:
/* printf("Unknown datalink %d\n", datalink_type); */
/* We shoudn't be here, because we already checked that this datalink is supported.
Should ndpi_is_datalink_supported() be updated? */
printf("Unknown datalink %d\n", datalink_type);
return(nproto);
}
+1
View File
@@ -318,6 +318,7 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow,
const u_char *packet,
FILE * csv_fp);
int ndpi_is_datalink_supported(int datalink_type);
/* flow callbacks for complete detected flow
(ndpi_flow_info will be freed right after) */