chiark / gitweb /
nspawn: inherit the exit status of container
[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         KDBUS_MSG_NULL,
71
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 */
78
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 */
91
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 */
100 };
101
102 enum {
103         KDBUS_VEC_ALIGNED               = 1 <<  0,
104 };
105
106 struct kdbus_vec {
107         __u64 address;
108         __u64 size;
109         __u64 flags;
110 };
111
112 /**
113  * struct  kdbus_msg_item - chain of data blocks
114  *
115  * size: overall data record size
116  * type: kdbus_msg_item type of data
117  */
118 struct kdbus_msg_item {
119         __u64 size;
120         __u64 type;
121         union {
122                 /* inline data */
123                 __u8 data[0];
124                 __u32 data32[0];
125                 __u64 data64[0];
126                 char str[0];
127
128                 /* data vector */
129                 struct kdbus_vec vec;
130
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;
138         };
139 };
140
141 enum {
142         KDBUS_MSG_FLAGS_EXPECT_REPLY    = 1 << 0,
143         KDBUS_MSG_FLAGS_NO_AUTO_START   = 1 << 1,
144 };
145
146 enum {
147         KDBUS_PAYLOAD_NONE,
148         KDBUS_PAYLOAD_DBUS1     = 0x4442757356657231ULL, /* 'DBusVer1' */
149         KDBUS_PAYLOAD_GVARIANT  = 0x4756617269616e74ULL, /* 'GVariant' */
150 };
151
152 /**
153  * struct kdbus_msg
154  *
155  * set by userspace:
156  * dst_id: destination id
157  * flags: KDBUS_MSG_FLAGS_*
158  * items: data records
159  *
160  * set by kernel:
161  * src_id: who sent the message
162  */
163 struct kdbus_msg {
164         __u64 size;
165         __u64 flags;
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 */
170         union {
171                 __u64 cookie_reply;     /* cookie we reply to */
172                 __u64 timeout_ns;       /* timespan to wait for reply */
173         };
174         struct kdbus_msg_item items[0];
175 };
176
177 enum {
178         KDBUS_POLICY_NULL,
179         KDBUS_POLICY_NAME,
180         KDBUS_POLICY_ACCESS,
181 };
182
183 enum {
184         KDBUS_POLICY_ACCESS_NULL,
185         KDBUS_POLICY_ACCESS_USER,
186         KDBUS_POLICY_ACCESS_GROUP,
187         KDBUS_POLICY_ACCESS_WORLD,
188 };
189
190 enum {
191         KDBUS_POLICY_RECV               = 1 <<  2,
192         KDBUS_POLICY_SEND               = 1 <<  1,
193         KDBUS_POLICY_OWN                = 1 <<  0,
194 };
195
196 struct kdbus_policy {
197         __u64 size;
198         __u64 type; /* NAME or ACCESS */
199         union {
200                 char name[0];
201                 struct {
202                         __u32 type;     /* USER, GROUP, WORLD */
203                         __u32 bits;     /* RECV, SEND, OWN */
204                         __u64 id;       /* uid, gid, 0 */
205                 } access;
206         };
207 };
208
209 struct kdbus_cmd_policy {
210         __u64 size;
211         __u8 buffer[0]; /* a series of KDBUS_POLICY_NAME plus one or
212                          * more KDBUS_POLICY_ACCESS each. */
213 };
214
215 enum {
216         KDBUS_CMD_HELLO_STARTER         =  1 <<  0,
217         KDBUS_CMD_HELLO_ACCEPT_FD       =  1 <<  1,
218
219         /* The following have an effect on directed messages only --
220          * not for broadcasts */
221         KDBUS_CMD_HELLO_ATTACH_COMM     =  1 << 10,
222         KDBUS_CMD_HELLO_ATTACH_EXE      =  1 << 11,
223         KDBUS_CMD_HELLO_ATTACH_CMDLINE  =  1 << 12,
224         KDBUS_CMD_HELLO_ATTACH_CGROUP   =  1 << 13,
225         KDBUS_CMD_HELLO_ATTACH_CAPS     =  1 << 14,
226         KDBUS_CMD_HELLO_ATTACH_SECLABEL =  1 << 15,
227         KDBUS_CMD_HELLO_ATTACH_AUDIT    =  1 << 16,
228 };
229
230 /* Flags for kdbus_cmd_bus_make, kdbus_cmd_ep_make and
231  * kdbus_cmd_ns_make */
232 enum {
233         KDBUS_ACCESS_GROUP              = 1 <<  0,
234         KDBUS_ACCESS_WORLD              = 1 <<  1,
235         KDBUS_POLICY_OPEN               = 1 <<  2,
236 };
237
238 /* Items to append to kdbus_cmd_bus_make, kdbus_cmd_ep_make and
239  * kdbus_cmd_ns_make */
240
241 enum {
242         KDBUS_CMD_MAKE_NONE,
243         KDBUS_CMD_MAKE_NAME,
244         KDBUS_CMD_MAKE_CGROUP,  /* the cgroup hierarchy ID for which to attach
245                                  * cgroup membership paths * to messages. */
246         KDBUS_CMD_MAKE_CRED,    /* allow translator services which connect
247                                  * to the bus on behalf of somebody else,
248                                  * allow specifiying the credentials of the
249                                  * client to connect on behalf on. Needs
250                                  * privileges */
251
252 };
253
254 struct kdbus_cmd_make_item {
255         __u64 size;
256         __u64 type;
257         union {
258                 __u8 data[0];
259                 __u64 data64[0];
260                 char str[0];
261         };
262 };
263
264 struct kdbus_cmd_hello {
265         __u64 size;
266
267         /* userspace → kernel, kernel → userspace */
268         __u64 conn_flags;       /* userspace specifies its
269                                  * capabilities and more, kernel
270                                  * returns its capabilites and
271                                  * more. Kernel might refuse client's
272                                  * capabilities by returning an error
273                                  * from KDBUS_CMD_HELLO */
274
275         /* kernel → userspace */
276         __u64 bus_flags;        /* this is .flags copied verbatim from
277                                  * from original KDBUS_CMD_BUS_MAKE
278                                  * ioctl. It's intended to be useful
279                                  * to do negotiation of features of
280                                  * the payload that is transfreted. */
281         __u64 id;               /* id assigned to this connection */
282         __u64 bloom_size;       /* The bloom filter size chosen by the
283                                  * bus owner */
284         struct kdbus_cmd_make_item items[0];
285 };
286
287 struct kdbus_cmd_bus_make {
288         __u64 size;
289         __u64 flags;            /* userspace → kernel, kernel → userspace
290                                  * When creating a bus feature
291                                  * kernel negotiation. */
292         __u64 bus_flags;        /* userspace → kernel
293                                  * When a bus is created this value is
294                                  * copied verbatim into the bus
295                                  * structure and returned from
296                                  * KDBUS_CMD_HELLO, later */
297         __u64 bloom_size;       /* size of the bloom filter for this bus */
298         struct kdbus_cmd_make_item items[0];
299
300 };
301
302 struct kdbus_cmd_ep_make {
303         __u64 size;
304         __u64 flags;            /* userspace → kernel, kernel → userspace
305                                  * When creating an entry point
306                                  * feature kernel negotiation done the
307                                  * same way as for
308                                  * KDBUS_CMD_BUS_MAKE. Unused for
309                                  * now. */
310         struct kdbus_cmd_make_item items[0];
311 };
312
313 struct kdbus_cmd_ns_make {
314         __u64 size;
315         __u64 flags;            /* userspace → kernel, kernel → userspace
316                                  * When creating an entry point
317                                  * feature kernel negotiation done the
318                                  * same way as for
319                                  * KDBUS_CMD_BUS_MAKE. Unused for
320                                  * now. */
321         struct kdbus_cmd_make_item items[0];
322 };
323
324 enum {
325         /* userspace → kernel */
326         KDBUS_CMD_NAME_REPLACE_EXISTING         = 1 <<  0,
327         KDBUS_CMD_NAME_QUEUE                    = 1 <<  1,
328         KDBUS_CMD_NAME_ALLOW_REPLACEMENT        = 1 <<  2,
329
330         /* kernel → userspace */
331         KDBUS_CMD_NAME_IN_QUEUE                 = 1 << 16,
332 };
333
334 struct kdbus_cmd_name {
335         __u64 size;
336         __u64 name_flags;
337         __u64 id;               /* We allow registration/deregestration of names of other peers */
338         __u64 conn_flags;
339         char name[0];
340 };
341
342 struct kdbus_cmd_names {
343         __u64 size;
344         struct kdbus_cmd_name names[0];
345 };
346
347 enum {
348         KDBUS_CMD_NAME_INFO_ITEM_NULL,
349         KDBUS_CMD_NAME_INFO_ITEM_NAME,          /* userspace → kernel */
350         KDBUS_CMD_NAME_INFO_ITEM_SECLABEL,      /* kernel → userspace */
351         KDBUS_CMD_NAME_INFO_ITEM_AUDIT,         /* kernel → userspace */
352 };
353
354 struct kdbus_cmd_name_info_item {
355         __u64 size;
356         __u64 type;
357         __u8 data[0];
358 };
359
360 struct kdbus_cmd_name_info {
361         __u64 size;                     /* overall size of info */
362         __u64 flags;
363         __u64 id;                       /* either ID, or 0 and _ITEM_NAME follows */
364         struct kdbus_creds creds;
365         struct kdbus_cmd_name_info_item items[0]; /* list of item records */
366 };
367
368 enum {
369         KDBUS_CMD_MATCH_NULL,
370         KDBUS_CMD_MATCH_BLOOM,          /* Matches a mask blob against KDBUS_MSG_BLOOM */
371         KDBUS_CMD_MATCH_SRC_NAME,       /* Matches a name string against KDBUS_MSG_SRC_NAMES */
372         KDBUS_CMD_MATCH_NAME_ADD,       /* Matches a name string against KDBUS_MSG_NAME_ADD */
373         KDBUS_CMD_MATCH_NAME_REMOVE,    /* Matches a name string against KDBUS_MSG_NAME_REMOVE */
374         KDBUS_CMD_MATCH_NAME_CHANGE,    /* Matches a name string against KDBUS_MSG_NAME_CHANGE */
375         KDBUS_CMD_MATCH_ID_ADD,         /* Matches an ID against KDBUS_MSG_ID_ADD */
376         KDBUS_CMD_MATCH_ID_REMOVE,      /* Matches an ID against KDBUS_MSG_ID_REMOVE */
377 };
378
379 struct kdbus_cmd_match_item {
380         __u64 size;
381         __u64 type;
382         union {
383                 __u64 id;
384                 __u8 data[0];
385                 char str[0];
386         };
387 };
388
389 struct kdbus_cmd_match {
390         __u64 size;
391         __u64 id;       /* We allow registration/deregestration of matches for other peers */
392         __u64 cookie;   /* userspace supplied cookie; when removing; kernel deletes everything with same cookie */
393         __u64 src_id;   /* ~0: any. other: exact unique match */
394         struct kdbus_cmd_match_item items[0];
395 };
396
397 struct kdbus_cmd_monitor {
398         __u64 id;               /* We allow setting the monitor flag of other peers */
399         unsigned int enabled;   /* A boolean to enable/disable monitoring */
400 };
401
402 /* FD states:
403  * control nodes: unset
404  *   bus owner  (via KDBUS_CMD_BUS_MAKE)
405  *   ns owner   (via KDBUS_CMD_NS_MAKE)
406  *
407  * ep nodes: unset
408  *   connected  (via KDBUS_CMD_HELLO)
409  *   starter    (via KDBUS_CMD_HELLO with KDBUS_CMD_HELLO_STARTER)
410  *   ep owner   (via KDBUS_CMD_EP_MAKE)
411  */
412 enum kdbus_cmd {
413         /* kdbus control node commands: require unset state */
414         KDBUS_CMD_BUS_MAKE =            _IOWR(KDBUS_IOC_MAGIC, 0x00, struct kdbus_cmd_bus_make),
415         KDBUS_CMD_NS_MAKE =             _IOWR(KDBUS_IOC_MAGIC, 0x10, struct kdbus_cmd_ns_make),
416
417         /* kdbus ep node commands: require unset state */
418         KDBUS_CMD_EP_MAKE =             _IOWR(KDBUS_IOC_MAGIC, 0x20, struct kdbus_cmd_ep_make),
419         KDBUS_CMD_HELLO =               _IOWR(KDBUS_IOC_MAGIC, 0x30, struct kdbus_cmd_hello),
420
421         /* kdbus ep node commands: require connected state */
422         KDBUS_CMD_MSG_SEND =            _IOWR(KDBUS_IOC_MAGIC, 0x40, struct kdbus_msg),
423         KDBUS_CMD_MSG_RECV =            _IOWR(KDBUS_IOC_MAGIC, 0x41, struct kdbus_msg),
424
425         KDBUS_CMD_NAME_ACQUIRE =        _IOWR(KDBUS_IOC_MAGIC, 0x50, struct kdbus_cmd_name),
426         KDBUS_CMD_NAME_RELEASE =        _IOWR(KDBUS_IOC_MAGIC, 0x51, struct kdbus_cmd_name),
427         KDBUS_CMD_NAME_LIST =           _IOWR(KDBUS_IOC_MAGIC, 0x52, struct kdbus_cmd_names),
428         KDBUS_CMD_NAME_QUERY =          _IOWR(KDBUS_IOC_MAGIC, 0x53, struct kdbus_cmd_name_info),
429
430         KDBUS_CMD_MATCH_ADD =           _IOWR(KDBUS_IOC_MAGIC, 0x60, struct kdbus_cmd_match),
431         KDBUS_CMD_MATCH_REMOVE =        _IOWR(KDBUS_IOC_MAGIC, 0x61, struct kdbus_cmd_match),
432         KDBUS_CMD_MONITOR =             _IOWR(KDBUS_IOC_MAGIC, 0x62, struct kdbus_cmd_monitor),
433
434         /* kdbus ep node commands: require ep owner state */
435         KDBUS_CMD_EP_POLICY_SET =       _IOWR(KDBUS_IOC_MAGIC, 0x70, struct kdbus_cmd_policy),
436 };
437 #endif