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