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