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>
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.
18 #include <sys/ioctl.h>
19 #include <sys/types.h>
20 #include <linux/types.h>
23 #define KDBUS_IOC_MAGIC 0x95
25 /* Message sent from kernel to userspace, when the owner or starter of
26 * a well-known name changes */
27 struct kdbus_manager_msg_name_change {
30 __u64 flags; /* 0 or (possibly?) KDBUS_NAME_IN_QUEUE */
34 struct kdbus_manager_msg_id_change {
36 __u64 flags; /* The kernel flags field from KDBUS_HELLO */
45 /* The starttime of the process PID. This is useful to detect
46 PID overruns from the client side. i.e. if you use the PID to
47 look something up in /proc/$PID/ you can afterwards check the
48 starttime field of it to ensure you didn't run into a PID
58 struct kdbus_timestamp {
63 #define KDBUS_SRC_ID_KERNEL (0)
64 #define KDBUS_DST_ID_WELL_KNOWN_NAME (0)
65 #define KDBUS_MATCH_SRC_ID_ANY (~0ULL)
66 #define KDBUS_DST_ID_BROADCAST (~0ULL)
68 /* Message Item Types */
72 /* Filled in by userspace */
73 KDBUS_MSG_PAYLOAD, /* .data, inline memory */
74 KDBUS_MSG_PAYLOAD_VEC, /* .data_vec, reference to memory area */
75 KDBUS_MSG_UNIX_FDS, /* .data_fds of file descriptors */
76 KDBUS_MSG_BLOOM, /* for broadcasts, carries bloom filter blob in .data */
77 KDBUS_MSG_DST_NAME, /* destination's well-known name, in .str */
79 /* Filled in by kernelspace */
80 KDBUS_MSG_SRC_NAMES = 0x200,/* NUL separated string list with well-known names of source */
81 KDBUS_MSG_TIMESTAMP, /* .timestamp */
82 KDBUS_MSG_SRC_CREDS, /* .creds */
83 KDBUS_MSG_SRC_PID_COMM, /* optional, in .str */
84 KDBUS_MSG_SRC_TID_COMM, /* optional, in .str */
85 KDBUS_MSG_SRC_EXE, /* optional, in .str */
86 KDBUS_MSG_SRC_CMDLINE, /* optional, in .str (a chain of NUL str) */
87 KDBUS_MSG_SRC_CGROUP, /* optional, in .str */
88 KDBUS_MSG_SRC_CAPS, /* caps data blob, in .data */
89 KDBUS_MSG_SRC_SECLABEL, /* NUL terminated string, in .str */
90 KDBUS_MSG_SRC_AUDIT, /* .audit */
92 /* Special messages from kernel, consisting of one and only one of these data blocks */
93 KDBUS_MSG_NAME_ADD = 0x400,/* .name_change */
94 KDBUS_MSG_NAME_REMOVE, /* .name_change */
95 KDBUS_MSG_NAME_CHANGE, /* .name_change */
96 KDBUS_MSG_ID_ADD, /* .id_change */
97 KDBUS_MSG_ID_REMOVE, /* .id_change */
98 KDBUS_MSG_REPLY_TIMEOUT, /* empty, but .reply_cookie in .kdbus_msg is filled in */
99 KDBUS_MSG_REPLY_DEAD, /* dito */
103 KDBUS_VEC_ALIGNED = 1 << 0,
113 * struct kdbus_msg_item - chain of data blocks
115 * size: overall data record size
116 * type: kdbus_msg_item type of data
118 struct kdbus_msg_item {
129 struct kdbus_vec vec;
131 /* specific fields */
132 int fds[0]; /* int array of file descriptors */
133 struct kdbus_creds creds;
134 struct kdbus_audit audit;
135 struct kdbus_timestamp timestamp;
136 struct kdbus_manager_msg_name_change name_change;
137 struct kdbus_manager_msg_id_change id_change;
142 KDBUS_MSG_FLAGS_EXPECT_REPLY = 1 << 0,
143 KDBUS_MSG_FLAGS_NO_AUTO_START = 1 << 1,
148 KDBUS_PAYLOAD_DBUS1 = 0x4442757356657231ULL, /* 'DBusVer1' */
149 KDBUS_PAYLOAD_GVARIANT = 0x4756617269616e74ULL, /* 'GVariant' */
156 * dst_id: destination id
157 * flags: KDBUS_MSG_FLAGS_*
158 * items: data records
161 * src_id: who sent the message
166 __u64 dst_id; /* connection, 0 == name in data, ~0 broadcast */
167 __u64 src_id; /* connection, 0 == kernel */
168 __u64 payload_type; /* 'DBusVer1', 'GVariant', ... */
169 __u64 cookie; /* userspace-supplied cookie */
171 __u64 cookie_reply; /* cookie we reply to */
172 __u64 timeout_ns; /* timespan to wait for reply */
174 struct kdbus_msg_item items[0];
184 KDBUS_POLICY_ACCESS_NULL,
185 KDBUS_POLICY_ACCESS_USER,
186 KDBUS_POLICY_ACCESS_GROUP,
187 KDBUS_POLICY_ACCESS_WORLD,
191 KDBUS_POLICY_RECV = 1 << 2,
192 KDBUS_POLICY_SEND = 1 << 1,
193 KDBUS_POLICY_OWN = 1 << 0,
196 struct kdbus_policy {
198 __u64 type; /* NAME or ACCESS */
202 __u32 type; /* USER, GROUP, WORLD */
203 __u32 bits; /* RECV, SEND, OWN */
204 __u64 id; /* uid, gid, 0 */
209 struct kdbus_cmd_policy {
211 __u8 buffer[0]; /* a series of KDBUS_POLICY_NAME plus one or
212 * more KDBUS_POLICY_ACCESS each. */
215 /* Flags for struct kdbus_cmd_hello */
217 KDBUS_HELLO_STARTER = 1 << 0,
218 KDBUS_HELLO_ACCEPT_FD = 1 << 1,
220 /* The following have an effect on directed messages only --
221 * not for broadcasts */
222 KDBUS_HELLO_ATTACH_COMM = 1 << 10,
223 KDBUS_HELLO_ATTACH_EXE = 1 << 11,
224 KDBUS_HELLO_ATTACH_CMDLINE = 1 << 12,
225 KDBUS_HELLO_ATTACH_CGROUP = 1 << 13,
226 KDBUS_HELLO_ATTACH_CAPS = 1 << 14,
227 KDBUS_HELLO_ATTACH_SECLABEL = 1 << 15,
228 KDBUS_HELLO_ATTACH_AUDIT = 1 << 16,
231 /* Items to append to struct kdbus_cmd_hello */
236 struct kdbus_cmd_hello_item {
246 struct kdbus_cmd_hello {
249 /* userspace → kernel, kernel → userspace */
250 __u64 conn_flags; /* userspace specifies its
251 * capabilities and more, kernel
252 * returns its capabilites and
253 * more. Kernel might refuse client's
254 * capabilities by returning an error
255 * from KDBUS_HELLO */
257 /* kernel → userspace */
258 __u64 bus_flags; /* this is .flags copied verbatim from
259 * from original KDBUS_CMD_BUS_MAKE
260 * ioctl. It's intended to be useful
261 * to do negotiation of features of
262 * the payload that is transfreted. */
263 __u64 id; /* id assigned to this connection */
264 __u64 bloom_size; /* The bloom filter size chosen by the
266 struct kdbus_cmd_hello_item items[0];
269 /* Flags for kdbus_cmd_{bus,ep,ns}_make */
271 KDBUS_MAKE_ACCESS_GROUP = 1 << 0,
272 KDBUS_MAKE_ACCESS_WORLD = 1 << 1,
273 KDBUS_MAKE_POLICY_OPEN = 1 << 2,
276 /* Items to append to kdbus_cmd_{bus,ep,ns}_make */
280 KDBUS_MAKE_CGROUP, /* the cgroup hierarchy ID for which to attach
281 * cgroup membership paths * to messages. */
282 KDBUS_MAKE_CRED, /* allow translator services which connect
283 * to the bus on behalf of somebody else,
284 * allow specifiying the credentials of the
285 * client to connect on behalf on. Needs
289 struct kdbus_cmd_make_item {
299 struct kdbus_cmd_bus_make {
301 __u64 flags; /* userspace → kernel, kernel → userspace
302 * When creating a bus feature
303 * kernel negotiation. */
304 __u64 bus_flags; /* userspace → kernel
305 * When a bus is created this value is
306 * copied verbatim into the bus
307 * structure and returned from
308 * KDBUS_CMD_HELLO, later */
309 __u64 bloom_size; /* size of the bloom filter for this bus */
310 struct kdbus_cmd_make_item items[0];
314 struct kdbus_cmd_ep_make {
316 __u64 flags; /* userspace → kernel, kernel → userspace
317 * When creating an entry point
318 * feature kernel negotiation done the
320 * KDBUS_CMD_BUS_MAKE. Unused for
322 struct kdbus_cmd_make_item items[0];
325 struct kdbus_cmd_ns_make {
327 __u64 flags; /* userspace → kernel, kernel → userspace
328 * When creating an entry point
329 * feature kernel negotiation done the
331 * KDBUS_CMD_BUS_MAKE. Unused for
333 struct kdbus_cmd_make_item items[0];
337 /* userspace → kernel */
338 KDBUS_NAME_REPLACE_EXISTING = 1 << 0,
339 KDBUS_NAME_QUEUE = 1 << 1,
340 KDBUS_NAME_ALLOW_REPLACEMENT = 1 << 2,
342 /* kernel → userspace */
343 KDBUS_NAME_IN_QUEUE = 1 << 16,
346 struct kdbus_cmd_name {
349 __u64 id; /* We allow registration/deregestration of names of other peers */
354 struct kdbus_cmd_names {
356 struct kdbus_cmd_name names[0];
360 KDBUS_NAME_INFO_ITEM_NULL,
361 KDBUS_NAME_INFO_ITEM_NAME, /* userspace → kernel */
362 KDBUS_NAME_INFO_ITEM_SECLABEL, /* kernel → userspace */
363 KDBUS_NAME_INFO_ITEM_AUDIT, /* kernel → userspace */
366 struct kdbus_cmd_name_info_item {
372 struct kdbus_cmd_name_info {
373 __u64 size; /* overall size of info */
375 __u64 id; /* either ID, or 0 and _ITEM_NAME follows */
376 struct kdbus_creds creds;
377 struct kdbus_cmd_name_info_item items[0]; /* list of item records */
382 KDBUS_MATCH_BLOOM, /* Matches a mask blob against KDBUS_MSG_BLOOM */
383 KDBUS_MATCH_SRC_NAME, /* Matches a name string against KDBUS_MSG_SRC_NAMES */
384 KDBUS_MATCH_NAME_ADD, /* Matches a name string against KDBUS_MSG_NAME_ADD */
385 KDBUS_MATCH_NAME_REMOVE, /* Matches a name string against KDBUS_MSG_NAME_REMOVE */
386 KDBUS_MATCH_NAME_CHANGE, /* Matches a name string against KDBUS_MSG_NAME_CHANGE */
387 KDBUS_MATCH_ID_ADD, /* Matches an ID against KDBUS_MSG_ID_ADD */
388 KDBUS_MATCH_ID_REMOVE, /* Matches an ID against KDBUS_MSG_ID_REMOVE */
391 struct kdbus_cmd_match_item {
401 struct kdbus_cmd_match {
403 __u64 id; /* We allow registration/deregestration of matches for other peers */
404 __u64 cookie; /* userspace supplied cookie; when removing; kernel deletes everything with same cookie */
405 __u64 src_id; /* ~0: any. other: exact unique match */
406 struct kdbus_cmd_match_item items[0];
409 struct kdbus_cmd_monitor {
410 __u64 id; /* We allow setting the monitor flag of other peers */
411 unsigned int enabled; /* A boolean to enable/disable monitoring */
415 * control nodes: unset
416 * bus owner (via KDBUS_CMD_BUS_MAKE)
417 * ns owner (via KDBUS_CMD_NS_MAKE)
420 * connected (via KDBUS_CMD_HELLO)
421 * starter (via KDBUS_CMD_HELLO with KDBUS_CMD_HELLO_STARTER)
422 * ep owner (via KDBUS_CMD_EP_MAKE)
425 /* kdbus control node commands: require unset state */
426 KDBUS_CMD_BUS_MAKE = _IOWR(KDBUS_IOC_MAGIC, 0x00, struct kdbus_cmd_bus_make),
427 KDBUS_CMD_NS_MAKE = _IOWR(KDBUS_IOC_MAGIC, 0x10, struct kdbus_cmd_ns_make),
429 /* kdbus ep node commands: require unset state */
430 KDBUS_CMD_EP_MAKE = _IOWR(KDBUS_IOC_MAGIC, 0x20, struct kdbus_cmd_ep_make),
431 KDBUS_CMD_HELLO = _IOWR(KDBUS_IOC_MAGIC, 0x30, struct kdbus_cmd_hello),
433 /* kdbus ep node commands: require connected state */
434 KDBUS_CMD_MSG_SEND = _IOWR(KDBUS_IOC_MAGIC, 0x40, struct kdbus_msg),
435 KDBUS_CMD_MSG_RECV = _IOWR(KDBUS_IOC_MAGIC, 0x41, struct kdbus_msg),
437 KDBUS_CMD_NAME_ACQUIRE = _IOWR(KDBUS_IOC_MAGIC, 0x50, struct kdbus_cmd_name),
438 KDBUS_CMD_NAME_RELEASE = _IOWR(KDBUS_IOC_MAGIC, 0x51, struct kdbus_cmd_name),
439 KDBUS_CMD_NAME_LIST = _IOWR(KDBUS_IOC_MAGIC, 0x52, struct kdbus_cmd_names),
440 KDBUS_CMD_NAME_QUERY = _IOWR(KDBUS_IOC_MAGIC, 0x53, struct kdbus_cmd_name_info),
442 KDBUS_CMD_MATCH_ADD = _IOWR(KDBUS_IOC_MAGIC, 0x60, struct kdbus_cmd_match),
443 KDBUS_CMD_MATCH_REMOVE = _IOWR(KDBUS_IOC_MAGIC, 0x61, struct kdbus_cmd_match),
444 KDBUS_CMD_MONITOR = _IOWR(KDBUS_IOC_MAGIC, 0x62, struct kdbus_cmd_monitor),
446 /* kdbus ep node commands: require ep owner state */
447 KDBUS_CMD_EP_POLICY_SET = _IOWR(KDBUS_IOC_MAGIC, 0x70, struct kdbus_cmd_policy),