5 * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
6 * David Goulet <dgoulet@efficios.com>
7 * 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License, version 2 only, as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 51
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <urcu/wfcqueue.h>
28 #include <urcu/list.h>
30 #include <common/hashtable/hashtable.h>
31 #include <common/sessiond-comm/sessiond-comm.h>
32 #include <common/sessiond-comm/relayd.h>
33 #include <common/dynamic-buffer.h>
37 enum connection_type
{
38 RELAY_CONNECTION_UNKNOWN
= 0,
41 RELAY_VIEWER_COMMAND
= 3,
42 RELAY_VIEWER_NOTIFICATION
= 4,
45 enum data_connection_state
{
46 DATA_CONNECTION_STATE_RECEIVE_HEADER
= 0,
47 DATA_CONNECTION_STATE_RECEIVE_PAYLOAD
= 1,
50 enum ctrl_connection_state
{
51 CTRL_CONNECTION_STATE_RECEIVE_HEADER
= 0,
52 CTRL_CONNECTION_STATE_RECEIVE_PAYLOAD
= 1,
55 struct data_connection_state_receive_header
{
56 uint64_t received
, left_to_receive
;
57 char header_reception_buffer
[sizeof(struct lttcomm_relayd_data_hdr
)];
60 struct data_connection_state_receive_payload
{
61 uint64_t received
, left_to_receive
;
62 struct lttcomm_relayd_data_hdr header
;
66 struct ctrl_connection_state_receive_header
{
67 uint64_t received
, left_to_receive
;
70 struct ctrl_connection_state_receive_payload
{
71 uint64_t received
, left_to_receive
;
72 struct lttcomm_relayd_hdr header
;
76 * Internal structure to map a socket with the corresponding session.
77 * A hashtable indexed on the socket FD is used for the lookups.
79 * Connections are assumed to be accessed from a single thread. Live
80 * connections between the relay and a live client are only accessed
81 * from the live worker thread.
83 * The connections between the consumerd/sessiond and the relayd are only
84 * handled by the "main" worker thread (as in, the worker thread in main.c).
86 * This is why there are no back references to connections from the
87 * sessions and session list.
89 struct relay_connection
{
90 struct lttcomm_sock
*sock
;
91 struct cds_wfcq_node qnode
;
93 enum connection_type type
;
95 * session is only ever set for RELAY_CONTROL connection type.
97 struct relay_session
*session
;
99 * viewer_session is only ever set for RELAY_VIEWER_COMMAND
102 struct relay_viewer_session
*viewer_session
;
105 * Protocol version to use for this connection. Only valid for
106 * RELAY_CONTROL connection type.
113 bool version_check_done
;
116 * Node member of connection within global socket hash table.
118 struct lttng_ht_node_ulong sock_n
;
120 struct lttng_ht
*socket_ht
; /* HACK: Contained within this hash table. */
121 struct rcu_head rcu_node
; /* For call_rcu teardown. */
125 enum data_connection_state state_id
;
127 struct data_connection_state_receive_header receive_header
;
128 struct data_connection_state_receive_payload receive_payload
;
132 enum ctrl_connection_state state_id
;
134 struct ctrl_connection_state_receive_header receive_header
;
135 struct ctrl_connection_state_receive_payload receive_payload
;
137 struct lttng_dynamic_buffer reception_buffer
;
142 struct relay_connection
*connection_create(struct lttcomm_sock
*sock
,
143 enum connection_type type
);
144 struct relay_connection
*connection_get_by_sock(struct lttng_ht
*relay_connections_ht
,
146 int connection_reset_protocol_state(struct relay_connection
*connection
);
147 bool connection_get(struct relay_connection
*connection
);
148 void connection_put(struct relay_connection
*connection
);
149 void connection_ht_add(struct lttng_ht
*relay_connections_ht
,
150 struct relay_connection
*conn
);
151 int connection_set_session(struct relay_connection
*conn
,
152 struct relay_session
*session
);
154 #endif /* _CONNECTION_H */