chiark / gitweb /
bus: sync with kdbus
[elogind.git] / src / libsystemd-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
14 #ifndef _KDBUS_H_
15 #define _KDBUS_H_
16
17 #ifndef __KERNEL__
18 #include <sys/ioctl.h>
19 #include <sys/types.h>
20 #include <linux/types.h>
21 #endif
22
23 #define KDBUS_IOC_MAGIC                 0x95
24 #define KDBUS_SRC_ID_KERNEL             (0)
25 #define KDBUS_DST_ID_NAME               (0)
26 #define KDBUS_MATCH_SRC_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:             Former owner of a name
49  * @new_id:             New owner of a name
50  * @old_flags:          flags from KDBUS_NAME_* the name entry used to have
51  * @new_flags:          flags from KDBUS_NAME_* the name entry has now
52  * @name:               Well-known name
53  *
54  * Sent from kernel to userspace when the owner or activator of
55  * a well-known name changes.
56  *
57  * Attached to:
58  *   KDBUS_ITEM_NAME_ADD
59  *   KDBUS_ITEM_NAME_REMOVE
60  *   KDBUS_ITEM_NAME_CHANGE
61  */
62 struct kdbus_notify_name_change {
63         struct kdbus_notify_id_change old;
64         struct kdbus_notify_id_change new;
65         char name[0];
66 };
67
68 /**
69  * struct kdbus_creds - process credentials
70  * @uid:                User ID
71  * @gid:                Group ID
72  * @pid:                Process ID
73  * @tid:                Thread ID
74  * @starttime:          Starttime of the process
75  *
76  * The starttime of the process PID. This is useful to detect PID overruns
77  * from the client side. i.e. if you use the PID to look something up in
78  * /proc/$PID/ you can afterwards check the starttime field of it, to ensure
79  * you didn't run into a PID overrun.
80  *
81  * Attached to:
82  *   KDBUS_ITEM_CREDS
83  */
84 struct kdbus_creds {
85         __u64 uid;
86         __u64 gid;
87         __u64 pid;
88         __u64 tid;
89         __u64 starttime;
90 };
91
92 /**
93  * struct kdbus_audit - audit information
94  * @sessionid:          The audit session ID
95  * @loginuid:           The audit login uid
96  *
97  * Attached to:
98  *   KDBUS_ITEM_AUDIT
99  */
100 struct kdbus_audit {
101         __u64 sessionid;
102         __u64 loginuid;
103 };
104
105 /**
106  * struct kdbus_timestamp
107  * @monotonic_ns:       Monotonic timestamp, in nanoseconds
108  * @realtime_ns:        Realtime timestamp, in nanoseconds
109  *
110  * Attached to:
111  *   KDBUS_ITEM_TIMESTAMP
112  */
113 struct kdbus_timestamp {
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 for memory addresses
122  * @offset:             Offset in the in-message payload memory
123  *
124  * Attached to:
125  *   KDBUS_ITEM_PAYLOAD_VEC
126  */
127 struct kdbus_vec {
128         __u64 size;
129         union {
130                 __u64 address;
131                 __u64 offset;
132         };
133 };
134
135 /**
136  * struct kdbus_memfd - a kdbus memfd
137  * @size:               The memfd's size
138  * @fd:                 The file descriptor number
139  * @__pad:              Padding to make the struct aligned
140  *
141  * Attached to:
142  *   KDBUS_ITEM_PAYLOAD_MEMFD
143  */
144 struct kdbus_memfd {
145         __u64 size;
146         int fd;
147         __u32 __pad;
148 };
149
150 /**
151  * struct kdbus_name - a registered well-known name with its flags
152  * @flags:              flags from KDBUS_NAME_*
153  * @name:               well-known name
154  *
155  * Attached to:
156  *   KDBUS_ITEM_NAME
157  */
158 struct kdbus_name {
159         __u64 flags;
160         char name[0];
161 };
162
163 /**
164  * struct kdbus_policy_access - policy access item
165  * @type:               One of KDBUS_POLICY_ACCESS_* types
166  * @bits:               Access to grant. One of KDBUS_POLICY_*
167  * @id:                 For KDBUS_POLICY_ACCESS_USER, the uid
168  *                      For KDBUS_POLICY_ACCESS_GROUP, the gid
169  *
170  * Embedded in:
171  *   struct kdbus_policy
172  */
173 struct kdbus_policy_access {
174         __u64 type;     /* USER, GROUP, WORLD */
175         __u64 bits;     /* RECV, SEND, OWN */
176         __u64 id;       /* uid, gid, 0 */
177 };
178
179 /**
180  * struct kdbus_policy - a policy item
181  * @access:             Policy access details
182  * @name:               Well-known name to grant access to
183  *
184  * Attached to:
185  *   KDBUS_POLICY_ACCESS
186  *   KDBUS_ITEM_POLICY_NAME
187  */
188 struct kdbus_policy {
189         union {
190                 struct kdbus_policy_access access;
191                 char name[0];
192         };
193 };
194
195 /**
196  * enum kdbus_item_type - item types to chain data in a list
197  * @KDBUS_ITEM_PAYLOAD_VEC:     Vector to data
198  * @KDBUS_ITEM_PAYLOAD_OFF:     Data at returned offset in the pool
199  * @KDBUS_ITEM_PAYLOAD_MEMFD:   Data as sealed memfd
200  * @KDBUS_ITEM_FDS:             Attached file descriptors
201  * @KDBUS_ITEM_BLOOM:           For broadcasts, carries bloom filter
202  * @KDBUS_ITEM_BLOOM_SIZE:      Desired bloom size, used by KDBUS_CMD_BUS_MAKE
203  * @KDBUS_ITEM_DST_NAME:        Destination's well-known name
204  * @KDBUS_ITEM_PRIORITY:        Queue priority for message
205  * @KDBUS_ITEM_MAKE_NAME:       Name of namespace, bus, endpoint
206  * @KDBUS_ITEM_POLICY_NAME:     Policy in struct kdbus_policy
207  * @KDBUS_ITEM_POLICY_ACCESS:   Policy in struct kdbus_policy
208  * @KDBUS_ITEM_NAME:            Well-know name with flags
209  * @KDBUS_ITEM_TIMESTAMP:       Timestamp
210  * @KDBUS_ITEM_CREDS:           Process credential
211  * @KDBUS_ITEM_PID_COMM:        Process ID "comm" identifier
212  * @KDBUS_ITEM_TID_COMM:        Thread ID "comm" identifier
213  * @KDBUS_ITEM_EXE:             The path of the executable
214  * @KDBUS_ITEM_CMDLINE:         The process command line
215  * @KDBUS_ITEM_CGROUP:          The croup membership
216  * @KDBUS_ITEM_CAPS:            The process capabilities
217  * @KDBUS_ITEM_SECLABEL:        The security label
218  * @KDBUS_ITEM_AUDIT:           The audit IDs
219  * @KDBUS_ITEM_NAME_ADD:        Notify in struct kdbus_notify_name_change
220  * @KDBUS_ITEM_NAME_REMOVE:     Notify in struct kdbus_notify_name_change
221  * @KDBUS_ITEM_NAME_CHANGE:     Notify in struct kdbus_notify_name_change
222  * @KDBUS_ITEM_ID_ADD:          Notify in struct kdbus_notify_id_change
223  * @KDBUS_ITEM_ID_REMOVE:       Notify in struct kdbus_notify_id_change
224  * @KDBUS_ITEM_REPLY_TIMEOUT:   Timeout has been reached
225  * @KDBUS_ITEM_REPLY_DEAD:      Destination died
226  */
227 enum kdbus_item_type {
228         _KDBUS_ITEM_NULL,
229         _KDBUS_ITEM_USER_BASE,
230         KDBUS_ITEM_PAYLOAD_VEC  = _KDBUS_ITEM_USER_BASE,
231         KDBUS_ITEM_PAYLOAD_OFF,
232         KDBUS_ITEM_PAYLOAD_MEMFD,
233         KDBUS_ITEM_FDS,
234         KDBUS_ITEM_BLOOM,
235         KDBUS_ITEM_BLOOM_SIZE,
236         KDBUS_ITEM_DST_NAME,
237         KDBUS_ITEM_PRIORITY,
238         KDBUS_ITEM_MAKE_NAME,
239
240         _KDBUS_ITEM_POLICY_BASE = 0x400,
241         KDBUS_ITEM_POLICY_NAME = _KDBUS_ITEM_POLICY_BASE,
242         KDBUS_ITEM_POLICY_ACCESS,
243
244         _KDBUS_ITEM_ATTACH_BASE = 0x600,
245         KDBUS_ITEM_NAME         = _KDBUS_ITEM_ATTACH_BASE,
246         KDBUS_ITEM_TIMESTAMP,
247         KDBUS_ITEM_CREDS,
248         KDBUS_ITEM_PID_COMM,
249         KDBUS_ITEM_TID_COMM,
250         KDBUS_ITEM_EXE,
251         KDBUS_ITEM_CMDLINE,
252         KDBUS_ITEM_CGROUP,
253         KDBUS_ITEM_CAPS,
254         KDBUS_ITEM_SECLABEL,
255         KDBUS_ITEM_AUDIT,
256
257         _KDBUS_ITEM_KERNEL_BASE = 0x800,
258         KDBUS_ITEM_NAME_ADD     = _KDBUS_ITEM_KERNEL_BASE,
259         KDBUS_ITEM_NAME_REMOVE,
260         KDBUS_ITEM_NAME_CHANGE,
261         KDBUS_ITEM_ID_ADD,
262         KDBUS_ITEM_ID_REMOVE,
263         KDBUS_ITEM_REPLY_TIMEOUT,
264         KDBUS_ITEM_REPLY_DEAD,
265 };
266
267 /**
268  * struct kdbus_item - chain of data blocks
269  * @size:               Overall data record size
270  * @type:               Kdbus_item type of data
271  * @data:               Generic bytes
272  * @data32:             Generic 32 bit array
273  * @data64:             Generic 64 bit array
274  * @str:                Generic string
275  * @id:                 Connection ID
276  * @vec:                KDBUS_ITEM_PAYLOAD_VEC
277  * @creds:              KDBUS_ITEM_CREDS
278  * @audit:              KDBUS_ITEM_AUDIT
279  * @timestamp:          KDBUS_ITEM_TIMESTAMP
280  * @name:               KDBUS_ITEM_NAME
281  * @memfd:              KDBUS_ITEM_PAYLOAD_MEMFD
282  * @name_change:        KDBUS_ITEM_NAME_ADD
283  *                      KDBUS_ITEM_NAME_REMOVE
284  *                      KDBUS_ITEM_NAME_CHANGE
285  * @id_change:          KDBUS_ITEM_ID_ADD
286  *                      KDBUS_ITEM_ID_REMOVE
287  * @policy:             KDBUS_ITEM_POLICY_NAME
288  *                      KDBUS_ITEM_POLICY_ACCESS
289  */
290 struct kdbus_item {
291         __u64 size;
292         __u64 type;
293         union {
294                 __u8 data[0];
295                 __u32 data32[0];
296                 __u64 data64[0];
297                 char str[0];
298
299                 __u64 id;
300                 struct kdbus_vec vec;
301                 struct kdbus_creds creds;
302                 struct kdbus_audit audit;
303                 struct kdbus_timestamp timestamp;
304                 struct kdbus_name name;
305                 struct kdbus_memfd memfd;
306                 int fds[0];
307                 struct kdbus_notify_name_change name_change;
308                 struct kdbus_notify_id_change id_change;
309                 struct kdbus_policy policy;
310         };
311 };
312
313 /**
314  * enum kdbus_msg_flags - type of message
315  * @KDBUS_MSG_FLAGS_EXPECT_REPLY:       Expect a reply message, used for method
316  *                                      calls. The cookie identifies the
317  *                                      message and the respective reply
318  * @KDBUS_MSG_FLAGS_NO_AUTO_START:      Do not start a service, if the addressed
319  *                                      name is not currently active
320  */
321 enum kdbus_msg_flags {
322         KDBUS_MSG_FLAGS_EXPECT_REPLY    = 1 << 0,
323         KDBUS_MSG_FLAGS_NO_AUTO_START   = 1 << 1,
324 };
325
326 /**
327  * enum kdbus_payload_type - type of payload carried by message
328  * @KDBUS_PAYLOAD_KERNEL:       Kernel-generated simple message
329  * @KDBUS_PAYLOAD_DBUS:         D-Bus marshalling
330  */
331 enum kdbus_payload_type {
332         KDBUS_PAYLOAD_KERNEL,
333         KDBUS_PAYLOAD_DBUS      = 0x4442757344427573ULL, /* 'DBusDBus' */
334 };
335
336 /**
337  * struct kdbus_msg - the representation of a kdbus message
338  * @size:               Total size of the message
339  * @flags:              Message flags (KDBUS_MSG_FLAGS_*)
340  * @dst_id:             64-bit ID of the destination connection
341  * @src_id:             64-bit ID of the source connection
342  * @payload_type:       Payload type (KDBUS_PAYLOAD_*)
343  * @cookie:             Userspace-supplied cookie
344  * @cookie_reply:       For kernel-generated messages, this is the cookie
345  *                      the message is a reply to
346  * @timeout_ns:         For non-kernel-generated messages, this denotes the
347  *                      message timeout in nanoseconds. A message has to be
348  *                      received with KDBUS_CMD_MSG_RECV by the destination
349  *                      connection within this time frame. For messages that
350  *                      have KDBUS_MSG_FLAGS_EXPECT_REPLY set in @flags,
351  *                      this value also denotes the timeout for the reply to
352  *                      this message. If there is no reply, or the message is
353  *                      not received in time by the other side, a
354  *                      kernel-generated message with an attached
355  *                      KDBUS_ITEM_REPLY_TIMEOUT item is sent to @src_id.
356  *                      A 0-value is only valid if KDBUS_MSG_FLAGS_EXPECT_REPLY
357  *                      is unset in @flags.
358  * @items:              A list of kdbus_items containing the message payload
359  */
360 struct kdbus_msg {
361         __u64 size;
362         __u64 flags;
363         __u64 dst_id;
364         __u64 src_id;
365         __u64 payload_type;
366         __u64 cookie;
367         union {
368                 __u64 cookie_reply;
369                 __u64 timeout_ns;
370         };
371         struct kdbus_item items[0];
372 } __attribute__((aligned(8)));
373
374 /**
375  * enum kdbus_policy_access_type - permissions of a policy record
376  * @KDBUS_POLICY_ACCESS_USER:   Grant access to a uid
377  * @KDBUS_POLICY_ACCESS_GROUP:  Grant access to gid
378  * @KDBUS_POLICY_ACCESS_WORLD:  World-accessible
379  */
380 enum kdbus_policy_access_type {
381         _KDBUS_POLICY_ACCESS_NULL,
382         KDBUS_POLICY_ACCESS_USER,
383         KDBUS_POLICY_ACCESS_GROUP,
384         KDBUS_POLICY_ACCESS_WORLD,
385 };
386
387 /**
388  * enum kdbus_policy_access_flags - mode flags
389  * @KDBUS_POLICY_RECV:          Allow receive
390  * @KDBUS_POLICY_SEND:          Allow send
391  * @KDBUS_POLICY_OWN:           Allow to own a well-known name
392  */
393 enum kdbus_policy_type {
394         KDBUS_POLICY_RECV               = 1 <<  2,
395         KDBUS_POLICY_SEND               = 1 <<  1,
396         KDBUS_POLICY_OWN                = 1 <<  0,
397 };
398
399 /**
400  * struct kdbus_cmd_policy - a series of policies to upload
401  * @size:               The total size of the structure
402  * @policies:           The policies to upload
403  *
404  * A KDBUS_POLICY_NAME must always preceeds a KDBUS_POLICY_ACCESS entry.
405  * A new KDBUS_POLICY_NAME can be added after KDBUS_POLICY_ACCESS for
406  * chaining multiple policies together.
407  */
408 struct kdbus_cmd_policy {
409         __u64 size;
410         struct kdbus_item policies[0];
411 } __attribute__((aligned(8)));
412
413 /**
414  * enum kdbus_hello_flags - flags for struct kdbus_cmd_hello
415  * @KDBUS_HELLO_ACCEPT_FD:      The connection allows the receiving of
416  *                              any passed file descriptors
417  * @KDBUS_HELLO_ACTIVATOR:      Special-purpose connection which registers
418  *                              a well-know name for a process to be started
419  *                              when traffic arrives
420  * @KDBUS_HELLO_MONITOR:        Special-purpose connection to monitor
421  *                              bus traffic
422  */
423 enum kdbus_hello_flags {
424         KDBUS_HELLO_ACCEPT_FD           =  1 <<  0,
425         KDBUS_HELLO_ACTIVATOR           =  1 <<  1,
426         KDBUS_HELLO_MONITOR             =  1 <<  2,
427 };
428
429 /**
430  * enum kdbus_attach_flags - flags for metadata attachments
431  * @KDBUS_ATTACH_TIMESTAMP:     Timestamp
432  * @KDBUS_ATTACH_CREDS:         Credentials
433  * @KDBUS_ATTACH_NAMES:         Well-known names
434  * @KDBUS_ATTACH_COMM:          The "comm" process identifier
435  * @KDBUS_ATTACH_EXE:           The path of the executable
436  * @KDBUS_ATTACH_CMDLINE:       The process command line
437  * @KDBUS_ATTACH_CGROUP:        The croup membership
438  * @KDBUS_ATTACH_CAPS:          The process capabilities
439  * @KDBUS_ATTACH_SECLABEL:      The security label
440  * @KDBUS_ATTACH_AUDIT:         The audit IDs
441  */
442 enum kdbus_attach_flags {
443         KDBUS_ATTACH_TIMESTAMP          =  1 <<  0,
444         KDBUS_ATTACH_CREDS              =  1 <<  1,
445         KDBUS_ATTACH_NAMES              =  1 <<  2,
446         KDBUS_ATTACH_COMM               =  1 <<  3,
447         KDBUS_ATTACH_EXE                =  1 <<  4,
448         KDBUS_ATTACH_CMDLINE            =  1 <<  5,
449         KDBUS_ATTACH_CGROUP             =  1 <<  6,
450         KDBUS_ATTACH_CAPS               =  1 <<  7,
451         KDBUS_ATTACH_SECLABEL           =  1 <<  8,
452         KDBUS_ATTACH_AUDIT              =  1 <<  9,
453 };
454
455 /**
456  * struct kdbus_cmd_hello - struct to say hello to kdbus
457  * @size:               The total size of the structure
458  * @conn_flags:         Connection flags (KDBUS_HELLO_*). The kernel will
459  *                      return its capabilities in that field.
460  * @attach_flags:       Mask of metadata to attach to each message sent
461  *                      (KDBUS_ATTACH_*)
462  * @bus_flags:          The flags field copied verbatim from the original
463  *                      KDBUS_CMD_BUS_MAKE ioctl. It's intended to be useful
464  *                      to do negotiation of features of the payload that is
465  *                      transferred (kernel â†’ userspace)
466  * @id:                 The ID of this connection (kernel â†’ userspace)
467  * @bloom_size:         The bloom filter size chosen by the owner
468  *                      (kernel â†’ userspace)
469  * @pool_size:          Maximum size of the pool buffer (kernel â†’ userspace)
470  * @id128:              Unique 128-bit ID of the bus (kernel â†’ userspace)
471  * @items:              A list of items
472  *
473  * This struct is used with the KDBUS_CMD_HELLO ioctl. See the ioctl
474  * documentation for more information.
475  */
476 struct kdbus_cmd_hello {
477         __u64 size;
478         __u64 conn_flags;
479         __u64 attach_flags;
480         __u64 bus_flags;
481         __u64 id;
482         __u64 bloom_size;
483         __u64 pool_size;
484         __u8 id128[16];
485         struct kdbus_item items[0];
486 } __attribute__((aligned(8)));
487
488 /* Flags for KDBUS_CMD_{BUS,EP,NS}_MAKE */
489 enum kdbus_make_flags {
490         KDBUS_MAKE_ACCESS_GROUP         = 1 <<  0,
491         KDBUS_MAKE_ACCESS_WORLD         = 1 <<  1,
492         KDBUS_MAKE_POLICY_OPEN          = 1 <<  2,
493 };
494
495 /**
496  * struct kdbus_cmd_make - struct to make a bus, an endpoint or a namespace
497  * @size:               The total size of the struct
498  * @flags:              Properties for the bus/ep/ns to create
499  * @items:              Items describing details
500  *
501  * This structure is used with the KDBUS_CMD_BUS_MAKE, KDBUS_CMD_EP_MAKE and
502  * KDBUS_CMD_NS_MAKE ioctls.
503  */
504 struct kdbus_cmd_make {
505         __u64 size;
506         __u64 flags;
507         struct kdbus_item items[0];
508 } __attribute__((aligned(8)));
509
510 /**
511  * enum kdbus_name_flags - properties of a well-known name
512  * @KDBUS_NAME_REPLACE_EXISTING:        Try to replace name of other connections
513  * @KDBUS_NAME_ALLOW_REPLACEMENT:       Allow the replacement of the name
514  * @KDBUS_NAME_QUEUE:                   Name should be queued if busy
515  * @KDBUS_NAME_IN_QUEUE:                Name is queued
516  * @KDBUS_NAME_ACTIVATOR:               Name is owned by a activator connection
517  */
518 enum kdbus_name_flags {
519         KDBUS_NAME_REPLACE_EXISTING     = 1 <<  0,
520         KDBUS_NAME_ALLOW_REPLACEMENT    = 1 <<  1,
521         KDBUS_NAME_QUEUE                = 1 <<  2,
522         KDBUS_NAME_IN_QUEUE             = 1 <<  3,
523         KDBUS_NAME_ACTIVATOR            = 1 <<  4,
524 };
525
526 /**
527  * struct kdbus_cmd_name - struct to describe a well-known name
528  * @size:               The total size of the struct
529  * @flags:              Flags for a name entry (KDBUS_NAME_*)
530  * @id:                 Privileged users may use this field to (de)register
531  *                      names on behalf of other peers.
532  * @conn_flags:         The flags of the owning connection (KDBUS_HELLO_*)
533  * @name:               The well-known name
534  *
535  * This structure is used with the KDBUS_CMD_NAME_ACQUIRE ioctl.
536  */
537 struct kdbus_cmd_name {
538         __u64 size;
539         __u64 flags;
540         __u64 id;
541         __u64 conn_flags;
542         char name[0];
543 } __attribute__((aligned(8)));
544
545 /**
546  * enum kdbus_name_list_flags - what to include into the returned list
547  * @KDBUS_NAME_LIST_UNIQUE:     All active connections
548  * @KDBUS_NAME_LIST_NAMES:      All known well-known names
549  * @KDBUS_NAME_LIST_ACTIVATORS: All activator connections
550  * @KDBUS_NAME_LIST_QUEUED:     All queued-up names
551  */
552 enum kdbus_name_list_flags {
553         KDBUS_NAME_LIST_UNIQUE          = 1 <<  0,
554         KDBUS_NAME_LIST_NAMES           = 1 <<  1,
555         KDBUS_NAME_LIST_ACTIVATORS      = 1 <<  2,
556         KDBUS_NAME_LIST_QUEUED          = 1 <<  3,
557 };
558
559 /**
560  * struct kdbus_cmd_name_list - request a list of name entries
561  * @flags:              Flags for the query (KDBUS_NAME_LIST_*)
562  * @offset:             The returned offset in the caller's pool buffer.
563  *                      The user must use KDBUS_CMD_FREE to free the
564  *                      allocated memory.
565  *
566  * This structure is used with the KDBUS_CMD_NAME_LIST ioctl.
567  */
568 struct kdbus_cmd_name_list {
569         __u64 flags;
570         __u64 offset;
571 } __attribute__((aligned(8)));
572
573 /**
574  * struct kdbus_name_list - information returned by KDBUS_CMD_NAME_LIST
575  * @size:               The total size of the structure
576  * @names:              A list of names
577  *
578  * Note that the user is responsible for freeing the allocated memory with
579  * the KDBUS_CMD_FREE ioctl.
580  */
581 struct kdbus_name_list {
582         __u64 size;
583         struct kdbus_cmd_name names[0];
584 };
585
586 /**
587  * struct kdbus_cmd_conn_info - struct used for KDBUS_CMD_CONN_INFO ioctl
588  * @size:               The total size of the struct
589  * @flags:              KDBUS_ATTACH_* flags
590  * @id:                 The 64-bit ID of the connection. If set to zero, passing
591  *                      @name is required. kdbus will look up the name to determine
592  *                      the ID in this case.
593  * @offset:             Returned offset in the caller's pool buffer where the
594  *                      kdbus_conn_info struct result is stored. The user must
595  *                      use KDBUS_CMD_FREE to free the allocated memory.
596  * @name:               The optional well-known name to look up. Only needed in
597  *                      case @id is zero.
598  *
599  * On success, the KDBUS_CMD_CONN_INFO ioctl will return 0 and @offset will
600  * tell the user the offset in the connection pool buffer at which to find the
601  * result in a struct kdbus_conn_info.
602  */
603 struct kdbus_cmd_conn_info {
604         __u64 size;
605         __u64 flags;
606         __u64 id;
607         __u64 offset;
608         char name[0];
609 } __attribute__((aligned(8)));
610
611 /**
612  * struct kdbus_conn_info - information returned by KDBUS_CMD_CONN_INFO
613  * @size:               The total size of the struct
614  * @id:                 The connection's 64-bit ID
615  * @flags:              The connection's flags
616  * @items:              A list of struct kdbus_item
617  *
618  * Note that the user is responsible for freeing the allocated memory with
619  * the KDBUS_CMD_FREE ioctl.
620  */
621 struct kdbus_conn_info {
622         __u64 size;
623         __u64 id;
624         __u64 flags;
625         struct kdbus_item items[0];
626 };
627
628 /**
629  * enum kdbus_match_type - type of match record
630  * @KDBUS_MATCH_BLOOM:          Matches against KDBUS_MSG_BLOOM
631  * @KDBUS_MATCH_SRC_NAME:       Matches a name string
632  * @KDBUS_MATCH_NAME_ADD:       Matches a name string
633  * @KDBUS_MATCH_NAME_REMOVE:    Matches a name string
634  * @KDBUS_MATCH_NAME_CHANGE:    Matches a name string
635  * @KDBUS_MATCH_ID_ADD:         Matches an ID
636  * @KDBUS_MATCH_ID_REMOVE:      Matches an ID
637  */
638 enum kdbus_match_type {
639         _KDBUS_MATCH_NULL,
640         KDBUS_MATCH_BLOOM,
641         KDBUS_MATCH_SRC_NAME,
642         KDBUS_MATCH_NAME_ADD,
643         KDBUS_MATCH_NAME_REMOVE,
644         KDBUS_MATCH_NAME_CHANGE,
645         KDBUS_MATCH_ID_ADD,
646         KDBUS_MATCH_ID_REMOVE,
647 };
648
649 /**
650  * struct kdbus_cmd_match - struct to add or remove matches
651  * @size:               The total size of the struct
652  * @id:                 Privileged users may (de)register matches on behalf
653  *                      of other peers. In other cases, set to 0.
654  * @cookie:             Userspace supplied cookie. When removing, the cookie
655  *                      identifies the match to remove.
656  * @src_id:             The source ID to match against. Use
657  *                      KDBUS_MATCH_SRC_ID_ANY or any other value for a unique
658  *                      match.
659  * @items:              A list of items for additional information
660  *
661  * This structure is used with the KDBUS_CMD_ADD_MATCH and
662  * KDBUS_CMD_REMOVE_MATCH ioctl.
663  */
664 struct kdbus_cmd_match {
665         __u64 size;
666         __u64 id;
667         __u64 cookie;
668         __u64 src_id;
669         struct kdbus_item items[0];
670 } __attribute__((aligned(8)));
671
672 /**
673  * enum kdbus_ioctl_type - Ioctl API
674  * @KDBUS_CMD_BUS_MAKE:         After opening the "control" device node, this
675  *                              command creates a new bus with the specified
676  *                              name. The bus is immediately shut down and
677  *                              cleaned up when the opened "control" device node
678  *                              is closed.
679  * @KDBUS_CMD_NS_MAKE:          Similar to KDBUS_CMD_BUS_MAKE, but it creates a
680  *                              new kdbus namespace.
681  * @KDBUS_CMD_EP_MAKE:          Creates a new named special endpoint to talk to
682  *                              the bus. Such endpoints usually carry a more
683  *                              restrictive policy and grant restricted access
684  *                              to specific applications.
685  * @KDBUS_CMD_HELLO:            By opening the bus device node a connection is
686  *                              created. After a HELLO the opened connection
687  *                              becomes an active peer on the bus.
688  * @KDBUS_CMD_BYEBYE:           Disconnect a connection. If the connection's
689  *                              message list is empty, the calls succeeds, and
690  *                              the handle is rendered unusable. Otherwise,
691  *                              -EAGAIN is returned without any further side-
692  *                              effects.
693  * @KDBUS_CMD_MSG_SEND:         Send a message and pass data from userspace to
694  *                              the kernel.
695  * @KDBUS_CMD_MSG_RECV:         Receive a message from the kernel which is
696  *                              placed in the receiver's pool.
697  * @KDBUS_CMD_FREE:             Release the allocated memory in the receiver's
698  *                              pool.
699  * @KDBUS_CMD_DROP:             Drop and free the next queued message and all
700  *                              its ressources without actually receiveing it.
701  * @KDBUS_CMD_SRC:              Return the sender's connection ID of the next
702  *                              queued message.
703  * @KDBUS_CMD_NAME_ACQUIRE:     Request a well-known bus name to associate with
704  *                              the connection. Well-known names are used to
705  *                              address a peer on the bus.
706  * @KDBUS_CMD_NAME_RELEASE:     Release a well-known name the connection
707  *                              currently owns.
708  * @KDBUS_CMD_NAME_LIST:        Retrieve the list of all currently registered
709  *                              well-known and unique names.
710  * @KDBUS_CMD_CONN_INFO:        Retrieve credentials and properties of the
711  *                              initial creator of the connection. The data was
712  *                              stored at registration time and does not
713  *                              necessarily represent the connected process or
714  *                              the actual state of the process.
715  * @KDBUS_CMD_MATCH_ADD:        Install a match which broadcast messages should
716  *                              be delivered to the connection.
717  * @KDBUS_CMD_MATCH_REMOVE:     Remove a current match for broadcast messages.
718  * @KDBUS_CMD_EP_POLICY_SET:    Set the policy of an endpoint. It is used to
719  *                              restrict the access for endpoints created with
720  *                              KDBUS_CMD_EP_MAKE.
721  * @KDBUS_CMD_MEMFD_NEW:        Return a new file descriptor which provides an
722  *                              anonymous shared memory file and which can be
723  *                              used to pass around larger chunks of data.
724  *                              Kdbus memfd files can be sealed, which allows
725  *                              the receiver to trust the data it has received.
726  *                              Kdbus memfd files expose only very limited
727  *                              operations, they can be mmap()ed, seek()ed,
728  *                              (p)read(v)() and (p)write(v)(); most other
729  *                              common file operations are not implemented.
730  *                              Special caution needs to be taken with
731  *                              read(v)()/write(v)() on a shared file; the
732  *                              underlying file position is always shared
733  *                              between all users of the file and race against
734  *                              each other, pread(v)()/pwrite(v)() avoid these
735  *                              issues.
736  * @KDBUS_CMD_MEMFD_SIZE_GET:   Return the size of the underlying file, which
737  *                              changes with write().
738  * @KDBUS_CMD_MEMFD_SIZE_SET:   Truncate the underlying file to the specified
739  *                              size.
740  * @KDBUS_CMD_MEMFD_SEAL_GET:   Return the state of the file sealing.
741  * @KDBUS_CMD_MEMFD_SEAL_SET:   Seal or break a seal of the file. Only files
742  *                              which are not shared with other processes and
743  *                              which are currently not mapped can be sealed.
744  *                              The current process needs to be the one and
745  *                              single owner of the file, the sealing cannot
746  *                              be changed as long as the file is shared.
747  */
748 enum kdbus_ioctl_type {
749         KDBUS_CMD_BUS_MAKE =            _IOW (KDBUS_IOC_MAGIC, 0x00, struct kdbus_cmd_make),
750         KDBUS_CMD_NS_MAKE =             _IOR (KDBUS_IOC_MAGIC, 0x10, struct kdbus_cmd_make),
751         KDBUS_CMD_EP_MAKE =             _IOW (KDBUS_IOC_MAGIC, 0x20, struct kdbus_cmd_make),
752
753         KDBUS_CMD_HELLO =               _IOWR(KDBUS_IOC_MAGIC, 0x30, struct kdbus_cmd_hello),
754         KDBUS_CMD_BYEBYE =              _IO  (KDBUS_IOC_MAGIC, 0x31),
755
756         KDBUS_CMD_MSG_SEND =            _IOW (KDBUS_IOC_MAGIC, 0x40, struct kdbus_msg),
757         KDBUS_CMD_MSG_RECV =            _IOR (KDBUS_IOC_MAGIC, 0x41, __u64 *),
758         KDBUS_CMD_FREE =                _IOW (KDBUS_IOC_MAGIC, 0x42, __u64 *),
759         KDBUS_CMD_MSG_DROP =            _IO  (KDBUS_IOC_MAGIC, 0x43),
760         KDBUS_CMD_MSG_SRC =             _IOR (KDBUS_IOC_MAGIC, 0x44, __u64 *),
761
762         KDBUS_CMD_NAME_ACQUIRE =        _IOWR(KDBUS_IOC_MAGIC, 0x50, struct kdbus_cmd_name),
763         KDBUS_CMD_NAME_RELEASE =        _IOW (KDBUS_IOC_MAGIC, 0x51, struct kdbus_cmd_name),
764         KDBUS_CMD_NAME_LIST =           _IOWR(KDBUS_IOC_MAGIC, 0x52, struct kdbus_cmd_name_list),
765
766         KDBUS_CMD_CONN_INFO =           _IOWR(KDBUS_IOC_MAGIC, 0x60, struct kdbus_cmd_conn_info),
767
768         KDBUS_CMD_MATCH_ADD =           _IOW (KDBUS_IOC_MAGIC, 0x70, struct kdbus_cmd_match),
769         KDBUS_CMD_MATCH_REMOVE =        _IOW (KDBUS_IOC_MAGIC, 0x71, struct kdbus_cmd_match),
770
771         KDBUS_CMD_EP_POLICY_SET =       _IOW (KDBUS_IOC_MAGIC, 0x80, struct kdbus_cmd_policy),
772
773         KDBUS_CMD_MEMFD_NEW =           _IOR (KDBUS_IOC_MAGIC, 0x90, int *),
774         KDBUS_CMD_MEMFD_SIZE_GET =      _IOR (KDBUS_IOC_MAGIC, 0x91, __u64 *),
775         KDBUS_CMD_MEMFD_SIZE_SET =      _IOW (KDBUS_IOC_MAGIC, 0x92, __u64 *),
776         KDBUS_CMD_MEMFD_SEAL_GET =      _IOR (KDBUS_IOC_MAGIC, 0x93, int *),
777         KDBUS_CMD_MEMFD_SEAL_SET =      _IO  (KDBUS_IOC_MAGIC, 0x94),
778 };
779
780 /*
781  * errno - api error codes
782  * @E2BIG:              A message contains too many records or items.
783  * @EADDRINUSE:         A well-known bus name is already taken by another
784  *                      connection.
785  * @EADDRNOTAVAIL:      A message flagged not to activate a service, addressed
786  *                      a service which is not currently running.
787  * @EAGAIN:             No messages are queued at the moment.
788  * @EBADF:              File descriptors passed with the message are not valid.
789  * @EBADFD:             A bus connection is in a corrupted state.
790  * @EBADMSG:            Passed data contains a combination of conflicting or
791  *                      inconsistent types.
792  * @ECONNRESET:         A connection is shut down, no further operations are
793  *                      possible.
794  * @ECOMM:              A peer does not accept the file descriptors addressed
795  *                      to it.
796  * @EDESTADDRREQ:       The well-known bus name is required but missing.
797  * @EDOM:               The size of data does not match the expectations. Used
798  *                      for the size of the bloom filter bit field.
799  * @EEXIST:             A requested namespace, bus or endpoint with the same
800  *                      name already exists.  A specific data type, which is
801  *                      only expected once, is provided multiple times.
802  * @EFAULT:             The supplied memory could not be accessed, or the data
803  *                      is not properly aligned.
804  * @EINVAL:             The provided data does not match its type or other
805  *                      expectations, like a string which is not NUL terminated,
806  *                      or a string length that points behind the first
807  *                      \0-byte in the string.
808  * @EMEDIUMTYPE:        A file descriptor which is not a kdbus memfd was
809  *                      refused to send as KDBUS_MSG_PAYLOAD_MEMFD.
810  * @EMFILE:             Too many file descriptors have been supplied with a
811  *                      message.
812  * @EMSGSIZE:           The supplied data is larger than the allowed maximum
813  *                      size.
814  * @ENAMETOOLONG:       The requested name is larger than the allowed maximum
815  *                      size.
816  * @ENOBUFS:            There is no space left for the submitted data to fit
817  *                      into the receiver's pool.
818  * @ENOMEM:             Out of memory.
819  * @ENOSYS:             The requested functionality is not available.
820  * @ENOTCONN:           The addressed peer is not an active connection.
821  * @ENOTSUPP:           The feature negotiation failed, a not supported feature
822  *                      was requested, or an unknown item type was received.
823  * @ENOTTY:             An unknown ioctl command was received.
824  * @ENOTUNIQ:           A specific data type was addressed to a broadcast
825  *                      address, but only direct addresses support this kind of
826  *                      data.
827  * @ENXIO:              A unique address does not exist, or an offset in the
828  *                      receiver's pool does not represent a queued message.
829  * @EPERM:              The policy prevented an operation. The requested
830  *                      resource is owned by another entity.
831  * @ESHUTDOWN:          A namespace or endpoint is currently shutting down;
832  *                      no further operations will be possible.
833  * @ESRCH:              A requested well-known bus name is not found.
834  * @ETXTBSY:            A kdbus memfd file cannot be sealed or the seal removed,
835  *                      because it is shared with other processes or still
836  *                      mmap()ed.
837  * @EXFULL:             The size limits in the pool are reached, no data of
838  *                      the size tried to submit can be queued.
839  */
840 #endif