Skip to content

Commit db7589d

Browse files
committed
config: remove ndpi_set_detection_preferences()
1 parent 7d2454c commit db7589d

File tree

8 files changed

+32
-52
lines changed

8 files changed

+32
-52
lines changed

doc/configuration_parameters.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ TODO
66
| Protocol | Parameter | Default value | Min value | Max value | Description | Notes |
77
| ------ | ------ | ------ | ------ | ------ | ------ | ------ |
88
| NULL | "packets_limit_per_flow" | 32 | 0 | 255 | The upper limit on the number of packets per flow that will be subject to DPI, after which classification will be considered complete (0 = no limit) |
9+
| NULL | "flow.direction_detection.enable" | 1 | NULL | NULL | Enable/disable internal detection of packet direction (client to server or server to client) |
910
| NULL | "flow_risk_lists.load" | 1 | NULL | NULL | Enable/disable loading of every IP addresses lists used to check any flow risks |
1011
| NULL | "flow_risk.anonymous_subscriber.list.icloudprivaterelay.load" | 1 | NULL | NULL | Enable/disable loading of internal iCouldPrivateRealy IP address list used to check `NDPI_ANONYMOUS_SUBSCRIBER` flow risk |
1112
| NULL | "flow_risk.anonymous_subscriber.list.protonvpn.load" | 1 | NULL | NULL | Enable/disable loading of internal IP address list of ProtonVPN exit nodes used to check `NDPI_ANONYMOUS_SUBSCRIBER` flow risk |
1213
| NULL | "flow_risk.crawler_bot.list.load" | 1 | NULL | NULL | Enable/disable loading of internal IP address list used to check `NDPI_HTTP_CRAWLER_BOT` flow risk |
1314
| NULL | "filename.config" | NULL | NULL | NULL | Name of the file containing a list of configuration knobs itself (one per line)!. Useful to configure nDPI via text file instead of via API |
1415
| NULL | "lru.$CACHE_NAME.size" | See description | 0 | 16777215 | Set the size (in number of elements) of the specified LRU cache (0 = the cache is disabled). The keyword "$CACHE_NAME" is a placeholder for the cache name and the possible values are: ookla, bittorrent, zoom, stun, tls_cert, mining, msteams, stun_zoom. The default value is "32768" for the bittorrent cache, "512" for the zoom cache and "1024" for all the other caches |
1516
| NULL | "lru.$CACHE_NAME.ttl" | See description | 0 | 16777215 | Set the TTL (in seconds) for the elements of the specified LRU cache (0 = the elements never explicitly expire). The keyword "$CACHE_NAME" is a placeholder for the cache name and the possible values are: ookla, bittorrent, zoom, stun, tls_cert, mining, msteams, stun_zoom. The default value is "120" for the ookla cache, "60" for the msteams and stun_zoom caches and "0" for all the other caches |
17+
| "tls" | "application_blocks_tracking.enable" | 0 | NULL | NULL | Enable/disable processing of TLS Application Blocks (post handshake) to extract statistical information about the flow |
1618
| "tls" | "metadata.sha1_fingerprint.enable" | 1 | NULL | NULL | Enable/disable computation and export of SHA1 fingerprint for TLS flows. Note that if it is disable, the flow risk `NDPI_MALICIOUS_SHA1_CERTIFICATE` is not checked |
1719
| "smtp" | "tls_dissection.enable" | 1 | NULL | NULL | Enable/disable dissection of TLS packets in cleartext SMTP flows (because of opportunistic TLS, via STARTTLS msg) |
1820
| "imap" | "tls_dissection.enable" | 1 | NULL | NULL | Enable/disable dissection of TLS packets in cleartext IMAP flows (because of opportunistic TLS, via STARTTLS msg) |

example/ndpiReader.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2781,14 +2781,14 @@ static void setupDetection(u_int16_t thread_id, pcap_t * pcap_handle) {
27812781
cfgs[i].proto, cfgs[i].param, cfgs[i].value, rc);
27822782
}
27832783

2784+
if(enable_doh_dot_detection)
2785+
ndpi_set_config(ndpi_thread_info[thread_id].workflow->ndpi_struct, "tls", "application_blocks_tracking.enable", "1");
2786+
27842787
ret = ndpi_finalize_initialization(ndpi_thread_info[thread_id].workflow->ndpi_struct);
27852788
if(ret != 0) {
27862789
fprintf(stderr, "Error ndpi_finalize_initialization: %d\n", ret);
27872790
exit(-1);
27882791
}
2789-
2790-
if(enable_doh_dot_detection)
2791-
ndpi_set_detection_preferences(ndpi_thread_info[thread_id].workflow->ndpi_struct, ndpi_pref_enable_tls_block_dissection, 1);
27922792
}
27932793

27942794
/* *********************************************** */

fuzz/fuzz_config.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
5757
ndpi_set_user_data(ndpi_info_mod, (void *)0xabcdabcd); /* Twice to trigger overwriting */
5858
ndpi_get_user_data(ndpi_info_mod);
5959

