summaryrefslogtreecommitdiff
path: root/Documentation/kdbus/kdbus.connection.xml
blob: 4bb5f30f379aca245c18e4b2d3a47274bdbe5da9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
<?xml version='1.0'?> <!--*-nxml-*-->
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
        "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">

<refentry id="kdbus.connection">

  <refentryinfo>
    <title>kdbus.connection</title>
    <productname>kdbus.connection</productname>
  </refentryinfo>

  <refmeta>
    <refentrytitle>kdbus.connection</refentrytitle>
    <manvolnum>7</manvolnum>
  </refmeta>

  <refnamediv>
    <refname>kdbus.connection</refname>
    <refpurpose>kdbus connection</refpurpose>
  </refnamediv>

  <refsect1>
    <title>Description</title>

    <para>
      Connections are identified by their <emphasis>connection ID</emphasis>,
      internally implemented as a <type>uint64_t</type> counter.
      The IDs of every newly created bus start at <constant>1</constant>, and
      every new connection will increment the counter by <constant>1</constant>.
      The IDs are not reused.
    </para>
    <para>
      In higher level tools, the user visible representation of a connection is
      defined by the D-Bus protocol specification as
      <constant>":1.&lt;ID&gt;"</constant>.
    </para>
    <para>
      Messages with a specific <type>uint64_t</type> destination ID are
      directly delivered to the connection with the corresponding ID. Signal
      messages (see
      <citerefentry>
        <refentrytitle>kdbus.message</refentrytitle>
        <manvolnum>7</manvolnum>
      </citerefentry>)
      may be addressed to the special destination ID
      <constant>KDBUS_DST_ID_BROADCAST</constant> (~0ULL) and will then
      potentially be delivered to all currently active connections on the bus.
      However, in order to receive any signal messages, clients must subscribe
      to them by installing a match (see
      <citerefentry>
        <refentrytitle>kdbus.match</refentrytitle>
        <manvolnum>7</manvolnum>
      </citerefentry>).
    </para>
    <para>
      Messages synthesized and sent directly by the kernel will carry the
      special source ID <constant>KDBUS_SRC_ID_KERNEL</constant> (0).
    </para>
    <para>
      In addition to the unique <type>uint64_t</type> connection ID,
      established connections can request the ownership of
      <emphasis>well-known names</emphasis>, under which they can be found and
      addressed by other bus clients. A well-known name is associated with one
      and only one connection at a time. See
      <citerefentry>
        <refentrytitle>kdbus.name</refentrytitle>
        <manvolnum>7</manvolnum>
      </citerefentry>
      on name acquisition, the name registry, and the validity of names.
    </para>
    <para>
      Messages can specify the special destination ID
      <constant>KDBUS_DST_ID_NAME</constant> (0) and carry a well-known name
      in the message data. Such a message is delivered to the destination
      connection which owns that well-known name.
    </para>

    <programlisting><![CDATA[
  +-------------------------------------------------------------------------+
  | +---------------+     +---------------------------+                     |
  | | Connection    |     | Message                   | -----------------+  |
  | | :1.22         | --> | src: 22                   |                  |  |
  | |               |     | dst: 25                   |                  |  |
  | |               |     |                           |                  |  |
  | |               |     |                           |                  |  |
  | |               |     +---------------------------+                  |  |
  | |               |                                                    |  |
  | |               | <--------------------------------------+           |  |
  | +---------------+                                        |           |  |
  |                                                          |           |  |
  | +---------------+     +---------------------------+      |           |  |
  | | Connection    |     | Message                   | -----+           |  |
  | | :1.25         | --> | src: 25                   |                  |  |
  | |               |     | dst: 0xffffffffffffffff   | -------------+   |  |
  | |               |     |  (KDBUS_DST_ID_BROADCAST) |              |   |  |
  | |               |     |                           | ---------+   |   |  |
  | |               |     +---------------------------+          |   |   |  |
  | |               |                                            |   |   |  |
  | |               | <--------------------------------------------------+  |
  | +---------------+                                            |   |      |
  |                                                              |   |      |
  | +---------------+     +---------------------------+          |   |      |
  | | Connection    |     | Message                   | --+      |   |      |
  | | :1.55         | --> | src: 55                   |   |      |   |      |
  | |               |     | dst: 0 / org.foo.bar      |   |      |   |      |
  | |               |     |                           |   |      |   |      |
  | |               |     |                           |   |      |   |      |
  | |               |     +---------------------------+   |      |   |      |
  | |               |                                     |      |   |      |
  | |               | <------------------------------------------+   |      |
  | +---------------+                                     |          |      |
  |                                                       |          |      |
  | +---------------+                                     |          |      |
  | | Connection    |                                     |          |      |
  | | :1.81         |                                     |          |      |
  | | org.foo.bar   |                                     |          |      |
  | |               |                                     |          |      |
  | |               |                                     |          |      |
  | |               | <-----------------------------------+          |      |
  | |               |                                                |      |
  | |               | <----------------------------------------------+      |
  | +---------------+                                                       |
  +-------------------------------------------------------------------------+
    ]]></programlisting>
  </refsect1>

  <refsect1>
    <title>Privileged connections</title>
    <para>
      A connection is considered <emphasis>privileged</emphasis> if the user
      it was created by is the same that created the bus, or if the creating
      task had <constant>CAP_IPC_OWNER</constant> set when it called
      <constant>KDBUS_CMD_HELLO</constant> (see below).
    </para>
    <para>
      Privileged connections have permission to employ certain restricted
      functions and commands, which are explained below and in other kdbus
      man-pages.
    </para>
  </refsect1>

  <refsect1>
    <title>Activator and policy holder connection</title>
    <para>
      An <emphasis>activator</emphasis> connection is a placeholder for a
      <emphasis>well-known name</emphasis>. Messages sent to such a connection
      can be used to start an implementer connection, which will then get all
      the messages from the activator copied over. An activator connection
      cannot be used to send any message.
    </para>
    <para>
      A <emphasis>policy holder</emphasis> connection only installs a policy
      for one or more names. These policy entries are kept active as long as
      the connection is alive, and are removed once it terminates. Such a
      policy connection type can be used to deploy restrictions for names that
      are not yet active on the bus. A policy holder connection cannot be used
      to send any message.
    </para>
    <para>
      The creation of activator or policy holder connections is restricted to
      privileged users on the bus (see above).
    </para>
  </refsect1>

  <refsect1>
    <title>Monitor connections</title>
    <para>
      Monitors are eavesdropping connections that receive all the traffic on the
      bus, but is invisible to other connections. Such connections have all
      properties of any other, regular connection, except for the following
      details:
    </para>

    <itemizedlist>
      <listitem><para>
        They will get every message sent over the bus, both unicasts and
        broadcasts.
      </para></listitem>

      <listitem><para>
        Installing matches for signal messages is neither necessary
        nor allowed.
      </para></listitem>

      <listitem><para>
        They cannot send messages or be directly addressed as receiver.
      </para></listitem>

      <listitem><para>
        They cannot own well-known names. Therefore, they also can't operate as
        activators.
      </para></listitem>

      <listitem><para>
        Their creation and destruction will not cause
        <constant>KDBUS_ITEM_ID_{ADD,REMOVE}</constant> (see
        <citerefentry>
          <refentrytitle>kdbus.item</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>).
      </para></listitem>

      <listitem><para>
        They are not listed with their unique name in name registry dumps
        (see <constant>KDBUS_CMD_NAME_LIST</constant> in
        <citerefentry>
          <refentrytitle>kdbus.name</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>), so other connections cannot detect the presence of
	a monitor.
      </para></listitem>
    </itemizedlist>
    <para>
      The creation of monitor connections is restricted to privileged users on
      the bus (see above).
    </para>
  </refsect1>

  <refsect1>
    <title>Creating connections</title>
    <para>
      A connection to a bus is created by opening an endpoint file (see
      <citerefentry>
        <refentrytitle>kdbus.endpoint</refentrytitle>
        <manvolnum>7</manvolnum>
      </citerefentry>)
      of a bus and becoming an active client with the
      <constant>KDBUS_CMD_HELLO</constant> ioctl. Every connection has a unique
      identifier on the bus and can address messages to every other connection
      on the same bus by using the peer's connection ID as the destination.
    </para>
    <para>
      The <constant>KDBUS_CMD_HELLO</constant> ioctl takes a <type>struct
      kdbus_cmd_hello</type> as argument.
    </para>

    <programlisting>
