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