diff options
author | Toni <matzeton@googlemail.com> | 2020-12-11 21:01:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-11 21:01:51 +0100 |
commit | 74a77e7b3d4af1a3bebb2628ba551089cefc4e74 (patch) | |
tree | ee2dae8badbdba806b1bf7f18a9cf755418162ef | |
parent | edf3a57a6a197ea197d6c07d50dc94bc7bd97f8d (diff) |
Added --ignore-vlanid / -I to exclude VLAN ids for flow hash calculation. #1073 (#1085)
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r-- | example/ndpiReader.c | 10 | ||||
-rw-r--r-- | example/reader_util.c | 5 | ||||
-rw-r--r-- | example/reader_util.h | 1 |
3 files changed, 14 insertions, 2 deletions
diff --git a/example/ndpiReader.c b/example/ndpiReader.c index 86dc261a1..52e4e2da8 100644 --- a/example/ndpiReader.c +++ b/example/ndpiReader.c @@ -71,6 +71,7 @@ static u_int8_t live_capture = 0; static u_int8_t undetected_flows_deleted = 0; FILE *csv_fp = NULL; /**< for CSV export */ static char* domain_to_check = NULL; +static u_int8_t ignore_vlanid = 0; /** User preferences **/ u_int8_t enable_protocol_guess = 1, enable_payload_analyzer = 0, num_bin_clusters = 0; u_int8_t verbose = 0, enable_joy_stats = 0; @@ -484,6 +485,7 @@ static void help(u_int long_help) { " -U <num> | Max number of UDP processed packets before giving up [default: %u]\n" " -D | Enable DoH traffic analysis based on content (no DPI)\n" " -x <domain> | Check domain name [Test only]\n" + " -I | Ignore VLAN id for flow hash calculation\n" , human_readeable_string_len, min_pattern_len, max_pattern_len, max_num_packets_per_flow, max_packet_payload_dissection, @@ -541,6 +543,7 @@ static struct option longopts[] = { { "cpu-bind", required_argument, NULL, 'g'}, { "loops", required_argument, NULL, 'l'}, { "num-threads", required_argument, NULL, 'n'}, + { "ignore-vlanid", no_argument, NULL, 'I'}, { "protos", required_argument, NULL, 'p'}, { "capture-duration", required_argument, NULL, 's'}, @@ -759,7 +762,7 @@ static void parseOptions(int argc, char **argv) { } #endif - while((opt = getopt_long(argc, argv, "b:e:c:C:dDf:g:i:hp:P:l:s:tu:v:V:n:Jrp:x:w:q0123:456:7:89:m:T:U:", + while((opt = getopt_long(argc, argv, "b:e:c:C:dDf:g:i:Ihp:P:l:s:tu:v:V:n:Jrp:x:w:q0123:456:7:89:m:T:U:", longopts, &option_idx)) != EOF) { #ifdef DEBUG_TRACE if(trace) fprintf(trace, " #### -%c [%s] #### \n", opt, optarg ? optarg : ""); @@ -788,6 +791,10 @@ static void parseOptions(int argc, char **argv) { _pcap_file[0] = optarg; break; + case 'I': + ignore_vlanid = 1; + break; + case 'm': pcap_analysis_duration = atol(optarg); break; @@ -2019,6 +2026,7 @@ static void setupDetection(u_int16_t thread_id, pcap_t * pcap_handle) { prefs.num_roots = NUM_ROOTS; prefs.max_ndpi_flows = MAX_NDPI_FLOWS; prefs.quiet_mode = quiet_mode; + prefs.ignore_vlanid = ignore_vlanid; memset(&ndpi_thread_info[thread_id], 0, sizeof(ndpi_thread_info[thread_id])); ndpi_thread_info[thread_id].workflow = ndpi_workflow_init(&prefs, pcap_handle); diff --git a/example/reader_util.c b/example/reader_util.c index 9708e49b1..8546c427e 100644 --- a/example/reader_util.c +++ b/example/reader_util.c @@ -779,7 +779,10 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow flow.protocol = iph->protocol, flow.vlan_id = vlan_id; flow.src_ip = iph->saddr, flow.dst_ip = iph->daddr; flow.src_port = htons(*sport), flow.dst_port = htons(*dport); - flow.hashval = hashval = flow.protocol + flow.vlan_id + flow.src_ip + flow.dst_ip + flow.src_port + flow.dst_port; + flow.hashval = hashval = flow.protocol + flow.src_ip + flow.dst_ip + flow.src_port + flow.dst_port; + if (workflow->prefs.ignore_vlanid == 0) { + flow.hashval += flow.vlan_id; + } #if 0 printf("hashval=%u [%u][%u][%u:%u][%u:%u]\n", hashval, flow.protocol, flow.vlan_id, diff --git a/example/reader_util.h b/example/reader_util.h index 7337bb182..f471c365f 100644 --- a/example/reader_util.h +++ b/example/reader_util.h @@ -264,6 +264,7 @@ typedef struct ndpi_stats { typedef struct ndpi_workflow_prefs { u_int8_t decode_tunnels; u_int8_t quiet_mode; + u_int8_t ignore_vlanid; u_int32_t num_roots; u_int32_t max_ndpi_flows; } ndpi_workflow_prefs_t; |