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