struct kdbus_cmd_hello {
  __u64 size;
  __u64 flags;
  __u64 return_flags;
  __u64 attach_flags_send;
  __u64 attach_flags_recv;
  __u64 bus_flags;
  __u64 id;
  __u64 pool_size;
  __u64 offset;
  __u8 id128[16];
  struct kdbus_item items[0];
};
    </programlisting>

    <para>The fields in this struct are described below.</para>

    <variablelist>
      <varlistentry>
        <term><varname>size</varname></term>
        <listitem><para>
          The overall size of the struct, including its items.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>flags</varname></term>
        <listitem>
          <para>Flags to apply to this connection</para>
          <variablelist>
            <varlistentry>
              <term><constant>KDBUS_HELLO_ACCEPT_FD</constant></term>
              <listitem>
                <para>
                  When this flag is set, the connection can be sent file
                  descriptors as message payload of unicast messages. If it's
                  not set, an attempt to send file descriptors will result in
                  <constant>-ECOMM</constant> on the sender's side.
                </para>
              </listitem>
            </varlistentry>

            <varlistentry>
              <term><constant>KDBUS_HELLO_ACTIVATOR</constant></term>
              <listitem>
                <para>
                  Make this connection an activator (see above). With this bit
                  set, an item of type <constant>KDBUS_ITEM_NAME</constant> has
                  to be attached. This item describes the well-known name this
                  connection should be an activator for.
                  A connection can not be an activator and a policy holder at
                  the same time time, so this bit is not allowed together with
                  <constant>KDBUS_HELLO_POLICY_HOLDER</constant>.
                </para>
              </listitem>
            </varlistentry>

            <varlistentry>
              <term><constant>KDBUS_HELLO_POLICY_HOLDER</constant></term>
              <listitem>
                <para>
                  Make this connection a policy holder (see above). With this
                  bit set, an item of type <constant>KDBUS_ITEM_NAME</constant>
                  has to be attached. This item describes the well-known name
                  this connection should hold a policy for.
                  A connection can not be an activator and a policy holder at
                  the same time time, so this bit is not allowed together with
                  <constant>KDBUS_HELLO_ACTIVATOR</constant>.
                </para>
              </listitem>
            </varlistentry>

            <varlistentry>
              <term><constant>KDBUS_HELLO_MONITOR</constant></term>
              <listitem>
                <para>
                  Make this connection a monitor connection (see above).
                </para>
                <para>
                  This flag can only be set by privileged bus connections. See
                  below for more information.
                  A connection can not be monitor and an activator or a policy
                  holder at the same time time, so this bit is not allowed
                  together with <constant>KDBUS_HELLO_ACTIVATOR</constant> or
                  <constant>KDBUS_HELLO_POLICY_HOLDER</constant>.
                </para>
              </listitem>
            </varlistentry>

            <varlistentry>
              <term><constant>KDBUS_FLAG_NEGOTIATE</constant></term>
              <listitem>
                <para>
                  Requests a set of valid flags for this ioctl. When this bit is
                  set, no action is taken; the ioctl will return
                  <errorcode>0</errorcode>, and the <varname>flags</varname>
                  field will have all bits set that are valid for this command.
                  The <constant>KDBUS_FLAG_NEGOTIATE</constant> bit will be
                  cleared by the operation.
                </para>
              </listitem>
            </varlistentry>
          </variablelist>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>return_flags</varname></term>
        <listitem><para>
          Flags returned by the kernel. Currently unused and always set to
          <constant>0</constant> by the kernel.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>attach_flags_send</varname></term>
        <listitem><para>
          Set the bits for metadata this connection permits to be sent to the
          receiving peer. Only metadata items that are both allowed to be sent
          by the sender and that are requested by the receiver will be attached
          to the message.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>attach_flags_recv</varname></term>
        <listitem><para>
          Request the attachment of metadata for each message received by this
          connection. See
          <citerefentry>
            <refentrytitle>kdbus</refentrytitle>
            <manvolnum>7</manvolnum>
          </citerefentry>
          for information about metadata, and
          <citerefentry>
            <refentrytitle>kdbus.item</refentrytitle>
            <manvolnum>7</manvolnum>
          </citerefentry>
          regarding items in general.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>bus_flags</varname></term>
        <listitem><para>
          Upon successful completion of the ioctl, this member will contain the
          flags of the bus it connected to.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>id</varname></term>
        <listitem><para>
          Upon successful completion of the command, this member will contain
          the numerical ID of the new connection.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>pool_size</varname></term>
        <listitem><para>
          The size of the communication pool, in bytes. The pool can be
          accessed by calling
          <citerefentry>
            <refentrytitle>mmap</refentrytitle>
            <manvolnum>2</manvolnum>
          </citerefentry>
          on the file descriptor that was used to issue the
          <constant>KDBUS_CMD_HELLO</constant> ioctl.
          The pool size of a connection must be greater than
          <constant>0</constant> and a multiple of
          <constant>PAGE_SIZE</constant>. See
          <citerefentry>
            <refentrytitle>kdbus.pool</refentrytitle>
            <manvolnum>7</manvolnum>
          </citerefentry>
          for more information.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>offset</varname></term>
        <listitem><para>
          The kernel will return the offset in the pool where returned details
          will be stored. See below.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>id128</varname></term>
        <listitem><para>
          Upon successful completion of the ioctl, this member will contain the
          <emphasis>128-bit UUID</emphasis> of the connected bus.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>items</varname></term>
        <listitem>
          <para>
            Variable list of items containing optional additional information.
            The following items are currently expected/valid:
          </para>
          <variablelist>
            <varlistentry>
              <term><constant>KDBUS_ITEM_CONN_DESCRIPTION</constant></term>
              <listitem>
                <para>
                  Contains a string that describes this connection, so it can
                  be identified later.
                </para>
              </listitem>
            </varlistentry>

            <varlistentry>
              <term><constant>KDBUS_ITEM_NAME</constant></term>
              <term><constant>KDBUS_ITEM_POLICY_ACCESS</constant></term>
              <listitem>
                <para>
                  For activators and policy holders only, combinations of
                  these two items describe policy access entries. See
                  <citerefentry>
                    <refentrytitle>kdbus.policy</refentrytitle>
                    <manvolnum>7</manvolnum>
                  </citerefentry>
                  for further details.
                </para>
              </listitem>
            </varlistentry>

            <varlistentry>
              <term><constant>KDBUS_ITEM_CREDS</constant></term>
              <term><constant>KDBUS_ITEM_PIDS</constant></term>
              <term><constant>KDBUS_ITEM_SECLABEL</constant></term>
              <listitem>
                <para>
                  Privileged bus users may submit these types in order to
                  create connections with faked credentials. This information
                  will be returned when peer information is queried by
                  <constant>KDBUS_CMD_CONN_INFO</constant>. See below for more
                  information on retrieving information on connections.
                </para>
              </listitem>
            </varlistentry>

            <varlistentry>
              <term><constant>KDBUS_ITEM_NEGOTIATE</constant></term>
              <listitem><para>
                With this item, programs can <emphasis>probe</emphasis> the
                kernel for known item types. See
                <citerefentry>
                  <refentrytitle>kdbus.item</refentrytitle>
                  <manvolnum>7</manvolnum>
                </citerefentry>
                for more details.
              </para></listitem>
            </varlistentry>
          </variablelist>

          <para>
            Unrecognized items are rejected, and the ioctl will fail with
            <varname>errno</varname> set to <constant>EINVAL</constant>.
          </para>
        </listitem>
      </varlistentry>
    </variablelist>

    <para>
      At the offset returned in the <varname>offset</varname> field of
      <type>struct kdbus_cmd_hello</type>, the kernel will store items
      of the following types:
    </para>

    <variablelist>
      <varlistentry>
        <term><constant>KDBUS_ITEM_BLOOM_PARAMETER</constant></term>
        <listitem>
          <para>
            Bloom filter parameter as defined by the bus creator.
          </para>
        </listitem>
      </varlistentry>
    </variablelist>

    <para>
      The offset in the pool has to be freed with the
      <constant>KDBUS_CMD_FREE</constant> ioctl. See
      <citerefentry>
        <refentrytitle>kdbus.pool</refentrytitle>
        <manvolnum>7</manvolnum>
      </citerefentry>
      for further information.
    </para>
  </refsect1>

  <refsect1>
    <title>Retrieving information on a connection</title>
    <para>
      The <constant>KDBUS_CMD_CONN_INFO</constant> ioctl can be used to
      retrieve credentials and properties of the initial creator of a
      connection. This ioctl uses the following struct.
    </para>

    <programlisting>
