Libtrap: Internal development docs  1.16.1
ifc_tls_internal.h
Go to the documentation of this file.
1 /**
2  * \file ifc_tls_internal.h
3  * \brief TRAP TCP/IP interfaces private structures
4  * \author Tomas Cejka <cejkat@cesnet.cz>
5  * \date 2014
6  */
7 /*
8  * Copyright (C) 2013 CESNET
9  *
10  * LICENSE TERMS
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  * notice, this list of conditions and the following disclaimer in
19  * the documentation and/or other materials provided with the
20  * distribution.
21  * 3. Neither the name of the Company nor the names of its contributors
22  * may be used to endorse or promote products derived from this
23  * software without specific prior written permission.
24  *
25  * ALTERNATIVELY, provided that this notice is retained in full, this
26  * product may be distributed under the terms of the GNU General Public
27  * License (GPL) version 2 or later, in which case the provisions
28  * of the GPL apply INSTEAD OF those given above.
29  *
30  * This software is provided ``as is'', and any express or implied
31  * warranties, including, but not limited to, the implied warranties of
32  * merchantability and fitness for a particular purpose are disclaimed.
33  * In no event shall the company or contributors be liable for any
34  * direct, indirect, incidental, special, exemplary, or consequential
35  * damages (including, but not limited to, procurement of substitute
36  * goods or services; loss of use, data, or profits; or business
37  * interruption) however caused and on any theory of liability, whether
38  * in contract, strict liability, or tort (including negligence or
39  * otherwise) arising in any way out of the use of this software, even
40  * if advised of the possibility of such damage.
41  *
42  */
43 
44 
45 #include <openssl/ssl.h>
46 #include <openssl/err.h>
47 
48 #include "ifc_socket_common.h"
49 
50 
51 /** \addtogroup trap_ifc
52  * @{
53  */
54 
55 /** \addtogroup tls_ifc
56  * @{
57  */
58 
59  /**
60  * \defgroup tls_sender TLS Output IFC
61  * @{
62  */
63 
64 /**
65  * \brief Structure for TLS IFC client information.
66  */
67 typedef struct tlsclient_s {
68  SSL *ssl; /**< Client SSL info. */
69 
70  int sd; /**< Client socket descriptor */
71  void *sending_pointer; /**< Pointer to data in client's assigned buffer */
72 
73  uint64_t timer_total; /**< Total time spent sending (microseconds) since client connection */
74  uint64_t timeouts; /**< Number of messages dropped (since connection) due to client blocking active buffer */
75 
76  uint32_t timer_last; /**< Time spent on last send call [microseconds] */
77  uint32_t pending_bytes; /**< The size of data that must be sent */
78  uint32_t id; /**< Client identification - PID for unix socket, port number for TCP socket */
79  uint32_t assigned_buffer; /**< Index of assigned buffer in array of buffers */
80 } tlsclient_t;
81 
82 /**
83  * \brief Structure for TLS IFC private information.
84  */
85 typedef struct tls_sender_private_s {
86  trap_ctx_priv_t *ctx; /**< Libtrap context */
87 
88  SSL_CTX *sslctx; /**< Server SSL context. */
89 
90  char *keyfile; /**< Path to private key file in PEM format. */
91  char *certfile; /**< Path to certificate in PEM format. */
92  char *cafile; /**< Path to trusted CAs (can be chain file) file in PEM format. */
93 
94  int term_pipe[2]; /**< File descriptor pair for select() termination */
95  int server_sd; /**< Server socket descriptor */
96 
97  char *server_port; /**< TCPIP port number / UNIX socket path */
98  char is_terminated; /**< Termination flag */
99  char initialized; /**< Initialization flag */
100 
101  uint64_t autoflush_timestamp; /**< Time when the last buffer was finished - used for autoflush */
102  uint64_t clients_bit_arr; /**< Bit array of currently connected clients - lowest bit = index 0, highest bit = index 63 */
103 
104  uint32_t ifc_idx; /**< Index of interface in 'out_ifc_list' array */
105  uint32_t connected_clients; /**< Number of currently connected clients */
106  uint32_t clients_arr_size; /**< Maximum number of clients */
107  uint32_t buffer_count; /**< Number of buffers used */
108  uint32_t buffer_size; /**< Buffer size [bytes] */
109  uint32_t active_buffer; /**< Index of active buffer in 'buffers' array */
110 
111  buffer_t *buffers; /**< Array of buffer structures */
112  tlsclient_t *clients; /**< Array of client structures */
113 
114  pthread_t accept_thr; /**< Pthread structure containing info about accept thread */
115  pthread_t send_thr; /**< Pthread structure containing info about sending thread */
116 
117  pthread_mutex_t mtx_no_data; /**< Mutex for cond_no_data */
118  pthread_cond_t cond_no_data; /**< Condition struct used when waiting for new data */
119  pthread_cond_t cond_full_buffer; /**< Condition struct used when waiting for free buffer */
121 
122 /**
123  * @}
124  */
125 
126 /**
127  * \defgroup tls_receiver TLS Input IFC
128  * @{
129  */
130 typedef struct tls_receiver_private_s {
131  trap_ctx_priv_t *ctx; /**< Libtrap context */
132  char *dest_addr; /**< Destination address */
133  char *dest_port; /**< Destination port */
134 
135  char *keyfile; /**< Path to private key file in PEM format. */
136  char *certfile; /**< Path to certificate in PEM format. */
137  char *cafile; /**< Path to trusted CAs (can be chain file) file in PEM format. */
138 
139  SSL_CTX *sslctx; /**< Whole client SSL context. */
140  SSL *ssl; /**< SSL conection info of client */
141 
142  char connected; /**< Indicates whether client is connected to server. */
143  char is_terminated; /**< Indicates whether client should be destroyed. */
144  int sd; /**< Socket descriptor */
145  void *data_pointer; /**< Pointer to next free byte, if NULL, we ended in header */
146  uint32_t data_wait_size; /** Missing data to accept in the next function call */
147  void *ext_buffer; /**< Pointer to buffer that was passed by higher layer - this is the place we write */
148  uint32_t ext_buffer_size; /** size of content of the extbuffer */
149  trap_buffer_header_t int_mess_header; /**< Internal message header - used for message_buffer payload size \note message_buffer size is sizeof(tls_tdu_header_t) + payload size */
150  uint32_t ifc_idx; /**< Index of IFC */
152 
153 /**
154  * @}
155  */
156 
157 /**
158  * @}
159  */
160 
161 /**
162  * @}
163  */
164 
uint64_t timer_total
pthread_cond_t cond_full_buffer
struct tls_sender_private_s tls_sender_private_t
Structure for TLS IFC private information.
Output buffer structure.
uint32_t pending_bytes
struct tls_receiver_private_s tls_receiver_private_t
pthread_cond_t cond_no_data
Structure for TLS IFC private information.
trap_ctx_priv_t * ctx
struct tlsclient_s tlsclient_t
Structure for TLS IFC client information.
trap_ctx_priv_t * ctx
Structure for TLS IFC client information.
void * sending_pointer
uint32_t timer_last
This file contains common functions and structures used in socket based interfaces (tcp-ip / tls)...
uint32_t assigned_buffer
uint64_t timeouts
trap_buffer_header_t int_mess_header
pthread_mutex_t mtx_no_data