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