chiark / gitweb /
bus: catch up with latest kdbus changes
[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  * @flags:              flags from KDBUS_NAME_*
34  * @name:               Well-known name
35  *
36  * Sent from kernel to userspace when the owner or starter of
37  * a well-known name changes.
38  *
39  * Attached to:
40  *   KDBUS_ITEM_NAME_ADD
41  *   KDBUS_ITEM_NAME_REMOVE
42  *   KDBUS_ITEM_NAME_CHANGE
43  */
44 struct kdbus_notify_name_change {
45         __u64 old_id;
46         __u64 new_id;
47         __u64 flags;
48         char name[0];
49 };
50
51 /**
52  * struct kdbus_notify_id_change - name registry change message
53  * @id:                 New or former owner of the name
54  * @flags:              flags field from KDBUS_HELLO_*
55  *
56  * Sent from kernel to userspace when the owner or starter of
57  * a well-known name changes.
58  *
59  * Attached to:
60  *   KDBUS_ITEM_ID_ADD
61  *   KDBUS_ITEM_ID_REMOVE
62  */
63 struct kdbus_notify_id_change {
64         __u64 id;
65         __u64 flags;
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:     Vevtor 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_DST_NAME:        Destination's well-known name
203  * @KDBUS_ITEM_PRIORITY:        Queue priority for message
204  * @KDBUS_ITEM_MAKE_NAME:       Name of namespace, bus, endpoint
205  * @KDBUS_ITEM_POLICY_NAME:     Policy in struct kdbus_policy
206  * @KDBUS_ITEM_POLICY_ACCESS:   Policy in struct kdbus_policy
207  * @KDBUS_ITEM_NAME:            Well-know name with flags
208  * @KDBUS_ITEM_STARTER_NAME:    Well-known name for the starter
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:      Destiantion 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_DST_NAME,
236         KDBUS_ITEM_PRIORITY,
237         KDBUS_ITEM_MAKE_NAME,
238
239         _KDBUS_ITEM_POLICY_BASE = 0x400,
240         KDBUS_ITEM_POLICY_NAME = _KDBUS_ITEM_POLICY_BASE,
241         KDBUS_ITEM_POLICY_ACCESS,
242
243         _KDBUS_ITEM_ATTACH_BASE = 0x600,
244         KDBUS_ITEM_NAME         = _KDBUS_ITEM_ATTACH_BASE,
245         KDBUS_ITEM_STARTER_NAME,
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_DBUS1:        Legacy D-Bus version 1 marshalling
330  * @KDBUS_PAYLOAD_GVARIANT:     GVariant marshalling
331  */
332 enum kdbus_payload_type {
333         KDBUS_PAYLOAD_KERNEL,
334         KDBUS_PAYLOAD_DBUS1     = 0x4442757356657231ULL, /* 'DBusVer1' */
335         KDBUS_PAYLOAD_GVARIANT  = 0x4756617269616e74ULL, /* 'GVariant' */
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
350  * @items:              A list of kdbus_items containing the message payload
351  */
352 struct kdbus_msg {
353         __u64 size;
354         __u64 flags;
355         __u64 dst_id;
356         __u64 src_id;
357         __u64 payload_type;
358         __u64 cookie;
359         union {
360                 __u64 cookie_reply;
361                 __u64 timeout_ns;
362         };
363         struct kdbus_item items[0];
364 };
365
366 /**
367  * enum kdbus_policy_access_type - permissions of a policy record
368  * @KDBUS_POLICY_ACCESS_USER:   Grant access to a uid
369  * @KDBUS_POLICY_ACCESS_GROUP:  Grant acces to gid
370  * @KDBUS_POLICY_ACCESS_WORLD:  World-accessible
371  */
372 enum kdbus_policy_access_type {
373         _KDBUS_POLICY_ACCESS_NULL,
374         KDBUS_POLICY_ACCESS_USER,
375         KDBUS_POLICY_ACCESS_GROUP,
376         KDBUS_POLICY_ACCESS_WORLD,
377 };
378
379 /**
380  * enum kdbus_policy_access_flags - mode flags
381  * @KDBUS_POLICY_RECV:          Allow receive
382  * @KDBUS_POLICY_SEND:          Allow send
383  * @KDBUS_POLICY_OWN:           Allow to own a well-known name
384  */
385 enum kdbus_policy_type {
386         KDBUS_POLICY_RECV               = 1 <<  2,
387         KDBUS_POLICY_SEND               = 1 <<  1,
388         KDBUS_POLICY_OWN                = 1 <<  0,
389 };
390
391 /**
392  * struct kdbus_cmd_policy - a series of policies to upload
393  * @size:               The total size of the structure
394  * @policies:           The policies to upload
395  *
396  * A KDBUS_POLICY_NAME must always preceed a KDBUS_POLICY_ACCESS entry.
397  * A new KDBUS_POLICY_NAME can be added after KDBUS_POLICY_ACCESS for
398  * chaining multiple policies together.
399  */
400 struct kdbus_cmd_policy {
401         __u64 size;
402         struct kdbus_item policies[0];
403 };
404
405 /**
406  * enum kdbus_hello_flags - flags for struct kdbus_cmd_hello
407  * @KDBUS_HELLO_STARTER:                The connection registers a name for activation
408  *                              by well-know name
409  * @KDBUS_HELLO_ACCEPT_FD:      The connection allows the receiving of
410  *                              any passed file descriptors
411  */
412 enum kdbus_hello_flags {
413         KDBUS_HELLO_STARTER             =  1 <<  0,
414         KDBUS_HELLO_ACCEPT_FD           =  1 <<  1,
415 };
416
417 /**
418  * enum kdbus_attach_flags - flags for metadata attachments
419  * @KDBUS_ATTACH_TIMESTAMP:     Timestamp
420  * @KDBUS_ATTACH_CREDS:         Credentials
421  * @KDBUS_ATTACH_NAMES:         Well-known names
422  * @KDBUS_ATTACH_COMM:          The "comm" process identifier
423  * @KDBUS_ATTACH_EXE:           The path of the executable
424  * @KDBUS_ATTACH_CMDLINE:       The process command line
425  * @KDBUS_ATTACH_CGROUP:        The croup membership
426  * @KDBUS_ATTACH_CAPS:          The process capabilities
427  * @KDBUS_ATTACH_SECLABEL:      The security label
428  * @KDBUS_ATTACH_AUDIT:         The audit IDs
429  */
430 enum kdbus_attach_flags {
431         KDBUS_ATTACH_TIMESTAMP          =  1 <<  0,
432         KDBUS_ATTACH_CREDS              =  1 <<  1,
433         KDBUS_ATTACH_NAMES              =  1 <<  2,
434         KDBUS_ATTACH_COMM               =  1 <<  3,
435         KDBUS_ATTACH_EXE                =  1 <<  4,
436         KDBUS_ATTACH_CMDLINE            =  1 <<  5,
437         KDBUS_ATTACH_CGROUP             =  1 <<  6,
438         KDBUS_ATTACH_CAPS               =  1 <<  7,
439         KDBUS_ATTACH_SECLABEL           =  1 <<  8,
440         KDBUS_ATTACH_AUDIT              =  1 <<  9,
441 };
442
443 /**
444  * struct kdbus_cmd_hello - struct to say hello to kdbus
445  * @size:               The total size of the structure
446  * @conn_flags:         Connection flags (KDBUS_HELLO_*). The kernel will
447  *                      return its capabilities in that field.
448  * @attach_flags:       Mask of metdata to attach to each message sent
449  *                      (KDBUS_ATTACH_*)
450  * @bus_flags:          The flags field copied verbatim from the original
451  *                      KDBUS_CMD_BUS_MAKE ioctl. It's intended to be useful
452  *                      to do negotiation of features of the payload that is
453  *                      transferred (kernel â†’ userspace)
454  * @id:                 The ID of this connection (kernel â†’ userspace)
455  * @bloom_size:         The bloom filter size chosen by the owner
456  *                      (kernel â†’ userspace)
457  * @pool_size:          Maximum size of the pool buffer (kernel â†’ userspace)
458  * @id128:              Unique 128-bit ID of the bus (kernel â†’ userspace)
459  * @items:              A list of items
460  *
461  * This struct is used with the KDBUS_CMD_HELLO ioctl. See the ioctl
462  * documentation for more information.
463  */
464 struct kdbus_cmd_hello {
465         __u64 size;
466
467         /* userspace â†’ kernel, kernel â†’ userspace */
468         __u64 conn_flags;
469         __u64 attach_flags;
470
471         /* kernel â†’ userspace */
472         __u64 bus_flags;
473         __u64 id;
474         __u64 bloom_size;
475         __u64 pool_size;
476         __u8 id128[16];
477
478         struct kdbus_item items[0];
479 };
480
481 /* Flags for KDBUS_CMD_{BUS,EP,NS}_MAKE */
482 enum kdbus_make_flags {
483         KDBUS_MAKE_ACCESS_GROUP         = 1 <<  0,
484         KDBUS_MAKE_ACCESS_WORLD         = 1 <<  1,
485         KDBUS_MAKE_POLICY_OPEN          = 1 <<  2,
486 };
487
488 /**
489  * struct kdbus_cmd_bus_make - struct to make a bus
490  * @size:               The total size of the struct
491  * @flags:              Properties for the bus to create
492  * @bloom_size:         Size of the bloom filter for this bus
493  * @items:              Items describing details such as the name of the bus
494  *
495  * This structure is used with the KDBUS_CMD_BUS_MAKE ioctl. Refer to the
496  * documentation for more information.
497  */
498 struct kdbus_cmd_bus_make {
499         __u64 size;
500         __u64 flags;
501         __u64 bloom_size;
502         struct kdbus_item items[0];
503 };
504
505 /**
506  * struct kdbus_cmd_ep_make - struct to make an endpoint
507  * @size:               The total size of the struct
508  * @flags:              Unused for now
509  * @items:              Items describing details such as the
510  *                      name of the endpoint
511  *
512  * This structure is used with the KDBUS_CMD_EP_MAKE ioctl. Refer to the
513  * documentation for more information.
514  */
515 struct kdbus_cmd_ep_make {
516         __u64 size;
517         __u64 flags;
518         struct kdbus_item items[0];
519 };
520
521 /**
522  * struct kdbus_cmd_ns_make - struct to make a namespace
523  * @size:               The total size of the struct
524  * @flags:              Unused for now
525  * @items:              Items describing details such as the
526  *                      name of the namespace
527  *
528  * This structure is used with the KDBUS_CMD_NS_MAKE ioctl. Refer to the
529  * documentation for more information.
530  */
531 struct kdbus_cmd_ns_make {
532         __u64 size;
533         __u64 flags;
534         struct kdbus_item items[0];
535 };
536
537 /**
538  * enum kdbus_name_flags - properties of a well-known name
539  * @KDBUS_NAME_REPLACE_EXISTING:        Try to replace name of other connections
540  * @KDBUS_NAME_QUEUE:                   Name should be queued if busy
541  * @KDBUS_NAME_ALLOW_REPLACEMENT:       Allow the replacement of the name
542  * @KDBUS_NAME_IN_QUEUE:                Name is queued
543  */
544 enum kdbus_name_flags {
545         /* userspace â†’ kernel */
546         KDBUS_NAME_REPLACE_EXISTING             = 1 <<  0,
547         KDBUS_NAME_QUEUE                        = 1 <<  1,
548         KDBUS_NAME_ALLOW_REPLACEMENT            = 1 <<  2,
549
550         /* kernel â†’ userspace */
551         KDBUS_NAME_IN_QUEUE                     = 1 << 16,
552 };
553
554 /**
555  * struct kdbus_cmd_name - struct to describe a well-known name
556  * @size:               The total size of the struct
557  * @flags:              Flags for a name entry (KDBUS_NAME_*)
558  * @id:                 Priviledged users may use this field to (de)register
559  *                      names on behalf of other peers.
560  * @conn_flags:         The flags of the owning connection (KDBUS_HELLO_*)
561  * @name:               The well-known name
562  *
563  * This structure is used with the KDBUS_CMD_NAME_ACQUIRE ioctl.
564  * Refer to the documentation for more information.
565  */
566 struct kdbus_cmd_name {
567         __u64 size;
568         __u64 flags;
569         __u64 id;
570         __u64 conn_flags;
571         char name[0];
572 };
573
574 /**
575  * enum kdbus_name_list_flags - what to include into the returned list
576  * @KDBUS_NAME_LIST_UNIQUE:     All active connections
577  * @KDBUS_NAME_LIST_NAMES:      All known well-known names
578  * @KDBUS_NAME_LIST_STARTERS:   All connections which are starter connections
579  * @KDBUS_NAME_LIST_QUEUED:     All queued-up names
580  */
581 enum kdbus_name_list_flags {
582         KDBUS_NAME_LIST_UNIQUE          = 1 <<  0,
583         KDBUS_NAME_LIST_NAMES           = 1 <<  1,
584         KDBUS_NAME_LIST_STARTERS        = 1 <<  2,
585         KDBUS_NAME_LIST_QUEUED          = 1 <<  3,
586 };
587
588 /**
589  * struct kdbus_cmd_name_list - request a list of name entries
590  * @flags:              Flags for the query (KDBUS_NAME_LIST_*)
591  * @offset:             The returned offset in the caller's pool buffer.
592  *                      The user must use KDBUS_CMD_FREE to free the
593  *                      allocated memory.
594  * 
595  * This structure is used with the KDBUS_CMD_NAME_LIST ioctl.
596  */
597 struct kdbus_cmd_name_list {
598         __u64 flags;
599         __u64 offset;
600 };
601
602 /**
603  * struct kdbus_name_list - information returned by KDBUS_CMD_NAME_LIST
604  * @size:               The total size of the structure
605  * @names:              A list of names
606  *
607  * Note that the user is responsible for freeing the allocated memory with
608  * the KDBUS_CMD_FREE ioctl.
609  */
610 struct kdbus_name_list {
611         __u64 size;
612         struct kdbus_cmd_name names[0];
613 };
614
615 /**
616  * struct kdbus_cmd_conn_info - struct used for KDBUS_CMD_CONN_INFO ioctl
617  * @size:               The total size of the struct
618  * @flags:              KDBUS_ATTACH_* flags
619  * @id:                 The 64-bit ID of the connection. If set to zero, passing
620  *                      @name is required. kdbus will look up the name to determine
621  *                      the ID in this case.
622  * @offset:             Returned offset in the caller's pool buffer where the
623  *                      kdbus_name_info struct result is stored. The user must
624  *                      use KDBUS_CMD_FREE to free the allocated memory.
625  * @name:               The optional well-known name to look up. Only needed in
626  *                      case @id is zero.
627  *
628  * On success, the KDBUS_CMD_CONN_INFO ioctl will return 0 and @offset will
629  * tell the user the offset in the connection pool buffer at which to find the
630  * result in a struct kdbus_conn_info.
631  */
632 struct kdbus_cmd_conn_info {
633         __u64 size;
634         __u64 flags;
635         __u64 id;
636         __u64 offset;
637         char name[0];
638 };
639
640 /**
641  * struct kdbus_conn_info - information returned by KDBUS_CMD_CONN_INFO
642  * @size:               The total size of the struct
643  * @id:                 The connection's 64-bit ID
644  * @flags:              The connection's flags
645  * @items:              A list of struct kdbus_item
646  *
647  * Note that the user is responsible for freeing the allocated memory with
648  * the KDBUS_CMD_FREE ioctl.
649  */
650 struct kdbus_conn_info {
651         __u64 size;
652         __u64 id;
653         __u64 flags;
654         struct kdbus_item items[0];
655 };
656
657 /**
658  * enum kdbus_match_type - type of match record
659  * @KDBUS_MATCH_BLOOM:          Matches against KDBUS_MSG_BLOOM
660  * @KDBUS_MATCH_SRC_NAME:       Matches a name string
661  * @KDBUS_MATCH_NAME_ADD:       Matches a name string
662  * @KDBUS_MATCH_NAME_REMOVE:    Matches a name string
663  * @KDBUS_MATCH_NAME_CHANGE:    Matches a name string
664  * @KDBUS_MATCH_ID_ADD:         Matches an ID
665  * @KDBUS_MATCH_ID_REMOVE:      Matches an ID
666  */
667 enum kdbus_match_type {
668         _KDBUS_MATCH_NULL,
669         KDBUS_MATCH_BLOOM,
670         KDBUS_MATCH_SRC_NAME,
671         KDBUS_MATCH_NAME_ADD,
672         KDBUS_MATCH_NAME_REMOVE,
673         KDBUS_MATCH_NAME_CHANGE,
674         KDBUS_MATCH_ID_ADD,
675         KDBUS_MATCH_ID_REMOVE,
676 };
677
678 /**
679  * struct kdbus_cmd_match - struct to add or remove matches
680  * @size:               The total size of the struct
681  * @id:                 Privileged users may (de)register matches on behalf
682  *                      of other peers. In other cases, set to 0.
683  * @cookie:             Userspace supplied cookie. When removing, the cookie
684  *                      identifies the match to remove.
685  * @src_id:             The source ID to match against. Use
686  *                      KDBUS_MATCH_SRC_ID_ANY or any other value for a unique
687  *                      match.
688  * @items:              A list of items for additional information
689  *
690  * This structure is used with the KDBUS_CMD_ADD_MATCH and
691  * KDBUS_CMD_REMOVE_MATCH ioctl. Refer to the documentation for more
692  * information.
693  */
694 struct kdbus_cmd_match {
695         __u64 size;
696         __u64 id;
697         __u64 cookie;
698         __u64 src_id;
699         struct kdbus_item items[0];
700 };
701
702 /**
703  * enum kdbus_monitor_flags - flags for monitoring
704  * @KDBUS_MONITOR_ENABLE:       Enable monitoring
705  */
706 enum kdbus_monitor_flags {
707         KDBUS_MONITOR_ENABLE            = 1 <<  0,
708 };
709
710 /**
711  * struct kdbus_cmd_monitor - struct to enable or disable eavesdropping
712  * @id:                 Priviledged users may enable or disable the monitor feature
713  *                      on behalf of other peers
714  * @flags:              Use KDBUS_MONITOR_ENABLE to enable eavesdropping
715  *
716  * This structure is used with the KDBUS_CMD_MONITOR ioctl.
717  * Refer to the documentation for more information.
718  */
719 struct kdbus_cmd_monitor {
720         __u64 id;
721         __u64 flags;
722 };
723
724 /**
725  * enum kdbus_ioctl_type - Ioctl API
726  * @KDBUS_CMD_BUS_MAKE:         After opening the "control" device node, this
727  *                              command creates a new bus with the specified
728  *                              name. The bus is immediately shut down and
729  *                              cleaned up when the opened "control" device node
730  *                              is closed.
731  * @KDBUS_CMD_NS_MAKE:          Similar to KDBUS_CMD_BUS_MAKE, but it creates a
732  *                              new kdbus namespace.
733  * @KDBUS_CMD_EP_MAKE:          Creates a new named special endpoint to talk to
734  *                              the bus. Such endpoints usually carry a more
735  *                              restrictive policy and grant restricted access
736  *                              to specific applications.
737  * @KDBUS_CMD_HELLO:            By opening the bus device node a connection is
738  *                              created. After a HELLO the opened connection
739  *                              becomes an active peer on the bus.
740  * @KDBUS_CMD_MSG_SEND:         Send a message and pass data from userspace to
741  *                              the kernel.
742  * @KDBUS_CMD_MSG_RECV:         Receive a message from the kernel which is
743  *                              placed in the receiver's pool.
744  * @KDBUS_CMD_FREE:             Release the allocated memory in the receiver's
745  *                              pool.
746  * @KDBUS_CMD_NAME_ACQUIRE:     Request a well-known bus name to associate with
747  *                              the connection. Well-known names are used to
748  *                              address a peer on the bus.
749  * @KDBUS_CMD_NAME_RELEASE:     Release a well-known name the connection
750  *                              currently owns.
751  * @KDBUS_CMD_NAME_LIST:        Retrieve the list of all currently registered
752  *                              well-known and unique names.
753  * @KDBUS_CMD_CONN_INFO:        Retrieve credentials and properties of the
754  *                              initial creator of the connection. The data was
755  *                              stored at registration time and does not
756  *                              neccessarily represent the connected process or
757  *                              the actual state of the process.
758  * @KDBUS_CMD_MATCH_ADD:        Install a match which broadcast messages should
759  *                              be delivered to the connection.
760  * @KDBUS_CMD_MATCH_REMOVE:     Remove a current match for broadcast messages.
761  * @KDBUS_CMD_MONITOR:          Monitor the bus and receive all transmitted
762  *                              messages. Privileges are required for this
763  *                              operation.
764  * @KDBUS_CMD_EP_POLICY_SET:    Set the policy of an endpoint. It is used to
765  *                              restrict the access for endpoints created with
766  *                              KDBUS_CMD_EP_MAKE.
767  * @KDBUS_CMD_MEMFD_NEW:        Return a new file descriptor which provides an
768  *                              anonymous shared memory file and which can be
769  *                              used to pass around larger chunks of data.
770  *                              Kdbus memfd files can be sealed, which allows
771  *                              the receiver to trust the data it has received.
772  *                              Kdbus memfd files expose only very limited
773  *                              operations, they can be mmap()ed, seek()ed,
774  *                              (p)read(v)() and (p)write(v)(); most other
775  *                              common file operations are not implemented.
776  *                              Special caution needs to be taken with
777  *                              read(v)()/write(v)() on a shared file; the
778  *                              underlying file position is always shared
779  *                              between all users of the file and race against
780  *                              each other, pread(v)()/pwrite(v)() avoid these
781  *                              issues.
782  * @KDBUS_CMD_MEMFD_SIZE_GET:   Return the size of the underlying file, which
783  *                              changes with write().
784  * @KDBUS_CMD_MEMFD_SIZE_SET:   Truncate the underlying file to the specified
785  *                              size.
786  * @KDBUS_CMD_MEMFD_SEAL_GET:   Return the state of the file sealing.
787  * @KDBUS_CMD_MEMFD_SEAL_SET:   Seal or break a seal of the file. Only files
788  *                              which are not shared with other processes and
789  *                              which are currently not mapped can be sealed.
790  *                              The current process needs to be the one and
791  *                              single owner of the file, the sealing cannot
792  *                              be changed as long as the file is shared.
793  */
794 enum kdbus_ioctl_type {
795         KDBUS_CMD_BUS_MAKE =            _IOW (KDBUS_IOC_MAGIC, 0x00, struct kdbus_cmd_bus_make),
796         KDBUS_CMD_NS_MAKE =             _IOR (KDBUS_IOC_MAGIC, 0x10, struct kdbus_cmd_ns_make),
797
798         KDBUS_CMD_EP_MAKE =             _IOW (KDBUS_IOC_MAGIC, 0x20, struct kdbus_cmd_ep_make),
799         KDBUS_CMD_HELLO =               _IOWR(KDBUS_IOC_MAGIC, 0x30, struct kdbus_cmd_hello),
800
801         KDBUS_CMD_MSG_SEND =            _IOW (KDBUS_IOC_MAGIC, 0x40, struct kdbus_msg),
802         KDBUS_CMD_MSG_RECV =            _IOR (KDBUS_IOC_MAGIC, 0x41, __u64 *),
803         KDBUS_CMD_FREE =                _IOW (KDBUS_IOC_MAGIC, 0x42, __u64 *),
804
805         KDBUS_CMD_NAME_ACQUIRE =        _IOWR(KDBUS_IOC_MAGIC, 0x50, struct kdbus_cmd_name),
806         KDBUS_CMD_NAME_RELEASE =        _IOW (KDBUS_IOC_MAGIC, 0x51, struct kdbus_cmd_name),
807         KDBUS_CMD_NAME_LIST =           _IOWR(KDBUS_IOC_MAGIC, 0x52, struct kdbus_cmd_name_list),
808
809         KDBUS_CMD_CONN_INFO =           _IOWR(KDBUS_IOC_MAGIC, 0x60, struct kdbus_cmd_conn_info),
810
811         KDBUS_CMD_MATCH_ADD =           _IOW (KDBUS_IOC_MAGIC, 0x70, struct kdbus_cmd_match),
812         KDBUS_CMD_MATCH_REMOVE =        _IOW (KDBUS_IOC_MAGIC, 0x71, struct kdbus_cmd_match),
813         KDBUS_CMD_MONITOR =             _IOW (KDBUS_IOC_MAGIC, 0x72, struct kdbus_cmd_monitor),
814
815         KDBUS_CMD_EP_POLICY_SET =       _IOW (KDBUS_IOC_MAGIC, 0x80, struct kdbus_cmd_policy),
816
817         KDBUS_CMD_MEMFD_NEW =           _IOR (KDBUS_IOC_MAGIC, 0x90, int *),
818         KDBUS_CMD_MEMFD_SIZE_GET =      _IOR (KDBUS_IOC_MAGIC, 0x91, __u64 *),
819         KDBUS_CMD_MEMFD_SIZE_SET =      _IOW (KDBUS_IOC_MAGIC, 0x92, __u64 *),
820         KDBUS_CMD_MEMFD_SEAL_GET =      _IOR (KDBUS_IOC_MAGIC, 0x93, int *),
821         KDBUS_CMD_MEMFD_SEAL_SET =      _IO  (KDBUS_IOC_MAGIC, 0x94),
822 };
823
824 /*
825  * errno - api error codes
826  * @E2BIG:              A message contains too many records or items.
827  * @EADDRNOTAVAIL:      A message flagged not to activate a service, addressed
828  *                      a service which is not currently running.
829  * @EAGAIN:             No messages are queued at the moment.
830  * @EBADF:              File descriptors passed with the message are not valid.
831  * @EBADFD:             A bus connection is in a corrupted state.
832  * @EBADMSG:            Passed data contains a combination of conflicting or
833  *                      inconsistent types.
834  * @EBUSY:              A well-known bus name is already taken by another
835  *                      connection.
836  * @ECOMM:              A peer does not accept the file descriptors addressed
837  *                      to it.
838  * @EDESTADDRREQ:       The well-known bus name is required but missing.
839  * @EDOM:               The size of data does not match the expectations. Used
840  *                      for the size of the bloom filter bit field.
841  * @EEXIST:             A requested namespace, bus or endpoint with the same
842  *                      name already exists.  A specific data type, which is
843  *                      only expected once, is provided multiple times.
844  * @EFAULT:             The supplied memory could not be accessed, or the data
845  *                      is not properly aligned.
846  * @EINVAL:             The provided data does not match its type or other
847  *                      expectations, like a string which is not NUL terminated,
848  *                      or a string length that points behind the first
849  *                      \0-byte in the string.
850  * @EMEDIUMTYPE:        A file descriptor which is not a kdbus memfd was
851  *                      refused to send as KDBUS_MSG_PAYLOAD_MEMFD.
852  * @EMFILE:             Too many file descriptors have been supplied with a
853  *                      message.
854  * @EMSGSIZE:           The supplied data is larger than the allowed maximum
855  *                      size.
856  * @ENAMETOOLONG:       The requested name is larger than the allowed maximum
857  *                      size.
858  * @ENOBUFS:            There is no space left for the submitted data to fit
859  *                      into the receiver's pool.
860  * @ENOMEM:             Out of memory.
861  * @ENOSYS:             The requested functionality is not available.
862  * @ENOTCONN:           The addressed peer is not an active connection.
863  * @ENOTSUPP:           The feature negotiation failed, a not supported feature
864  *                      was requested.
865  * @ENOTTY:             An unknown ioctl command was received.
866  * @ENOTUNIQ:           A specific data type was addressed to a broadcast
867  *                      address, but only direct addresses support this kind of
868  *                      data.
869  * @ENXIO:              A unique address does not exist.
870  * @EPERM:              The policy prevented an operation. The requested
871  *                      resource is owned by another entity.
872  * @ESHUTDOWN:          The connection is currently shutting down, no further
873  *                      operations are possible.
874  * @ESRCH:              A requested well-known bus name is not found.
875  * @ETXTBSY:            A kdbus memfd file cannot be sealed or the seal removed,
876  *                      because it is shared with other processes or still
877  *                      mmap()ed.
878  * @EXFULL:             The size limits in the pool are reached, no data of
879  *                      the size tried to submit can be queued.
880  */
881 #endif