From 85ad7810e3abfb565d2d0095273937a3d44a1655 Mon Sep 17 00:00:00 2001 From: Pavel Odintsov Date: Mon, 31 Jul 2023 11:35:37 +0100 Subject: [PATCH] Unified logic to serialise attack information --- src/fast_library.cpp | 14 ++++++++++++++ src/fast_library.hpp | 4 ++++ src/fastnetmon_logic.cpp | 12 +----------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/fast_library.cpp b/src/fast_library.cpp index 12568375..2a3f4e19 100644 --- a/src/fast_library.cpp +++ b/src/fast_library.cpp @@ -2451,3 +2451,17 @@ bool subnet_belongs_to_patricia_tree(patricia_tree_t* patricia_tree, const subne } } +// Prepares textual dump of simple packets buffer +void print_simple_packet_buffer_to_string(const boost::circular_buffer& simple_packets_buffer, std::string& output) { + if (simple_packets_buffer.size() != 0) { + std::stringstream ss; + + for (const simple_packet_t& packet : simple_packets_buffer) { + ss << print_simple_packet(packet); + } + + output = ss.str(); + } +} + + diff --git a/src/fast_library.hpp b/src/fast_library.hpp index e7eeee98..2dd0fbc8 100644 --- a/src/fast_library.hpp +++ b/src/fast_library.hpp @@ -19,6 +19,8 @@ #include "attack_details.hpp" +#include + #define TCP_FIN_FLAG_SHIFT 1 #define TCP_SYN_FLAG_SHIFT 2 #define TCP_RST_FLAG_SHIFT 3 @@ -166,3 +168,5 @@ std::string convert_any_subnet_to_string(const subnet_cidr_mask_t& subnet); std::string print_binary_string_as_hex_with_leading_0x(const uint8_t* data_ptr, uint32_t data_length); bool read_ipv6_subnet_from_string(subnet_ipv6_cidr_mask_t& ipv6_address, const std::string& ipv6_subnet_as_string); bool subnet_belongs_to_patricia_tree(patricia_tree_t* patricia_tree, const subnet_cidr_mask_t& subnet); +// Prepares textual dump of simple packets buffer +void print_simple_packet_buffer_to_string(const boost::circular_buffer& simple_packets_buffer, std::string& output); diff --git a/src/fastnetmon_logic.cpp b/src/fastnetmon_logic.cpp index eeb47c7b..6db8f37c 100644 --- a/src/fastnetmon_logic.cpp +++ b/src/fastnetmon_logic.cpp @@ -1267,18 +1267,8 @@ void call_blackhole_actions_per_host(attack_action_t attack_action, action_name = "unban"; } - // For all attack types at this moment we could prepare simple packet dump std::string simple_packets_dump; - - if (simple_packets_buffer.size() != 0) { - std::stringstream ss; - - for (const simple_packet_t& packet : simple_packets_buffer) { - ss << print_simple_packet(packet); - } - - simple_packets_dump = ss.str(); - } + print_simple_packet_buffer_to_string(simple_packets_buffer, simple_packets_dump); std::string basic_attack_information_in_json = get_attack_description_in_json_for_web_hooks(client_ip, subnet_ipv6_cidr_mask_t{}, false, action_name, current_attack);