mirror of
https://github.com/pavel-odintsov/fastnetmon
synced 2024-11-23 00:52:00 +01:00
Added logic to make compiler more verbose about variety of code issues
This commit is contained in:
parent
36d66016ad
commit
0b76fc02ae
@ -39,6 +39,12 @@ set(LIB_CPP_KAFKA_INSTALL_PATH "${FASTNETMON_LIBRARIES_GLOBAL_PATH}/cppkafka_0_3
|
||||
set(LIB_RDKAFKA_INSTALL_PATH "${FASTNETMON_LIBRARIES_GLOBAL_PATH}/rdkafka_1_7_0")
|
||||
set(GTEST_INSTALL_PATH "${FASTNETMON_LIBRARIES_GLOBAL_PATH}/gtest_1_13_0")
|
||||
|
||||
# -Wunused includes more warnings than -Wall
|
||||
# In order to get a warning about an unused function parameter, you must either specify -Wextra -Wunused (note that -Wall implies -Wunused), or separately specify -Wunused-parameter.
|
||||
# TODO: return -Wunused-parameter and address all warning later, I started it but did not finish as we have too many of them
|
||||
# catch-value is documented here: https://patchwork.ozlabs.org/project/gcc/patch/tkrat.8c7b4260a533be2f@netcologne.de/#1680619
|
||||
add_definitions("-Wreorder -Wunused -Wparentheses -Wimplicit-fallthrough -Wreturn-type -Wuninitialized -Winit-self -Wmaybe-uninitialized -Wcatch-value=3 -Wclass-memaccess")
|
||||
|
||||
# On Windows we need to build libgcc and libstdc++ statically to avoid need to carry dlls with us
|
||||
if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
set(CMAKE_CXX_STANDARD_LIBRARIES "-static-libgcc -static-libstdc++ ${CMAKE_CXX_STANDARD_LIBRARIES}")
|
||||
|
@ -619,7 +619,7 @@ std::string print_flow_tracking_for_specified_protocol(contrack_map_type& protoc
|
||||
|
||||
uint64_t packed_connection_data = itr->first;
|
||||
packed_conntrack_hash_t unpacked_key_struct;
|
||||
convert_integer_to_conntrack_hash_struct(&packed_connection_data, &unpacked_key_struct);
|
||||
convert_integer_to_conntrack_hash_struct(packed_connection_data, unpacked_key_struct);
|
||||
|
||||
std::string opposite_ip_as_string = convert_ip_as_uint_to_string(unpacked_key_struct.opposite_ip);
|
||||
if (flow_direction == INCOMING) {
|
||||
@ -639,8 +639,14 @@ std::string print_flow_tracking_for_specified_protocol(contrack_map_type& protoc
|
||||
return buffer.str();
|
||||
}
|
||||
|
||||
void convert_integer_to_conntrack_hash_struct(packed_session* packed_connection_data, packed_conntrack_hash_t* unpacked_data) {
|
||||
memcpy(unpacked_data, packed_connection_data, sizeof(uint64_t));
|
||||
void convert_integer_to_conntrack_hash_struct(const uint64_t& packed_connection_data, packed_conntrack_hash_t& unpacked_data) {
|
||||
// Normally this code will trigger
|
||||
// warning: ‘void* memcpy(void*, const void*, size_t)’ copying an object of non-trivial type ‘class
|
||||
// packed_conntrack_hash_t’ from an array of ‘const uint64_t’ {aka ‘const long unsigned int’} [-Wclass-memaccess]
|
||||
// Yes, it's very bad practice to overwrite struct memory that way but we have enough safe guards (such as
|
||||
// explicitly packed structure and static_assert with sizeof check for structure size) in place to do it We apply
|
||||
// void* for target argument to suppress this warning
|
||||
memcpy((void*)&unpacked_data, &packed_connection_data, sizeof(uint64_t));
|
||||
}
|
||||
|
||||
// This function returns true when attack for particular IPv6 or IPv4 address is finished
|
||||
@ -1109,7 +1115,7 @@ bool process_flow_tracking_table(conntrack_main_struct_t& conntrack_element, std
|
||||
for (contrack_map_type::iterator itr = conntrack_element.in_tcp.begin(); itr != conntrack_element.in_tcp.end(); ++itr) {
|
||||
uint64_t packed_connection_data = itr->first;
|
||||
packed_conntrack_hash_t unpacked_key_struct;
|
||||
convert_integer_to_conntrack_hash_struct(&packed_connection_data, &unpacked_key_struct);
|
||||
convert_integer_to_conntrack_hash_struct(packed_connection_data, unpacked_key_struct);
|
||||
|
||||
uniq_remote_hosts_which_generate_requests_to_us[unpacked_key_struct.opposite_ip]++;
|
||||
uniq_local_ports_which_target_of_connectiuons_from_inside[unpacked_key_struct.dst_port]++;
|
||||
@ -1639,8 +1645,6 @@ bool fill_attack_information(
|
||||
uint64_t out_pps = current_attack.traffic_counters.total.out_packets;
|
||||
uint64_t in_bps = current_attack.traffic_counters.total.in_bytes;
|
||||
uint64_t out_bps = current_attack.traffic_counters.total.out_bytes;
|
||||
uint64_t in_flows = current_attack.traffic_counters.in_flows;
|
||||
uint64_t out_flows = current_attack.traffic_counters.out_flows;
|
||||
|
||||
direction_t data_direction;
|
||||
|
||||
@ -1779,7 +1783,6 @@ void speed_calculation_callback_local_ipv4(const uint32_t& client_ip, const subn
|
||||
extern patricia_tree_t* whitelist_tree_ipv4;
|
||||
extern patricia_tree_t* lookup_tree_ipv4;
|
||||
|
||||
extern std::mutex ipv4_packets_circular_buffer_mutex;
|
||||
extern boost::circular_buffer<simple_packet_t> ipv4_packets_circular_buffer;
|
||||
|
||||
// Check global ban settings
|
||||
@ -1967,8 +1970,6 @@ void recalculate_speed() {
|
||||
speed_calc_period = time_difference;
|
||||
}
|
||||
|
||||
subnet_counter_t zero_map_element{};
|
||||
|
||||
uint64_t incoming_total_flows = 0;
|
||||
uint64_t outgoing_total_flows = 0;
|
||||
|
||||
@ -2357,8 +2358,6 @@ void collect_traffic_to_buckets_ipv6(const simple_packet_t& current_packet, pack
|
||||
|
||||
// Process IPv6 traffic
|
||||
void process_ipv6_packet(simple_packet_t& current_packet) {
|
||||
extern bool kafka_traffic_export;
|
||||
|
||||
uint64_t sampled_number_of_packets = current_packet.number_of_packets * current_packet.sample_ratio;
|
||||
uint64_t sampled_number_of_bytes = current_packet.length * current_packet.sample_ratio;
|
||||
|
||||
@ -2443,7 +2442,6 @@ void collect_traffic_to_buckets_ipv4(const simple_packet_t& current_packet, pack
|
||||
|
||||
// Process simple unified packet
|
||||
void process_packet(simple_packet_t& current_packet) {
|
||||
extern bool kafka_traffic_export;
|
||||
extern abstract_subnet_counters_t<uint32_t, subnet_counter_t> ipv4_host_counters;
|
||||
extern packet_buckets_storage_t<uint32_t> packet_buckets_ipv4_storage;
|
||||
|
||||
@ -2516,12 +2514,6 @@ void process_packet(simple_packet_t& current_packet) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t subnet_in_host_byte_order = 0;
|
||||
// We operate in host bytes order and need to convert subnet
|
||||
if (!current_subnet.is_zero_subnet()) {
|
||||
subnet_in_host_byte_order = ntohl(current_subnet.subnet_address);
|
||||
}
|
||||
|
||||
if (current_packet.packet_direction == OUTGOING or current_packet.packet_direction == INCOMING) {
|
||||
std::lock_guard<std::mutex> lock_guard(ipv4_network_counters.counter_map_mutex);
|
||||
|
||||
|
@ -30,7 +30,7 @@ std::string print_subnet_ipv4_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, direction_t flow_direction);
|
||||
|
||||
void convert_integer_to_conntrack_hash_struct(packed_session* packed_connection_data, packed_conntrack_hash_t* unpacked_data);
|
||||
void convert_integer_to_conntrack_hash_struct(const uint64_t& packed_connection_data, packed_conntrack_hash_t& unpacked_data);
|
||||
|
||||
void cleanup_ban_list();
|
||||
|
||||
|
@ -4,8 +4,6 @@
|
||||
|
||||
// Encode simple packet into Protobuf
|
||||
bool write_simple_packet_to_protobuf(const simple_packet_t& packet, TrafficData& traffic_data) {
|
||||
extern log4cpp::Category& logger;
|
||||
|
||||
// Numbers before field match fields from proto file: traffic_data.proto
|
||||
|
||||
// 1 we use arrival_time as traffic telemetry protocols do not provide this time in a reliable manner
|
||||
|
Loading…
Reference in New Issue
Block a user