46 #include <arpa/inet.h> 48 #include <netinet/in.h> 52 #include <sys/socket.h> 54 #include <sys/types.h> 61 #include <semaphore.h> 64 #include <openssl/ssl.h> 65 #include <openssl/err.h> 66 #include <openssl/bio.h> 67 #include <openssl/pem.h> 68 #include <openssl/x509.h> 69 #include <openssl/x509_vfy.h> 72 #include "../include/libtrap/trap.h" 89 #define MAX_RECOVERY_TRY 10 91 #define RECOVERY_WAIT_USEC 500000 92 #define USEC_IN_SEC 1000000 93 #define ACK_MESS_SIZE 1 94 #define CRIT_1VS2SEND 10000 96 #define MAX(a,b) ((a)<(b)?(b):(a)) 99 #define MIN(a,b) ((a)>(b)?(b):(a)) 104 const SSL_METHOD *method;
107 method = SSLv23_server_method();
109 ctx = SSL_CTX_new(method);
111 perror(
"Unable to create SSL context");
112 ERR_print_errors_fp(stderr);
116 #if defined(SSL_CTX_set_ecdh_auto) 117 SSL_CTX_set_ecdh_auto(ctx, 1);
119 SSL_CTX_set_tmp_ecdh(ctx, EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
127 const SSL_METHOD *method;
130 method = SSLv23_client_method();
132 ctx = SSL_CTX_new(method);
134 perror(
"Unable to create SSL context");
135 ERR_print_errors_fp(stderr);
152 cert = SSL_get_peer_certificate(arg);
158 if (SSL_get_verify_result(arg) == X509_V_OK) {
177 X509* certificate = X509_new();
178 BIO* bio_cert = BIO_new_file(cert,
"r");
180 PEM_read_bio_X509(bio_cert, &certificate, NULL, NULL);
181 if (certificate == NULL) {
185 if (SSL_CTX_add_client_CA(ctx, certificate) != 1) {
190 SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2);
191 SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv3);
192 SSL_CTX_set_options(ctx, SSL_OP_NO_TLSv1);
193 SSL_CTX_set_options(ctx, SSL_OP_NO_TLSv1_1);
195 X509_free(certificate);
196 BIO_free_all(bio_cert);
215 ret = SSL_CTX_use_certificate_chain_file(ctx, crt);
218 crt, ERR_reason_error_string(ERR_get_error()));
222 ret = SSL_CTX_use_PrivateKey_file(ctx, key, SSL_FILETYPE_PEM);
225 key, ERR_reason_error_string(ERR_get_error()));
229 if (SSL_CTX_check_private_key(ctx) == 0) {
230 VERBOSE(
CL_ERROR,
"Private key does not match the certificate public key.");
235 if (SSL_CTX_load_verify_locations(ctx, ca, NULL) != 1) {
236 VERBOSE(
CL_ERROR,
"Could not load CA location used for verification.");
239 SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL);
265 if (sa->sa_family == AF_INET) {
266 return &(((
struct sockaddr_in*)sa)->sin_addr);
269 return &(((
struct sockaddr_in6*)sa)->sin6_addr);
288 void *data_p = (*data);
290 ssize_t numbytes = *size;
294 assert(data_p != NULL);
298 "s%"PRIu64
"us", tm->tv_sec, tm->tv_usec)});
301 FD_SET(config->
sd, &
set);
306 retval = select(config->
sd + 1, &
set, NULL, NULL, tm);
308 if (FD_ISSET(config->
sd, &
set)) {
310 recvb = SSL_read(config->
ssl, data_p, numbytes);
336 }
while (numbytes > 0);
343 }
else if (retval == 0) {
347 }
else if (retval < 0 && errno == EINTR) {
397 #ifdef LIMITED_RECOVERY 398 uint32_t recovery = 0;
403 void *p = &messageframe;
404 struct timeval tm, *temptm;
410 struct timespec spec_time;
412 clock_gettime(CLOCK_MONOTONIC, &spec_time);
414 uint64_t entry_time = spec_time.tv_sec * 1000000 + (spec_time.tv_nsec / 1000);
415 uint64_t curr_time = 0;
420 struct timespec sleeptimespec;
426 if ((config == NULL) || (
data == NULL) || (size == NULL)) {
465 #ifdef LIMITED_RECOVERY 476 clock_gettime(CLOCK_MONOTONIC, &spec_time);
477 curr_time = spec_time.tv_sec * 1000000 + (spec_time.tv_nsec / 1000);
478 if ((curr_time - entry_time) >= timeout) {
485 sleeptime = timeout - (curr_time - entry_time);
487 if (sleeptime < 1000000) {
488 sleeptimespec.tv_sec = sleeptime / 1000000;
489 sleeptimespec.tv_nsec = (sleeptime % 1000000) * 1000;
491 " us: %"PRIu64
"s%"PRIu64
"ns", sleeptime,
492 sleeptimespec.tv_sec, sleeptimespec.tv_nsec));
494 sleeptimespec.tv_sec = 1;
495 sleeptimespec.tv_nsec = 0;
499 if (nanosleep(&sleeptimespec, NULL) == -1) {
500 if (errno == EINTR) {
510 clock_gettime(CLOCK_MONOTONIC, &spec_time);
511 curr_time = spec_time.tv_sec * 1000000 + (spec_time.tv_nsec / 1000);
512 sleeptime = timeout - (int) (curr_time - entry_time);
513 if ((
int) sleeptime > 0) {
567 #ifdef ENABLE_CHECK_HEADER 569 if (tls_check_header(&messageframe) == 0) {
609 if (config != NULL) {
625 if (config != NULL) {
649 char *conf_file = NULL;
651 char *buf_file = NULL;
656 r = asprintf(&conf_file,
"%s/trap-i%02"PRIu32
"-config.txt", path, idx);
658 VERBOSE(
CL_ERROR,
"Not enough memory, dump failed. (%s:%d)", __FILE__, __LINE__);
662 f = fopen(conf_file,
"w");
663 fprintf(f,
"Dest addr: %s\nDest port: %s\nConnected: %d\n" 664 "Terminated: %d\nSocket descriptor: %d\n" 665 "Data pointer: %p\nData wait size: %"PRIu32
"\nMessage header: %"PRIu32
"\n" 666 "Extern buffer pointer: %p\nExtern buffer data size: %"PRIu32
"\n" 667 "Timeout: %"PRId32
"us (%s)\nPrivate key: %s\nCertificate: %s\n",
677 r = asprintf(&buf_file,
"%s/trap-i%02"PRIu32
"-buffer.dat", path, idx);
680 VERBOSE(
CL_ERROR,
"Not enough memory, dump failed. (%s:%d)", __FILE__, __LINE__);
683 f = fopen(buf_file,
"w");
685 VERBOSE(
CL_ERROR,
"Writing buffer header failed. (%s:%d)", __FILE__, __LINE__);
689 VERBOSE(
CL_ERROR,
"Writing buffer content failed. (%s:%d)", __FILE__, __LINE__);
741 char *param_iterator = NULL;
742 char *dest_addr = NULL;
743 char *dest_port = NULL;
744 char *keyfile = NULL;
745 char *certfile = NULL;
749 if (params == NULL) {
750 VERBOSE(
CL_ERROR,
"IFC requires at least three parameters (port:keyfile:certfile).");
755 if (config == NULL) {
756 VERBOSE(
CL_ERROR,
"Failed to allocate internal memory for input IFC.");
766 if ((dest_addr == NULL) || (strlen(dest_addr) == 0)) {
767 VERBOSE(
CL_ERROR,
"Expected parameters: 'destination address:port:keyfile:certfile' are missing.");
769 goto failsafe_cleanup;
771 if (param_iterator != NULL) {
774 VERBOSE(
CL_ERROR,
"Missing 'dest_port', 'keyfile', 'certfile' and trusted 'CAfile' parameters.");
776 goto failsafe_cleanup;
778 if (param_iterator != NULL) {
781 VERBOSE(
CL_ERROR,
"Missing 'keyfile', 'certfile' and trusted 'CAfile' parameters.");
783 goto failsafe_cleanup;
785 if (param_iterator != NULL) {
788 VERBOSE(
CL_ERROR,
"Missing 'certfile' and trusted 'CAfile' parameters.");
790 goto failsafe_cleanup;
792 if (param_iterator != NULL) {
799 dest_port = dest_addr;
800 dest_addr = strdup(
"localhost");
801 VERBOSE(
CL_ERROR,
"Only 3 parameters given, using 'localhost' as a destination address.");
816 VERBOSE(
CL_ERROR,
"Malformed params for input IFC, missing destination address and port.");
818 goto failsafe_cleanup;
826 if (config->
sslctx == NULL) {
828 goto failsafe_cleanup;
832 goto failsafe_cleanup;
839 #ifndef ENABLE_NEGOTIATION 841 struct timeval tv = {5, 0};
848 goto failsafe_cleanup;
864 #ifndef ENABLE_NEGOTIATION 869 goto failsafe_cleanup;
880 if (config != NULL && config->
sslctx != NULL) {
881 SSL_CTX_free(config->
sslctx);
898 SSL_free(config->
ssl);
917 FD_SET(sock, &fdset);
920 rv = select(sock + 1, NULL, &fdset, NULL, tv);
923 socklen_t len =
sizeof so_error;
925 getsockopt(sock, SOL_SOCKET, SO_ERROR, &so_error, &len);
943 int sockfd = -1, options;
945 struct addrinfo *servinfo, *p = NULL;
946 int rv, addr_count = 0;
947 char s[INET6_ADDRSTRLEN];
953 memset(&addr, 0,
sizeof(addr));
955 addr.
tls_addr.ai_family = AF_UNSPEC;
956 addr.
tls_addr.ai_socktype = SOCK_STREAM;
967 for (p = servinfo; p != NULL; p = p->ai_next) {
970 tv->tv_sec = (tv->tv_sec * 1000000 + tv->tv_usec) / addr_count;
971 tv->tv_usec = tv->tv_sec % 1000000;
972 tv->tv_sec /= 1000000;
974 tv->tv_sec, tv->tv_usec);
978 for (p = servinfo; p != NULL; p = p->ai_next) {
979 if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
982 if ((options = fcntl(sockfd, F_GETFL)) != -1) {
983 if (fcntl(sockfd, F_SETFL, O_NONBLOCK | options) == -1) {
987 if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
988 if (errno != EINPROGRESS && errno != EAGAIN) {
1022 freeaddrinfo(servinfo);
1029 if (inet_ntop(p->ai_family,
get_in_addr((
struct sockaddr *)p->ai_addr), s,
sizeof s) != NULL) {
1033 freeaddrinfo(servinfo);
1038 if (c->
ssl == NULL) {
1039 VERBOSE(
CL_ERROR,
"Creating SSL structure failed: %s", ERR_reason_error_string(ERR_get_error()));
1044 if (SSL_set_fd(c->
ssl, c->
sd) != 1) {
1045 VERBOSE(
CL_ERROR,
"Setting SSL file descriptor to tcp socket failed: %s",
1046 ERR_reason_error_string(ERR_get_error()));
1049 SSL_set_connect_state(c->
ssl);
1052 rv = SSL_connect(c->
ssl);
1054 rv = ERR_get_error();
1056 case SSL_ERROR_NONE:
1057 case SSL_ERROR_WANT_CONNECT:
1058 case SSL_ERROR_WANT_X509_LOOKUP:
1059 case SSL_ERROR_WANT_READ:
1060 case SSL_ERROR_WANT_WRITE:
1063 VERBOSE(
CL_ERROR,
"SSL connection failed, could be wrong certificate. %s",
1064 ERR_reason_error_string(ERR_get_error()));
1083 #ifdef ENABLE_NEGOTIATION 1095 VERBOSE(
CL_VERBOSE_LIBRARY,
"Input_ifc_negotiation result: success (format has changed; it was not first negotiation).");
1099 VERBOSE(
CL_VERBOSE_LIBRARY,
"Input_ifc_negotiation result: success (required set of fields of the input interface is subset of the recevied format).");
1103 VERBOSE(
CL_VERBOSE_LIBRARY,
"Input_ifc_negotiation result: success (new recevied format specifier is subset of the old one; it was not first negotiation).");
1107 VERBOSE(
CL_VERBOSE_LIBRARY,
"Input_ifc_negotiation result: failed (error while receiving hello message from output interface).");
1153 shutdown(c->
sd, SHUT_RDWR);
1188 struct timespec spec_time;
1190 clock_gettime(CLOCK_MONOTONIC, &spec_time);
1192 return spec_time.tv_sec * 1000000 + (spec_time.tv_nsec / 1000);
1202 char remoteIP[INET6_ADDRSTRLEN];
1203 struct sockaddr_storage remoteaddr;
1206 int newclient, fdmax;
1210 struct sockaddr *tmpaddr;
1211 uint32_t client_id = 0;
1214 addrlen =
sizeof(remoteaddr);
1223 if (select(fdmax + 1, &scset, NULL, NULL, NULL) == -1) {
1224 if (errno == EINTR) {
1230 VERBOSE(
CL_ERROR,
"%s:%d unexpected error code %d", __func__, __LINE__, errno);
1235 newclient = accept(c->
server_sd, (
struct sockaddr *) &remoteaddr, &addrlen);
1236 if (newclient == -1) {
1239 tmpaddr = (
struct sockaddr *) &remoteaddr;
1240 switch(((
struct sockaddr *) tmpaddr)->sa_family) {
1242 client_id = ntohs(((
struct sockaddr_in *) tmpaddr)->sin_port);
1245 client_id = ntohs(((
struct sockaddr_in6 *) tmpaddr)->sin6_port);
1249 inet_ntop(remoteaddr.ss_family,
get_in_addr((
struct sockaddr*) &remoteaddr), remoteIP, INET6_ADDRSTRLEN),
1264 if (cl->
ssl == NULL) {
1265 VERBOSE(
CL_ERROR,
"Creating SSL structure failed: %s", ERR_reason_error_string(ERR_get_error()));
1268 if (SSL_set_fd(cl->
ssl, newclient) != 1) {
1269 VERBOSE(
CL_ERROR,
"Setting SSL file descriptor to tcp socket failed: %s",
1270 ERR_reason_error_string(ERR_get_error()));
1276 if (SSL_accept(cl->
ssl) <= 0) {
1277 ERR_print_errors_fp(stderr);
1298 #ifdef ENABLE_NEGOTIATION 1303 VERBOSE(
CL_VERBOSE_LIBRARY,
"Output_ifc_negotiation result: failed (unknown data format of this output interface -> refuse client).");
1307 VERBOSE(
CL_VERBOSE_LIBRARY,
"Output_ifc_negotiation result: failed (error while sending hello message to input interface).");
1319 shutdown(newclient, SHUT_RDWR);
1339 uint32_t header = htonl(buffer->
wr_index);
1340 memcpy(buffer->
header, &header,
sizeof(header));
1399 switch (SSL_get_error(c->
ssl, sent)) {
1400 case SSL_ERROR_ZERO_RETURN:
1401 case SSL_ERROR_SYSCALL:
1403 case SSL_ERROR_WANT_READ:
1404 case SSL_ERROR_WANT_WRITE:
1443 uint64_t send_entry_time;
1444 uint64_t send_exit_time;
1445 uint8_t waiting_clients;
1446 struct timeval select_timeout;
1451 if (c->is_terminated != 0) {
1454 if (c->connected_clients == 0) {
1459 if ((
get_cur_timestamp() - c->autoflush_timestamp) > c->ctx->out_ifc_list[c->ifc_idx].timeout) {
1465 waiting_clients = 0;
1466 select_timeout.tv_sec = 1;
1467 select_timeout.tv_usec = 0;
1470 FD_SET(c->term_pipe[0], &disset);
1471 if (maxsd < c->term_pipe[0]) {
1472 maxsd = c->term_pipe[0];
1476 for (i = j = 0; i < c->clients_arr_size; ++i) {
1477 if (j == c->connected_clients) {
1487 cl = &(c->clients[i]);
1491 FD_SET(cl->
sd, &disset);
1494 if (maxsd < cl->sd) {
1509 FD_SET(cl->
sd, &
set);
1513 if (waiting_clients == c->connected_clients) {
1514 pthread_mutex_lock(&c->mtx_no_data);
1515 pthread_cond_wait(&c->cond_no_data, &c->mtx_no_data);
1516 pthread_mutex_unlock(&c->mtx_no_data);
1520 res = select(maxsd + 1, &disset, &
set, NULL, &select_timeout);
1523 if (c->is_terminated == 0) {
1528 VERBOSE(
CL_ERROR,
"Sending thread: unexpected error in select (errno: %i)", errno);
1535 }
else if (res == 0) {
1540 if (FD_ISSET(c->term_pipe[0], &disset)) {
1547 for (i = j = 0; i < c->clients_arr_size; ++i) {
1548 if (j == c->connected_clients) {
1552 cl = &(c->clients[i]);
1560 if (FD_ISSET(cl->
sd, &disset)) {
1570 if (FD_ISSET(cl->
sd, &
set)) {
1576 cl->
timer_last = (send_exit_time - send_entry_time);
1603 uint32_t free_bytes;
1612 VERBOSE(
CL_ERROR,
"Buffer is too small for this message. Skipping...");
1632 while (buffer->clients_bit_arr != 0) {
1633 clock_gettime(CLOCK_REALTIME, &ts);
1635 ts.tv_nsec += (ts.tv_sec * 1000000000L) + (timeout * 1000L);
1636 ts.tv_sec = (ts.tv_nsec / 1000000000L);
1637 ts.tv_nsec %= 1000000000L;
1663 if (free_bytes >= (size +
sizeof(size))) {
1718 VERBOSE(
CL_ERROR,
"Destroying IFC that is probably not initialized.");
1785 json_t *client_stats = NULL;
1798 if (client_stats == NULL) {
1802 if (json_array_append_new(client_stats_arr, client_stats) == -1) {
1815 char *conf_file = NULL;
1820 r = asprintf(&conf_file,
"%s/trap-o%02"PRIu32
"-config.txt", path, idx);
1822 VERBOSE(
CL_ERROR,
"Not enough memory, dump failed. (%s:%d)", __FILE__, __LINE__);
1826 f = fopen(conf_file,
"w");
1827 fprintf(f,
"Server port: %s\n" 1828 "Server socket descriptor: %d\n" 1829 "Connected clients: %d\n" 1831 "Active buffer: %d\n" 1832 "Buffer count: %u\n" 1847 fprintf(f,
"Clients:\n");
1886 char *param_iterator = NULL;
1887 char *param_str = NULL;
1888 char *server_port = NULL;
1889 char *keyfile = NULL;
1890 char *certfile = NULL;
1891 char *cafile = NULL;
1898 #define X(pointer) free(pointer); \ 1902 if (params == NULL) {
1903 VERBOSE(
CL_ERROR,
"IFC requires at least three parameters (port:keyfile:certfile).");
1911 goto failsafe_cleanup;
1916 if ((server_port == NULL) || (strlen(server_port) == 0)) {
1919 goto failsafe_cleanup;
1921 if (param_iterator != NULL) {
1924 VERBOSE(
CL_ERROR,
"Missing 'keyfile', 'certfile' and trusted 'CAfile' for TLS IFC.");
1926 goto failsafe_cleanup;
1928 if (param_iterator != NULL) {
1931 VERBOSE(
CL_ERROR,
"Missing 'certfile' and trusted 'CAfile' for TLS IFC.");
1933 goto failsafe_cleanup;
1935 if (param_iterator != NULL) {
1940 goto failsafe_cleanup;
1944 while (param_iterator != NULL) {
1946 if (param_str == NULL)
1950 VERBOSE(
CL_ERROR,
"Optional buffer count given, but it is probably in wrong format.");
1955 VERBOSE(
CL_ERROR,
"Optional buffer size given, but it is probably in wrong format.");
1960 VERBOSE(
CL_ERROR,
"Optional max clients number given, but it is probably in wrong format.");
1973 goto failsafe_cleanup;
1975 for (i = 0; i < buffer_count; ++i) {
1978 b->
header = malloc(buffer_size +
sizeof(buffer_size));
1987 goto failsafe_cleanup;
1989 for (i = 0; i < max_clients; ++i) {
2023 VERBOSE(
CL_ERROR,
"Socket could not be opened on given port '%s'.", server_port);
2024 goto failsafe_cleanup;
2028 VERBOSE(
CL_ERROR,
"Opening of pipe failed. Using stdin as a fall back.");
2033 if (priv->
sslctx == NULL) {
2035 goto failsafe_cleanup;
2040 goto failsafe_cleanup;
2045 goto failsafe_cleanup;
2097 struct addrinfo *ai, *p = NULL;
2103 memset(&addr, 0,
sizeof(addr));
2106 addr.
tls_addr.ai_family = AF_UNSPEC;
2107 addr.
tls_addr.ai_socktype = SOCK_STREAM;
2108 addr.
tls_addr.ai_flags = AI_PASSIVE;
2113 for (p = ai; p != NULL; p = p->ai_next) {
2114 c->
server_sd = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
2120 if (setsockopt(c->
server_sd, SOL_SOCKET, SO_REUSEADDR, &yes,
sizeof(
int)) == -1) {
2121 VERBOSE(
CL_ERROR,
"Failed to set socket to reuse address. (%d)", errno);
2124 if (bind(c->
server_sd, p->ai_addr, p->ai_addrlen) < 0) {
#define BUFFER_SIZE_PARAM_LENGTH
static uint64_t get_cur_timestamp()
#define TRAP_E_OK
Success, no error.
int create_tls_receiver_ifc(trap_ctx_priv_t *ctx, char *params, trap_input_ifc_t *ifc, uint32_t idx)
Constructor of input TCP/IP IFC module. This function is called by TRAP library to initialize one inp...
static SSL_CTX * tlsserver_create_context()
char * trap_get_param_by_delimiter(const char *source, char **dest, const char delimiter)
Splitter of params string. Cut the first param, copy it into dest and returns pointer to the start of...
ifc_get_client_stats_json_func_t get_client_stats_json
Pointer to get_client_stats_json function.
pthread_cond_t cond_full_buffer
#define NEG_RES_SENDER_FMT_SUBSET
If the data format of input and output interfaces is the same and new data specifier of the output in...
static void tls_sender_create_dump(void *priv, uint32_t idx, const char *path)
Internal functions and macros for libtrap Verbose and debug macros from libcommlbr.
uint32_t clients_arr_size
#define TRAP_IFC_PARAM_DELIMITER
static int receive_part(void *priv, void **data, uint32_t *size, struct timeval *tm)
static void * accept_clients_thread(void *arg)
This function runs in a separate thread and handles new client's connection requests.
void tls_receiver_terminate(void *priv)
Set interface state as terminated.
struct trap_buffer_header_s trap_buffer_header_t
static int tls_configure_ctx(SSL_CTX *ctx, const char *key, const char *crt, const char *ca)
Configure ssl context of new connection.
pthread_mutex_t ifc_mtx
Locking mutex for interface.
#define NEG_RES_FAILED
If receiving the data from output interface fails or sending the data to input interface fails...
void tls_sender_destroy(void *priv)
Destructor of TCP sender (output ifc)
pthread_cond_t cond_no_data
void trap_set_timeouts(int timeout, struct timeval *tm, struct timespec *tmnblk)
Internal function for setting of timeout structs according to libtrap timeout.
static void disconnect_client(tls_sender_private_t *priv, int cl_id)
This function is called when a client was/is being disconnected.
ifc_get_id_func_t get_id
Pointer to get_id function.
#define TRAP_TIMEOUT_STR(t)
static int wait_for_connection(int sock, struct timeval *tv)
#define TRAP_E_FIELDS_MISMATCH
Returned when receiver fields are not subset of sender fields.
Structure for TLS IFC private information.
int output_ifc_negotiation(void *ifc_priv_data, char ifc_type, uint32_t client_idx)
static void insert_into_buffer(file_buffer_t *buffer, const void *data, uint16_t size)
static void set_index(uint64_t *bits, int i)
Set i-th element (one bit) of 'bits' to 1.
void tls_server_disconnect_all_clients(void *priv)
Function disconnects all clients of the output interface whose private structure is passed via "priv"...
void tls_receiver_destroy(void *priv)
Destructor of TLS receiver (input ifc)
static void del_index(uint64_t *bits, int i)
Set i-th element (one bit) of 'bits' to 0.
#define TRAP_E_TERMINATED
Interface was terminated during reading/writing.
ifc_create_dump_func_t create_dump
Pointer to function for generating of dump.
static void client_socket_disconnect(void *priv)
#define TRAP_E_IO_ERROR
IO Error.
#define NEG_RES_FMT_CHANGED
If the data format has changed (for JSON type, UNIREC type uses *SUBSET variants) ...
#define VERBOSE(level, format, args...)
TRAP TCP/IP interfaces private structures.
struct sockaddr_un unix_addr
used for path of UNIX socket
static int verify_certificate(SSL *arg)
Verify context of ssl.
int tls_receiver_recv(void *priv, void *data, uint32_t *size, int timeout)
Receive data from interface.
static int trap_errorf(trap_ctx_priv_t *ctx, int err_num, const char *msg,...)
int create_tls_sender_ifc(trap_ctx_priv_t *ctx, const char *params, trap_output_ifc_t *ifc, uint32_t idx)
Constructor of output TCP/IP IFC module. This function is called by TRAP library to initialize one ou...
uint32_t connected_clients
void tls_sender_flush(void *priv)
Force flush of active buffer.
ifc_get_client_count_func_t get_client_count
Pointer to get_client_count function.
#define NEG_RES_CONT
If the data format and data specifier of input and output interface are the same (input interface can...
ifc_disconn_clients_func_t disconn_clients
Pointer to disconnect_clients function.
#define TRAP_E_BAD_FPARAMS
Bad parameters of function.
static int server_socket_open(void *priv)
Open TLS socket for sender module.
static int tls_server_configure_ctx(const char *cert, SSL_CTX *ctx)
Configure context of ssl server.
uint8_t tls_recv_ifc_is_conn(void *priv)
char bufferswitch
Enable (1) or Disable (0) buffering, default is Enabled (1).
struct addrinfo tls_addr
used for TCPIP socket
#define DEFAULT_BUFFER_SIZE
static uint64_t check_index(uint64_t bits, int i)
Return value of i-th element (one bit) in the 'bits' array.
int32_t datatimeout
Timeout for *_send() calls.
#define TRAP_E_NEGOTIATION_FAILED
Returned by trap_recv when negotiation of the output and input interfaces failed. ...
Structure for TLS IFC client information.
ifc_send_func_t send
Pointer to send function.
#define NEG_RES_FMT_UNKNOWN
If the output interface has not specified data format.
#define TRAP_IFC_TYPE_TLS
trap_ifc_tls (input&output part)
#define DEFAULT_MAX_CLIENTS
#define TRAP_E_FORMAT_MISMATCH
Returned by trap_recv when data format or data specifier of the output and input interfaces doesn't m...
#define NEG_RES_FMT_MISMATCH
If the data format or data specifier of input and output interfaces does not match.
#define DEFAULT_BUFFER_COUNT
#define TRAP_E_MEMORY
Memory allocation error.
int8_t tls_sender_get_client_stats_json(void *priv, json_t *client_stats_arr)
#define NEG_RES_OK
Signaling success (hello message successfully sent to input interface)
int tls_sender_send(void *priv, const void *data, uint16_t size, int timeout)
Store message into buffer.
static void finish_buffer(tls_sender_private_t *priv, buffer_t *buffer)
Write buffer size to its header and shift active index.
static void * get_in_addr(struct sockaddr *sa)
Get sockaddr, IPv4 or IPv6.
int32_t tls_sender_get_client_count(void *priv)
#define TRAP_E_BAD_CERT
Wrong certificate given to TLS interface.
ifc_destroy_func_t destroy
Pointer to destructor function.
ifc_terminate_func_t terminate
Pointer to terminate function.
This file contains common functions and structures used in socket based interfaces (tcp-ip / tls)...
static int send_data(tls_sender_private_t *priv, tlsclient_t *c, uint32_t cl_id)
Send data to client from his assigned buffer.
#define TRAP_E_TIMEOUT
Read or write operation timeout.
static SSL_CTX * tlsclient_create_context()
uint64_t * counter_autoflush
#define NEG_RES_RECEIVER_FMT_SUBSET
If the data format of input and output interfaces is the same and data specifier of the input interfa...
static void * sending_thread_func(void *priv)
This function runs in a separate thread. It handles sending data to connected clients for TLS interfa...
void tls_sender_terminate(void *priv)
Set interface state as terminated.
#define DEFAULT_MAX_DATA_LENGTH
uint64_t autoflush_timestamp
static int client_socket_connect(tls_receiver_private_t *priv, struct timeval *tv)
client_socket is used as a receiver
ifc_flush_func_t flush
Pointer to flush function.
trap_buffer_header_t int_mess_header
char * tls_send_ifc_get_id(void *priv)
static void tls_receiver_create_dump(void *priv, uint32_t idx, const char *path)
uint64_t * counter_send_buffer
int input_ifc_negotiation(void *ifc_priv_data, char ifc_type)
void * priv
Pointer to instance's private data.
pthread_mutex_t mtx_no_data
trap_output_ifc_t * out_ifc_list
char * tls_recv_ifc_get_id(void *priv)
#define MAX_CLIENTS_PARAM_LENGTH
Interface of TRAP interfaces.
#define BUFFER_COUNT_PARAM_LENGTH
trap_input_ifc_t * in_ifc_list
#define TRAP_E_BADPARAMS
Bad parameters passed to interface initializer.