diff --git a/src/fastnetmon.cpp b/src/fastnetmon.cpp index 5308244..2a67506 100644 --- a/src/fastnetmon.cpp +++ b/src/fastnetmon.cpp @@ -191,6 +191,12 @@ map_of_vector_counters SubnetVectorMap; // Flow tracking structures map_of_vector_counters_for_flow SubnetVectorMapFlow; +typedef std::vector lookup_vector_indexes_t; +typedef std::vector lookup_vector_data_t; + +lookup_vector_indexes_t lookup_vector_indexes; +lookup_vector_data_t lookup_vector_data; + /* End of our data structs */ boost::mutex data_counters_mutex; @@ -969,12 +975,22 @@ bool load_our_networks_list() { /* Preallocate data structures */ - patricia_process (lookup_tree, (void_fn_t)subnet_vectors_allocator); - logger<first); + lookup_vector_data.push_back(ii->second); + } + logger<= itr->second.size()) { + if (shift_in_vector < 0 or shift_in_vector >= itr->size()) { logger<< log4cpp::Priority::ERROR<<"We tried to access to element with index "<second.size(); + <<" which located outside allocated vector with size "<size(); logger<< log4cpp::Priority::ERROR<<"We expect issues with this packet in OUTGOING direction: "<second[shift_in_vector]; + map_element* current_element = &(*itr)[shift_in_vector]; // Main packet/bytes counter __sync_fetch_and_add(¤t_element->out_packets, sampled_number_of_packets); @@ -1135,16 +1154,16 @@ void process_packet(simple_packet& current_packet) { } else if (packet_direction == INCOMING) { int64_t shift_in_vector = (int64_t)ntohl(current_packet.dst_ip) - (int64_t)subnet_in_host_byte_order; - if (shift_in_vector < 0 or shift_in_vector >= itr->second.size()) { + if (shift_in_vector < 0 or shift_in_vector >= itr->size()) { logger<< log4cpp::Priority::ERROR<<"We tried to access to element with index "<second.size(); + <<" which located outside allocated vector with size "<size(); logger<< log4cpp::Priority::INFO<<"We expect issues with this packet in INCOMING direction: "<second[shift_in_vector]; + map_element* current_element = &(*itr)[shift_in_vector]; // Main packet/bytes counter __sync_fetch_and_add(¤t_element->in_packets, sampled_number_of_packets); @@ -1307,15 +1326,17 @@ void recalculate_speed() { uint64_t incoming_total_flows = 0; uint64_t outgoing_total_flows = 0; - for (map_of_vector_counters::iterator itr = SubnetVectorMap.begin(); itr != SubnetVectorMap.end(); ++itr) { - for (vector_of_counters::iterator vector_itr = itr->second.begin(); vector_itr != itr->second.end(); ++vector_itr) { - int current_index = vector_itr - itr->second.begin(); + for (lookup_vector_indexes_t::iterator itr = lookup_vector_indexes.begin(); itr != lookup_vector_indexes.end(); ++itr) { + vector_of_counters* vector_pointer = &lookup_vector_data[ itr - lookup_vector_indexes.begin() ]; + + for (vector_of_counters::iterator vector_itr = vector_pointer->begin(); vector_itr != vector_pointer->end(); ++vector_itr) { + int current_index = vector_itr - vector_pointer->begin(); // New element map_element new_speed_element; // convert to host order for math operations - uint32_t subnet_ip = ntohl(itr->first); + uint32_t subnet_ip = ntohl(*itr); uint32_t client_ip_in_host_bytes_order = subnet_ip + current_index; // covnert to our standard network byte order @@ -1364,7 +1385,7 @@ void recalculate_speed() { new_speed_element.icmp_in_bytes = uint64_t((double)vector_itr->icmp_in_bytes / speed_calc_period); new_speed_element.icmp_out_bytes = uint64_t((double)vector_itr->icmp_out_bytes / speed_calc_period); - conntrack_main_struct* flow_counter_ptr = &SubnetVectorMapFlow[itr->first][current_index]; + conntrack_main_struct* flow_counter_ptr = &SubnetVectorMapFlow[*itr][current_index]; // todo: optimize this operations! uint64_t total_out_flows =