ctrl-channel.xml 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 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 the DHCPv4 and DHCPv6 servers
  19. include support for a mechanism that allows
  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 in Kea 1.1.0 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 the control channel is conducted using JSON
  35. structures. If configured, Kea will open a socket and listen
  36. for 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 of the map 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. The <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 is command specific).
  71. <command>arguments</command> is a map of additional data values returned by
  72. the server which is 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 the Control Channel</title>
  77. <para>Kea does not currently provide a client for using the control channel. The primary
  78. reason for this is the expectation is that the entity using the 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 only examples are provided to show
  82. 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. Text passed to <command>socat</command>
  94. will be sent to Kea and the responses received from Kea printed to standard output.</para>
  95. <para>It is also easy to open UNIX socket programatically. An example of
  96. such a simplistic client written in C is available in the Kea Developer's
  97. Guide, chapter Control Channel Overview, section Using Control Channel.</para>
  98. </section>
  99. <section id="commands-common">
  100. <title>Commands Supported by Both the DHCPv4 and DHCPv6 Servers</title>
  101. <section id="command-leases-reclaim">
  102. <title>leases-reclaim</title>
  103. <para>
  104. The <emphasis>leases-reclaim</emphasis> command instructs the server to
  105. reclaim all expired leases immediately. The command has the following
  106. JSON syntax:
  107. <screen>
  108. {
  109. "command": "leases-reclaim",
  110. "arguments": {
  111. "remove": true
  112. }
  113. }
  114. </screen>
  115. </para>
  116. <para>The <emphasis>remove</emphasis> boolean parameter is mandatory
  117. and it indicates whether the reclaimed leases should be removed from
  118. the lease database (if true), or they should be left in the
  119. <emphasis>expired-reclaimed</emphasis> state (if false). The latter
  120. facilitates lease affinity, i.e. ability to re-assign expired lease to
  121. the same client which used this lease before. See
  122. <xref linkend="lease-affinity"/> for the details. Also, see
  123. <xref linkend="lease-reclamation"/> for the general information
  124. about the processing of expired leases (leases reclamation).</para>
  125. </section>
  126. <section id="command-libreload">
  127. <title>libreload</title>
  128. <para>
  129. The <emphasis>libreload</emphasis> command will first unload and then
  130. load all currently loaded hook libraries. This is primarily intended
  131. to allow one or more hook libraries to be replaced with newer versions
  132. without requiring Kea servers to be reconfigured or restarted. Note
  133. the hook libraries will be passed the same parameter values (if any)
  134. they were passed when originally loaded.
  135. <screen>
  136. {
  137. "command": "libreload",
  138. "arguments": { }
  139. }
  140. </screen>
  141. </para>
  142. <para>
  143. The server will respond with a result of 0 indicating success, or 1
  144. indicating a failure.
  145. </para>
  146. </section> <!-- end of command-libreload -->
  147. <section id="command-list-commands">
  148. <title>list-commands</title>
  149. <para>
  150. The <emphasis>list-commands</emphasis> command retrieves a list of all
  151. commands supported by the server. It does not take any arguments.
  152. An example command may look like this:
  153. <screen>
  154. {
  155. "command": "list-commands",
  156. "arguments": { }
  157. }
  158. </screen>
  159. </para>
  160. <para>
  161. The server will respond with a list of all supported commands. The
  162. arguments element will be a list of strings. Each string will convey
  163. one supported command.
  164. </para>
  165. </section> <!-- end of command-list-commands -->
  166. <section id="command-set-config">
  167. <title>set-config</title>
  168. <para>
  169. The <emphasis>set-config</emphasis> command instructs the server to replace
  170. its current configuration with the new configuration supplied in the
  171. command's arguments. The supplied configuration is expected to be the full
  172. configuration for the target server along with an optional Logger
  173. configuration. While optional, the Logger configuration is highly
  174. recommended as without it the server will revert to its default logging
  175. configuration. The structure of the command is as follows:
  176. </para>
  177. <screen>
  178. {
  179. "command": "set-config",
  180. "arguments": {
  181. "&#60;server&#62;": {
  182. },
  183. "Logging": {
  184. }
  185. }
  186. }
  187. </screen>
  188. <para>
  189. where &#60;server&#62; is the configuration element name for a given server
  190. such as "Dhcp4" or "Dhcp6". For example:
  191. </para>
  192. <screen>
  193. {
  194. "command": "set-config",
  195. "arguments": {
  196. "Dhcp6": {
  197. :
  198. },
  199. "Logging": {
  200. :
  201. }
  202. }
  203. }
  204. </screen>
  205. <para>
  206. If the new configuration proves to be invalid the server will retain
  207. its current configuration. Please note that the new configuration is
  208. retained in memory only. If the server is restarted or a configuration
  209. reload is triggered via a signal, the server will use the configuration
  210. stored in its configuration file.
  211. The server's response will contain a numeric code, "result" (0 for success,
  212. non-zero on failure), and a string, "text", describing the outcome:
  213. <screen>
  214. {"result": 0, "text": "Configuration successful." }
  215. or
  216. {"result": 1, "text": "unsupported parameter: BOGUS (&#60;string&#62;:16:26)" }
  217. </screen>
  218. </para>
  219. </section> <!-- end of command-set-config -->
  220. <section id="command-shutdown">
  221. <title>shutdown</title>
  222. <para>
  223. The <emphasis>shutdown</emphasis> command instructs the server to initiate
  224. its shutdown procedure. It is the equivalent of sending a SIGTERM signal
  225. to the process. This command does not take any arguments. An example
  226. command may look like this:
  227. <screen>
  228. {
  229. "command": "shutdown",
  230. "arguments": { }
  231. }
  232. </screen>
  233. </para>
  234. <para>
  235. The server will respond with a confirmation that the shutdown procedure
  236. has been initiated.
  237. </para>
  238. </section> <!-- end of command-shutdown -->
  239. </section> <!-- end of commands supported by both servers -->
  240. </chapter>