Connection object holds information about TCP and UDP connections. There is a connection object for each of the following:
- UDP listener
- TCP listener
- TCP connection.
TCP (established) connections are tracked in a Least Recently Used cache. LRU cache is used to check for various timeout conditions. Each TCP connection has a unique Id (connection ID) associated with it. The only purpose of this ID is to provide a unique key for LRU cache. LRU cache implementation uses UT HASH.
Listener connections are not tracked in LRU cache.
UDP listener and TCP connection objects have DNS query objects associated with them.
|
| enum | listener_start_error_e {
LISTENER_ERR_SOCKET = -1
, LISTENER_ERR_SOCKET_OPT_REUSEADDR = -2
, LISTENER_ERR_SOCKET_OPT_REUSEPORT = -3
, LISTENER_ERR_BIND = -4
,
LISTENER_ERR_LISTEN = -5
, LISTENER_ERR_SOCKET_OPT_IP_PKTINFO = -6
, LISTENER_ERR_SOCKET_OPT_IPV6_V6ONLY = -7
, LISTENER_ERR_SOCKET_OPT_IPV6_RECVPKTINFO = -8
,
LISTENER_ERR_SOCKET_OPT_RCVBUF = -9
, LISTENER_ERR_SOCKET_OPT_SNDBUF = -10
} |
| |
| enum | conn_tcp_state_e {
TCP_CONN_ST_ASSIGN_CONN_ID_ERR = 0
, TCP_CONN_ST_WAIT_FOR_QUERY
, TCP_CONN_ST_WAIT_FOR_QUERY_DATA
, TCP_CONN_ST_WAIT_FOR_WRITE
,
TCP_CONN_ST_CLOSED_FOR_READ
, TCP_CONN_ST_READ_ERR
, TCP_CONN_ST_CLOSED_FOR_WRITE
, TCP_CONN_ST_WRITE_ERR
,
TCP_CONN_ST_QUERY_SIZE_TOOLARGE
} |
| |
|
| void | conn_fifo_enqueue_read (conn_fifo_queue_t *queue, conn_t *entry) |
| |
| conn_t * | conn_fifo_dequeue_read (conn_fifo_queue_t *queue) |
| |
| void | conn_fifo_enqueue_write (conn_fifo_queue_t *queue, conn_t *entry) |
| |
| conn_t * | conn_fifo_dequeue_write (conn_fifo_queue_t *queue) |
| |
| void | conn_fifo_enqueue_gen (conn_fifo_queue_t *queue, conn_t *conn) |
| |
| conn_t * | conn_fifo_dequeue_gen (conn_fifo_queue_t *queue) |
| |
| void | conn_fifo_remove_from_read_queue (conn_fifo_queue_t *queue, conn_t *conn_rm) |
| |
| void | conn_fifo_remove_from_write_queue (conn_fifo_queue_t *queue, conn_t *conn_rm) |
| |
| void | conn_fifo_enqueue_release (conn_fifo_queue_t *queue, conn_t *conn) |
| |
| conn_t * | conn_fifo_dequeue_release (conn_fifo_queue_t *queue) |
| |
| void | conn_tcp_release (conn_tcp_t *conn_tcp) |
| |
| void | conn_udp_release (conn_udp_t *conn_udp) |
| |
| void | conn_release (conn_t *conn) |
| |
| void | conn_udp_vectors_reset (conn_udp_t *conn_udp) |
| |
| conn_udp_t * | conn_udp_new (config_t *cfg, int family) |
| |
| conn_t * | conn_new_tcp (int fd, config_t *cfg, int ip_version, struct sockaddr_storage *client_ip, struct sockaddr_storage *local_ip) |
| |
| conn_t * | conn_listener_provision (config_t *cfg, int family, int protocol, char *err_buf, size_t err_buf_len) |
| |
| conn_t * | conn_lru_cache_get (conn_t **lru, uint64_t id) |
| |
| bool | conn_tcp_id_assign (uint64_t *id, conn_t **lru, uint64_t *base) |
| |
| void | conn_tcp_report_metrics (conn_tcp_t *conn_tcp, metrics_t *metrics) |
| |
◆ CONN_IS_TCP_CONN
| #define CONN_IS_TCP_CONN |
( |
|
conn | ) |
conn->lc == 1 && conn->proto == 1 |
Marco that returns true if conn (conn_t struct) is a TCP connection
◆ CONN_IS_TCP_LISTENER
| #define CONN_IS_TCP_LISTENER |
( |
|
conn | ) |
conn->lc == 0 && conn->proto == 1 |
Marco that returns true if conn (conn_t struct) is a TCP listener
◆ CONN_IS_UDP_LISTENER
| #define CONN_IS_UDP_LISTENER |
( |
|
conn | ) |
conn->lc == 0 && conn->proto == 0 |
Marco that returns true if conn (conn_t struct) is a UDP listener
◆ conn_fifo_queue_t
Connection object FIFO queue. New objects are enqueued (added) to the tail of the queue, and objects are dequeued (removed) from head of the queue.
◆ conn_t
Structure holds data common to TCP and UDP connections.
◆ conn_tcp_state_t
Enumerated TCP connection states.
◆ conn_tcp_t
Structure holds data specific to TCP listener connection.
◆ conn_udp_t
Structure holds data specific to UDP listener connection.
◆ listener_start_error_t
◆ conn_tcp_state_e
Enumerated TCP connection states.
| Enumerator |
|---|
| TCP_CONN_ST_WAIT_FOR_QUERY | Wait for query request (not first one).
|
| TCP_CONN_ST_WAIT_FOR_WRITE | Wait for epoll notification for socket to become "writable".
|
| TCP_CONN_ST_CLOSED_FOR_READ | TCP connection is closed for read (by far end), also known as half close.
|
| TCP_CONN_ST_READ_ERR | There was an error reading from connection socket. Socket is closed and no further reads nor writes are done.
|
| TCP_CONN_ST_CLOSED_FOR_WRITE | TCP connection is was closed for write.
|
| TCP_CONN_ST_WRITE_ERR | There was an error writing to connection socket. Socket is closed and no further reads nor writes are done.
|
| TCP_CONN_ST_QUERY_SIZE_TOOLARGE | Query size received over TCP connection exceeds RIP_NS_PACKETSZ.
|
◆ listener_start_error_e
Enumerated error returned by listener_start() function.
| Enumerator |
|---|
| LISTENER_ERR_SOCKET | Socket create error.
|
| LISTENER_ERR_SOCKET_OPT_REUSEADDR | Error setting socket option SO_REUSEADDR.
|
| LISTENER_ERR_SOCKET_OPT_REUSEPORT | Error setting socket option SO_REUSEPORT.
|
| LISTENER_ERR_BIND | Error binding socket.
|
| LISTENER_ERR_LISTEN | Error calling listen() on socket, applies to TCP only.
|
| LISTENER_ERR_SOCKET_OPT_IP_PKTINFO | Error setting socket option IP_PKTINFO.
|
| LISTENER_ERR_SOCKET_OPT_IPV6_V6ONLY | Error setting socket option IPV6_V6ONLY.
|
| LISTENER_ERR_SOCKET_OPT_IPV6_RECVPKTINFO | Error setting socket option IPV6_RECVPKTINFO.
|
| LISTENER_ERR_SOCKET_OPT_RCVBUF | Error setting socket option IPV6_RECVPKTINFO.
|
| LISTENER_ERR_SOCKET_OPT_SNDBUF | Error setting socket option IPV6_RECVPKTINFO.
|
◆ conn_fifo_dequeue_gen()
Remove (dequeue) a connection object from generic fifo queue.
- Parameters
-
| queue | Queue to remove connection object from. |
- Returns
- On success returns object, otherwise there are no entries in the queue and returns NULL.
◆ conn_fifo_dequeue_read()
Remove (dequeue) a connection object from read fifo queue.
- Parameters
-
| queue | Read queue to remove connection object from. |
- Returns
- On success returns connection object, otherwise there are no entries in the queue and returns NULL.
◆ conn_fifo_dequeue_release()
Remove (dequeue) a generic object from fifo queue.
- Parameters
-
| queue | Queue to remove connection object from. |
- Returns
- On success returns object, otherwise there are no entries in the queue and returns NULL.
◆ conn_fifo_dequeue_write()
Remove (dequeue) a connection object from write fifo queue.
- Parameters
-
| queue | Write queue to remove connection object from. |
- Returns
- On success returns connection object, otherwise there are no entries in the queue and returns NULL.
◆ conn_fifo_enqueue_gen()
Add (enqueue) a connection object to generic fifo queue.
- Parameters
-
| queue | Queue to add object to. |
| conn | Object to queue up. |
◆ conn_fifo_enqueue_read()
Add (enqueue) a connection object to read fifo queue.
- Parameters
-
| queue | Read queue to add connection object to. |
| conn | Connection object to queue up. |
◆ conn_fifo_enqueue_release()
Add (enqueue) a connection object to release fifo queue.
- Parameters
-
| queue | Queue to add object to. |
| conn | Object to queue up. |
◆ conn_fifo_enqueue_write()
Add (enqueue) a connection object to write fifo queue.
- Parameters
-
| queue | Write queue to add connection object to. |
| conn | Connection object to queue up. |
◆ conn_fifo_remove_from_read_queue()
Remove conn from read queue.
- Parameters
-
| queue | Read queue to remove conn object from. |
| conn_rm | Conn object to remove from queue. |
◆ conn_fifo_remove_from_write_queue()
Remove conn from write queue.
- Parameters
-
| queue | Write queue to remove conn object from. |
| conn_rm | Conn object to remove from queue. |
◆ conn_listener_provision()
| conn_t * conn_listener_provision |
( |
config_t * |
cfg, |
|
|
int |
family, |
|
|
int |
protocol, |
|
|
char * |
err_buf, |
|
|
size_t |
err_buf_len |
|
) |
| |
Provision a new TCP or UDP listener and return the corresponding connection conn_t object.
Listener is started and associated with new connection object. New connection object is initialized meaning it has all necessary buffers allocated.
- Parameters
-
| cfg | Configuration object that has settings:
|
| family | IP family to start a listener for, valid options are:
|
| protocol | Protocol to start listener for, valid options are:
- IPPROTO_TCP,
- IPPROTO_UDP.
|
| err_buf | Buffer where to store error message if error was encountered. If NULL no message is stored. |
| err_buf_len | Length of error buffer. |
- Returns
- On success returns a newly allocated and active connection object. On error returns NULL and message is populated into error buffer.
◆ conn_lru_cache_get()
Get entry in TCP connection LRU cache and also update LRU state (entry is set as MRU).
- Parameters
-
| lru | Pointer to LRU cache. |
| id | Entry key to look for. |
- Returns
- On success returns a pointer to connection in LRU cache. Entry place in LRU is updated. Otherwise returns NULL indicating that entry was not found in LRU cache.
◆ conn_new_tcp()
| conn_t * conn_new_tcp |
( |
int |
fd, |
|
|
config_t * |
cfg, |
|
|
int |
ip_version, |
|
|
struct sockaddr_storage * |
client_ip, |
|
|
struct sockaddr_storage * |
local_ip |
|
) |
| |
Create a new TCP connection object for an established TCP connection.
- Parameters
-
| fd | Socket for TCP connection. |
| cfg | Application configuration to get various settings from. |
| ip_version | IP version this connection is for, 0=IPv4, 1=IPv6. |
| client_ip | Client IP address. |
| local_ip | Local IP address. |
- Returns
- Returns a newly allocated and initialized TCP connection object.
◆ conn_release()
| void conn_release |
( |
conn_t * |
conn | ) |
|
Free memory associated with conn_t object and free object it self.
- Parameters
-
| conn | Connection object to release. |
◆ conn_tcp_id_assign()
| bool conn_tcp_id_assign |
( |
uint64_t * |
id, |
|
|
conn_t ** |
lru, |
|
|
uint64_t * |
base |
|
) |
| |
Assign a new TCP connection ID.
- Parameters
-
| id | Where to store newly assigned TCP connection ID. |
| lru | TCP connection LRU cache, used to verify uniqueness of connection ID being assigned. |
| base | Base for connection ID. (Base is unique per Vectorloop object. |
- Returns
- Returns true if connection ID was assigned, otherwise returns false.
◆ conn_tcp_release()
Free memory associated with conn_tcp_t object and free object it self.
- Parameters
-
| conn_tcp | TCP connection object to release. |
◆ conn_tcp_report_metrics()
Report TCP metrics for a query.
- Parameters
-
| conn_tcp | TCP connection to report metrics for. |
| metrics | Metrics object where to report metrics. |
◆ conn_udp_new()
Create a new UDP connection object
- Parameters
-
| cfg | Application configuration to get various settings from. |
| family | IP family: AF_INET or AF_INET6. |
- Returns
- Returns a newly allocated and initialized UDP connection object.
◆ conn_udp_release()
Free memory associated with conn_udp_t object and free object it self.
- Parameters
-
| conn_udp | UDP connection object to release. |
◆ conn_udp_vectors_reset()
| void conn_udp_vectors_reset |
( |
conn_udp_t * |
conn_udp | ) |
|
Reset UDP connection vectors so the can be reused for next iteration of read/resolve/send of DNS queries.
- Parameters
-
| conn_udp | UDP connection to reset vectors for. |