Merge branch 'denisvm-magicnumbers' into dev

This commit is contained in:
Campus
2016-12-06 22:23:36 +01:00
3 changed files with 23 additions and 23 deletions
+7 -7
View File
@@ -675,10 +675,10 @@ char* formatTraffic(float numBits, int bits, char *buf) {
if(numBits < 1024) { if(numBits < 1024) {
snprintf(buf, 32, "%lu %c", (unsigned long)numBits, unit); snprintf(buf, 32, "%lu %c", (unsigned long)numBits, unit);
} else if(numBits < 1048576) { } else if(numBits < (1024*1024)) {
snprintf(buf, 32, "%.2f K%c", (float)(numBits)/1024, unit); snprintf(buf, 32, "%.2f K%c", (float)(numBits)/1024, unit);
} else { } else {
float tmpMBits = ((float)numBits)/1048576; float tmpMBits = ((float)numBits)/(1024*1024);
if(tmpMBits < 1024) { if(tmpMBits < 1024) {
snprintf(buf, 32, "%.2f M%c", tmpMBits, unit); snprintf(buf, 32, "%.2f M%c", tmpMBits, unit);
@@ -704,10 +704,10 @@ char* formatPackets(float numPkts, char *buf) {
if(numPkts < 1000) { if(numPkts < 1000) {
snprintf(buf, 32, "%.2f", numPkts); snprintf(buf, 32, "%.2f", numPkts);
} else if(numPkts < 1000000) { } else if(numPkts < (1000*1000)) {
snprintf(buf, 32, "%.2f K", numPkts/1000); snprintf(buf, 32, "%.2f K", numPkts/1000);
} else { } else {
numPkts /= 1000000; numPkts /= (1000*1000);
snprintf(buf, 32, "%.2f M", numPkts); snprintf(buf, 32, "%.2f M", numPkts);
} }
@@ -735,10 +735,10 @@ char* formatBytes(u_int32_t howMuch, char *buf, u_int buf_len) {
if(howMuch < 1024) { if(howMuch < 1024) {
snprintf(buf, buf_len, "%lu %c", (unsigned long)howMuch, unit); snprintf(buf, buf_len, "%lu %c", (unsigned long)howMuch, unit);
} else if(howMuch < 1048576) { } else if(howMuch < (1024*1024)) {
snprintf(buf, buf_len, "%.2f K%c", (float)(howMuch)/1024, unit); snprintf(buf, buf_len, "%.2f K%c", (float)(howMuch)/1024, unit);
} else { } else {
float tmpGB = ((float)howMuch)/1048576; float tmpGB = ((float)howMuch)/(1024*1024);
if(tmpGB < 1024) { if(tmpGB < 1024) {
snprintf(buf, buf_len, "%.2f M%c", tmpGB, unit); snprintf(buf, buf_len, "%.2f M%c", tmpGB, unit);
@@ -801,7 +801,7 @@ static void printResults(u_int64_t tot_usec) {
cumulative_stats.pppoe_count += ndpi_thread_info[thread_id].workflow->stats.pppoe_count; cumulative_stats.pppoe_count += ndpi_thread_info[thread_id].workflow->stats.pppoe_count;
cumulative_stats.vlan_count += ndpi_thread_info[thread_id].workflow->stats.vlan_count; cumulative_stats.vlan_count += ndpi_thread_info[thread_id].workflow->stats.vlan_count;
cumulative_stats.fragmented_count += ndpi_thread_info[thread_id].workflow->stats.fragmented_count; cumulative_stats.fragmented_count += ndpi_thread_info[thread_id].workflow->stats.fragmented_count;
for(i = 0; i < 6; i++) for(i = 0; i < sizeof(cumulative_stats.packet_len)/sizeof(cumulative_stats.packet_len[0]); i++)
cumulative_stats.packet_len[i] += ndpi_thread_info[thread_id].workflow->stats.packet_len[i]; cumulative_stats.packet_len[i] += ndpi_thread_info[thread_id].workflow->stats.packet_len[i];
cumulative_stats.max_packet_len += ndpi_thread_info[thread_id].workflow->stats.max_packet_len; cumulative_stats.max_packet_len += ndpi_thread_info[thread_id].workflow->stats.max_packet_len;
} }
+12 -12
View File
@@ -212,7 +212,7 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow
Note: to keep things simple (ndpiReader is just a demo app) Note: to keep things simple (ndpiReader is just a demo app)
we handle IPv6 a-la-IPv4. we handle IPv6 a-la-IPv4.
*/ */
if(version == 4) { if(version == IPVERSION) {
if(ipsize < 20) if(ipsize < 20)
return NULL; return NULL;
@@ -254,7 +254,7 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow
*proto = iph->protocol; *proto = iph->protocol;
l4 = ((u_int8_t *) l3 + l4_offset); l4 = ((u_int8_t *) l3 + l4_offset);
if(iph->protocol == 6 && l4_packet_len >= 20) { if(iph->protocol == IPPROTO_TCP && l4_packet_len >= 20) {
u_int tcp_len; u_int tcp_len;
workflow->stats.tcp_count++; workflow->stats.tcp_count++;
@@ -284,7 +284,7 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow
tcp_len = ndpi_min(4*(*tcph)->doff, l4_packet_len); tcp_len = ndpi_min(4*(*tcph)->doff, l4_packet_len);
*payload = &l4[tcp_len]; *payload = &l4[tcp_len];
*payload_len = ndpi_max(0, l4_packet_len-4*(*tcph)->doff); *payload_len = ndpi_max(0, l4_packet_len-4*(*tcph)->doff);
} else if(iph->protocol == 17 && l4_packet_len >= 8) { } else if(iph->protocol == IPPROTO_UDP && l4_packet_len >= 8) {
// udp // udp
workflow->stats.udp_count++; workflow->stats.udp_count++;
@@ -347,7 +347,7 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow
newflow->lower_port = lower_port, newflow->upper_port = upper_port; newflow->lower_port = lower_port, newflow->upper_port = upper_port;
newflow->ip_version = version; newflow->ip_version = version;
if(version == 4) { if(version == IPVERSION) {
inet_ntop(AF_INET, &lower_ip, newflow->lower_name, sizeof(newflow->lower_name)); inet_ntop(AF_INET, &lower_ip, newflow->lower_name, sizeof(newflow->lower_name));
inet_ntop(AF_INET, &upper_ip, newflow->upper_name, sizeof(newflow->upper_name)); inet_ntop(AF_INET, &upper_ip, newflow->upper_name, sizeof(newflow->upper_name));
} else { } else {
@@ -416,12 +416,12 @@ static struct ndpi_flow_info *get_ndpi_flow_info6(struct ndpi_workflow * workflo
struct ndpi_iphdr iph; struct ndpi_iphdr iph;
memset(&iph, 0, sizeof(iph)); memset(&iph, 0, sizeof(iph));
iph.version = 4; iph.version = IPVERSION;
iph.saddr = iph6->ip6_src.u6_addr.u6_addr32[2] + iph6->ip6_src.u6_addr.u6_addr32[3]; iph.saddr = iph6->ip6_src.u6_addr.u6_addr32[2] + iph6->ip6_src.u6_addr.u6_addr32[3];
iph.daddr = iph6->ip6_dst.u6_addr.u6_addr32[2] + iph6->ip6_dst.u6_addr.u6_addr32[3]; iph.daddr = iph6->ip6_dst.u6_addr.u6_addr32[2] + iph6->ip6_dst.u6_addr.u6_addr32[3];
iph.protocol = iph6->ip6_ctlun.ip6_un1.ip6_un1_nxt; iph.protocol = iph6->ip6_ctlun.ip6_un1.ip6_un1_nxt;
if(iph.protocol == 0x3C /* IPv6 destination option */) { if(iph.protocol == IPPROTO_DSTOPTS /* IPv6 destination option */) {
u_int8_t *options = (u_int8_t*)iph6 + sizeof(const struct ndpi_ipv6hdr); u_int8_t *options = (u_int8_t*)iph6 + sizeof(const struct ndpi_ipv6hdr);
iph.protocol = options[0]; iph.protocol = options[0];
@@ -461,7 +461,7 @@ static unsigned int packet_processing(struct ndpi_workflow * workflow,
u_int8_t src_to_dst_direction= 1; u_int8_t src_to_dst_direction= 1;
if(iph) if(iph)
flow = get_ndpi_flow_info(workflow, 4, vlan_id, iph, NULL, flow = get_ndpi_flow_info(workflow, IPVERSION, vlan_id, iph, NULL,
ip_offset, ipsize, ip_offset, ipsize,
ntohs(iph->tot_len) - (iph->ihl * 4), ntohs(iph->tot_len) - (iph->ihl * 4),
&tcph, &udph, &sport, &dport, &tcph, &udph, &sport, &dport,
@@ -510,7 +510,7 @@ static unsigned int packet_processing(struct ndpi_workflow * workflow,
if(flow->detected_protocol.protocol == NDPI_PROTOCOL_BITTORRENT) { if(flow->detected_protocol.protocol == NDPI_PROTOCOL_BITTORRENT) {
int i, j, n = 0; int i, j, n = 0;
for(i=0, j = 0; i<20; i++) { for(i=0, j = 0; j < sizeof(flow->bittorent_hash)-1; i++) {
sprintf(&flow->bittorent_hash[j], "%02x", flow->ndpi_flow->bittorent_hash[i]); sprintf(&flow->bittorent_hash[j], "%02x", flow->ndpi_flow->bittorent_hash[i]);
j += 2, n += flow->ndpi_flow->bittorent_hash[i]; j += 2, n += flow->ndpi_flow->bittorent_hash[i];
} }
@@ -748,11 +748,11 @@ void ndpi_workflow_process_packet (struct ndpi_workflow * workflow,
} }
} }
if(iph->version == 4) { if(iph->version == IPVERSION) {
ip_len = ((u_int16_t)iph->ihl * 4); ip_len = ((u_int16_t)iph->ihl * 4);
iph6 = NULL; iph6 = NULL;
if(iph->protocol == 41) { if(iph->protocol == IPPROTO_IPV6) {
ip_offset += ip_len; ip_offset += ip_len;
goto iph_check; goto iph_check;
} }
@@ -775,7 +775,7 @@ void ndpi_workflow_process_packet (struct ndpi_workflow * workflow,
proto = iph6->ip6_ctlun.ip6_un1.ip6_un1_nxt; proto = iph6->ip6_ctlun.ip6_un1.ip6_un1_nxt;
ip_len = sizeof(struct ndpi_ipv6hdr); ip_len = sizeof(struct ndpi_ipv6hdr);
if(proto == 0x3C /* IPv6 destination option */) { if(proto == IPPROTO_DSTOPTS /* IPv6 destination option */) {
u_int8_t *options = (u_int8_t*)&packet[ip_offset+ip_len]; u_int8_t *options = (u_int8_t*)&packet[ip_offset+ip_len];
proto = options[0]; proto = options[0];
@@ -816,7 +816,7 @@ void ndpi_workflow_process_packet (struct ndpi_workflow * workflow,
iph = (struct ndpi_iphdr *) &packet[ip_offset]; iph = (struct ndpi_iphdr *) &packet[ip_offset];
if(iph->version != 4) { if(iph->version != IPVERSION) {
// printf("WARNING: not good (packet_id=%u)!\n", (unsigned int)workflow->stats.raw_packet_count); // printf("WARNING: not good (packet_id=%u)!\n", (unsigned int)workflow->stats.raw_packet_count);
goto v4_warning; goto v4_warning;
} }
+4 -4
View File
@@ -2786,7 +2786,7 @@ static u_int8_t ndpi_detection_get_l4_internal(struct ndpi_detection_module_stru
iph = (const struct ndpi_iphdr *) l3; iph = (const struct ndpi_iphdr *) l3;
if(iph->version == 4 && iph->ihl >= 5) { if(iph->version == IPVERSION && iph->ihl >= 5) {
NDPI_LOG(NDPI_PROTOCOL_UNKNOWN, ndpi_struct, NDPI_LOG_DEBUG, "ipv4 header\n"); NDPI_LOG(NDPI_PROTOCOL_UNKNOWN, ndpi_struct, NDPI_LOG_DEBUG, "ipv4 header\n");
} }
#ifdef NDPI_DETECTION_SUPPORT_IPV6 #ifdef NDPI_DETECTION_SUPPORT_IPV6
@@ -2902,7 +2902,7 @@ static int ndpi_init_packet_header(struct ndpi_detection_module_struct *ndpi_str
} }
#endif /* NDPI_DETECTION_SUPPORT_IPV6 */ #endif /* NDPI_DETECTION_SUPPORT_IPV6 */
if(decaps_iph && decaps_iph->version == 4 && decaps_iph->ihl >= 5) { if(decaps_iph && decaps_iph->version == IPVERSION && decaps_iph->ihl >= 5) {
NDPI_LOG(NDPI_PROTOCOL_UNKNOWN, ndpi_struct, NDPI_LOG_DEBUG, "ipv4 header\n"); NDPI_LOG(NDPI_PROTOCOL_UNKNOWN, ndpi_struct, NDPI_LOG_DEBUG, "ipv4 header\n");
} }
#ifdef NDPI_DETECTION_SUPPORT_IPV6 #ifdef NDPI_DETECTION_SUPPORT_IPV6
@@ -2941,7 +2941,7 @@ static int ndpi_init_packet_header(struct ndpi_detection_module_struct *ndpi_str
flow->packet.l4_packet_len = l4len; flow->packet.l4_packet_len = l4len;
/* tcp / udp detection */ /* tcp / udp detection */
if(l4protocol == 6 /* TCP */ &&flow->packet.l4_packet_len >= 20 /* min size of tcp */ ) { if(l4protocol == IPPROTO_TCP && flow->packet.l4_packet_len >= 20 /* min size of tcp */ ) {
/* tcp */ /* tcp */
flow->packet.tcp = (struct ndpi_tcphdr *) l4ptr; flow->packet.tcp = (struct ndpi_tcphdr *) l4ptr;
@@ -2969,7 +2969,7 @@ static int ndpi_init_packet_header(struct ndpi_detection_module_struct *ndpi_str
/* tcp header not complete */ /* tcp header not complete */
flow->packet.tcp = NULL; flow->packet.tcp = NULL;
} }
} else if(l4protocol == 17 /* udp */ &&flow->packet.l4_packet_len >= 8 /* size of udp */ ) { } else if(l4protocol == IPPROTO_UDP && flow->packet.l4_packet_len >= 8 /* size of udp */ ) {
flow->packet.udp = (struct ndpi_udphdr *) l4ptr; flow->packet.udp = (struct ndpi_udphdr *) l4ptr;
flow->packet.payload_packet_len =flow->packet.l4_packet_len - 8; flow->packet.payload_packet_len =flow->packet.l4_packet_len - 8;
flow->packet.payload = ((u_int8_t *)flow->packet.udp) + 8; flow->packet.payload = ((u_int8_t *)flow->packet.udp) + 8;