Add function for direction detection for IPv6 traffic. Add separate counter for IPv6 packets which belongs to us. Switch from increment to atomic increment for IPv6 counters.
This commit is contained in:
parent
41a9701530
commit
ee8948ac13
|
@ -748,6 +748,45 @@ std::string print_ipv6_address(struct in6_addr& ipv6_address) {
|
|||
return result;
|
||||
}
|
||||
|
||||
direction get_packet_direction_ipv6(patricia_tree_t* lookup_tree, struct in6_addr src_ipv6, struct in6_addr dst_ipv6) {
|
||||
direction packet_direction;
|
||||
|
||||
bool our_ip_is_destination = false;
|
||||
bool our_ip_is_source = false;
|
||||
|
||||
prefix_t prefix_for_check_address;
|
||||
prefix_for_check_address.family = AF_INET6;
|
||||
prefix_for_check_address.bitlen = 128;
|
||||
|
||||
patricia_node_t* found_patrica_node = NULL;
|
||||
prefix_for_check_address.add.sin6 = dst_ipv6;
|
||||
|
||||
found_patrica_node = patricia_search_best2(lookup_tree, &prefix_for_check_address, 1);
|
||||
|
||||
if (found_patrica_node) {
|
||||
our_ip_is_destination = true;
|
||||
}
|
||||
|
||||
found_patrica_node = NULL;
|
||||
prefix_for_check_address.add.sin6 = src_ipv6;
|
||||
|
||||
if (found_patrica_node) {
|
||||
our_ip_is_source = true;
|
||||
}
|
||||
|
||||
if (our_ip_is_source && our_ip_is_destination) {
|
||||
packet_direction = INTERNAL;
|
||||
} else if (our_ip_is_source) {
|
||||
packet_direction = OUTGOING;
|
||||
} else if (our_ip_is_destination) {
|
||||
packet_direction = INCOMING;
|
||||
} else {
|
||||
packet_direction = OTHER;
|
||||
}
|
||||
|
||||
return packet_direction;
|
||||
}
|
||||
|
||||
/* Get traffic type: check it belongs to our IPs */
|
||||
direction get_packet_direction(patricia_tree_t* lookup_tree, uint32_t src_ip, uint32_t dst_ip, unsigned long& subnet, unsigned int& subnet_cidr_mask) {
|
||||
direction packet_direction;
|
||||
|
|
|
@ -91,6 +91,8 @@ bool read_pid_from_file(pid_t& pid, std::string pid_path);
|
|||
|
||||
direction get_packet_direction(patricia_tree_t* lookup_tree, uint32_t src_ip, uint32_t dst_ip, unsigned long& subnet, unsigned int& subnet_cidr_mask);
|
||||
|
||||
direction get_packet_direction_ipv6(patricia_tree_t* lookup_tree, struct in6_addr src_ipv6, struct in6_addr dst_ipv6);
|
||||
|
||||
std::string convert_prefix_to_string_representation(prefix_t* prefix);
|
||||
std::string find_subnet_by_ip_in_string_format(patricia_tree_t* patricia_tree, std::string ip);
|
||||
std::string convert_subnet_to_string(subnet_t my_subnet);
|
||||
|
|
|
@ -258,6 +258,9 @@ uint64_t total_unparsed_packets = 0;
|
|||
// Total amount of IPv6 packets
|
||||
uint64_t total_ipv6_packets = 0;
|
||||
|
||||
// IPv6 traffic which belongs to our own networks
|
||||
uint64_t our_ipv6_packets = 0;
|
||||
|
||||
uint64_t incoming_total_flows_speed = 0;
|
||||
uint64_t outgoing_total_flows_speed = 0;
|
||||
|
||||
|
@ -1303,6 +1306,13 @@ bool load_our_networks_list() {
|
|||
make_and_lookup(lookup_tree_ipv4, const_cast<char*>(network_address_in_cidr_form.c_str()));
|
||||
}
|
||||
|
||||
for (std::vector<std::string>::iterator ii = networks_list_ipv6_as_string.begin();
|
||||
ii != networks_list_ipv6_as_string.end(); ++ii) {
|
||||
|
||||
// TODO: add IPv6 subnet format validation
|
||||
make_and_lookup_ipv6(lookup_tree_ipv6, (char*)ii->c_str());
|
||||
}
|
||||
|
||||
logger << log4cpp::Priority::INFO
|
||||
<< "Total number of monitored hosts (total size of all networks): " << total_number_of_hosts_in_our_networks;
|
||||
|
||||
|
@ -1333,7 +1343,13 @@ void process_packet(simple_packet& current_packet) {
|
|||
}
|
||||
|
||||
if (current_packet.ip_protocol_version == 6) {
|
||||
total_ipv6_packets++;
|
||||
__sync_fetch_and_add(&total_ipv6_packets, 1);
|
||||
|
||||
direction packet_direction = get_packet_direction_ipv6(lookup_tree_ipv6, current_packet.src_ipv6, current_packet.dst_ipv6);
|
||||
|
||||
if (packet_direction != OTHER) {
|
||||
__sync_fetch_and_add(&our_ipv6_packets, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// We do not process IPv6 at all on this mement
|
||||
|
@ -2059,6 +2075,7 @@ void traffic_draw_programm() {
|
|||
}
|
||||
|
||||
output_buffer << "Total amount of IPv6 packets: " << total_ipv6_packets << "\n";
|
||||
output_buffer << "Total amount of IPv6 packets related to our own network: " << our_ipv6_packets << "\n";
|
||||
output_buffer << "Total amount of not processed packets: " << total_unparsed_packets << "\n";
|
||||
|
||||
// Print backend stats
|
||||
|
|
Loading…
Reference in New Issue