ctrl-channel.xml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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-leases-reclaim">
  101. <title>leases-reclaim command</title>
  102. <para>
  103. <emphasis>leases-reclaim</emphasis> command instructs the server to
  104. reclaim all expired leases immediately. The command has the following
  105. JSON syntax:
  106. <screen>
  107. {
  108. "command": "leases-reclaim",
  109. "arguments": {
  110. "remove": true
  111. }
  112. }
  113. </screen>
  114. </para>
  115. <para>The <emphasis>remove</emphasis> boolean parameter is mandatory
  116. and it indicates whether the reclaimed leases should be removed from
  117. the lease database (if true), or they should be left in the
  118. <emphasis>expired-reclaimed</emphasis> state (if false). The latter
  119. facilitates lease affinity, i.e. ability to re-assign expired lease to
  120. the same client which used this lease before. See
  121. <xref linkend="lease-affinity"/> for the details. Also, see
  122. <xref linkend="lease-reclamation"/> for the general information
  123. about the processing of expired leases (leases reclamation).</para>
  124. </section>
  125. <section id="command-list-commands">
  126. <title>list-commands command</title>
  127. <para>
  128. <emphasis>list-commands</emphasis> command retrieves a list of all
  129. commands supported by the server. It does not take any arguments.
  130. An example command may look like this:
  131. <screen>
  132. {
  133. "command": "list-commands",
  134. "arguments": { }
  135. }
  136. </screen>
  137. </para>
  138. <para>
  139. The server will respond with a list of all supported commands. The
  140. arguments element will be a list of strings. Each string will convey
  141. one supported command.
  142. </para>
  143. </section> <!-- end of command-list-commands -->
  144. <section id="command-shutdown">
  145. <title>shutdown command</title>
  146. <para>
  147. <emphasis>shutdown</emphasis> command instructs the server to initiate
  148. its shutdown procedure. It is the equivalent of sending a SIGTERM signal
  149. to the process. This command does not take any arguments. An example
  150. command may look like this:
  151. <screen>
  152. {
  153. "command": "shutdown",
  154. "arguments": { }
  155. }
  156. </screen>
  157. </para>
  158. <para>
  159. The server will respond with a confirmation that the shutdown procedure
  160. has been initiated.
  161. </para>
  162. </section> <!-- end of command-shutdown -->
  163. </section> <!-- end of commands supported by both servers -->
  164. </chapter>