Added ndpi_category_set_name() API call

This commit is contained in:
Luca Deri
2017-09-19 22:39:00 +02:00
parent 1a4e57e736
commit 9fb5981128
5 changed files with 84 additions and 24 deletions
-4
View File
@@ -2783,7 +2783,6 @@ static void produceBpfFilter(char *filePath) {
@brief MAIN FUNCTION @brief MAIN FUNCTION
**/ **/
int main(int argc, char **argv) { int main(int argc, char **argv) {
int i; int i;
automataUnitTest(); automataUnitTest();
@@ -2799,7 +2798,6 @@ int main(int argc, char **argv) {
#endif #endif
} }
if((!json_flag) && (!quiet_mode)) { if((!json_flag) && (!quiet_mode)) {
printf("\n-----------------------------------------------------------\n" printf("\n-----------------------------------------------------------\n"
"* NOTE: This is demo app to show *some* nDPI features.\n" "* NOTE: This is demo app to show *some* nDPI features.\n"
@@ -2823,7 +2821,6 @@ int main(int argc, char **argv) {
return 0; return 0;
} }
#ifdef WIN32 #ifdef WIN32
#ifndef __GNUC__ #ifndef __GNUC__
#define EPOCHFILETIME (116444736000000000i64) #define EPOCHFILETIME (116444736000000000i64)
@@ -2831,7 +2828,6 @@ int main(int argc, char **argv) {
#define EPOCHFILETIME (116444736000000000LL) #define EPOCHFILETIME (116444736000000000LL)
#endif #endif
/** /**
@brief Timezone @brief Timezone
**/ **/
+3
View File
@@ -52,3 +52,6 @@ set_ndpi_debug_function
ndpi_category_str ndpi_category_str
ndpi_get_proto_category ndpi_get_proto_category
ndpi_netbios_name_interpret ndpi_netbios_name_interpret
ndpi_category_set_name
ndpi_category_get_name
ndpi_is_custom_category
+14 -1
View File
@@ -443,11 +443,24 @@ extern "C" {
/** /**
* Get protocol category as string * Get protocol category as string
* *
* @par mod = the detection module
* @par category = the category associated to the protocol * @par category = the category associated to the protocol
* @return the string name of the category * @return the string name of the category
* *
*/ */
const char* ndpi_category_str(ndpi_protocol_category_t category); const char* ndpi_category_get_name(struct ndpi_detection_module_struct *ndpi_mod,
ndpi_protocol_category_t category);
/**
* Set protocol category string
*
* @par mod = the detection module
* @par category = the category associated to the protocol
* @paw name = the string name of the category
*
*/
void ndpi_category_set_name(struct ndpi_detection_module_struct *ndpi_mod,
ndpi_protocol_category_t category, char *name);
/** /**
* Get protocol category * Get protocol category
+5 -1
View File
@@ -764,6 +764,7 @@ typedef enum {
NDPI_PROTOCOL_CATEGORY_NETWORK_TOOL, /* Network administration and monitor protocols */ NDPI_PROTOCOL_CATEGORY_NETWORK_TOOL, /* Network administration and monitor protocols */
NDPI_PROTOCOL_CATEGORY_SYSTEM_OS, /* System/Operating System level applications */ NDPI_PROTOCOL_CATEGORY_SYSTEM_OS, /* System/Operating System level applications */
NDPI_PROTOCOL_CATEGORY_SW_UPDATE, /* Software update */ NDPI_PROTOCOL_CATEGORY_SW_UPDATE, /* Software update */
/* See #define NUM_CUSTOM_CATEGORIES */
NDPI_PROTOCOL_CATEGORY_CUSTOM_1, /* User custom category 1 */ NDPI_PROTOCOL_CATEGORY_CUSTOM_1, /* User custom category 1 */
NDPI_PROTOCOL_CATEGORY_CUSTOM_2, /* User custom category 2 */ NDPI_PROTOCOL_CATEGORY_CUSTOM_2, /* User custom category 2 */
NDPI_PROTOCOL_CATEGORY_CUSTOM_3, /* User custom category 3 */ NDPI_PROTOCOL_CATEGORY_CUSTOM_3, /* User custom category 3 */
@@ -804,6 +805,9 @@ typedef struct ndpi_proto {
#define NDPI_PROTOCOL_NULL { NDPI_PROTOCOL_UNKNOWN , NDPI_PROTOCOL_UNKNOWN } #define NDPI_PROTOCOL_NULL { NDPI_PROTOCOL_UNKNOWN , NDPI_PROTOCOL_UNKNOWN }
#define NUM_CUSTOM_CATEGORIES 5
#define CUSTOM_CATEGORY_LABEL_LEN 32
struct ndpi_detection_module_struct { struct ndpi_detection_module_struct {
NDPI_PROTOCOL_BITMASK detection_bitmask; NDPI_PROTOCOL_BITMASK detection_bitmask;
NDPI_PROTOCOL_BITMASK generic_http_packet_bitmask; NDPI_PROTOCOL_BITMASK generic_http_packet_bitmask;
@@ -814,7 +818,7 @@ struct ndpi_detection_module_struct {
#ifdef NDPI_ENABLE_DEBUG_MESSAGES #ifdef NDPI_ENABLE_DEBUG_MESSAGES
void *user_data; void *user_data;
#endif #endif
char custom_category_labels[NUM_CUSTOM_CATEGORIES][CUSTOM_CATEGORY_LABEL_LEN];
/* callback function buffer */ /* callback function buffer */
struct ndpi_call_function_struct callback_buffer[NDPI_MAX_SUPPORTED_PROTOCOLS + 1]; struct ndpi_call_function_struct callback_buffer[NDPI_MAX_SUPPORTED_PROTOCOLS + 1];
u_int32_t callback_buffer_size; u_int32_t callback_buffer_size;
+60 -16
View File
@@ -1839,6 +1839,7 @@ void set_ndpi_debug_function(struct ndpi_detection_module_struct *ndpi_str, ndpi
struct ndpi_detection_module_struct *ndpi_init_detection_module(void) { struct ndpi_detection_module_struct *ndpi_init_detection_module(void) {
struct ndpi_detection_module_struct *ndpi_str = ndpi_malloc(sizeof(struct ndpi_detection_module_struct)); struct ndpi_detection_module_struct *ndpi_str = ndpi_malloc(sizeof(struct ndpi_detection_module_struct));
int i;
if(ndpi_str == NULL) { if(ndpi_str == NULL) {
#ifdef NDPI_ENABLE_DEBUG_MESSAGES #ifdef NDPI_ENABLE_DEBUG_MESSAGES
@@ -1890,6 +1891,11 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(void) {
ndpi_str->impossible_bigrams_automa.ac_automa = ac_automata_init(ac_match_handler); ndpi_str->impossible_bigrams_automa.ac_automa = ac_automata_init(ac_match_handler);
ndpi_init_protocol_defaults(ndpi_str); ndpi_init_protocol_defaults(ndpi_str);
for(i=0; i<NUM_CUSTOM_CATEGORIES; i++)
snprintf(ndpi_str->custom_category_labels[i],
CUSTOM_CATEGORY_LABEL_LEN, "User custom category %u", i+1);
return ndpi_str; return ndpi_str;
} }
@@ -2269,17 +2275,18 @@ int ndpi_load_protocols_file(struct ndpi_detection_module_struct *ndpi_mod, char
return(0); return(0);
} }
/* ******************************************************************** */
/* ntop */ /* ntop */
void ndpi_set_bitmask_protocol_detection( char * label, void ndpi_set_bitmask_protocol_detection(char * label,
struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_detection_module_struct *ndpi_struct,
const NDPI_PROTOCOL_BITMASK * detection_bitmask, const NDPI_PROTOCOL_BITMASK * detection_bitmask,
const u_int32_t idx, const u_int32_t idx,
u_int16_t ndpi_protocol_id, u_int16_t ndpi_protocol_id,
void (*func) (struct ndpi_detection_module_struct *, struct ndpi_flow_struct *flow), void (*func) (struct ndpi_detection_module_struct *, struct ndpi_flow_struct *flow),
const NDPI_SELECTION_BITMASK_PROTOCOL_SIZE ndpi_selection_bitmask, const NDPI_SELECTION_BITMASK_PROTOCOL_SIZE ndpi_selection_bitmask,
u_int8_t b_save_bitmask_unknow, u_int8_t b_save_bitmask_unknow,
u_int8_t b_add_detection_bitmask) u_int8_t b_add_detection_bitmask) {
{
/* /*
Compare specify protocol bitmask with main detection bitmask Compare specify protocol bitmask with main detection bitmask
*/ */
@@ -4589,7 +4596,44 @@ int ndpi_is_custom_category(ndpi_protocol_category_t category) {
/* ****************************************************** */ /* ****************************************************** */
const char* ndpi_category_str(ndpi_protocol_category_t category) { void ndpi_category_set_name(struct ndpi_detection_module_struct *ndpi_mod,
ndpi_protocol_category_t category, char *name) {
if(!name) return;
switch(category) {
case NDPI_PROTOCOL_CATEGORY_CUSTOM_1:
snprintf(ndpi_mod->custom_category_labels[0], CUSTOM_CATEGORY_LABEL_LEN, "%s", name);
break;
case NDPI_PROTOCOL_CATEGORY_CUSTOM_2:
snprintf(ndpi_mod->custom_category_labels[1], CUSTOM_CATEGORY_LABEL_LEN, "%s", name);
break;
case NDPI_PROTOCOL_CATEGORY_CUSTOM_3:
snprintf(ndpi_mod->custom_category_labels[2], CUSTOM_CATEGORY_LABEL_LEN, "%s", name);
break;
case NDPI_PROTOCOL_CATEGORY_CUSTOM_4:
snprintf(ndpi_mod->custom_category_labels[3], CUSTOM_CATEGORY_LABEL_LEN, "%s", name);
break;
case NDPI_PROTOCOL_CATEGORY_CUSTOM_5:
snprintf(ndpi_mod->custom_category_labels[4], CUSTOM_CATEGORY_LABEL_LEN, "%s", name);
break;
default:
break;
}
}
/* ****************************************************** */
const char* ndpi_category_get_name(struct ndpi_detection_module_struct *ndpi_mod,
ndpi_protocol_category_t category) {
if(!ndpi_mod) return(NULL);
switch(category) { switch(category) {
case NDPI_PROTOCOL_CATEGORY_MEDIA: case NDPI_PROTOCOL_CATEGORY_MEDIA:
return("Media"); return("Media");
@@ -4652,19 +4696,19 @@ const char* ndpi_category_str(ndpi_protocol_category_t category) {
return("SoftwareUpdate"); return("SoftwareUpdate");
break; break;
case NDPI_PROTOCOL_CATEGORY_CUSTOM_1: case NDPI_PROTOCOL_CATEGORY_CUSTOM_1:
return("User custom category 1"); return(ndpi_mod->custom_category_labels[0]);
break; break;
case NDPI_PROTOCOL_CATEGORY_CUSTOM_2: case NDPI_PROTOCOL_CATEGORY_CUSTOM_2:
return("User custom category 2"); return(ndpi_mod->custom_category_labels[1]);
break; break;
case NDPI_PROTOCOL_CATEGORY_CUSTOM_3: case NDPI_PROTOCOL_CATEGORY_CUSTOM_3:
return("User custom category 3"); return(ndpi_mod->custom_category_labels[2]);
break; break;
case NDPI_PROTOCOL_CATEGORY_CUSTOM_4: case NDPI_PROTOCOL_CATEGORY_CUSTOM_4:
return("User custom category 4"); return(ndpi_mod->custom_category_labels[3]);
break; break;
case NDPI_PROTOCOL_CATEGORY_CUSTOM_5: case NDPI_PROTOCOL_CATEGORY_CUSTOM_5:
return("User custom category 5"); return(ndpi_mod->custom_category_labels[4]);
break; break;
case NDPI_PROTOCOL_NUM_CATEGORIES: case NDPI_PROTOCOL_NUM_CATEGORIES:
return("Code should not use this internal constant"); return("Code should not use this internal constant");