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