#include <pthread.h>#include <event.h>#include <errno.h>#include <string.h>#include <signal.h>#include <time.h>#include <sys/socket.h>#include <sys/un.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <boost/thread/shared_mutex.hpp>#include <netinet/in.h>#include <netdb.h>#include <arpa/inet.h>#include <set>#include <algorithm>#include <vector>#include <list>#include "types.hpp"#include "Protocol.h"#include "LocalDB.hpp"#include "common_functions.hpp"#include "hashtable.hpp"#include "Aho_Corasick.hpp"#include "daemonize.hpp"#include "dst_config.hpp"#include "file_tokenizer.hpp"Typedefs | |
| typedef thread_s | thread_t |
| typedef client_s | client_t |
Functions | |
| void | read_cb (int fd, short event_type, void *arg) |
| Reads data from socket and cuts them into packets. | |
| void | do_register () |
| Register our server in main server and request configuration. | |
| void | send_data_cb (int fd, short event_type, void *arg) |
| Callback run every time there is something to send in output buffer. It attempts to send next buffer from cli->packets_to_send. | |
| void | close_con (client_t *cli) |
| Close connection used to communication with client and remove all events. | |
| void | soft_close_con (client_t *cli) |
| Remove all events and register new read event. | |
| void | send_auth_cb (int fd, short event_type, void *arg) |
| Send authorization request to client. | |
| void | register_cb (int fd, short event_type, void *arg) |
| Callback to register proxy in main server. | |
| bool | pattern_check_ban_callback (const t_uid &patternIndex, int patternPosition, void *context) |
| Function call after found uid in destination list. | |
| bool | pattern_add_traffic_callback (const t_uid &patternIndex, int patternPosition, void *context) |
| Function call after found uid in destination list. | |
| void | find_host (char *input_buffer, int parser_position, int size, uint32_t &host_length, char *host) |
| void | protocol_limit_server_protocol_check (client_s *cli, char *input_buffer, uint32_t packet_size) |
| void | protocol_limit_server_protocol_update (client_s *cli, char *input_buffer, uint32_t packet_size) |
| void | protocol_limit_server_protocol_send_diff (client_s *cli, char *input_buffer, uint32_t packet_size) |
| void | protocol_limit_server_update_add_dest (client_s *cli, char *input_buffer, uint32_t packet_size) |
| void | protocol_limit_server_update_set_dest_specyfic_config (client_s *cli, char *input_buffer, uint32_t packet_size) |
| void | protocol_limit_server_update_dest_host_diff (client_s *cli, char *input_buffer, uint32_t packet_size) |
| void | protocol_limit_server_update_dest_diff (client_s *cli, char *input_buffer, uint32_t packet_size) |
| void | protocol_limit_server_answer_uid (client_s *cli, char *input_buffer, uint32_t packet_size) |
| uint32_t | protocol_core (client_s *cli, char *input_buffer, uint32_t size) |
| Main function to parse the received data and call proper procedure. | |
| void | do_accept (int listener_socket, short event_type, void *arg) |
| Callback run every time there is new connection. | |
| void | time_cb (int fd, short event_type, void *arg) |
| Diagnostic callback. | |
| void | time_regen_connection (int fd, short event_type, void *arg) |
| void | pipe_cb (int fd, short event_type, void *arg) |
| Callback run aftern notifaction worker thread. | |
| void * | worker (void *arg) |
| Worker thread. Enters libevent loop, and should never leave it. | |
| void | signal_handler (int signal) |
| void | init () |
| Initialize connection and create worker threads. | |
| void | read_local_config (const char *conf_file_name) |
| Read local configuration. | |
| int | main (int argc, char **argv) |
Variables | |
| Aho_Corasick< char > | pattern_finder |
| struct timeval | tv |
| struct event_base * | thread_loops [RECV_THREAD_AMOUNT] |
| pthread_t | thread_ids [RECV_THREAD_AMOUNT] |
| int | thread_usage [RECV_THREAD_AMOUNT] |
| pthread_mutex_t | thread_usage_guard = PTHREAD_MUTEX_INITIALIZER |
| pthread_mutex_t | mutex_queue [RECV_THREAD_AMOUNT] |
| int | pipe_queue [RECV_THREAD_AMOUNT][2] |
| int | last_thread = 0 |
| boost::shared_mutex | update_lock |
| pthread_mutex_t | master_guard = PTHREAD_MUTEX_INITIALIZER |
| char | main_server_address [128] |
| int | main_server_port |
| char * | local_server_path |
| int | local_server_port |
| int | daemonize |
| char | log_error [1024] |
| char | log_common [1024] |
| char | local_server_name [256] |
| int | recv_threads |
| const char * | NOTIFY = "1" |
| const char * | ZERO_CONFIG = "*" |
| int | curr_month = 0 |
| set< t_uid > | dest_list |
| HashMap< t_uid,dest_config * > | local_config (hashFunction) |
| pthread_mutex_t | master_server_connecting = PTHREAD_MUTEX_INITIALIZER |
| bool | master_server_connected = false |
| client_t * | master_server_cli |
| std::list< client_t * > | queue [RECV_THREAD_AMOUNT] |
| int | listener_socket |
| void close_con | ( | client_t * | cli | ) |
Close connection used to communication with client and remove all events.
| [in] | cli |
| void do_accept | ( | int | listener_socket, | |
| short | event_type, | |||
| void * | arg | |||
| ) |
Callback run every time there is new connection.
| [in] | listener_socket | |
| [in] | event_type | |
| [in] | arg |
| void do_register | ( | ) |
Register our server in main server and request configuration.
| void find_host | ( | char * | input_buffer, | |
| int | parser_position, | |||
| int | size, | |||
| uint32_t & | host_length, | |||
| char * | host | |||
| ) |
| [in] | input_buffer | |
| [in] | parser_position | |
| [in] | size | |
| [in] | host_length | |
| [in] | host |
| void init | ( | ) |
Initialize connection and create worker threads.
| int main | ( | int | argc, | |
| char ** | argv | |||
| ) |
| [in] | argc | |
| [in] | argv |
| bool pattern_add_traffic_callback | ( | const t_uid & | patternIndex, | |
| int | patternPosition, | |||
| void * | context | |||
| ) |
Function call after found uid in destination list.
| [in] | patternIndex | |
| [in] | patternPosition | |
| [in] | context |
| bool pattern_check_ban_callback | ( | const t_uid & | patternIndex, | |
| int | patternPosition, | |||
| void * | context | |||
| ) |
Function call after found uid in destination list.
| [in] | patternIndex | |
| [in] | patternPosition | |
| [in] | context |
| void pipe_cb | ( | int | fd, | |
| short | event_type, | |||
| void * | arg | |||
| ) |
Callback run aftern notifaction worker thread.
| [in] | fd | |
| [in] | event_type | |
| [in] | arg |
| uint32_t protocol_core | ( | client_s * | cli, | |
| char * | input_buffer, | |||
| uint32_t | size | |||
| ) |
Main function to parse the received data and call proper procedure.
| [in] | cli | client who received something |
| [in] | input_buffer | buffer pointer |
| [in] | size | total buffer length |
| void protocol_limit_server_answer_uid | ( | client_s * | cli, | |
| char * | input_buffer, | |||
| uint32_t | packet_size | |||
| ) |
| void protocol_limit_server_protocol_check | ( | client_s * | cli, | |
| char * | input_buffer, | |||
| uint32_t | packet_size | |||
| ) |
| void protocol_limit_server_protocol_send_diff | ( | client_s * | cli, | |
| char * | input_buffer, | |||
| uint32_t | packet_size | |||
| ) |
| void protocol_limit_server_protocol_update | ( | client_s * | cli, | |
| char * | input_buffer, | |||
| uint32_t | packet_size | |||
| ) |
| void protocol_limit_server_update_add_dest | ( | client_s * | cli, | |
| char * | input_buffer, | |||
| uint32_t | packet_size | |||
| ) |
| void protocol_limit_server_update_dest_diff | ( | client_s * | cli, | |
| char * | input_buffer, | |||
| uint32_t | packet_size | |||
| ) |
| void protocol_limit_server_update_dest_host_diff | ( | client_s * | cli, | |
| char * | input_buffer, | |||
| uint32_t | packet_size | |||
| ) |
| void protocol_limit_server_update_set_dest_specyfic_config | ( | client_s * | cli, | |
| char * | input_buffer, | |||
| uint32_t | packet_size | |||
| ) |
| void read_cb | ( | int | fd, | |
| short | event_type, | |||
| void * | arg | |||
| ) |
Reads data from socket and cuts them into packets.
| [in] | fd | fd from which data are avialable |
| [in] | event_type | unused |
| [in] | arg | client related with this event |
| void read_local_config | ( | const char * | conf_file_name | ) |
Read local configuration.
| void register_cb | ( | int | fd, | |
| short | event_type, | |||
| void * | arg | |||
| ) |
Callback to register proxy in main server.
| [in] | fd | |
| [in] | event_type | |
| [in] | arg |
| void send_auth_cb | ( | int | fd, | |
| short | event_type, | |||
| void * | arg | |||
| ) |
Send authorization request to client.
| [in] | fd | |
| [in] | event_type | |
| [in] | arg |
| void send_data_cb | ( | int | fd, | |
| short | event_type, | |||
| void * | arg | |||
| ) |
Callback run every time there is something to send in output buffer. It attempts to send next buffer from cli->packets_to_send.
| [in] | fd | File descriptor on which event occured. |
| [in] | event_type | unused |
| [in] | arg | Client context used by fd (as void*) |
| void signal_handler | ( | int | signal | ) |
| void soft_close_con | ( | client_t * | cli | ) |
Remove all events and register new read event.
| [in] | cli |
| void time_cb | ( | int | fd, | |
| short | event_type, | |||
| void * | arg | |||
| ) |
Diagnostic callback.
| [in] | fd | |
| [in] | event_type | |
| [in] | arg |
| void time_regen_connection | ( | int | fd, | |
| short | event_type, | |||
| void * | arg | |||
| ) |
| [in] | fd | |
| [in] | event_type | |
| [in] | arg |
| void* worker | ( | void * | arg | ) |
Worker thread. Enters libevent loop, and should never leave it.
| [in] | arg | thread Index (converted to pointer type) |
| int curr_month = 0 |
Variable identifying current month (1-12)
| int daemonize |
| int last_thread = 0 |
next thread to use (round-robin)
| int listener_socket |
| HashMap<t_uid ,dest_config*> local_config(hashFunction) |
| char local_server_name[256] |
| char* local_server_path |
| char log_common[1024] |
| char log_error[1024] |
| char main_server_address[128] |
Local configuration
| int main_server_port |
| pthread_mutex_t master_guard = PTHREAD_MUTEX_INITIALIZER |
| bool master_server_connected = false |
| pthread_mutex_t master_server_connecting = PTHREAD_MUTEX_INITIALIZER |
| pthread_mutex_t mutex_queue |
| const char* NOTIFY = "1" |
| Aho_Corasick<char> pattern_finder |
Local variables stores destination id
| int pipe_queue[RECV_THREAD_AMOUNT][2] |
| int recv_threads |
| pthread_t thread_ids[RECV_THREAD_AMOUNT] |
worker threads
| struct event_base* thread_loops[RECV_THREAD_AMOUNT] |
| int thread_usage[RECV_THREAD_AMOUNT] |
| pthread_mutex_t thread_usage_guard = PTHREAD_MUTEX_INITIALIZER |
| struct timeval tv |
interval beetwen worker callback
| boost::shared_mutex update_lock |
mutex to lock array during destination update
| const char* ZERO_CONFIG = "*" |
1.5.6