2 * Copyright (C) 2011 EfficiOS Inc.
3 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * SPDX-License-Identifier: GPL-2.0-only
10 * This header is meant for liblttng and libust internal use ONLY. These
11 * declarations should NOT be considered stable API.
14 #ifndef _LTTNG_SESSIOND_COMM_H
15 #define _LTTNG_SESSIOND_COMM_H
20 #include <common/compat/socket.hpp>
21 #include <common/compiler.hpp>
22 #include <common/defaults.hpp>
23 #include <common/macros.hpp>
24 #include <common/optional.hpp>
25 #include <common/unix.hpp>
26 #include <common/uri.hpp>
27 #include <common/uuid.hpp>
29 #include <lttng/channel-internal.hpp>
30 #include <lttng/lttng.h>
31 #include <lttng/rotate-internal.hpp>
32 #include <lttng/save-internal.hpp>
33 #include <lttng/snapshot-internal.hpp>
34 #include <lttng/trigger/trigger-internal.hpp>
36 #include <arpa/inet.h>
38 #include <netinet/in.h>
42 /* Queue size of listen(2) */
43 #define LTTNG_SESSIOND_COMM_MAX_LISTEN 64
45 /* Maximum number of FDs that can be sent over a Unix socket */
46 #if defined(__linux__)
47 /* Based on the kernel's SCM_MAX_FD which is 253 since 2.6.38 (255 before) */
48 #define LTTCOMM_MAX_SEND_FDS 253
50 #define LTTCOMM_MAX_SEND_FDS 16
53 enum lttcomm_sessiond_command {
54 LTTCOMM_SESSIOND_COMMAND_MIN,
55 LTTCOMM_SESSIOND_COMMAND_ADD_CONTEXT,
56 LTTCOMM_SESSIOND_COMMAND_DISABLE_CHANNEL,
57 LTTCOMM_SESSIOND_COMMAND_DISABLE_EVENT,
58 LTTCOMM_SESSIOND_COMMAND_LIST_SYSCALLS,
59 LTTCOMM_SESSIOND_COMMAND_ENABLE_CHANNEL,
60 LTTCOMM_SESSIOND_COMMAND_ENABLE_EVENT,
61 LTTCOMM_SESSIOND_COMMAND_DESTROY_SESSION,
62 LTTCOMM_SESSIOND_COMMAND_LIST_CHANNELS,
63 LTTCOMM_SESSIOND_COMMAND_LIST_DOMAINS,
64 LTTCOMM_SESSIOND_COMMAND_LIST_EVENTS,
65 LTTCOMM_SESSIOND_COMMAND_LIST_SESSIONS,
66 LTTCOMM_SESSIOND_COMMAND_LIST_TRACEPOINTS,
67 LTTCOMM_SESSIOND_COMMAND_REGISTER_CONSUMER,
68 LTTCOMM_SESSIOND_COMMAND_START_TRACE,
69 LTTCOMM_SESSIOND_COMMAND_STOP_TRACE,
70 LTTCOMM_SESSIOND_COMMAND_LIST_TRACEPOINT_FIELDS,
71 LTTCOMM_SESSIOND_COMMAND_DISABLE_CONSUMER,
72 LTTCOMM_SESSIOND_COMMAND_ENABLE_CONSUMER,
73 LTTCOMM_SESSIOND_COMMAND_SET_CONSUMER_URI,
74 LTTCOMM_SESSIOND_COMMAND_DATA_PENDING,
75 LTTCOMM_SESSIOND_COMMAND_SNAPSHOT_ADD_OUTPUT,
76 LTTCOMM_SESSIOND_COMMAND_SNAPSHOT_DEL_OUTPUT,
77 LTTCOMM_SESSIOND_COMMAND_SNAPSHOT_LIST_OUTPUT,
78 LTTCOMM_SESSIOND_COMMAND_SNAPSHOT_RECORD,
79 LTTCOMM_SESSIOND_COMMAND_SAVE_SESSION,
80 LTTCOMM_SESSIOND_COMMAND_PROCESS_ATTR_TRACKER_ADD_INCLUDE_VALUE,
81 LTTCOMM_SESSIOND_COMMAND_PROCESS_ATTR_TRACKER_REMOVE_INCLUDE_VALUE,
82 LTTCOMM_SESSIOND_COMMAND_PROCESS_ATTR_TRACKER_GET_POLICY,
83 LTTCOMM_SESSIOND_COMMAND_PROCESS_ATTR_TRACKER_SET_POLICY,
84 LTTCOMM_SESSIOND_COMMAND_PROCESS_ATTR_TRACKER_GET_INCLUSION_SET,
85 LTTCOMM_SESSIOND_COMMAND_SET_SESSION_SHM_PATH,
86 LTTCOMM_SESSIOND_COMMAND_REGENERATE_METADATA,
87 LTTCOMM_SESSIOND_COMMAND_REGENERATE_STATEDUMP,
88 LTTCOMM_SESSIOND_COMMAND_REGISTER_TRIGGER,
89 LTTCOMM_SESSIOND_COMMAND_UNREGISTER_TRIGGER,
90 LTTCOMM_SESSIOND_COMMAND_ROTATE_SESSION,
91 LTTCOMM_SESSIOND_COMMAND_ROTATION_GET_INFO,
92 LTTCOMM_SESSIOND_COMMAND_ROTATION_SET_SCHEDULE,
93 LTTCOMM_SESSIOND_COMMAND_SESSION_LIST_ROTATION_SCHEDULES,
94 LTTCOMM_SESSIOND_COMMAND_CREATE_SESSION_EXT,
95 LTTCOMM_SESSIOND_COMMAND_CLEAR_SESSION,
96 LTTCOMM_SESSIOND_COMMAND_LIST_TRIGGERS,
97 LTTCOMM_SESSIOND_COMMAND_EXECUTE_ERROR_QUERY,
98 LTTCOMM_SESSIOND_COMMAND_KERNEL_TRACER_STATUS,
99 LTTCOMM_SESSIOND_COMMAND_MAX,
102 static inline bool lttcomm_sessiond_command_is_valid(enum lttcomm_sessiond_command cmd)
104 return cmd > LTTCOMM_SESSIOND_COMMAND_MIN && cmd < LTTCOMM_SESSIOND_COMMAND_MAX;
107 static inline const char *lttcomm_sessiond_command_str(enum lttcomm_sessiond_command cmd)
110 case LTTCOMM_SESSIOND_COMMAND_ADD_CONTEXT:
111 return "ADD_CONTEXT";
112 case LTTCOMM_SESSIOND_COMMAND_DISABLE_CHANNEL:
113 return "DISABLE_CHANNEL";
114 case LTTCOMM_SESSIOND_COMMAND_DISABLE_EVENT:
115 return "DISABLE_EVENT";
116 case LTTCOMM_SESSIOND_COMMAND_LIST_SYSCALLS:
117 return "LIST_SYSCALLS";
118 case LTTCOMM_SESSIOND_COMMAND_ENABLE_CHANNEL:
119 return "ENABLE_CHANNEL";
120 case LTTCOMM_SESSIOND_COMMAND_ENABLE_EVENT:
121 return "ENABLE_EVENT";
122 case LTTCOMM_SESSIOND_COMMAND_DESTROY_SESSION:
123 return "DESTROY_SESSION";
124 case LTTCOMM_SESSIOND_COMMAND_LIST_CHANNELS:
125 return "LIST_CHANNELS";
126 case LTTCOMM_SESSIOND_COMMAND_LIST_DOMAINS:
127 return "LIST_DOMAINS";
128 case LTTCOMM_SESSIOND_COMMAND_LIST_EVENTS:
129 return "LIST_EVENTS";
130 case LTTCOMM_SESSIOND_COMMAND_LIST_SESSIONS:
131 return "LIST_SESSIONS";
132 case LTTCOMM_SESSIOND_COMMAND_LIST_TRACEPOINTS:
133 return "LIST_TRACEPOINTS";
134 case LTTCOMM_SESSIOND_COMMAND_REGISTER_CONSUMER:
135 return "REGISTER_CONSUMER";
136 case LTTCOMM_SESSIOND_COMMAND_START_TRACE:
137 return "START_TRACE";
138 case LTTCOMM_SESSIOND_COMMAND_STOP_TRACE:
140 case LTTCOMM_SESSIOND_COMMAND_LIST_TRACEPOINT_FIELDS:
141 return "LIST_TRACEPOINT_FIELDS";
142 case LTTCOMM_SESSIOND_COMMAND_DISABLE_CONSUMER:
143 return "DISABLE_CONSUMER";
144 case LTTCOMM_SESSIOND_COMMAND_ENABLE_CONSUMER:
145 return "ENABLE_CONSUMER";
146 case LTTCOMM_SESSIOND_COMMAND_SET_CONSUMER_URI:
147 return "SET_CONSUMER_URI";
148 case LTTCOMM_SESSIOND_COMMAND_DATA_PENDING:
149 return "DATA_PENDING";
150 case LTTCOMM_SESSIOND_COMMAND_SNAPSHOT_ADD_OUTPUT:
151 return "SNAPSHOT_ADD_OUTPUT";
152 case LTTCOMM_SESSIOND_COMMAND_SNAPSHOT_DEL_OUTPUT:
153 return "SNAPSHOT_DEL_OUTPUT";
154 case LTTCOMM_SESSIOND_COMMAND_SNAPSHOT_LIST_OUTPUT:
155 return "SNAPSHOT_LIST_OUTPUT";
156 case LTTCOMM_SESSIOND_COMMAND_SNAPSHOT_RECORD:
157 return "SNAPSHOT_RECORD";
158 case LTTCOMM_SESSIOND_COMMAND_SAVE_SESSION:
159 return "SAVE_SESSION";
160 case LTTCOMM_SESSIOND_COMMAND_PROCESS_ATTR_TRACKER_ADD_INCLUDE_VALUE:
161 return "PROCESS_ATTR_TRACKER_ADD_INCLUDE_VALUE";
162 case LTTCOMM_SESSIOND_COMMAND_PROCESS_ATTR_TRACKER_REMOVE_INCLUDE_VALUE:
163 return "PROCESS_ATTR_TRACKER_REMOVE_INCLUDE_VALUE";
164 case LTTCOMM_SESSIOND_COMMAND_PROCESS_ATTR_TRACKER_GET_POLICY:
165 return "PROCESS_ATTR_TRACKER_GET_POLICY";
166 case LTTCOMM_SESSIOND_COMMAND_PROCESS_ATTR_TRACKER_SET_POLICY:
167 return "PROCESS_ATTR_TRACKER_SET_POLICY";
168 case LTTCOMM_SESSIOND_COMMAND_PROCESS_ATTR_TRACKER_GET_INCLUSION_SET:
169 return "PROCESS_ATTR_TRACKER_GET_INCLUSION_SET";
170 case LTTCOMM_SESSIOND_COMMAND_SET_SESSION_SHM_PATH:
171 return "SET_SESSION_SHM_PATH";
172 case LTTCOMM_SESSIOND_COMMAND_REGENERATE_METADATA:
173 return "REGENERATE_METADATA";
174 case LTTCOMM_SESSIOND_COMMAND_REGENERATE_STATEDUMP:
175 return "REGENERATE_STATEDUMP";
176 case LTTCOMM_SESSIOND_COMMAND_REGISTER_TRIGGER:
177 return "REGISTER_TRIGGER";
178 case LTTCOMM_SESSIOND_COMMAND_UNREGISTER_TRIGGER:
179 return "UNREGISTER_TRIGGER";
180 case LTTCOMM_SESSIOND_COMMAND_ROTATE_SESSION:
181 return "ROTATE_SESSION";
182 case LTTCOMM_SESSIOND_COMMAND_ROTATION_GET_INFO:
183 return "ROTATION_GET_INFO";
184 case LTTCOMM_SESSIOND_COMMAND_ROTATION_SET_SCHEDULE:
185 return "ROTATION_SET_SCHEDULE";
186 case LTTCOMM_SESSIOND_COMMAND_SESSION_LIST_ROTATION_SCHEDULES:
187 return "SESSION_LIST_ROTATION_SCHEDULES";
188 case LTTCOMM_SESSIOND_COMMAND_CREATE_SESSION_EXT:
189 return "CREATE_SESSION_EXT";
190 case LTTCOMM_SESSIOND_COMMAND_CLEAR_SESSION:
191 return "CLEAR_SESSION";
192 case LTTCOMM_SESSIOND_COMMAND_LIST_TRIGGERS:
193 return "LIST_TRIGGERS";
194 case LTTCOMM_SESSIOND_COMMAND_EXECUTE_ERROR_QUERY:
195 return "EXECUTE_ERROR_QUERY";
196 case LTTCOMM_SESSIOND_COMMAND_KERNEL_TRACER_STATUS:
197 return "KERNEL_TRACER_STATUS";
203 enum lttcomm_relayd_command {
204 RELAYD_ADD_STREAM = 1,
205 RELAYD_CREATE_SESSION = 2,
206 RELAYD_START_DATA = 3,
207 RELAYD_UPDATE_SYNC_INFO = 4,
209 RELAYD_SEND_METADATA = 6,
210 RELAYD_CLOSE_STREAM = 7,
211 RELAYD_DATA_PENDING = 8,
212 RELAYD_QUIESCENT_CONTROL = 9,
213 RELAYD_BEGIN_DATA_PENDING = 10,
214 RELAYD_END_DATA_PENDING = 11,
215 RELAYD_ADD_INDEX = 12,
216 RELAYD_SEND_INDEX = 13,
217 RELAYD_CLOSE_INDEX = 14,
218 /* Live-reading commands (2.4+). */
219 RELAYD_LIST_SESSIONS = 15,
220 /* All streams of the channel have been sent to the relayd (2.4+). */
221 RELAYD_STREAMS_SENT = 16,
222 /* Ask the relay to reset the metadata trace file (2.8+) */
223 RELAYD_RESET_METADATA = 17,
224 /* Ask the relay to rotate a set of stream files (2.11+) */
225 RELAYD_ROTATE_STREAMS = 18,
226 /* Ask the relay to create a trace chunk (2.11+) */
227 RELAYD_CREATE_TRACE_CHUNK = 19,
228 /* Ask the relay to close a trace chunk (2.11+) */
229 RELAYD_CLOSE_TRACE_CHUNK = 20,
230 /* Ask the relay whether a trace chunk exists (2.11+) */
231 RELAYD_TRACE_CHUNK_EXISTS = 21,
232 /* Get the current configuration of a relayd peer (2.12+) */
233 RELAYD_GET_CONFIGURATION = 22,
235 /* Feature branch specific commands start at 10000. */
238 static inline const char *lttcomm_relayd_command_str(lttcomm_relayd_command cmd)
241 case RELAYD_ADD_STREAM:
242 return "RELAYD_ADD_STREAM";
243 case RELAYD_CREATE_SESSION:
244 return "RELAYD_CREATE_SESSION";
245 case RELAYD_START_DATA:
246 return "RELAYD_START_DATA";
247 case RELAYD_UPDATE_SYNC_INFO:
248 return "RELAYD_UPDATE_SYNC_INFO";
250 return "RELAYD_VERSION";
251 case RELAYD_SEND_METADATA:
252 return "RELAYD_SEND_METADATA";
253 case RELAYD_CLOSE_STREAM:
254 return "RELAYD_CLOSE_STREAM";
255 case RELAYD_DATA_PENDING:
256 return "RELAYD_DATA_PENDING";
257 case RELAYD_QUIESCENT_CONTROL:
258 return "RELAYD_QUIESCENT_CONTROL";
259 case RELAYD_BEGIN_DATA_PENDING:
260 return "RELAYD_BEGIN_DATA_PENDING";
261 case RELAYD_END_DATA_PENDING:
262 return "RELAYD_END_DATA_PENDING";
263 case RELAYD_ADD_INDEX:
264 return "RELAYD_ADD_INDEX";
265 case RELAYD_SEND_INDEX:
266 return "RELAYD_SEND_INDEX";
267 case RELAYD_CLOSE_INDEX:
268 return "RELAYD_CLOSE_INDEX";
269 case RELAYD_LIST_SESSIONS:
270 return "RELAYD_LIST_SESSIONS";
271 case RELAYD_STREAMS_SENT:
272 return "RELAYD_STREAMS_SENT";
273 case RELAYD_RESET_METADATA:
274 return "RELAYD_RESET_METADATA";
275 case RELAYD_ROTATE_STREAMS:
276 return "RELAYD_ROTATE_STREAMS";
277 case RELAYD_CREATE_TRACE_CHUNK:
278 return "RELAYD_CREATE_TRACE_CHUNK";
279 case RELAYD_CLOSE_TRACE_CHUNK:
280 return "RELAYD_CLOSE_TRACE_CHUNK";
281 case RELAYD_TRACE_CHUNK_EXISTS:
282 return "RELAYD_TRACE_CHUNK_EXISTS";
283 case RELAYD_GET_CONFIGURATION:
284 return "RELAYD_GET_CONFIGURATION";
291 * lttcomm error code.
293 enum lttcomm_return_code {
294 LTTCOMM_CONSUMERD_SUCCESS = 0, /* Everything went fine. */
296 * Some code paths use -1 to express an error, others
297 * negate this consumer return code. Starting codes at
298 * 100 ensures there is no mix-up between this error value
299 * and legitimate status codes.
301 LTTCOMM_CONSUMERD_COMMAND_SOCK_READY = 100, /* Command socket ready */
302 LTTCOMM_CONSUMERD_SUCCESS_RECV_FD, /* Success on receiving fds */
303 LTTCOMM_CONSUMERD_ERROR_RECV_FD, /* Error on receiving fds */
304 LTTCOMM_CONSUMERD_ERROR_RECV_CMD, /* Error on receiving command */
305 LTTCOMM_CONSUMERD_POLL_ERROR, /* Error in polling thread */
306 LTTCOMM_CONSUMERD_POLL_NVAL, /* Poll on closed fd */
307 LTTCOMM_CONSUMERD_POLL_HUP, /* All fds have hungup */
308 LTTCOMM_CONSUMERD_EXIT_SUCCESS, /* Consumerd exiting normally */
309 LTTCOMM_CONSUMERD_EXIT_FAILURE, /* Consumerd exiting on error */
310 LTTCOMM_CONSUMERD_OUTFD_ERROR, /* Error opening the tracefile */
311 LTTCOMM_CONSUMERD_SPLICE_EBADF, /* EBADF from splice(2) */
312 LTTCOMM_CONSUMERD_SPLICE_EINVAL, /* EINVAL from splice(2) */
313 LTTCOMM_CONSUMERD_SPLICE_ENOMEM, /* ENOMEM from splice(2) */
314 LTTCOMM_CONSUMERD_SPLICE_ESPIPE, /* ESPIPE from splice(2) */
315 LTTCOMM_CONSUMERD_ENOMEM, /* Consumer is out of memory */
316 LTTCOMM_CONSUMERD_ERROR_METADATA, /* Error with metadata. */
317 LTTCOMM_CONSUMERD_FATAL, /* Fatal error. */
318 LTTCOMM_CONSUMERD_RELAYD_FAIL, /* Error on remote relayd */
319 LTTCOMM_CONSUMERD_CHANNEL_FAIL, /* Channel creation failed. */
320 LTTCOMM_CONSUMERD_CHAN_NOT_FOUND, /* Channel not found. */
321 LTTCOMM_CONSUMERD_ALREADY_SET, /* Resource already set. */
322 LTTCOMM_CONSUMERD_ROTATION_FAIL, /* Rotation has failed. */
323 LTTCOMM_CONSUMERD_SNAPSHOT_FAILED, /* snapshot has failed. */
324 LTTCOMM_CONSUMERD_CREATE_TRACE_CHUNK_FAILED, /* Trace chunk creation failed. */
325 LTTCOMM_CONSUMERD_CLOSE_TRACE_CHUNK_FAILED, /* Trace chunk close failed. */
326 LTTCOMM_CONSUMERD_INVALID_PARAMETERS, /* Invalid parameters. */
327 LTTCOMM_CONSUMERD_TRACE_CHUNK_EXISTS_LOCAL, /* Trace chunk exists on consumer daemon. */
328 LTTCOMM_CONSUMERD_TRACE_CHUNK_EXISTS_REMOTE, /* Trace chunk exists on relay daemon. */
329 LTTCOMM_CONSUMERD_UNKNOWN_TRACE_CHUNK, /* Unknown trace chunk. */
330 LTTCOMM_CONSUMERD_RELAYD_CLEAR_DISALLOWED, /* Relayd does not accept clear command. */
331 LTTCOMM_CONSUMERD_UNKNOWN_ERROR, /* Unknown error. */
333 /* MUST be last element */
334 LTTCOMM_NR, /* Last element */
337 /* lttng socket protocol. */
338 enum lttcomm_sock_proto {
344 * Index in the net_families array below. Please keep in sync!
346 enum lttcomm_sock_domain {
351 enum lttcomm_metadata_command {
352 LTTCOMM_METADATA_REQUEST = 1,
356 * Commands sent from the consumerd to the sessiond to request if new metadata
357 * is available. This message is used to find the per UID _or_ per PID registry
358 * for the channel key. For per UID lookup, the triplet
359 * bits_per_long/uid/session_id is used. On lookup failure, we search for the
360 * per PID registry indexed by session id ignoring the other values.
362 struct lttcomm_metadata_request_msg {
363 uint64_t session_id; /* Tracing session id */
364 uint64_t session_id_per_pid; /* Tracing session id for per-pid */
365 uint32_t bits_per_long; /* Consumer ABI */
367 uint64_t key; /* Metadata channel key. */
370 struct lttcomm_sockaddr {
371 enum lttcomm_sock_domain type;
373 struct sockaddr_in sin;
374 struct sockaddr_in6 sin6;
378 struct lttcomm_sock {
380 enum lttcomm_sock_proto proto;
381 struct lttcomm_sockaddr sockaddr;
382 const struct lttcomm_proto_ops *ops;
386 * Relayd sock. Adds the protocol version to use for the communications with
389 struct lttcomm_relayd_sock {
390 struct lttcomm_sock sock;
395 struct lttcomm_net_family {
397 int (*create)(struct lttcomm_sock *sock, int type, int proto);
400 struct lttcomm_proto_ops {
401 int (*bind)(struct lttcomm_sock *sock);
402 int (*close)(struct lttcomm_sock *sock);
403 int (*connect)(struct lttcomm_sock *sock);
404 struct lttcomm_sock *(*accept)(struct lttcomm_sock *sock);
405 int (*listen)(struct lttcomm_sock *sock, int backlog);
406 ssize_t (*recvmsg)(struct lttcomm_sock *sock, void *buf, size_t len, int flags);
407 ssize_t (*sendmsg)(struct lttcomm_sock *sock, const void *buf, size_t len, int flags);
410 struct process_attr_integral_value_comm {
418 * Data structure received from lttng client to session daemon.
420 struct lttcomm_session_msg {
421 uint32_t cmd_type; /* enum lttcomm_sessiond_command */
422 struct lttng_session session;
423 struct lttng_domain domain;
427 char channel_name[LTTNG_SYMBOL_NAME_LEN];
429 } LTTNG_PACKED enable;
431 char channel_name[LTTNG_SYMBOL_NAME_LEN];
433 } LTTNG_PACKED disable;
437 } LTTNG_PACKED channel;
440 char channel_name[LTTNG_SYMBOL_NAME_LEN];
442 } LTTNG_PACKED context;
443 /* Use by register_consumer */
449 char channel_name[LTTNG_SYMBOL_NAME_LEN];
451 struct lttng_calibrate calibrate;
452 /* Used by the set_consumer_url and used by create_session also call */
454 /* Number of lttng_uri following */
458 struct lttng_snapshot_output output;
459 } LTTNG_PACKED snapshot_output;
462 struct lttng_snapshot_output output;
463 } LTTNG_PACKED snapshot_record;
466 unsigned int timer_interval; /* usec */
467 } LTTNG_PACKED session_live;
469 struct lttng_save_session_attr attr;
470 } LTTNG_PACKED save_session;
472 char shm_path[PATH_MAX];
473 } LTTNG_PACKED set_shm_path;
475 /* enum lttng_process_attr */
476 int32_t process_attr;
477 /* enum lttng_process_attr_value_type */
480 struct process_attr_integral_value_comm integral_value;
482 * For user/group names, a variable length,
483 * zero-terminated, string of length 'name_len'
484 * (including the terminator) follows.
486 * integral_value should not be used in those cases.
489 } LTTNG_PACKED process_attr_tracker_add_remove_include_value;
491 /* enum lttng_process_attr */
492 int32_t process_attr;
493 } LTTNG_PACKED process_attr_tracker_get_inclusion_set;
495 /* enum lttng_process_attr */
496 int32_t process_attr;
497 } LTTNG_PACKED process_attr_tracker_get_tracking_policy;
499 /* enum lttng_process_attr */
500 int32_t process_attr;
501 /* enum lttng_tracking_policy */
502 int32_t tracking_policy;
503 } LTTNG_PACKED process_attr_tracker_set_tracking_policy;
506 uint8_t is_trigger_anonymous;
507 } LTTNG_PACKED trigger;
510 } LTTNG_PACKED error_query;
512 uint64_t rotation_id;
513 } LTTNG_PACKED get_rotation_info;
515 /* enum lttng_rotation_schedule_type */
518 * If set == 1, set schedule to value, if set == 0,
519 * clear this schedule type.
523 } LTTNG_PACKED rotation_set_schedule;
526 * Includes the null-terminator.
527 * Must be an absolute path.
529 * Size bounded by LTTNG_PATH_MAX.
531 uint16_t home_dir_size;
532 uint64_t session_descriptor_size;
533 /* An lttng_session_descriptor follows. */
534 } LTTNG_PACKED create_session;
536 /* Count of fds sent. */
540 #define LTTNG_FILTER_MAX_LEN 65536
541 #define LTTNG_SESSION_DESCRIPTOR_MAX_LEN 65536
544 * Filter bytecode data. The reloc table is located at the end of the
545 * bytecode. It is made of tuples: (uint16_t, var. len. string). It
546 * starts at reloc_table_offset.
548 #define LTTNG_FILTER_PADDING 32
549 struct lttng_bytecode {
550 uint32_t len; /* len of data */
551 uint32_t reloc_table_offset;
553 char padding[LTTNG_FILTER_PADDING];
558 * Event exclusion data. At the end of the structure, there will actually
559 * by zero or more names, where the actual number of names is given by
560 * the 'count' item of the structure.
562 #define LTTNG_EVENT_EXCLUSION_PADDING 32
563 struct lttng_event_exclusion {
565 char padding[LTTNG_EVENT_EXCLUSION_PADDING];
566 char names[LTTNG_FLEXIBLE_ARRAY_MEMBER_LENGTH][LTTNG_SYMBOL_NAME_LEN];
569 #define LTTNG_EVENT_EXCLUSION_NAME_AT(_exclusion, _i) ((_exclusion)->names[_i])
572 * Listing command header.
574 struct lttcomm_list_command_header {
575 /* Number of elements */
580 * Event extended info header. This is the structure preceding each
581 * extended info data.
583 struct lttcomm_event_extended_header {
585 * Size of filter string immediately following this header.
586 * This size includes the terminal null character.
591 * Number of exclusion names, immediately following the filter
592 * string. Each exclusion name has a fixed length of
593 * LTTNG_SYMBOL_NAME_LEN bytes, including the terminal null
596 uint32_t nb_exclusions;
599 * Size of the event's userspace probe location (if applicable).
601 uint32_t userspace_probe_location_len;
605 * Command header of the reply to an LTTCOMM_SESSIOND_COMMAND_DESTROY_SESSION command.
607 struct lttcomm_session_destroy_command_header {
608 /* enum lttng_session */
609 int32_t rotation_state;
613 * tracker command header.
615 struct lttcomm_tracker_command_header {
616 uint32_t nb_tracker_id;
620 * Data structure for the response from sessiond to the lttng client.
622 struct lttcomm_lttng_msg {
623 uint32_t cmd_type; /* enum lttcomm_sessiond_command */
624 uint32_t ret_code; /* enum lttcomm_return_code */
625 uint32_t pid; /* pid_t */
626 uint32_t cmd_header_size;
631 struct lttcomm_lttng_output_id {
636 * lttcomm_consumer_msg is the message sent from sessiond to consumerd
637 * to either add a channel, add a stream, update a stream, or stop
640 struct lttcomm_consumer_msg {
641 uint32_t cmd_type; /* enum lttng_consumer_command */
644 uint64_t channel_key;
646 /* ID of the session's current trace chunk. */
647 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED chunk_id;
648 char pathname[PATH_MAX];
650 /* nb_init_streams is the number of streams open initially. */
651 uint32_t nb_init_streams;
652 char name[LTTNG_SYMBOL_NAME_LEN];
653 /* Use splice or mmap to consume this fd */
654 enum lttng_event_output output;
655 int type; /* Per cpu or metadata. */
656 uint64_t tracefile_size; /* bytes */
657 uint32_t tracefile_count; /* number of tracefiles */
658 /* If the channel's streams have to be monitored or not. */
660 /* timer to check the streams usage in live mode (usec). */
661 unsigned int live_timer_interval;
662 /* is part of a live session */
664 /* timer to sample a channel's positions (usec). */
665 unsigned int monitor_timer_interval;
666 } LTTNG_PACKED channel; /* Only used by Kernel. */
669 uint64_t channel_key;
670 int32_t cpu; /* On which CPU this stream is assigned. */
671 /* Tells the consumer if the stream should be or not monitored. */
673 } LTTNG_PACKED stream; /* Only used by Kernel. */
676 enum lttng_stream_type type;
679 uint8_t relayd_socket_protocol;
680 /* Tracing session id associated to the relayd. */
682 /* Relayd session id, only used with control socket. */
683 uint64_t relayd_session_id;
684 } LTTNG_PACKED relayd_sock;
686 uint64_t net_seq_idx;
687 } LTTNG_PACKED destroy_relayd;
690 } LTTNG_PACKED data_pending;
692 uint64_t subbuf_size; /* bytes */
693 uint64_t num_subbuf; /* power of 2 */
694 int32_t overwrite; /* 1: overwrite, 0: discard */
695 uint32_t switch_timer_interval; /* usec */
696 uint32_t read_timer_interval; /* usec */
697 unsigned int live_timer_interval; /* usec */
698 uint8_t is_live; /* is part of a live session */
699 uint32_t monitor_timer_interval; /* usec */
700 int32_t output; /* splice, mmap */
701 int32_t type; /* metadata or per_cpu */
702 uint64_t session_id; /* Tracing session id */
703 char pathname[PATH_MAX]; /* Channel file path. */
704 char name[LTTNG_SYMBOL_NAME_LEN]; /* Channel name. */
705 /* Credentials used to open the UST buffer shared mappings. */
709 } LTTNG_PACKED buffer_credentials;
710 uint64_t relayd_id; /* Relayd id if apply. */
711 uint64_t key; /* Unique channel key. */
712 /* ID of the session's current trace chunk. */
713 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED chunk_id;
714 unsigned char uuid[LTTNG_UUID_LEN]; /* uuid for ust tracer. */
715 uint32_t chan_id; /* Channel ID on the tracer side. */
716 uint64_t tracefile_size; /* bytes */
717 uint32_t tracefile_count; /* number of tracefiles */
718 uint64_t session_id_per_pid; /* Per-pid session ID. */
719 /* Tells the consumer if the stream should be or not monitored. */
722 * For UST per UID buffers, this is the application UID of the
723 * channel. This can be different from the user UID requesting the
724 * channel creation and used for the rights on the stream file
725 * because the application can be in the tracing for instance.
727 uint32_t ust_app_uid;
728 int64_t blocking_timeout;
729 char root_shm_path[PATH_MAX];
730 char shm_path[PATH_MAX];
731 } LTTNG_PACKED ask_channel;
734 } LTTNG_PACKED get_channel;
737 } LTTNG_PACKED destroy_channel;
739 uint64_t key; /* Metadata channel key. */
740 uint64_t target_offset; /* Offset in the consumer */
741 uint64_t len; /* Length of metadata to be received. */
742 uint64_t version; /* Version of the metadata. */
743 } LTTNG_PACKED push_metadata;
745 uint64_t key; /* Metadata channel key. */
746 } LTTNG_PACKED close_metadata;
748 uint64_t key; /* Metadata channel key. */
749 } LTTNG_PACKED setup_metadata;
751 uint64_t key; /* Channel key. */
752 } LTTNG_PACKED flush_channel;
754 uint64_t key; /* Channel key. */
755 } LTTNG_PACKED clear_quiescent_channel;
757 char pathname[PATH_MAX];
758 /* Indicate if the snapshot goes on the relayd or locally. */
760 uint32_t metadata; /* This a metadata snapshot. */
761 uint64_t relayd_id; /* Relayd id if apply. */
763 uint64_t nb_packets_per_stream;
764 } LTTNG_PACKED snapshot_channel;
766 uint64_t channel_key;
767 uint64_t net_seq_idx;
768 } LTTNG_PACKED sent_streams;
771 uint64_t channel_key;
772 } LTTNG_PACKED discarded_events;
775 uint64_t channel_key;
776 } LTTNG_PACKED lost_packets;
779 } LTTNG_PACKED regenerate_metadata;
781 uint32_t metadata; /* This is a metadata channel. */
782 uint64_t relayd_id; /* Relayd id if apply. */
784 } LTTNG_PACKED rotate_channel;
788 } LTTNG_PACKED check_rotation_pending_local;
793 } LTTNG_PACKED check_rotation_pending_relay;
796 * Relayd id, if applicable (remote).
798 * A directory file descriptor referring to the chunk's
799 * output folder is transmitted if the chunk is local
802 * `override_name` is left NULL (all-zeroes) if the
803 * chunk's name is not overridden.
805 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED relayd_id;
806 char override_name[LTTNG_NAME_MAX];
809 uint64_t creation_timestamp;
810 LTTNG_OPTIONAL_COMM(struct {
814 LTTNG_PACKED credentials;
815 } LTTNG_PACKED create_trace_chunk;
817 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED relayd_id;
820 uint64_t close_timestamp;
821 /* enum lttng_trace_chunk_command_type */
822 LTTNG_OPTIONAL_COMM(uint32_t) LTTNG_PACKED close_command;
823 } LTTNG_PACKED close_trace_chunk;
825 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED relayd_id;
828 } LTTNG_PACKED trace_chunk_exists;
830 uint8_t sessiond_uuid[LTTNG_UUID_LEN];
834 } LTTNG_PACKED clear_channel;
837 } LTTNG_PACKED open_channel_packets;
842 * Channel monitoring message returned to the session daemon on every
843 * monitor timer expiration.
845 struct lttcomm_consumer_channel_monitor_msg {
846 /* Key of the sampled channel. */
848 /* Id of the sampled channel's session. */
851 * Lowest and highest usage (bytes) at the moment the sample was taken.
853 uint64_t lowest, highest;
855 * Sum of all the consumed positions for a channel.
857 uint64_t consumed_since_last_sample;
861 * Status message returned to the sessiond after a received command.
863 struct lttcomm_consumer_status_msg {
864 enum lttcomm_return_code ret_code;
867 struct lttcomm_consumer_status_channel {
868 enum lttcomm_return_code ret_code;
870 unsigned int stream_count;
873 struct lttcomm_consumer_close_trace_chunk_reply {
874 enum lttcomm_return_code ret_code;
875 uint32_t path_length;
879 #ifdef HAVE_LIBLTTNG_UST_CTL
881 #include <lttng/ust-abi.h>
884 * Data structure for the commands sent from sessiond to UST.
886 struct lttcomm_ust_msg {
890 struct lttng_ust_abi_channel channel;
891 struct lttng_ust_abi_stream stream;
892 struct lttng_ust_abi_event event;
893 struct lttng_ust_abi_context context;
894 struct lttng_ust_abi_tracer_version version;
899 * Data structure for the response from UST to the session daemon.
900 * cmd_type is sent back in the reply for validation.
902 struct lttcomm_ust_reply {
905 uint32_t ret_code; /* enum lttcomm_return_code */
906 uint32_t ret_val; /* return value */
909 uint64_t memory_map_size;
910 } LTTNG_PACKED channel;
912 uint64_t memory_map_size;
913 } LTTNG_PACKED stream;
914 struct lttng_ust_abi_tracer_version version;
918 #endif /* HAVE_LIBLTTNG_UST_CTL */
920 const char *lttcomm_get_readable_code(enum lttcomm_return_code code);
922 int lttcomm_init_inet_sockaddr(struct lttcomm_sockaddr *sockaddr,
925 int lttcomm_init_inet6_sockaddr(struct lttcomm_sockaddr *sockaddr,
929 struct lttcomm_sock *lttcomm_alloc_sock(enum lttcomm_sock_proto proto);
930 int lttcomm_populate_sock_from_open_socket(struct lttcomm_sock *sock,
932 enum lttcomm_sock_proto protocol);
933 int lttcomm_create_sock(struct lttcomm_sock *sock);
934 struct lttcomm_sock *lttcomm_alloc_sock_from_uri(struct lttng_uri *uri);
935 void lttcomm_destroy_sock(struct lttcomm_sock *sock);
936 struct lttcomm_sock *lttcomm_alloc_copy_sock(struct lttcomm_sock *src);
937 void lttcomm_copy_sock(struct lttcomm_sock *dst, struct lttcomm_sock *src);
939 /* Relayd socket object. */
940 struct lttcomm_relayd_sock *
941 lttcomm_alloc_relayd_sock(struct lttng_uri *uri, uint32_t major, uint32_t minor);
943 int lttcomm_setsockopt_rcv_timeout(int sock, unsigned int msec);
944 int lttcomm_setsockopt_snd_timeout(int sock, unsigned int msec);
946 int lttcomm_sock_get_port(const struct lttcomm_sock *sock, uint16_t *port);
948 * Set a port to an lttcomm_sock. This will have no effect is the socket is
951 int lttcomm_sock_set_port(struct lttcomm_sock *sock, uint16_t port);
954 /* Get network timeout, in milliseconds */
955 unsigned long lttcomm_get_network_timeout();
957 #endif /* _LTTNG_SESSIOND_COMM_H */