2 * Copyright (C) 2013 Kay Sievers
3 * Copyright (C) 2013 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
4 * Copyright (C) 2013 Linux Foundation
6 * kdbus is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License as published by the
8 * Free Software Foundation; either version 2.1 of the License, or (at
9 * your option) any later version.
16 #include <sys/ioctl.h>
17 #include <sys/types.h>
18 #include <linux/types.h>
21 #define KDBUS_IOC_MAGIC 0x95
23 /* Message sent from kernel to userspace, when the owner or starter of
24 * a well-known name changes */
25 struct kdbus_manager_msg_name_change {
28 __u64 flags; /* 0 or (possibly?) KDBUS_CMD_NAME_IN_QUEUE */
32 struct kdbus_manager_msg_id_change {
34 __u64 flags; /* The kernel flags field from KDBUS_CMD_HELLO */
43 /* The starttime of the process PID. This is useful to detect
44 PID overruns from the client side. i.e. if you use the PID to
45 look something up in /proc/$PID/ you can afterwards check the
46 starttime field of it to ensure you didn't run into a PID
51 #define KDBUS_SRC_ID_KERNEL (0)
52 #define KDBUS_DST_ID_WELL_KNOWN_NAME (0)
53 #define KDBUS_MATCH_SRC_ID_ANY (~0ULL)
54 #define KDBUS_DST_ID_BROADCAST (~0ULL)
56 /* Message Data Types */
58 /* Filled in by userspace */
59 KDBUS_MSG_NULL, /* empty record */
60 KDBUS_MSG_PAYLOAD, /* .data */
61 KDBUS_MSG_PAYLOAD_VEC, /* .data_vec, converted into _PAYLOAD at delivery */
62 KDBUS_MSG_MMAP, /* .data_vec */
63 KDBUS_MSG_MMAP_DONATE, /* .data_vec, unmap the memory from the sender */
64 KDBUS_MSG_UNIX_FDS, /* .data_fds of file descriptors */
65 KDBUS_MSG_BLOOM, /* for broadcasts, carries bloom filter blob */
66 KDBUS_MSG_DST_NAME, /* destination's well-known name */
68 /* Filled in by kernelspace */
69 KDBUS_MSG_SRC_NAMES = 0x200,/* NUL separated string list with well-known names of source */
70 KDBUS_MSG_TIMESTAMP, /* .ts_ns of CLOCK_MONOTONIC */
71 KDBUS_MSG_SRC_CREDS, /* .creds */
72 KDBUS_MSG_SRC_COMM, /* optional */
73 KDBUS_MSG_SRC_THREAD_COMM, /* optional */
74 KDBUS_MSG_SRC_EXE, /* optional */
75 KDBUS_MSG_SRC_CMDLINE, /* optional */
76 KDBUS_MSG_SRC_CGROUP, /* optional, specified which one */
77 KDBUS_MSG_SRC_CAPS, /* caps data blob */
78 KDBUS_MSG_SRC_SECLABEL, /* NUL terminated string */
79 KDBUS_MSG_SRC_AUDIT, /* array of two uint64_t of audit loginuid + sessiond */
81 /* Special messages from kernel, consisting of one and only one of these data blocks */
82 KDBUS_MSG_NAME_ADD = 0x400,/* .name_change */
83 KDBUS_MSG_NAME_REMOVE, /* .name_change */
84 KDBUS_MSG_NAME_CHANGE, /* .name_change */
85 KDBUS_MSG_ID_ADD, /* .id_change */
86 KDBUS_MSG_ID_REMOVE, /* .id_change */
87 KDBUS_MSG_ID_CHANGE, /* .id_change */
88 KDBUS_MSG_REPLY_TIMEOUT, /* empty, but .reply_cookie in .kdbus_msg is filled in */
89 KDBUS_MSG_REPLY_DEAD, /* dito */
98 * struct kdbus_msg_data - chain of data blocks
100 * size: overall data record size
101 * type: kdbus_msg_data_type of data
103 struct kdbus_msg_data {
114 struct kdbus_vec vec;
116 /* specific fields */
117 int fds[0]; /* int array of file descriptors */
118 __u64 ts_ns; /* timestamp in nanoseconds */
119 struct kdbus_creds creds;
120 struct kdbus_manager_msg_name_change name_change;
121 struct kdbus_manager_msg_id_change id_change;
126 KDBUS_MSG_FLAGS_EXPECT_REPLY = 1,
127 KDBUS_MSG_FLAGS_NO_AUTO_START = 2, /* possibly? */
131 KDBUS_PAYLOAD_NONE = 0,
132 KDBUS_PAYLOAD_DBUS1 = 0x4442757356657231ULL, /* 'DBusVer1' */
133 KDBUS_PAYLOAD_GVARIANT = 0x4756617269616e74ULL, /* 'GVariant' */
140 * dst_id: destination id
141 * flags: KDBUS_MSG_FLAGS_*
142 * data_size: overall message size
146 * src_id: who sent the message
151 __u64 dst_id; /* connection, 0 == name in data, ~0 broadcast */
152 __u64 src_id; /* connection, 0 == kernel */
153 __u64 payload_type; /* 'DBusVer1', 'GVariant', ... */
154 __u64 cookie; /* userspace-supplied cookie */
156 __u64 cookie_reply; /* cookie we reply to */
157 __u64 timeout_ns; /* timespan to wait for reply */
159 struct kdbus_msg_data data[0];
174 KDBUS_POLICY_RECV = 4,
175 KDBUS_POLICY_SEND = 2,
176 KDBUS_POLICY_OWN = 1,
179 struct kdbus_policy {
181 __u64 type; /* NAME or ACCESS */
185 __u32 type; /* USER, GROUP, WORLD */
186 __u32 bits; /* RECV, SEND, OWN */
187 __u64 id; /* uid, gid, 0 */
192 struct kdbus_cmd_policy {
194 __u8 buffer[0]; /* a series of KDBUS_POLICY_NAME plus one or more KDBUS_POLICY_ACCESS each. */
198 KDBUS_CMD_HELLO_STARTER = 1,
199 KDBUS_CMD_HELLO_ACCEPT_FD = 2,
200 KDBUS_CMD_HELLO_ACCEPT_MMAP = 4,
204 KDBUS_CMD_FNAME_ACCESS_GROUP = 1,
205 KDBUS_CMD_FNAME_ACCESS_WORLD = 2,
206 KDBUS_CMD_FNAME_POLICY_OPEN = 4,
209 struct kdbus_cmd_hello {
210 /* userspace → kernel, kernel → userspace */
211 __u64 kernel_flags; /* userspace specifies its
212 * capabilities and more, kernel
213 * returns its capabilites and
214 * more. Kernel might refuse client's
215 * capabilities by returning an error
216 * from KDBUS_CMD_HELLO */
218 /* userspace → kernel */
219 __u64 pid; /* To allow translator services which
220 * connect to the bus on behalf of
221 * somebody else, allow specifiying
222 * the PID of the client to connect on
223 * behalf on. Normal clients should
224 * pass this as 0 (i.e. to do things
225 * under their own PID). Priviliged
226 * clients can pass != 0, to operate
227 * on behalf of somebody else. */
229 /* kernel → userspace */
230 __u64 bus_flags; /* this is .flags copied verbatim from
231 * from original KDBUS_CMD_BUS_MAKE
232 * ioctl. It's intended to be useful
233 * to do negotiation of features of
234 * the payload that is transfreted. */
235 __u64 id; /* peer id */
238 struct kdbus_cmd_fname {
240 __u64 kernel_flags; /* userspace → kernel, kernel → userspace
241 * When creating a bus/ns/ep feature
242 * kernel negotiation done the same
243 * way as for KDBUS_CMD_BUS_MAKE. */
244 __u64 user_flags; /* userspace → kernel
245 * When a bus is created this value is
246 * copied verbatim into the bus
247 * structure and returned from
248 * KDBUS_CMD_HELLO, later */
253 /* userspace → kernel */
254 KDBUS_CMD_NAME_REPLACE_EXISTING = 1,
255 KDBUS_CMD_NAME_QUEUE = 2,
256 KDBUS_CMD_NAME_ALLOW_REPLACEMENT = 4,
257 KDBUS_CMD_NAME_STEAL_MESSAGES = 8,
259 /* kernel → userspace */
260 KDBUS_CMD_NAME_IN_QUEUE = 0x200,
263 struct kdbus_cmd_name {
266 __u64 id; /* We allow registration/deregestration of names of other peers */
270 struct kdbus_cmd_names {
272 struct kdbus_cmd_name names[0];
276 KDBUS_CMD_NAME_INFO_ITEM_NAME,
277 KDBUS_CMD_NAME_INFO_ITEM_SECLABEL,
278 KDBUS_CMD_NAME_INFO_ITEM_AUDIT,
281 struct kdbus_cmd_name_info_item {
287 struct kdbus_cmd_name_info {
288 __u64 size; /* overall size of info */
290 __u64 id; /* either ID, or 0 and _ITEM_NAME follows */
291 struct kdbus_creds creds;
292 struct kdbus_cmd_name_info_item item[0]; /* list of item records */
296 KDBUS_CMD_MATCH_BLOOM, /* Matches a mask blob against KDBUS_MSG_BLOOM */
297 KDBUS_CMD_MATCH_SRC_NAME, /* Matches a name string against KDBUS_MSG_SRC_NAMES */
298 KDBUS_CMD_MATCH_NAME_ADD, /* Matches a name string against KDBUS_MSG_NAME_ADD */
299 KDBUS_CMD_MATCH_NAME_REMOVE, /* Matches a name string against KDBUS_MSG_NAME_REMOVE */
300 KDBUS_CMD_MATCH_NAME_CHANGE, /* Matches a name string against KDBUS_MSG_NAME_CHANGE */
301 KDBUS_CMD_MATCH_ID_ADD, /* Matches an ID against KDBUS_MSG_ID_ADD */
302 KDBUS_CMD_MATCH_ID_REMOVE, /* Matches an ID against KDBUS_MSG_ID_REMOVE */
303 KDBUS_CMD_MATCH_ID_CHANGE, /* Matches an ID against KDBUS_MSG_ID_CHANGE */
306 struct kdbus_cmd_match_item {
312 struct kdbus_cmd_match {
314 __u64 id; /* We allow registration/deregestration of matches for other peers */
315 __u64 cookie; /* userspace supplied cookie; when removing; kernel deletes everything with same cookie */
316 __u64 src_id; /* ~0: any. other: exact unique match */
317 struct kdbus_cmd_match_item items[0];
320 struct kdbus_cmd_monitor {
321 __u64 id; /* We allow setting the monitor flag of other peers */
322 int enabled; /* A boolean to enable/disable monitoring */
326 * control nodes: unset
327 * bus owner (via KDBUS_CMD_BUS_MAKE)
328 * ns owner (via KDBUS_CMD_NS_MAKE)
331 * connected (via KDBUS_CMD_HELLO)
332 * starter (via KDBUS_CMD_HELLO with KDBUS_CMD_HELLO_STARTER)
333 * ep owner (via KDBUS_CMD_EP_MAKE)
336 /* kdbus control node commands: require unset state */
337 KDBUS_CMD_BUS_MAKE = _IOWR(KDBUS_IOC_MAGIC, 0x00, struct kdbus_cmd_fname),
338 KDBUS_CMD_NS_MAKE = _IOWR(KDBUS_IOC_MAGIC, 0x10, struct kdbus_cmd_fname),
340 /* kdbus control node commands: require bus owner state */
341 KDBUS_CMD_BUS_POLICY_SET = _IOWR(KDBUS_IOC_MAGIC, 0x20, struct kdbus_cmd_policy),
343 /* kdbus ep node commands: require unset state */
344 KDBUS_CMD_EP_MAKE = _IOWR(KDBUS_IOC_MAGIC, 0x30, struct kdbus_cmd_fname),
345 KDBUS_CMD_HELLO = _IOWR(KDBUS_IOC_MAGIC, 0x31, struct kdbus_cmd_hello),
347 /* kdbus ep node commands: require connected state */
348 KDBUS_CMD_MSG_SEND = _IOWR(KDBUS_IOC_MAGIC, 0x40, struct kdbus_msg),
349 KDBUS_CMD_MSG_RECV = _IOWR(KDBUS_IOC_MAGIC, 0x41, struct kdbus_msg),
351 KDBUS_CMD_NAME_ACQUIRE = _IOWR(KDBUS_IOC_MAGIC, 0x50, struct kdbus_cmd_name),
352 KDBUS_CMD_NAME_RELEASE = _IOWR(KDBUS_IOC_MAGIC, 0x51, struct kdbus_cmd_name),
353 KDBUS_CMD_NAME_LIST = _IOWR(KDBUS_IOC_MAGIC, 0x52, struct kdbus_cmd_names),
354 KDBUS_CMD_NAME_QUERY = _IOWR(KDBUS_IOC_MAGIC, 0x53, struct kdbus_cmd_name_info),
356 KDBUS_CMD_MATCH_ADD = _IOWR(KDBUS_IOC_MAGIC, 0x60, struct kdbus_cmd_match),
357 KDBUS_CMD_MATCH_REMOVE = _IOWR(KDBUS_IOC_MAGIC, 0x61, struct kdbus_cmd_match),
358 KDBUS_CMD_MONITOR = _IOWR(KDBUS_IOC_MAGIC, 0x62, struct kdbus_cmd_monitor),
360 /* kdbus ep node commands: require ep owner state */
361 KDBUS_CMD_EP_POLICY_SET = _IOWR(KDBUS_IOC_MAGIC, 0x70, struct kdbus_cmd_policy),
367 * - allow HELLO to change unique names
368 * - allow HELLO without assigning a unique name at all
369 * - when receive fails due to too small buffer return real size
370 * - when receiving maybe allow read-only mmaping into reciving process memory space or so?