ctrl-channel.xml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
  4. <!ENTITY mdash "&#x2014;" >
  5. <!ENTITY % version SYSTEM "version.ent">
  6. %version;
  7. ]>
  8. <chapter id="ctrl-channel">
  9. <title>Management API</title>
  10. <para>A classic approach to daemon configuration assumes that
  11. the server's configuration is stored in the configuration files
  12. and when the configuration is changed, the daemon is restarted.
  13. This approach has the significant disadvantage of introducing periods
  14. of downtime, when client traffic is not handled. Another risk
  15. is that if the new configuration is invalid for whatever reason,
  16. the server may refuse to start, which will further extend the
  17. downtime period, until the issue is resolved.</para>
  18. <para>To avoid such problems, both DHCPv4 and DHCPv6 servers
  19. introduced support for a mechanism that will allow
  20. on-line reconfiguration, without requiring server shutdown.
  21. Both servers can be instructed to open control sockets, which
  22. is a communication channel. The server is able to receive
  23. commands on that channel, act on them and report back status.
  24. While the set of commands supported in Kea 0.9.2 is limited,
  25. the number is expected to grow over time.</para>
  26. <para>Currently the only supported type of control channel
  27. is UNIX stream socket. For details how to configure it, see
  28. <xref linkend="dhcp4-ctrl-channel" /> and <xref
  29. linkend="dhcp6-ctrl-channel" />. It is likely that support
  30. for other control channel types will be added in the future.
  31. </para>
  32. <section id="ctrl-channel-syntax">
  33. <title>Data syntax</title>
  34. <para>Communication over control channel is conducted using JSON
  35. structures. If configured, Kea will open a socket and will listen
  36. for any incoming connections. A process connecting to this socket
  37. is expected to send JSON commands structured as follows:
  38. <screen>
  39. {
  40. "command": "foo",
  41. "arguments": {
  42. "param1": "value1",
  43. "param2": "value2",
  44. ...
  45. }
  46. }
  47. </screen>
  48. <command>command</command> is the name of command to execute and
  49. is mandatory. <command>arguments</command> is a map of parameters
  50. required to carry out the given command. The exact content and
  51. format is command specific.</para>
  52. <para>The server will process the incoming command and then send a
  53. response of the form:
  54. <screen>
  55. {
  56. "result": 0|1,
  57. "text": "textual description",
  58. "arguments": {
  59. "argument1": "value1",
  60. "argument2": "value2",
  61. ...
  62. }
  63. }
  64. </screen>
  65. <command>result</command> indicates the outcome of the command. A value of 0
  66. means success while any non-zero value designates an error. Currently 1 is
  67. used as a generic error, but additional error codes may be added in the
  68. future.<command>text</command> field typically appears when result is
  69. non-zero and contains a description of the error encountered, but it may
  70. also appear for successful results. That's command specific.
  71. <command>arguments</command> is a map of additional data values returned by
  72. the server, specific to the command issued. The map is always present, even
  73. if it contains no data values.</para>
  74. </section>
  75. <section id="ctrl-channel-client">
  76. <title>Using control channel</title>
  77. <para>ISC does not provide a client for using control channel. The primary
  78. reason for that is the expectation is that the entity using control channel
  79. is typically an IPAM or similar network management/monitoring software which
  80. may have quite varied expectations regarding the client and is even likely to
  81. be written in languages different than C or C++. Therefore we only provide
  82. examples how one can take advantage of the API.</para>
  83. <para>The easiest way is to use a tool called <command>socat</command>,
  84. a tool available from <ulink url="http://www.dest-unreach.org/socat/">socat
  85. homepage</ulink>, but it is also widely available in Linux and BSD
  86. distributions. Once Kea is started, one could connect to the control
  87. interface using the following command:
  88. <screen>
  89. $ socat UNIX:/path/to/the/kea/socket -
  90. </screen>
  91. where <command>/path/to/the/kea/socket</command> is the path specified in the
  92. <command>Dhcp4/control-socket/socket-name</command> parameter in the Kea
  93. configuration file.</para>
  94. <para>It is also easy to open UNIX socket programmatically. An example of
  95. such a simplistic client written in C is available in the Kea Developer's
  96. Guide, chapter Control Channel Overview, section Using Control Channel.</para>
  97. </section>
  98. <section id="commands-common">
  99. <title>Commands supported by both DHCPv4 and DHCPv6 servers</title>
  100. <section id="command-list-commands">
  101. <title>list-commands command</title>
  102. <para>
  103. <emphasis>list-commands</emphasis> command retrieves a list of all
  104. commands supported by the server. It does not take any arguments.
  105. An example command may look like this:
  106. <screen>
  107. {
  108. "command": "list-commands",
  109. "arguments": { }
  110. }
  111. </screen>
  112. </para>
  113. <para>
  114. The server will respond with a list of all supported commands. The
  115. arguments element will be a list of strings. Each string will convey
  116. one supported command.
  117. </para>
  118. </section> <!-- end of command-list-commands -->
  119. <section id="command-shutdown">
  120. <title>shutdown command</title>
  121. <para>
  122. <emphasis>shutdown</emphasis> command instructs the server to initiate
  123. its shutdown procedure. It is the equivalent of sending a SIGTERM singal
  124. to the process. This command does not take any arguments. An example
  125. command may look like this:
  126. <screen>
  127. {
  128. "command": "shutdown",
  129. "arguments": { }
  130. }
  131. </screen>
  132. </para>
  133. <para>
  134. The server will respond with a confirmation that the shutdown procedure
  135. has been initiated.
  136. </para>
  137. </section> <!-- end of command-shutdown -->
  138. </section> <!-- end of commands supported by both servers -->
  139. </chapter>