Fix: sessiond: abort called on undefined client command
[lttng-tools.git] / src / common / sessiond-comm / sessiond-comm.hpp
CommitLineData
6e3805e2 1/*
21cf9b6b 2 * Copyright (C) 2011 EfficiOS Inc.
ab5be9fa 3 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
fac6795d 4 *
ab5be9fa 5 * SPDX-License-Identifier: GPL-2.0-only
ba999de0 6 *
fac6795d
DG
7 */
8
773168b7 9/*
990570ed
DG
10 * This header is meant for liblttng and libust internal use ONLY. These
11 * declarations should NOT be considered stable API.
773168b7 12 */
fac6795d 13
990570ed
DG
14#ifndef _LTTNG_SESSIOND_COMM_H
15#define _LTTNG_SESSIOND_COMM_H
16
fac6795d 17#include <limits.h>
f3ed775e 18#include <lttng/lttng.h>
c9e313bc
SM
19#include <lttng/snapshot-internal.hpp>
20#include <lttng/save-internal.hpp>
21#include <lttng/channel-internal.hpp>
22#include <lttng/trigger/trigger-internal.hpp>
23#include <lttng/rotate-internal.hpp>
24#include <common/compat/socket.hpp>
25#include <common/uri.hpp>
26#include <common/defaults.hpp>
27#include <common/uuid.hpp>
28#include <common/macros.hpp>
29#include <common/optional.hpp>
5e16da05 30
6364a07a
DG
31#include <arpa/inet.h>
32#include <netinet/in.h>
4222116f 33#include <stdint.h>
6364a07a
DG
34#include <sys/un.h>
35
c9e313bc
SM
36#include "inet.hpp"
37#include "inet6.hpp"
38#include <common/unix.hpp>
0d37f2bc 39
fac6795d 40/* Queue size of listen(2) */
f158a754 41#define LTTNG_SESSIOND_COMM_MAX_LISTEN 64
fac6795d 42
990570ed 43/* Maximum number of FDs that can be sent over a Unix socket */
0b5a4de9
JG
44#if defined(__linux__)
45/* Based on the kernel's SCM_MAX_FD which is 253 since 2.6.38 (255 before) */
46#define LTTCOMM_MAX_SEND_FDS 253
47#else
48#define LTTCOMM_MAX_SEND_FDS 16
49#endif
990570ed 50
6abb15de 51enum lttcomm_sessiond_command {
6c1db447 52 LTTCOMM_SESSIOND_COMMAND_MIN = -1,
0d0c377a 53 /* Tracer command */
159b042f 54 LTTNG_ADD_CONTEXT = 0,
b812e5ca 55 /* LTTNG_CALIBRATE used to be here */
159b042f
JG
56 LTTNG_DISABLE_CHANNEL = 2,
57 LTTNG_DISABLE_EVENT = 3,
58 LTTNG_LIST_SYSCALLS = 4,
59 LTTNG_ENABLE_CHANNEL = 5,
60 LTTNG_ENABLE_EVENT = 6,
18a720cd 61 /* 7 */
0d0c377a 62 /* Session daemon command */
b178f53e 63 /* 8 */
159b042f
JG
64 LTTNG_DESTROY_SESSION = 9,
65 LTTNG_LIST_CHANNELS = 10,
66 LTTNG_LIST_DOMAINS = 11,
67 LTTNG_LIST_EVENTS = 12,
68 LTTNG_LIST_SESSIONS = 13,
69 LTTNG_LIST_TRACEPOINTS = 14,
70 LTTNG_REGISTER_CONSUMER = 15,
71 LTTNG_START_TRACE = 16,
72 LTTNG_STOP_TRACE = 17,
73 LTTNG_LIST_TRACEPOINT_FIELDS = 18,
53a80697 74
de5e9086 75 /* Consumer */
159b042f
JG
76 LTTNG_DISABLE_CONSUMER = 19,
77 LTTNG_ENABLE_CONSUMER = 20,
78 LTTNG_SET_CONSUMER_URI = 21,
67676bd8
DG
79 /* 22 */
80 /* 23 */
159b042f
JG
81 LTTNG_DATA_PENDING = 24,
82 LTTNG_SNAPSHOT_ADD_OUTPUT = 25,
83 LTTNG_SNAPSHOT_DEL_OUTPUT = 26,
84 LTTNG_SNAPSHOT_LIST_OUTPUT = 27,
85 LTTNG_SNAPSHOT_RECORD = 28,
b178f53e
JG
86 /* 29 */
87 /* 30 */
159b042f
JG
88 LTTNG_SAVE_SESSION = 31,
89 LTTNG_PROCESS_ATTR_TRACKER_ADD_INCLUDE_VALUE = 32,
90 LTTNG_PROCESS_ATTR_TRACKER_REMOVE_INCLUDE_VALUE = 33,
91 LTTNG_PROCESS_ATTR_TRACKER_GET_POLICY = 34,
92 LTTNG_PROCESS_ATTR_TRACKER_SET_POLICY = 35,
93 LTTNG_PROCESS_ATTR_TRACKER_GET_INCLUSION_SET = 36,
94 LTTNG_SET_SESSION_SHM_PATH = 40,
95 LTTNG_REGENERATE_METADATA = 41,
96 LTTNG_REGENERATE_STATEDUMP = 42,
97 LTTNG_REGISTER_TRIGGER = 43,
98 LTTNG_UNREGISTER_TRIGGER = 44,
99 LTTNG_ROTATE_SESSION = 45,
100 LTTNG_ROTATION_GET_INFO = 46,
101 LTTNG_ROTATION_SET_SCHEDULE = 47,
102 LTTNG_SESSION_LIST_ROTATION_SCHEDULES = 48,
103 LTTNG_CREATE_SESSION_EXT = 49,
104 LTTNG_CLEAR_SESSION = 50,
fbc9f37d 105 LTTNG_LIST_TRIGGERS = 51,
b99a0cb3 106 LTTNG_EXECUTE_ERROR_QUERY = 52,
6c1db447 107 LTTCOMM_SESSIOND_COMMAND_MAX,
7c9534d6
JD
108};
109
6c1db447
JG
110static inline
111bool lttcomm_sessiond_command_is_valid(enum lttcomm_sessiond_command cmd)
112{
113 return cmd > LTTCOMM_SESSIOND_COMMAND_MIN && cmd < LTTCOMM_SESSIOND_COMMAND_MAX;
114}
115
19f912db
FD
116static inline
117const char *lttcomm_sessiond_command_str(enum lttcomm_sessiond_command cmd)
118{
119 switch (cmd) {
120 case LTTNG_ADD_CONTEXT:
121 return "LTTNG_ADD_CONTEXT";
122 case LTTNG_DISABLE_CHANNEL:
123 return "LTTNG_DISABLE_CHANNEL";
124 case LTTNG_DISABLE_EVENT:
125 return "LTTNG_DISABLE_EVENT";
126 case LTTNG_LIST_SYSCALLS:
127 return "LTTNG_LIST_SYSCALLS";
128 case LTTNG_ENABLE_CHANNEL:
129 return "LTTNG_ENABLE_CHANNEL";
130 case LTTNG_ENABLE_EVENT:
131 return "LTTNG_ENABLE_EVENT";
132 case LTTNG_DESTROY_SESSION:
133 return "LTTNG_DESTROY_SESSION";
134 case LTTNG_LIST_CHANNELS:
135 return "LTTNG_LIST_CHANNELS";
136 case LTTNG_LIST_DOMAINS:
137 return "LTTNG_LIST_DOMAINS";
138 case LTTNG_LIST_EVENTS:
139 return "LTTNG_LIST_EVENTS";
140 case LTTNG_LIST_SESSIONS:
141 return "LTTNG_LIST_SESSIONS";
142 case LTTNG_LIST_TRACEPOINTS:
143 return "LTTNG_LIST_TRACEPOINTS";
144 case LTTNG_REGISTER_CONSUMER:
145 return "LTTNG_REGISTER_CONSUMER";
146 case LTTNG_START_TRACE:
147 return "LTTNG_START_TRACE";
148 case LTTNG_STOP_TRACE:
149 return "LTTNG_STOP_TRACE";
150 case LTTNG_LIST_TRACEPOINT_FIELDS:
151 return "LTTNG_LIST_TRACEPOINT_FIELDS";
152 case LTTNG_DISABLE_CONSUMER:
153 return "LTTNG_DISABLE_CONSUMER";
154 case LTTNG_ENABLE_CONSUMER:
155 return "LTTNG_ENABLE_CONSUMER";
156 case LTTNG_SET_CONSUMER_URI:
157 return "LTTNG_SET_CONSUMER_URI";
158 case LTTNG_DATA_PENDING:
159 return "LTTNG_DATA_PENDING";
160 case LTTNG_SNAPSHOT_ADD_OUTPUT:
161 return "LTTNG_SNAPSHOT_ADD_OUTPUT";
162 case LTTNG_SNAPSHOT_DEL_OUTPUT:
163 return "LTTNG_SNAPSHOT_DEL_OUTPUT";
164 case LTTNG_SNAPSHOT_LIST_OUTPUT:
165 return "LTTNG_SNAPSHOT_LIST_OUTPUT";
166 case LTTNG_SNAPSHOT_RECORD:
167 return "LTTNG_SNAPSHOT_RECORD";
168 case LTTNG_SAVE_SESSION:
169 return "LTTNG_SAVE_SESSION";
170 case LTTNG_PROCESS_ATTR_TRACKER_ADD_INCLUDE_VALUE:
171 return "LTTNG_PROCESS_ATTR_TRACKER_ADD_INCLUDE_VALUE";
172 case LTTNG_PROCESS_ATTR_TRACKER_REMOVE_INCLUDE_VALUE:
173 return "LTTNG_PROCESS_ATTR_TRACKER_REMOVE_INCLUDE_VALUE";
174 case LTTNG_PROCESS_ATTR_TRACKER_GET_POLICY:
175 return "LTTNG_PROCESS_ATTR_TRACKER_GET_POLICY";
176 case LTTNG_PROCESS_ATTR_TRACKER_SET_POLICY:
177 return "LTTNG_PROCESS_ATTR_TRACKER_SET_POLICY";
178 case LTTNG_PROCESS_ATTR_TRACKER_GET_INCLUSION_SET:
179 return "LTTNG_PROCESS_ATTR_TRACKER_GET_INCLUSION_SET";
180 case LTTNG_SET_SESSION_SHM_PATH:
181 return "LTTNG_SET_SESSION_SHM_PATH";
182 case LTTNG_REGENERATE_METADATA:
183 return "LTTNG_REGENERATE_METADATA";
184 case LTTNG_REGENERATE_STATEDUMP:
185 return "LTTNG_REGENERATE_STATEDUMP";
186 case LTTNG_REGISTER_TRIGGER:
187 return "LTTNG_REGISTER_TRIGGER";
188 case LTTNG_UNREGISTER_TRIGGER:
189 return "LTTNG_UNREGISTER_TRIGGER";
190 case LTTNG_ROTATE_SESSION:
191 return "LTTNG_ROTATE_SESSION";
192 case LTTNG_ROTATION_GET_INFO:
193 return "LTTNG_ROTATION_GET_INFO";
194 case LTTNG_ROTATION_SET_SCHEDULE:
195 return "LTTNG_ROTATION_SET_SCHEDULE";
196 case LTTNG_SESSION_LIST_ROTATION_SCHEDULES:
197 return "LTTNG_SESSION_LIST_ROTATION_SCHEDULES";
198 case LTTNG_CREATE_SESSION_EXT:
199 return "LTTNG_CREATE_SESSION_EXT";
200 case LTTNG_CLEAR_SESSION:
201 return "LTTNG_CLEAR_SESSION";
202 case LTTNG_LIST_TRIGGERS:
203 return "LTTNG_LIST_TRIGGERS";
b99a0cb3
JG
204 case LTTNG_EXECUTE_ERROR_QUERY:
205 return "LTTNG_EXECUTE_ERROR_QUERY";
19f912db
FD
206 default:
207 abort();
208 }
209}
210
7c9534d6
JD
211enum lttcomm_relayd_command {
212 RELAYD_ADD_STREAM = 1,
213 RELAYD_CREATE_SESSION = 2,
214 RELAYD_START_DATA = 3,
215 RELAYD_UPDATE_SYNC_INFO = 4,
216 RELAYD_VERSION = 5,
217 RELAYD_SEND_METADATA = 6,
218 RELAYD_CLOSE_STREAM = 7,
219 RELAYD_DATA_PENDING = 8,
220 RELAYD_QUIESCENT_CONTROL = 9,
221 RELAYD_BEGIN_DATA_PENDING = 10,
222 RELAYD_END_DATA_PENDING = 11,
1c20f0e2
JD
223 RELAYD_ADD_INDEX = 12,
224 RELAYD_SEND_INDEX = 13,
225 RELAYD_CLOSE_INDEX = 14,
a4baae1b 226 /* Live-reading commands (2.4+). */
d3e2ba59 227 RELAYD_LIST_SESSIONS = 15,
a4baae1b
JD
228 /* All streams of the channel have been sent to the relayd (2.4+). */
229 RELAYD_STREAMS_SENT = 16,
93ec662e
JD
230 /* Ask the relay to reset the metadata trace file (2.8+) */
231 RELAYD_RESET_METADATA = 17,
c35f9726
JG
232 /* Ask the relay to rotate a set of stream files (2.11+) */
233 RELAYD_ROTATE_STREAMS = 18,
e5add6d0
JG
234 /* Ask the relay to create a trace chunk (2.11+) */
235 RELAYD_CREATE_TRACE_CHUNK = 19,
bbc4768c
JG
236 /* Ask the relay to close a trace chunk (2.11+) */
237 RELAYD_CLOSE_TRACE_CHUNK = 20,
c35f9726
JG
238 /* Ask the relay whether a trace chunk exists (2.11+) */
239 RELAYD_TRACE_CHUNK_EXISTS = 21,
8614e600
MD
240 /* Get the current configuration of a relayd peer (2.12+) */
241 RELAYD_GET_CONFIGURATION = 22,
3fe73a46
MD
242
243 /* Feature branch specific commands start at 10000. */
fac6795d
DG
244};
245
00e71031
FD
246static inline
247const char *lttcomm_relayd_command_str(lttcomm_relayd_command cmd)
248{
249 switch (cmd) {
250 case RELAYD_ADD_STREAM:
251 return "RELAYD_ADD_STREAM";
252 case RELAYD_CREATE_SESSION:
253 return "RELAYD_CREATE_SESSION";
254 case RELAYD_START_DATA:
255 return "RELAYD_START_DATA";
256 case RELAYD_UPDATE_SYNC_INFO:
257 return "RELAYD_UPDATE_SYNC_INFO";
258 case RELAYD_VERSION:
259 return "RELAYD_VERSION";
260 case RELAYD_SEND_METADATA:
261 return "RELAYD_SEND_METADATA";
262 case RELAYD_CLOSE_STREAM:
263 return "RELAYD_CLOSE_STREAM";
264 case RELAYD_DATA_PENDING:
265 return "RELAYD_DATA_PENDING";
266 case RELAYD_QUIESCENT_CONTROL:
267 return "RELAYD_QUIESCENT_CONTROL";
268 case RELAYD_BEGIN_DATA_PENDING:
269 return "RELAYD_BEGIN_DATA_PENDING";
270 case RELAYD_END_DATA_PENDING:
271 return "RELAYD_END_DATA_PENDING";
272 case RELAYD_ADD_INDEX:
273 return "RELAYD_ADD_INDEX";
274 case RELAYD_SEND_INDEX:
275 return "RELAYD_SEND_INDEX";
276 case RELAYD_CLOSE_INDEX:
277 return "RELAYD_CLOSE_INDEX";
278 case RELAYD_LIST_SESSIONS:
279 return "RELAYD_LIST_SESSIONS";
280 case RELAYD_STREAMS_SENT:
281 return "RELAYD_STREAMS_SENT";
282 case RELAYD_RESET_METADATA:
283 return "RELAYD_RESET_METADATA";
284 case RELAYD_ROTATE_STREAMS:
285 return "RELAYD_ROTATE_STREAMS";
286 case RELAYD_CREATE_TRACE_CHUNK:
287 return "RELAYD_CREATE_TRACE_CHUNK";
288 case RELAYD_CLOSE_TRACE_CHUNK:
289 return "RELAYD_CLOSE_TRACE_CHUNK";
290 case RELAYD_TRACE_CHUNK_EXISTS:
291 return "RELAYD_TRACE_CHUNK_EXISTS";
292 case RELAYD_GET_CONFIGURATION:
293 return "RELAYD_GET_CONFIGURATION";
294 default:
295 abort();
296 }
297}
298
fac6795d
DG
299/*
300 * lttcomm error code.
301 */
302enum lttcomm_return_code {
0c759fc9 303 LTTCOMM_CONSUMERD_SUCCESS = 0, /* Everything went fine. */
d2956687
JG
304 /*
305 * Some code paths use -1 to express an error, others
306 * negate this consumer return code. Starting codes at
307 * 100 ensures there is no mix-up between this error value
308 * and legitimate status codes.
309 */
310 LTTCOMM_CONSUMERD_COMMAND_SOCK_READY = 100, /* Command socket ready */
f73fabfd
DG
311 LTTCOMM_CONSUMERD_SUCCESS_RECV_FD, /* Success on receiving fds */
312 LTTCOMM_CONSUMERD_ERROR_RECV_FD, /* Error on receiving fds */
313 LTTCOMM_CONSUMERD_ERROR_RECV_CMD, /* Error on receiving command */
314 LTTCOMM_CONSUMERD_POLL_ERROR, /* Error in polling thread */
315 LTTCOMM_CONSUMERD_POLL_NVAL, /* Poll on closed fd */
316 LTTCOMM_CONSUMERD_POLL_HUP, /* All fds have hungup */
317 LTTCOMM_CONSUMERD_EXIT_SUCCESS, /* Consumerd exiting normally */
318 LTTCOMM_CONSUMERD_EXIT_FAILURE, /* Consumerd exiting on error */
319 LTTCOMM_CONSUMERD_OUTFD_ERROR, /* Error opening the tracefile */
320 LTTCOMM_CONSUMERD_SPLICE_EBADF, /* EBADF from splice(2) */
321 LTTCOMM_CONSUMERD_SPLICE_EINVAL, /* EINVAL from splice(2) */
322 LTTCOMM_CONSUMERD_SPLICE_ENOMEM, /* ENOMEM from splice(2) */
323 LTTCOMM_CONSUMERD_SPLICE_ESPIPE, /* ESPIPE from splice(2) */
ffe60014 324 LTTCOMM_CONSUMERD_ENOMEM, /* Consumer is out of memory */
d88aee68
DG
325 LTTCOMM_CONSUMERD_ERROR_METADATA, /* Error with metadata. */
326 LTTCOMM_CONSUMERD_FATAL, /* Fatal error. */
618a6a28 327 LTTCOMM_CONSUMERD_RELAYD_FAIL, /* Error on remote relayd */
0c759fc9 328 LTTCOMM_CONSUMERD_CHANNEL_FAIL, /* Channel creation failed. */
e462382a 329 LTTCOMM_CONSUMERD_CHAN_NOT_FOUND, /* Channel not found. */
e9404c27 330 LTTCOMM_CONSUMERD_ALREADY_SET, /* Resource already set. */
92b7a7f8 331 LTTCOMM_CONSUMERD_ROTATION_FAIL, /* Rotation has failed. */
3eb928aa 332 LTTCOMM_CONSUMERD_SNAPSHOT_FAILED, /* snapshot has failed. */
d2956687 333 LTTCOMM_CONSUMERD_CREATE_TRACE_CHUNK_FAILED,/* Trace chunk creation failed. */
64efa44e 334 LTTCOMM_CONSUMERD_CLOSE_TRACE_CHUNK_FAILED, /* Trace chunk close failed. */
d2956687
JG
335 LTTCOMM_CONSUMERD_INVALID_PARAMETERS, /* Invalid parameters. */
336 LTTCOMM_CONSUMERD_TRACE_CHUNK_EXISTS_LOCAL, /* Trace chunk exists on consumer daemon. */
337 LTTCOMM_CONSUMERD_TRACE_CHUNK_EXISTS_REMOTE,/* Trace chunk exists on relay daemon. */
338 LTTCOMM_CONSUMERD_UNKNOWN_TRACE_CHUNK, /* Unknown trace chunk. */
b01b201a 339 LTTCOMM_CONSUMERD_RELAYD_CLEAR_DISALLOWED, /* Relayd does not accept clear command. */
04ed9e10 340 LTTCOMM_CONSUMERD_UNKNOWN_ERROR, /* Unknown error. */
80e327fa 341
20fe2104
DG
342 /* MUST be last element */
343 LTTCOMM_NR, /* Last element */
fac6795d
DG
344};
345
de5e9086
DG
346/* lttng socket protocol. */
347enum lttcomm_sock_proto {
348 LTTCOMM_SOCK_UDP,
349 LTTCOMM_SOCK_TCP,
350};
351
352/*
353 * Index in the net_families array below. Please keep in sync!
354 */
355enum lttcomm_sock_domain {
01d0a631
CB
356 LTTCOMM_INET = 0,
357 LTTCOMM_INET6 = 1,
de5e9086
DG
358};
359
331744e3
JD
360enum lttcomm_metadata_command {
361 LTTCOMM_METADATA_REQUEST = 1,
362};
363
364/*
365 * Commands sent from the consumerd to the sessiond to request if new metadata
366 * is available. This message is used to find the per UID _or_ per PID registry
367 * for the channel key. For per UID lookup, the triplet
368 * bits_per_long/uid/session_id is used. On lookup failure, we search for the
369 * per PID registry indexed by session id ignoring the other values.
370 */
371struct lttcomm_metadata_request_msg {
1950109e
JD
372 uint64_t session_id; /* Tracing session id */
373 uint64_t session_id_per_pid; /* Tracing session id for per-pid */
331744e3
JD
374 uint32_t bits_per_long; /* Consumer ABI */
375 uint32_t uid;
376 uint64_t key; /* Metadata channel key. */
377} LTTNG_PACKED;
378
de5e9086
DG
379struct lttcomm_sockaddr {
380 enum lttcomm_sock_domain type;
381 union {
382 struct sockaddr_in sin;
383 struct sockaddr_in6 sin6;
384 } addr;
4222116f 385};
de5e9086
DG
386
387struct lttcomm_sock {
d88aee68 388 int32_t fd;
de5e9086
DG
389 enum lttcomm_sock_proto proto;
390 struct lttcomm_sockaddr sockaddr;
391 const struct lttcomm_proto_ops *ops;
4222116f 392};
de5e9086 393
6151a90f
JD
394/*
395 * Relayd sock. Adds the protocol version to use for the communications with
396 * the relayd.
397 */
398struct lttcomm_relayd_sock {
399 struct lttcomm_sock sock;
400 uint32_t major;
401 uint32_t minor;
4222116f 402};
6151a90f 403
de5e9086
DG
404struct lttcomm_net_family {
405 int family;
406 int (*create) (struct lttcomm_sock *sock, int type, int proto);
407};
408
409struct lttcomm_proto_ops {
410 int (*bind) (struct lttcomm_sock *sock);
411 int (*close) (struct lttcomm_sock *sock);
412 int (*connect) (struct lttcomm_sock *sock);
413 struct lttcomm_sock *(*accept) (struct lttcomm_sock *sock);
414 int (*listen) (struct lttcomm_sock *sock, int backlog);
415 ssize_t (*recvmsg) (struct lttcomm_sock *sock, void *buf, size_t len,
416 int flags);
c2d69327
JG
417 ssize_t (*sendmsg) (struct lttcomm_sock *sock, const void *buf,
418 size_t len, int flags);
de5e9086
DG
419};
420
159b042f
JG
421struct process_attr_integral_value_comm {
422 union {
423 int64_t _signed;
424 uint64_t _unsigned;
425 } u;
426} LTTNG_PACKED;
427
fac6795d 428/*
9bda164d 429 * Data structure received from lttng client to session daemon.
fac6795d
DG
430 */
431struct lttcomm_session_msg {
d0b96690 432 uint32_t cmd_type; /* enum lttcomm_sessiond_command */
42abccdb 433 struct lttng_session session;
9f19cc17 434 struct lttng_domain domain;
fac6795d 435 union {
f3ed775e 436 /* Event data */
fac6795d 437 struct {
db8870ed 438 char channel_name[LTTNG_SYMBOL_NAME_LEN];
8ddd72ef 439 uint32_t length;
fc5e05b7 440 } LTTNG_PACKED enable;
6e911cad
MD
441 struct {
442 char channel_name[LTTNG_SYMBOL_NAME_LEN];
8ddd72ef 443 uint32_t length;
6e911cad 444 } LTTNG_PACKED disable;
f3ed775e
DG
445 /* Create channel */
446 struct {
999af9c1 447 uint32_t length;
fc5e05b7 448 } LTTNG_PACKED channel;
d65106b1
DG
449 /* Context */
450 struct {
db8870ed 451 char channel_name[LTTNG_SYMBOL_NAME_LEN];
26e1c61f 452 uint32_t length;
fc5e05b7 453 } LTTNG_PACKED context;
d9800920
DG
454 /* Use by register_consumer */
455 struct {
456 char path[PATH_MAX];
fc5e05b7 457 } LTTNG_PACKED reg;
9f19cc17
DG
458 /* List */
459 struct {
db8870ed 460 char channel_name[LTTNG_SYMBOL_NAME_LEN];
fc5e05b7 461 } LTTNG_PACKED list;
d0254c7c 462 struct lttng_calibrate calibrate;
a4b92340 463 /* Used by the set_consumer_url and used by create_session also call */
de5e9086 464 struct {
a4b92340
DG
465 /* Number of lttng_uri following */
466 uint32_t size;
fc5e05b7 467 } LTTNG_PACKED uri;
da3c9ec1 468 struct {
7bd95aee 469 struct lttng_snapshot_output output;
da3c9ec1
DG
470 } LTTNG_PACKED snapshot_output;
471 struct {
472 uint32_t wait;
7bd95aee 473 struct lttng_snapshot_output output;
da3c9ec1 474 } LTTNG_PACKED snapshot_record;
ecc48a90
JD
475 struct {
476 uint32_t nb_uri;
477 unsigned int timer_interval; /* usec */
478 } LTTNG_PACKED session_live;
00c76cea 479 struct {
7bd95aee 480 struct lttng_save_session_attr attr;
00c76cea 481 } LTTNG_PACKED save_session;
d7ba1388
MD
482 struct {
483 char shm_path[PATH_MAX];
484 } LTTNG_PACKED set_shm_path;
ccf10263 485 struct {
159b042f
JG
486 /* enum lttng_process_attr */
487 int32_t process_attr;
488 /* enum lttng_process_attr_value_type */
489 int32_t value_type;
490
491 struct process_attr_integral_value_comm integral_value;
55c9e7ca 492 /*
159b042f
JG
493 * For user/group names, a variable length,
494 * zero-terminated, string of length 'name_len'
495 * (including the terminator) follows.
496 *
497 * integral_value should not be used in those cases.
55c9e7ca 498 */
159b042f
JG
499 uint32_t name_len;
500 } LTTNG_PACKED process_attr_tracker_add_remove_include_value;
55c9e7ca 501 struct {
159b042f
JG
502 /* enum lttng_process_attr */
503 int32_t process_attr;
504 } LTTNG_PACKED process_attr_tracker_get_inclusion_set;
505 struct {
506 /* enum lttng_process_attr */
507 int32_t process_attr;
508 } LTTNG_PACKED process_attr_tracker_get_tracking_policy;
509 struct {
510 /* enum lttng_process_attr */
511 int32_t process_attr;
512 /* enum lttng_tracking_policy */
513 int32_t tracking_policy;
514 } LTTNG_PACKED process_attr_tracker_set_tracking_policy;
e9404c27
JG
515 struct {
516 uint32_t length;
0efb2ad7 517 uint8_t is_trigger_anonymous;
e9404c27 518 } LTTNG_PACKED trigger;
b99a0cb3
JG
519 struct {
520 uint32_t length;
521 } LTTNG_PACKED error_query;
d88744a4 522 struct {
d68c9a04
JD
523 uint64_t rotation_id;
524 } LTTNG_PACKED get_rotation_info;
259c2674 525 struct {
66ea93b1
JG
526 /* enum lttng_rotation_schedule_type */
527 uint8_t type;
528 /*
529 * If set == 1, set schedule to value, if set == 0,
530 * clear this schedule type.
531 */
532 uint8_t set;
533 uint64_t value;
534 } LTTNG_PACKED rotation_set_schedule;
b178f53e
JG
535 struct {
536 /*
537 * Includes the null-terminator.
538 * Must be an absolute path.
539 *
540 * Size bounded by LTTNG_PATH_MAX.
541 */
542 uint16_t home_dir_size;
543 uint64_t session_descriptor_size;
544 /* An lttng_session_descriptor follows. */
545 } LTTNG_PACKED create_session;
fac6795d 546 } u;
99608320
JR
547 /* Count of fds sent. */
548 uint32_t fd_count;
fc5e05b7 549} LTTNG_PACKED;
fac6795d 550
d93c4f1f 551#define LTTNG_FILTER_MAX_LEN 65536
b178f53e 552#define LTTNG_SESSION_DESCRIPTOR_MAX_LEN 65536
53a80697
MD
553
554/*
555 * Filter bytecode data. The reloc table is located at the end of the
556 * bytecode. It is made of tuples: (uint16_t, var. len. string). It
557 * starts at reloc_table_offset.
558 */
b6bbed5f 559#define LTTNG_FILTER_PADDING 32
2b00d462 560struct lttng_bytecode {
d93c4f1f
CB
561 uint32_t len; /* len of data */
562 uint32_t reloc_table_offset;
f3f0db50 563 uint64_t seqnum;
b6bbed5f 564 char padding[LTTNG_FILTER_PADDING];
53a80697 565 char data[0];
fc5e05b7 566} LTTNG_PACKED;
53a80697 567
579640f9
JI
568/*
569 * Event exclusion data. At the end of the structure, there will actually
570 * by zero or more names, where the actual number of names is given by
571 * the 'count' item of the structure.
572 */
573#define LTTNG_EVENT_EXCLUSION_PADDING 32
574struct lttng_event_exclusion {
575 uint32_t count;
576 char padding[LTTNG_EVENT_EXCLUSION_PADDING];
62e6775c 577 char names[][LTTNG_SYMBOL_NAME_LEN];
579640f9
JI
578} LTTNG_PACKED;
579
d7af3565 580#define LTTNG_EVENT_EXCLUSION_NAME_AT(_exclusion, _i) \
62e6775c 581 ((_exclusion)->names[_i])
d7af3565 582
999af9c1
JR
583/*
584 * Listing command header.
585 */
586struct lttcomm_list_command_header {
587 /* Number of elements */
588 uint32_t count;
589} LTTNG_PACKED;
590
b4e3ceb9
PP
591/*
592 * Event extended info header. This is the structure preceding each
593 * extended info data.
594 */
595struct lttcomm_event_extended_header {
596 /*
597 * Size of filter string immediately following this header.
598 * This size includes the terminal null character.
599 */
600 uint32_t filter_len;
795d57ce
PP
601
602 /*
603 * Number of exclusion names, immediately following the filter
604 * string. Each exclusion name has a fixed length of
605 * LTTNG_SYMBOL_NAME_LEN bytes, including the terminal null
606 * character.
607 */
608 uint32_t nb_exclusions;
56f0bc67
JG
609
610 /*
611 * Size of the event's userspace probe location (if applicable).
612 */
613 uint32_t userspace_probe_location_len;
b4e3ceb9
PP
614} LTTNG_PACKED;
615
3e3665b8
JG
616/*
617 * Command header of the reply to an LTTNG_DESTROY_SESSION command.
618 */
619struct lttcomm_session_destroy_command_header {
620 /* enum lttng_session */
621 int32_t rotation_state;
622};
623
55c9e7ca
JR
624/*
625 * tracker command header.
626 */
627struct lttcomm_tracker_command_header {
628 uint32_t nb_tracker_id;
629} LTTNG_PACKED;
630
fac6795d 631/*
5e16da05 632 * Data structure for the response from sessiond to the lttng client.
fac6795d 633 */
5461b305 634struct lttcomm_lttng_msg {
d0b96690
DG
635 uint32_t cmd_type; /* enum lttcomm_sessiond_command */
636 uint32_t ret_code; /* enum lttcomm_return_code */
637 uint32_t pid; /* pid_t */
795a978d 638 uint32_t cmd_header_size;
773168b7 639 uint32_t data_size;
e368fb43 640 uint32_t fd_count;
fc5e05b7 641} LTTNG_PACKED;
fac6795d 642
da3c9ec1
DG
643struct lttcomm_lttng_output_id {
644 uint32_t id;
645} LTTNG_PACKED;
646
6e3805e2 647/*
3bd1e081
MD
648 * lttcomm_consumer_msg is the message sent from sessiond to consumerd
649 * to either add a channel, add a stream, update a stream, or stop
650 * operation.
6e3805e2 651 */
3bd1e081 652struct lttcomm_consumer_msg {
92816cc3 653 uint32_t cmd_type; /* enum lttng_consumer_command */
3bd1e081
MD
654 union {
655 struct {
d88aee68 656 uint64_t channel_key;
ffe60014 657 uint64_t session_id;
d2956687 658 /* ID of the session's current trace chunk. */
0a30bf9b 659 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED chunk_id;
ffe60014 660 char pathname[PATH_MAX];
d88aee68 661 uint64_t relayd_id;
c30aaa51 662 /* nb_init_streams is the number of streams open initially. */
d88aee68 663 uint32_t nb_init_streams;
de5e9086 664 char name[LTTNG_SYMBOL_NAME_LEN];
ffe60014
DG
665 /* Use splice or mmap to consume this fd */
666 enum lttng_event_output output;
667 int type; /* Per cpu or metadata. */
1624d5b7
JD
668 uint64_t tracefile_size; /* bytes */
669 uint32_t tracefile_count; /* number of tracefiles */
2bba9e53
DG
670 /* If the channel's streams have to be monitored or not. */
671 uint32_t monitor;
ecc48a90
JD
672 /* timer to check the streams usage in live mode (usec). */
673 unsigned int live_timer_interval;
a2814ea7
JG
674 /* is part of a live session */
675 uint8_t is_live;
e9404c27
JG
676 /* timer to sample a channel's positions (usec). */
677 unsigned int monitor_timer_interval;
ffe60014 678 } LTTNG_PACKED channel; /* Only used by Kernel. */
3bd1e081 679 struct {
d88aee68
DG
680 uint64_t stream_key;
681 uint64_t channel_key;
682 int32_t cpu; /* On which CPU this stream is assigned. */
6dc3064a
DG
683 /* Tells the consumer if the stream should be or not monitored. */
684 uint32_t no_monitor;
ffe60014 685 } LTTNG_PACKED stream; /* Only used by Kernel. */
de5e9086 686 struct {
d88aee68 687 uint64_t net_index;
de5e9086 688 enum lttng_stream_type type;
4222116f
JR
689 uint32_t major;
690 uint32_t minor;
691 uint8_t relayd_socket_protocol;
46e6455f
DG
692 /* Tracing session id associated to the relayd. */
693 uint64_t session_id;
d3e2ba59
JD
694 /* Relayd session id, only used with control socket. */
695 uint64_t relayd_session_id;
fc5e05b7 696 } LTTNG_PACKED relayd_sock;
173af62f
DG
697 struct {
698 uint64_t net_seq_idx;
fc5e05b7 699 } LTTNG_PACKED destroy_relayd;
53632229
DG
700 struct {
701 uint64_t session_id;
fc5e05b7 702 } LTTNG_PACKED data_pending;
ffe60014 703 struct {
d0b96690
DG
704 uint64_t subbuf_size; /* bytes */
705 uint64_t num_subbuf; /* power of 2 */
d88aee68
DG
706 int32_t overwrite; /* 1: overwrite, 0: discard */
707 uint32_t switch_timer_interval; /* usec */
708 uint32_t read_timer_interval; /* usec */
e9404c27 709 unsigned int live_timer_interval; /* usec */
a2814ea7 710 uint8_t is_live; /* is part of a live session */
e9404c27 711 uint32_t monitor_timer_interval; /* usec */
d88aee68
DG
712 int32_t output; /* splice, mmap */
713 int32_t type; /* metadata or per_cpu */
d0b96690
DG
714 uint64_t session_id; /* Tracing session id */
715 char pathname[PATH_MAX]; /* Channel file path. */
ffe60014 716 char name[LTTNG_SYMBOL_NAME_LEN]; /* Channel name. */
d2956687
JG
717 /* Credentials used to open the UST buffer shared mappings. */
718 struct {
719 uint32_t uid;
720 uint32_t gid;
721 } LTTNG_PACKED buffer_credentials;
d88aee68
DG
722 uint64_t relayd_id; /* Relayd id if apply. */
723 uint64_t key; /* Unique channel key. */
d2956687 724 /* ID of the session's current trace chunk. */
0a30bf9b 725 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED chunk_id;
c70636a7 726 unsigned char uuid[LTTNG_UUID_LEN]; /* uuid for ust tracer. */
7972aab2 727 uint32_t chan_id; /* Channel ID on the tracer side. */
1624d5b7
JD
728 uint64_t tracefile_size; /* bytes */
729 uint32_t tracefile_count; /* number of tracefiles */
1950109e 730 uint64_t session_id_per_pid; /* Per-pid session ID. */
2bba9e53
DG
731 /* Tells the consumer if the stream should be or not monitored. */
732 uint32_t monitor;
567eb353
DG
733 /*
734 * For UST per UID buffers, this is the application UID of the
735 * channel. This can be different from the user UID requesting the
736 * channel creation and used for the rights on the stream file
737 * because the application can be in the tracing for instance.
738 */
739 uint32_t ust_app_uid;
491d1539 740 int64_t blocking_timeout;
3d071855 741 char root_shm_path[PATH_MAX];
d7ba1388 742 char shm_path[PATH_MAX];
ffe60014
DG
743 } LTTNG_PACKED ask_channel;
744 struct {
d88aee68 745 uint64_t key;
ffe60014
DG
746 } LTTNG_PACKED get_channel;
747 struct {
d88aee68 748 uint64_t key;
ffe60014 749 } LTTNG_PACKED destroy_channel;
d88aee68
DG
750 struct {
751 uint64_t key; /* Metadata channel key. */
752 uint64_t target_offset; /* Offset in the consumer */
753 uint64_t len; /* Length of metadata to be received. */
93ec662e 754 uint64_t version; /* Version of the metadata. */
d88aee68
DG
755 } LTTNG_PACKED push_metadata;
756 struct {
757 uint64_t key; /* Metadata channel key. */
758 } LTTNG_PACKED close_metadata;
759 struct {
760 uint64_t key; /* Metadata channel key. */
761 } LTTNG_PACKED setup_metadata;
7972aab2
DG
762 struct {
763 uint64_t key; /* Channel key. */
764 } LTTNG_PACKED flush_channel;
0dd01979
MD
765 struct {
766 uint64_t key; /* Channel key. */
767 } LTTNG_PACKED clear_quiescent_channel;
6dc3064a
DG
768 struct {
769 char pathname[PATH_MAX];
770 /* Indicate if the snapshot goes on the relayd or locally. */
771 uint32_t use_relayd;
772 uint32_t metadata; /* This a metadata snapshot. */
773 uint64_t relayd_id; /* Relayd id if apply. */
774 uint64_t key;
d07ceecd 775 uint64_t nb_packets_per_stream;
6dc3064a 776 } LTTNG_PACKED snapshot_channel;
a4baae1b
JD
777 struct {
778 uint64_t channel_key;
779 uint64_t net_seq_idx;
780 } LTTNG_PACKED sent_streams;
fb83fe64
JD
781 struct {
782 uint64_t session_id;
783 uint64_t channel_key;
784 } LTTNG_PACKED discarded_events;
785 struct {
786 uint64_t session_id;
787 uint64_t channel_key;
788 } LTTNG_PACKED lost_packets;
93ec662e
JD
789 struct {
790 uint64_t session_id;
eded6438 791 } LTTNG_PACKED regenerate_metadata;
b99a8d42 792 struct {
b99a8d42
JD
793 uint32_t metadata; /* This is a metadata channel. */
794 uint64_t relayd_id; /* Relayd id if apply. */
795 uint64_t key;
b99a8d42 796 } LTTNG_PACKED rotate_channel;
92816cc3
JG
797 struct {
798 uint64_t session_id;
799 uint64_t chunk_id;
800 } LTTNG_PACKED check_rotation_pending_local;
d88744a4
JD
801 struct {
802 uint64_t relayd_id;
803 uint64_t session_id;
804 uint64_t chunk_id;
92816cc3 805 } LTTNG_PACKED check_rotation_pending_relay;
a1ae2ea5 806 struct {
d2956687
JG
807 /*
808 * Relayd id, if applicable (remote).
809 *
810 * A directory file descriptor referring to the chunk's
811 * output folder is transmitted if the chunk is local
812 * (relayd_id unset).
813 *
814 * `override_name` is left NULL (all-zeroes) if the
913a542b 815 * chunk's name is not overridden.
d2956687 816 */
0a30bf9b 817 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED relayd_id;
d2956687
JG
818 char override_name[LTTNG_NAME_MAX];
819 uint64_t session_id;
820 uint64_t chunk_id;
821 uint64_t creation_timestamp;
e5add6d0 822 LTTNG_OPTIONAL_COMM(struct {
d2956687
JG
823 uint32_t uid;
824 uint32_t gid;
e5add6d0 825 } LTTNG_PACKED ) LTTNG_PACKED credentials;
d2956687
JG
826 } LTTNG_PACKED create_trace_chunk;
827 struct {
0a30bf9b 828 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED relayd_id;
d2956687
JG
829 uint64_t session_id;
830 uint64_t chunk_id;
831 uint64_t close_timestamp;
bbc4768c
JG
832 /* enum lttng_trace_chunk_command_type */
833 LTTNG_OPTIONAL_COMM(uint32_t) LTTNG_PACKED close_command;
d2956687
JG
834 } LTTNG_PACKED close_trace_chunk;
835 struct {
0a30bf9b 836 LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED relayd_id;
a1ae2ea5 837 uint64_t session_id;
d2956687
JG
838 uint64_t chunk_id;
839 } LTTNG_PACKED trace_chunk_exists;
840 struct {
328c2fe7 841 uint8_t sessiond_uuid[LTTNG_UUID_LEN];
d2956687 842 } LTTNG_PACKED init;
b01b201a
MD
843 struct {
844 uint64_t key;
845 } LTTNG_PACKED clear_channel;
04ed9e10
JG
846 struct {
847 uint64_t key;
848 } LTTNG_PACKED open_channel_packets;
3bd1e081 849 } u;
fc5e05b7 850} LTTNG_PACKED;
6e3805e2 851
e9404c27
JG
852/*
853 * Channel monitoring message returned to the session daemon on every
854 * monitor timer expiration.
855 */
856struct lttcomm_consumer_channel_monitor_msg {
857 /* Key of the sampled channel. */
858 uint64_t key;
319dcddc
JG
859 /* Id of the sampled channel's session. */
860 uint64_t session_id;
e9404c27
JG
861 /*
862 * Lowest and highest usage (bytes) at the moment the sample was taken.
863 */
864 uint64_t lowest, highest;
e8360425
JD
865 /*
866 * Sum of all the consumed positions for a channel.
867 */
319dcddc 868 uint64_t consumed_since_last_sample;
e9404c27
JG
869} LTTNG_PACKED;
870
f50f23d9
DG
871/*
872 * Status message returned to the sessiond after a received command.
873 */
874struct lttcomm_consumer_status_msg {
0c759fc9 875 enum lttcomm_return_code ret_code;
fc5e05b7 876} LTTNG_PACKED;
f50f23d9 877
ffe60014 878struct lttcomm_consumer_status_channel {
0c759fc9 879 enum lttcomm_return_code ret_code;
d88aee68 880 uint64_t key;
ffe60014
DG
881 unsigned int stream_count;
882} LTTNG_PACKED;
883
ecd1a12f
MD
884struct lttcomm_consumer_close_trace_chunk_reply {
885 enum lttcomm_return_code ret_code;
886 uint32_t path_length;
887 char path[];
888};
889
51791532
JG
890#ifdef HAVE_LIBLTTNG_UST_CTL
891
9df8df5e 892#include <lttng/ust-abi.h>
6e3805e2 893
3817e7df
DG
894/*
895 * Data structure for the commands sent from sessiond to UST.
896 */
897struct lttcomm_ust_msg {
3817e7df
DG
898 uint32_t handle;
899 uint32_t cmd;
900 union {
fc4b93fa
MD
901 struct lttng_ust_abi_channel channel;
902 struct lttng_ust_abi_stream stream;
903 struct lttng_ust_abi_event event;
904 struct lttng_ust_abi_context context;
905 struct lttng_ust_abi_tracer_version version;
3817e7df 906 } u;
fc5e05b7 907} LTTNG_PACKED;
3817e7df
DG
908
909/*
910 * Data structure for the response from UST to the session daemon.
911 * cmd_type is sent back in the reply for validation.
912 */
913struct lttcomm_ust_reply {
914 uint32_t handle;
915 uint32_t cmd;
916 uint32_t ret_code; /* enum lttcomm_return_code */
917 uint32_t ret_val; /* return value */
918 union {
2b0bf864
DG
919 struct {
920 uint64_t memory_map_size;
fc5e05b7 921 } LTTNG_PACKED channel;
2b0bf864
DG
922 struct {
923 uint64_t memory_map_size;
fc5e05b7 924 } LTTNG_PACKED stream;
fc4b93fa 925 struct lttng_ust_abi_tracer_version version;
3817e7df 926 } u;
fc5e05b7 927} LTTNG_PACKED;
3817e7df 928
74d0b642 929#endif /* HAVE_LIBLTTNG_UST_CTL */
3bd1e081 930
ca806b0b 931const char *lttcomm_get_readable_code(enum lttcomm_return_code code);
fac6795d 932
ca806b0b 933int lttcomm_init_inet_sockaddr(struct lttcomm_sockaddr *sockaddr,
6364a07a 934 const char *ip, unsigned int port);
ca806b0b 935int lttcomm_init_inet6_sockaddr(struct lttcomm_sockaddr *sockaddr,
6364a07a
DG
936 const char *ip, unsigned int port);
937
ca806b0b 938struct lttcomm_sock *lttcomm_alloc_sock(enum lttcomm_sock_proto proto);
4222116f
JR
939int lttcomm_populate_sock_from_open_socket(struct lttcomm_sock *sock,
940 int fd,
941 enum lttcomm_sock_proto protocol);
ca806b0b
SM
942int lttcomm_create_sock(struct lttcomm_sock *sock);
943struct lttcomm_sock *lttcomm_alloc_sock_from_uri(struct lttng_uri *uri);
944void lttcomm_destroy_sock(struct lttcomm_sock *sock);
945struct lttcomm_sock *lttcomm_alloc_copy_sock(struct lttcomm_sock *src);
946void lttcomm_copy_sock(struct lttcomm_sock *dst,
de5e9086 947 struct lttcomm_sock *src);
6364a07a 948
6151a90f 949/* Relayd socket object. */
ca806b0b 950struct lttcomm_relayd_sock *lttcomm_alloc_relayd_sock(
6151a90f
JD
951 struct lttng_uri *uri, uint32_t major, uint32_t minor);
952
ca806b0b
SM
953int lttcomm_setsockopt_rcv_timeout(int sock, unsigned int msec);
954int lttcomm_setsockopt_snd_timeout(int sock, unsigned int msec);
783a3b9a 955
ca806b0b 956int lttcomm_sock_get_port(const struct lttcomm_sock *sock,
2288467f
JG
957 uint16_t *port);
958/*
959 * Set a port to an lttcomm_sock. This will have no effect is the socket is
960 * already bound.
961 */
ca806b0b 962int lttcomm_sock_set_port(struct lttcomm_sock *sock, uint16_t port);
2288467f 963
ca806b0b 964void lttcomm_init(void);
554831e7 965/* Get network timeout, in milliseconds */
ca806b0b 966unsigned long lttcomm_get_network_timeout(void);
554831e7 967
773168b7 968#endif /* _LTTNG_SESSIOND_COMM_H */
This page took 0.131283 seconds and 4 git commands to generate.