config-backend.dox 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 to 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 the other
  52. components: DHCPv6 or DHCP-DDNS):
  53. -# Write your own implementation of isc::dhcp::ControlledDhcpv4Srv::init(),
  54. isc::dhcp::ControlledDhcpv4Srv::init() and isc::dhcp::ControlledDhcpv4Srv::cleanup()
  55. and put it in the src/bin/dhcp4 directory (e.g. as foo_controller.cc).
  56. -# Modify src/bin/dhcp4/Makefile.am to include your file (e.g. foo_controller.cc) in
  57. the build.
  58. -# Modify the AC_ARG_WITH(kea-config,...) macro in configure.ac to include an
  59. entry for your configuration backend.
  60. -# Add your own AM_CONDITIONAL(CONFIG_BACKEND_FOO, ...) and
  61. AC_DEFINE(CONFIG_BACKEND_FOO, ...) macros to configure.ac (following the
  62. above-mentioned AC_ARG_WITH macro) to set the C++ macro for your backend.
  63. -# Modify the sanity check in configure.ac to allow your configuration backend name.
  64. Optionally you can also:
  65. -# Implement unit tests for your backend in the src/bin/dhcp4/tests directory.
  66. -# Modify src/bin/dhcp4/tests/Makefile.am to include the file(s) containing the
  67. unit tests.
  68. @section configBackendJSONDesign The JSON Configuration Backend
  69. The following are some details of the JSON backend framework.
  70. -# A switch called --with-kea-config has been implemented in the
  71. configure script. It allows the selection at compilation time of how the
  72. servers will be configured. Currently (June 2014),
  73. there are two values: JSON (the default, read configuration from a JSON file)
  74. and BUNDY (use the BUNDY/BIND10 framework). Although the Bundy/BIND10
  75. framework has been removed from Kea, the configuration choice
  76. is available for other projects (e.g. Bundy) that want to include an
  77. implementation of Kea using that backend. Such projects are advised to
  78. import the Kea modules and compile them with the Bundy backend
  79. enabled.<br/><br/>
  80. This switchable backend concept is quite simple. There are different
  81. implementations of ControlledXSrv class, each backend keeping its code
  82. in a separate file. It is a matter of compiling/linking
  83. one file or another. Hence it is easy to remove the old backend (and for
  84. external projects, like Bundy, to keep it if they desire). It is also easy
  85. for other organizations to add and maintain their own backends (e.g. LDAP).<br/><br/>
  86. -# Each backend uses the common code for configuration and command
  87. processing callbacks. They all assume that JSON formatted parameters are sent
  88. and they are expected to return well formatted JSON responses. The exact
  89. format of configuration and commands is module-specific.<br/><br/>
  90. -# A command handler handles the reading the configuration from a
  91. file. Its main responsibility is to load the configuration and process
  92. it. The JSON backend must call that handler when starting up the server.
  93. This is implemented in configure() in the kea_controller.cc files
  94. in src/bin/dhcp4 and src/bin/dhcp6 directories.<br/><br/>
  95. -# The current JSON parser in @ref
  96. isc::data::Element::fromJSON() has been extended to allow optional
  97. preprocessing. For now, that capability simply removes whole-line
  98. comments starting with the hash character, but it is expected to grow over
  99. time (in-line comments and file inclusions are the obvious envisaged
  100. additions). This is implemented in @ref isc::data::Element::fromJSONFile.<br/><br/>
  101. -# The current format of the BIND10 configuration file (BIND 10 stored its
  102. configuration in (installation directory) /var/bind10/b10-config.db) has been
  103. retained as the configuration file format. Its actual naming is now arbitrary
  104. and left up to the user (it is passed as a parameter to the -c command line
  105. option). From the implementation perspective, this is slight change
  106. from the BIND10 days, as back then a subset of the configuration was received by
  107. the daemon processes. Nowadays the whole configuration is pased. To take a
  108. specific example, the following is how b10-config.db looks today:
  109. @code
  110. {
  111. "Init": { ... }
  112. "Dhcp4": {
  113. "subnet4" { subnet definitions here },
  114. "option-data" { option data here },
  115. "interfaces": [ "eth0" ],
  116. ...
  117. },
  118. "Dhcp6": {
  119. "subnet6" { subnet definitions here },
  120. "option-data" { option data here },
  121. "interfaces": [ "eth0" ],
  122. ...
  123. },
  124. "Logging": {
  125. "Loggers": [{"name": *, "severity": "DEBUG" }]
  126. }
  127. }
  128. @endcode
  129. The Kea components used to receive only relevant parts of it (e.g. Kea4
  130. received configuration data that only contained the content of the Dhcp4 element).
  131. Now each component receives all of it: the code
  132. iterates over the top level elements and picks the appropriate
  133. tree (or get the element by name). That approach makes the common configuration
  134. (such as the logging initialization code) very easy to share among Kea4, Kea6 and
  135. DHCP-DDNS.<br/><br/>
  136. -# The .spec files used in BIND 10 by the control program to validate commands
  137. have been retained. They will be kept and maintained even though no use of
  138. them is currently planned. At some future time syntax validation may be implemented,
  139. although it is out of scope for Kea 0.9 (and probably
  140. for 1.0 as well, as it is a pretty big task).<br/><br/>
  141. -# A shell script has been added (as src/bin/keactrl/keactrl) to
  142. start, stop and reconfigure the daemons. Its only
  143. job is to pass the configuration file to each daemon and remember its PID file, so
  144. that sending signals is possible (for configuration reload or shutdown). It is also
  145. able to print out a status.
  146. Future changes planned for this part of the code are:
  147. -# Implement a common base class for the Kea4, Kea6, and D2 servers. Some
  148. operations will be common for all three components: logger initialization,
  149. handling and, at some future point, control socket. This calls for a small
  150. base class that @ref isc::dhcp::Dhcpv4Srv "Dhcpv4Srv", @ref
  151. isc::dhcp::Dhcpv6Srv "Dhcpv6Srv" and the @ref isc::d2::D2Controller
  152. "D2Controller" classes can use. It is expected that the base class (@ref
  153. isc::dhcp::Daemon) will be a small one but will grow over time as the code is
  154. unified. This has been implemented in @ref isc::dhcp::Daemon.<br/><br/>
  155. -# After Kea 0.9 is released, a form of secure socket will be implemented
  156. through which commands can be sent. Whatever the design, it will allow the
  157. sending of configurations and commands in JSON format and the receiving of
  158. responses. Once that is done, Kea will have the same capability the BIND10
  159. framework to send additional parameters. One obvious use case will be to send
  160. a new configuration file name as the parameter for "reload".
  161. */