@@ -96,6 +96,16 @@ u_int8_t enable_protocol_guess = 1, enable_payload_analyzer = 0, num_bin_cluster
96
96
u_int8_t verbose = 0 , enable_flow_stats = 0 ;
97
97
int stun_monitoring_pkts_to_process = -1 ; /* Default */
98
98
int stun_monitoring_flags = -1 ; /* Default */
99
+
100
+ struct cfg {
101
+ char * proto ;
102
+ char * param ;
103
+ char * value ;
104
+ };
105
+ #define MAX_NUM_CFGS 16
106
+ static struct cfg cfgs [MAX_NUM_CFGS ];
107
+ static int num_cfgs = 0 ;
108
+
99
109
int nDPI_LogLevel = 0 ;
100
110
char * _debug_protocols = NULL ;
101
111
char * _disabled_protocols = NULL ;
@@ -594,11 +604,20 @@ static void help(u_int long_help) {
594
604
" --lru-cache-ttl=NAME:size | Specify the TTL [in seconds] for this LRU cache (0 to disable it). This flag can be used multiple times\n"
595
605
" --stun-monitoring=<pkts>:<flags> | Configure STUN monitoring: keep monitoring STUN session for <pkts> more pkts looking for RTP\n"
596
606
" | (0:0 to disable the feature); set the specified features in <flags>\n"
607
+ " --cfg=proto,param,value | Configure the specific attribute of this protocol\n"
597
608
,
598
609
human_readeable_string_len ,
599
610
min_pattern_len , max_pattern_len , max_num_packets_per_flow , max_packet_payload_dissection ,
600
611
max_num_reported_top_payloads , max_num_tcp_dissected_pkts , max_num_udp_dissected_pkts );
601
612
613
+ NDPI_PROTOCOL_BITMASK all ;
614
+ ndpi_info_mod = ndpi_init_detection_module (init_prefs );
615
+ NDPI_BITMASK_SET_ALL (all );
616
+ ndpi_set_protocol_detection_bitmask2 (ndpi_info_mod , & all );
617
+
618
+ printf ("\nProtocols configuration parameters:\n" );
619
+ ndpi_dump_config (ndpi_info_mod , stdout );
620
+
602
621
printf ("\nLRU Cache names: ookla, bittorrent, zoom, stun, tls_cert, mining, msteams, stun_zoom\n" );
603
622
604
623
#ifndef WIN32
@@ -621,24 +640,18 @@ static void help(u_int long_help) {
621
640
ndpi_detection_get_sizeof_ndpi_flow_struct (),
622
641
sizeof (((struct ndpi_flow_struct * )0 )-> protos ));
623
642
624
- NDPI_PROTOCOL_BITMASK all ;
625
-
626
- ndpi_info_mod = ndpi_init_detection_module (init_prefs );
627
643
printf ("\n\nnDPI supported protocols:\n" );
628
644
printf ("%3s %-22s %-10s %-8s %-12s %s\n" ,
629
645
"Id" , "Protocol" , "Layer_4" , "Nw_Proto" , "Breed" , "Category" );
630
646
num_threads = 1 ;
631
647
632
- NDPI_BITMASK_SET_ALL (all );
633
- ndpi_set_protocol_detection_bitmask2 (ndpi_info_mod , & all );
634
-
635
648
ndpi_dump_protocols (ndpi_info_mod , stdout );
636
649
637
650
printf ("\n\nnDPI supported risks:\n" );
638
651
ndpi_dump_risks_score (stdout );
639
-
640
- ndpi_exit_detection_module (ndpi_info_mod );
641
652
}
653
+
654
+ ndpi_exit_detection_module (ndpi_info_mod );
642
655
643
656
exit (!long_help );
644
657
}
@@ -649,6 +662,8 @@ static void help(u_int long_help) {
649
662
650
663
#define OPTLONG_VALUE_STUN_MONITORING 2000
651
664
665
+ #define OPTLONG_VALUE_CFG 3000
666
+
652
667
static struct option longopts [] = {
653
668
/* mandatory extcap options */
654
669
{ "extcap-interfaces" , no_argument , NULL , '0' },
@@ -694,6 +709,8 @@ static struct option longopts[] = {
694
709
{ "lru-cache-ttl" , required_argument , NULL , OPTLONG_VALUE_LRU_CACHE_TTL },
695
710
{ "stun-monitoring" , required_argument , NULL , OPTLONG_VALUE_STUN_MONITORING },
696
711
712
+ { "cfg" , required_argument , NULL , OPTLONG_VALUE_CFG },
713
+
697
714
{0 , 0 , 0 , 0 }
698
715
};
699
716
@@ -950,6 +967,42 @@ static int parse_two_unsigned_integer(char *param, u_int32_t *num1, u_int32_t *n
950
967
return -1 ;
951
968
}
952
969
970
+ static int parse_three_strings (char * param , char * * s1 , char * * s2 , char * * s3 )
971
+ {
972
+ char * saveptr , * tmp_str , * s1_str , * s2_str = NULL , * s3_str ;
973
+
974
+ tmp_str = ndpi_strdup (param );
975
+ if (tmp_str ) {
976
+ if (param [0 ] == ',' ) { /* First parameter might be missing */
977
+ s1_str = NULL ;
978
+ s2_str = strtok_r (tmp_str , "," , & saveptr );
979
+ } else {
980
+ s1_str = strtok_r (tmp_str , "," , & saveptr );
981
+ if (s1_str ) {
982
+ s2_str = strtok_r (NULL , "," , & saveptr );
983
+ }
984
+ }
985
+ if (s2_str ) {
986
+ s3_str = strtok_r (NULL , "," , & saveptr );
987
+ if (s3_str ) {
988
+ * s1 = ndpi_strdup (s1_str );
989
+ * s2 = ndpi_strdup (s2_str );
990
+ * s3 = ndpi_strdup (s3_str );
991
+ ndpi_free (tmp_str );
992
+ if (!s1 || !s2 || !s3 ) {
993
+ ndpi_free (s1 );
994
+ ndpi_free (s2 );
995
+ ndpi_free (s3 );
996
+ return -1 ;
997
+ }
998
+ return 0 ;
999
+ }
1000
+ }
1001
+ }
1002
+ ndpi_free (tmp_str );
1003
+ return -1 ;
1004
+ }
1005
+
953
1006
/* ********************************** */
954
1007
955
1008
/**
@@ -968,6 +1021,7 @@ static void parseOptions(int argc, char **argv) {
968
1021
#endif
969
1022
int cache_idx , cache_size , cache_ttl ;
970
1023
u_int32_t num_pkts , flags ;
1024
+ char * s1 , * s2 , * s3 ;
971
1025
972
1026
#ifdef USE_DPDK
973
1027
{
@@ -1316,6 +1370,18 @@ static void parseOptions(int argc, char **argv) {
1316
1370
stun_monitoring_flags = flags ;
1317
1371
break ;
1318
1372
1373
+ case OPTLONG_VALUE_CFG :
1374
+ if (num_cfgs >= MAX_NUM_CFGS ||
1375
+ parse_three_strings (optarg , & s1 , & s2 , & s3 ) == -1 ) {
1376
+ printf ("Invalid parameter [%s] [num:%d/%d]\n" , optarg , num_cfgs , MAX_NUM_CFGS );
1377
+ exit (1 );
1378
+ }
1379
+ cfgs [num_cfgs ].proto = s1 ;
1380
+ cfgs [num_cfgs ].param = s2 ;
1381
+ cfgs [num_cfgs ].value = s3 ;
1382
+ num_cfgs ++ ;
1383
+ break ;
1384
+
1319
1385
default :
1320
1386
#ifdef DEBUG_TRACE
1321
1387
if (trace ) fprintf (trace , " #### Unknown option -%c: skipping it #### \n" , opt );
@@ -2669,7 +2735,7 @@ static void debug_printf(u_int32_t protocol, void *id_struct,
2669
2735
static void setupDetection (u_int16_t thread_id , pcap_t * pcap_handle ) {
2670
2736
NDPI_PROTOCOL_BITMASK enabled_bitmask ;
2671
2737
struct ndpi_workflow_prefs prefs ;
2672
- int i ;
2738
+ int i , rc ;
2673
2739
2674
2740
memset (& prefs , 0 , sizeof (prefs ));
2675
2741
prefs .decode_tunnels = decode_tunnels ;
@@ -2757,6 +2823,14 @@ static void setupDetection(u_int16_t thread_id, pcap_t * pcap_handle) {
2757
2823
ndpi_set_protocol_aggressiveness (ndpi_thread_info [thread_id ].workflow -> ndpi_struct , i , aggressiveness [i ]);
2758
2824
}
2759
2825
2826
+ for (i = 0 ; i < num_cfgs ; i ++ ) {
2827
+ rc = ndpi_set_config (ndpi_thread_info [thread_id ].workflow -> ndpi_struct ,
2828
+ cfgs [i ].proto , cfgs [i ].param , cfgs [i ].value );
2829
+ if (rc != 0 )
2830
+ fprintf (stderr , "Error setting config [%s][%s][%s]: %d\n" ,
2831
+ cfgs [i ].proto , cfgs [i ].param , cfgs [i ].value , rc );
2832
+ }
2833
+
2760
2834
if (stun_monitoring_pkts_to_process != -1 &&
2761
2835
stun_monitoring_flags != -1 )
2762
2836
ndpi_set_monitoring_state (ndpi_thread_info [thread_id ].workflow -> ndpi_struct , NDPI_PROTOCOL_STUN ,
@@ -5684,6 +5758,12 @@ int main(int argc, char **argv) {
5684
5758
ndpi_free (_debug_protocols );
5685
5759
ndpi_free (_disabled_protocols );
5686
5760
5761
+ for (i = 0 ; i < num_cfgs ; i ++ ) {
5762
+ ndpi_free (cfgs [i ].proto );
5763
+ ndpi_free (cfgs [i ].param );
5764
+ ndpi_free (cfgs [i ].value );
5765
+ }
5766
+
5687
5767
#ifdef DEBUG_TRACE
5688
5768
if (trace ) fclose (trace );
5689
5769
#endif
0 commit comments