struct kdbus_cmd_info {
  __u64 size;
  __u64 flags;
  __u64 return_flags;
  __u64 id;
  __u64 attach_flags;
  __u64 offset;
  __u64 info_size;
  struct kdbus_item items[0];
};
    </programlisting>

    <variablelist>
      <varlistentry>
        <term><varname>size</varname></term>
        <listitem><para>
          The overall size of the struct, including its items.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>flags</varname></term>
        <listitem><para>
          Currently, no flags are supported.
          <constant>KDBUS_FLAG_NEGOTIATE</constant> is accepted to probe for
          valid flags. If set, the ioctl will return <errorcode>0</errorcode>,
          and the <varname>flags</varname> field is set to
          <constant>0</constant>.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>return_flags</varname></term>
        <listitem><para>
          Flags returned by the kernel. Currently unused and always set to
          <constant>0</constant> by the kernel.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>id</varname></term>
        <listitem><para>
          The numerical ID of the connection for which information is to be
          retrieved. If set to a non-zero value, the
          <constant>KDBUS_ITEM_OWNED_NAME</constant> item is ignored.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>attach_flags</varname></term>
        <listitem><para>
          Specifies which metadata items should be attached to the answer. See
          <citerefentry>
            <refentrytitle>kdbus.message</refentrytitle>
            <manvolnum>7</manvolnum>
          </citerefentry>.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>offset</varname></term>
        <listitem><para>
          When the ioctl returns, this field will contain the offset of the
          connection information inside the caller's pool. See
          <citerefentry>
            <refentrytitle>kdbus.pool</refentrytitle>
            <manvolnum>7</manvolnum>
          </citerefentry>
          for further information.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>info_size</varname></term>
        <listitem><para>
          The kernel will return the size of the returned information, so
          applications can optionally
          <citerefentry>
            <refentrytitle>mmap</refentrytitle>
            <manvolnum>2</manvolnum>
          </citerefentry>
          specific parts of the pool. See
          <citerefentry>
            <refentrytitle>kdbus.pool</refentrytitle>
            <manvolnum>7</manvolnum>
          </citerefentry>
          for further information.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>items</varname></term>
        <listitem>
          <para>
            The following items are expected for
            <constant>KDBUS_CMD_CONN_INFO</constant>.
          </para>
          <variablelist>
            <varlistentry>
              <term><constant>KDBUS_ITEM_OWNED_NAME</constant></term>
              <listitem>
                <para>
                  Contains the well-known name of the connection to look up as.
                  This item is mandatory if the <varname>id</varname> field is
                  set to 0.
                </para>
              </listitem>
            </varlistentry>

            <varlistentry>
              <term><constant>KDBUS_ITEM_NEGOTIATE</constant></term>
              <listitem><para>
                With this item, programs can <emphasis>probe</emphasis> the
                kernel for known item types. See
                <citerefentry>
                  <refentrytitle>kdbus.item</refentrytitle>
                  <manvolnum>7</manvolnum>
                </citerefentry>
                for more details.
              </para></listitem>
            </varlistentry>
          </variablelist>
          <para>
            Unrecognized items are rejected, and the ioctl will fail with
            <varname>errno</varname> set to <constant>EINVAL</constant>.
          </para>
        </listitem>
      </varlistentry>
    </variablelist>

    <para>
      When the ioctl returns, the following struct will be stored in the
      caller's pool at <varname>offset</varname>. The fields in this struct
      are described below.
    </para>

    <programlisting>
