config-backend.dox 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. // Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. /**
  15. @page configBackend Kea Configuration Backends
  16. @section configBackendIntro Introduction
  17. Kea is a flexible DHCP protocol engine. It offers a selection of lease database
  18. backends, extensibility via the hooks API and the definition of custom options.
  19. Depending on the environment, one lease database backend may be better than
  20. other. Similarly, because the best way of configuring the server can depend on
  21. the environment, Kea provides different ways of obtaining configuration
  22. information, through the Configuration Backend. Since the means by which
  23. configuration information is received cannot be part of the configuration itself, it
  24. has to be chosen at the compilation time (when configuring the sources).
  25. This page explains the background to the Configuration Backend and how
  26. it is implemented. It is aimed at people who want to develop and
  27. maintain their own backends.
  28. @section configBackendMotivation Motivation for Different Backends
  29. BIND10 (the project under which the first stages of Kea were developed)
  30. used to maintain an extensive framework that was responsible for the
  31. configuration of components. After BIND10 was cancelled, two projects
  32. were created: <a href="http://kea.isc.org">Kea</a> (focused on DHCP)
  33. and <a href="http://www.bundy-dns.de">Bundy</a> (aimed at DNS). The
  34. Kea team decided to remove the BIND10 framework, while the Bundy team
  35. decided to keep it. However, even though the Kea team is focused on a
  36. backend that reads a JSON configuration file from disk, it decided to
  37. make it easy for others to use different backends.
  38. While ISC currently (May 2014) plans to maintain only one configuration backend
  39. (a JSON file read from disk), there may be other organizations (e.g.
  40. the Bundy project community) that will maintain other backends. It is quite
  41. possible that additional backends (e.g. using LDAP or XML) will be
  42. developed and maintained by other organizations.
  43. @section configBackendAdding How to Add a New Configuration Backend
  44. The configuration backend concept was designed to make external (i.e. not
  45. maintained by ISC) configurations backends easy to maintain. In particular,
  46. the set of patches vs. separate files required strongly favors separate
  47. files. This is important if an external organization wants to develop its
  48. own configuration backend and then needs to apply it every ISC release
  49. of Kea.
  50. The following steps are needed to add new configuration backend (it is assumed
  51. that the modified component is DHCPv4. Similar approach applies to other
  52. components):
  53. -# Modify AC_ARG_WITH(kea-config,...) macro in configure.ac
  54. -# Add your own AM_CONDITIONAL(CONFIG_BACKEND_FOO, ...) macro in configure.ac
  55. -# Add your own conditional AC_DEFINE(CONFIG_BACKEND_FOO, ...) invocation
  56. in configure.ac
  57. -# Modify sanity check in configure.ac to allow your configuration backend name.
  58. -# Modify src/bin/dhcp4/Makefile.am to include your own backend
  59. implementation (e.g. foo_controller.cc).
  60. -# Write your own implementation of isc::dhcp::ControlledDhcpv4Srv::init(),
  61. isc::dhcp::ControlledDhcpv4Srv::init() and isc::dhcp::ControlledDhcpv4Srv::cleanup().
  62. Optionally you can also:
  63. -# Modify src/bin/dhcp4/tests/Makefile.am to include foo_controller_unittest.cc if
  64. selected backend is foo.
  65. -# Implement unit-tests for your backend in foo_controller_unittest.cc file.
  66. @section configBackendJSONDesign The JSON Configuration Backend
  67. The following are some considerations that shaped the design of the configuration
  68. backend framework.
  69. -# A new parameter called --with-kea-config will be implemented in the
  70. configure script. It will allow the selection at compilation time of how the
  71. servers will be configured. For the next 2-3 months (until around June 2014),
  72. there will be two values: JSON (read from file) and BUNDY (use the BUNDY/BIND10 framework).
  73. Once the file based configuration is implemented and the Kea team is ready to switch
  74. (i.e. enough confidence, Forge tests updated for new configuration
  75. mechanism), the Bundy/BIND10 framework will be removed from the Kea repository. Other projects
  76. (e.g. Bundy) who want to maintain it, are advised to just revert the single
  77. commit that will bring the Bundy framework back to their repositories.
  78. This switchable backend concept is quite simple. There are just different
  79. implementations of ControlledXSrv class, so it is a matter of compiling/linking
  80. one file or another. Hence it is easy to remove the old backend (and for
  81. Bundy to keep it if they desire so). It is also easy for other
  82. organizations to add and maintain their own backends (e.g. LDAP).
  83. -# Each backend must use the common code for configuration and command
  84. processing callbacks. They all assume that JSON formatted parameters are sent
  85. and they are expected to return well formatted JSON responses. The exact
  86. format of configuration and commands is module specific.
  87. -# After Kea 0.9 is released, a form of secure socket will be implemented
  88. through which commands can be sent. Whatever the design, it will allow the
  89. sending of configurations and commands in JSON format and the receiving of
  90. responses. Once that is done, Kea will have the same capability the BIND10
  91. framework to send additional parameters. One obvious use case will be to send
  92. a new configuration file name as the parameter for "reload".
  93. -# A command handler needs to be added for reading the configuration from a
  94. file. Its main responsibility is to load the configuration and process
  95. it. The JSON backend must call that handler when starting up the server.
  96. -# Extend the existing JSON parser. The current JSON parser in @ref
  97. isc::data::Element::fromJSON() needs to be extended to allow optional
  98. preprocessing. For now that capability will simply remove whole-line
  99. comments staring with the hash character, but it is expected to grow over
  100. time (in-line comments and file inclusions are the obvious envisaged
  101. additions).
  102. -# Implement a common base class for the Kea4, Kea6, and D2 servers. Some
  103. operations will be common for all three components: logger initialization,
  104. handling and, at some future point, control socket. This calls for a small
  105. base class that @ref isc::dhcp::Dhcpv4Srv "Dhcpv4Srv", @ref
  106. isc::dhcp::Dhcpv6Srv "Dhcpv6Srv" and the @ref isc::d2::D2Controller
  107. "D2Controller" classes can use. It is expected that the base class (@ref
  108. isc::dhcp::Daemon) will be a small one but will grow over time as the code is
  109. unified.
  110. -# A way is needed to initialize stand-alone logging (i.e. each
  111. Kea component will initialize it on its own).
  112. -# The current format of the BIND10 configuration file, b10-config.db will be
  113. retained as the configuration file format. This is slight change
  114. from the BIND10 days, as then a subset of the configuration was received by
  115. the daemon processes. To take a specific example, the following is how
  116. b10-config.db looks today:
  117. @code
  118. {
  119. "Init": { ... }
  120. "Dhcp4": {
  121. "subnet4" { subnet definitions here },
  122. "option-data" { option data here },
  123. "interfaces": [ "eth0" ],
  124. ...
  125. },
  126. "Dhcp6": {
  127. "subnet6" { subnet definitions here },
  128. "option-data" { option data here },
  129. "interfaces": [ "eth0" ],
  130. ...
  131. },
  132. "Logging": {
  133. "Loggers": [{"name": *, "severity": "DEBUG" }]
  134. }
  135. }
  136. @endcode
  137. <br/>
  138. The Kea components used to receive only relevant parts of it (e.g. Kea4
  139. received config that contained content of the Dhcp4 element). Now they
  140. will receive all of it. The modification in the code to handle this
  141. is really minor: just iterate over the top level elements and pick the appropriate
  142. tree (or get the element by name). Also, that approach makes the logging
  143. initialization code very easy to share among Kea4, Kea6 and D2.
  144. -# The .spec files used in BIND 10 by the control program to validate commands
  145. will be retained. They will be kept and maintained even though no use of
  146. them is planned. At some future time syntax validation may be implemented,
  147. although it is out of scope for Kea 0.9 (and probably
  148. for 1.0 as it is pretty big task).
  149. -# Addition of a shell script to start/stop Kea4,Kea6 and D2. There will be a script that will
  150. start, stop and reconfigure the daemons. Its only
  151. job will be to pass the configuration file to each daemon and remember its PID file, so
  152. that sending signals will be be possible (for configuration reload or shutdown). Optionally,
  153. it could also print out a status based on PID, but that may be tricky to
  154. implement in a portable way. The minimum set of commands will be:
  155. -# Start the processes
  156. - eventually based on configuration, initially start them all
  157. - it could launch a nanny script which restarts them on a crash (past 0.9)
  158. -# Prompt the processes to reload configuration
  159. - for now it will be a matter of sending singal to the right process
  160. - this could also decide if D2 should still be running or not, and react accordingly (post 0.9)
  161. -# Stop the processes in an orderly fashion
  162. -# Perhaps return status of each process
  163. */