Added packetIDs with -P

This commit is contained in:
Luca Deri
2019-09-02 14:47:37 +02:00
parent 5d5d056849
commit bc4c48fa0b
+48 -5
View File
@@ -93,11 +93,17 @@ struct flow_id_stats {
UT_hash_handle hh; /* makes this structure hashable */ UT_hash_handle hh; /* makes this structure hashable */
}; };
struct packet_id_stats {
u_int32_t packet_id;
UT_hash_handle hh; /* makes this structure hashable */
};
struct payload_stats { struct payload_stats {
u_int8_t *pattern; u_int8_t *pattern;
u_int8_t pattern_len; u_int8_t pattern_len;
u_int16_t num_occurrencies; u_int16_t num_occurrencies;
struct flow_id_stats *flows; struct flow_id_stats *flows;
struct packet_id_stats *packets;
UT_hash_handle hh; /* makes this structure hashable */ UT_hash_handle hh; /* makes this structure hashable */
}; };
@@ -109,14 +115,17 @@ u_int32_t max_num_reported_top_payloads = 25;
u_int16_t min_pattern_len = 4; u_int16_t min_pattern_len = 4;
u_int16_t max_pattern_len = 8; u_int16_t max_pattern_len = 8;
/* *********************************************************** */
void ndpi_analyze_payload(struct ndpi_flow_info *flow, void ndpi_analyze_payload(struct ndpi_flow_info *flow,
u_int8_t src_to_dst_direction, u_int8_t src_to_dst_direction,
u_int8_t *payload, u_int8_t *payload,
u_int16_t payload_len) { u_int16_t payload_len,
u_int32_t packet_id) {
struct payload_stats *ret; struct payload_stats *ret;
u_int i; u_int i;
struct flow_id_stats *f; struct flow_id_stats *f;
struct packet_id_stats *p;
#ifdef DEBUG_PAYLOAD #ifdef DEBUG_PAYLOAD
for(i=0; i<payload_len; i++) for(i=0; i<payload_len; i++)
@@ -156,12 +165,23 @@ void ndpi_analyze_payload(struct ndpi_flow_info *flow,
f->flow_id = flow->flow_id; f->flow_id = flow->flow_id;
HASH_ADD_INT(ret->flows, flow_id, f); HASH_ADD_INT(ret->flows, flow_id, f);
} }
HASH_FIND_INT(ret->packets, &packet_id, p);
if(p == NULL) {
if((p = (struct packet_id_stats*)calloc(1, sizeof(struct packet_id_stats))) == NULL)
return; /* OOM */
p->packet_id = packet_id;
HASH_ADD_INT(ret->packets, packet_id, p);
}
} }
/* *********************************************************** */
void ndpi_payload_analyzer(struct ndpi_flow_info *flow, void ndpi_payload_analyzer(struct ndpi_flow_info *flow,
u_int8_t src_to_dst_direction, u_int8_t src_to_dst_direction,
u_int8_t *payload, u_int16_t payload_len) { u_int8_t *payload, u_int16_t payload_len,
u_int32_t packet_id) {
u_int16_t i, j; u_int16_t i, j;
u_int16_t scan_len = ndpi_min(max_packet_payload_dissection, payload_len); u_int16_t scan_len = ndpi_min(max_packet_payload_dissection, payload_len);
@@ -180,8 +200,7 @@ void ndpi_payload_analyzer(struct ndpi_flow_info *flow,
for(i=0; i<scan_len; i++) { for(i=0; i<scan_len; i++) {
for(j=min_pattern_len; j <= max_pattern_len; j++) { for(j=min_pattern_len; j <= max_pattern_len; j++) {
if((i+j) < payload_len) { if((i+j) < payload_len) {
ndpi_analyze_payload(flow, src_to_dst_direction, &payload[i], j); ndpi_analyze_payload(flow, src_to_dst_direction, &payload[i], j, packet_id);
ndpi_analyze_payload(flow, src_to_dst_direction, &payload[i], j);
} }
} }
} }
@@ -202,6 +221,7 @@ static int payload_stats_sort_asc(void *_a, void *_b) {
void print_payload_stat(struct payload_stats *p) { void print_payload_stat(struct payload_stats *p) {
u_int i; u_int i;
struct flow_id_stats *s, *tmp; struct flow_id_stats *s, *tmp;
struct packet_id_stats *s1, *tmp1;
printf("\t["); printf("\t[");
@@ -231,7 +251,19 @@ void print_payload_stat(struct payload_stats *p) {
i++; i++;
} }
printf("][packetIds: ");
/* ******************************** */
i = 0;
HASH_ITER(hh, p->packets, s1, tmp1) {
printf("%s%u", (i > 0) ? " " : "", s1->packet_id);
i++;
}
printf("]\n"); printf("]\n");
} }
/* ***************************************************** */ /* ***************************************************** */
@@ -259,6 +291,15 @@ void ndpi_report_payload_stats() {
} }
} }
{
struct packet_id_stats *p1, *tmp1;
HASH_ITER(hh, p->packets, p1, tmp1) {
HASH_DEL(p->packets, p1);
free(p1);
}
}
HASH_DEL(pstats, p); HASH_DEL(pstats, p);
free(p); free(p);
num++; num++;
@@ -1035,7 +1076,9 @@ static struct ndpi_proto packet_processing(struct ndpi_workflow * workflow,
} }
if(enable_payload_analyzer && (payload_len > 0)) if(enable_payload_analyzer && (payload_len > 0))
ndpi_payload_analyzer(flow, src_to_dst_direction, payload, payload_len); ndpi_payload_analyzer(flow, src_to_dst_direction,
payload, payload_len,
workflow->stats.ip_packet_count);
if(enable_joy_stats) { if(enable_joy_stats) {
/* Update BD, distribution and mean. */ /* Update BD, distribution and mean. */