Added per subnet counters for IPv6 and they work
This commit is contained in:
parent
fd8930b27e
commit
09a43cef4e
|
@ -1418,3 +1418,14 @@ bool write_simple_packet(int fd, simple_packet_t& packet, bool populate_ipv6) {
|
|||
return true;
|
||||
}
|
||||
|
||||
// Represent IPv6 cidr subnet in string form
|
||||
std::string print_ipv6_cidr_subnet(subnet_ipv6_cidr_mask_t subnet) {
|
||||
return print_ipv6_address(subnet.subnet_address) + "/" + std::to_string(subnet.cidr_prefix_length);
|
||||
}
|
||||
|
||||
// Abstract function with overloads for templated classes where we use v4 and v4
|
||||
std::string convert_any_ip_to_string(subnet_ipv6_cidr_mask_t subnet) {
|
||||
return print_ipv6_cidr_subnet(subnet);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -118,4 +118,6 @@ bool get_interface_number_by_device_name(int socket_fd, std::string interface_na
|
|||
bool set_boost_process_name(boost::thread* thread, std::string process_name);
|
||||
std::string convert_subnet_to_string(subnet_cidr_mask_t my_subnet);
|
||||
|
||||
std::string print_ipv6_cidr_subnet(subnet_ipv6_cidr_mask_t subnet);
|
||||
std::string convert_any_ip_to_string(subnet_ipv6_cidr_mask_t subnet);
|
||||
#endif
|
||||
|
|
|
@ -2125,10 +2125,52 @@ void traffic_draw_ipv6_program() {
|
|||
|
||||
output_buffer << std::endl;
|
||||
|
||||
if (enable_subnet_counters) {
|
||||
output_buffer << std::endl << "Subnet load:" << std::endl;
|
||||
output_buffer << print_subnet_ipv6_load() << "\n";
|
||||
}
|
||||
|
||||
// Print screen contents into file
|
||||
print_screen_contents_into_file(output_buffer.str(), cli_stats_ipv6_file_path);
|
||||
}
|
||||
|
||||
std::string print_subnet_ipv6_load() {
|
||||
std::stringstream buffer;
|
||||
|
||||
sort_type_t sorter_type;
|
||||
if (sort_parameter == "packets") {
|
||||
sorter_type = PACKETS;
|
||||
} else if (sort_parameter == "bytes") {
|
||||
sorter_type = BYTES;
|
||||
} else if (sort_parameter == "flows") {
|
||||
sorter_type = FLOWS;
|
||||
} else {
|
||||
logger << log4cpp::Priority::INFO << "Unexpected sorter type: " << sort_parameter;
|
||||
sorter_type = PACKETS;
|
||||
}
|
||||
|
||||
direction_t sort_direction = OUTGOING;
|
||||
|
||||
std::vector<pair_of_map_for_ipv6_subnet_counters_elements_t> vector_for_sort;
|
||||
ipv6_subnet_counters.get_sorted_average_speed(vector_for_sort, sorter_type, sort_direction);
|
||||
|
||||
|
||||
for (std::vector<pair_of_map_for_ipv6_subnet_counters_elements_t>::iterator itr = vector_for_sort.begin();
|
||||
itr != vector_for_sort.end(); ++itr) {
|
||||
map_element_t* speed = &itr->second;
|
||||
std::string subnet_as_string = print_ipv6_cidr_subnet(itr->first);
|
||||
|
||||
buffer << std::setw(42) << std::left << subnet_as_string;
|
||||
|
||||
buffer << " "
|
||||
<< "pps in: " << std::setw(8) << speed->in_packets << " out: " << std::setw(8)
|
||||
<< speed->out_packets << " mbps in: " << std::setw(5) << convert_speed_to_mbps(speed->in_bytes)
|
||||
<< " out: " << std::setw(5) << convert_speed_to_mbps(speed->out_bytes) << "\n";
|
||||
}
|
||||
|
||||
return buffer.str();
|
||||
}
|
||||
|
||||
void traffic_draw_ipv4_program() {
|
||||
std::stringstream output_buffer;
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ logging_configuration_t read_logging_settings(configuration_map_t configuration_
|
|||
void print_attack_details_to_file(std::string details, std::string client_ip_as_string, attack_details current_attack);
|
||||
std::string print_ban_thresholds(ban_settings_t current_ban_settings);
|
||||
std::string print_subnet_ipv4_load();
|
||||
std::string print_subnet_ipv6_load();
|
||||
std::string print_flow_tracking_for_ip(conntrack_main_struct_t& conntrack_element, std::string client_ip);
|
||||
std::string print_flow_tracking_for_specified_protocol(contrack_map_type& protocol_map,
|
||||
std::string client_ip,
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <sys/time.h> // struct timeval
|
||||
#include <utility> // std::pair
|
||||
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -206,6 +207,11 @@ typedef map_element_t subnet_counter_t;
|
|||
typedef std::pair<subnet_cidr_mask_t, subnet_counter_t> pair_of_map_for_subnet_counters_elements_t;
|
||||
typedef std::map<subnet_cidr_mask_t, subnet_counter_t> map_for_subnet_counters_t;
|
||||
|
||||
// IPv6 per subnet counters
|
||||
typedef std::pair<subnet_ipv6_cidr_mask_t, subnet_counter_t> pair_of_map_for_ipv6_subnet_counters_elements_t;
|
||||
typedef std::unordered_map<subnet_ipv6_cidr_mask_t, subnet_counter_t> map_for_ipv6_subnet_counters_t;
|
||||
|
||||
|
||||
class packed_conntrack_hash_t {
|
||||
public:
|
||||
packed_conntrack_hash_t() : opposite_ip(0), src_port(0), dst_port(0) {
|
||||
|
|
Loading…
Reference in New Issue