chiark / gitweb /
sd-bus: sync kdbus.h (ABI break)
[elogind.git] / src / libsystemd / sd-bus / kdbus.h
1 /*
2  * Copyright (C) 2013 Kay Sievers
3  * Copyright (C) 2013 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
4  * Copyright (C) 2013 Linux Foundation
5  * Copyright (C) 2013 Lennart Poettering
6  * Copyright (C) 2013 Daniel Mack <daniel@zonque.org>
7  *
8  * kdbus is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU Lesser General Public License as published by the
10  * Free Software Foundation; either version 2.1 of the License, or (at
11  * your option) any later version.
12  *
13  * "Everything should be made as simple as possible, but not simpler."
14  *   -- Albert Einstein
15  */
16
17 #ifndef _KDBUS_H_
18 #define _KDBUS_H_
19
20 #ifndef __KERNEL__
21 #include <sys/ioctl.h>
22 #include <sys/types.h>
23 #include <linux/types.h>
24 #endif
25
26 #define KDBUS_IOC_MAGIC                 0x95
27 #define KDBUS_SRC_ID_KERNEL             (0)
28 #define KDBUS_DST_ID_NAME               (0)
29 #define KDBUS_MATCH_ID_ANY              (~0ULL)
30 #define KDBUS_DST_ID_BROADCAST          (~0ULL)
31
32 /**
33  * struct kdbus_notify_id_change - name registry change message
34  * @id:                 New or former owner of the name
35  * @flags:              flags field from KDBUS_HELLO_*
36  *
37  * Sent from kernel to userspace when the owner or activator of
38  * a well-known name changes.
39  *
40  * Attached to:
41  *   KDBUS_ITEM_ID_ADD
42  *   KDBUS_ITEM_ID_REMOVE
43  */
44 struct kdbus_notify_id_change {
45         __u64 id;
46         __u64 flags;
47 };
48
49 /**
50  * struct kdbus_notify_name_change - name registry change message
51  * @old:                ID and flags of former owner of a name
52  * @new:                ID and flags of new owner of a name
53  * @name:               Well-known name
54  *
55  * Sent from kernel to userspace when the owner or activator of
56  * a well-known name changes.
57  *
58  * Attached to:
59  *   KDBUS_ITEM_NAME_ADD
60  *   KDBUS_ITEM_NAME_REMOVE
61  *   KDBUS_ITEM_NAME_CHANGE
62  */
63 struct kdbus_notify_name_change {
64         struct kdbus_notify_id_change old;
65         struct kdbus_notify_id_change new;
66         char name[0];
67 };
68
69 /**
70  * struct kdbus_creds - process credentials
71  * @uid:                User ID
72  * @gid:                Group ID
73  * @pid:                Process ID
74  * @tid:                Thread ID
75  * @starttime:          Starttime of the process
76  *
77  * The starttime of the process PID. This is useful to detect PID overruns
78  * from the client side. i.e. if you use the PID to look something up in
79  * /proc/$PID/ you can afterwards check the starttime field of it, to ensure
80  * you didn't run into a PID overrun.
81  *
82  * Attached to:
83  *   KDBUS_ITEM_CREDS
84  */
85 struct kdbus_creds {
86         __u64 uid;
87         __u64 gid;
88         __u64 pid;
89         __u64 tid;
90         __u64 starttime;
91 };
92
93 /**
94  * struct kdbus_audit - audit information
95  * @sessionid:          The audit session ID
96  * @loginuid:           The audit login uid
97  *
98  * Attached to:
99  *   KDBUS_ITEM_AUDIT
100  */
101 struct kdbus_audit {
102         __u64 sessionid;
103         __u64 loginuid;
104 };
105
106 /**
107  * struct kdbus_timestamp
108  * @seqnum:             Global per-domain message sequence number
109  * @monotonic_ns:       Monotonic timestamp, in nanoseconds
110  * @realtime_ns:        Realtime timestamp, in nanoseconds
111  *
112  * Attached to:
113  *   KDBUS_ITEM_TIMESTAMP
114  */
115 struct kdbus_timestamp {
116         __u64 seqnum;
117         __u64 monotonic_ns;
118         __u64 realtime_ns;
119 };
120
121 /**
122  * struct kdbus_vec - I/O vector for kdbus payload items
123  * @size:               The size of the vector
124  * @address:            Memory address for memory addresses
125  * @offset:             Offset in the in-message payload memory,
126  *                      relative to the message head
127  *
128  * Attached to:
129  *   KDBUS_ITEM_PAYLOAD_VEC
130  */
131 struct kdbus_vec {
132         __u64 size;
133         union {
134                 __u64 address;
135                 __u64 offset;
136         };
137 };
138
139 /**
140  * struct kdbus_bloom_parameter - bus-wide bloom parameters
141  * @size:               Size of the bit field in bytes (m / 8)
142  * @n_hash:             Number of hash functions used (k)
143  */
144 struct kdbus_bloom_parameter {
145         __u64 size;
146         __u64 n_hash;
147 };
148
149 /**
150  * struct kdbus_bloom_filter - bloom filter containing n elements
151  * @generation:         Generation of the element set in the filter
152  * @data:               Bit field, multiple of 8 bytes
153  */
154 struct kdbus_bloom_filter {
155         __u64 generation;
156         __u64 data[0];
157 };
158
159 /**
160  * struct kdbus_memfd - a kdbus memfd
161  * @size:               The memfd's size
162  * @fd:                 The file descriptor number
163  * @__pad:              Padding to ensure proper alignement and size
164  *
165  * Attached to:
166  *   KDBUS_ITEM_PAYLOAD_MEMFD
167  */
168 struct kdbus_memfd {
169         __u64 size;
170         int fd;
171         __u32 __pad;
172 };
173
174 /**
175  * struct kdbus_name - a registered well-known name with its flags
176  * @flags:              flags from KDBUS_NAME_*
177  * @name:               well-known name
178  *
179  * Attached to:
180  *   KDBUS_ITEM_NAME
181  */
182 struct kdbus_name {
183         __u64 flags;
184         char name[0];
185 };
186
187 /**
188  * struct kdbus_policy_access - policy access item
189  * @type:               One of KDBUS_POLICY_ACCESS_* types
190  * @bits:               Access to grant. One of KDBUS_POLICY_*
191  * @id:                 For KDBUS_POLICY_ACCESS_USER, the uid
192  *                      For KDBUS_POLICY_ACCESS_GROUP, the gid
193  */
194 struct kdbus_policy_access {
195         __u64 type;     /* USER, GROUP, WORLD */
196         __u64 access;   /* OWN, TALK, SEE */
197         __u64 id;       /* uid, gid, 0 */
198 };
199
200 /**
201  * enum kdbus_item_type - item types to chain data in a list
202  * @_KDBUS_ITEM_NULL:           Uninitialized/invalid
203  * @_KDBUS_ITEM_USER_BASE:      Start of user items
204  * @KDBUS_ITEM_PAYLOAD_VEC:     Vector to data
205  * @KDBUS_ITEM_PAYLOAD_OFF:     Data at returned offset to message head
206  * @KDBUS_ITEM_PAYLOAD_MEMFD:   Data as sealed memfd
207  * @KDBUS_ITEM_FDS:             Attached file descriptors
208  * @KDBUS_ITEM_BLOOM_PARAMETER: Bus-wide bloom parameters, used with
209  *                              KDBUS_CMD_BUS_MAKE, carries a
210  *                              struct kdbus_bloom_parameter
211  * @KDBUS_ITEM_BLOOM_FILTER:    Bloom filter carried with a message, used to
212  *                              match against a bloom mask of a connection,
213  *                              carries a struct kdbus_bloom_filter
214  * @KDBUS_ITEM_BLOOM_MASK:      Bloom mask used to match against a message's
215  *                              bloom filter
216  * @KDBUS_ITEM_DST_NAME:        Destination's well-known name
217  * @KDBUS_ITEM_MAKE_NAME:       Name of domain, bus, endpoint
218  * @KDBUS_ITEM_MEMFD_NAME:      The human readable name of a memfd (debugging)
219  * @KDBUS_ITEM_ATTACH_FLAGS:    Attach-flags, used for updating which metadata
220  *                              a connection subscribes to
221  * @_KDBUS_ITEM_ATTACH_BASE:    Start of metadata attach items
222  * @KDBUS_ITEM_NAME:            Well-know name with flags
223  * @KDBUS_ITEM_ID:              Connection ID
224  * @KDBUS_ITEM_TIMESTAMP:       Timestamp
225  * @KDBUS_ITEM_CREDS:           Process credential
226  * @KDBUS_ITEM_PID_COMM:        Process ID "comm" identifier
227  * @KDBUS_ITEM_TID_COMM:        Thread ID "comm" identifier
228  * @KDBUS_ITEM_EXE:             The path of the executable
229  * @KDBUS_ITEM_CMDLINE:         The process command line
230  * @KDBUS_ITEM_CGROUP:          The croup membership
231  * @KDBUS_ITEM_CAPS:            The process capabilities
232  * @KDBUS_ITEM_SECLABEL:        The security label
233  * @KDBUS_ITEM_AUDIT:           The audit IDs
234  * @KDBUS_ITEM_CONN_NAME:       The connection's human-readable name (debugging)
235  * @_KDBUS_ITEM_POLICY_BASE:    Start of policy items
236  * @KDBUS_ITEM_POLICY_ACCESS:   Policy access block
237  * @_KDBUS_ITEM_KERNEL_BASE:    Start of kernel-generated message items
238  * @KDBUS_ITEM_NAME_ADD:        Notify in struct kdbus_notify_name_change
239  * @KDBUS_ITEM_NAME_REMOVE:     Notify in struct kdbus_notify_name_change
240  * @KDBUS_ITEM_NAME_CHANGE:     Notify in struct kdbus_notify_name_change
241  * @KDBUS_ITEM_ID_ADD:          Notify in struct kdbus_notify_id_change
242  * @KDBUS_ITEM_ID_REMOVE:       Notify in struct kdbus_notify_id_change
243  * @KDBUS_ITEM_REPLY_TIMEOUT:   Timeout has been reached
244  * @KDBUS_ITEM_REPLY_DEAD:      Destination died
245  */
246 enum kdbus_item_type {
247         _KDBUS_ITEM_NULL,
248         _KDBUS_ITEM_USER_BASE,
249         KDBUS_ITEM_PAYLOAD_VEC  = _KDBUS_ITEM_USER_BASE,
250         KDBUS_ITEM_PAYLOAD_OFF,
251         KDBUS_ITEM_PAYLOAD_MEMFD,
252         KDBUS_ITEM_FDS,
253         KDBUS_ITEM_BLOOM_PARAMETER,
254         KDBUS_ITEM_BLOOM_FILTER,
255         KDBUS_ITEM_BLOOM_MASK,
256         KDBUS_ITEM_DST_NAME,
257         KDBUS_ITEM_MAKE_NAME,
258         KDBUS_ITEM_MEMFD_NAME,
259         KDBUS_ITEM_ATTACH_FLAGS,
260
261         _KDBUS_ITEM_ATTACH_BASE = 0x1000,
262         KDBUS_ITEM_NAME         = _KDBUS_ITEM_ATTACH_BASE,
263         KDBUS_ITEM_ID,
264         KDBUS_ITEM_TIMESTAMP,
265         KDBUS_ITEM_CREDS,
266         KDBUS_ITEM_PID_COMM,
267         KDBUS_ITEM_TID_COMM,
268         KDBUS_ITEM_EXE,
269         KDBUS_ITEM_CMDLINE,
270         KDBUS_ITEM_CGROUP,
271         KDBUS_ITEM_CAPS,
272         KDBUS_ITEM_SECLABEL,
273         KDBUS_ITEM_AUDIT,
274         KDBUS_ITEM_CONN_NAME,
275
276         _KDBUS_ITEM_POLICY_BASE = 0x2000,
277         KDBUS_ITEM_POLICY_ACCESS = _KDBUS_ITEM_POLICY_BASE,
278
279         _KDBUS_ITEM_KERNEL_BASE = 0x8000,
280         KDBUS_ITEM_NAME_ADD     = _KDBUS_ITEM_KERNEL_BASE,
281         KDBUS_ITEM_NAME_REMOVE,
282         KDBUS_ITEM_NAME_CHANGE,
283         KDBUS_ITEM_ID_ADD,
284         KDBUS_ITEM_ID_REMOVE,
285         KDBUS_ITEM_REPLY_TIMEOUT,
286         KDBUS_ITEM_REPLY_DEAD,
287 };
288
289 /**
290  * struct kdbus_item - chain of data blocks
291  * @size:               Overall data record size
292  * @type:               Kdbus_item type of data
293  * @data:               Generic bytes
294  * @data32:             Generic 32 bit array
295  * @data64:             Generic 64 bit array
296  * @str:                Generic string
297  * @id:                 Connection ID
298  * @vec:                KDBUS_ITEM_PAYLOAD_VEC
299  * @creds:              KDBUS_ITEM_CREDS
300  * @audit:              KDBUS_ITEM_AUDIT
301  * @timestamp:          KDBUS_ITEM_TIMESTAMP
302  * @name:               KDBUS_ITEM_NAME
303  * @bloom_parameter:    KDBUS_ITEM_BLOOM_PARAMETER
304  * @bloom_filter:       KDBUS_ITEM_BLOOM_FILTER
305  * @memfd:              KDBUS_ITEM_PAYLOAD_MEMFD
306  * @name_change:        KDBUS_ITEM_NAME_ADD
307  *                      KDBUS_ITEM_NAME_REMOVE
308  *                      KDBUS_ITEM_NAME_CHANGE
309  * @id_change:          KDBUS_ITEM_ID_ADD
310  *                      KDBUS_ITEM_ID_REMOVE
311  * @policy:             KDBUS_ITEM_POLICY_ACCESS
312  */
313 struct kdbus_item {
314         __u64 size;
315         __u64 type;
316         union {
317                 __u8 data[0];
318                 __u32 data32[0];
319                 __u64 data64[0];
320                 char str[0];
321
322                 __u64 id;
323                 struct kdbus_vec vec;
324                 struct kdbus_creds creds;
325                 struct kdbus_audit audit;
326                 struct kdbus_timestamp timestamp;
327                 struct kdbus_name name;
328                 struct kdbus_bloom_parameter bloom_parameter;
329                 struct kdbus_bloom_filter bloom_filter;
330                 struct kdbus_memfd memfd;
331                 int fds[0];
332                 struct kdbus_notify_name_change name_change;
333                 struct kdbus_notify_id_change id_change;
334                 struct kdbus_policy_access policy_access;
335         };
336 };
337
338 /**
339  * enum kdbus_msg_flags - type of message
340  * @KDBUS_MSG_FLAGS_EXPECT_REPLY:       Expect a reply message, used for
341  *                                      method calls. The userspace-supplied
342  *                                      cookie identifies the message and the
343  *                                      respective reply carries the cookie
344  *                                      in cookie_reply
345  * @KDBUS_MSG_FLAGS_SYNC_REPLY:         Wait for destination connection to
346  *                                      reply to this message. The
347  *                                      KDBUS_CMD_MSG_SEND ioctl() will block
348  *                                      until the reply is received, and
349  *                                      offset_reply in struct kdbus_msg will
350  *                                      yield the offset in the sender's pool
351  *                                      where the reply can be found.
352  *                                      This flag is only valid if
353  *                                      @KDBUS_MSG_FLAGS_EXPECT_REPLY is set as
354  *                                      well.
355  * @KDBUS_MSG_FLAGS_NO_AUTO_START:      Do not start a service, if the addressed
356  *                                      name is not currently active
357  */
358 enum kdbus_msg_flags {
359         KDBUS_MSG_FLAGS_EXPECT_REPLY    = 1 << 0,
360         KDBUS_MSG_FLAGS_SYNC_REPLY      = 1 << 1,
361         KDBUS_MSG_FLAGS_NO_AUTO_START   = 1 << 2,
362 };
363
364 /**
365  * enum kdbus_payload_type - type of payload carried by message
366  * @KDBUS_PAYLOAD_KERNEL:       Kernel-generated simple message
367  * @KDBUS_PAYLOAD_DBUS:         D-Bus marshalling "DBusDBus"
368  */
369 enum kdbus_payload_type {
370         KDBUS_PAYLOAD_KERNEL,
371         KDBUS_PAYLOAD_DBUS      = 0x4442757344427573ULL,
372 };
373
374 /**
375  * struct kdbus_msg - the representation of a kdbus message
376  * @size:               Total size of the message
377  * @flags:              Message flags (KDBUS_MSG_FLAGS_*)
378  * @priority:           Message queue priority value
379  * @dst_id:             64-bit ID of the destination connection
380  * @src_id:             64-bit ID of the source connection
381  * @payload_type:       Payload type (KDBUS_PAYLOAD_*)
382  * @cookie:             Userspace-supplied cookie, for the connection
383  *                      to identify its messages
384  * @timeout_ns:         The time to wait for a message reply from the peer.
385  *                      If there is no reply, a kernel-generated message
386  *                      with an attached KDBUS_ITEM_REPLY_TIMEOUT item
387  *                      is sent to @src_id.
388  * @cookie_reply:       A reply to the requesting message with the same
389  *                      cookie. The requesting connection can match its
390  *                      request and the reply with this value
391  * @offset_reply:       If KDBUS_MSG_FLAGS_WAIT_FOR_REPLY, this field will
392  *                      contain the offset in the sender's pool where the
393  *                      reply is stored.
394  * @items:              A list of kdbus_items containing the message payload
395  */
396 struct kdbus_msg {
397         __u64 size;
398         __u64 flags;
399         __s64 priority;
400         __u64 dst_id;
401         __u64 src_id;
402         __u64 payload_type;
403         __u64 cookie;
404         union {
405                 __u64 timeout_ns;
406                 __u64 cookie_reply;
407                 __u64 offset_reply;
408         };
409         struct kdbus_item items[0];
410 } __attribute__((aligned(8)));
411
412 /**
413  * enum kdbus_recv_flags - flags for de-queuing messages
414  * @KDBUS_RECV_PEEK:            Return the next queued message without
415  *                              actually de-queuing it, and without installing
416  *                              any file descriptors or other resources. It is
417  *                              usually used to determine the activating
418  *                              connection of a bus name.
419  * @KDBUS_RECV_DROP:            Drop and free the next queued message and all
420  *                              its resources without actually receiving it.
421  * @KDBUS_RECV_USE_PRIORITY:    Only de-queue messages with the specified or
422  *                              higher priority (lowest values); if not set,
423  *                              the priority value is ignored.
424  */
425 enum kdbus_recv_flags {
426         KDBUS_RECV_PEEK         = 1 <<  0,
427         KDBUS_RECV_DROP         = 1 <<  1,
428         KDBUS_RECV_USE_PRIORITY = 1 <<  2,
429 };
430
431 /**
432  * struct kdbus_cmd_recv - struct to de-queue a buffered message
433  * @flags:              KDBUS_RECV_* flags
434  * @priority:           Minimum priority of the messages to de-queue. Lowest
435  *                      values have the highest priority.
436  * @offset:             Returned offset in the pool where the message is
437  *                      stored. The user must use KDBUS_CMD_FREE to free
438  *                      the allocated memory.
439  *
440  * This struct is used with the KDBUS_CMD_MSG_RECV ioctl.
441  */
442 struct kdbus_cmd_recv {
443         __u64 flags;
444         __s64 priority;
445         __u64 offset;
446 } __attribute__((aligned(8)));
447
448 /**
449  * enum kdbus_policy_access_type - permissions of a policy record
450  * @_KDBUS_POLICY_ACCESS_NULL:  Uninitialized/invalid
451  * @KDBUS_POLICY_ACCESS_USER:   Grant access to a uid
452  * @KDBUS_POLICY_ACCESS_GROUP:  Grant access to gid
453  * @KDBUS_POLICY_ACCESS_WORLD:  World-accessible
454  */
455 enum kdbus_policy_access_type {
456         _KDBUS_POLICY_ACCESS_NULL,
457         KDBUS_POLICY_ACCESS_USER,
458         KDBUS_POLICY_ACCESS_GROUP,
459         KDBUS_POLICY_ACCESS_WORLD,
460 };
461
462 /**
463  * enum kdbus_policy_access_flags - mode flags
464  * @KDBUS_POLICY_OWN:           Allow to own a well-known name
465  *                              Implies KDBUS_POLICY_TALK and KDBUS_POLICY_SEE
466  * @KDBUS_POLICY_TALK:          Allow communication to a well-known name
467  *                              Implies KDBUS_POLICY_SEE
468  * @KDBUS_POLICY_SEE:           Allow to see a well-known name
469  */
470 enum kdbus_policy_type {
471         KDBUS_POLICY_SEE        = 0,
472         KDBUS_POLICY_TALK,
473         KDBUS_POLICY_OWN,
474 };
475
476 /**
477  * enum kdbus_hello_flags - flags for struct kdbus_cmd_hello
478  * @KDBUS_HELLO_ACCEPT_FD:      The connection allows the receiving of
479  *                              any passed file descriptors
480  * @KDBUS_HELLO_ACTIVATOR:      Special-purpose connection which registers
481  *                              a well-know name for a process to be started
482  *                              when traffic arrives
483  * @KDBUS_HELLO_POLICY_HOLDER:  Special-purpose connection which registers
484  *                              policy entries for one or multiple names. The
485  *                              provided names are not activated, and are not
486  *                              registered with the name database
487  * @KDBUS_HELLO_MONITOR:        Special-purpose connection to monitor
488  *                              bus traffic
489  */
490 enum kdbus_hello_flags {
491         KDBUS_HELLO_ACCEPT_FD           =  1 <<  0,
492         KDBUS_HELLO_ACTIVATOR           =  1 <<  1,
493         KDBUS_HELLO_POLICY_HOLDER       =  1 <<  2,
494         KDBUS_HELLO_MONITOR             =  1 <<  3,
495 };
496
497 /**
498  * enum kdbus_attach_flags - flags for metadata attachments
499  * @KDBUS_ATTACH_TIMESTAMP:     Timestamp
500  * @KDBUS_ATTACH_CREDS:         Credentials
501  * @KDBUS_ATTACH_NAMES:         Well-known names
502  * @KDBUS_ATTACH_COMM:          The "comm" process identifier
503  * @KDBUS_ATTACH_EXE:           The path of the executable
504  * @KDBUS_ATTACH_CMDLINE:       The process command line
505  * @KDBUS_ATTACH_CGROUP:        The croup membership
506  * @KDBUS_ATTACH_CAPS:          The process capabilities
507  * @KDBUS_ATTACH_SECLABEL:      The security label
508  * @KDBUS_ATTACH_AUDIT:         The audit IDs
509  * @KDBUS_ATTACH_CONN_NAME:     The human-readable connection name
510  */
511 enum kdbus_attach_flags {
512         KDBUS_ATTACH_TIMESTAMP          =  1 <<  0,
513         KDBUS_ATTACH_CREDS              =  1 <<  1,
514         KDBUS_ATTACH_NAMES              =  1 <<  2,
515         KDBUS_ATTACH_COMM               =  1 <<  3,
516         KDBUS_ATTACH_EXE                =  1 <<  4,
517         KDBUS_ATTACH_CMDLINE            =  1 <<  5,
518         KDBUS_ATTACH_CGROUP             =  1 <<  6,
519         KDBUS_ATTACH_CAPS               =  1 <<  7,
520         KDBUS_ATTACH_SECLABEL           =  1 <<  8,
521         KDBUS_ATTACH_AUDIT              =  1 <<  9,
522         KDBUS_ATTACH_CONN_NAME          =  1 << 10,
523 };
524
525 /**
526  * struct kdbus_cmd_hello - struct to say hello to kdbus
527  * @size:               The total size of the structure
528  * @conn_flags:         Connection flags (KDBUS_HELLO_*). The kernel will
529  *                      return its capabilities in that field.
530  * @attach_flags:       Mask of metadata to attach to each message sent
531  *                      (KDBUS_ATTACH_*)
532  * @bus_flags:          The flags field copied verbatim from the original
533  *                      KDBUS_CMD_BUS_MAKE ioctl. It's intended to be useful
534  *                      to do negotiation of features of the payload that is
535  *                      transferred (kernel â†’ userspace)
536  * @id:                 The ID of this connection (kernel â†’ userspace)
537  * @pool_size:          Size of the connection's buffer where the received
538  *                      messages are placed
539  * @bloom:              The bloom properties of the bus, specified
540  *                      by the bus creator (kernel â†’ userspace)
541  * @id128:              Unique 128-bit ID of the bus (kernel â†’ userspace)
542  * @items:              A list of items
543  *
544  * This struct is used with the KDBUS_CMD_HELLO ioctl.
545  */
546 struct kdbus_cmd_hello {
547         __u64 size;
548         __u64 conn_flags;
549         __u64 attach_flags;
550         __u64 bus_flags;
551         __u64 id;
552         __u64 pool_size;
553         struct kdbus_bloom_parameter bloom;
554         __u8 id128[16];
555         struct kdbus_item items[0];
556 } __attribute__((aligned(8)));
557
558 /**
559  * enum kdbus_make_flags - Flags for KDBUS_CMD_{BUS,EP,NS}_MAKE
560  * @KDBUS_MAKE_ACCESS_GROUP:    Make the device node group-accessible
561  * @KDBUS_MAKE_ACCESS_WORLD:    Make the device node world-accessible
562  */
563 enum kdbus_make_flags {
564         KDBUS_MAKE_ACCESS_GROUP         = 1 <<  0,
565         KDBUS_MAKE_ACCESS_WORLD         = 1 <<  1,
566 };
567
568 /**
569  * struct kdbus_cmd_make - struct to make a bus, an endpoint or a domain
570  * @size:               The total size of the struct
571  * @flags:              Properties for the bus/ep/domain to create
572  * @items:              Items describing details
573  *
574  * This structure is used with the KDBUS_CMD_BUS_MAKE, KDBUS_CMD_EP_MAKE and
575  * KDBUS_CMD_DOMAIN_MAKE ioctls.
576  */
577 struct kdbus_cmd_make {
578         __u64 size;
579         __u64 flags;
580         struct kdbus_item items[0];
581 } __attribute__((aligned(8)));
582
583 /**
584  * enum kdbus_name_flags - properties of a well-known name
585  * @KDBUS_NAME_REPLACE_EXISTING:        Try to replace name of other connections
586  * @KDBUS_NAME_ALLOW_REPLACEMENT:       Allow the replacement of the name
587  * @KDBUS_NAME_QUEUE:                   Name should be queued if busy
588  * @KDBUS_NAME_IN_QUEUE:                Name is queued
589  * @KDBUS_NAME_ACTIVATOR:               Name is owned by a activator connection
590  */
591 enum kdbus_name_flags {
592         KDBUS_NAME_REPLACE_EXISTING     = 1 <<  0,
593         KDBUS_NAME_ALLOW_REPLACEMENT    = 1 <<  1,
594         KDBUS_NAME_QUEUE                = 1 <<  2,
595         KDBUS_NAME_IN_QUEUE             = 1 <<  3,
596         KDBUS_NAME_ACTIVATOR            = 1 <<  4,
597 };
598
599 /**
600  * struct kdbus_cmd_name - struct to describe a well-known name
601  * @size:               The total size of the struct
602  * @flags:              Flags for a name entry (KDBUS_NAME_*)
603  * @owner_id:           The current owner of the name. For requests,
604  *                      privileged users may set this field to
605  *                      (de)register names on behalf of other connections.
606  * @conn_flags:         The flags of the owning connection (KDBUS_HELLO_*)
607  * @name:               The well-known name
608  *
609  * This structure is used with the KDBUS_CMD_NAME_ACQUIRE ioctl.
610  */
611 struct kdbus_cmd_name {
612         __u64 size;
613         __u64 flags;
614         __u64 owner_id;
615         __u64 conn_flags;
616         char name[0];
617 } __attribute__((aligned(8)));
618
619 /**
620  * enum kdbus_name_list_flags - what to include into the returned list
621  * @KDBUS_NAME_LIST_UNIQUE:     All active connections
622  * @KDBUS_NAME_LIST_NAMES:      All known well-known names
623  * @KDBUS_NAME_LIST_ACTIVATORS: All activator connections
624  * @KDBUS_NAME_LIST_QUEUED:     All queued-up names
625  */
626 enum kdbus_name_list_flags {
627         KDBUS_NAME_LIST_UNIQUE          = 1 <<  0,
628         KDBUS_NAME_LIST_NAMES           = 1 <<  1,
629         KDBUS_NAME_LIST_ACTIVATORS      = 1 <<  2,
630         KDBUS_NAME_LIST_QUEUED          = 1 <<  3,
631 };
632
633 /**
634  * struct kdbus_cmd_name_list - request a list of name entries
635  * @flags:              Flags for the query (KDBUS_NAME_LIST_*)
636  * @offset:             The returned offset in the caller's pool buffer.
637  *                      The user must use KDBUS_CMD_FREE to free the
638  *                      allocated memory.
639  *
640  * This structure is used with the KDBUS_CMD_NAME_LIST ioctl.
641  */
642 struct kdbus_cmd_name_list {
643         __u64 flags;
644         __u64 offset;
645 } __attribute__((aligned(8)));
646
647 /**
648  * struct kdbus_name_list - information returned by KDBUS_CMD_NAME_LIST
649  * @size:               The total size of the structure
650  * @names:              A list of names
651  *
652  * Note that the user is responsible for freeing the allocated memory with
653  * the KDBUS_CMD_FREE ioctl.
654  */
655 struct kdbus_name_list {
656         __u64 size;
657         struct kdbus_cmd_name names[0];
658 };
659
660 /**
661  * struct kdbus_cmd_conn_info - struct used for KDBUS_CMD_CONN_INFO ioctl
662  * @size:               The total size of the struct
663  * @flags:              KDBUS_ATTACH_* flags
664  * @id:                 The 64-bit ID of the connection. If set to zero, passing
665  *                      @name is required. kdbus will look up the name to
666  *                      determine the ID in this case.
667  * @offset:             Returned offset in the caller's pool buffer where the
668  *                      kdbus_conn_info struct result is stored. The user must
669  *                      use KDBUS_CMD_FREE to free the allocated memory.
670  * @name:               The optional well-known name to look up. Only needed in
671  *                      case @id is zero.
672  *
673  * On success, the KDBUS_CMD_CONN_INFO ioctl will return 0 and @offset will
674  * tell the user the offset in the connection pool buffer at which to find the
675  * result in a struct kdbus_conn_info.
676  */
677 struct kdbus_cmd_conn_info {
678         __u64 size;
679         __u64 flags;
680         __u64 id;
681         __u64 offset;
682         char name[0];
683 } __attribute__((aligned(8)));
684
685 /**
686  * struct kdbus_conn_info - information returned by KDBUS_CMD_CONN_INFO
687  * @size:               The total size of the struct
688  * @id:                 The connection's 64-bit ID
689  * @flags:              The connection's flags
690  * @items:              A list of struct kdbus_item
691  *
692  * Note that the user is responsible for freeing the allocated memory with
693  * the KDBUS_CMD_FREE ioctl.
694  */
695 struct kdbus_conn_info {
696         __u64 size;
697         __u64 id;
698         __u64 flags;
699         struct kdbus_item items[0];
700 };
701
702 /**
703  * struct kdbus_cmd_conn_update - update flags of a connection
704  * @size:               The total size of the struct
705  * @items:              A list of struct kdbus_item
706  *
707  * This struct is used with the KDBUS_CMD_CONN_UPDATE ioctl.
708  */
709 struct kdbus_cmd_conn_update {
710         __u64 size;
711         struct kdbus_item items[0];
712 } __attribute__((aligned(8)));
713
714 /**
715  * struct kdbus_cmd_match - struct to add or remove matches
716  * @size:               The total size of the struct
717  * @owner_id:           Privileged users may (de)register matches on behalf
718  *                      of other peers
719  * @cookie:             Userspace supplied cookie. When removing, the cookie
720  *                      identifies the match to remove
721  * @items:              A list of items for additional information
722  *
723  * This structure is used with the KDBUS_CMD_ADD_MATCH and
724  * KDBUS_CMD_REMOVE_MATCH ioctl.
725  */
726 struct kdbus_cmd_match {
727         __u64 size;
728         __u64 owner_id;
729         __u64 cookie;
730         struct kdbus_item items[0];
731 } __attribute__((aligned(8)));
732
733 /**
734  * struct kdbus_cmd_memfd_make - create a kdbus memfd
735  * @size:               The total size of the struct
736  * @file_size:          The initial file size
737  * @fd:                 The returned file descriptor number
738  * @__pad:              Padding to ensure proper alignement
739  * @items:              A list of items for additional information
740  *
741  * This structure is used with the KDBUS_CMD_MEMFD_NEW ioctl.
742  */
743 struct kdbus_cmd_memfd_make {
744         __u64 size;
745         __u64 file_size;
746         int fd;
747         __u32 __pad;
748         struct kdbus_item items[0];
749 } __attribute__((aligned(8)));
750
751 /**
752  * enum kdbus_ioctl_type - Ioctl API
753  * @KDBUS_CMD_BUS_MAKE:         After opening the "control" device node, this
754  *                              command creates a new bus with the specified
755  *                              name. The bus is immediately shut down and
756  *                              cleaned up when the opened "control" device node
757  *                              is closed.
758  * @KDBUS_CMD_DOMAIN_MAKE:              Similar to KDBUS_CMD_BUS_MAKE, but it creates a
759  *                              new kdbus domain.
760  * @KDBUS_CMD_EP_MAKE:          Creates a new named special endpoint to talk to
761  *                              the bus. Such endpoints usually carry a more
762  *                              restrictive policy and grant restricted access
763  *                              to specific applications.
764  * @KDBUS_CMD_HELLO:            By opening the bus device node a connection is
765  *                              created. After a HELLO the opened connection
766  *                              becomes an active peer on the bus.
767  * @KDBUS_CMD_BYEBYE:           Disconnect a connection. If the connection's
768  *                              message list is empty, the calls succeeds, and
769  *                              the handle is rendered unusable. Otherwise,
770  *                              -EAGAIN is returned without any further side-
771  *                              effects.
772  * @KDBUS_CMD_MSG_SEND:         Send a message and pass data from userspace to
773  *                              the kernel.
774  * @KDBUS_CMD_MSG_RECV:         Receive a message from the kernel which is
775  *                              placed in the receiver's pool.
776  * @KDBUS_CMD_MSG_CANCEL:       Cancel a pending request of a message that
777  *                              blocks while waiting for a reply. The parameter
778  *                              denotes the cookie of the message in flight.
779  * @KDBUS_CMD_FREE:             Release the allocated memory in the receiver's
780  *                              pool.
781  * @KDBUS_CMD_NAME_ACQUIRE:     Request a well-known bus name to associate with
782  *                              the connection. Well-known names are used to
783  *                              address a peer on the bus.
784  * @KDBUS_CMD_NAME_RELEASE:     Release a well-known name the connection
785  *                              currently owns.
786  * @KDBUS_CMD_NAME_LIST:        Retrieve the list of all currently registered
787  *                              well-known and unique names.
788  * @KDBUS_CMD_CONN_INFO:        Retrieve credentials and properties of the
789  *                              initial creator of the connection. The data was
790  *                              stored at registration time and does not
791  *                              necessarily represent the connected process or
792  *                              the actual state of the process.
793  * @KDBUS_CMD_CONN_UPDATE:      Update the properties of a connection. Used to
794  *                              update the metadata subscription.
795  * @KDBUS_CMD_MATCH_ADD:        Install a match which broadcast messages should
796  *                              be delivered to the connection.
797  * @KDBUS_CMD_MATCH_REMOVE:     Remove a current match for broadcast messages.
798  * @KDBUS_CMD_EP_POLICY_SET:    Set the policy of an endpoint. It is used to
799  *                              restrict the access for endpoints created with
800  *                              KDBUS_CMD_EP_MAKE.
801  * @KDBUS_CMD_MEMFD_NEW:        Return a new file descriptor which provides an
802  *                              anonymous shared memory file and which can be
803  *                              used to pass around larger chunks of data.
804  *                              Kdbus memfd files can be sealed, which allows
805  *                              the receiver to trust the data it has received.
806  *                              Kdbus memfd files expose only very limited
807  *                              operations, they can be mmap()ed, seek()ed,
808  *                              (p)read(v)() and (p)write(v)(); most other
809  *                              common file operations are not implemented.
810  *                              Special caution needs to be taken with
811  *                              read(v)()/write(v)() on a shared file; the
812  *                              underlying file position is always shared
813  *                              between all users of the file and race against
814  *                              each other, pread(v)()/pwrite(v)() avoid these
815  *                              issues.
816  * @KDBUS_CMD_MEMFD_SIZE_GET:   Return the size of the underlying file, which
817  *                              changes with write().
818  * @KDBUS_CMD_MEMFD_SIZE_SET:   Truncate the underlying file to the specified
819  *                              size.
820  * @KDBUS_CMD_MEMFD_SEAL_GET:   Return the state of the file sealing.
821  * @KDBUS_CMD_MEMFD_SEAL_SET:   Seal or break a seal of the file. Only files
822  *                              which are not shared with other processes and
823  *                              which are currently not mapped can be sealed.
824  *                              The current process needs to be the one and
825  *                              single owner of the file, the sealing cannot
826  *                              be changed as long as the file is shared.
827  */
828 enum kdbus_ioctl_type {
829         KDBUS_CMD_BUS_MAKE =            _IOW (KDBUS_IOC_MAGIC, 0x00, struct kdbus_cmd_make),
830         KDBUS_CMD_DOMAIN_MAKE =         _IOW (KDBUS_IOC_MAGIC, 0x10, struct kdbus_cmd_make),
831         KDBUS_CMD_EP_MAKE =             _IOW (KDBUS_IOC_MAGIC, 0x20, struct kdbus_cmd_make),
832
833         KDBUS_CMD_HELLO =               _IOWR(KDBUS_IOC_MAGIC, 0x30, struct kdbus_cmd_hello),
834         KDBUS_CMD_BYEBYE =              _IO  (KDBUS_IOC_MAGIC, 0x31),
835
836         KDBUS_CMD_MSG_SEND =            _IOWR(KDBUS_IOC_MAGIC, 0x40, struct kdbus_msg),
837         KDBUS_CMD_MSG_RECV =            _IOWR(KDBUS_IOC_MAGIC, 0x41, struct kdbus_cmd_recv),
838         KDBUS_CMD_MSG_CANCEL =          _IOW (KDBUS_IOC_MAGIC, 0x42, __u64 *),
839         KDBUS_CMD_FREE =                _IOW (KDBUS_IOC_MAGIC, 0x43, __u64 *),
840
841         KDBUS_CMD_NAME_ACQUIRE =        _IOWR(KDBUS_IOC_MAGIC, 0x50, struct kdbus_cmd_name),
842         KDBUS_CMD_NAME_RELEASE =        _IOW (KDBUS_IOC_MAGIC, 0x51, struct kdbus_cmd_name),
843         KDBUS_CMD_NAME_LIST =           _IOWR(KDBUS_IOC_MAGIC, 0x52, struct kdbus_cmd_name_list),
844
845         KDBUS_CMD_CONN_INFO =           _IOWR(KDBUS_IOC_MAGIC, 0x60, struct kdbus_cmd_conn_info),
846         KDBUS_CMD_CONN_UPDATE =         _IOW (KDBUS_IOC_MAGIC, 0x61, struct kdbus_cmd_conn_update),
847
848         KDBUS_CMD_MATCH_ADD =           _IOW (KDBUS_IOC_MAGIC, 0x70, struct kdbus_cmd_match),
849         KDBUS_CMD_MATCH_REMOVE =        _IOW (KDBUS_IOC_MAGIC, 0x71, struct kdbus_cmd_match),
850
851         KDBUS_CMD_MEMFD_NEW =           _IOWR(KDBUS_IOC_MAGIC, 0xc0, struct kdbus_cmd_memfd_make),
852         KDBUS_CMD_MEMFD_SIZE_GET =      _IOR (KDBUS_IOC_MAGIC, 0xc1, __u64 *),
853         KDBUS_CMD_MEMFD_SIZE_SET =      _IOW (KDBUS_IOC_MAGIC, 0xc2, __u64 *),
854         KDBUS_CMD_MEMFD_SEAL_GET =      _IOR (KDBUS_IOC_MAGIC, 0xc3, int *),
855         KDBUS_CMD_MEMFD_SEAL_SET =      _IO  (KDBUS_IOC_MAGIC, 0xc4),
856 };
857
858 /*
859  * errno - api error codes
860  * @E2BIG:              A message contains too many records or items.
861  * @EADDRINUSE:         A well-known bus name is already taken by another
862  *                      connection.
863  * @EADDRNOTAVAIL:      A message flagged not to activate a service, addressed
864  *                      a service which is not currently running.
865  * @EAGAIN:             No messages are queued at the moment.
866  * @EALREADY:           A requested name is already owned by the connection,
867  *                      a connection is already disconnected, memfd is already
868  *                      sealed or has the requested size.
869  * @EBADF:              File descriptors passed with the message are not valid.
870  * @EBADFD:             A bus connection is in a corrupted state.
871  * @EBADMSG:            Passed data contains a combination of conflicting or
872  *                      inconsistent types.
873  * @EBUSY:              The user tried to say BYEBYE to a connection, but the
874  *                      connection had a non-empty message list.
875  * @ECANCELED:          A synchronous message sending was cancelled.
876  * @ECONNRESET:         A connection is shut down, no further operations are
877  *                      possible.
878  * @ECOMM:              A peer does not accept the file descriptors addressed
879  *                      to it.
880  * @EDESTADDRREQ:       The well-known bus name is required but missing.
881  * @EDOM:               The size of data does not match the expectations. Used
882  *                      for bloom bit field sizes.
883  * @EEXIST:             A requested domain, bus or endpoint with the same
884  *                      name already exists.  A specific data type, which is
885  *                      only expected once, is provided multiple times.
886  * @EFAULT:             The supplied memory could not be accessed, or the data
887  *                      is not properly aligned.
888  * @EINVAL:             The provided data does not match its type or other
889  *                      expectations, like a string which is not NUL terminated,
890  *                      or a string length that points behind the first
891  *                      \0-byte in the string.
892  * @EMEDIUMTYPE:        A file descriptor which is not a kdbus memfd was
893  *                      refused to send as KDBUS_MSG_PAYLOAD_MEMFD.
894  * @EMFILE:             Too many file descriptors have been supplied with a
895  *                      message.
896  *                      Too many connections or buses are created for a given
897  *                      user.
898  * @EMLINK:             Too many requests from this connection to other peers
899  *                      are queued and waiting for a reply
900  * @EMSGSIZE:           The supplied data is larger than the allowed maximum
901  *                      size.
902  * @ENAMETOOLONG:       The requested name is larger than the allowed maximum
903  *                      size.
904  * @ENOBUFS:            There is no space left for the submitted data to fit
905  *                      into the receiver's pool.
906  * @ENOENT:             The name to query information about is currently not on
907  *                      the bus.
908  * @ENOMEM:             Out of memory.
909  * @ENOMSG:             The queue is not empty, but no message with a matching
910  *                      priority is currently queued.
911  * @ENOSYS:             The requested functionality is not available.
912  * @ENOTSUPP:           The feature negotiation failed, a not supported feature
913  *                      was requested, or an unknown item type was received.
914  * @ENOTTY:             An unknown ioctl command was received.
915  * @ENOTUNIQ:           A specific data type was addressed to a broadcast
916  *                      address, but only direct addresses support this kind of
917  *                      data.
918  * @ENXIO:              A unique address does not exist, or an offset in the
919  *                      receiver's pool does not represent a queued message.
920  * @EPERM:              The policy prevented an operation. The requested
921  *                      resource is owned by another entity.
922  * @EPIPE:              When sending a message, a synchronous reply from the
923  *                      receiving connection was expected but the connection
924  *                      died before answering.
925  * @ESHUTDOWN:          A domain, bus or endpoint is currently shutting down;
926  *                      no further operations will be possible.
927  * @ESRCH:              A requested well-known bus name is not found.
928  * @ETIMEDOUT:          A synchronous wait for a message reply did not arrive
929  *                      within the specified time frame.
930  * @ETXTBSY:            A kdbus memfd file cannot be sealed or the seal removed,
931  *                      because it is shared with other processes or still
932  *                      mmap()ed.
933  * @EXFULL:             The size limits in the pool are reached, no data of
934  *                      the size tried to submit can be queued.
935  */
936 #endif