ctrl-channel.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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-build-report">
  102. <title>build-report</title>
  103. <para>
  104. The <emphasis>build-report</emphasis> command returns
  105. on the control channel what the command line
  106. <command>-W</command> argument displays, i.e. the embedded
  107. content of the <filename>config.report</filename> file.
  108. This command does not take any parameters.
  109. </para>
  110. <screen>
  111. {
  112. "command": "build-report"
  113. }
  114. </screen>
  115. </section> <!-- end of command-build-report -->
  116. <section id="command-config-get">
  117. <title>config-get</title>
  118. <para>The <emphasis>config-get</emphasis> command retrieves the current
  119. configuration used by the server. This command does not take any
  120. parameters. The configuration returned is roughly equal to the
  121. configuration that was loaded using -c command line option during server
  122. start-up or later set using set-config command. However, there may be
  123. certain differences. Comments are not retained. If the original
  124. configuration used file inclusion, the returned configuration will
  125. include all parameters from all the included files.</para>
  126. <para> Note that returned configuration is not redacted, i.e. it will
  127. contain database passwords in plain text if those were specified in the
  128. original configuration. Care should be taken to not expose the command
  129. channel to unprivileged users.</para>
  130. <para>
  131. An example command invocation looks like this:
  132. <screen>
  133. {
  134. "command": "config-get"
  135. }
  136. </screen>
  137. </para>
  138. </section>
  139. <section id="command-config-write">
  140. <title>config-write</title>
  141. <para>The <emphasis>config-write</emphasis> command instructs Kea server
  142. to write its current configuration to a file on disk. It takes one
  143. optional argument called <emphasis>filename</emphasis> that specifies
  144. the name of the file to write configuration to. If not specified, the
  145. name used when starting Kea (passed as -c argument) will be used. Note
  146. that the filename specified must not contain .. or backslashes. Kea
  147. should be able to write its files only in the directory it is running
  148. and any attempts to step out of that directory will be rejected.</para>
  149. <para>
  150. An example command invocation looks like this:
  151. <screen>
  152. {
  153. "command": "config-write",
  154. "parameters": {
  155. "filename": "config-modified-2017-03-15.json"
  156. }
  157. }
  158. </screen>
  159. </para>
  160. </section>
  161. <section id="command-leases-reclaim">
  162. <title>leases-reclaim</title>
  163. <para>
  164. The <emphasis>leases-reclaim</emphasis> command instructs the server to
  165. reclaim all expired leases immediately. The command has the following
  166. JSON syntax:
  167. <screen>
  168. {
  169. "command": "leases-reclaim",
  170. "arguments": {
  171. "remove": true
  172. }
  173. }
  174. </screen>
  175. </para>
  176. <para>The <emphasis>remove</emphasis> boolean parameter is mandatory
  177. and it indicates whether the reclaimed leases should be removed from
  178. the lease database (if true), or they should be left in the
  179. <emphasis>expired-reclaimed</emphasis> state (if false). The latter
  180. facilitates lease affinity, i.e. ability to re-assign expired lease to
  181. the same client which used this lease before. See
  182. <xref linkend="lease-affinity"/> for the details. Also, see
  183. <xref linkend="lease-reclamation"/> for the general information
  184. about the processing of expired leases (leases reclamation).</para>
  185. </section>
  186. <section id="command-libreload">
  187. <title>libreload</title>
  188. <para>
  189. The <emphasis>libreload</emphasis> command will first unload and then
  190. load all currently loaded hook libraries. This is primarily intended
  191. to allow one or more hook libraries to be replaced with newer versions
  192. without requiring Kea servers to be reconfigured or restarted. Note
  193. the hook libraries will be passed the same parameter values (if any)
  194. they were passed when originally loaded.
  195. <screen>
  196. {
  197. "command": "libreload",
  198. "arguments": { }
  199. }
  200. </screen>
  201. </para>
  202. <para>
  203. The server will respond with a result of 0 indicating success, or 1
  204. indicating a failure.
  205. </para>
  206. </section> <!-- end of command-libreload -->
  207. <section id="command-list-commands">
  208. <title>list-commands</title>
  209. <para>
  210. The <emphasis>list-commands</emphasis> command retrieves a list of all
  211. commands supported by the server. It does not take any arguments.
  212. An example command may look like this:
  213. <screen>
  214. {
  215. "command": "list-commands",
  216. "arguments": { }
  217. }
  218. </screen>
  219. </para>
  220. <para>
  221. The server will respond with a list of all supported commands. The
  222. arguments element will be a list of strings. Each string will convey
  223. one supported command.
  224. </para>
  225. </section> <!-- end of command-list-commands -->
  226. <section id="command-set-config">
  227. <title>set-config</title>
  228. <para>
  229. The <emphasis>set-config</emphasis> command instructs the server to replace
  230. its current configuration with the new configuration supplied in the
  231. command's arguments. The supplied configuration is expected to be the full
  232. configuration for the target server along with an optional Logger
  233. configuration. While optional, the Logger configuration is highly
  234. recommended as without it the server will revert to its default logging
  235. configuration. The structure of the command is as follows:
  236. </para>
  237. <screen>
  238. {
  239. "command": "set-config",
  240. "arguments": {
  241. "&#60;server&#62;": {
  242. },
  243. "Logging": {
  244. }
  245. }
  246. }
  247. </screen>
  248. <para>
  249. where &#60;server&#62; is the configuration element name for a given server
  250. such as "Dhcp4" or "Dhcp6". For example:
  251. </para>
  252. <screen>
  253. {
  254. "command": "set-config",
  255. "arguments": {
  256. "Dhcp6": {
  257. :
  258. },
  259. "Logging": {
  260. :
  261. }
  262. }
  263. }
  264. </screen>
  265. <para>
  266. If the new configuration proves to be invalid the server will retain
  267. its current configuration. Please note that the new configuration is
  268. retained in memory only. If the server is restarted or a configuration
  269. reload is triggered via a signal, the server will use the configuration
  270. stored in its configuration file.
  271. The server's response will contain a numeric code, "result" (0 for success,
  272. non-zero on failure), and a string, "text", describing the outcome:
  273. <screen>
  274. {"result": 0, "text": "Configuration successful." }
  275. or
  276. {"result": 1, "text": "unsupported parameter: BOGUS (&#60;string&#62;:16:26)" }
  277. </screen>
  278. </para>
  279. </section> <!-- end of command-set-config -->
  280. <section id="command-shutdown">
  281. <title>shutdown</title>
  282. <para>
  283. The <emphasis>shutdown</emphasis> command instructs the server to initiate
  284. its shutdown procedure. It is the equivalent of sending a SIGTERM signal
  285. to the process. This command does not take any arguments. An example
  286. command may look like this:
  287. <screen>
  288. {
  289. "command": "shutdown",
  290. "arguments": { }
  291. }
  292. </screen>
  293. </para>
  294. <para>
  295. The server will respond with a confirmation that the shutdown procedure
  296. has been initiated.
  297. </para>
  298. </section> <!-- end of command-shutdown -->
  299. <section id="command-version-get">
  300. <title>version-get</title>
  301. <para>
  302. The <emphasis>version-get</emphasis> command returns on the control
  303. channel what the command line <command>-v</command> argument
  304. displays with in arguments the extended version, i.e., what
  305. the command line <command>-V</command> argument displays. This command
  306. does not take any parameters.
  307. </para>
  308. <screen>
  309. {
  310. "command": "version-get"
  311. }
  312. </screen>
  313. </section> <!-- end of command-version-get -->
  314. </section> <!-- end of commands supported by both servers -->
  315. </chapter>