struct kdbus_info {
  __u64 size;
  __u64 id;
  __u64 flags;
  struct kdbus_item items[0];
};
    </programlisting>

    <variablelist>
      <varlistentry>
        <term><varname>size</varname></term>
        <listitem><para>
          The overall size of the struct, including its items.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>id</varname></term>
        <listitem><para>
          The connection's unique ID.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>flags</varname></term>
        <listitem><para>
          The connection's flags as specified when it was created.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>items</varname></term>
        <listitem>
          <para>
            Depending on the <varname>flags</varname> field in
            <type>struct kdbus_cmd_info</type>, items of types
            <constant>KDBUS_ITEM_OWNED_NAME</constant> and
            <constant>KDBUS_ITEM_CONN_DESCRIPTION</constant> may follow here.
            <constant>KDBUS_ITEM_NEGOTIATE</constant> is also allowed.
          </para>
        </listitem>
      </varlistentry>
    </variablelist>

    <para>
      Once the caller is finished with parsing the return buffer, it needs to
      employ the <constant>KDBUS_CMD_FREE</constant> command for the offset, in
      order to free the buffer part. See
      <citerefentry>
        <refentrytitle>kdbus.pool</refentrytitle>
        <manvolnum>7</manvolnum>
      </citerefentry>
      for further information.
    </para>
  </refsect1>

  <refsect1>
    <title>Getting information about a connection's bus creator</title>
    <para>
      The <constant>KDBUS_CMD_BUS_CREATOR_INFO</constant> ioctl takes the same
      struct as <constant>KDBUS_CMD_CONN_INFO</constant>, but is used to
      retrieve information about the creator of the bus the connection is
      attached to. The metadata returned by this call is collected during the
      creation of the bus and is never altered afterwards, so it provides
      pristine information on the task that created the bus, at the moment when
      it did so.
    </para>
    <para>
      In response to this call, a slice in the connection's pool is allocated
      and filled with an object of type <type>struct kdbus_info</type>,
      pointed to by the ioctl's <varname>offset</varname> field.
    </para>

    <programlisting>
