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