]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd/sd-bus/PORTING-DBUS1
libsystemd: split up into subdirs
[thirdparty/systemd.git] / src / libsystemd / sd-bus / PORTING-DBUS1
CommitLineData
6206f4b4 1A few hints on supporting kdbus as backend in your favorite D-Bus library.
00586799
LP
2
3~~~
4
5Before you read this, have a look at the DIFFERENCES and
0a6de115 6GVARIANT_SERIALIZATION texts you find in the same directory where you
00586799
LP
7found this.
8
6206f4b4 9We invite you to port your favorite D-Bus protocol implementation
00586799 10over to kdbus. However, there are a couple of complexities
6206f4b4
KS
11involved. On kdbus we only speak GVariant marshaling, kdbus clients
12ignore traffic in dbus1 marshaling. Thus, you need to add a second,
0a6de115 13GVariant compatible marshaler to your library first.
00586799
LP
14
15After you have done that: here's the basic principle how kdbus works:
16
17You connect to a bus by opening its bus node in /dev/kdbus/. All
0a6de115 18buses have a device node there, it starts with a numeric UID of the
00586799
LP
19owner of the bus, followed by a dash and a string identifying the
20bus. The system bus is thus called /dev/kdbus/0-system, and for user
6206f4b4 21buses the device node is /dev/kdbus/1000-user (if 1000 is your user
00586799
LP
22id).
23
6bb648a1 24(Before we proceed, please always keep a copy of libsystemd next
00586799
LP
25to you, ultimately that's where the details are, this document simply
26is a rough overview to help you grok things.)
27
28CONNECTING
29
0a6de115 30To connect to a bus, simply open() its device node and issue the
00586799
LP
31KDBUS_CMD_HELLO call. That's it. Now you are connected. Do not send
32Hello messages or so (as you would on dbus1), that does not exist for
33kdbus.
34
35The structure you pass to the ioctl will contain a couple of
0a6de115 36parameters that you need to know, to operate on the bus.
00586799
LP
37
38There are two flags fields, one indicating features of the kdbus
39kernel side ("conn_flags"), the other one ("bus_flags") indicating
40features of the bus owner (i.e. systemd). Both flags fields are 64bit
41in width.
42
43When calling into the ioctl, you need to place your own supported
44feature bits into these fields. This tells the kernel about the
061eab67 45features you support. When the ioctl returns, it will contain the
00586799
LP
46features the kernel supports.
47
48If any of the higher 32bit are set on the two flags fields and your
49client does not know what they mean, it must disconnect. The upper
5032bit are used to indicate "incompatible" feature additions on the bus
51system, the lower 32bit indicate "compatible" feature additions. A
52client that does not support a "compatible" feature addition can go on
53communicating with the bus, however a client that does not support an
54"incompatible" feature must not proceed with the connection.
55
56The hello structure also contains another flags field "attach_flags"
0a6de115 57which indicates metadata that is optionally attached to all incoming
00586799
LP
58messages. You probably want to set KDBUS_ATTACH_NAMES unconditionally
59in it. This has the effect that all well-known names of a sender are
60attached to all incoming messages. You need this information to
61implement matches that match on a message sender name correctly. Of
061eab67 62course, you should only request the attachment of as little metadata
00586799
LP
63fields as you need.
64
65The kernel will return in the "id" field your unique id. This is a
66simple numeric value. For compatibility with classic dbus1 simply
67format this as string and prefix ":0.".
68
69The kernel will also return the bloom filter size used for the signal
70broadcast bloom filter (see below).
71
f000939e 72The kernel will also return the bus ID of the bus in a 128bit field.
00586799 73
0a6de115 74The pool size field specifies the size of the memory mapped buffer.
00586799 75After the calling the hello ioctl, you should memory map the kdbus
0a6de115
KS
76fd. In this memory mapped region, the kernel will place all your incoming
77messages.
00586799
LP
78
79SENDING MESSAGES
80
81Use the MSG_SEND ioctl to send a message to another peer. The ioctl
82takes a structure that contains a variety of fields:
83
84The flags field corresponds closely to the old dbus1 message header
85flags field, though the DONT_EXPECT_REPLY field got inverted into
86EXPECT_REPLY.
87
88The dst_id/src_id field contains the unique id of the destination and
6206f4b4 89the sender. The sender field is overridden by the kernel usually, hence
00586799
LP
90you shouldn't fill it in. The destination field can also take the
91special value KDBUS_DST_ID_BROADCAST for broadcast messages. For
92messages intended to a well-known name set the field to
93KDBUS_DST_ID_NAME, and attach the name in a special "items" entry to
94the message (see below).
95
96The payload field indicates the payload. For all dbus traffic it
97should carry the value 0x4442757344427573ULL. (Which encodes
98'DBusDBus').
99
100The cookie field corresponds with the "serial" field of classic
101dbus1. We simply renamed it here (and extended it to 64bit) since we
102didn't want to imply the monotonicity of the assignment the way the
103word "serial" indicates it.
104
105When sending a message that expects a reply, you need to set the
106EXPECT_REPLY flag in the message flag field. In this case you should
107also fill out the "timeout_ns" value which indicates the timeout in
108nsec for this call. If the peer does not respond in this time you will
6206f4b4 109get a notification of a timeout. Note that this is also used for
00586799
LP
110security purposes: a single reply messages is only allowed through the
111bus as long as the timeout has not ended. With this timeout value you
112hence "open a time window" in which the peer might respond to your
113request and the policy allows the response to go through.
114
115When sending a message that is a reply, you need to fill in the
116cookie_reply field, which is similar to the reply_serial field of
117dbus1. Note that a message cannot have EXPECT_REPLY and a reply_serial
118at the same time!
119
120This pretty much explains the ioctl header. The actual payload of the
121data is now referenced in additional items that are attached to this
122ioctl header structure at the end. When sending a message, you attach
123items of the type PAYLOAD_VEC, PAYLOAD_MEMFD, FDS, BLOOM, DST_NAME to
124it:
125
126 KDBUS_ITEM_PAYLOAD_VEC: contains a pointer + length pair for
127 referencing arbitrary user memory. This is how you reference most
128 of your data. It's a lot like the good old iovec structure of glibc.
129
6206f4b4
KS
130 KDBUS_ITEM_PAYLOAD_MEMFD: for large data blocks it is preferable
131 to send prepared "memfds" (see below) over. This item contains an
00586799
LP
132 fd for a memfd plus a size.
133
134 KDBUS_ITEM_PAYLOAD_FDS: for sending over fds attach an item of this
135 type with an array of fds.
136
137 KDBUS_ITEM_BLOOM: the calculated bloom filter of this message, only
6206f4b4 138 for undirected (broadcast) message.
00586799
LP
139
140 KDBUS_DST_NAME: for messages that are directed to a well-known name
141 (instead of a unique name), this item contains the well-known name
142 field.
143
6206f4b4 144A single message may consists of no, one or more payload items of type
00586799
LP
145PAYLOAD_VEC or PAYLOAD_MEMFD. D-Bus protocol implementations should
146treat them as a single block that just happens to be split up into
147multiple items. Some restrictions apply however:
148
149 The message header in its entirety must be contained in a single
6206f4b4 150 PAYLOAD_VEC item.
00586799 151
6206f4b4 152 You may only split your message up right in front of each GVariant
061eab67 153 contained in the payload, as well is immediately before framing of a
00586799
LP
154 Gvariant, as well after as any padding bytes if there are any. The
155 padding bytes must be wholly contained in the preceding
156 PAYLOAD_VEC/PAYLOAD_MEMFD item. You may not split up simple types
157 nor arrays of trivial types. The latter is necessary to allow APIs
158 to return direct pointers to linear chunks of fixed size trivial
159 arrays. Examples: The simple types "u", "s", "t" have to be in the
160 same payload item. The array of simple types "ay", "ai" have to be
161 fully in contained in the same payload item. For an array "as" or
162 "a(si)" the only restriction however is to keep each string
163 individually in an uninterrupted item, to keep the framing of each
164 element and the array in a single uninterrupted item, however the
165 various strings might end up in different items.
166
061eab67 167Note again, that splitting up messages into separate items is up to the
00586799 168implementation. Also note that the kdbus kernel side might merge
6206f4b4 169separate items if it deems this to be useful. However, the order in
00586799
LP
170which items are contained in the message is left untouched.
171
172PAYLOAD_MEMFD items allow zero-copy data transfer (see below regarding
173the memfd concept). Note however that the overhead of mapping these
174makes them relatively expensive, and only worth the trouble for memory
175blocks > 128K (this value appears to be quite universal across
176architectures, as we tested). Thus we recommend sending PAYLOAD_VEC
177items over for small messages and restore to PAYLOAD_MEMFD items for
178messages > 128K. Since while building up the message you might not
179know yet whether it will grow beyond this boundary a good approach is
180to simply build the message unconditionally in a memfd
181object. However, when the message is sealed to be sent away check for
182the size limit. If the size of the message is < 128K, then simply send
183the data as PAYLOAD_VEC and reuse the memfd. If it is >= 128K, seal
184the memfd and send it as PAYLOAD_MEMFD, and allocate a new memfd for
185the next message.
186
187RECEIVING MESSAGES
188
189Use the MSG_RECV ioctl to read a message from kdbus. This will return
190an offset into the pool memory map, relative to its beginning.
191
192The received message structure more or less follows the structure of
193the message originally sent. However, certain changes have been
194made. In the header the src_id field will be filled in.
195
196The payload items might have gotten merged and PAYLOAD_VEC items are
061eab67 197not used. Instead, you will only find PAYLOAD_OFF and PAYLOAD_MEMFD
00586799
LP
198items. The former contain an offset and size into your memory mapped
199pool where you find the payload.
200
0a6de115 201If during the HELLO ioctl you asked for getting metadata attached to
061eab67 202your message, you will find additional KDBUS_ITEM_CREDS,
00586799
LP
203KDBUS_ITEM_PID_COMM, KDBUS_ITEM_TID_COMM, KDBUS_ITEM_TIMESTAMP,
204KDBUS_ITEM_EXE, KDBUS_ITEM_CMDLINE, KDBUS_ITEM_CGROUP,
205KDBUS_ITEM_CAPS, KDBUS_ITEM_SECLABEL, KDBUS_ITEM_AUDIT items that
061eab67
KS
206contain this metadata. This metadata will be gathered from the sender
207at the point in time it sends the message. This information is
208uncached, and since it is appended by the kernel, trustable. The
209KDBUS_ITEM_SECLABEL item usually contains the SELinux security label,
00586799
LP
210if it is used.
211
212After processing the message you need to call the KDBUS_CMD_FREE
213ioctl, which releases the message from the pool, and allows the kernel
214to store another message there. Note that the memory used by the pool
061eab67 215is ordinary anonymous, swappable memory that is backed by tmpfs. Hence
00586799
LP
216there is no need to copy the message out of it quickly, instead you
217can just leave it there as long as you need it and release it via the
218FREE ioctl only after that's done.
219
220BLOOM FILTERS
221
6206f4b4 222The kernel does not understand dbus marshaling, it will not look into
00586799 223the message payload. To allow clients to subscribe to specific subsets
6206f4b4 224of the broadcast matches we employ bloom filters.
00586799 225
061eab67 226When broadcasting messages, a bloom filter needs to be attached to the
00586799
LP
227message in a KDBUS_ITEM_BLOOM item (and only for broadcasting
228messages!). If you don't know what bloom filters are, read up now on
229Wikipedia. In short: they are a very efficient way how to
230probabilistically check whether a certain word is contained in a
231vocabulary. It knows no false negatives, but it does know false
232positives.
233
234The bloom filter that needs to be included has the parameters m=512
235(bits in the filter), k=8 (nr of hash functions). The underlying hash
236function is SipHash-2-4. We calculate two hash values for an input
237strings, one with the hash key b9660bf0467047c18875c49c54b9bd15 (this
0a6de115 238is supposed to be read as a series of 16 hexadecimal formatted
00586799
LP
239bytes), and one with the hash key
240aaa154a2e0714b39bfe1dd2e9fc54a3b. This results in two 64bit hash
241values, A and B. The 8 hash functions for the bloom filter require a 9
242bit output each (since m=512=2^9), to generate these we XOR combine
243the first 8 bit of A shifted to the left by 1, with the first 8 bit of
244B. Then, for the next hash function we use the second 8 bit pair, and
245so on.
246
247For each message to send across the bus we populate the bloom filter
248with all possible matchable strings. If a client then wants to
061eab67 249subscribe to messages of this type, it simply tells the kernel to test
00586799
LP
250its own calculated bit mask against the bloom filter of each message.
251
061eab67
KS
252More specifically, the following strings are added to the bloom filter
253of each message that is broadcasted:
00586799
LP
254
255 The string "interface:" suffixed by the interface name
256
257 The string "member:" suffixed by the member name
258
259 The string "path:" suffixed by the path name
260
261 The string "path-slash-prefix:" suffixed with the path name, and
262 also all prefixes of the path name (cut off at "/"), also prefixed
263 with "path-slash-prefix".
264
265 The string "message-type:" suffixed with the strings "signal",
266 "method_call", "error" or "method_return" for the respective message
267 type of the message.
268
269 If the first argument of the message is a string, "arg0:" suffixed
270 with the first argument.
271
272 If the first argument of the message is a string, "arg0-dot-prefix"
273 suffixed with the first argument, and also all prefixes of the
274 argument (cut off at "."), also prefixed with "arg0-dot-prefix".
275
276 If the first argument of the message is a string,
277 "arg0-slash-prefix" suffixed with the first argument, and also all
278 prefixes of the argument (cut off at "/"), also prefixed with
279 "arg0-slash-prefix".
280
281 Similar for all further arguments that are strings up to 63, for the
282 arguments and their "dot" and "slash" prefixes. On the first
061eab67 283 argument that is not a string, addition to the bloom filter should be
00586799
LP
284 stopped however.
285
061eab67 286(Note that the bloom filter does not contain sender nor receiver
00586799
LP
287names!)
288
289When a client wants to subscribe to messages matching a certain
061eab67 290expression, it should calculate the bloom mask following the same
6206f4b4 291algorithm. The kernel will then simply test the mask against the
00586799
LP
292attached bloom filters.
293
294Note that bloom filters are probabilistic, which means that clients
6206f4b4 295might get messages they did not expect. Your bus protocol
00586799
LP
296implementation must be capable of dealing with these unexpected
297messages (which it needs to anyway, given that transfers are
298relatively unrestricted on kdbus and people can send you all kinds of
061eab67 299non-sense).
00586799
LP
300
301INSTALLING MATCHES
302
061eab67 303To install matches for broadcast messages, use the KDBUS_CMD_ADD_MATCH
00586799
LP
304ioctl. It takes a structure that contains an encoded match expression,
305and that is followed by one or more items, which are combined in an
061eab67 306AND way. (Meaning: a message is matched exactly when all items
00586799
LP
307attached to the original ioctl struct match).
308
309To match against other user messages add a KDBUS_ITEM_BLOOM item in
310the match (see above). Note that the bloom filter does not include
311matches to the sender names. To additionally check against sender
312names, use the KDBUS_ITEM_ID (for unique id matches) and
313KDBUS_ITEM_NAME (for well-known name matches) item types.
314
315To match against kernel generated messages (see below) you should add
316items of the same type as the kernel messages include,
317i.e. KDBUS_ITEM_NAME_ADD, KDBUS_ITEM_NAME_REMOVE,
318KDBUS_ITEM_NAME_CHANGE, KDBUS_ITEM_ID_ADD, KDBUS_ITEM_ID_REMOVE and
319fill them out. Note however, that you have some wildcards in this
320case, for example the .id field of KDBUS_ITEM_ADD/KDBUS_ITEM_REMOVE
321structures may be set to 0 to match against any id addition/removal.
322
323Note that dbus match strings do no map 1:1 to these ioctl() calls. In
324many cases (where the match string is "underspecified") you might need
325to issue up to six different ioctl() calls for the same match. For
326example, the empty match (which matches against all messages), would
327translate into one KDBUS_ITEM_BLOOM ioctl, one KDBUS_ITEM_NAME_ADD,
328one KDBUS_ITEM_NAME_CHANGE, one KDBUS_ITEM_NAME_REMOVE, one
329KDBUS_ITEM_ID_ADD and one KDBUS_ITEM_ID_REMOVE.
330
061eab67
KS
331When creating a match, you may attach a "cookie" value to them, which
332is used for deleting this match again. The cookie can be selected freely
333by the client. When issuing KDBUS_CMD_REMOVE_MATCH, simply pass the
00586799 334same cookie as before and all matches matching the same "cookie" value
6206f4b4 335will be removed. This is particularly handy for the case where multiple
00586799
LP
336ioctl()s are added for a single match strings.
337
338MEMFDS
339
340The "memfd" concept is used for zero-copy data transfers (see
341above). memfds are file descriptors to memory chunks of arbitrary
342sizes. If you have a memfd you can mmap() it to get access to the data
343it contains or write to it. They are comparable to file descriptors to
344unlinked files on a tmpfs, or to anonymous memory that one may refer
345to with an fd. They have one particular property: they can be
346"sealed". A memfd that is "sealed" is protected from alteration. Only
347memfds that are currently not mapped and to which a single fd refers
348may be sealed (they may also be unsealed in that case).
349
350The concept of "sealing" makes memfds useful for using them as
351transport for kdbus messages: only when the receiver knows that the
061eab67
KS
352message it has received cannot change while looking at, it can safely
353parse it without having to copy it to a safe memory area. memfds can also
00586799 354be reused in multiple messages. A sender may send the same memfd to
061eab67 355multiple peers, and since it is sealed, it can be sure that the receiver
00586799 356will not be able to modify it. "Sealing" hence provides both sides of
6206f4b4 357a transaction with the guarantee that the data stays constant and is
00586799
LP
358reusable.
359
360memfds are a generic concept that can be used outside of the immediate
361kdbus usecase. You can send them across AF_UNIX sockets too, sealed or
061eab67 362unsealed. In kdbus themselves, they can be used to send zero-copy
00586799
LP
363payloads, but may also be sent as normal fds.
364
061eab67
KS
365memfds are allocated with the KDBUS_CMD_MEMFD_NEW ioctl. After allocation,
366simply memory map them and write to them. To set their size, use
6206f4b4 367KDBUS_CMD_MEMFD_SIZE_SET. Note that memfds will be increased in size
00586799
LP
368automatically if you touch previously unallocated pages. However, the
369size will only be increased in multiples of the page size in that
f000939e 370case. Thus, in almost all cases, an explicit KDBUS_CMD_MEMFD_SIZE_SET
00586799
LP
371is necessary, since it allows setting memfd sizes in finer
372granularity. To seal a memfd use the KDBUS_CMD_MEMFD_SEAL_SET ioctl
061eab67 373call. It will only succeed if the caller has the only fd reference to
00586799
LP
374the memfd open, and if the memfd is currently unmapped.
375
061eab67
KS
376If memfds are shared, keep in mind that the file pointer used by
377write/read/seek is shared too, only pread/pwrite are safe to use
378in that case.
379
00586799 380memfds may be sent across kdbus via KDBUS_ITEM_PAYLOAD_MEMFD items
061eab67 381attached to messages. If this is done, the data included in the memfd
00586799
LP
382is considered part of the payload stream of a message, and are treated
383the same way as KDBUS_ITEM_PAYLOAD_VEC by the receiving side. It is
384possible to interleave KDBUS_ITEM_PAYLOAD_MEMFD and
385KDBUS_ITEM_PAYLOAD_VEC items freely, by the reader they will be
386considered a single stream of bytes in the order these items appear in
387the message, that just happens to be split up at various places
388(regarding rules how they may be split up, see above). The kernel will
389refuse taking KDBUS_ITEM_PAYLOAD_MEMFD items that refer to memfds that
390are not sealed.
391
392Note that sealed memfds may be unsealed again if they are not mapped
393you have the only fd reference to them.
394
395Alternatively to sending memfds as KDBUS_ITEM_PAYLOAD_MEMFD items
061eab67
KS
396(where they are just a part of the payload stream of a message) you can
397also simply attach any memfd to a message using
398KDBUS_ITEM_PAYLOAD_FDS. In this case, the memfd contents is not
00586799 399considered part of the payload stream of the message, but simply fds
061eab67 400like any other, that happen to be attached to the message.
00586799
LP
401
402MESSAGES FROM THE KERNEL
403
6206f4b4 404A couple of messages previously generated by the dbus1 bus driver are
00586799 405now generated by the kernel. Since the kernel does not understand the
061eab67 406payload marshaling, they are generated by the kernel in a different
f000939e 407format. This is indicated with the "payload type" field of the
00586799
LP
408messages set to 0. Library implementations should take these messages
409and synthesize traditional driver messages for them on reception.
410
411More specifically:
412
413 Instead of the NameOwnerChanged, NameLost, NameAcquired signals
414 there are kernel messages containing KDBUS_ITEM_NAME_ADD,
415 KDBUS_ITEM_NAME_REMOVE, KDBUS_ITEM_NAME_CHANGE, KDBUS_ITEM_ID_ADD,
416 KDBUS_ITEM_ID_REMOVE items are generated (each message will contain
6bb648a1 417 exactly one of these items). Note that in libsystemd we have
00586799
LP
418 obsoleted NameLost/NameAcquired messages, since they are entirely
419 redundant to NameOwnerChanged. This library will hence only
420 synthesize NameOwnerChanged messages from these kernel messages,
061eab67 421 and never generate NameLost/NameAcquired. If your library needs to
00586799
LP
422 stay compatible to the old dbus1 userspace, you possibly might need
423 to synthesize both a NameOwnerChanged and NameLost/NameAcquired
424 message from the same kernel message.
425
061eab67 426 When a method call times out, a KDBUS_ITEM_REPLY_TIMEOUT message is
00586799
LP
427 generated. This should be synthesized into a method error reply
428 message to the original call.
429
430 When a method call fails because the peer terminated the connection
061eab67 431 before responding, a KDBUS_ITEM_REPLY_DEAD message is
0a6de115 432 generated. Similarly, it should be synthesized into a method error
00586799
LP
433 reply message.
434
435For synthesized messages we recommend setting the cookie field to
436(uint32_t) -1 (and not (uint64_t) -1!), so that the cookie is not 0
437(which the dbus1 spec does not allow), but clearly recognizable as
438synthetic.
439
440Note that the KDBUS_ITEM_NAME_XYZ messages will actually inform you
441about all kinds of names, including activatable ones. Classic dbus1
442NameOwnerChanged messages OTOH are only generated when a name is
443really acquired on the bus and not just simply activatable. This means
6206f4b4 444you must explicitly check for the case where an activatable name
00586799
LP
445becomes acquired or an acquired name is lost and returns to be
446activatable.
447
448NAME REGISTRY
449
061eab67 450To acquire names on the bus, use the KDBUS_CMD_NAME_ACQUIRE ioctl(). It
00586799
LP
451takes a flags field similar to dbus1's RequestName() bus driver call,
452however the NO_QUEUE flag got inverted into a QUEUE flag instead.
453
6206f4b4 454To release a previously acquired name use the KDBUS_CMD_NAME_RELEASE
00586799
LP
455ioctl().
456
457To list acquired names use the KDBUS_CMD_CONN_INFO ioctl. It may be
458used to list unique names, well known names as well as activatable
6206f4b4 459names and clients currently queuing for ownership of a well-known
00586799 460name. The ioctl will return an offset into the memory pool. After
061eab67 461reading all the data you need, you need to release this via the
00586799
LP
462KDBUS_CMD_FREE ioctl(), similar how you release a received message.
463
00586799
LP
464CREDENTIALS
465
061eab67 466kdbus can optionally attach various kinds of metadata about the sender at
00586799
LP
467the point of time of sending ("credentials") to messages, on request
468of the receiver. This is both supported on directed and undirected
469(broadcast) messages. The metadata to attach is selected at time of
470the HELLO ioctl of the receiver via a flags field (see above). Note
471that clients must be able to handle that messages contain more
472metadata than they asked for themselves, to simplify implementation of
473broadcasting in the kernel. The receiver should not rely on this data
474to be around though, even though it will be correct if it happens to
061eab67 475be attached. In order to avoid programming errors in applications, we
f000939e 476recommend though not passing this data on to clients that did not
00586799
LP
477explicitly ask for it.
478
479Credentials may also be queried for a well-known or unique name. Use
480the KDBUS_CMD_CONN_INFO for this. It will return an offset to the pool
481area again, which will contain the same credential items as messages
061eab67
KS
482have attached. Note that when issuing the ioctl, you can select a
483different set of credentials to gather, than what was originally requested
00586799
LP
484for being attached to incoming messages.
485
486Credentials are always specific to the sender namespace that was
6206f4b4 487current at the time of sending, and of the process that opened the
00586799
LP
488bus connection at the time of opening it. Note that this latter data
489is cached!
490
491POLICY
492
493The kernel enforces only very limited policy on names. It will not do
494access filtering by userspace payload, and thus not by interface or
495method name.
496
6206f4b4 497This ultimately means that most fine-grained policy enforcement needs
00586799
LP
498to be done by the receiving process. We recommend using PolicyKit for
499any more complex checks. However, libraries should make simple static
500policy decisions regarding privileged/unprivileged method calls
501easy. We recommend doing this by enabling KDBUS_ATTACH_CAPS and
502KDBUS_ATTACH_CREDS for incoming messages, and then discerning client
061eab67 503access by some capability, or if sender and receiver UIDs match.
00586799
LP
504
505BUS ADDRESSES
506
507When connecting to kdbus use the "kernel:" protocol prefix in DBus
508address strings. The device node path is encoded in its "path="
509parameter.
510
511Client libraries should use the following connection string when
512connecting to the system bus:
513
514 kernel:path=/dev/kdbus/0-system/bus;unix:path=/run/dbus/system_bus_socket
515
516This will ensure that kdbus is preferred over the legacy AF_UNIX
517socket, but compatibility is kept. For the user bus use:
518
e9b1d28d 519 kernel:path=/dev/kdbus/$UID-user/bus;unix:path=$XDG_RUNTIME_DIR/bus
00586799
LP
520
521With $UID replaced by the callers numer user ID, and $XDG_RUNTIME_DIR
522following the XDG basedir spec.
523
524Of course the $DBUS_SYSTEM_BUS_ADDRESS and $DBUS_SESSION_BUS_ADDRESS
525variables should still take precedence.
526
9129246b
LP
527DBUS SERVICE FILES
528
529Activatable services for kdbus may not use classic dbus1 service
530activation files. Instead, programs should drop in native systemd
531.service and .busname unit files, so that they are treated uniformly
532with other types of units and activation of the system.
533
534Note that this results in a major difference to classic dbus1:
061eab67
KS
535activatable bus names can be established at any time in the boot process.
536This is unlike dbus1 where activatable names are unconditionally available
9129246b
LP
537as long as dbus-daemon is running. Being able to control when
538activatable names are established is essential to allow usage of kdbus
539during early boot and in initrds, without the risk of triggering
540services too early.
541
00586799
LP
542DISCLAIMER
543
061eab67 544This all is so far just the status quo. We are putting this together, because
00586799
LP
545we are quite confident that further API changes will be smaller, but
546to make this very clear: this is all subject to change, still!
547
6206f4b4 548We invite you to port over your favorite dbus library to this new
00586799
LP
549scheme, but please be prepared to make minor changes when we still
550change these interfaces!