struct kdbus_info {
  __u64 size;
  __u64 id;
  __u64 flags;
  struct kdbus_item items[0];
};
    </programlisting>

    <variablelist>
      <varlistentry>
        <term><varname>size</varname></term>
        <listitem><para>
          The overall size of the struct, including its items.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>id</varname></term>
        <listitem><para>
          The bus ID.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>flags</varname></term>
        <listitem><para>
          The bus flags as specified when it was created.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>items</varname></term>
        <listitem>
          <para>
            Metadata information is stored in items here. The item list
            contains a <constant>KDBUS_ITEM_MAKE_NAME</constant> item that
            indicates the bus name of the calling connection.
            <constant>KDBUS_ITEM_NEGOTIATE</constant> is allowed to probe
            for known item types.
          </para>
        </listitem>
      </varlistentry>
    </variablelist>

    <para>
      Once the caller is finished with parsing the return buffer, it needs to
      employ the <constant>KDBUS_CMD_FREE</constant> command for the offset, in
      order to free the buffer part. See
      <citerefentry>
        <refentrytitle>kdbus.pool</refentrytitle>
        <manvolnum>7</manvolnum>
      </citerefentry>
      for further information.
    </para>
  </refsect1>

  <refsect1>
    <title>Updating connection details</title>
    <para>
      Some of a connection's details can be updated with the
      <constant>KDBUS_CMD_CONN_UPDATE</constant> ioctl, using the file
      descriptor that was used to create the connection. The update command
      uses the following struct.
    </para>

    <programlisting>
