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