60+
/* ndpi_set_config: try to keep the soame order of the definitions in ndpi_main.c.
61+
+ 1 to trigger unvalid parameter error */
62+
6063
ndpi_set_tls_cert_expire_days(ndpi_info_mod, fuzzed_data.ConsumeIntegral<u_int8_t>());
6164

6265
if(fuzzed_data.ConsumeBool())
@@ -76,15 +79,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
7679
/* TODO: stub for geo stuff */
7780
ndpi_load_geoip(ndpi_info_mod, NULL, NULL);
7881

79-
if(fuzzed_data.ConsumeBool())
80-
ndpi_set_detection_preferences(ndpi_info_mod, ndpi_pref_direction_detect_disable,
81-
fuzzed_data.ConsumeBool());
82-
if(fuzzed_data.ConsumeBool())
83-
ndpi_set_detection_preferences(ndpi_info_mod, ndpi_pref_enable_tls_block_dissection,
84-
0 /* unused */);
85-
86-
ndpi_set_detection_preferences(ndpi_info_mod, static_cast<ndpi_detection_preference>(0xFF), 0xFF); /* Invalid preference */
87-
82+
if(fuzzed_data.ConsumeBool()) {
83+
value = fuzzed_data.ConsumeIntegralInRange(0, 1 + 1);
84+
sprintf(cfg_value, "%d", value);
85+
ndpi_set_config(ndpi_info_mod, "tls", "application_blocks_tracking.enable", cfg_value);
86+
}
8887
if(fuzzed_data.ConsumeBool()) {
8988
value = fuzzed_data.ConsumeIntegralInRange(0, 1 + 1);
9089
sprintf(cfg_value, "%d", value);
@@ -138,6 +137,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
138137
sprintf(cfg_value, "%d", value);
139138
ndpi_set_config(ndpi_info_mod, NULL, "packets_limit_per_flow", cfg_value);
140139
}
140+
if(fuzzed_data.ConsumeBool()) {
141+
value = fuzzed_data.ConsumeIntegralInRange(0, 1 + 1);
142+
sprintf(cfg_value, "%d", value);
143+
ndpi_set_config(ndpi_info_mod, NULL, "flow.direction_detection.enable", cfg_value);
144+
}
141145
if(fuzzed_data.ConsumeBool()) {
142146
value = fuzzed_data.ConsumeIntegralInRange(0, 1 + 1);
143147
sprintf(cfg_value, "%d", value);

fuzz/fuzz_ndpi_reader.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
7272
NDPI_BITMASK_SET_ALL(all);
7373
ndpi_set_protocol_detection_bitmask2(workflow->ndpi_struct, &all);
7474

75-
ndpi_set_detection_preferences(workflow->ndpi_struct, ndpi_pref_enable_tls_block_dissection, 0 /* unused */);
75+
ndpi_set_config(workflow->ndpi_struct, "tls", "application_blocks_tracking.enable", "1");
7676

7777
memset(workflow->stats.protocol_counter, 0,
7878
sizeof(workflow->stats.protocol_counter));

src/include/ndpi_api.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,9 +1035,6 @@ extern "C" {
10351035
int ndpi_get_custom_category_match(struct ndpi_detection_module_struct *ndpi_struct,
10361036
char *name_or_ip, u_int name_len,
10371037
ndpi_protocol_category_t *id);
1038-
int ndpi_set_detection_preferences(struct ndpi_detection_module_struct *ndpi_mod,
1039-
ndpi_detection_preference pref,
1040-
int value);
10411038

10421039
u_int16_t ndpi_map_user_proto_id_to_ndpi_id(struct ndpi_detection_module_struct *ndpi_str,
10431040
u_int16_t user_proto_id);

src/include/ndpi_typedefs.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,11 +1071,6 @@ typedef enum {
10711071
NDPI_PROTOCOL_ANY_CATEGORY /* Used to handle wildcards */
10721072
} ndpi_protocol_category_t;
10731073

1074-
typedef enum {
1075-
ndpi_pref_direction_detect_disable = 0,
1076-
ndpi_pref_enable_tls_block_dissection, /* nDPI considers only those blocks past the certificate exchange */
1077-
} ndpi_detection_preference;
1078-
10791074
/* ntop extensions */
10801075
typedef struct ndpi_proto_defaults {
10811076
char *protoName;

src/lib/ndpi_main.c

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -960,34 +960,6 @@ static void init_string_based_protocols(struct ndpi_detection_module_struct *ndp
960960

961961
/* ******************************************************************** */
962962

963-
int ndpi_set_detection_preferences(struct ndpi_detection_module_struct *ndpi_str, ndpi_detection_preference pref,
964-
int value) {
965-
if(!ndpi_str)
966-
return -1;
967-
968-
switch(pref) {
969-
case ndpi_pref_direction_detect_disable:
970-
ndpi_str->direction_detect_disable = (u_int8_t) value;
971-
break;
972-
973-
case ndpi_pref_enable_tls_block_dissection:
974-
/*
975-
If this option is enabled only the TLS Application data blocks past the
976-
certificate negotiation are considered
977-
*/
978-
ndpi_str->num_tls_blocks_to_follow = NDPI_MAX_NUM_TLS_APPL_BLOCKS;
979-
ndpi_str->skip_tls_blocks_until_change_cipher = 1;
980-
break;
981-
982-
default:
983-
return(-1);
984-
}
985-
986-
return(0);
987-
}
988-
989-
/* ******************************************************************** */
990-
991963
static void ndpi_validate_protocol_initialization(struct ndpi_detection_module_struct *ndpi_str) {
992964
u_int i;
993965

@@ -3651,6 +3623,11 @@ int ndpi_finalize_initialization(struct ndpi_detection_module_struct *ndpi_str)
36513623

36523624
ndpi_str->ac_automa_finalized = 1;
36533625

3626+
if(ndpi_str->cfg.tls_app_blocks_tracking_enabled) {
3627+
ndpi_str->num_tls_blocks_to_follow = NDPI_MAX_NUM_TLS_APPL_BLOCKS;
3628+
ndpi_str->skip_tls_blocks_until_change_cipher = 1;
3629+
}
3630+
36543631
ndpi_str->finalized = 1;
36553632

36563633
return 0;
@@ -4049,6 +4026,7 @@ void ndpi_exit_detection_module(struct ndpi_detection_module_struct *ndpi_str) {
40494026
ndpi_free(ndpi_str->callback_buffer);
40504027
if(ndpi_str->callback_buffer_tcp_payload)
40514028
ndpi_free(ndpi_str->callback_buffer_tcp_payload);
4029+
40524030
ndpi_free(ndpi_str);
40534031
}
40544032

@@ -6592,7 +6570,7 @@ void ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_str,
65926570

65936571
packet->tcp_retransmission = 0, packet->packet_direction = 0;
65946572

6595-
if(ndpi_str->direction_detect_disable) {
6573+
if(!ndpi_str->cfg.direction_detect_enabled) {
65966574
packet->packet_direction = flow->packet_direction;
65976575
} else {
65986576
if(iph != NULL && ntohl(iph->saddr) < ntohl(iph->daddr))
@@ -6617,7 +6595,7 @@ void ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_str,
66176595
else if(flags == (TH_FIN | TH_PUSH | TH_URG))
66186596
ndpi_set_risk(ndpi_str, flow, NDPI_TCP_ISSUES, "TCP XMAS scan");
66196597

6620-
if(!ndpi_str->direction_detect_disable &&
6598+
if(ndpi_str->cfg.direction_detect_enabled &&
66216599
(tcph->source != tcph->dest))
66226600
packet->packet_direction = (ntohs(tcph->source) < ntohs(tcph->dest)) ? 1 : 0;
66236601

@@ -6698,7 +6676,7 @@ void ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_str,
66986676
flow->next_tcp_seq_nr[1] = 0;
66996677
}
67006678
} else if(udph != NULL) {
6701-
if(!ndpi_str->direction_detect_disable &&
6679+
if(ndpi_str->cfg.direction_detect_enabled &&
67026680
(udph->source != udph->dest))
67036681
packet->packet_direction = (htons(udph->source) < htons(udph->dest)) ? 1 : 0;
67046682
}
@@ -10788,6 +10766,7 @@ static const struct cfg_param {
1078810766
} cfg_params[] = {
1078910767
/* Per-protocol parameters */
1079010768

10769+
{ "tls", "application_blocks_tracking.enable", "0", NULL, NULL, CFG_PARAM_ENABLE_DISABLE, __OFF(tls_app_blocks_tracking_enabled) },
1079110770
{ "tls", "metadata.sha1_fingerprint.enable", "1", NULL, NULL, CFG_PARAM_ENABLE_DISABLE, __OFF(tls_sha1_fingerprint_enabled) },
1079210771

1079310772
{ "smtp", "tls_dissection.enable", "1", NULL, NULL, CFG_PARAM_ENABLE_DISABLE, __OFF(smtp_opportunistic_tls_enabled) },
@@ -10807,6 +10786,7 @@ static const struct cfg_param {
1080710786
/* Global parameters */
1080810787

1080910788
{ NULL, "packets_limit_per_flow", "32", "0", "255", CFG_PARAM_INT, __OFF(max_packets_to_process) },
10789+
{ NULL, "flow.direction_detection.enable", "1", NULL, NULL, CFG_PARAM_ENABLE_DISABLE, __OFF(direction_detect_enabled) },
1081010790

1081110791
{ NULL, "flow_risk_lists.load", "1", NULL, NULL, CFG_PARAM_ENABLE_DISABLE, __OFF(flow_risk_lists_enabled)},
1081210792

src/lib/ndpi_private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ typedef struct {
126126

127127
struct ndpi_detection_module_config_struct {
128128
int max_packets_to_process;
129+
int direction_detect_enabled;
129130

130131
char filename_config[CFG_MAX_LEN];
131132

@@ -150,6 +151,7 @@ struct ndpi_detection_module_config_struct {
150151

151152
/* Protocols */
152153

154+
int tls_app_blocks_tracking_enabled;
153155
int tls_sha1_fingerprint_enabled;
154156

155157
int smtp_opportunistic_tls_enabled;

0 commit comments

Comments
 (0)