struct kdbus_cmd {
  __u64 size;
  __u64 flags;
  __u64 return_flags;
  struct kdbus_item items[0];
};
    </programlisting>

    <variablelist>
      <varlistentry>
        <term><varname>size</varname></term>
        <listitem><para>
          The overall size of the struct, including its items.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>flags</varname></term>
        <listitem><para>
          Currently, no flags are supported.
          <constant>KDBUS_FLAG_NEGOTIATE</constant> is accepted to probe for
          valid flags. If set, the ioctl will return <errorcode>0</errorcode>,
          and the <varname>flags</varname> field is set to
          <constant>0</constant>.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>return_flags</varname></term>
        <listitem><para>
          Flags returned by the kernel. Currently unused and always set to
          <constant>0</constant> by the kernel.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>items</varname></term>
        <listitem>
          <para>
            Items to describe the connection details to be updated. The
            following item types are supported.
          </para>
          <variablelist>
            <varlistentry>
              <term><constant>KDBUS_ITEM_ATTACH_FLAGS_SEND</constant></term>
              <listitem>
                <para>
                  Supply a new set of metadata items that this connection
                  permits to be sent along with messages.
                </para>
              </listitem>
            </varlistentry>

            <varlistentry>
              <term><constant>KDBUS_ITEM_ATTACH_FLAGS_RECV</constant></term>
              <listitem>
                <para>
                  Supply a new set of metadata items that this connection
                  requests to be attached to each message.
                </para>
              </listitem>
            </varlistentry>

            <varlistentry>
              <term><constant>KDBUS_ITEM_NAME</constant></term>
              <term><constant>KDBUS_ITEM_POLICY_ACCESS</constant></term>
              <listitem>
                <para>
                  Policy holder connections may supply a new set of policy
                  information with these items. For other connection types,
                  <constant>EOPNOTSUPP</constant> is returned in
                  <varname>errno</varname>.
                </para>
              </listitem>
            </varlistentry>

            <varlistentry>
              <term><constant>KDBUS_ITEM_NEGOTIATE</constant></term>
              <listitem><para>
                With this item, programs can <emphasis>probe</emphasis> the
                kernel for known item types. See
                <citerefentry>
                  <refentrytitle>kdbus.item</refentrytitle>
                  <manvolnum>7</manvolnum>
                </citerefentry>
                for more details.
              </para></listitem>
            </varlistentry>
          </variablelist>

          <para>
            Unrecognized items are rejected, and the ioctl will fail with
            <varname>errno</varname> set to <constant>EINVAL</constant>.
          </para>
        </listitem>
      </varlistentry>
    </variablelist>
  </refsect1>

  <refsect1>
    <title>Termination of connections</title>
    <para>
      A connection can be terminated by simply calling
      <citerefentry>
        <refentrytitle>close</refentrytitle>
        <manvolnum>2</manvolnum>
      </citerefentry>
      on its file descriptor. All pending incoming messages will be discarded,
      and the memory allocated by the pool will be freed.
    </para>

    <para>
      An alternative way of closing down a connection is via the
      <constant>KDBUS_CMD_BYEBYE</constant> ioctl. This ioctl will succeed only
      if the message queue of the connection is empty at the time of closing;
      otherwise, the ioctl will fail with <varname>errno</varname> set to
      <constant>EBUSY</constant>. When this ioctl returns
      successfully, the connection has been terminated and won't accept any new
      messages from remote peers. This way, a connection can be terminated
      race-free, without losing any messages. The ioctl takes an argument of
      type <type>struct kdbus_cmd</type>.
    </para>

    <programlisting>
