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