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
56 struct kdbus_timestamp {
61 #define KDBUS_SRC_ID_KERNEL (0)
62 #define KDBUS_DST_ID_WELL_KNOWN_NAME (0)
63 #define KDBUS_MATCH_SRC_ID_ANY (~0ULL)
64 #define KDBUS_DST_ID_BROADCAST (~0ULL)
66 /* Message Data Types */
68 /* Filled in by userspace */
69 KDBUS_MSG_NULL, /* empty record */
70 KDBUS_MSG_PAYLOAD, /* .data */
71 KDBUS_MSG_PAYLOAD_VEC, /* .data_vec */
72 KDBUS_MSG_UNIX_FDS, /* .data_fds of file descriptors */
73 KDBUS_MSG_BLOOM, /* for broadcasts, carries bloom filter blob in .data */
74 KDBUS_MSG_DST_NAME, /* destination's well-known name, in .str */
76 /* Filled in by kernelspace */
77 KDBUS_MSG_SRC_NAMES = 0x200,/* NUL separated string list with well-known names of source */
78 KDBUS_MSG_TIMESTAMP, /* .timestamp */
79 KDBUS_MSG_SRC_CREDS, /* .creds */
80 KDBUS_MSG_SRC_PID_COMM, /* optional, in .str */
81 KDBUS_MSG_SRC_TID_COMM, /* optional, in .str */
82 KDBUS_MSG_SRC_EXE, /* optional, in .str */
83 KDBUS_MSG_SRC_CMDLINE, /* optional, in .str (a chain of NUL str) */
84 KDBUS_MSG_SRC_CGROUP, /* optional, in .str */
85 KDBUS_MSG_SRC_CAPS, /* caps data blob, in .data */
86 KDBUS_MSG_SRC_SECLABEL, /* NUL terminated string, in .str */
87 KDBUS_MSG_SRC_AUDIT, /* .audit */
89 /* Special messages from kernel, consisting of one and only one of these data blocks */
90 KDBUS_MSG_NAME_ADD = 0x400,/* .name_change */
91 KDBUS_MSG_NAME_REMOVE, /* .name_change */
92 KDBUS_MSG_NAME_CHANGE, /* .name_change */
93 KDBUS_MSG_ID_ADD, /* .id_change */
94 KDBUS_MSG_ID_REMOVE, /* .id_change */
95 KDBUS_MSG_ID_CHANGE, /* .id_change */
96 KDBUS_MSG_REPLY_TIMEOUT, /* empty, but .reply_cookie in .kdbus_msg is filled in */
97 KDBUS_MSG_REPLY_DEAD, /* dito */
106 * struct kdbus_msg_data - chain of data blocks
108 * size: overall data record size
109 * type: kdbus_msg_data_type of data
111 struct kdbus_msg_data {
122 struct kdbus_vec vec;
124 /* specific fields */
125 int fds[0]; /* int array of file descriptors */
126 struct kdbus_creds creds;
127 struct kdbus_audit audit;
128 struct kdbus_timestamp timestamp;
129 struct kdbus_manager_msg_name_change name_change;
130 struct kdbus_manager_msg_id_change id_change;
135 KDBUS_MSG_FLAGS_EXPECT_REPLY = 1,
136 KDBUS_MSG_FLAGS_NO_AUTO_START = 2, /* possibly? */
140 KDBUS_PAYLOAD_NONE = 0,
141 KDBUS_PAYLOAD_DBUS1 = 0x4442757356657231ULL, /* 'DBusVer1' */
142 KDBUS_PAYLOAD_GVARIANT = 0x4756617269616e74ULL, /* 'GVariant' */
149 * dst_id: destination id
150 * flags: KDBUS_MSG_FLAGS_*
151 * data_size: overall message size
155 * src_id: who sent the message
160 __u64 dst_id; /* connection, 0 == name in data, ~0 broadcast */
161 __u64 src_id; /* connection, 0 == kernel */
162 __u64 payload_type; /* 'DBusVer1', 'GVariant', ... */
163 __u64 cookie; /* userspace-supplied cookie */
165 __u64 cookie_reply; /* cookie we reply to */
166 __u64 timeout_ns; /* timespan to wait for reply */
168 struct kdbus_msg_data items[0];
183 KDBUS_POLICY_RECV = 4,
184 KDBUS_POLICY_SEND = 2,
185 KDBUS_POLICY_OWN = 1,
188 struct kdbus_policy {
190 __u64 type; /* NAME or ACCESS */
194 __u32 type; /* USER, GROUP, WORLD */
195 __u32 bits; /* RECV, SEND, OWN */
196 __u64 id; /* uid, gid, 0 */
201 struct kdbus_cmd_policy {
203 __u8 buffer[0]; /* a series of KDBUS_POLICY_NAME plus one or
204 * more KDBUS_POLICY_ACCESS each. */
208 KDBUS_CMD_HELLO_STARTER = 1 << 0,
209 KDBUS_CMD_HELLO_ACCEPT_FD = 1 << 1,
210 KDBUS_CMD_HELLO_ACCEPT_MMAP = 1 << 2,
212 /* The following have an effect on directed messages only --
213 * not for broadcasts */
214 KDBUS_CMD_HELLO_ATTACH_COMM = 1 << 10,
215 KDBUS_CMD_HELLO_ATTACH_EXE = 1 << 11,
216 KDBUS_CMD_HELLO_ATTACH_CMDLINE = 1 << 12,
217 KDBUS_CMD_HELLO_ATTACH_CGROUP = 1 << 13,
218 KDBUS_CMD_HELLO_ATTACH_CAPS = 1 << 14,
219 KDBUS_CMD_HELLO_ATTACH_SECLABEL = 1 << 15,
220 KDBUS_CMD_HELLO_ATTACH_AUDIT = 1 << 16,
223 /* Flags for kdbus_cmd_bus_make, kdbus_cmd_ep_make and
224 * kdbus_cmd_ns_make */
226 KDBUS_ACCESS_GROUP = 1,
227 KDBUS_ACCESS_WORLD = 2,
228 KDBUS_POLICY_OPEN = 4,
231 struct kdbus_cmd_hello {
232 /* userspace → kernel, kernel → userspace */
233 __u64 conn_flags; /* userspace specifies its
234 * capabilities and more, kernel
235 * returns its capabilites and
236 * more. Kernel might refuse client's
237 * capabilities by returning an error
238 * from KDBUS_CMD_HELLO */
240 /* userspace → kernel */
241 __u64 pid; /* To allow translator services which
242 * connect to the bus on behalf of
243 * somebody else, allow specifiying
244 * the PID of the client to connect on
245 * behalf on. Normal clients should
246 * pass this as 0 (i.e. to do things
247 * under their own PID). Priviliged
248 * clients can pass != 0, to operate
249 * on behalf of somebody else. */
251 /* kernel → userspace */
252 __u64 bus_flags; /* this is .flags copied verbatim from
253 * from original KDBUS_CMD_BUS_MAKE
254 * ioctl. It's intended to be useful
255 * to do negotiation of features of
256 * the payload that is transfreted. */
257 __u64 id; /* peer id */
258 __u64 bloom_size; /* The bloom filter size chosen by the
262 struct kdbus_cmd_bus_make {
264 __u64 flags; /* userspace → kernel, kernel → userspace
265 * When creating a bus feature
266 * kernel negotiation. */
267 __u64 bus_flags; /* userspace → kernel
268 * When a bus is created this value is
269 * copied verbatim into the bus
270 * structure and returned from
271 * KDBUS_CMD_HELLO, later */
272 __u64 cgroup_id; /* the cgroup hierarchy ID for which
273 * to attach cgroup membership paths
274 * to messages. 0 if no cgroup data
275 * shall be attached. */
276 __u64 bloom_size; /* Size of the bloom filter for this bus. */
280 struct kdbus_cmd_ep_make {
282 __u64 flags; /* userspace → kernel, kernel → userspace
283 * When creating an entry point
284 * feature kernel negotiation done the
286 * KDBUS_CMD_BUS_MAKE. Unused for
291 struct kdbus_cmd_ns_make {
293 __u64 flags; /* userspace → kernel, kernel → userspace
294 * When creating an entry point
295 * feature kernel negotiation done the
297 * KDBUS_CMD_BUS_MAKE. Unused for
303 /* userspace → kernel */
304 KDBUS_CMD_NAME_REPLACE_EXISTING = 1,
305 KDBUS_CMD_NAME_QUEUE = 2,
306 KDBUS_CMD_NAME_ALLOW_REPLACEMENT = 4,
308 /* kernel → userspace */
309 KDBUS_CMD_NAME_IN_QUEUE = 0x200,
312 struct kdbus_cmd_name {
315 __u64 id; /* We allow registration/deregestration of names of other peers */
320 struct kdbus_cmd_names {
322 struct kdbus_cmd_name names[0];
326 KDBUS_CMD_NAME_INFO_ITEM_NAME,
327 KDBUS_CMD_NAME_INFO_ITEM_SECLABEL,
328 KDBUS_CMD_NAME_INFO_ITEM_AUDIT,
331 struct kdbus_cmd_name_info_item {
337 struct kdbus_cmd_name_info {
338 __u64 size; /* overall size of info */
340 __u64 id; /* either ID, or 0 and _ITEM_NAME follows */
341 struct kdbus_creds creds;
342 struct kdbus_cmd_name_info_item item[0]; /* list of item records */
346 KDBUS_CMD_MATCH_BLOOM, /* Matches a mask blob against KDBUS_MSG_BLOOM */
347 KDBUS_CMD_MATCH_SRC_NAME, /* Matches a name string against KDBUS_MSG_SRC_NAMES */
348 KDBUS_CMD_MATCH_NAME_ADD, /* Matches a name string against KDBUS_MSG_NAME_ADD */
349 KDBUS_CMD_MATCH_NAME_REMOVE, /* Matches a name string against KDBUS_MSG_NAME_REMOVE */
350 KDBUS_CMD_MATCH_NAME_CHANGE, /* Matches a name string against KDBUS_MSG_NAME_CHANGE */
351 KDBUS_CMD_MATCH_ID_ADD, /* Matches an ID against KDBUS_MSG_ID_ADD */
352 KDBUS_CMD_MATCH_ID_REMOVE, /* Matches an ID against KDBUS_MSG_ID_REMOVE */
353 KDBUS_CMD_MATCH_ID_CHANGE, /* Matches an ID against KDBUS_MSG_ID_CHANGE */
356 struct kdbus_cmd_match_item {
366 struct kdbus_cmd_match {
368 __u64 id; /* We allow registration/deregestration of matches for other peers */
369 __u64 cookie; /* userspace supplied cookie; when removing; kernel deletes everything with same cookie */
370 __u64 src_id; /* ~0: any. other: exact unique match */
371 struct kdbus_cmd_match_item items[0];
374 struct kdbus_cmd_monitor {
375 __u64 id; /* We allow setting the monitor flag of other peers */
376 int enabled; /* A boolean to enable/disable monitoring */
380 * control nodes: unset
381 * bus owner (via KDBUS_CMD_BUS_MAKE)
382 * ns owner (via KDBUS_CMD_NS_MAKE)
385 * connected (via KDBUS_CMD_HELLO)
386 * starter (via KDBUS_CMD_HELLO with KDBUS_CMD_HELLO_STARTER)
387 * ep owner (via KDBUS_CMD_EP_MAKE)
390 /* kdbus control node commands: require unset state */
391 KDBUS_CMD_BUS_MAKE = _IOWR(KDBUS_IOC_MAGIC, 0x00, struct kdbus_cmd_bus_make),
392 KDBUS_CMD_NS_MAKE = _IOWR(KDBUS_IOC_MAGIC, 0x10, struct kdbus_cmd_ns_make),
394 /* kdbus control node commands: require bus owner state */
395 KDBUS_CMD_BUS_POLICY_SET = _IOWR(KDBUS_IOC_MAGIC, 0x20, struct kdbus_cmd_policy),
397 /* kdbus ep node commands: require unset state */
398 KDBUS_CMD_EP_MAKE = _IOWR(KDBUS_IOC_MAGIC, 0x30, struct kdbus_cmd_ep_make),
399 KDBUS_CMD_HELLO = _IOWR(KDBUS_IOC_MAGIC, 0x31, struct kdbus_cmd_hello),
401 /* kdbus ep node commands: require connected state */
402 KDBUS_CMD_MSG_SEND = _IOWR(KDBUS_IOC_MAGIC, 0x40, struct kdbus_msg),
403 KDBUS_CMD_MSG_RECV = _IOWR(KDBUS_IOC_MAGIC, 0x41, struct kdbus_msg),
405 KDBUS_CMD_NAME_ACQUIRE = _IOWR(KDBUS_IOC_MAGIC, 0x50, struct kdbus_cmd_name),
406 KDBUS_CMD_NAME_RELEASE = _IOWR(KDBUS_IOC_MAGIC, 0x51, struct kdbus_cmd_name),
407 KDBUS_CMD_NAME_LIST = _IOWR(KDBUS_IOC_MAGIC, 0x52, struct kdbus_cmd_names),
408 KDBUS_CMD_NAME_QUERY = _IOWR(KDBUS_IOC_MAGIC, 0x53, struct kdbus_cmd_name_info),
410 KDBUS_CMD_MATCH_ADD = _IOWR(KDBUS_IOC_MAGIC, 0x60, struct kdbus_cmd_match),
411 KDBUS_CMD_MATCH_REMOVE = _IOWR(KDBUS_IOC_MAGIC, 0x61, struct kdbus_cmd_match),
412 KDBUS_CMD_MONITOR = _IOWR(KDBUS_IOC_MAGIC, 0x62, struct kdbus_cmd_monitor),
414 /* kdbus ep node commands: require ep owner state */
415 KDBUS_CMD_EP_POLICY_SET = _IOWR(KDBUS_IOC_MAGIC, 0x70, struct kdbus_cmd_policy),