chiark / gitweb /
sd-bus: sync kdbus.h (API change: switch to absolute timeouts)
[elogind.git] / src / libsystemd / sd-bus / kdbus.h
1 /*
2  * Copyright (C) 2013-2014 Kay Sievers
3  * Copyright (C) 2013-2014 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
4  * Copyright (C) 2013-2014 Linux Foundation
5  * Copyright (C) 2013-2014 Lennart Poettering
6  * Copyright (C) 2013-2014 Daniel Mack <daniel@zonque.org>
7  * Copyright (C) 2013-2014 David Herrmann <dh.herrmann@gmail.com>
8  *
9  * kdbus is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU Lesser General Public License as published by the
11  * Free Software Foundation; either version 2.1 of the License, or (at
12  * your option) any later version.
13  *
14  * "Everything should be made as simple as possible, but not simpler."
15  *   -- Albert Einstein
16  */
17
18 #ifndef _KDBUS_UAPI_H_
19 #define _KDBUS_UAPI_H_
20
21 #include <linux/ioctl.h>
22 #include <linux/types.h>
23
24 #define KDBUS_IOCTL_MAGIC               0x95
25 #define KDBUS_SRC_ID_KERNEL             (0)
26 #define KDBUS_DST_ID_NAME               (0)
27 #define KDBUS_MATCH_ID_ANY              (~0ULL)
28 #define KDBUS_DST_ID_BROADCAST          (~0ULL)
29 #define KDBUS_FLAG_KERNEL               (1ULL << 63)
30
31 /**
32  * struct kdbus_notify_id_change - name registry change message
33  * @id:                 New or former owner of the name
34  * @flags:              flags field from KDBUS_HELLO_*
35  *
36  * Sent from kernel to userspace when the owner or activator of
37  * a well-known name changes.
38  *
39  * Attached to:
40  *   KDBUS_ITEM_ID_ADD
41  *   KDBUS_ITEM_ID_REMOVE
42  */
43 struct kdbus_notify_id_change {
44         __u64 id;
45         __u64 flags;
46 };
47
48 /**
49  * struct kdbus_notify_name_change - name registry change message
50  * @old_id:             ID and flags of former owner of a name
51  * @new_id:             ID and flags of new owner of a name
52  * @name:               Well-known name
53  *
54  * Sent from kernel to userspace when the owner or activator of
55  * a well-known name changes.
56  *
57  * Attached to:
58  *   KDBUS_ITEM_NAME_ADD
59  *   KDBUS_ITEM_NAME_REMOVE
60  *   KDBUS_ITEM_NAME_CHANGE
61  */
62 struct kdbus_notify_name_change {
63         struct kdbus_notify_id_change old_id;
64         struct kdbus_notify_id_change new_id;
65         char name[0];
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  * @seqnum:             Global per-domain message sequence number
108  * @monotonic_ns:       Monotonic timestamp, in nanoseconds
109  * @realtime_ns:        Realtime timestamp, in nanoseconds
110  *
111  * Attached to:
112  *   KDBUS_ITEM_TIMESTAMP
113  */
114 struct kdbus_timestamp {
115         __u64 seqnum;
116         __u64 monotonic_ns;
117         __u64 realtime_ns;
118 };
119
120 /**
121  * struct kdbus_vec - I/O vector for kdbus payload items
122  * @size:               The size of the vector
123  * @address:            Memory address of data buffer
124  * @offset:             Offset in the in-message payload memory,
125  *                      relative to the message head
126  *
127  * Attached to:
128  *   KDBUS_ITEM_PAYLOAD_VEC, KDBUS_ITEM_PAYLOAD_OFF
129  */
130 struct kdbus_vec {
131         __u64 size;
132         union {
133                 __u64 address;
134                 __u64 offset;
135         };
136 };
137
138 /**
139  * struct kdbus_bloom_parameter - bus-wide bloom parameters
140  * @size:               Size of the bit field in bytes (m / 8)
141  * @n_hash:             Number of hash functions used (k)
142  */
143 struct kdbus_bloom_parameter {
144         __u64 size;
145         __u64 n_hash;
146 };
147
148 /**
149  * struct kdbus_bloom_filter - bloom filter containing n elements
150  * @generation:         Generation of the element set in the filter
151  * @data:               Bit field, multiple of 8 bytes
152  */
153 struct kdbus_bloom_filter {
154         __u64 generation;
155         __u64 data[0];
156 };
157
158 /**
159  * struct kdbus_memfd - a kdbus memfd
160  * @size:               The memfd's size
161  * @fd:                 The file descriptor number
162  * @__pad:              Padding to ensure proper alignment and size
163  *
164  * Attached to:
165  *   KDBUS_ITEM_PAYLOAD_MEMFD
166  */
167 struct kdbus_memfd {
168         __u64 size;
169         int fd;
170         __u32 __pad;
171 };
172
173 /**
174  * struct kdbus_name - a registered well-known name with its flags
175  * @flags:              Flags from KDBUS_NAME_*
176  * @name:               Well-known name
177  *
178  * Attached to:
179  *   KDBUS_ITEM_NAME
180  */
181 struct kdbus_name {
182         __u64 flags;
183         char name[0];
184 };
185
186 /**
187  * struct kdbus_policy_access - policy access item
188  * @type:               One of KDBUS_POLICY_ACCESS_* types
189  * @access:             Access to grant
190  * @id:                 For KDBUS_POLICY_ACCESS_USER, the uid
191  *                      For KDBUS_POLICY_ACCESS_GROUP, the gid
192  */
193 struct kdbus_policy_access {
194         __u64 type;     /* USER, GROUP, WORLD */
195         __u64 access;   /* OWN, TALK, SEE */
196         __u64 id;       /* uid, gid, 0 */
197 };
198
199 /**
200  * enum kdbus_item_type - item types to chain data in a list
201  * @_KDBUS_ITEM_NULL:           Uninitialized/invalid
202  * @_KDBUS_ITEM_USER_BASE:      Start of user items
203  * @KDBUS_ITEM_PAYLOAD_VEC:     Vector to data
204  * @KDBUS_ITEM_PAYLOAD_OFF:     Data at returned offset to message head
205  * @KDBUS_ITEM_PAYLOAD_MEMFD:   Data as sealed memfd
206  * @KDBUS_ITEM_FDS:             Attached file descriptors
207  * @KDBUS_ITEM_BLOOM_PARAMETER: Bus-wide bloom parameters, used with
208  *                              KDBUS_CMD_BUS_MAKE, carries a
209  *                              struct kdbus_bloom_parameter
210  * @KDBUS_ITEM_BLOOM_FILTER:    Bloom filter carried with a message, used to
211  *                              match against a bloom mask of a connection,
212  *                              carries a struct kdbus_bloom_filter
213  * @KDBUS_ITEM_BLOOM_MASK:      Bloom mask used to match against a message's
214  *                              bloom filter
215  * @KDBUS_ITEM_DST_NAME:        Destination's well-known name
216  * @KDBUS_ITEM_MAKE_NAME:       Name of domain, bus, endpoint
217  * @KDBUS_ITEM_ATTACH_FLAGS:    Attach-flags, used for updating which metadata
218  *                              a connection subscribes to
219  * @_KDBUS_ITEM_ATTACH_BASE:    Start of metadata attach items
220  * @KDBUS_ITEM_NAME:            Well-know name with flags
221  * @KDBUS_ITEM_ID:              Connection ID
222  * @KDBUS_ITEM_TIMESTAMP:       Timestamp
223  * @KDBUS_ITEM_CREDS:           Process credential
224  * @KDBUS_ITEM_AUXGROUPS:       Auxiliary process groups
225  * @KDBUS_ITEM_PID_COMM:        Process ID "comm" identifier
226  * @KDBUS_ITEM_TID_COMM:        Thread ID "comm" identifier
227  * @KDBUS_ITEM_EXE:             The path of the executable
228  * @KDBUS_ITEM_CMDLINE:         The process command line
229  * @KDBUS_ITEM_CGROUP:          The croup membership
230  * @KDBUS_ITEM_CAPS:            The process capabilities
231  * @KDBUS_ITEM_SECLABEL:        The security label
232  * @KDBUS_ITEM_AUDIT:           The audit IDs
233  * @KDBUS_ITEM_CONN_NAME:       The connection's human-readable name (debugging)
234  * @_KDBUS_ITEM_POLICY_BASE:    Start of policy items
235  * @KDBUS_ITEM_POLICY_ACCESS:   Policy access block
236  * @_KDBUS_ITEM_KERNEL_BASE:    Start of kernel-generated message items
237  * @KDBUS_ITEM_NAME_ADD:        Notify in struct kdbus_notify_name_change
238  * @KDBUS_ITEM_NAME_REMOVE:     Notify in struct kdbus_notify_name_change
239  * @KDBUS_ITEM_NAME_CHANGE:     Notify in struct kdbus_notify_name_change
240  * @KDBUS_ITEM_ID_ADD:          Notify in struct kdbus_notify_id_change
241  * @KDBUS_ITEM_ID_REMOVE:       Notify in struct kdbus_notify_id_change
242  * @KDBUS_ITEM_REPLY_TIMEOUT:   Timeout has been reached
243  * @KDBUS_ITEM_REPLY_DEAD:      Destination died
244  */
245 enum kdbus_item_type {
246         _KDBUS_ITEM_NULL,
247         _KDBUS_ITEM_USER_BASE,
248         KDBUS_ITEM_PAYLOAD_VEC  = _KDBUS_ITEM_USER_BASE,
249         KDBUS_ITEM_PAYLOAD_OFF,
250         KDBUS_ITEM_PAYLOAD_MEMFD,
251         KDBUS_ITEM_FDS,
252         KDBUS_ITEM_BLOOM_PARAMETER,
253         KDBUS_ITEM_BLOOM_FILTER,
254         KDBUS_ITEM_BLOOM_MASK,
255         KDBUS_ITEM_DST_NAME,
256         KDBUS_ITEM_MAKE_NAME,
257         KDBUS_ITEM_ATTACH_FLAGS,
258
259         _KDBUS_ITEM_ATTACH_BASE = 0x1000,
260         KDBUS_ITEM_NAME         = _KDBUS_ITEM_ATTACH_BASE,
261         KDBUS_ITEM_ID,
262         KDBUS_ITEM_TIMESTAMP,
263         KDBUS_ITEM_CREDS,
264         KDBUS_ITEM_AUXGROUPS,
265         KDBUS_ITEM_PID_COMM,
266         KDBUS_ITEM_TID_COMM,
267         KDBUS_ITEM_EXE,
268         KDBUS_ITEM_CMDLINE,
269         KDBUS_ITEM_CGROUP,
270         KDBUS_ITEM_CAPS,
271         KDBUS_ITEM_SECLABEL,
272         KDBUS_ITEM_AUDIT,
273         KDBUS_ITEM_CONN_NAME,
274
275         _KDBUS_ITEM_POLICY_BASE = 0x2000,
276         KDBUS_ITEM_POLICY_ACCESS = _KDBUS_ITEM_POLICY_BASE,
277
278         _KDBUS_ITEM_KERNEL_BASE = 0x8000,
279         KDBUS_ITEM_NAME_ADD     = _KDBUS_ITEM_KERNEL_BASE,
280         KDBUS_ITEM_NAME_REMOVE,
281         KDBUS_ITEM_NAME_CHANGE,
282         KDBUS_ITEM_ID_ADD,
283         KDBUS_ITEM_ID_REMOVE,
284         KDBUS_ITEM_REPLY_TIMEOUT,
285         KDBUS_ITEM_REPLY_DEAD,
286 };
287
288 /**
289  * struct kdbus_item - chain of data blocks
290  * @size:               Overall data record size
291  * @type:               Kdbus_item type of data
292  * @data:               Generic bytes
293  * @data32:             Generic 32 bit array
294  * @data64:             Generic 64 bit array
295  * @str:                Generic string
296  * @id:                 Connection ID
297  * @vec:                KDBUS_ITEM_PAYLOAD_VEC
298  * @creds:              KDBUS_ITEM_CREDS
299  * @audit:              KDBUS_ITEM_AUDIT
300  * @timestamp:          KDBUS_ITEM_TIMESTAMP
301  * @name:               KDBUS_ITEM_NAME
302  * @bloom_parameter:    KDBUS_ITEM_BLOOM_PARAMETER
303  * @bloom_filter:       KDBUS_ITEM_BLOOM_FILTER
304  * @memfd:              KDBUS_ITEM_PAYLOAD_MEMFD
305  * @name_change:        KDBUS_ITEM_NAME_ADD
306  *                      KDBUS_ITEM_NAME_REMOVE
307  *                      KDBUS_ITEM_NAME_CHANGE
308  * @id_change:          KDBUS_ITEM_ID_ADD
309  *                      KDBUS_ITEM_ID_REMOVE
310  * @policy:             KDBUS_ITEM_POLICY_ACCESS
311  */
312 struct kdbus_item {
313         __u64 size;
314         __u64 type;
315         union {
316                 __u8 data[0];
317                 __u32 data32[0];
318                 __u64 data64[0];
319                 char str[0];
320
321                 __u64 id;
322                 struct kdbus_vec vec;
323                 struct kdbus_creds creds;
324                 struct kdbus_audit audit;
325                 struct kdbus_timestamp timestamp;
326                 struct kdbus_name name;
327                 struct kdbus_bloom_parameter bloom_parameter;
328                 struct kdbus_bloom_filter bloom_filter;
329                 struct kdbus_memfd memfd;
330                 int fds[0];
331                 struct kdbus_notify_name_change name_change;
332                 struct kdbus_notify_id_change id_change;
333                 struct kdbus_policy_access policy_access;
334         };
335 };
336
337 /**
338  * enum kdbus_msg_flags - type of message
339  * @KDBUS_MSG_FLAGS_EXPECT_REPLY:       Expect a reply message, used for
340  *                                      method calls. The userspace-supplied
341  *                                      cookie identifies the message and the
342  *                                      respective reply carries the cookie
343  *                                      in cookie_reply
344  * @KDBUS_MSG_FLAGS_SYNC_REPLY:         Wait for destination connection to
345  *                                      reply to this message. The
346  *                                      KDBUS_CMD_MSG_SEND ioctl() will block
347  *                                      until the reply is received, and
348  *                                      offset_reply in struct kdbus_msg will
349  *                                      yield the offset in the sender's pool
350  *                                      where the reply can be found.
351  *                                      This flag is only valid if
352  *                                      @KDBUS_MSG_FLAGS_EXPECT_REPLY is set as
353  *                                      well.
354  * @KDBUS_MSG_FLAGS_NO_AUTO_START:      Do not start a service, if the addressed
355  *                                      name is not currently active
356  */
357 enum kdbus_msg_flags {
358         KDBUS_MSG_FLAGS_EXPECT_REPLY    = 1ULL << 0,
359         KDBUS_MSG_FLAGS_SYNC_REPLY      = 1ULL << 1,
360         KDBUS_MSG_FLAGS_NO_AUTO_START   = 1ULL << 2,
361 };
362
363 /**
364  * enum kdbus_payload_type - type of payload carried by message
365  * @KDBUS_PAYLOAD_KERNEL:       Kernel-generated simple message
366  * @KDBUS_PAYLOAD_DBUS:         D-Bus marshalling "DBusDBus"
367  */
368 enum kdbus_payload_type {
369         KDBUS_PAYLOAD_KERNEL,
370         KDBUS_PAYLOAD_DBUS      = 0x4442757344427573ULL,
371 };
372
373 /**
374  * struct kdbus_msg - the representation of a kdbus message
375  * @size:               Total size of the message
376  * @flags:              Message flags (KDBUS_MSG_FLAGS_*), userspace → kernel
377  * @kernel_flags:       Supported message flags, kernel → userspace
378  * @priority:           Message queue priority value
379  * @dst_id:             64-bit ID of the destination connection
380  * @src_id:             64-bit ID of the source connection
381  * @payload_type:       Payload type (KDBUS_PAYLOAD_*)
382  * @cookie:             Userspace-supplied cookie, for the connection
383  *                      to identify its messages
384  * @timeout_ns:         The time to wait for a message reply from the peer.
385  *                      If there is no reply, a kernel-generated message
386  *                      with an attached KDBUS_ITEM_REPLY_TIMEOUT item
387  *                      is sent to @src_id. The timeout is expected in
388  *                      nanoseconds and as absolute CLOCK_MONOTONIC value.
389  * @cookie_reply:       A reply to the requesting message with the same
390  *                      cookie. The requesting connection can match its
391  *                      request and the reply with this value
392  * @offset_reply:       If KDBUS_MSG_FLAGS_EXPECT_REPLY, this field will
393  *                      contain the offset in the sender's pool where the
394  *                      reply is stored.
395  * @items:              A list of kdbus_items containing the message payload
396  */
397 struct kdbus_msg {
398         __u64 size;
399         __u64 flags;
400         __u64 kernel_flags;
401         __s64 priority;
402         __u64 dst_id;
403         __u64 src_id;
404         __u64 payload_type;
405         __u64 cookie;
406         union {
407                 __u64 timeout_ns;
408                 __u64 cookie_reply;
409                 __u64 offset_reply;
410         };
411         struct kdbus_item items[0];
412 } __attribute__((aligned(8)));
413
414 /**
415  * enum kdbus_recv_flags - flags for de-queuing messages
416  * @KDBUS_RECV_PEEK:            Return the next queued message without
417  *                              actually de-queuing it, and without installing
418  *                              any file descriptors or other resources. It is
419  *                              usually used to determine the activating
420  *                              connection of a bus name.
421  * @KDBUS_RECV_DROP:            Drop and free the next queued message and all
422  *                              its resources without actually receiving it.
423  * @KDBUS_RECV_USE_PRIORITY:    Only de-queue messages with the specified or
424  *                              higher priority (lowest values); if not set,
425  *                              the priority value is ignored.
426  */
427 enum kdbus_recv_flags {
428         KDBUS_RECV_PEEK         = 1ULL <<  0,
429         KDBUS_RECV_DROP         = 1ULL <<  1,
430         KDBUS_RECV_USE_PRIORITY = 1ULL <<  2,
431 };
432
433 /**
434  * struct kdbus_cmd_recv - struct to de-queue a buffered message
435  * @flags:              KDBUS_RECV_* flags, userspace → kernel
436  * @kernel_flags:       Supported KDBUS_RECV_* flags, kernel → userspace
437  * @priority:           Minimum priority of the messages to de-queue. Lowest
438  *                      values have the highest priority.
439  * @offset:             Returned offset in the pool where the message is
440  *                      stored. The user must use KDBUS_CMD_FREE to free
441  *                      the allocated memory.
442  *
443  * This struct is used with the KDBUS_CMD_MSG_RECV ioctl.
444  */
445 struct kdbus_cmd_recv {
446         __u64 flags;
447         __u64 kernel_flags;
448         __s64 priority;
449         __u64 offset;
450 } __attribute__((aligned(8)));
451
452 /**
453  * struct kdbus_cmd_cancel - struct to cancel a synchronously pending message
454  * @cookie              The cookie of the pending message
455  * @flags               Flags for the free command. Currently unused.
456  *
457  * This struct is used with the KDBUS_CMD_CANCEL ioctl.
458  */
459 struct kdbus_cmd_cancel {
460         __u64 cookie;
461         __u64 flags;
462 } __attribute__((aligned(8)));
463
464 /**
465  * struct kdbus_cmd_free - struct to free a slice of memory in the pool
466  * @offset:             The offset of the memory slice, as returned by other
467  *                      ioctls
468  * @flags:              Flags for the free command, userspace → kernel
469  * @kernel_flags:       Supported flags of the free command, userspace → kernel
470  *
471  * This struct is used with the KDBUS_CMD_FREE ioctl.
472  */
473 struct kdbus_cmd_free {
474         __u64 offset;
475         __u64 flags;
476         __u64 kernel_flags;
477 } __attribute__((aligned(8)));
478
479 /**
480  * enum kdbus_policy_access_type - permissions of a policy record
481  * @_KDBUS_POLICY_ACCESS_NULL:  Uninitialized/invalid
482  * @KDBUS_POLICY_ACCESS_USER:   Grant access to a uid
483  * @KDBUS_POLICY_ACCESS_GROUP:  Grant access to gid
484  * @KDBUS_POLICY_ACCESS_WORLD:  World-accessible
485  */
486 enum kdbus_policy_access_type {
487         _KDBUS_POLICY_ACCESS_NULL,
488         KDBUS_POLICY_ACCESS_USER,
489         KDBUS_POLICY_ACCESS_GROUP,
490         KDBUS_POLICY_ACCESS_WORLD,
491 };
492
493 /**
494  * enum kdbus_policy_access_flags - mode flags
495  * @KDBUS_POLICY_OWN:           Allow to own a well-known name
496  *                              Implies KDBUS_POLICY_TALK and KDBUS_POLICY_SEE
497  * @KDBUS_POLICY_TALK:          Allow communication to a well-known name
498  *                              Implies KDBUS_POLICY_SEE
499  * @KDBUS_POLICY_SEE:           Allow to see a well-known name
500  */
501 enum kdbus_policy_type {
502         KDBUS_POLICY_SEE        = 0,
503         KDBUS_POLICY_TALK,
504         KDBUS_POLICY_OWN,
505 };
506
507 /**
508  * enum kdbus_hello_flags - flags for struct kdbus_cmd_hello
509  * @KDBUS_HELLO_ACCEPT_FD:      The connection allows the reception of
510  *                              any passed file descriptors
511  * @KDBUS_HELLO_ACTIVATOR:      Special-purpose connection which registers
512  *                              a well-know name for a process to be started
513  *                              when traffic arrives
514  * @KDBUS_HELLO_POLICY_HOLDER:  Special-purpose connection which registers
515  *                              policy entries for a name. The provided name
516  *                              is not activated and not registered with the
517  *                              name database, it only allows unprivileged
518  *                              connections to aquire a name, talk or discover
519  *                              a service
520  * @KDBUS_HELLO_MONITOR:        Special-purpose connection to monitor
521  *                              bus traffic
522  */
523 enum kdbus_hello_flags {
524         KDBUS_HELLO_ACCEPT_FD           =  1ULL <<  0,
525         KDBUS_HELLO_ACTIVATOR           =  1ULL <<  1,
526         KDBUS_HELLO_POLICY_HOLDER       =  1ULL <<  2,
527         KDBUS_HELLO_MONITOR             =  1ULL <<  3,
528 };
529
530 /**
531  * enum kdbus_attach_flags - flags for metadata attachments
532  * @KDBUS_ATTACH_TIMESTAMP:     Timestamp
533  * @KDBUS_ATTACH_CREDS:         Credentials
534  * @KDBUS_ATTACH_AUXGROUPS:     Auxiliary groups
535  * @KDBUS_ATTACH_NAMES:         Well-known names
536  * @KDBUS_ATTACH_COMM_TID:      The "comm" process identifier of the TID
537  * @KDBUS_ATTACH_COMM_PID:      The "comm" process identifier of the PID
538  * @KDBUS_ATTACH_EXE:           The path of the executable
539  * @KDBUS_ATTACH_CMDLINE:       The process command line
540  * @KDBUS_ATTACH_CGROUP:        The croup membership
541  * @KDBUS_ATTACH_CAPS:          The process capabilities
542  * @KDBUS_ATTACH_SECLABEL:      The security label
543  * @KDBUS_ATTACH_AUDIT:         The audit IDs
544  * @KDBUS_ATTACH_CONN_NAME:     The human-readable connection name
545  * @_KDBUS_ATTACH_ALL:          All of the above
546  */
547 enum kdbus_attach_flags {
548         KDBUS_ATTACH_TIMESTAMP          =  1ULL <<  0,
549         KDBUS_ATTACH_CREDS              =  1ULL <<  1,
550         KDBUS_ATTACH_AUXGROUPS          =  1ULL <<  2,
551         KDBUS_ATTACH_NAMES              =  1ULL <<  3,
552         KDBUS_ATTACH_TID_COMM           =  1ULL <<  4,
553         KDBUS_ATTACH_PID_COMM           =  1ULL <<  5,
554         KDBUS_ATTACH_EXE                =  1ULL <<  6,
555         KDBUS_ATTACH_CMDLINE            =  1ULL <<  7,
556         KDBUS_ATTACH_CGROUP             =  1ULL <<  8,
557         KDBUS_ATTACH_CAPS               =  1ULL <<  9,
558         KDBUS_ATTACH_SECLABEL           =  1ULL << 10,
559         KDBUS_ATTACH_AUDIT              =  1ULL << 11,
560         KDBUS_ATTACH_CONN_NAME          =  1ULL << 12,
561         _KDBUS_ATTACH_ALL               =  (1ULL << 13) - 1,
562 };
563
564 /**
565  * struct kdbus_cmd_hello - struct to say hello to kdbus
566  * @size:               The total size of the structure
567  * @flags:              Connection flags (KDBUS_HELLO_*), userspace → kernel
568  * @kernel_flags:       Supported connection flags, kernel → userspace
569  * @attach_flags:       Mask of metadata to attach to each message sent
570  *                      (KDBUS_ATTACH_*)
571  * @bus_flags:          The flags field copied verbatim from the original
572  *                      KDBUS_CMD_BUS_MAKE ioctl. It's intended to be useful
573  *                      to do negotiation of features of the payload that is
574  *                      transferred (kernel → userspace)
575  * @id:                 The ID of this connection (kernel → userspace)
576  * @pool_size:          Size of the connection's buffer where the received
577  *                      messages are placed
578  * @bloom:              The bloom properties of the bus, specified
579  *                      by the bus creator (kernel → userspace)
580  * @id128:              Unique 128-bit ID of the bus (kernel → userspace)
581  * @items:              A list of items
582  *
583  * This struct is used with the KDBUS_CMD_HELLO ioctl.
584  */
585 struct kdbus_cmd_hello {
586         __u64 size;
587         __u64 flags;
588         __u64 kernel_flags;
589         __u64 attach_flags;
590         __u64 bus_flags;
591         __u64 id;
592         __u64 pool_size;
593         struct kdbus_bloom_parameter bloom;
594         __u8 id128[16];
595         struct kdbus_item items[0];
596 } __attribute__((aligned(8)));
597
598 /**
599  * enum kdbus_make_flags - Flags for KDBUS_CMD_{BUS,EP,NS}_MAKE
600  * @KDBUS_MAKE_ACCESS_GROUP:    Make the device node group-accessible
601  * @KDBUS_MAKE_ACCESS_WORLD:    Make the device node world-accessible
602  */
603 enum kdbus_make_flags {
604         KDBUS_MAKE_ACCESS_GROUP         = 1ULL <<  0,
605         KDBUS_MAKE_ACCESS_WORLD         = 1ULL <<  1,
606 };
607
608 /**
609  * struct kdbus_cmd_make - struct to make a bus, an endpoint or a domain
610  * @size:               The total size of the struct
611  * @flags:              Properties for the bus/ep/domain to create,
612  *                      userspace → kernel
613  * @kernel_flags:       Supported flags for the used command, kernel → userspace
614  * @items:              Items describing details
615  *
616  * This structure is used with the KDBUS_CMD_BUS_MAKE, KDBUS_CMD_ENDPOINT_MAKE
617  * and KDBUS_CMD_DOMAIN_MAKE ioctls.
618  */
619 struct kdbus_cmd_make {
620         __u64 size;
621         __u64 flags;
622         __u64 kernel_flags;
623         struct kdbus_item items[0];
624 } __attribute__((aligned(8)));
625
626 /**
627  * enum kdbus_name_flags - properties of a well-known name
628  * @KDBUS_NAME_REPLACE_EXISTING:        Try to replace name of other connections
629  * @KDBUS_NAME_ALLOW_REPLACEMENT:       Allow the replacement of the name
630  * @KDBUS_NAME_QUEUE:                   Name should be queued if busy
631  * @KDBUS_NAME_IN_QUEUE:                Name is queued
632  * @KDBUS_NAME_ACTIVATOR:               Name is owned by a activator connection
633  */
634 enum kdbus_name_flags {
635         KDBUS_NAME_REPLACE_EXISTING     = 1ULL <<  0,
636         KDBUS_NAME_ALLOW_REPLACEMENT    = 1ULL <<  1,
637         KDBUS_NAME_QUEUE                = 1ULL <<  2,
638         KDBUS_NAME_IN_QUEUE             = 1ULL <<  3,
639         KDBUS_NAME_ACTIVATOR            = 1ULL <<  4,
640 };
641
642 /**
643  * struct kdbus_cmd_name - struct to describe a well-known name
644  * @size:               The total size of the struct
645  * @flags:              Flags for a name entry (KDBUS_NAME_*),
646  *                      userspace → kernel, kernel → userspace
647  * @kernel_flags:       Supported flags for a name entry, kernel → userspace
648  * @items:              Item list, containing the well-known name as
649  *                      KDBUS_ITEM_NAME
650  *
651  * This structure is used with the KDBUS_CMD_NAME_ACQUIRE ioctl.
652  */
653 struct kdbus_cmd_name {
654         __u64 size;
655         __u64 flags;
656         __u64 kernel_flags;
657         struct kdbus_item items[0];
658 } __attribute__((aligned(8)));
659
660 /**
661  * struct kdbus_name_info - struct to describe a well-known name
662  * @size:               The total size of the struct
663  * @flags:              Flags for a name entry (KDBUS_NAME_*),
664  * @conn_flags:         The flags of the owning connection (KDBUS_HELLO_*)
665  * @owner_id:           The current owner of the name
666  * @items:              Item list, containing the well-known name as
667  *                      KDBUS_ITEM_NAME
668  *
669  * This structure is used as return struct for the KDBUS_CMD_NAME_LIST ioctl.
670  */
671 struct kdbus_name_info {
672         __u64 size;
673         __u64 flags;
674         __u64 conn_flags;
675         __u64 owner_id;
676         struct kdbus_item items[0];
677 } __attribute__((aligned(8)));
678
679 /**
680  * enum kdbus_name_list_flags - what to include into the returned list
681  * @KDBUS_NAME_LIST_UNIQUE:     All active connections
682  * @KDBUS_NAME_LIST_NAMES:      All known well-known names
683  * @KDBUS_NAME_LIST_ACTIVATORS: All activator connections
684  * @KDBUS_NAME_LIST_QUEUED:     All queued-up names
685  */
686 enum kdbus_name_list_flags {
687         KDBUS_NAME_LIST_UNIQUE          = 1ULL <<  0,
688         KDBUS_NAME_LIST_NAMES           = 1ULL <<  1,
689         KDBUS_NAME_LIST_ACTIVATORS      = 1ULL <<  2,
690         KDBUS_NAME_LIST_QUEUED          = 1ULL <<  3,
691 };
692
693 /**
694  * struct kdbus_cmd_name_list - request a list of name entries
695  * @flags:              Flags for the query (KDBUS_NAME_LIST_*),
696  *                      userspace → kernel
697  * @kernel_flags:       Supported flags for queries, kernel → userspace
698  * @offset:             The returned offset in the caller's pool buffer.
699  *                      The user must use KDBUS_CMD_FREE to free the
700  *                      allocated memory.
701  *
702  * This structure is used with the KDBUS_CMD_NAME_LIST ioctl.
703  */
704 struct kdbus_cmd_name_list {
705         __u64 flags;
706         __u64 kernel_flags;
707         __u64 offset;
708 } __attribute__((aligned(8)));
709
710 /**
711  * struct kdbus_name_list - information returned by KDBUS_CMD_NAME_LIST
712  * @size:               The total size of the structure
713  * @names:              A list of names
714  *
715  * Note that the user is responsible for freeing the allocated memory with
716  * the KDBUS_CMD_FREE ioctl.
717  */
718 struct kdbus_name_list {
719         __u64 size;
720         struct kdbus_name_info names[0];
721 };
722
723 /**
724  * struct kdbus_cmd_conn_info - struct used for KDBUS_CMD_CONN_INFO ioctl
725  * @size:               The total size of the struct
726  * @flags:              KDBUS_ATTACH_* flags, userspace → kernel
727  * @kernel_flags:       Supported KDBUS_ATTACH_* flags, kernel → userspace
728  * @id:                 The 64-bit ID of the connection. If set to zero, passing
729  *                      @name is required. kdbus will look up the name to
730  *                      determine the ID in this case.
731  * @offset:             Returned offset in the caller's pool buffer where the
732  *                      kdbus_conn_info struct result is stored. The user must
733  *                      use KDBUS_CMD_FREE to free the allocated memory.
734  * @name:               The optional well-known name to look up. Only needed in
735  *                      case @id is zero.
736  *
737  * On success, the KDBUS_CMD_CONN_INFO ioctl will return 0 and @offset will
738  * tell the user the offset in the connection pool buffer at which to find the
739  * result in a struct kdbus_conn_info.
740  */
741 struct kdbus_cmd_conn_info {
742         __u64 size;
743         __u64 flags;
744         __u64 kernel_flags;
745         __u64 id;
746         __u64 offset;
747         struct kdbus_item items[0];
748 } __attribute__((aligned(8)));
749
750 /**
751  * struct kdbus_conn_info - information returned by KDBUS_CMD_CONN_INFO
752  * @size:               The total size of the struct
753  * @id:                 The connection's 64-bit ID
754  * @flags:              The connection's flags
755  * @items:              A list of struct kdbus_item
756  *
757  * Note that the user is responsible for freeing the allocated memory with
758  * the KDBUS_CMD_FREE ioctl.
759  */
760 struct kdbus_conn_info {
761         __u64 size;
762         __u64 id;
763         __u64 flags;
764         struct kdbus_item items[0];
765 };
766
767 /**
768  * struct kdbus_cmd_update - update flags of a connection
769  * @size:               The total size of the struct
770  * @flags:              Flags for the update command, userspace → kernel
771  * @kernel_flags:       Supported flags for this command, kernel → userspace
772  * @items:              A list of struct kdbus_item
773  *
774  * This struct is used with the KDBUS_CMD_CONN_UPDATE ioctl.
775  */
776 struct kdbus_cmd_update {
777         __u64 size;
778         __u64 flags;
779         __u64 kernel_flags;
780         struct kdbus_item items[0];
781 } __attribute__((aligned(8)));
782
783 /**
784  * enum kdbus_cmd_match_flags - flags to control the KDBUS_CMD_MATCH_ADD ioctl
785  * @KDBUS_MATCH_REPLACE:        If entries with the supplied cookie already
786  *                              exists, remove them before installing the new
787  *                              matches.
788  */
789 enum kdbus_cmd_match_flags {
790         KDBUS_MATCH_REPLACE     = 1ULL <<  0,
791 };
792
793 /**
794  * struct kdbus_cmd_match - struct to add or remove matches
795  * @size:               The total size of the struct
796  * @cookie:             Userspace supplied cookie. When removing, the cookie
797  *                      identifies the match to remove
798  * @flags:              Flags for match command (KDBUS_MATCH_*),
799  *                      userspace → kernel
800  * @kernel_flags:       Supported flags of the used command, kernel → userspace
801  * @items:              A list of items for additional information
802  *
803  * This structure is used with the KDBUS_CMD_ADD_MATCH and
804  * KDBUS_CMD_REMOVE_MATCH ioctl.
805  */
806 struct kdbus_cmd_match {
807         __u64 size;
808         __u64 cookie;
809         __u64 flags;
810         __u64 kernel_flags;
811         struct kdbus_item items[0];
812 } __attribute__((aligned(8)));
813
814 /**
815  * enum kdbus_ioctl_type - Ioctl API
816  * @KDBUS_CMD_BUS_MAKE:         After opening the "control" device node, this
817  *                              command creates a new bus with the specified
818  *                              name. The bus is immediately shut down and
819  *                              cleaned up when the opened "control" device node
820  *                              is closed.
821  * @KDBUS_CMD_DOMAIN_MAKE:      Similar to KDBUS_CMD_BUS_MAKE, but it creates a
822  *                              new kdbus domain.
823  * @KDBUS_CMD_ENDPOINT_MAKE:    Creates a new named special endpoint to talk to
824  *                              the bus. Such endpoints usually carry a more
825  *                              restrictive policy and grant restricted access
826  *                              to specific applications.
827  * @KDBUS_CMD_HELLO:            By opening the bus device node a connection is
828  *                              created. After a HELLO the opened connection
829  *                              becomes an active peer on the bus.
830  * @KDBUS_CMD_BYEBYE:           Disconnect a connection. If there are no
831  *                              messages queued up in the connection's pool,
832  *                              the call succeeds, and the handle is rendered
833  *                              unusable. Otherwise, -EBUSY is returned without
834  *                              any further side-effects.
835  * @KDBUS_CMD_MSG_SEND:         Send a message and pass data from userspace to
836  *                              the kernel.
837  * @KDBUS_CMD_MSG_RECV:         Receive a message from the kernel which is
838  *                              placed in the receiver's pool.
839  * @KDBUS_CMD_MSG_CANCEL:       Cancel a pending request of a message that
840  *                              blocks while waiting for a reply. The parameter
841  *                              denotes the cookie of the message in flight.
842  * @KDBUS_CMD_FREE:             Release the allocated memory in the receiver's
843  *                              pool.
844  * @KDBUS_CMD_NAME_ACQUIRE:     Request a well-known bus name to associate with
845  *                              the connection. Well-known names are used to
846  *                              address a peer on the bus.
847  * @KDBUS_CMD_NAME_RELEASE:     Release a well-known name the connection
848  *                              currently owns.
849  * @KDBUS_CMD_NAME_LIST:        Retrieve the list of all currently registered
850  *                              well-known and unique names.
851  * @KDBUS_CMD_CONN_INFO:        Retrieve credentials and properties of the
852  *                              initial creator of the connection. The data was
853  *                              stored at registration time and does not
854  *                              necessarily represent the connected process or
855  *                              the actual state of the process.
856  * @KDBUS_CMD_CONN_UPDATE:      Update the properties of a connection. Used to
857  *                              update the metadata subscription mask and
858  *                              policy.
859  * @KDBUS_CMD_ENDPOINT_UPDATE:  Update the properties of a custom enpoint. Used
860  *                              to update the policy.
861  * @KDBUS_CMD_MATCH_ADD:        Install a match which broadcast messages should
862  *                              be delivered to the connection.
863  * @KDBUS_CMD_MATCH_REMOVE:     Remove a current match for broadcast messages.
864  */
865 enum kdbus_ioctl_type {
866         KDBUS_CMD_BUS_MAKE =            _IOW(KDBUS_IOCTL_MAGIC, 0x00,
867                                              struct kdbus_cmd_make),
868         KDBUS_CMD_DOMAIN_MAKE =         _IOW(KDBUS_IOCTL_MAGIC, 0x10,
869                                              struct kdbus_cmd_make),
870         KDBUS_CMD_ENDPOINT_MAKE =       _IOW(KDBUS_IOCTL_MAGIC, 0x20,
871                                              struct kdbus_cmd_make),
872
873         KDBUS_CMD_HELLO =               _IOWR(KDBUS_IOCTL_MAGIC, 0x30,
874                                               struct kdbus_cmd_hello),
875         KDBUS_CMD_BYEBYE =              _IO(KDBUS_IOCTL_MAGIC, 0x31),
876
877         KDBUS_CMD_MSG_SEND =            _IOWR(KDBUS_IOCTL_MAGIC, 0x40,
878                                               struct kdbus_msg),
879         KDBUS_CMD_MSG_RECV =            _IOWR(KDBUS_IOCTL_MAGIC, 0x41,
880                                               struct kdbus_cmd_recv),
881         KDBUS_CMD_MSG_CANCEL =          _IOW(KDBUS_IOCTL_MAGIC, 0x42,
882                                              struct kdbus_cmd_cancel),
883         KDBUS_CMD_FREE =                _IOW(KDBUS_IOCTL_MAGIC, 0x43,
884                                              struct kdbus_cmd_free),
885
886         KDBUS_CMD_NAME_ACQUIRE =        _IOWR(KDBUS_IOCTL_MAGIC, 0x50,
887                                               struct kdbus_cmd_name),
888         KDBUS_CMD_NAME_RELEASE =        _IOW(KDBUS_IOCTL_MAGIC, 0x51,
889                                              struct kdbus_cmd_name),
890         KDBUS_CMD_NAME_LIST =           _IOWR(KDBUS_IOCTL_MAGIC, 0x52,
891                                               struct kdbus_cmd_name_list),
892
893         KDBUS_CMD_CONN_INFO =           _IOWR(KDBUS_IOCTL_MAGIC, 0x60,
894                                               struct kdbus_cmd_conn_info),
895         KDBUS_CMD_CONN_UPDATE =         _IOW(KDBUS_IOCTL_MAGIC, 0x61,
896                                              struct kdbus_cmd_update),
897
898         KDBUS_CMD_ENDPOINT_UPDATE =     _IOW(KDBUS_IOCTL_MAGIC, 0x71,
899                                              struct kdbus_cmd_update),
900
901         KDBUS_CMD_MATCH_ADD =           _IOW(KDBUS_IOCTL_MAGIC, 0x80,
902                                              struct kdbus_cmd_match),
903         KDBUS_CMD_MATCH_REMOVE =        _IOW(KDBUS_IOCTL_MAGIC, 0x81,
904                                              struct kdbus_cmd_match),
905 };
906
907 #endif /* _KDBUS_UAPI_H_ */