chiark / gitweb /
remove unused variables
[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_IOCTL_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  * @access:             Access to grant
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_AUXGROUPS:       Auxiliary process groups
227  * @KDBUS_ITEM_PID_COMM:        Process ID "comm" identifier
228  * @KDBUS_ITEM_TID_COMM:        Thread ID "comm" identifier
229  * @KDBUS_ITEM_EXE:             The path of the executable
230  * @KDBUS_ITEM_CMDLINE:         The process command line
231  * @KDBUS_ITEM_CGROUP:          The croup membership
232  * @KDBUS_ITEM_CAPS:            The process capabilities
233  * @KDBUS_ITEM_SECLABEL:        The security label
234  * @KDBUS_ITEM_AUDIT:           The audit IDs
235  * @KDBUS_ITEM_CONN_NAME:       The connection's human-readable name (debugging)
236  * @_KDBUS_ITEM_POLICY_BASE:    Start of policy items
237  * @KDBUS_ITEM_POLICY_ACCESS:   Policy access block
238  * @_KDBUS_ITEM_KERNEL_BASE:    Start of kernel-generated message items
239  * @KDBUS_ITEM_NAME_ADD:        Notify in struct kdbus_notify_name_change
240  * @KDBUS_ITEM_NAME_REMOVE:     Notify in struct kdbus_notify_name_change
241  * @KDBUS_ITEM_NAME_CHANGE:     Notify in struct kdbus_notify_name_change
242  * @KDBUS_ITEM_ID_ADD:          Notify in struct kdbus_notify_id_change
243  * @KDBUS_ITEM_ID_REMOVE:       Notify in struct kdbus_notify_id_change
244  * @KDBUS_ITEM_REPLY_TIMEOUT:   Timeout has been reached
245  * @KDBUS_ITEM_REPLY_DEAD:      Destination died
246  */
247 enum kdbus_item_type {
248         _KDBUS_ITEM_NULL,
249         _KDBUS_ITEM_USER_BASE,
250         KDBUS_ITEM_PAYLOAD_VEC  = _KDBUS_ITEM_USER_BASE,
251         KDBUS_ITEM_PAYLOAD_OFF,
252         KDBUS_ITEM_PAYLOAD_MEMFD,
253         KDBUS_ITEM_FDS,
254         KDBUS_ITEM_BLOOM_PARAMETER,
255         KDBUS_ITEM_BLOOM_FILTER,
256         KDBUS_ITEM_BLOOM_MASK,
257         KDBUS_ITEM_DST_NAME,
258         KDBUS_ITEM_MAKE_NAME,
259         KDBUS_ITEM_MEMFD_NAME,
260         KDBUS_ITEM_ATTACH_FLAGS,
261
262         _KDBUS_ITEM_ATTACH_BASE = 0x1000,
263         KDBUS_ITEM_NAME         = _KDBUS_ITEM_ATTACH_BASE,
264         KDBUS_ITEM_ID,
265         KDBUS_ITEM_TIMESTAMP,
266         KDBUS_ITEM_CREDS,
267         KDBUS_ITEM_AUXGROUPS,
268         KDBUS_ITEM_PID_COMM,
269         KDBUS_ITEM_TID_COMM,
270         KDBUS_ITEM_EXE,
271         KDBUS_ITEM_CMDLINE,
272         KDBUS_ITEM_CGROUP,
273         KDBUS_ITEM_CAPS,
274         KDBUS_ITEM_SECLABEL,
275         KDBUS_ITEM_AUDIT,
276         KDBUS_ITEM_CONN_NAME,
277
278         _KDBUS_ITEM_POLICY_BASE = 0x2000,
279         KDBUS_ITEM_POLICY_ACCESS = _KDBUS_ITEM_POLICY_BASE,
280
281         _KDBUS_ITEM_KERNEL_BASE = 0x8000,
282         KDBUS_ITEM_NAME_ADD     = _KDBUS_ITEM_KERNEL_BASE,
283         KDBUS_ITEM_NAME_REMOVE,
284         KDBUS_ITEM_NAME_CHANGE,
285         KDBUS_ITEM_ID_ADD,
286         KDBUS_ITEM_ID_REMOVE,
287         KDBUS_ITEM_REPLY_TIMEOUT,
288         KDBUS_ITEM_REPLY_DEAD,
289 };
290
291 /**
292  * struct kdbus_item - chain of data blocks
293  * @size:               Overall data record size
294  * @type:               Kdbus_item type of data
295  * @data:               Generic bytes
296  * @data32:             Generic 32 bit array
297  * @data64:             Generic 64 bit array
298  * @str:                Generic string
299  * @id:                 Connection ID
300  * @vec:                KDBUS_ITEM_PAYLOAD_VEC
301  * @creds:              KDBUS_ITEM_CREDS
302  * @audit:              KDBUS_ITEM_AUDIT
303  * @timestamp:          KDBUS_ITEM_TIMESTAMP
304  * @name:               KDBUS_ITEM_NAME
305  * @bloom_parameter:    KDBUS_ITEM_BLOOM_PARAMETER
306  * @bloom_filter:       KDBUS_ITEM_BLOOM_FILTER
307  * @memfd:              KDBUS_ITEM_PAYLOAD_MEMFD
308  * @name_change:        KDBUS_ITEM_NAME_ADD
309  *                      KDBUS_ITEM_NAME_REMOVE
310  *                      KDBUS_ITEM_NAME_CHANGE
311  * @id_change:          KDBUS_ITEM_ID_ADD
312  *                      KDBUS_ITEM_ID_REMOVE
313  * @policy:             KDBUS_ITEM_POLICY_ACCESS
314  */
315 struct kdbus_item {
316         __u64 size;
317         __u64 type;
318         union {
319                 __u8 data[0];
320                 __u32 data32[0];
321                 __u64 data64[0];
322                 char str[0];
323
324                 __u64 id;
325                 struct kdbus_vec vec;
326                 struct kdbus_creds creds;
327                 struct kdbus_audit audit;
328                 struct kdbus_timestamp timestamp;
329                 struct kdbus_name name;
330                 struct kdbus_bloom_parameter bloom_parameter;
331                 struct kdbus_bloom_filter bloom_filter;
332                 struct kdbus_memfd memfd;
333                 int fds[0];
334                 struct kdbus_notify_name_change name_change;
335                 struct kdbus_notify_id_change id_change;
336                 struct kdbus_policy_access policy_access;
337         };
338 };
339
340 /**
341  * enum kdbus_msg_flags - type of message
342  * @KDBUS_MSG_FLAGS_EXPECT_REPLY:       Expect a reply message, used for
343  *                                      method calls. The userspace-supplied
344  *                                      cookie identifies the message and the
345  *                                      respective reply carries the cookie
346  *                                      in cookie_reply
347  * @KDBUS_MSG_FLAGS_SYNC_REPLY:         Wait for destination connection to
348  *                                      reply to this message. The
349  *                                      KDBUS_CMD_MSG_SEND ioctl() will block
350  *                                      until the reply is received, and
351  *                                      offset_reply in struct kdbus_msg will
352  *                                      yield the offset in the sender's pool
353  *                                      where the reply can be found.
354  *                                      This flag is only valid if
355  *                                      @KDBUS_MSG_FLAGS_EXPECT_REPLY is set as
356  *                                      well.
357  * @KDBUS_MSG_FLAGS_NO_AUTO_START:      Do not start a service, if the addressed
358  *                                      name is not currently active
359  */
360 enum kdbus_msg_flags {
361         KDBUS_MSG_FLAGS_EXPECT_REPLY    = 1 << 0,
362         KDBUS_MSG_FLAGS_SYNC_REPLY      = 1 << 1,
363         KDBUS_MSG_FLAGS_NO_AUTO_START   = 1 << 2,
364 };
365
366 /**
367  * enum kdbus_payload_type - type of payload carried by message
368  * @KDBUS_PAYLOAD_KERNEL:       Kernel-generated simple message
369  * @KDBUS_PAYLOAD_DBUS:         D-Bus marshalling "DBusDBus"
370  */
371 enum kdbus_payload_type {
372         KDBUS_PAYLOAD_KERNEL,
373         KDBUS_PAYLOAD_DBUS      = 0x4442757344427573ULL,
374 };
375
376 /**
377  * struct kdbus_msg - the representation of a kdbus message
378  * @size:               Total size of the message
379  * @flags:              Message flags (KDBUS_MSG_FLAGS_*)
380  * @priority:           Message queue priority value
381  * @dst_id:             64-bit ID of the destination connection
382  * @src_id:             64-bit ID of the source connection
383  * @payload_type:       Payload type (KDBUS_PAYLOAD_*)
384  * @cookie:             Userspace-supplied cookie, for the connection
385  *                      to identify its messages
386  * @timeout_ns:         The time to wait for a message reply from the peer.
387  *                      If there is no reply, a kernel-generated message
388  *                      with an attached KDBUS_ITEM_REPLY_TIMEOUT item
389  *                      is sent to @src_id.
390  * @cookie_reply:       A reply to the requesting message with the same
391  *                      cookie. The requesting connection can match its
392  *                      request and the reply with this value
393  * @offset_reply:       If KDBUS_MSG_FLAGS_EXPECT_REPLY, this field will
394  *                      contain the offset in the sender's pool where the
395  *                      reply is stored.
396  * @items:              A list of kdbus_items containing the message payload
397  */
398 struct kdbus_msg {
399         __u64 size;
400         __u64 flags;
401         __s64 priority;
402         __u64 dst_id;
403         __u64 src_id;
404         __u64 payload_type;
405         __u64 cookie;
406         union {
407                 __u64 timeout_ns;
408                 __u64 cookie_reply;
409                 __u64 offset_reply;
410         };
411         struct kdbus_item items[0];
412 } __attribute__((aligned(8)));
413
414 /**
415  * enum kdbus_recv_flags - flags for de-queuing messages
416  * @KDBUS_RECV_PEEK:            Return the next queued message without
417  *                              actually de-queuing it, and without installing
418  *                              any file descriptors or other resources. It is
419  *                              usually used to determine the activating
420  *                              connection of a bus name.
421  * @KDBUS_RECV_DROP:            Drop and free the next queued message and all
422  *                              its resources without actually receiving it.
423  * @KDBUS_RECV_USE_PRIORITY:    Only de-queue messages with the specified or
424  *                              higher priority (lowest values); if not set,
425  *                              the priority value is ignored.
426  */
427 enum kdbus_recv_flags {
428         KDBUS_RECV_PEEK         = 1 <<  0,
429         KDBUS_RECV_DROP         = 1 <<  1,
430         KDBUS_RECV_USE_PRIORITY = 1 <<  2,
431 };
432
433 /**
434  * struct kdbus_cmd_recv - struct to de-queue a buffered message
435  * @flags:              KDBUS_RECV_* flags
436  * @priority:           Minimum priority of the messages to de-queue. Lowest
437  *                      values have the highest priority.
438  * @offset:             Returned offset in the pool where the message is
439  *                      stored. The user must use KDBUS_CMD_FREE to free
440  *                      the allocated memory.
441  *
442  * This struct is used with the KDBUS_CMD_MSG_RECV ioctl.
443  */
444 struct kdbus_cmd_recv {
445         __u64 flags;
446         __s64 priority;
447         __u64 offset;
448 } __attribute__((aligned(8)));
449
450 /**
451  * enum kdbus_policy_access_type - permissions of a policy record
452  * @_KDBUS_POLICY_ACCESS_NULL:  Uninitialized/invalid
453  * @KDBUS_POLICY_ACCESS_USER:   Grant access to a uid
454  * @KDBUS_POLICY_ACCESS_GROUP:  Grant access to gid
455  * @KDBUS_POLICY_ACCESS_WORLD:  World-accessible
456  */
457 enum kdbus_policy_access_type {
458         _KDBUS_POLICY_ACCESS_NULL,
459         KDBUS_POLICY_ACCESS_USER,
460         KDBUS_POLICY_ACCESS_GROUP,
461         KDBUS_POLICY_ACCESS_WORLD,
462 };
463
464 /**
465  * enum kdbus_policy_access_flags - mode flags
466  * @KDBUS_POLICY_OWN:           Allow to own a well-known name
467  *                              Implies KDBUS_POLICY_TALK and KDBUS_POLICY_SEE
468  * @KDBUS_POLICY_TALK:          Allow communication to a well-known name
469  *                              Implies KDBUS_POLICY_SEE
470  * @KDBUS_POLICY_SEE:           Allow to see a well-known name
471  */
472 enum kdbus_policy_type {
473         KDBUS_POLICY_SEE        = 0,
474         KDBUS_POLICY_TALK,
475         KDBUS_POLICY_OWN,
476 };
477
478 /**
479  * enum kdbus_hello_flags - flags for struct kdbus_cmd_hello
480  * @KDBUS_HELLO_ACCEPT_FD:      The connection allows the receiving of
481  *                              any passed file descriptors
482  * @KDBUS_HELLO_ACTIVATOR:      Special-purpose connection which registers
483  *                              a well-know name for a process to be started
484  *                              when traffic arrives
485  * @KDBUS_HELLO_POLICY_HOLDER:  Special-purpose connection which registers
486  *                              policy entries for a name. The provided name
487  *                              is not activated and not registered with the
488  *                              name database, it only allows unprivileged
489  *                              connections to aquire a name, talk or discover
490  *                              a service
491  * @KDBUS_HELLO_MONITOR:        Special-purpose connection to monitor
492  *                              bus traffic
493  */
494 enum kdbus_hello_flags {
495         KDBUS_HELLO_ACCEPT_FD           =  1 <<  0,
496         KDBUS_HELLO_ACTIVATOR           =  1 <<  1,
497         KDBUS_HELLO_POLICY_HOLDER       =  1 <<  2,
498         KDBUS_HELLO_MONITOR             =  1 <<  3,
499 };
500
501 /**
502  * enum kdbus_attach_flags - flags for metadata attachments
503  * @KDBUS_ATTACH_TIMESTAMP:     Timestamp
504  * @KDBUS_ATTACH_CREDS:         Credentials
505  * @KDBUS_ATTACH_AUXGROUPS:     Auxiliary groups
506  * @KDBUS_ATTACH_NAMES:         Well-known names
507  * @KDBUS_ATTACH_COMM:          The "comm" process identifier
508  * @KDBUS_ATTACH_EXE:           The path of the executable
509  * @KDBUS_ATTACH_CMDLINE:       The process command line
510  * @KDBUS_ATTACH_CGROUP:        The croup membership
511  * @KDBUS_ATTACH_CAPS:          The process capabilities
512  * @KDBUS_ATTACH_SECLABEL:      The security label
513  * @KDBUS_ATTACH_AUDIT:         The audit IDs
514  * @KDBUS_ATTACH_CONN_NAME:     The human-readable connection name
515  * @_KDBUS_ATTACH_ALL:          All of the above
516  */
517 enum kdbus_attach_flags {
518         KDBUS_ATTACH_TIMESTAMP          =  1 <<  0,
519         KDBUS_ATTACH_CREDS              =  1 <<  1,
520         KDBUS_ATTACH_AUXGROUPS          =  1 <<  2,
521         KDBUS_ATTACH_NAMES              =  1 <<  3,
522         KDBUS_ATTACH_COMM               =  1 <<  4,
523         KDBUS_ATTACH_EXE                =  1 <<  5,
524         KDBUS_ATTACH_CMDLINE            =  1 <<  6,
525         KDBUS_ATTACH_CGROUP             =  1 <<  7,
526         KDBUS_ATTACH_CAPS               =  1 <<  8,
527         KDBUS_ATTACH_SECLABEL           =  1 <<  9,
528         KDBUS_ATTACH_AUDIT              =  1 << 10,
529         KDBUS_ATTACH_CONN_NAME          =  1 << 11,
530         _KDBUS_ATTACH_ALL               =  (1 << 12) - 1,
531 };
532
533 /**
534  * struct kdbus_cmd_hello - struct to say hello to kdbus
535  * @size:               The total size of the structure
536  * @conn_flags:         Connection flags (KDBUS_HELLO_*). The kernel will
537  *                      return its capabilities in that field.
538  * @attach_flags:       Mask of metadata to attach to each message sent
539  *                      (KDBUS_ATTACH_*)
540  * @bus_flags:          The flags field copied verbatim from the original
541  *                      KDBUS_CMD_BUS_MAKE ioctl. It's intended to be useful
542  *                      to do negotiation of features of the payload that is
543  *                      transferred (kernel â†’ userspace)
544  * @id:                 The ID of this connection (kernel â†’ userspace)
545  * @pool_size:          Size of the connection's buffer where the received
546  *                      messages are placed
547  * @bloom:              The bloom properties of the bus, specified
548  *                      by the bus creator (kernel â†’ userspace)
549  * @id128:              Unique 128-bit ID of the bus (kernel â†’ userspace)
550  * @items:              A list of items
551  *
552  * This struct is used with the KDBUS_CMD_HELLO ioctl.
553  */
554 struct kdbus_cmd_hello {
555         __u64 size;
556         __u64 conn_flags;
557         __u64 attach_flags;
558         __u64 bus_flags;
559         __u64 id;
560         __u64 pool_size;
561         struct kdbus_bloom_parameter bloom;
562         __u8 id128[16];
563         struct kdbus_item items[0];
564 } __attribute__((aligned(8)));
565
566 /**
567  * enum kdbus_make_flags - Flags for KDBUS_CMD_{BUS,EP,NS}_MAKE
568  * @KDBUS_MAKE_ACCESS_GROUP:    Make the device node group-accessible
569  * @KDBUS_MAKE_ACCESS_WORLD:    Make the device node world-accessible
570  */
571 enum kdbus_make_flags {
572         KDBUS_MAKE_ACCESS_GROUP         = 1 <<  0,
573         KDBUS_MAKE_ACCESS_WORLD         = 1 <<  1,
574 };
575
576 /**
577  * struct kdbus_cmd_make - struct to make a bus, an endpoint or a domain
578  * @size:               The total size of the struct
579  * @flags:              Properties for the bus/ep/domain to create
580  * @items:              Items describing details
581  *
582  * This structure is used with the KDBUS_CMD_BUS_MAKE, KDBUS_CMD_EP_MAKE and
583  * KDBUS_CMD_DOMAIN_MAKE ioctls.
584  */
585 struct kdbus_cmd_make {
586         __u64 size;
587         __u64 flags;
588         struct kdbus_item items[0];
589 } __attribute__((aligned(8)));
590
591 /**
592  * enum kdbus_name_flags - properties of a well-known name
593  * @KDBUS_NAME_REPLACE_EXISTING:        Try to replace name of other connections
594  * @KDBUS_NAME_ALLOW_REPLACEMENT:       Allow the replacement of the name
595  * @KDBUS_NAME_QUEUE:                   Name should be queued if busy
596  * @KDBUS_NAME_IN_QUEUE:                Name is queued
597  * @KDBUS_NAME_ACTIVATOR:               Name is owned by a activator connection
598  */
599 enum kdbus_name_flags {
600         KDBUS_NAME_REPLACE_EXISTING     = 1 <<  0,
601         KDBUS_NAME_ALLOW_REPLACEMENT    = 1 <<  1,
602         KDBUS_NAME_QUEUE                = 1 <<  2,
603         KDBUS_NAME_IN_QUEUE             = 1 <<  3,
604         KDBUS_NAME_ACTIVATOR            = 1 <<  4,
605 };
606
607 /**
608  * struct kdbus_cmd_name - struct to describe a well-known name
609  * @size:               The total size of the struct
610  * @flags:              Flags for a name entry (KDBUS_NAME_*)
611  * @owner_id:           The current owner of the name.
612  * @conn_flags:         The flags of the owning connection (KDBUS_HELLO_*)
613  * @name:               The well-known name
614  *
615  * This structure is used with the KDBUS_CMD_NAME_ACQUIRE ioctl.
616  */
617 struct kdbus_cmd_name {
618         __u64 size;
619         __u64 flags;
620         __u64 owner_id;
621         __u64 conn_flags;
622         char name[0];
623 } __attribute__((aligned(8)));
624
625 /**
626  * enum kdbus_name_list_flags - what to include into the returned list
627  * @KDBUS_NAME_LIST_UNIQUE:     All active connections
628  * @KDBUS_NAME_LIST_NAMES:      All known well-known names
629  * @KDBUS_NAME_LIST_ACTIVATORS: All activator connections
630  * @KDBUS_NAME_LIST_QUEUED:     All queued-up names
631  */
632 enum kdbus_name_list_flags {
633         KDBUS_NAME_LIST_UNIQUE          = 1 <<  0,
634         KDBUS_NAME_LIST_NAMES           = 1 <<  1,
635         KDBUS_NAME_LIST_ACTIVATORS      = 1 <<  2,
636         KDBUS_NAME_LIST_QUEUED          = 1 <<  3,
637 };
638
639 /**
640  * struct kdbus_cmd_name_list - request a list of name entries
641  * @flags:              Flags for the query (KDBUS_NAME_LIST_*)
642  * @offset:             The returned offset in the caller's pool buffer.
643  *                      The user must use KDBUS_CMD_FREE to free the
644  *                      allocated memory.
645  *
646  * This structure is used with the KDBUS_CMD_NAME_LIST ioctl.
647  */
648 struct kdbus_cmd_name_list {
649         __u64 flags;
650         __u64 offset;
651 } __attribute__((aligned(8)));
652
653 /**
654  * struct kdbus_name_list - information returned by KDBUS_CMD_NAME_LIST
655  * @size:               The total size of the structure
656  * @names:              A list of names
657  *
658  * Note that the user is responsible for freeing the allocated memory with
659  * the KDBUS_CMD_FREE ioctl.
660  */
661 struct kdbus_name_list {
662         __u64 size;
663         struct kdbus_cmd_name names[0];
664 };
665
666 /**
667  * struct kdbus_cmd_conn_info - struct used for KDBUS_CMD_CONN_INFO ioctl
668  * @size:               The total size of the struct
669  * @flags:              KDBUS_ATTACH_* flags
670  * @id:                 The 64-bit ID of the connection. If set to zero, passing
671  *                      @name is required. kdbus will look up the name to
672  *                      determine the ID in this case.
673  * @offset:             Returned offset in the caller's pool buffer where the
674  *                      kdbus_conn_info struct result is stored. The user must
675  *                      use KDBUS_CMD_FREE to free the allocated memory.
676  * @name:               The optional well-known name to look up. Only needed in
677  *                      case @id is zero.
678  *
679  * On success, the KDBUS_CMD_CONN_INFO ioctl will return 0 and @offset will
680  * tell the user the offset in the connection pool buffer at which to find the
681  * result in a struct kdbus_conn_info.
682  */
683 struct kdbus_cmd_conn_info {
684         __u64 size;
685         __u64 flags;
686         __u64 id;
687         __u64 offset;
688         char name[0];
689 } __attribute__((aligned(8)));
690
691 /**
692  * struct kdbus_conn_info - information returned by KDBUS_CMD_CONN_INFO
693  * @size:               The total size of the struct
694  * @id:                 The connection's 64-bit ID
695  * @flags:              The connection's flags
696  * @items:              A list of struct kdbus_item
697  *
698  * Note that the user is responsible for freeing the allocated memory with
699  * the KDBUS_CMD_FREE ioctl.
700  */
701 struct kdbus_conn_info {
702         __u64 size;
703         __u64 id;
704         __u64 flags;
705         struct kdbus_item items[0];
706 };
707
708 /**
709  * struct kdbus_cmd_update - update flags of a connection
710  * @size:               The total size of the struct
711  * @items:              A list of struct kdbus_item
712  *
713  * This struct is used with the KDBUS_CMD_CONN_UPDATE ioctl.
714  */
715 struct kdbus_cmd_update {
716         __u64 size;
717         struct kdbus_item items[0];
718 } __attribute__((aligned(8)));
719
720 /**
721  * struct kdbus_cmd_match - struct to add or remove matches
722  * @size:               The total size of the struct
723  * @cookie:             Userspace supplied cookie. When removing, the cookie
724  *                      identifies the match to remove
725  * @items:              A list of items for additional information
726  *
727  * This structure is used with the KDBUS_CMD_ADD_MATCH and
728  * KDBUS_CMD_REMOVE_MATCH ioctl.
729  */
730 struct kdbus_cmd_match {
731         __u64 size;
732         __u64 cookie;
733         struct kdbus_item items[0];
734 } __attribute__((aligned(8)));
735
736 /**
737  * enum kdbus_ioctl_type - Ioctl API
738  * @KDBUS_CMD_BUS_MAKE:         After opening the "control" device node, this
739  *                              command creates a new bus with the specified
740  *                              name. The bus is immediately shut down and
741  *                              cleaned up when the opened "control" device node
742  *                              is closed.
743  * @KDBUS_CMD_DOMAIN_MAKE:      Similar to KDBUS_CMD_BUS_MAKE, but it creates a
744  *                              new kdbus domain.
745  * @KDBUS_CMD_EP_MAKE:          Creates a new named special endpoint to talk to
746  *                              the bus. Such endpoints usually carry a more
747  *                              restrictive policy and grant restricted access
748  *                              to specific applications.
749  * @KDBUS_CMD_HELLO:            By opening the bus device node a connection is
750  *                              created. After a HELLO the opened connection
751  *                              becomes an active peer on the bus.
752  * @KDBUS_CMD_BYEBYE:           Disconnect a connection. If the connection's
753  *                              message list is empty, the calls succeeds, and
754  *                              the handle is rendered unusable. Otherwise,
755  *                              -EAGAIN is returned without any further side-
756  *                              effects.
757  * @KDBUS_CMD_MSG_SEND:         Send a message and pass data from userspace to
758  *                              the kernel.
759  * @KDBUS_CMD_MSG_RECV:         Receive a message from the kernel which is
760  *                              placed in the receiver's pool.
761  * @KDBUS_CMD_MSG_CANCEL:       Cancel a pending request of a message that
762  *                              blocks while waiting for a reply. The parameter
763  *                              denotes the cookie of the message in flight.
764  * @KDBUS_CMD_FREE:             Release the allocated memory in the receiver's
765  *                              pool.
766  * @KDBUS_CMD_NAME_ACQUIRE:     Request a well-known bus name to associate with
767  *                              the connection. Well-known names are used to
768  *                              address a peer on the bus.
769  * @KDBUS_CMD_NAME_RELEASE:     Release a well-known name the connection
770  *                              currently owns.
771  * @KDBUS_CMD_NAME_LIST:        Retrieve the list of all currently registered
772  *                              well-known and unique names.
773  * @KDBUS_CMD_CONN_INFO:        Retrieve credentials and properties of the
774  *                              initial creator of the connection. The data was
775  *                              stored at registration time and does not
776  *                              necessarily represent the connected process or
777  *                              the actual state of the process.
778  * @KDBUS_CMD_CONN_UPDATE:      Update the properties of a connection. Used to
779  *                              update the metadata subscription mask and
780  *                              policy.
781  * @KDBUS_CMD_EP_UPDATE:        Update the properties of a custom enpoint. Used
782  *                              to update the policy.
783  * @KDBUS_CMD_MATCH_ADD:        Install a match which broadcast messages should
784  *                              be delivered to the connection.
785  * @KDBUS_CMD_MATCH_REMOVE:     Remove a current match for broadcast messages.
786  */
787 enum kdbus_ioctl_type {
788         KDBUS_CMD_BUS_MAKE =            _IOW(KDBUS_IOCTL_MAGIC, 0x00,
789                                              struct kdbus_cmd_make),
790         KDBUS_CMD_DOMAIN_MAKE =         _IOW(KDBUS_IOCTL_MAGIC, 0x10,
791                                              struct kdbus_cmd_make),
792         KDBUS_CMD_EP_MAKE =             _IOW(KDBUS_IOCTL_MAGIC, 0x20,
793                                              struct kdbus_cmd_make),
794
795         KDBUS_CMD_HELLO =               _IOWR(KDBUS_IOCTL_MAGIC, 0x30,
796                                               struct kdbus_cmd_hello),
797         KDBUS_CMD_BYEBYE =              _IO(KDBUS_IOCTL_MAGIC, 0x31),
798
799         KDBUS_CMD_MSG_SEND =            _IOWR(KDBUS_IOCTL_MAGIC, 0x40,
800                                               struct kdbus_msg),
801         KDBUS_CMD_MSG_RECV =            _IOWR(KDBUS_IOCTL_MAGIC, 0x41,
802                                               struct kdbus_cmd_recv),
803         KDBUS_CMD_MSG_CANCEL =          _IOW(KDBUS_IOCTL_MAGIC, 0x42, __u64 *),
804         KDBUS_CMD_FREE =                _IOW(KDBUS_IOCTL_MAGIC, 0x43, __u64 *),
805
806         KDBUS_CMD_NAME_ACQUIRE =        _IOWR(KDBUS_IOCTL_MAGIC, 0x50,
807                                               struct kdbus_cmd_name),
808         KDBUS_CMD_NAME_RELEASE =        _IOW(KDBUS_IOCTL_MAGIC, 0x51,
809                                              struct kdbus_cmd_name),
810         KDBUS_CMD_NAME_LIST =           _IOWR(KDBUS_IOCTL_MAGIC, 0x52,
811                                              struct kdbus_cmd_name_list),
812
813         KDBUS_CMD_CONN_INFO =           _IOWR(KDBUS_IOCTL_MAGIC, 0x60,
814                                               struct kdbus_cmd_conn_info),
815         KDBUS_CMD_CONN_UPDATE =         _IOW(KDBUS_IOCTL_MAGIC, 0x61,
816                                              struct kdbus_cmd_update),
817
818         KDBUS_CMD_EP_UPDATE =           _IOW(KDBUS_IOCTL_MAGIC, 0x71,
819                                              struct kdbus_cmd_update),
820
821         KDBUS_CMD_MATCH_ADD =           _IOW(KDBUS_IOCTL_MAGIC, 0x80,
822                                              struct kdbus_cmd_match),
823         KDBUS_CMD_MATCH_REMOVE =        _IOW(KDBUS_IOCTL_MAGIC, 0x81,
824                                              struct kdbus_cmd_match),
825 };
826
827 /*
828  * errno - api error codes
829  * @E2BIG:              A message contains too many records or items.
830  * @EADDRINUSE:         A well-known bus name is already taken by another
831  *                      connection.
832  * @EADDRNOTAVAIL:      A message flagged not to activate a service, addressed
833  *                      a service which is not currently running.
834  * @EAGAIN:             No messages are queued at the moment.
835  * @EALREADY:           A requested name is already owned by the connection,
836  *                      a connection is already disconnected, memfd is already
837  *                      sealed or has the requested size.
838  * @EBADF:              File descriptors passed with the message are not valid.
839  * @EBADFD:             A bus connection is in a corrupted state.
840  * @EBADMSG:            Passed data contains a combination of conflicting or
841  *                      inconsistent types.
842  * @EBUSY:              The user tried to say BYEBYE to a connection, but the
843  *                      connection had a non-empty message list.
844  * @ECANCELED:          A synchronous message sending was cancelled.
845  * @ECONNRESET:         A connection is shut down, no further operations are
846  *                      possible.
847  * @ECOMM:              A peer does not accept the file descriptors addressed
848  *                      to it.
849  * @EDESTADDRREQ:       The well-known bus name is required but missing.
850  * @EDOM:               The size of data does not match the expectations. Used
851  *                      for bloom bit field sizes.
852  * @EEXIST:             A requested domain, bus or endpoint with the same
853  *                      name already exists.  A specific data type, which is
854  *                      only expected once, is provided multiple times.
855  * @EFAULT:             The supplied memory could not be accessed, the data
856  *                      is not properly aligned, or the current task's memory
857  *                      is inaccessible.
858  * @EINVAL:             The provided data does not match its type or other
859  *                      expectations, like a string which is not NUL terminated,
860  *                      or a string length that points behind the first
861  *                      \0-byte in the string.
862  * @EMEDIUMTYPE:        A file descriptor which is not a kdbus memfd was
863  *                      refused to send as KDBUS_MSG_PAYLOAD_MEMFD.
864  * @EMFILE:             Too many file descriptors have been supplied with a
865  *                      message.
866  *                      Too many connections or buses are created for a given
867  *                      user.
868  * @EMLINK:             Too many requests from this connection to other peers
869  *                      are queued and waiting for a reply
870  * @EMSGSIZE:           The supplied data is larger than the allowed maximum
871  *                      size.
872  * @ENAMETOOLONG:       The requested name is larger than the allowed maximum
873  *                      size.
874  * @ENOBUFS:            There is no space left for the submitted data to fit
875  *                      into the receiver's pool.
876  * @ENOENT:             The to be cancelled message was not found.
877  * @ENOMEM:             Out of memory.
878  * @ENOMSG:             The queue is not empty, but no message with a matching
879  *                      priority is currently queued.
880  * @ENOSYS:             The requested functionality is not available.
881  * @ENOTTY:             An unknown ioctl command was received.
882  * @ENOTUNIQ:           A specific data type was addressed to a broadcast
883  *                      address, but only direct addresses support this kind of
884  *                      data.
885  * @ENXIO:              A unique address does not exist, or an offset in the
886  *                      receiver's pool does not represent a queued message.
887  * @EOPNOTSUPP:         The feature negotiation failed, a not supported feature
888  *                      was requested, or an unknown item type was received.
889  * @EPERM:              The policy prevented an operation. The requested
890  *                      resource is owned by another entity.
891  * @EPIPE:              When sending a message, a synchronous reply from the
892  *                      receiving connection was expected but the connection
893  *                      died before answering.
894  * @ESHUTDOWN:          A domain, bus or endpoint is currently shutting down;
895  *                      no further operations will be possible.
896  * @ESRCH:              A requested well-known bus name is not found.
897  * @ETIMEDOUT:          A synchronous wait for a message reply did not arrive
898  *                      within the specified time frame.
899  * @ETXTBSY:            A kdbus memfd file cannot be sealed or the seal removed,
900  *                      because it is shared with other processes or still
901  *                      mmap()ed.
902  * @EXFULL:             The size limits in the pool are reached, no data of
903  *                      the size tried to submit can be queued.
904  */
905 #endif