5 * Copyright (C) 2013 Julien Desfossez <jdesfossez@efficios.com>
6 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
7 * Copyright (C) 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * SPDX-License-Identifier: GPL-2.0-only
17 #include <urcu/wfcqueue.h>
18 #include <urcu/list.h>
20 #include <common/hashtable/hashtable.h>
21 #include <common/sessiond-comm/sessiond-comm.h>
22 #include <common/sessiond-comm/relayd.h>
23 #include <common/dynamic-buffer.h>
27 enum connection_type
{
28 RELAY_CONNECTION_UNKNOWN
= 0,
31 RELAY_VIEWER_COMMAND
= 3,
32 RELAY_VIEWER_NOTIFICATION
= 4,
35 enum data_connection_state
{
36 DATA_CONNECTION_STATE_RECEIVE_HEADER
= 0,
37 DATA_CONNECTION_STATE_RECEIVE_PAYLOAD
= 1,
40 enum ctrl_connection_state
{
41 CTRL_CONNECTION_STATE_RECEIVE_HEADER
= 0,
42 CTRL_CONNECTION_STATE_RECEIVE_PAYLOAD
= 1,
45 struct data_connection_state_receive_header
{
46 uint64_t received
, left_to_receive
;
47 char header_reception_buffer
[sizeof(struct lttcomm_relayd_data_hdr
)];
50 struct data_connection_state_receive_payload
{
51 uint64_t received
, left_to_receive
;
52 struct lttcomm_relayd_data_hdr header
;
56 struct ctrl_connection_state_receive_header
{
57 uint64_t received
, left_to_receive
;
60 struct ctrl_connection_state_receive_payload
{
61 uint64_t received
, left_to_receive
;
62 struct lttcomm_relayd_hdr header
;
66 * Internal structure to map a socket with the corresponding session.
67 * A hashtable indexed on the socket FD is used for the lookups.
69 * Connections are assumed to be accessed from a single thread. Live
70 * connections between the relay and a live client are only accessed
71 * from the live worker thread.
73 * The connections between the consumerd/sessiond and the relayd are only
74 * handled by the "main" worker thread (as in, the worker thread in main.c).
76 * This is why there are no back references to connections from the
77 * sessions and session list.
79 struct relay_connection
{
80 struct lttcomm_sock
*sock
;
81 struct cds_wfcq_node qnode
;
83 enum connection_type type
;
85 * session is only ever set for RELAY_CONTROL connection type.
87 struct relay_session
*session
;
89 * viewer_session is only ever set for RELAY_VIEWER_COMMAND
92 struct relay_viewer_session
*viewer_session
;
95 * Protocol version to use for this connection. Only valid for
96 * RELAY_CONTROL connection type.
103 bool version_check_done
;
106 * Node member of connection within global socket hash table.
108 struct lttng_ht_node_ulong sock_n
;
110 struct lttng_ht
*socket_ht
; /* HACK: Contained within this hash table. */
111 struct rcu_head rcu_node
; /* For call_rcu teardown. */
115 enum data_connection_state state_id
;
117 struct data_connection_state_receive_header receive_header
;
118 struct data_connection_state_receive_payload receive_payload
;
122 enum ctrl_connection_state state_id
;
124 struct ctrl_connection_state_receive_header receive_header
;
125 struct ctrl_connection_state_receive_payload receive_payload
;
127 struct lttng_dynamic_buffer reception_buffer
;
132 struct relay_connection
*connection_create(struct lttcomm_sock
*sock
,
133 enum connection_type type
);
134 struct relay_connection
*connection_get_by_sock(struct lttng_ht
*relay_connections_ht
,
136 int connection_reset_protocol_state(struct relay_connection
*connection
);
137 bool connection_get(struct relay_connection
*connection
);
138 void connection_put(struct relay_connection
*connection
);
139 void connection_ht_add(struct lttng_ht
*relay_connections_ht
,
140 struct relay_connection
*conn
);
141 int connection_set_session(struct relay_connection
*conn
,
142 struct relay_session
*session
);
144 #endif /* _CONNECTION_H */