| 1 | #ifndef _CONNECTION_H |
| 2 | #define _CONNECTION_H |
| 3 | |
| 4 | /* |
| 5 | * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com> |
| 6 | * David Goulet <dgoulet@efficios.com> |
| 7 | * 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 8 | * |
| 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. |
| 12 | * |
| 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 |
| 16 | * more details. |
| 17 | * |
| 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. |
| 21 | */ |
| 22 | |
| 23 | #include <limits.h> |
| 24 | #include <inttypes.h> |
| 25 | #include <pthread.h> |
| 26 | #include <urcu.h> |
| 27 | #include <urcu/wfcqueue.h> |
| 28 | #include <urcu/list.h> |
| 29 | |
| 30 | #include <common/hashtable/hashtable.h> |
| 31 | #include <common/sessiond-comm/sessiond-comm.h> |
| 32 | |
| 33 | #include "session.h" |
| 34 | |
| 35 | enum connection_type { |
| 36 | RELAY_CONNECTION_UNKNOWN = 0, |
| 37 | RELAY_DATA = 1, |
| 38 | RELAY_CONTROL = 2, |
| 39 | RELAY_VIEWER_COMMAND = 3, |
| 40 | RELAY_VIEWER_NOTIFICATION = 4, |
| 41 | }; |
| 42 | |
| 43 | /* |
| 44 | * Internal structure to map a socket with the corresponding session. |
| 45 | * A hashtable indexed on the socket FD is used for the lookups. |
| 46 | * |
| 47 | * Connections are assumed to be accessed from a single thread. Live |
| 48 | * connections between the relay and a live client are only accessed |
| 49 | * from the live worker thread. |
| 50 | * |
| 51 | * The connections between the consumerd/sessiond and the relayd are only |
| 52 | * handled by the "main" worker thread (as in, the worker thread in main.c). |
| 53 | * |
| 54 | * This is why there are no back references to connections from the |
| 55 | * sessions and session list. |
| 56 | */ |
| 57 | struct relay_connection { |
| 58 | struct lttcomm_sock *sock; |
| 59 | struct cds_wfcq_node qnode; |
| 60 | |
| 61 | enum connection_type type; |
| 62 | /* |
| 63 | * session is only ever set for RELAY_CONTROL connection type. |
| 64 | */ |
| 65 | struct relay_session *session; |
| 66 | /* |
| 67 | * viewer_session is only ever set for RELAY_VIEWER_COMMAND |
| 68 | * connection type. |
| 69 | */ |
| 70 | struct relay_viewer_session *viewer_session; |
| 71 | |
| 72 | /* |
| 73 | * Protocol version to use for this connection. Only valid for |
| 74 | * RELAY_CONTROL connection type. |
| 75 | */ |
| 76 | uint32_t major; |
| 77 | uint32_t minor; |
| 78 | |
| 79 | struct urcu_ref ref; |
| 80 | |
| 81 | bool version_check_done; |
| 82 | |
| 83 | /* |
| 84 | * Node member of connection within global socket hash table. |
| 85 | */ |
| 86 | struct lttng_ht_node_ulong sock_n; |
| 87 | bool in_socket_ht; |
| 88 | struct lttng_ht *socket_ht; /* HACK: Contained within this hash table. */ |
| 89 | struct rcu_head rcu_node; /* For call_rcu teardown. */ |
| 90 | }; |
| 91 | |
| 92 | struct relay_connection *connection_create(struct lttcomm_sock *sock, |
| 93 | enum connection_type type); |
| 94 | struct relay_connection *connection_get_by_sock(struct lttng_ht *relay_connections_ht, |
| 95 | int sock); |
| 96 | bool connection_get(struct relay_connection *connection); |
| 97 | void connection_put(struct relay_connection *connection); |
| 98 | void connection_ht_add(struct lttng_ht *relay_connections_ht, |
| 99 | struct relay_connection *conn); |
| 100 | |
| 101 | #endif /* _CONNECTION_H */ |