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