Added ndpi_get_l4_proto_name() and ndpi_get_l4_proto_info() API calls to print L4 protocol

This commit is contained in:
Luca Deri
2019-10-08 11:35:33 +02:00
parent 4bdbf02c2d
commit 10873bfe35
4 changed files with 68 additions and 14 deletions
+7 -1
View File
@@ -412,9 +412,15 @@ static void help(u_int long_help) {
#endif #endif
if(long_help) { if(long_help) {
NDPI_PROTOCOL_BITMASK all;
printf("\n\nnDPI supported protocols:\n"); printf("\n\nnDPI supported protocols:\n");
printf("%3s %-22s %-12s %s\n", "Id", "Protocol", "Breed", "Category"); printf("%3s %-22s %-8s %-12s %s\n", "Id", "Protocol", "Layer_4", "Breed", "Category");
num_threads = 1; num_threads = 1;
NDPI_BITMASK_SET_ALL(all);
ndpi_set_protocol_detection_bitmask2(ndpi_info_mod, &all);
ndpi_dump_protocols(ndpi_info_mod); ndpi_dump_protocols(ndpi_info_mod);
} }
exit(!long_help); exit(!long_help);
+5 -1
View File
@@ -759,11 +759,15 @@ extern "C" {
struct ndpi_flow_struct *flow, struct ndpi_flow_struct *flow,
ndpi_protocol *ret); ndpi_protocol *ret);
int ndpi_get_custom_category_match(struct ndpi_detection_module_struct *ndpi_struct, int ndpi_get_custom_category_match(struct ndpi_detection_module_struct *ndpi_struct,
char *name_or_ip, u_int name_len, unsigned long *id); char *name_or_ip, u_int name_len, unsigned long *id);
int ndpi_set_detection_preferences(struct ndpi_detection_module_struct *ndpi_mod, int ndpi_set_detection_preferences(struct ndpi_detection_module_struct *ndpi_mod,
ndpi_detection_preference pref, ndpi_detection_preference pref,
int value); int value);
/* Tells to called on what l4 protocol given application protocol can be found */
ndpi_l4_proto_info ndpi_get_l4_proto_info(struct ndpi_detection_module_struct *ndpi_struct, u_int16_t ndpi_proto_id);
const char* ndpi_get_l4_proto_name(ndpi_l4_proto_info proto);
ndpi_proto_defaults_t* ndpi_get_proto_defaults(struct ndpi_detection_module_struct *ndpi_mod); ndpi_proto_defaults_t* ndpi_get_proto_defaults(struct ndpi_detection_module_struct *ndpi_mod);
u_int ndpi_get_ndpi_num_supported_protocols(struct ndpi_detection_module_struct *ndpi_mod); u_int ndpi_get_ndpi_num_supported_protocols(struct ndpi_detection_module_struct *ndpi_mod);
u_int ndpi_get_ndpi_num_custom_protocols(struct ndpi_detection_module_struct *ndpi_mod); u_int ndpi_get_ndpi_num_custom_protocols(struct ndpi_detection_module_struct *ndpi_mod);
+7
View File
@@ -35,6 +35,13 @@ typedef enum {
NDPI_LOG_DEBUG_EXTRA NDPI_LOG_DEBUG_EXTRA
} ndpi_log_level_t; } ndpi_log_level_t;
typedef enum {
ndpi_l4_proto_unknown = 0,
ndpi_l4_proto_tcp_only,
ndpi_l4_proto_udp_only,
ndpi_l4_proto_tcp_and_udp,
} ndpi_l4_proto_info;
/* NDPI_VISIT */ /* NDPI_VISIT */
typedef enum { typedef enum {
ndpi_preorder, ndpi_preorder,
+40 -3
View File
@@ -3374,8 +3374,7 @@ void ndpi_set_protocol_detection_bitmask2(struct ndpi_detection_module_struct *n
for(a = 0; a < ndpi_str->callback_buffer_size; a++) { for(a = 0; a < ndpi_str->callback_buffer_size; a++) {
if((ndpi_str->callback_buffer[a].ndpi_selection_bitmask & (NDPI_SELECTION_BITMASK_PROTOCOL_INT_TCP | if((ndpi_str->callback_buffer[a].ndpi_selection_bitmask & (NDPI_SELECTION_BITMASK_PROTOCOL_INT_TCP |
NDPI_SELECTION_BITMASK_PROTOCOL_INT_UDP | NDPI_SELECTION_BITMASK_PROTOCOL_INT_UDP |
NDPI_SELECTION_BITMASK_PROTOCOL_INT_TCP_OR_UDP)) NDPI_SELECTION_BITMASK_PROTOCOL_INT_TCP_OR_UDP)) == 0
== 0
|| (ndpi_str-> || (ndpi_str->
callback_buffer[a].ndpi_selection_bitmask & NDPI_SELECTION_BITMASK_PROTOCOL_COMPLETE_TRAFFIC) != 0) { callback_buffer[a].ndpi_selection_bitmask & NDPI_SELECTION_BITMASK_PROTOCOL_COMPLETE_TRAFFIC) != 0) {
if(_ndpi_debug_callbacks) NDPI_LOG_DBG2(ndpi_str, if(_ndpi_debug_callbacks) NDPI_LOG_DBG2(ndpi_str,
@@ -5920,8 +5919,9 @@ void ndpi_dump_protocols(struct ndpi_detection_module_struct *ndpi_str) {
int i; int i;
for(i=0; i<(int)ndpi_str->ndpi_num_supported_protocols; i++) for(i=0; i<(int)ndpi_str->ndpi_num_supported_protocols; i++)
printf("%3d %-22s %-12s %s\n", i, printf("%3d %-22s %-8s %-12s %s\n", i,
ndpi_str->proto_defaults[i].protoName, ndpi_str->proto_defaults[i].protoName,
ndpi_get_l4_proto_name(ndpi_get_l4_proto_info(ndpi_str, i)),
ndpi_get_proto_breed_name(ndpi_str, ndpi_str->proto_defaults[i].protoBreed), ndpi_get_proto_breed_name(ndpi_str, ndpi_str->proto_defaults[i].protoBreed),
ndpi_category_get_name(ndpi_str, ndpi_str->proto_defaults[i].protoCategory) ndpi_category_get_name(ndpi_str, ndpi_str->proto_defaults[i].protoCategory)
); );
@@ -6403,3 +6403,40 @@ u_int8_t ndpi_extra_dissection_possible(struct ndpi_detection_module_struct *ndp
} }
/* ******************************************************************** */ /* ******************************************************************** */
const char* ndpi_get_l4_proto_name(ndpi_l4_proto_info proto) {
switch(proto) {
case ndpi_l4_proto_unknown:
return("");
break;
case ndpi_l4_proto_tcp_only:
return("TCP");
break;
case ndpi_l4_proto_udp_only:
return("UDP");
break;
case ndpi_l4_proto_tcp_and_udp:
return("TCP/UDP");
break;
}
}
/* ******************************************************************** */
ndpi_l4_proto_info ndpi_get_l4_proto_info(struct ndpi_detection_module_struct *ndpi_struct,
u_int16_t ndpi_proto_id) {
if(ndpi_proto_id < ndpi_struct->ndpi_num_supported_protocols) {
u_int16_t idx = ndpi_struct->proto_defaults[ndpi_proto_id].protoIdx;
NDPI_SELECTION_BITMASK_PROTOCOL_SIZE bm = ndpi_struct->callback_buffer[idx].ndpi_selection_bitmask;
if(bm & NDPI_SELECTION_BITMASK_PROTOCOL_INT_TCP) return(ndpi_l4_proto_tcp_only);
else if(bm & NDPI_SELECTION_BITMASK_PROTOCOL_INT_UDP) return(ndpi_l4_proto_udp_only);
else if(bm & NDPI_SELECTION_BITMASK_PROTOCOL_INT_TCP_OR_UDP) return(ndpi_l4_proto_tcp_and_udp);
}
return(ndpi_l4_proto_unknown); /* default */
}