diff options
author | Ivan Nardi <12729895+IvanNardi@users.noreply.github.com> | 2024-07-03 18:02:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-03 18:02:07 +0200 |
commit | 843e4872706b07b9e78418986d35fc86bc156d60 (patch) | |
tree | 6198692542842324200ff783d5daf5398b5c92d0 /src/lib | |
parent | e5661337d07fb1f7b2d55318bfef0929e3ca6e61 (diff) |
Add infrastructure for explicit support of Fist Packet Classification (#2488)
Let's start with some basic helpers and with FPC based on flow addresses.
See: #2322
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/ndpi_main.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index f2162e005..ac1c28897 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -8287,6 +8287,33 @@ static int ndpi_do_guess(struct ndpi_detection_module_struct *ndpi_str, struct n /* ********************************************************************************* */ +static void fpc_update(struct ndpi_detection_module_struct *ndpi_str, + struct ndpi_flow_struct *flow, + u_int16_t fpc_master, u_int16_t fpc_app, + ndpi_fpc_confidence_t fpc_confidence) +{ + NDPI_LOG_DBG(ndpi_str, "FPC %d.%d/%s -> %d.%d/%s\n", + flow->fpc.master_protocol, flow->fpc.app_protocol, + ndpi_fpc_confidence_get_name(flow->fpc.confidence), + fpc_master, fpc_app, + ndpi_fpc_confidence_get_name(fpc_confidence)); + flow->fpc.master_protocol = fpc_master; + flow->fpc.app_protocol = fpc_app; + flow->fpc.confidence = fpc_confidence; +} + +/* ********************************************************************************* */ + +static void fpc_check_ip(struct ndpi_detection_module_struct *ndpi_str, + struct ndpi_flow_struct *flow) +{ + if(flow->guessed_protocol_id_by_ip != NDPI_PROTOCOL_UNKNOWN) + fpc_update(ndpi_str, flow, NDPI_PROTOCOL_UNKNOWN, + flow->guessed_protocol_id_by_ip, NDPI_FPC_CONFIDENCE_IP); +} + +/* ********************************************************************************* */ + static ndpi_protocol ndpi_internal_detection_process_packet(struct ndpi_detection_module_struct *ndpi_str, struct ndpi_flow_struct *flow, const unsigned char *packet_data, @@ -8421,6 +8448,8 @@ static ndpi_protocol ndpi_internal_detection_process_packet(struct ndpi_detectio if(ndpi_do_guess(ndpi_str, flow, &ret) == -1) return(ret); + + fpc_check_ip(ndpi_str, flow); } num_calls = ndpi_check_flow_func(ndpi_str, flow, &ndpi_selection_packet); @@ -9383,6 +9412,25 @@ const char *ndpi_confidence_get_name(ndpi_confidence_t confidence) /* ****************************************************** */ +const char *ndpi_fpc_confidence_get_name(ndpi_fpc_confidence_t fpc_confidence) +{ + switch(fpc_confidence) { + case NDPI_FPC_CONFIDENCE_UNKNOWN: + return "Unknown"; + + case NDPI_FPC_CONFIDENCE_IP: + return "IP address"; + + case NDPI_FPC_CONFIDENCE_DNS: + return "DNS"; + + default: + return "Invalid"; /* Out of sync with ndpi_fpc_confidence_t definition */ + } +} + +/* ****************************************************** */ + const char *ndpi_category_get_name(struct ndpi_detection_module_struct *ndpi_str, ndpi_protocol_category_t category) { if((!ndpi_str) || (category >= NDPI_PROTOCOL_NUM_CATEGORIES)) { |