struct kdbus_cmd {
  __u64 size;
  __u64 flags;
  __u64 return_flags;
  struct kdbus_item items[0];
};
    </programlisting>

    <variablelist>
      <varlistentry>
        <term><varname>size</varname></term>
        <listitem><para>
          The overall size of the struct, including its items.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>flags</varname></term>
        <listitem><para>
          Currently, no flags are supported.
          <constant>KDBUS_FLAG_NEGOTIATE</constant> is accepted to probe for
          valid flags. If set, the ioctl will fail with
          <varname>errno</varname> set to <constant>EPROTO</constant>, and
          the <varname>flags</varname> field is set to <constant>0</constant>.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>return_flags</varname></term>
        <listitem><para>
          Flags returned by the kernel. Currently unused and always set to
          <constant>0</constant> by the kernel.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>items</varname></term>
        <listitem>
          <para>
            The following item types are supported.
          </para>
          <variablelist>
            <varlistentry>
              <term><constant>KDBUS_ITEM_NEGOTIATE</constant></term>
              <listitem><para>
                With this item, programs can <emphasis>probe</emphasis> the
                kernel for known item types. See
                <citerefentry>
                  <refentrytitle>kdbus.item</refentrytitle>
                  <manvolnum>7</manvolnum>
                </citerefentry>
                for more details.
              </para></listitem>
            </varlistentry>
          </variablelist>

          <para>
            Unrecognized items are rejected, and the ioctl will fail with
            <varname>errno</varname> set to <constant>EINVAL</constant>.
          </para>
        </listitem>
      </varlistentry>
    </variablelist>
  </refsect1>

  <refsect1>
    <title>Return value</title>
    <para>
      On success, all mentioned ioctl commands return <errorcode>0</errorcode>;
      on error, <errorcode>-1</errorcode> is returned, and
      <varname>errno</varname> is set to indicate the error.
      If the issued ioctl is illegal for the file descriptor used,
      <varname>errno</varname> will be set to <constant>ENOTTY</constant>.
    </para>

    <refsect2>
      <title>
        <constant>KDBUS_CMD_HELLO</constant> may fail with the following
        errors
      </title>

      <variablelist>
        <varlistentry>
          <term><constant>EFAULT</constant></term>
          <listitem><para>
            The supplied pool size was 0 or not a multiple of the page size.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><constant>EINVAL</constant></term>
          <listitem><para>
            The flags supplied in <type>struct kdbus_cmd_hello</type>
            are invalid.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><constant>EINVAL</constant></term>
          <listitem><para>
            An illegal combination of
            <constant>KDBUS_HELLO_MONITOR</constant>,
            <constant>KDBUS_HELLO_ACTIVATOR</constant> and
            <constant>KDBUS_HELLO_POLICY_HOLDER</constant> was passed in
            <varname>flags</varname>.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><constant>EINVAL</constant></term>
          <listitem><para>
            An invalid set of items was supplied.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><constant>ECONNREFUSED</constant></term>
          <listitem><para>
            The attach_flags_send field did not satisfy the requirements of
            the bus.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><constant>EPERM</constant></term>
          <listitem><para>
            A <constant>KDBUS_ITEM_CREDS</constant> items was supplied, but the
            current user is not privileged.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><constant>ESHUTDOWN</constant></term>
          <listitem><para>
            The bus you were trying to connect to has already been shut down.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><constant>EMFILE</constant></term>
          <listitem><para>
            The maximum number of connections on the bus has been reached.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><constant>EOPNOTSUPP</constant></term>
          <listitem><para>
            The endpoint does not support the connection flags supplied in
            <type>struct kdbus_cmd_hello</type>.
          </para></listitem>
        </varlistentry>
      </variablelist>
    </refsect2>

    <refsect2>
      <title>
        <constant>KDBUS_CMD_BYEBYE</constant> may fail with the following
        errors
      </title>

      <variablelist>
        <varlistentry>
          <term><constant>EALREADY</constant></term>
          <listitem><para>
            The connection has already been shut down.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><constant>EBUSY</constant></term>
          <listitem><para>
            There are still messages queued up in the connection's pool.
          </para></listitem>
        </varlistentry>
      </variablelist>
    </refsect2>

    <refsect2>
      <title>
        <constant>KDBUS_CMD_CONN_INFO</constant> may fail with the following
        errors
      </title>

      <variablelist>
        <varlistentry>
          <term><constant>EINVAL</constant></term>
          <listitem><para>
            Invalid flags, or neither an ID nor a name was provided, or the
            name is invalid.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><constant>ESRCH</constant></term>
          <listitem><para>
            Connection lookup by name failed.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><constant>ENXIO</constant></term>
          <listitem><para>
            No connection with the provided connection ID found.
          </para></listitem>
        </varlistentry>
      </variablelist>
    </refsect2>

    <refsect2>
      <title>
        <constant>KDBUS_CMD_CONN_UPDATE</constant> may fail with the following
        errors
      </title>

      <variablelist>
        <varlistentry>
          <term><constant>EINVAL</constant></term>
          <listitem><para>
            Illegal flags or items.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><constant>EINVAL</constant></term>
          <listitem><para>
            Wildcards submitted in policy entries, or illegal sequence
            of policy items.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><constant>EOPNOTSUPP</constant></term>
          <listitem><para>
            Operation not supported by connection.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><constant>E2BIG</constant></term>
          <listitem><para>
            Too many policy items attached.
          </para></listitem>
        </varlistentry>
      </variablelist>
    </refsect2>
  </refsect1>

  <refsect1>
    <title>See Also</title>
    <simplelist type="inline">
      <member>
        <citerefentry>
          <refentrytitle>kdbus</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>
      </member>
      <member>
        <citerefentry>
          <refentrytitle>kdbus.bus</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>
      </member>
      <member>
        <citerefentry>
          <refentrytitle>kdbus.endpoint</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>
      </member>
      <member>
        <citerefentry>
          <refentrytitle>kdbus.message</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>
      </member>
      <member>
        <citerefentry>
          <refentrytitle>kdbus.name</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>
      </member>
      <member>
        <citerefentry>
          <refentrytitle>kdbus.policy</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>
      </member>
      <member>
        <citerefentry>
          <refentrytitle>kdbus.pool</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>
      </member>
      <member>
        <citerefentry>
          <refentrytitle>kdbus.item</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>
      </member>
    </simplelist>
  </refsect1>
</refentry>