config: allow configuration of guessing algorithms

This commit is contained in:
Nardi Ivan
2024-01-18 10:21:24 +01:00
committed by Ivan Nardi
parent 6c85f10cd5
commit 0712d496fe
18 changed files with 140 additions and 23 deletions
-2
View File
@@ -290,14 +290,12 @@ extern "C" {
*
* @par ndpi_struct = the detection module
* @par flow = the flow given for the detection module
* @par enable_guess = guess protocol if unknown
* @par protocol_was_guessed = 1 if the protocol was guesses (requires enable_guess = 1), 0 otherwise
* @return the detected protocol even if the flow is not completed;
*
*/
ndpi_protocol ndpi_detection_giveup(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
u_int8_t enable_guess,
u_int8_t *protocol_was_guessed);
/**
+1
View File
@@ -167,6 +167,7 @@ struct ndpi_detection_module_config_struct {
int fully_encrypted_heuristic;
int track_payload_enabled;
int libgcrypt_init;
int guess_on_giveup;
char filename_config[CFG_MAX_LEN];
+2
View File
@@ -761,6 +761,8 @@ struct ndpi_lru_cache {
struct ndpi_lru_cache_entry *entries;
};
#define NDPI_GIVEUP_GUESS_BY_PORT 0x01
#define NDPI_GIVEUP_GUESS_BY_IP 0x02
/* Aggressiveness values */
+7 -4
View File
@@ -7377,7 +7377,7 @@ static void ndpi_check_tcp_flags(struct ndpi_detection_module_struct *ndpi_str,
/* ********************************************************************************* */
ndpi_protocol ndpi_detection_giveup(struct ndpi_detection_module_struct *ndpi_str, struct ndpi_flow_struct *flow,
u_int8_t enable_guess, u_int8_t *protocol_was_guessed) {
u_int8_t *protocol_was_guessed) {
ndpi_protocol ret = NDPI_PROTOCOL_NULL;
u_int16_t cached_proto;
@@ -7448,7 +7448,8 @@ ndpi_protocol ndpi_detection_giveup(struct ndpi_detection_module_struct *ndpi_st
}
/* Classification by-port */
if(enable_guess && ret.app_protocol == NDPI_PROTOCOL_UNKNOWN) {
if((ndpi_str->cfg.guess_on_giveup & NDPI_GIVEUP_GUESS_BY_PORT) &&
ret.app_protocol == NDPI_PROTOCOL_UNKNOWN) {
/* Ignore guessed protocol if they have been discarded */
if(flow->guessed_protocol_id != NDPI_PROTOCOL_UNKNOWN &&
@@ -7464,7 +7465,8 @@ ndpi_protocol ndpi_detection_giveup(struct ndpi_detection_module_struct *ndpi_st
}
/* Classification by-ip, as last effort */
if(ret.app_protocol == NDPI_PROTOCOL_UNKNOWN &&
if((ndpi_str->cfg.guess_on_giveup & NDPI_GIVEUP_GUESS_BY_IP) &&
ret.app_protocol == NDPI_PROTOCOL_UNKNOWN &&
flow->guessed_protocol_id_by_ip != NDPI_PROTOCOL_UNKNOWN) {
ndpi_set_detected_protocol(ndpi_str, flow,
@@ -7929,7 +7931,7 @@ static int ndpi_do_guess(struct ndpi_detection_module_struct *ndpi_str, struct n
if(flow->guessed_protocol_id_by_ip != NDPI_PROTOCOL_UNKNOWN) {
u_int8_t protocol_was_guessed;
*ret = ndpi_detection_giveup(ndpi_str, flow, 0, &protocol_was_guessed);
*ret = ndpi_detection_giveup(ndpi_str, flow, &protocol_was_guessed);
}
ndpi_fill_protocol_category(ndpi_str, flow, ret);
@@ -10795,6 +10797,7 @@ static const struct cfg_param {
{ NULL, "tcp_ack_payload_heuristic.enable", "0", NULL, NULL, CFG_PARAM_ENABLE_DISABLE, __OFF(tcp_ack_paylod_heuristic) },
{ NULL, "fully_encrypted_heuristic.enable", "1", NULL, NULL, CFG_PARAM_ENABLE_DISABLE, __OFF(fully_encrypted_heuristic) },
{ NULL, "libgcrypt.init", "1", NULL, NULL, CFG_PARAM_ENABLE_DISABLE, __OFF(libgcrypt_init), },
{ NULL, "guess_on_giveup", "0x3", "0", "3", CFG_PARAM_INT, __OFF(guess_on_giveup) },
{ NULL, "flow_risk_lists.load", "1", NULL, NULL, CFG_PARAM_ENABLE_DISABLE, __OFF(flow_risk_lists_enabled)},