]> git.proxmox.com Git - systemd.git/blame - src/libsystemd/sd-bus/kdbus.h
Imported Upstream version 220
[systemd.git] / src / libsystemd / sd-bus / kdbus.h
CommitLineData
60f067b4 1/*
60f067b4
JS
2 * kdbus is free software; you can redistribute it and/or modify it under
3 * the terms of the GNU Lesser General Public License as published by the
4 * Free Software Foundation; either version 2.1 of the License, or (at
5 * your option) any later version.
60f067b4
JS
6 */
7
5eef597e
MP
8#ifndef _KDBUS_UAPI_H_
9#define _KDBUS_UAPI_H_
60f067b4 10
5eef597e 11#include <linux/ioctl.h>
60f067b4 12#include <linux/types.h>
60f067b4
JS
13
14#define KDBUS_IOCTL_MAGIC 0x95
15#define KDBUS_SRC_ID_KERNEL (0)
16#define KDBUS_DST_ID_NAME (0)
17#define KDBUS_MATCH_ID_ANY (~0ULL)
18#define KDBUS_DST_ID_BROADCAST (~0ULL)
e735f4d4 19#define KDBUS_FLAG_NEGOTIATE (1ULL << 63)
60f067b4
JS
20
21/**
22 * struct kdbus_notify_id_change - name registry change message
23 * @id: New or former owner of the name
24 * @flags: flags field from KDBUS_HELLO_*
25 *
26 * Sent from kernel to userspace when the owner or activator of
27 * a well-known name changes.
28 *
29 * Attached to:
30 * KDBUS_ITEM_ID_ADD
31 * KDBUS_ITEM_ID_REMOVE
32 */
33struct kdbus_notify_id_change {
34 __u64 id;
35 __u64 flags;
e735f4d4 36} __attribute__((__aligned__(8)));
60f067b4
JS
37
38/**
39 * struct kdbus_notify_name_change - name registry change message
5eef597e
MP
40 * @old_id: ID and flags of former owner of a name
41 * @new_id: ID and flags of new owner of a name
60f067b4
JS
42 * @name: Well-known name
43 *
44 * Sent from kernel to userspace when the owner or activator of
45 * a well-known name changes.
46 *
47 * Attached to:
48 * KDBUS_ITEM_NAME_ADD
49 * KDBUS_ITEM_NAME_REMOVE
50 * KDBUS_ITEM_NAME_CHANGE
51 */
52struct kdbus_notify_name_change {
5eef597e
MP
53 struct kdbus_notify_id_change old_id;
54 struct kdbus_notify_id_change new_id;
60f067b4 55 char name[0];
e735f4d4 56} __attribute__((__aligned__(8)));
60f067b4
JS
57
58/**
59 * struct kdbus_creds - process credentials
60 * @uid: User ID
f47781d8
MP
61 * @euid: Effective UID
62 * @suid: Saved UID
63 * @fsuid: Filesystem UID
60f067b4 64 * @gid: Group ID
f47781d8
MP
65 * @egid: Effective GID
66 * @sgid: Saved GID
67 * @fsgid: Filesystem GID
68 *
69 * Attached to:
70 * KDBUS_ITEM_CREDS
71 */
72struct kdbus_creds {
e3bff60a
MP
73 __u64 uid;
74 __u64 euid;
75 __u64 suid;
76 __u64 fsuid;
77 __u64 gid;
78 __u64 egid;
79 __u64 sgid;
80 __u64 fsgid;
e735f4d4 81} __attribute__((__aligned__(8)));
f47781d8
MP
82
83/**
84 * struct kdbus_pids - process identifiers
60f067b4
JS
85 * @pid: Process ID
86 * @tid: Thread ID
e735f4d4 87 * @ppid: Parent process ID
60f067b4 88 *
f47781d8 89 * The PID and TID of a process.
60f067b4
JS
90 *
91 * Attached to:
f47781d8 92 * KDBUS_ITEM_PIDS
60f067b4 93 */
f47781d8 94struct kdbus_pids {
60f067b4
JS
95 __u64 pid;
96 __u64 tid;
e735f4d4
MP
97 __u64 ppid;
98} __attribute__((__aligned__(8)));
60f067b4 99
5eef597e
MP
100/**
101 * struct kdbus_caps - process capabilities
102 * @last_cap: Highest currently known capability bit
103 * @caps: Variable number of 32-bit capabilities flags
104 *
105 * Contains a variable number of 32-bit capabilities flags.
106 *
107 * Attached to:
108 * KDBUS_ITEM_CAPS
109 */
110struct kdbus_caps {
111 __u32 last_cap;
112 __u32 caps[0];
e735f4d4 113} __attribute__((__aligned__(8)));
5eef597e 114
60f067b4
JS
115/**
116 * struct kdbus_audit - audit information
117 * @sessionid: The audit session ID
118 * @loginuid: The audit login uid
119 *
120 * Attached to:
121 * KDBUS_ITEM_AUDIT
122 */
123struct kdbus_audit {
f47781d8
MP
124 __u32 sessionid;
125 __u32 loginuid;
e735f4d4 126} __attribute__((__aligned__(8)));
60f067b4
JS
127
128/**
129 * struct kdbus_timestamp
130 * @seqnum: Global per-domain message sequence number
131 * @monotonic_ns: Monotonic timestamp, in nanoseconds
132 * @realtime_ns: Realtime timestamp, in nanoseconds
133 *
134 * Attached to:
135 * KDBUS_ITEM_TIMESTAMP
136 */
137struct kdbus_timestamp {
138 __u64 seqnum;
139 __u64 monotonic_ns;
140 __u64 realtime_ns;
e735f4d4 141} __attribute__((__aligned__(8)));
60f067b4
JS
142
143/**
144 * struct kdbus_vec - I/O vector for kdbus payload items
145 * @size: The size of the vector
5eef597e 146 * @address: Memory address of data buffer
60f067b4
JS
147 * @offset: Offset in the in-message payload memory,
148 * relative to the message head
149 *
150 * Attached to:
5eef597e 151 * KDBUS_ITEM_PAYLOAD_VEC, KDBUS_ITEM_PAYLOAD_OFF
60f067b4
JS
152 */
153struct kdbus_vec {
154 __u64 size;
155 union {
156 __u64 address;
157 __u64 offset;
158 };
e735f4d4 159} __attribute__((__aligned__(8)));
60f067b4
JS
160
161/**
162 * struct kdbus_bloom_parameter - bus-wide bloom parameters
163 * @size: Size of the bit field in bytes (m / 8)
164 * @n_hash: Number of hash functions used (k)
165 */
166struct kdbus_bloom_parameter {
167 __u64 size;
168 __u64 n_hash;
e735f4d4 169} __attribute__((__aligned__(8)));
60f067b4
JS
170
171/**
172 * struct kdbus_bloom_filter - bloom filter containing n elements
173 * @generation: Generation of the element set in the filter
174 * @data: Bit field, multiple of 8 bytes
175 */
176struct kdbus_bloom_filter {
177 __u64 generation;
178 __u64 data[0];
e735f4d4 179} __attribute__((__aligned__(8)));
60f067b4
JS
180
181/**
182 * struct kdbus_memfd - a kdbus memfd
f47781d8
MP
183 * @start: The offset into the memfd where the segment starts
184 * @size: The size of the memfd segment
60f067b4 185 * @fd: The file descriptor number
5eef597e 186 * @__pad: Padding to ensure proper alignment and size
60f067b4
JS
187 *
188 * Attached to:
189 * KDBUS_ITEM_PAYLOAD_MEMFD
190 */
191struct kdbus_memfd {
f47781d8 192 __u64 start;
60f067b4
JS
193 __u64 size;
194 int fd;
195 __u32 __pad;
e735f4d4 196} __attribute__((__aligned__(8)));
60f067b4
JS
197
198/**
199 * struct kdbus_name - a registered well-known name with its flags
200 * @flags: Flags from KDBUS_NAME_*
201 * @name: Well-known name
202 *
203 * Attached to:
f47781d8 204 * KDBUS_ITEM_OWNED_NAME
60f067b4
JS
205 */
206struct kdbus_name {
207 __u64 flags;
208 char name[0];
e735f4d4
MP
209} __attribute__((__aligned__(8)));
210
211/**
212 * enum kdbus_policy_access_type - permissions of a policy record
213 * @_KDBUS_POLICY_ACCESS_NULL: Uninitialized/invalid
214 * @KDBUS_POLICY_ACCESS_USER: Grant access to a uid
215 * @KDBUS_POLICY_ACCESS_GROUP: Grant access to gid
216 * @KDBUS_POLICY_ACCESS_WORLD: World-accessible
217 */
218enum kdbus_policy_access_type {
219 _KDBUS_POLICY_ACCESS_NULL,
220 KDBUS_POLICY_ACCESS_USER,
221 KDBUS_POLICY_ACCESS_GROUP,
222 KDBUS_POLICY_ACCESS_WORLD,
223};
224
225/**
226 * enum kdbus_policy_access_flags - mode flags
227 * @KDBUS_POLICY_OWN: Allow to own a well-known name
228 * Implies KDBUS_POLICY_TALK and KDBUS_POLICY_SEE
229 * @KDBUS_POLICY_TALK: Allow communication to a well-known name
230 * Implies KDBUS_POLICY_SEE
231 * @KDBUS_POLICY_SEE: Allow to see a well-known name
232 */
233enum kdbus_policy_type {
234 KDBUS_POLICY_SEE = 0,
235 KDBUS_POLICY_TALK,
236 KDBUS_POLICY_OWN,
60f067b4
JS
237};
238
239/**
240 * struct kdbus_policy_access - policy access item
241 * @type: One of KDBUS_POLICY_ACCESS_* types
242 * @access: Access to grant
243 * @id: For KDBUS_POLICY_ACCESS_USER, the uid
244 * For KDBUS_POLICY_ACCESS_GROUP, the gid
245 */
246struct kdbus_policy_access {
247 __u64 type; /* USER, GROUP, WORLD */
248 __u64 access; /* OWN, TALK, SEE */
249 __u64 id; /* uid, gid, 0 */
e735f4d4
MP
250} __attribute__((__aligned__(8)));
251
252/**
253 * enum kdbus_attach_flags - flags for metadata attachments
254 * @KDBUS_ATTACH_TIMESTAMP: Timestamp
255 * @KDBUS_ATTACH_CREDS: Credentials
256 * @KDBUS_ATTACH_PIDS: PIDs
257 * @KDBUS_ATTACH_AUXGROUPS: Auxiliary groups
258 * @KDBUS_ATTACH_NAMES: Well-known names
259 * @KDBUS_ATTACH_TID_COMM: The "comm" process identifier of the TID
260 * @KDBUS_ATTACH_PID_COMM: The "comm" process identifier of the PID
261 * @KDBUS_ATTACH_EXE: The path of the executable
262 * @KDBUS_ATTACH_CMDLINE: The process command line
263 * @KDBUS_ATTACH_CGROUP: The croup membership
264 * @KDBUS_ATTACH_CAPS: The process capabilities
265 * @KDBUS_ATTACH_SECLABEL: The security label
266 * @KDBUS_ATTACH_AUDIT: The audit IDs
267 * @KDBUS_ATTACH_CONN_DESCRIPTION: The human-readable connection name
268 * @_KDBUS_ATTACH_ALL: All of the above
269 * @_KDBUS_ATTACH_ANY: Wildcard match to enable any kind of
270 * metatdata.
271 */
272enum kdbus_attach_flags {
273 KDBUS_ATTACH_TIMESTAMP = 1ULL << 0,
274 KDBUS_ATTACH_CREDS = 1ULL << 1,
275 KDBUS_ATTACH_PIDS = 1ULL << 2,
276 KDBUS_ATTACH_AUXGROUPS = 1ULL << 3,
277 KDBUS_ATTACH_NAMES = 1ULL << 4,
278 KDBUS_ATTACH_TID_COMM = 1ULL << 5,
279 KDBUS_ATTACH_PID_COMM = 1ULL << 6,
280 KDBUS_ATTACH_EXE = 1ULL << 7,
281 KDBUS_ATTACH_CMDLINE = 1ULL << 8,
282 KDBUS_ATTACH_CGROUP = 1ULL << 9,
283 KDBUS_ATTACH_CAPS = 1ULL << 10,
284 KDBUS_ATTACH_SECLABEL = 1ULL << 11,
285 KDBUS_ATTACH_AUDIT = 1ULL << 12,
286 KDBUS_ATTACH_CONN_DESCRIPTION = 1ULL << 13,
287 _KDBUS_ATTACH_ALL = (1ULL << 14) - 1,
288 _KDBUS_ATTACH_ANY = ~0ULL
60f067b4
JS
289};
290
291/**
292 * enum kdbus_item_type - item types to chain data in a list
f47781d8
MP
293 * @_KDBUS_ITEM_NULL: Uninitialized/invalid
294 * @_KDBUS_ITEM_USER_BASE: Start of user items
e735f4d4 295 * @KDBUS_ITEM_NEGOTIATE: Negotiate supported items
f47781d8
MP
296 * @KDBUS_ITEM_PAYLOAD_VEC: Vector to data
297 * @KDBUS_ITEM_PAYLOAD_OFF: Data at returned offset to message head
298 * @KDBUS_ITEM_PAYLOAD_MEMFD: Data as sealed memfd
299 * @KDBUS_ITEM_FDS: Attached file descriptors
e735f4d4
MP
300 * @KDBUS_ITEM_CANCEL_FD: FD used to cancel a synchronous
301 * operation by writing to it from
302 * userspace
f47781d8
MP
303 * @KDBUS_ITEM_BLOOM_PARAMETER: Bus-wide bloom parameters, used with
304 * KDBUS_CMD_BUS_MAKE, carries a
305 * struct kdbus_bloom_parameter
306 * @KDBUS_ITEM_BLOOM_FILTER: Bloom filter carried with a message,
307 * used to match against a bloom mask of a
308 * connection, carries a struct
309 * kdbus_bloom_filter
310 * @KDBUS_ITEM_BLOOM_MASK: Bloom mask used to match against a
311 * message'sbloom filter
312 * @KDBUS_ITEM_DST_NAME: Destination's well-known name
313 * @KDBUS_ITEM_MAKE_NAME: Name of domain, bus, endpoint
314 * @KDBUS_ITEM_ATTACH_FLAGS_SEND: Attach-flags, used for updating which
315 * metadata a connection opts in to send
316 * @KDBUS_ITEM_ATTACH_FLAGS_RECV: Attach-flags, used for updating which
317 * metadata a connection requests to
318 * receive for each reeceived message
319 * @KDBUS_ITEM_ID: Connection ID
320 * @KDBUS_ITEM_NAME: Well-know name with flags
321 * @_KDBUS_ITEM_ATTACH_BASE: Start of metadata attach items
322 * @KDBUS_ITEM_TIMESTAMP: Timestamp
323 * @KDBUS_ITEM_CREDS: Process credentials
324 * @KDBUS_ITEM_PIDS: Process identifiers
325 * @KDBUS_ITEM_AUXGROUPS: Auxiliary process groups
326 * @KDBUS_ITEM_OWNED_NAME: A name owned by the associated
327 * connection
328 * @KDBUS_ITEM_TID_COMM: Thread ID "comm" identifier
329 * (Don't trust this, see below.)
330 * @KDBUS_ITEM_PID_COMM: Process ID "comm" identifier
331 * (Don't trust this, see below.)
332 * @KDBUS_ITEM_EXE: The path of the executable
333 * (Don't trust this, see below.)
334 * @KDBUS_ITEM_CMDLINE: The process command line
335 * (Don't trust this, see below.)
336 * @KDBUS_ITEM_CGROUP: The croup membership
337 * @KDBUS_ITEM_CAPS: The process capabilities
338 * @KDBUS_ITEM_SECLABEL: The security label
339 * @KDBUS_ITEM_AUDIT: The audit IDs
340 * @KDBUS_ITEM_CONN_DESCRIPTION: The connection's human-readable name
341 * (debugging)
342 * @_KDBUS_ITEM_POLICY_BASE: Start of policy items
343 * @KDBUS_ITEM_POLICY_ACCESS: Policy access block
344 * @_KDBUS_ITEM_KERNEL_BASE: Start of kernel-generated message items
345 * @KDBUS_ITEM_NAME_ADD: Notification in kdbus_notify_name_change
346 * @KDBUS_ITEM_NAME_REMOVE: Notification in kdbus_notify_name_change
347 * @KDBUS_ITEM_NAME_CHANGE: Notification in kdbus_notify_name_change
348 * @KDBUS_ITEM_ID_ADD: Notification in kdbus_notify_id_change
349 * @KDBUS_ITEM_ID_REMOVE: Notification in kdbus_notify_id_change
350 * @KDBUS_ITEM_REPLY_TIMEOUT: Timeout has been reached
351 * @KDBUS_ITEM_REPLY_DEAD: Destination died
352 *
353 * N.B: The process and thread COMM fields, as well as the CMDLINE and
354 * EXE fields may be altered by unprivileged processes und should
355 * hence *not* used for security decisions. Peers should make use of
356 * these items only for informational purposes, such as generating log
357 * records.
60f067b4
JS
358 */
359enum kdbus_item_type {
360 _KDBUS_ITEM_NULL,
361 _KDBUS_ITEM_USER_BASE,
e735f4d4
MP
362 KDBUS_ITEM_NEGOTIATE = _KDBUS_ITEM_USER_BASE,
363 KDBUS_ITEM_PAYLOAD_VEC,
60f067b4
JS
364 KDBUS_ITEM_PAYLOAD_OFF,
365 KDBUS_ITEM_PAYLOAD_MEMFD,
366 KDBUS_ITEM_FDS,
e735f4d4 367 KDBUS_ITEM_CANCEL_FD,
60f067b4
JS
368 KDBUS_ITEM_BLOOM_PARAMETER,
369 KDBUS_ITEM_BLOOM_FILTER,
370 KDBUS_ITEM_BLOOM_MASK,
371 KDBUS_ITEM_DST_NAME,
372 KDBUS_ITEM_MAKE_NAME,
f47781d8
MP
373 KDBUS_ITEM_ATTACH_FLAGS_SEND,
374 KDBUS_ITEM_ATTACH_FLAGS_RECV,
375 KDBUS_ITEM_ID,
376 KDBUS_ITEM_NAME,
60f067b4 377
f47781d8 378 /* keep these item types in sync with KDBUS_ATTACH_* flags */
60f067b4 379 _KDBUS_ITEM_ATTACH_BASE = 0x1000,
f47781d8 380 KDBUS_ITEM_TIMESTAMP = _KDBUS_ITEM_ATTACH_BASE,
60f067b4 381 KDBUS_ITEM_CREDS,
f47781d8 382 KDBUS_ITEM_PIDS,
5eef597e 383 KDBUS_ITEM_AUXGROUPS,
f47781d8 384 KDBUS_ITEM_OWNED_NAME,
60f067b4 385 KDBUS_ITEM_TID_COMM,
f47781d8 386 KDBUS_ITEM_PID_COMM,
60f067b4
JS
387 KDBUS_ITEM_EXE,
388 KDBUS_ITEM_CMDLINE,
389 KDBUS_ITEM_CGROUP,
390 KDBUS_ITEM_CAPS,
391 KDBUS_ITEM_SECLABEL,
392 KDBUS_ITEM_AUDIT,
f47781d8 393 KDBUS_ITEM_CONN_DESCRIPTION,
60f067b4
JS
394
395 _KDBUS_ITEM_POLICY_BASE = 0x2000,
396 KDBUS_ITEM_POLICY_ACCESS = _KDBUS_ITEM_POLICY_BASE,
397
398 _KDBUS_ITEM_KERNEL_BASE = 0x8000,
399 KDBUS_ITEM_NAME_ADD = _KDBUS_ITEM_KERNEL_BASE,
400 KDBUS_ITEM_NAME_REMOVE,
401 KDBUS_ITEM_NAME_CHANGE,
402 KDBUS_ITEM_ID_ADD,
403 KDBUS_ITEM_ID_REMOVE,
404 KDBUS_ITEM_REPLY_TIMEOUT,
405 KDBUS_ITEM_REPLY_DEAD,
406};
407
408/**
409 * struct kdbus_item - chain of data blocks
410 * @size: Overall data record size
411 * @type: Kdbus_item type of data
412 * @data: Generic bytes
413 * @data32: Generic 32 bit array
414 * @data64: Generic 64 bit array
415 * @str: Generic string
416 * @id: Connection ID
417 * @vec: KDBUS_ITEM_PAYLOAD_VEC
418 * @creds: KDBUS_ITEM_CREDS
419 * @audit: KDBUS_ITEM_AUDIT
420 * @timestamp: KDBUS_ITEM_TIMESTAMP
421 * @name: KDBUS_ITEM_NAME
422 * @bloom_parameter: KDBUS_ITEM_BLOOM_PARAMETER
423 * @bloom_filter: KDBUS_ITEM_BLOOM_FILTER
424 * @memfd: KDBUS_ITEM_PAYLOAD_MEMFD
425 * @name_change: KDBUS_ITEM_NAME_ADD
426 * KDBUS_ITEM_NAME_REMOVE
427 * KDBUS_ITEM_NAME_CHANGE
428 * @id_change: KDBUS_ITEM_ID_ADD
429 * KDBUS_ITEM_ID_REMOVE
430 * @policy: KDBUS_ITEM_POLICY_ACCESS
431 */
432struct kdbus_item {
433 __u64 size;
434 __u64 type;
435 union {
436 __u8 data[0];
437 __u32 data32[0];
438 __u64 data64[0];
439 char str[0];
440
441 __u64 id;
442 struct kdbus_vec vec;
443 struct kdbus_creds creds;
f47781d8 444 struct kdbus_pids pids;
60f067b4 445 struct kdbus_audit audit;
5eef597e 446 struct kdbus_caps caps;
60f067b4
JS
447 struct kdbus_timestamp timestamp;
448 struct kdbus_name name;
449 struct kdbus_bloom_parameter bloom_parameter;
450 struct kdbus_bloom_filter bloom_filter;
451 struct kdbus_memfd memfd;
452 int fds[0];
453 struct kdbus_notify_name_change name_change;
454 struct kdbus_notify_id_change id_change;
455 struct kdbus_policy_access policy_access;
456 };
e735f4d4
MP
457} __attribute__((__aligned__(8)));
458
60f067b4
JS
459/**
460 * enum kdbus_msg_flags - type of message
e735f4d4
MP
461 * @KDBUS_MSG_EXPECT_REPLY: Expect a reply message, used for
462 * method calls. The userspace-supplied
463 * cookie identifies the message and the
464 * respective reply carries the cookie
465 * in cookie_reply
e3bff60a
MP
466 * @KDBUS_MSG_NO_AUTO_START: Do not start a service if the addressed
467 * name is not currently active. This flag is
468 * not looked at by the kernel but only
469 * serves as hint for userspace implementations.
e735f4d4 470 * @KDBUS_MSG_SIGNAL: Treat this message as signal
60f067b4
JS
471 */
472enum kdbus_msg_flags {
e735f4d4
MP
473 KDBUS_MSG_EXPECT_REPLY = 1ULL << 0,
474 KDBUS_MSG_NO_AUTO_START = 1ULL << 1,
475 KDBUS_MSG_SIGNAL = 1ULL << 2,
60f067b4
JS
476};
477
478/**
479 * enum kdbus_payload_type - type of payload carried by message
480 * @KDBUS_PAYLOAD_KERNEL: Kernel-generated simple message
481 * @KDBUS_PAYLOAD_DBUS: D-Bus marshalling "DBusDBus"
e735f4d4
MP
482 *
483 * Any payload-type is accepted. Common types will get added here once
484 * established.
60f067b4
JS
485 */
486enum kdbus_payload_type {
487 KDBUS_PAYLOAD_KERNEL,
488 KDBUS_PAYLOAD_DBUS = 0x4442757344427573ULL,
489};
490
491/**
492 * struct kdbus_msg - the representation of a kdbus message
493 * @size: Total size of the message
e735f4d4 494 * @flags: Message flags (KDBUS_MSG_*), userspace → kernel
60f067b4
JS
495 * @priority: Message queue priority value
496 * @dst_id: 64-bit ID of the destination connection
497 * @src_id: 64-bit ID of the source connection
498 * @payload_type: Payload type (KDBUS_PAYLOAD_*)
499 * @cookie: Userspace-supplied cookie, for the connection
500 * to identify its messages
501 * @timeout_ns: The time to wait for a message reply from the peer.
e3bff60a
MP
502 * If there is no reply, and the send command is
503 * executed asynchronously, a kernel-generated message
60f067b4 504 * with an attached KDBUS_ITEM_REPLY_TIMEOUT item
e3bff60a
MP
505 * is sent to @src_id. For synchronously executed send
506 * command, the value denotes the maximum time the call
507 * blocks to wait for a reply. The timeout is expected in
5eef597e 508 * nanoseconds and as absolute CLOCK_MONOTONIC value.
60f067b4
JS
509 * @cookie_reply: A reply to the requesting message with the same
510 * cookie. The requesting connection can match its
511 * request and the reply with this value
60f067b4
JS
512 * @items: A list of kdbus_items containing the message payload
513 */
514struct kdbus_msg {
515 __u64 size;
516 __u64 flags;
517 __s64 priority;
518 __u64 dst_id;
519 __u64 src_id;
520 __u64 payload_type;
521 __u64 cookie;
522 union {
523 __u64 timeout_ns;
524 __u64 cookie_reply;
60f067b4
JS
525 };
526 struct kdbus_item items[0];
e735f4d4
MP
527} __attribute__((__aligned__(8)));
528
529/**
530 * struct kdbus_msg_info - returned message container
531 * @offset: Offset of kdbus_msg slice in pool
532 * @msg_size: Copy of the kdbus_msg.size field
533 * @return_flags: Command return flags, kernel → userspace
534 */
535struct kdbus_msg_info {
536 __u64 offset;
537 __u64 msg_size;
538 __u64 return_flags;
539} __attribute__((__aligned__(8)));
540
541/**
542 * enum kdbus_send_flags - flags for sending messages
543 * @KDBUS_SEND_SYNC_REPLY: Wait for destination connection to
544 * reply to this message. The
545 * KDBUS_CMD_SEND ioctl() will block
546 * until the reply is received, and
547 * offset_reply in struct kdbus_msg will
548 * yield the offset in the sender's pool
549 * where the reply can be found.
550 * This flag is only valid if
551 * @KDBUS_MSG_EXPECT_REPLY is set as well.
552 */
553enum kdbus_send_flags {
554 KDBUS_SEND_SYNC_REPLY = 1ULL << 0,
555};
556
557/**
558 * struct kdbus_cmd_send - send message
559 * @size: Overall size of this structure
560 * @flags: Flags to change send behavior (KDBUS_SEND_*)
561 * @return_flags: Command return flags, kernel → userspace
562 * @msg_address: Storage address of the kdbus_msg to send
563 * @reply: Storage for message reply if KDBUS_SEND_SYNC_REPLY
564 * was given
565 * @items: Additional items for this command
566 */
567struct kdbus_cmd_send {
568 __u64 size;
569 __u64 flags;
570 __u64 return_flags;
571 __u64 msg_address;
572 struct kdbus_msg_info reply;
573 struct kdbus_item items[0];
574} __attribute__((__aligned__(8)));
60f067b4
JS
575
576/**
577 * enum kdbus_recv_flags - flags for de-queuing messages
578 * @KDBUS_RECV_PEEK: Return the next queued message without
579 * actually de-queuing it, and without installing
580 * any file descriptors or other resources. It is
581 * usually used to determine the activating
582 * connection of a bus name.
583 * @KDBUS_RECV_DROP: Drop and free the next queued message and all
584 * its resources without actually receiving it.
585 * @KDBUS_RECV_USE_PRIORITY: Only de-queue messages with the specified or
586 * higher priority (lowest values); if not set,
587 * the priority value is ignored.
588 */
589enum kdbus_recv_flags {
5eef597e
MP
590 KDBUS_RECV_PEEK = 1ULL << 0,
591 KDBUS_RECV_DROP = 1ULL << 1,
592 KDBUS_RECV_USE_PRIORITY = 1ULL << 2,
60f067b4
JS
593};
594
e735f4d4
MP
595/**
596 * enum kdbus_recv_return_flags - return flags for message receive commands
597 * @KDBUS_RECV_RETURN_INCOMPLETE_FDS: One or more file descriptors could not
598 * be installed. These descriptors in
599 * KDBUS_ITEM_FDS will carry the value -1.
e3bff60a
MP
600 * @KDBUS_RECV_RETURN_DROPPED_MSGS: There have been dropped messages since
601 * the last time a message was received.
602 * The 'dropped_msgs' counter contains the
603 * number of messages dropped pool
604 * overflows or other missed broadcasts.
e735f4d4
MP
605 */
606enum kdbus_recv_return_flags {
607 KDBUS_RECV_RETURN_INCOMPLETE_FDS = 1ULL << 0,
e3bff60a 608 KDBUS_RECV_RETURN_DROPPED_MSGS = 1ULL << 1,
e735f4d4
MP
609};
610
60f067b4
JS
611/**
612 * struct kdbus_cmd_recv - struct to de-queue a buffered message
e735f4d4 613 * @size: Overall size of this object
5eef597e 614 * @flags: KDBUS_RECV_* flags, userspace → kernel
e735f4d4 615 * @return_flags: Command return flags, kernel → userspace
60f067b4
JS
616 * @priority: Minimum priority of the messages to de-queue. Lowest
617 * values have the highest priority.
e3bff60a
MP
618 * @dropped_msgs: In case there were any dropped messages since the last
619 * time a message was received, this will be set to the
620 * number of lost messages and
621 * KDBUS_RECV_RETURN_DROPPED_MSGS will be set in
622 * 'return_flags'. This can only happen if the ioctl
623 * returns 0 or EAGAIN.
e735f4d4
MP
624 * @msg: Return storage for received message.
625 * @items: Additional items for this command.
60f067b4 626 *
e735f4d4 627 * This struct is used with the KDBUS_CMD_RECV ioctl.
60f067b4
JS
628 */
629struct kdbus_cmd_recv {
e735f4d4 630 __u64 size;
60f067b4 631 __u64 flags;
e735f4d4 632 __u64 return_flags;
60f067b4 633 __s64 priority;
e735f4d4
MP
634 __u64 dropped_msgs;
635 struct kdbus_msg_info msg;
636 struct kdbus_item items[0];
637} __attribute__((__aligned__(8)));
5eef597e
MP
638
639/**
640 * struct kdbus_cmd_free - struct to free a slice of memory in the pool
e735f4d4
MP
641 * @size: Overall size of this structure
642 * @flags: Flags for the free command, userspace → kernel
643 * @return_flags: Command return flags, kernel → userspace
5eef597e
MP
644 * @offset: The offset of the memory slice, as returned by other
645 * ioctls
e735f4d4 646 * @items: Additional items to modify the behavior
5eef597e
MP
647 *
648 * This struct is used with the KDBUS_CMD_FREE ioctl.
649 */
650struct kdbus_cmd_free {
e735f4d4 651 __u64 size;
5eef597e 652 __u64 flags;
e735f4d4
MP
653 __u64 return_flags;
654 __u64 offset;
655 struct kdbus_item items[0];
656} __attribute__((__aligned__(8)));
60f067b4
JS
657
658/**
659 * enum kdbus_hello_flags - flags for struct kdbus_cmd_hello
5eef597e 660 * @KDBUS_HELLO_ACCEPT_FD: The connection allows the reception of
60f067b4
JS
661 * any passed file descriptors
662 * @KDBUS_HELLO_ACTIVATOR: Special-purpose connection which registers
663 * a well-know name for a process to be started
664 * when traffic arrives
665 * @KDBUS_HELLO_POLICY_HOLDER: Special-purpose connection which registers
5eef597e
MP
666 * policy entries for a name. The provided name
667 * is not activated and not registered with the
668 * name database, it only allows unprivileged
e735f4d4 669 * connections to acquire a name, talk or discover
5eef597e 670 * a service
60f067b4
JS
671 * @KDBUS_HELLO_MONITOR: Special-purpose connection to monitor
672 * bus traffic
673 */
674enum kdbus_hello_flags {
5eef597e
MP
675 KDBUS_HELLO_ACCEPT_FD = 1ULL << 0,
676 KDBUS_HELLO_ACTIVATOR = 1ULL << 1,
677 KDBUS_HELLO_POLICY_HOLDER = 1ULL << 2,
678 KDBUS_HELLO_MONITOR = 1ULL << 3,
60f067b4
JS
679};
680
681/**
682 * struct kdbus_cmd_hello - struct to say hello to kdbus
683 * @size: The total size of the structure
5eef597e 684 * @flags: Connection flags (KDBUS_HELLO_*), userspace → kernel
e735f4d4 685 * @return_flags: Command return flags, kernel → userspace
f47781d8
MP
686 * @attach_flags_send: Mask of metadata to attach to each message sent
687 * off by this connection (KDBUS_ATTACH_*)
688 * @attach_flags_recv: Mask of metadata to attach to each message receieved
689 * by the new connection (KDBUS_ATTACH_*)
60f067b4
JS
690 * @bus_flags: The flags field copied verbatim from the original
691 * KDBUS_CMD_BUS_MAKE ioctl. It's intended to be useful
692 * to do negotiation of features of the payload that is
693 * transferred (kernel → userspace)
694 * @id: The ID of this connection (kernel → userspace)
695 * @pool_size: Size of the connection's buffer where the received
696 * messages are placed
e3bff60a
MP
697 * @offset: Pool offset where items are returned to report
698 * additional information about the bus and the newly
699 * created connection.
700 * @items_size: Size of buffer returned in the pool slice at @offset.
60f067b4
JS
701 * @id128: Unique 128-bit ID of the bus (kernel → userspace)
702 * @items: A list of items
703 *
704 * This struct is used with the KDBUS_CMD_HELLO ioctl.
705 */
706struct kdbus_cmd_hello {
707 __u64 size;
5eef597e 708 __u64 flags;
e735f4d4 709 __u64 return_flags;
f47781d8
MP
710 __u64 attach_flags_send;
711 __u64 attach_flags_recv;
60f067b4
JS
712 __u64 bus_flags;
713 __u64 id;
714 __u64 pool_size;
e735f4d4
MP
715 __u64 offset;
716 __u64 items_size;
60f067b4
JS
717 __u8 id128[16];
718 struct kdbus_item items[0];
e735f4d4 719} __attribute__((__aligned__(8)));
60f067b4
JS
720
721/**
e735f4d4
MP
722 * struct kdbus_info - connection information
723 * @size: total size of the struct
724 * @id: 64bit object ID
725 * @flags: object creation flags
726 * @items: list of items
60f067b4 727 *
e735f4d4
MP
728 * Note that the user is responsible for freeing the allocated memory with
729 * the KDBUS_CMD_FREE ioctl.
60f067b4 730 */
e735f4d4 731struct kdbus_info {
60f067b4 732 __u64 size;
e735f4d4 733 __u64 id;
60f067b4 734 __u64 flags;
5eef597e 735 struct kdbus_item items[0];
e735f4d4 736} __attribute__((__aligned__(8)));
5eef597e
MP
737
738/**
e735f4d4
MP
739 * enum kdbus_list_flags - what to include into the returned list
740 * @KDBUS_LIST_UNIQUE: active connections
741 * @KDBUS_LIST_ACTIVATORS: activator connections
742 * @KDBUS_LIST_NAMES: known well-known names
743 * @KDBUS_LIST_QUEUED: queued-up names
5eef597e 744 */
e735f4d4
MP
745enum kdbus_list_flags {
746 KDBUS_LIST_UNIQUE = 1ULL << 0,
747 KDBUS_LIST_NAMES = 1ULL << 1,
748 KDBUS_LIST_ACTIVATORS = 1ULL << 2,
749 KDBUS_LIST_QUEUED = 1ULL << 3,
60f067b4
JS
750};
751
752/**
e735f4d4
MP
753 * struct kdbus_cmd_list - list connections
754 * @size: overall size of this object
755 * @flags: flags for the query (KDBUS_LIST_*), userspace → kernel
756 * @return_flags: command return flags, kernel → userspace
757 * @offset: Offset in the caller's pool buffer where an array of
758 * kdbus_info objects is stored.
60f067b4
JS
759 * The user must use KDBUS_CMD_FREE to free the
760 * allocated memory.
e735f4d4
MP
761 * @list_size: size of returned list in bytes
762 * @items: Items for the command. Reserved for future use.
60f067b4 763 *
e735f4d4 764 * This structure is used with the KDBUS_CMD_LIST ioctl.
60f067b4 765 */
e735f4d4
MP
766struct kdbus_cmd_list {
767 __u64 size;
60f067b4 768 __u64 flags;
e735f4d4 769 __u64 return_flags;
60f067b4 770 __u64 offset;
e735f4d4
MP
771 __u64 list_size;
772 struct kdbus_item items[0];
773} __attribute__((__aligned__(8)));
60f067b4
JS
774
775/**
5eef597e 776 * struct kdbus_cmd_info - struct used for KDBUS_CMD_CONN_INFO ioctl
60f067b4 777 * @size: The total size of the struct
e3bff60a 778 * @flags: Flags for this ioctl, userspace → kernel
e735f4d4 779 * @return_flags: Command return flags, kernel → userspace
60f067b4
JS
780 * @id: The 64-bit ID of the connection. If set to zero, passing
781 * @name is required. kdbus will look up the name to
782 * determine the ID in this case.
e3bff60a
MP
783 * @attach_flags: Set of attach flags to specify the set of information
784 * to receive, userspace → kernel
60f067b4 785 * @offset: Returned offset in the caller's pool buffer where the
5eef597e 786 * kdbus_info struct result is stored. The user must
60f067b4 787 * use KDBUS_CMD_FREE to free the allocated memory.
f47781d8 788 * @info_size: Output buffer to report size of data at @offset.
5eef597e
MP
789 * @items: The optional item list, containing the
790 * well-known name to look up as a KDBUS_ITEM_NAME.
791 * Only needed in case @id is zero.
60f067b4
JS
792 *
793 * On success, the KDBUS_CMD_CONN_INFO ioctl will return 0 and @offset will
794 * tell the user the offset in the connection pool buffer at which to find the
5eef597e 795 * result in a struct kdbus_info.
60f067b4 796 */
5eef597e 797struct kdbus_cmd_info {
60f067b4
JS
798 __u64 size;
799 __u64 flags;
e735f4d4 800 __u64 return_flags;
60f067b4 801 __u64 id;
e3bff60a 802 __u64 attach_flags;
60f067b4 803 __u64 offset;
f47781d8 804 __u64 info_size;
5eef597e 805 struct kdbus_item items[0];
e735f4d4 806} __attribute__((__aligned__(8)));
60f067b4 807
5eef597e
MP
808/**
809 * enum kdbus_cmd_match_flags - flags to control the KDBUS_CMD_MATCH_ADD ioctl
810 * @KDBUS_MATCH_REPLACE: If entries with the supplied cookie already
811 * exists, remove them before installing the new
812 * matches.
813 */
814enum kdbus_cmd_match_flags {
815 KDBUS_MATCH_REPLACE = 1ULL << 0,
816};
817
60f067b4
JS
818/**
819 * struct kdbus_cmd_match - struct to add or remove matches
820 * @size: The total size of the struct
5eef597e
MP
821 * @flags: Flags for match command (KDBUS_MATCH_*),
822 * userspace → kernel
e735f4d4
MP
823 * @return_flags: Command return flags, kernel → userspace
824 * @cookie: Userspace supplied cookie. When removing, the cookie
825 * identifies the match to remove
60f067b4
JS
826 * @items: A list of items for additional information
827 *
5eef597e
MP
828 * This structure is used with the KDBUS_CMD_MATCH_ADD and
829 * KDBUS_CMD_MATCH_REMOVE ioctl.
60f067b4
JS
830 */
831struct kdbus_cmd_match {
832 __u64 size;
e735f4d4
MP
833 __u64 flags;
834 __u64 return_flags;
60f067b4 835 __u64 cookie;
e735f4d4
MP
836 struct kdbus_item items[0];
837} __attribute__((__aligned__(8)));
838
839/**
840 * enum kdbus_make_flags - Flags for KDBUS_CMD_{BUS,ENDPOINT}_MAKE
841 * @KDBUS_MAKE_ACCESS_GROUP: Make the bus or endpoint node group-accessible
842 * @KDBUS_MAKE_ACCESS_WORLD: Make the bus or endpoint node world-accessible
843 */
844enum kdbus_make_flags {
845 KDBUS_MAKE_ACCESS_GROUP = 1ULL << 0,
846 KDBUS_MAKE_ACCESS_WORLD = 1ULL << 1,
847};
848
849/**
850 * enum kdbus_name_flags - flags for KDBUS_CMD_NAME_ACQUIRE
851 * @KDBUS_NAME_REPLACE_EXISTING: Try to replace name of other connections
852 * @KDBUS_NAME_ALLOW_REPLACEMENT: Allow the replacement of the name
853 * @KDBUS_NAME_QUEUE: Name should be queued if busy
854 * @KDBUS_NAME_IN_QUEUE: Name is queued
855 * @KDBUS_NAME_ACTIVATOR: Name is owned by a activator connection
856 */
857enum kdbus_name_flags {
858 KDBUS_NAME_REPLACE_EXISTING = 1ULL << 0,
859 KDBUS_NAME_ALLOW_REPLACEMENT = 1ULL << 1,
860 KDBUS_NAME_QUEUE = 1ULL << 2,
861 KDBUS_NAME_IN_QUEUE = 1ULL << 3,
862 KDBUS_NAME_ACTIVATOR = 1ULL << 4,
863};
864
865/**
866 * struct kdbus_cmd - generic ioctl payload
867 * @size: Overall size of this structure
868 * @flags: Flags for this ioctl, userspace → kernel
869 * @return_flags: Ioctl return flags, kernel → userspace
870 * @items: Additional items to modify the behavior
871 *
872 * This is a generic ioctl payload object. It's used by all ioctls that only
873 * take flags and items as input.
874 */
875struct kdbus_cmd {
876 __u64 size;
5eef597e 877 __u64 flags;
e735f4d4 878 __u64 return_flags;
60f067b4 879 struct kdbus_item items[0];
e735f4d4 880} __attribute__((__aligned__(8)));
60f067b4
JS
881
882/**
f47781d8 883 * Ioctl API
e735f4d4 884 *
f47781d8
MP
885 * KDBUS_CMD_BUS_MAKE: After opening the "control" node, this command
886 * creates a new bus with the specified
60f067b4 887 * name. The bus is immediately shut down and
f47781d8
MP
888 * cleaned up when the opened file descriptor is
889 * closed.
e735f4d4 890 *
f47781d8 891 * KDBUS_CMD_ENDPOINT_MAKE: Creates a new named special endpoint to talk to
60f067b4
JS
892 * the bus. Such endpoints usually carry a more
893 * restrictive policy and grant restricted access
894 * to specific applications.
e735f4d4
MP
895 * KDBUS_CMD_ENDPOINT_UPDATE: Update the properties of a custom enpoint. Used
896 * to update the policy.
897 *
f47781d8 898 * KDBUS_CMD_HELLO: By opening the bus node, a connection is
60f067b4
JS
899 * created. After a HELLO the opened connection
900 * becomes an active peer on the bus.
e735f4d4
MP
901 * KDBUS_CMD_UPDATE: Update the properties of a connection. Used to
902 * update the metadata subscription mask and
903 * policy.
f47781d8 904 * KDBUS_CMD_BYEBYE: Disconnect a connection. If there are no
5eef597e
MP
905 * messages queued up in the connection's pool,
906 * the call succeeds, and the handle is rendered
907 * unusable. Otherwise, -EBUSY is returned without
908 * any further side-effects.
f47781d8 909 * KDBUS_CMD_FREE: Release the allocated memory in the receiver's
60f067b4 910 * pool.
f47781d8 911 * KDBUS_CMD_CONN_INFO: Retrieve credentials and properties of the
60f067b4
JS
912 * initial creator of the connection. The data was
913 * stored at registration time and does not
914 * necessarily represent the connected process or
915 * the actual state of the process.
f47781d8 916 * KDBUS_CMD_BUS_CREATOR_INFO: Retrieve information of the creator of the bus
5eef597e 917 * a connection is attached to.
e735f4d4
MP
918 *
919 * KDBUS_CMD_SEND: Send a message and pass data from userspace to
920 * the kernel.
921 * KDBUS_CMD_RECV: Receive a message from the kernel which is
922 * placed in the receiver's pool.
923 *
924 * KDBUS_CMD_NAME_ACQUIRE: Request a well-known bus name to associate with
925 * the connection. Well-known names are used to
926 * address a peer on the bus.
927 * KDBUS_CMD_NAME_RELEASE: Release a well-known name the connection
928 * currently owns.
929 * KDBUS_CMD_LIST: Retrieve the list of all currently registered
930 * well-known and unique names.
931 *
932 * KDBUS_CMD_MATCH_ADD: Install a match which broadcast messages should
60f067b4 933 * be delivered to the connection.
f47781d8
MP
934 * KDBUS_CMD_MATCH_REMOVE: Remove a current match for broadcast messages.
935 */
e735f4d4
MP
936enum kdbus_ioctl_type {
937 /* bus owner (00-0f) */
938 KDBUS_CMD_BUS_MAKE = _IOW(KDBUS_IOCTL_MAGIC, 0x00,
939 struct kdbus_cmd),
940
941 /* endpoint owner (10-1f) */
942 KDBUS_CMD_ENDPOINT_MAKE = _IOW(KDBUS_IOCTL_MAGIC, 0x10,
943 struct kdbus_cmd),
944 KDBUS_CMD_ENDPOINT_UPDATE = _IOW(KDBUS_IOCTL_MAGIC, 0x11,
945 struct kdbus_cmd),
946
947 /* connection owner (80-ff) */
948 KDBUS_CMD_HELLO = _IOWR(KDBUS_IOCTL_MAGIC, 0x80,
949 struct kdbus_cmd_hello),
950 KDBUS_CMD_UPDATE = _IOW(KDBUS_IOCTL_MAGIC, 0x81,
951 struct kdbus_cmd),
952 KDBUS_CMD_BYEBYE = _IOW(KDBUS_IOCTL_MAGIC, 0x82,
953 struct kdbus_cmd),
954 KDBUS_CMD_FREE = _IOW(KDBUS_IOCTL_MAGIC, 0x83,
955 struct kdbus_cmd_free),
956 KDBUS_CMD_CONN_INFO = _IOR(KDBUS_IOCTL_MAGIC, 0x84,
957 struct kdbus_cmd_info),
958 KDBUS_CMD_BUS_CREATOR_INFO = _IOR(KDBUS_IOCTL_MAGIC, 0x85,
959 struct kdbus_cmd_info),
960 KDBUS_CMD_LIST = _IOR(KDBUS_IOCTL_MAGIC, 0x86,
961 struct kdbus_cmd_list),
962
963 KDBUS_CMD_SEND = _IOW(KDBUS_IOCTL_MAGIC, 0x90,
964 struct kdbus_cmd_send),
965 KDBUS_CMD_RECV = _IOR(KDBUS_IOCTL_MAGIC, 0x91,
966 struct kdbus_cmd_recv),
967
968 KDBUS_CMD_NAME_ACQUIRE = _IOW(KDBUS_IOCTL_MAGIC, 0xa0,
969 struct kdbus_cmd),
970 KDBUS_CMD_NAME_RELEASE = _IOW(KDBUS_IOCTL_MAGIC, 0xa1,
971 struct kdbus_cmd),
972
973 KDBUS_CMD_MATCH_ADD = _IOW(KDBUS_IOCTL_MAGIC, 0xb0,
974 struct kdbus_cmd_match),
975 KDBUS_CMD_MATCH_REMOVE = _IOW(KDBUS_IOCTL_MAGIC, 0xb1,
976 struct kdbus_cmd_match),
977};
60f067b4 978
5eef597e 979#endif /* _KDBUS_UAPI_H_ */