2015-05-14 17:21:26 +02:00
|
|
|
#ifndef FAST_LIBRARY_H
|
|
|
|
#define FAST_LIBRARY_H
|
2015-03-21 11:47:25 +01:00
|
|
|
|
2015-03-21 12:24:31 +01:00
|
|
|
#include "fastnetmon_types.h"
|
|
|
|
|
2022-02-09 15:27:32 +01:00
|
|
|
#include <iostream>
|
|
|
|
#include <map>
|
|
|
|
#include <sstream>
|
2015-03-21 11:47:25 +01:00
|
|
|
#include <stdint.h>
|
2022-02-09 15:27:32 +01:00
|
|
|
#include <string>
|
2015-03-21 11:47:25 +01:00
|
|
|
#include <sys/types.h>
|
2015-05-02 22:53:45 +02:00
|
|
|
#include <unistd.h>
|
2015-03-21 12:24:31 +01:00
|
|
|
#include <utility>
|
2022-02-09 15:27:32 +01:00
|
|
|
#include <vector>
|
2015-03-21 12:24:31 +01:00
|
|
|
|
2022-02-09 15:27:32 +01:00
|
|
|
#include <boost/regex.hpp>
|
2015-03-21 12:24:31 +01:00
|
|
|
#include <boost/thread.hpp>
|
|
|
|
#include <boost/thread/mutex.hpp>
|
|
|
|
|
2015-08-12 19:30:27 +02:00
|
|
|
#include <json-c/json.h>
|
|
|
|
|
2015-03-21 12:24:31 +01:00
|
|
|
// Boost libs
|
|
|
|
#include <boost/algorithm/string.hpp>
|
2015-03-21 11:47:25 +01:00
|
|
|
|
2015-05-18 12:38:19 +02:00
|
|
|
#include "libpatricia/patricia.h"
|
|
|
|
|
2015-07-03 17:01:18 +02:00
|
|
|
#ifdef ENABLE_LUA_HOOKS
|
|
|
|
#include <luajit-2.0/lua.hpp>
|
|
|
|
#endif
|
|
|
|
|
2022-02-15 18:11:11 +01:00
|
|
|
#include "fast_endianless.hpp"
|
|
|
|
|
2015-05-07 11:48:43 +02:00
|
|
|
#define TCP_FIN_FLAG_SHIFT 1
|
|
|
|
#define TCP_SYN_FLAG_SHIFT 2
|
|
|
|
#define TCP_RST_FLAG_SHIFT 3
|
|
|
|
#define TCP_PSH_FLAG_SHIFT 4
|
|
|
|
#define TCP_ACK_FLAG_SHIFT 5
|
|
|
|
#define TCP_URG_FLAG_SHIFT 6
|
|
|
|
|
2015-05-10 20:42:49 +02:00
|
|
|
typedef std::map<std::string, uint64_t> graphite_data_t;
|
2015-05-11 17:50:01 +02:00
|
|
|
typedef std::vector<std::string> interfaces_list_t;
|
|
|
|
typedef std::vector<std::string> ip_addresses_list_t;
|
|
|
|
|
2015-08-10 12:05:53 +02:00
|
|
|
ip_addresses_list_t get_local_ip_v4_addresses_list();
|
2015-05-11 17:50:01 +02:00
|
|
|
ip_addresses_list_t get_ip_list_for_interface(std::string interface);
|
|
|
|
interfaces_list_t get_interfaces_list();
|
2015-05-10 20:42:49 +02:00
|
|
|
|
|
|
|
bool store_data_to_graphite(unsigned short int graphite_port, std::string graphite_host, graphite_data_t graphite_data);
|
2015-03-21 12:24:31 +01:00
|
|
|
std::string get_protocol_name_by_number(unsigned int proto_number);
|
|
|
|
uint64_t convert_speed_to_mbps(uint64_t speed_in_bps);
|
|
|
|
std::vector<std::string> exec(std::string cmd);
|
|
|
|
uint32_t convert_ip_as_string_to_uint(std::string ip);
|
|
|
|
std::string convert_ip_as_uint_to_string(uint32_t ip_as_integer);
|
|
|
|
std::string convert_int_to_string(int value);
|
2015-06-18 14:42:56 +02:00
|
|
|
std::string print_ipv6_address(struct in6_addr& ipv6_address);
|
2022-02-11 13:38:08 +01:00
|
|
|
std::string print_simple_packet(simple_packet_t packet);
|
2015-03-21 12:24:31 +01:00
|
|
|
std::string convert_timeval_to_date(struct timeval tv);
|
2018-09-28 17:59:49 +02:00
|
|
|
bool convert_hex_as_string_to_uint(std::string hex, uint32_t& value);
|
2015-06-15 11:14:30 +02:00
|
|
|
|
2015-03-21 12:24:31 +01:00
|
|
|
int extract_bit_value(uint8_t num, int bit);
|
2015-06-15 11:14:30 +02:00
|
|
|
int extract_bit_value(uint16_t num, int bit);
|
|
|
|
|
|
|
|
int clear_bit_value(uint8_t& num, int bit);
|
|
|
|
int clear_bit_value(uint16_t& num, int bit);
|
|
|
|
|
|
|
|
int set_bit_value(uint8_t& num, int bit);
|
|
|
|
int set_bit_value(uint16_t& num, int bit);
|
|
|
|
|
2015-03-21 12:24:31 +01:00
|
|
|
std::string print_tcp_flags(uint8_t flag_value);
|
2015-05-15 12:55:52 +02:00
|
|
|
uint64_t MurmurHash64A(const void* key, int len, uint64_t seed);
|
2015-03-21 12:24:31 +01:00
|
|
|
std::string print_tcp_flags(uint8_t flag_value);
|
2015-05-15 12:55:52 +02:00
|
|
|
int timeval_subtract(struct timeval* result, struct timeval* x, struct timeval* y);
|
2015-03-21 12:24:31 +01:00
|
|
|
bool folder_exists(std::string path);
|
2018-08-03 00:53:47 +02:00
|
|
|
bool is_cidr_subnet(std::string subnet);
|
2015-10-16 12:16:46 +02:00
|
|
|
bool is_v4_host(std::string host);
|
2015-03-21 12:24:31 +01:00
|
|
|
bool file_exists(std::string path);
|
|
|
|
uint32_t convert_cidr_to_binary_netmask(unsigned int cidr);
|
|
|
|
std::string get_printable_protocol_name(unsigned int protocol);
|
|
|
|
std::string get_net_address_from_network_as_string(std::string network_cidr_format);
|
|
|
|
std::string print_time_t_in_fastnetmon_format(time_t current_time);
|
|
|
|
unsigned int get_cidr_mask_from_network_as_string(std::string network_cidr_format);
|
2015-05-15 12:55:52 +02:00
|
|
|
void copy_networks_from_string_form_to_binary(std::vector<std::string> networks_list_as_string,
|
2015-05-21 18:34:17 +02:00
|
|
|
std::vector<subnet_t>& our_networks);
|
2015-03-21 11:47:25 +01:00
|
|
|
int convert_string_to_integer(std::string line);
|
|
|
|
|
2015-09-24 01:23:38 +02:00
|
|
|
bool print_pid_to_file(pid_t pid, std::string pid_path);
|
2015-05-02 22:53:45 +02:00
|
|
|
bool read_pid_from_file(pid_t& pid, std::string pid_path);
|
|
|
|
|
2022-02-09 15:27:32 +01:00
|
|
|
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);
|
2015-06-28 22:29:40 +02:00
|
|
|
|
2015-08-10 12:58:17 +02:00
|
|
|
direction get_packet_direction_ipv6(patricia_tree_t* lookup_tree, struct in6_addr src_ipv6, struct in6_addr dst_ipv6);
|
|
|
|
|
2015-05-18 12:38:19 +02:00
|
|
|
std::string convert_prefix_to_string_representation(prefix_t* prefix);
|
2015-05-18 13:07:55 +02:00
|
|
|
std::string find_subnet_by_ip_in_string_format(patricia_tree_t* patricia_tree, std::string ip);
|
2015-05-21 18:34:17 +02:00
|
|
|
std::string convert_subnet_to_string(subnet_t my_subnet);
|
2015-06-28 22:29:40 +02:00
|
|
|
std::string get_direction_name(direction direction_value);
|
2015-07-04 23:12:10 +02:00
|
|
|
subnet_t convert_subnet_from_string_to_binary(std::string subnet_cidr);
|
2022-02-09 15:27:32 +01:00
|
|
|
std::vector<std::string> split_strings_to_vector_by_comma(std::string raw_string);
|
2015-07-07 21:57:19 +02:00
|
|
|
subnet_t convert_subnet_from_string_to_binary_with_cidr_format(std::string subnet_cidr);
|
2015-05-18 12:38:19 +02:00
|
|
|
|
2015-06-30 11:46:49 +02:00
|
|
|
#ifdef __linux__
|
|
|
|
bool manage_interface_promisc_mode(std::string interface_name, bool switch_on);
|
|
|
|
#endif
|
|
|
|
|
2015-07-03 17:01:18 +02:00
|
|
|
#ifdef ENABLE_LUA_HOOKS
|
2015-07-03 17:06:00 +02:00
|
|
|
lua_State* init_lua_jit(std::string lua_hooks_path);
|
2022-02-09 15:27:32 +01:00
|
|
|
bool call_lua_function(std::string function_name,
|
|
|
|
lua_State* lua_state_param,
|
|
|
|
std::string client_addres_in_string_format,
|
|
|
|
void* ptr);
|
2015-07-03 17:01:18 +02:00
|
|
|
#endif
|
|
|
|
|
2015-08-12 16:19:15 +02:00
|
|
|
std::string serialize_attack_description(attack_details& current_attack);
|
|
|
|
attack_type_t detect_attack_type(attack_details& current_attack);
|
|
|
|
std::string get_printable_attack_name(attack_type_t attack);
|
2015-08-12 19:30:27 +02:00
|
|
|
std::string serialize_network_load_to_text(map_element& network_speed_meter, bool average);
|
|
|
|
json_object* serialize_attack_description_to_json(attack_details& current_attack);
|
|
|
|
json_object* serialize_network_load_to_json(map_element& network_speed_meter);
|
|
|
|
std::string serialize_statistic_counters_about_attack(attack_details& current_attack);
|
2015-08-12 16:19:15 +02:00
|
|
|
|
2015-09-25 23:24:50 +02:00
|
|
|
std::string dns_lookup(std::string domain_name);
|
|
|
|
bool store_data_to_stats_server(unsigned short int graphite_port, std::string graphite_host, std::string buffer_as_string);
|
2022-02-09 15:27:32 +01:00
|
|
|
bool get_interface_number_by_device_name(int socket_fd, std::string interface_name, int& interface_number);
|
2015-09-25 23:24:50 +02:00
|
|
|
|
2015-03-21 11:47:25 +01:00
|
|
|
#endif
|