chiark / gitweb /
kdbus: update kdbus.h from upstream
[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
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 {
28         __u64 old_id;
29         __u64 new_id;
30         __u64 flags;            /* 0 or (possibly?) KDBUS_CMD_NAME_IN_QUEUE */
31         char name[0];
32 };
33
34 struct kdbus_manager_msg_id_change {
35         __u64 id;
36         __u64 flags; /* The kernel flags field from KDBUS_CMD_HELLO */
37 };
38
39 struct kdbus_creds {
40         __u64 uid;
41         __u64 gid;
42         __u64 pid;
43         __u64 tid;
44
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
49         ovretun. */
50         __u64 starttime;
51 };
52
53 struct kdbus_audit {
54         __u64 sessionid;
55         __u64 loginuid;
56 };
57
58 struct kdbus_timestamp {
59         __u64 monotonic_ns;
60         __u64 realtime_ns;
61 };
62
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)
67
68 /* Message Item Types */
69 enum {
70         /* Filled in by userspace */
71         KDBUS_MSG_NULL,                 /* empty record */
72         KDBUS_MSG_PAYLOAD,              /* .data */
73         KDBUS_MSG_PAYLOAD_VEC,          /* .data_vec */
74         KDBUS_MSG_UNIX_FDS,             /* .data_fds of file descriptors */
75         KDBUS_MSG_BLOOM,                /* for broadcasts, carries bloom filter blob in .data */
76         KDBUS_MSG_DST_NAME,             /* destination's well-known name, in .str */
77
78         /* Filled in by kernelspace */
79         KDBUS_MSG_SRC_NAMES     = 0x200,/* NUL separated string list with well-known names of source */
80         KDBUS_MSG_TIMESTAMP,            /* .timestamp */
81         KDBUS_MSG_SRC_CREDS,            /* .creds */
82         KDBUS_MSG_SRC_PID_COMM,         /* optional, in .str */
83         KDBUS_MSG_SRC_TID_COMM,         /* optional, in .str */
84         KDBUS_MSG_SRC_EXE,              /* optional, in .str */
85         KDBUS_MSG_SRC_CMDLINE,          /* optional, in .str (a chain of NUL str) */
86         KDBUS_MSG_SRC_CGROUP,           /* optional, in .str */
87         KDBUS_MSG_SRC_CAPS,             /* caps data blob, in .data */
88         KDBUS_MSG_SRC_SECLABEL,         /* NUL terminated string, in .str */
89         KDBUS_MSG_SRC_AUDIT,            /* .audit */
90
91         /* Special messages from kernel, consisting of one and only one of these data blocks */
92         KDBUS_MSG_NAME_ADD      = 0x400,/* .name_change */
93         KDBUS_MSG_NAME_REMOVE,          /* .name_change */
94         KDBUS_MSG_NAME_CHANGE,          /* .name_change */
95         KDBUS_MSG_ID_ADD,               /* .id_change */
96         KDBUS_MSG_ID_REMOVE,            /* .id_change */
97         KDBUS_MSG_REPLY_TIMEOUT,        /* empty, but .reply_cookie in .kdbus_msg is filled in */
98         KDBUS_MSG_REPLY_DEAD,           /* dito */
99 };
100
101 struct kdbus_vec {
102         __u64 address;
103         __u64 size;
104 };
105
106 /**
107  * struct  kdbus_msg_item - chain of data blocks
108  *
109  * size: overall data record size
110  * type: kdbus_msg_item type of data
111  */
112 struct kdbus_msg_item {
113         __u64 size;
114         __u64 type;
115         union {
116                 /* inline data */
117                 __u8 data[0];
118                 __u32 data32[0];
119                 __u64 data64[0];
120                 char str[0];
121
122                 /* data vector */
123                 struct kdbus_vec vec;
124
125                 /* specific fields */
126                 int fds[0];                             /* int array of file descriptors */
127                 struct kdbus_creds creds;
128                 struct kdbus_audit audit;
129                 struct kdbus_timestamp timestamp;
130                 struct kdbus_manager_msg_name_change name_change;
131                 struct kdbus_manager_msg_id_change id_change;
132         };
133 };
134
135 enum {
136         KDBUS_MSG_FLAGS_EXPECT_REPLY    = 1,
137         KDBUS_MSG_FLAGS_NO_AUTO_START   = 2, /* possibly? */
138 };
139
140 enum {
141         KDBUS_PAYLOAD_NONE      = 0,
142         KDBUS_PAYLOAD_DBUS1     = 0x4442757356657231ULL, /* 'DBusVer1' */
143         KDBUS_PAYLOAD_GVARIANT  = 0x4756617269616e74ULL, /* 'GVariant' */
144 };
145
146 /**
147  * struct kdbus_msg
148  *
149  * set by userspace:
150  * dst_id: destination id
151  * flags: KDBUS_MSG_FLAGS_*
152  * items: data records
153  *
154  * set by kernel:
155  * src_id: who sent the message
156  */
157 struct kdbus_msg {
158         __u64 size;
159         __u64 flags;
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 */
164         union {
165                 __u64 cookie_reply;     /* cookie we reply to */
166                 __u64 timeout_ns;       /* timespan to wait for reply */
167         };
168         struct kdbus_msg_item items[0];
169 };
170
171 enum {
172         KDBUS_POLICY_NAME,
173         KDBUS_POLICY_ACCESS,
174 };
175
176 enum {
177         KDBUS_POLICY_USER,
178         KDBUS_POLICY_GROUP,
179         KDBUS_POLICY_WORLD,
180 };
181
182 enum {
183         KDBUS_POLICY_RECV       = 4,
184         KDBUS_POLICY_SEND       = 2,
185         KDBUS_POLICY_OWN        = 1,
186 };
187
188 struct kdbus_policy {
189         __u64 size;
190         __u64 type; /* NAME or ACCESS */
191         union {
192                 char name[0];
193                 struct {
194                         __u32 type;     /* USER, GROUP, WORLD */
195                         __u32 bits;     /* RECV, SEND, OWN */
196                         __u64 id;       /* uid, gid, 0 */
197                 } access;
198         };
199 };
200
201 struct kdbus_cmd_policy {
202         __u64 size;
203         __u8 buffer[0]; /* a series of KDBUS_POLICY_NAME plus one or
204                          * more KDBUS_POLICY_ACCESS each. */
205 };
206
207 enum {
208         KDBUS_CMD_HELLO_STARTER         =  1 <<  0,
209         KDBUS_CMD_HELLO_ACCEPT_FD       =  1 <<  1,
210         KDBUS_CMD_HELLO_ACCEPT_MMAP     =  1 <<  2,
211
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,
221 };
222
223 /* Flags for kdbus_cmd_bus_make, kdbus_cmd_ep_make and
224  * kdbus_cmd_ns_make */
225 enum {
226         KDBUS_ACCESS_GROUP      =  1,
227         KDBUS_ACCESS_WORLD      =  2,
228         KDBUS_POLICY_OPEN       =  4,
229 };
230
231 /* Items to append to kdbus_cmd_bus_make, kdbus_cmd_ep_make and
232  * kdbus_cmd_ns_make */
233
234 enum {
235         KDBUS_CMD_MAKE_NONE,
236         KDBUS_CMD_MAKE_NAME,
237         KDBUS_CMD_MAKE_CGROUP,  /* the cgroup hierarchy ID for which to attach
238                                  * cgroup membership paths * to messages. */
239         KDBUS_CMD_MAKE_CRED,    /* allow translator services which connect
240                                  * to the bus on behalf of somebody else,
241                                  * allow specifiying the credentials of the
242                                  * client to connect on behalf on. Needs
243                                  * privileges */
244
245 };
246
247 struct kdbus_cmd_make_item {
248         __u64 size;
249         __u64 type;
250         union {
251                 __u8 data[0];
252                 __u64 data64[0];
253                 char str[0];
254         };
255 };
256
257 struct kdbus_cmd_hello {
258         __u64 size;
259
260         /* userspace → kernel, kernel → userspace */
261         __u64 conn_flags;       /* userspace specifies its
262                                  * capabilities and more, kernel
263                                  * returns its capabilites and
264                                  * more. Kernel might refuse client's
265                                  * capabilities by returning an error
266                                  * from KDBUS_CMD_HELLO */
267
268         /* kernel → userspace */
269         __u64 bus_flags;        /* this is .flags copied verbatim from
270                                  * from original KDBUS_CMD_BUS_MAKE
271                                  * ioctl. It's intended to be useful
272                                  * to do negotiation of features of
273                                  * the payload that is transfreted. */
274         __u64 id;               /* id assigned to this connection */
275         __u64 bloom_size;       /* The bloom filter size chosen by the
276                                  * bus owner */
277         struct kdbus_cmd_make_item items[0];
278 };
279
280 struct kdbus_cmd_bus_make {
281         __u64 size;
282         __u64 flags;            /* userspace → kernel, kernel → userspace
283                                  * When creating a bus feature
284                                  * kernel negotiation. */
285         __u64 bus_flags;        /* userspace → kernel
286                                  * When a bus is created this value is
287                                  * copied verbatim into the bus
288                                  * structure and returned from
289                                  * KDBUS_CMD_HELLO, later */
290         __u64 bloom_size;       /* size of the bloom filter for this bus */
291         struct kdbus_cmd_make_item items[0];
292
293 };
294
295 struct kdbus_cmd_ep_make {
296         __u64 size;
297         __u64 flags;            /* userspace → kernel, kernel → userspace
298                                  * When creating an entry point
299                                  * feature kernel negotiation done the
300                                  * same way as for
301                                  * KDBUS_CMD_BUS_MAKE. Unused for
302                                  * now. */
303         struct kdbus_cmd_make_item items[0];
304 };
305
306 struct kdbus_cmd_ns_make {
307         __u64 size;
308         __u64 flags;            /* userspace → kernel, kernel → userspace
309                                  * When creating an entry point
310                                  * feature kernel negotiation done the
311                                  * same way as for
312                                  * KDBUS_CMD_BUS_MAKE. Unused for
313                                  * now. */
314         struct kdbus_cmd_make_item items[0];
315 };
316
317 enum {
318         /* userspace → kernel */
319         KDBUS_CMD_NAME_REPLACE_EXISTING         =  1,
320         KDBUS_CMD_NAME_QUEUE                    =  2,
321         KDBUS_CMD_NAME_ALLOW_REPLACEMENT        =  4,
322
323         /* kernel → userspace */
324         KDBUS_CMD_NAME_IN_QUEUE = 0x200,
325 };
326
327 struct kdbus_cmd_name {
328         __u64 size;
329         __u64 name_flags;
330         __u64 id;               /* We allow registration/deregestration of names of other peers */
331         __u64 conn_flags;
332         char name[0];
333 };
334
335 struct kdbus_cmd_names {
336         __u64 size;
337         struct kdbus_cmd_name names[0];
338 };
339
340 enum {
341         KDBUS_CMD_NAME_INFO_ITEM_NAME,          /* userspace → kernel */
342         KDBUS_CMD_NAME_INFO_ITEM_SECLABEL,      /* kernel → userspace */
343         KDBUS_CMD_NAME_INFO_ITEM_AUDIT,         /* kernel → userspace */
344 };
345
346 struct kdbus_cmd_name_info_item {
347         __u64 size;
348         __u64 type;
349         __u8 data[0];
350 };
351
352 struct kdbus_cmd_name_info {
353         __u64 size;                     /* overall size of info */
354         __u64 flags;
355         __u64 id;                       /* either ID, or 0 and _ITEM_NAME follows */
356         struct kdbus_creds creds;
357         struct kdbus_cmd_name_info_item items[0]; /* list of item records */
358 };
359
360 enum {
361         KDBUS_CMD_MATCH_BLOOM,          /* Matches a mask blob against KDBUS_MSG_BLOOM */
362         KDBUS_CMD_MATCH_SRC_NAME,       /* Matches a name string against KDBUS_MSG_SRC_NAMES */
363         KDBUS_CMD_MATCH_NAME_ADD,       /* Matches a name string against KDBUS_MSG_NAME_ADD */
364         KDBUS_CMD_MATCH_NAME_REMOVE,    /* Matches a name string against KDBUS_MSG_NAME_REMOVE */
365         KDBUS_CMD_MATCH_NAME_CHANGE,    /* Matches a name string against KDBUS_MSG_NAME_CHANGE */
366         KDBUS_CMD_MATCH_ID_ADD,         /* Matches an ID against KDBUS_MSG_ID_ADD */
367         KDBUS_CMD_MATCH_ID_REMOVE,      /* Matches an ID against KDBUS_MSG_ID_REMOVE */
368 };
369
370 struct kdbus_cmd_match_item {
371         __u64 size;
372         __u64 type;
373         union {
374                 __u64 id;
375                 __u8 data[0];
376                 char str[0];
377         };
378 };
379
380 struct kdbus_cmd_match {
381         __u64 size;
382         __u64 id;       /* We allow registration/deregestration of matches for other peers */
383         __u64 cookie;   /* userspace supplied cookie; when removing; kernel deletes everything with same cookie */
384         __u64 src_id;   /* ~0: any. other: exact unique match */
385         struct kdbus_cmd_match_item items[0];
386 };
387
388 struct kdbus_cmd_monitor {
389         __u64 id;               /* We allow setting the monitor flag of other peers */
390         unsigned int enabled;   /* A boolean to enable/disable monitoring */
391 };
392
393 /* FD states:
394  * control nodes: unset
395  *   bus owner  (via KDBUS_CMD_BUS_MAKE)
396  *   ns owner   (via KDBUS_CMD_NS_MAKE)
397  *
398  * ep nodes: unset
399  *   connected  (via KDBUS_CMD_HELLO)
400  *   starter    (via KDBUS_CMD_HELLO with KDBUS_CMD_HELLO_STARTER)
401  *   ep owner   (via KDBUS_CMD_EP_MAKE)
402  */
403 enum kdbus_cmd {
404         /* kdbus control node commands: require unset state */
405         KDBUS_CMD_BUS_MAKE =            _IOWR(KDBUS_IOC_MAGIC, 0x00, struct kdbus_cmd_bus_make),
406         KDBUS_CMD_NS_MAKE =             _IOWR(KDBUS_IOC_MAGIC, 0x10, struct kdbus_cmd_ns_make),
407
408         /* kdbus ep node commands: require unset state */
409         KDBUS_CMD_EP_MAKE =             _IOWR(KDBUS_IOC_MAGIC, 0x20, struct kdbus_cmd_ep_make),
410         KDBUS_CMD_HELLO =               _IOWR(KDBUS_IOC_MAGIC, 0x30, struct kdbus_cmd_hello),
411
412         /* kdbus ep node commands: require connected state */
413         KDBUS_CMD_MSG_SEND =            _IOWR(KDBUS_IOC_MAGIC, 0x40, struct kdbus_msg),
414         KDBUS_CMD_MSG_RECV =            _IOWR(KDBUS_IOC_MAGIC, 0x41, struct kdbus_msg),
415
416         KDBUS_CMD_NAME_ACQUIRE =        _IOWR(KDBUS_IOC_MAGIC, 0x50, struct kdbus_cmd_name),
417         KDBUS_CMD_NAME_RELEASE =        _IOWR(KDBUS_IOC_MAGIC, 0x51, struct kdbus_cmd_name),
418         KDBUS_CMD_NAME_LIST =           _IOWR(KDBUS_IOC_MAGIC, 0x52, struct kdbus_cmd_names),
419         KDBUS_CMD_NAME_QUERY =          _IOWR(KDBUS_IOC_MAGIC, 0x53, struct kdbus_cmd_name_info),
420
421         KDBUS_CMD_MATCH_ADD =           _IOWR(KDBUS_IOC_MAGIC, 0x60, struct kdbus_cmd_match),
422         KDBUS_CMD_MATCH_REMOVE =        _IOWR(KDBUS_IOC_MAGIC, 0x61, struct kdbus_cmd_match),
423         KDBUS_CMD_MONITOR =             _IOWR(KDBUS_IOC_MAGIC, 0x62, struct kdbus_cmd_monitor),
424
425         /* kdbus ep node commands: require ep owner state */
426         KDBUS_CMD_EP_POLICY_SET =       _IOWR(KDBUS_IOC_MAGIC, 0x70, struct kdbus_cmd_policy),
427 };
428 #endif