| 1 | /* |
| 2 | * Copyright (C) 2012 David Goulet <dgoulet@efficios.com> |
| 3 | * Copyright (C) 2012 Julien Desfossez <julien.desfossez@efficios.com> |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0-only |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | #ifndef _RELAYD_COMM |
| 10 | #define _RELAYD_COMM |
| 11 | |
| 12 | #include <common/compiler.hpp> |
| 13 | #include <common/defaults.hpp> |
| 14 | #include <common/index/ctf-index.hpp> |
| 15 | #include <common/macros.hpp> |
| 16 | #include <common/optional.hpp> |
| 17 | #include <common/uuid.hpp> |
| 18 | |
| 19 | #include <lttng/lttng.h> |
| 20 | |
| 21 | #include <limits.h> |
| 22 | #include <stdint.h> |
| 23 | |
| 24 | #define RELAYD_VERSION_COMM_MAJOR VERSION_MAJOR |
| 25 | #define RELAYD_VERSION_COMM_MINOR VERSION_MINOR |
| 26 | |
| 27 | #define RELAYD_COMM_LTTNG_HOST_NAME_MAX_2_4 64 |
| 28 | #define RELAYD_COMM_LTTNG_NAME_MAX_2_4 255 |
| 29 | #define RELAYD_COMM_LTTNG_PATH_MAX 4096 |
| 30 | #define RELAYD_COMM_DEFAULT_STREAM_NAME_LEN 264 /* 256 + 8 */ |
| 31 | |
| 32 | /* |
| 33 | * lttng-relayd communication header. |
| 34 | */ |
| 35 | struct lttcomm_relayd_hdr { |
| 36 | /* Circuit ID not used for now so always ignored */ |
| 37 | uint64_t circuit_id; |
| 38 | uint64_t data_size; /* data size following this header */ |
| 39 | uint32_t cmd; /* enum lttcomm_relayd_command */ |
| 40 | uint32_t cmd_version; /* command version */ |
| 41 | } LTTNG_PACKED; |
| 42 | |
| 43 | /* |
| 44 | * lttng-relayd data header. |
| 45 | */ |
| 46 | struct lttcomm_relayd_data_hdr { |
| 47 | /* Circuit ID not used for now so always ignored */ |
| 48 | uint64_t circuit_id; |
| 49 | uint64_t stream_id; /* Stream ID known by the relayd */ |
| 50 | uint64_t net_seq_num; /* Network sequence number, per stream. */ |
| 51 | uint32_t data_size; /* data size following this header */ |
| 52 | uint32_t padding_size; /* Size of 0 padding the data */ |
| 53 | } LTTNG_PACKED; |
| 54 | |
| 55 | /* |
| 56 | * Reply from a create session command. |
| 57 | */ |
| 58 | struct lttcomm_relayd_status_session { |
| 59 | uint64_t session_id; |
| 60 | uint32_t ret_code; |
| 61 | } LTTNG_PACKED; |
| 62 | |
| 63 | /* |
| 64 | * Used to add a stream on the relay daemon. |
| 65 | */ |
| 66 | struct lttcomm_relayd_add_stream { |
| 67 | char channel_name[RELAYD_COMM_DEFAULT_STREAM_NAME_LEN]; |
| 68 | char pathname[RELAYD_COMM_LTTNG_PATH_MAX]; |
| 69 | } LTTNG_PACKED; |
| 70 | |
| 71 | /* |
| 72 | * Used to add a stream on the relay daemon. |
| 73 | * Protocol version 2.2 |
| 74 | */ |
| 75 | struct lttcomm_relayd_add_stream_2_2 { |
| 76 | char channel_name[RELAYD_COMM_DEFAULT_STREAM_NAME_LEN]; |
| 77 | char pathname[RELAYD_COMM_LTTNG_PATH_MAX]; |
| 78 | uint64_t tracefile_size; |
| 79 | uint64_t tracefile_count; |
| 80 | } LTTNG_PACKED; |
| 81 | |
| 82 | struct lttcomm_relayd_add_stream_2_11 { |
| 83 | uint32_t channel_name_len; |
| 84 | uint32_t pathname_len; |
| 85 | uint64_t tracefile_size; |
| 86 | uint64_t tracefile_count; |
| 87 | uint64_t trace_chunk_id; |
| 88 | char names[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH]; |
| 89 | } LTTNG_PACKED; |
| 90 | |
| 91 | /* |
| 92 | * Answer from an add stream command. |
| 93 | */ |
| 94 | struct lttcomm_relayd_status_stream { |
| 95 | uint64_t handle; |
| 96 | uint32_t ret_code; |
| 97 | } LTTNG_PACKED; |
| 98 | |
| 99 | /* |
| 100 | * Used to return command code for command not needing special data. |
| 101 | */ |
| 102 | struct lttcomm_relayd_generic_reply { |
| 103 | uint32_t ret_code; |
| 104 | } LTTNG_PACKED; |
| 105 | |
| 106 | /* |
| 107 | * Version command. |
| 108 | */ |
| 109 | struct lttcomm_relayd_version { |
| 110 | uint32_t major; |
| 111 | uint32_t minor; |
| 112 | } LTTNG_PACKED; |
| 113 | |
| 114 | /* |
| 115 | * Metadata payload used when metadata command is sent. |
| 116 | */ |
| 117 | struct lttcomm_relayd_metadata_payload { |
| 118 | uint64_t stream_id; |
| 119 | uint32_t padding_size; |
| 120 | char payload[]; |
| 121 | } LTTNG_PACKED; |
| 122 | |
| 123 | /* |
| 124 | * Used to indicate that a specific stream id can now be closed. |
| 125 | */ |
| 126 | struct lttcomm_relayd_close_stream { |
| 127 | uint64_t stream_id; |
| 128 | uint64_t last_net_seq_num; /* sequence number of last packet */ |
| 129 | } LTTNG_PACKED; |
| 130 | |
| 131 | /* |
| 132 | * Used to test if for a given stream id the data is pending on the relayd side |
| 133 | * for reading. |
| 134 | */ |
| 135 | struct lttcomm_relayd_data_pending { |
| 136 | uint64_t stream_id; |
| 137 | uint64_t last_net_seq_num; /* Sequence number of the last packet */ |
| 138 | } LTTNG_PACKED; |
| 139 | |
| 140 | struct lttcomm_relayd_begin_data_pending { |
| 141 | uint64_t session_id; |
| 142 | } LTTNG_PACKED; |
| 143 | |
| 144 | struct lttcomm_relayd_end_data_pending { |
| 145 | uint64_t session_id; |
| 146 | } LTTNG_PACKED; |
| 147 | |
| 148 | struct lttcomm_relayd_quiescent_control { |
| 149 | uint64_t stream_id; |
| 150 | } LTTNG_PACKED; |
| 151 | |
| 152 | /* |
| 153 | * Index data. |
| 154 | */ |
| 155 | struct lttcomm_relayd_index { |
| 156 | uint64_t relay_stream_id; |
| 157 | uint64_t net_seq_num; |
| 158 | uint64_t packet_size; |
| 159 | uint64_t content_size; |
| 160 | uint64_t timestamp_begin; |
| 161 | uint64_t timestamp_end; |
| 162 | uint64_t events_discarded; |
| 163 | uint64_t stream_id; |
| 164 | /* 2.8+ */ |
| 165 | uint64_t stream_instance_id; |
| 166 | uint64_t packet_seq_num; |
| 167 | } LTTNG_PACKED; |
| 168 | |
| 169 | static inline size_t lttcomm_relayd_index_len(uint32_t major, uint32_t minor) |
| 170 | { |
| 171 | if (major == 1) { |
| 172 | switch (minor) { |
| 173 | case 0: |
| 174 | return offsetof(struct lttcomm_relayd_index, stream_id) + |
| 175 | member_sizeof(struct lttcomm_relayd_index, stream_id); |
| 176 | case 1: |
| 177 | return offsetof(struct lttcomm_relayd_index, packet_seq_num) + |
| 178 | member_sizeof(struct lttcomm_relayd_index, packet_seq_num); |
| 179 | default: |
| 180 | abort(); |
| 181 | } |
| 182 | } |
| 183 | abort(); |
| 184 | } |
| 185 | |
| 186 | /* |
| 187 | * Create session in 2.4 adds additionnal parameters for live reading. |
| 188 | */ |
| 189 | struct lttcomm_relayd_create_session_2_4 { |
| 190 | char session_name[RELAYD_COMM_LTTNG_NAME_MAX_2_4]; |
| 191 | char hostname[RELAYD_COMM_LTTNG_HOST_NAME_MAX_2_4]; |
| 192 | uint32_t live_timer; |
| 193 | uint32_t snapshot; |
| 194 | } LTTNG_PACKED; |
| 195 | |
| 196 | struct lttcomm_relayd_create_session_2_11 { |
| 197 | uint32_t session_name_len; |
| 198 | uint32_t hostname_len; |
| 199 | /* Optional, set to 0 to indicate it is not user-specified. */ |
| 200 | uint32_t base_path_len; |
| 201 | uint32_t live_timer; |
| 202 | uint8_t snapshot; |
| 203 | uint8_t session_name_contains_creation_time; |
| 204 | /* Sessiond instance UUID */ |
| 205 | uint8_t sessiond_uuid[LTTNG_UUID_LEN]; |
| 206 | /* Sessiond session id */ |
| 207 | uint64_t session_id; |
| 208 | /* Session creation time, in seconds since UNIX Epoch. */ |
| 209 | uint64_t creation_time; |
| 210 | LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED current_chunk_id; |
| 211 | /* Contains the session_name, hostname, base_path. */ |
| 212 | char names[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH]; |
| 213 | } LTTNG_PACKED; |
| 214 | |
| 215 | struct lttcomm_relayd_create_session_reply_2_11 { |
| 216 | struct lttcomm_relayd_status_session generic; |
| 217 | /* Includes the '\0' terminator. */ |
| 218 | uint32_t output_path_length; |
| 219 | char output_path[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH]; |
| 220 | } LTTNG_PACKED; |
| 221 | |
| 222 | /* |
| 223 | * Used to ask the relay to reset the metadata trace file (regeneration). |
| 224 | * Send the new version of the metadata (starts at 0). |
| 225 | */ |
| 226 | struct lttcomm_relayd_reset_metadata { |
| 227 | uint64_t stream_id; |
| 228 | uint64_t version; |
| 229 | } LTTNG_PACKED; |
| 230 | |
| 231 | struct lttcomm_relayd_stream_rotation_position { |
| 232 | uint64_t stream_id; |
| 233 | /* |
| 234 | * Sequence number of the first packet belonging to the new |
| 235 | * "destination" trace chunk to which the stream is rotating. |
| 236 | * |
| 237 | * Ignored for metadata streams. |
| 238 | */ |
| 239 | uint64_t rotate_at_seq_num; |
| 240 | } LTTNG_PACKED; |
| 241 | |
| 242 | /* |
| 243 | * For certain releases, the LTTNG_PACKED annotation was missing on the |
| 244 | * `new_chunk_id` field which causes padding to be added between the |
| 245 | * "optional" structure's `is_set` and `value` fields. |
| 246 | * |
| 247 | * Three alignment cases are handled: |
| 248 | * - `value` is aligned to the next byte boundary after `is_set` |
| 249 | * no padding is produced, see |
| 250 | * `struct lttcomm_relayd_rotate_streams_packed`, |
| 251 | * - `value` is aligned to the next 4-byte boundary after `is_set` |
| 252 | * (e.g. x86), 3 bytes of padding are produced, see |
| 253 | * `struct lttcomm_relayd_rotate_streams_3_bytes_padding`, |
| 254 | * - `value` is aligned to the next 8-byte boundary after `is_set` |
| 255 | * (e.g. x86-64), 7 bytes of padding are produced, see |
| 256 | * `struct lttcomm_relayd_rotate_streams_7_bytes_padding`. |
| 257 | * |
| 258 | * Note that since this structure's advertised size is used to determine |
| 259 | * the size of the padding it includes, it can't be extended with new |
| 260 | * optional fields. A new command would be needed. |
| 261 | */ |
| 262 | struct lttcomm_relayd_rotate_streams { |
| 263 | uint32_t stream_count; |
| 264 | /* |
| 265 | * Streams can be rotated outside of a chunk but not be parented to |
| 266 | * a new chunk. |
| 267 | * |
| 268 | * Improperly packed, but left as-is for backwards compatibility |
| 269 | * with unpatched relay daemons. |
| 270 | */ |
| 271 | LTTNG_OPTIONAL_COMM(uint64_t) new_chunk_id; |
| 272 | /* `stream_count` positions follow. */ |
| 273 | struct lttcomm_relayd_stream_rotation_position rotation_positions[]; |
| 274 | } LTTNG_PACKED; |
| 275 | |
| 276 | struct lttcomm_relayd_rotate_streams_packed { |
| 277 | uint32_t stream_count; |
| 278 | LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED new_chunk_id; |
| 279 | struct lttcomm_relayd_stream_rotation_position rotation_positions[]; |
| 280 | } LTTNG_PACKED; |
| 281 | |
| 282 | struct lttcomm_relayd_rotate_streams_3_bytes_padding { |
| 283 | uint32_t stream_count; |
| 284 | struct { |
| 285 | union { |
| 286 | uint8_t is_set; |
| 287 | uint32_t padding; |
| 288 | }; |
| 289 | uint64_t value; |
| 290 | } LTTNG_PACKED new_chunk_id; |
| 291 | struct lttcomm_relayd_stream_rotation_position rotation_positions[]; |
| 292 | } LTTNG_PACKED; |
| 293 | |
| 294 | struct lttcomm_relayd_rotate_streams_7_bytes_padding { |
| 295 | uint32_t stream_count; |
| 296 | struct { |
| 297 | union { |
| 298 | uint8_t is_set; |
| 299 | uint64_t padding; |
| 300 | }; |
| 301 | uint64_t value; |
| 302 | } LTTNG_PACKED new_chunk_id; |
| 303 | struct lttcomm_relayd_stream_rotation_position rotation_positions[]; |
| 304 | } LTTNG_PACKED; |
| 305 | |
| 306 | struct lttcomm_relayd_create_trace_chunk { |
| 307 | uint64_t chunk_id; |
| 308 | /* Seconds since EPOCH. */ |
| 309 | uint64_t creation_timestamp; |
| 310 | /* Includes trailing NULL. */ |
| 311 | uint32_t override_name_length; |
| 312 | char override_name[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH]; |
| 313 | } LTTNG_PACKED; |
| 314 | |
| 315 | struct lttcomm_relayd_close_trace_chunk { |
| 316 | uint64_t chunk_id; |
| 317 | /* Seconds since EPOCH. */ |
| 318 | uint64_t close_timestamp; |
| 319 | /* enum lttng_trace_chunk_command_type */ |
| 320 | LTTNG_OPTIONAL_COMM(uint32_t) LTTNG_PACKED close_command; |
| 321 | } LTTNG_PACKED; |
| 322 | |
| 323 | struct lttcomm_relayd_close_trace_chunk_reply { |
| 324 | struct lttcomm_relayd_generic_reply generic; |
| 325 | /* Includes trailing NULL. */ |
| 326 | uint32_t path_length; |
| 327 | char path[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH]; |
| 328 | } LTTNG_PACKED; |
| 329 | |
| 330 | struct lttcomm_relayd_trace_chunk_exists { |
| 331 | uint64_t chunk_id; |
| 332 | } LTTNG_PACKED; |
| 333 | |
| 334 | struct lttcomm_relayd_trace_chunk_exists_reply { |
| 335 | struct lttcomm_relayd_generic_reply generic; |
| 336 | uint8_t trace_chunk_exists; |
| 337 | } LTTNG_PACKED; |
| 338 | |
| 339 | enum lttcomm_relayd_configuration_flag { |
| 340 | /* The relay daemon (2.12) is configured to allow clear operations. */ |
| 341 | LTTCOMM_RELAYD_CONFIGURATION_FLAG_CLEAR_ALLOWED = (1 << 0), |
| 342 | }; |
| 343 | |
| 344 | struct lttcomm_relayd_get_configuration { |
| 345 | uint64_t query_flags; |
| 346 | } LTTNG_PACKED; |
| 347 | |
| 348 | /* |
| 349 | * Used to return a relay daemon's configuration in reply to the |
| 350 | * RELAYD_GET_CONFIGURATION command. |
| 351 | */ |
| 352 | struct lttcomm_relayd_get_configuration_reply { |
| 353 | struct lttcomm_relayd_generic_reply generic; |
| 354 | /* Set of lttcomm_relayd_configuration_flag. */ |
| 355 | uint64_t relayd_configuration_flags; |
| 356 | /* Optional variable-length payload. */ |
| 357 | char payload[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH]; |
| 358 | } LTTNG_PACKED; |
| 359 | |
| 360 | #endif /* _RELAYD_COMM */ |