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