config-backend.dox 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. // Copyright (C) 2014, 2015 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. /**
  7. @page configBackend Kea Configuration Backends
  8. @section configBackendIntro Introduction
  9. Kea is a flexible DHCP protocol engine. It offers a selection of lease database
  10. backends, extensibility via the hooks API and the definition of custom options.
  11. Depending on the environment, one lease database backend may be better than
  12. other. Similarly, because the best way of configuring the server can depend on
  13. the environment, Kea provides different ways of obtaining configuration
  14. information, through the Configuration Backend. Since the means by which
  15. configuration information is received cannot be part of the configuration itself, it
  16. has to be chosen at the compilation time (when configuring the sources).
  17. This page explains the background to the Configuration Backend and how
  18. it is implemented. It is aimed at people who want to develop and
  19. maintain their own backends.
  20. @section configBackendMotivation Motivation for Different Backends
  21. BIND10 (the project under which the first stages of Kea were developed)
  22. used to maintain an extensive framework that was responsible for the
  23. configuration of components. After BIND10 was cancelled, two projects
  24. were created: <a href="http://kea.isc.org">Kea</a> (focused on DHCP)
  25. and <a href="http://www.bundy-dns.de">Bundy</a> (aimed at DNS). The
  26. Kea team decided to remove the BIND10 framework, while the Bundy team
  27. decided to keep it. However, even though the Kea team is focused on a
  28. backend that reads a JSON configuration file from disk, it decided to
  29. make it easy for others to use different backends.
  30. While ISC currently (May 2015) maintains only one configuration backend
  31. (a JSON file read from disk), it is quite possible that additional backends
  32. (e.g. using LDAP or XML) will be developed in the future by ISC or other
  33. organizations.
  34. @section configBackendAdding How to Add a New Configuration Backend
  35. The configuration backend concept was designed to make external (i.e. not
  36. maintained by ISC) configurations backends easy to maintain. In particular,
  37. the set of patches vs. separate files required strongly favors separate
  38. files. This is important if an external organization wants to develop its
  39. own configuration backend and then needs to apply it to every ISC release
  40. of Kea.
  41. The following steps are needed to add new configuration backend (it is assumed
  42. that the modified component is DHCPv4. Similar approach applies to the other
  43. components: DHCPv6 or DHCP-DDNS):
  44. -# Write your own implementation of isc::dhcp::ControlledDhcpv4Srv::init(),
  45. isc::dhcp::ControlledDhcpv4Srv::init() and isc::dhcp::ControlledDhcpv4Srv::cleanup()
  46. and put it in the src/bin/dhcp4 directory (e.g. as foo_controller.cc).
  47. -# Modify src/bin/dhcp4/Makefile.am to include your file (e.g. foo_controller.cc) in
  48. the build.
  49. -# Modify the AC_ARG_WITH(kea-config,...) macro in configure.ac to include an
  50. entry for your configuration backend.
  51. -# Add your own AM_CONDITIONAL(CONFIG_BACKEND_FOO, ...) and
  52. AC_DEFINE(CONFIG_BACKEND_FOO, ...) macros to configure.ac (following the
  53. above-mentioned AC_ARG_WITH macro) to set the C++ macro for your backend.
  54. -# Modify the sanity check in configure.ac to allow your configuration backend name.
  55. Optionally you can also:
  56. -# Implement unit tests for your backend in the src/bin/dhcp4/tests directory.
  57. -# Modify src/bin/dhcp4/tests/Makefile.am to include the file(s) containing the
  58. unit tests.
  59. @section configBackendJSONDesign The JSON Configuration Backend
  60. The following are some details of the JSON backend framework.
  61. -# A switch called --with-kea-config has been implemented in the
  62. configure script. It allows the selection at compilation time of how the
  63. servers will be configured. Currently (June 2014),
  64. there is one value: JSON (read configuration from a JSON file)
  65. Although the Bundy/BIND10 framework has been removed from Kea, the
  66. configuration choice is available for other projects (e.g. Bundy)
  67. that want to include an implementation of Kea using that backend.
  68. Such projects are advised to import the Kea modules and compile
  69. them with the Bundy backend enabled.<br/><br/>
  70. This switchable backend concept is quite simple. There are different
  71. implementations of ControlledXSrv class, each backend keeping its code
  72. in a separate file. It is a matter of compiling/linking
  73. one file or another. Hence it is easy to remove the old backend (and for
  74. external projects, like Bundy, to keep it if they desire). It is also easy
  75. for other organizations to add and maintain their own backends (e.g. LDAP).<br/><br/>
  76. -# Each backend uses the common code for configuration and command
  77. processing callbacks. They all assume that JSON formatted parameters are sent
  78. and they are expected to return well formatted JSON responses. The exact
  79. format of configuration and commands is module-specific.<br/><br/>
  80. -# A command handler handles the reading the configuration from a
  81. file. Its main responsibility is to load the configuration and process
  82. it. The JSON backend must call that handler when starting up the server.
  83. This is implemented in configure() in the kea_controller.cc files
  84. in src/bin/dhcp4 and src/bin/dhcp6 directories.<br/><br/>
  85. -# The current JSON parser in @ref
  86. isc::data::Element::fromJSON() has been extended to allow optional
  87. preprocessing. For now, that capability simply removes whole-line
  88. comments starting with the hash character, but it is expected to grow over
  89. time (in-line comments and file inclusions are the obvious envisaged
  90. additions). This is implemented in @ref isc::data::Element::fromJSONFile.<br/><br/>
  91. -# The current format of the BIND10 configuration file (BIND 10 stored its
  92. configuration in (installation directory) /var/bind10/b10-config.db) has been
  93. retained as the configuration file format. Its actual naming is now arbitrary
  94. and left up to the user (it is passed as a parameter to the -c command line
  95. option). From the implementation perspective, this is slight change
  96. from the BIND10 days, as back then a subset of the configuration was received by
  97. the daemon processes. Nowadays the whole configuration is passed. To take a
  98. specific example, the following is how b10-config.db looks today:
  99. @code
  100. {
  101. "Init": { ... }
  102. "Dhcp4": {
  103. "subnet4" { subnet definitions here },
  104. "option-data" { option data here },
  105. "interfaces": [ "eth0" ],
  106. ...
  107. },
  108. "Dhcp6": {
  109. "subnet6" { subnet definitions here },
  110. "option-data" { option data here },
  111. "interfaces": [ "eth0" ],
  112. ...
  113. },
  114. "Logging": {
  115. "Loggers": [{"name": *, "severity": "DEBUG" }]
  116. }
  117. }
  118. @endcode
  119. The Kea components used to receive only relevant parts of it (e.g. Kea4
  120. received configuration data that only contained the content of the Dhcp4 element).
  121. Now each component receives all of it: the code
  122. iterates over the top level elements and picks the appropriate
  123. tree (or get the element by name). That approach makes the common configuration
  124. (such as the logging initialization code) very easy to share among Kea4, Kea6 and
  125. DHCP-DDNS.<br/><br/>
  126. -# The .spec files used in BIND 10 by the control program to validate commands
  127. have been retained. They will be kept and maintained even though no use of
  128. them is currently planned. At some future time syntax validation may be implemented,
  129. although it is out of scope for Kea 0.9 (and probably
  130. for 1.0 as well, as it is a pretty big task).<br/><br/>
  131. -# A shell script has been added (as src/bin/keactrl/keactrl) to
  132. start, stop and reconfigure the daemons. Its only
  133. job is to pass the configuration file to each daemon and remember its PID file, so
  134. that sending signals is possible (for configuration reload or shutdown). It is also
  135. able to print out a status.
  136. Future changes planned for this part of the code are:
  137. -# Implement a common base class for the Kea4, Kea6, and D2 servers. Some
  138. operations will be common for all three components: logger initialization,
  139. handling and, at some future point, control socket. This calls for a small
  140. base class that @ref isc::dhcp::Dhcpv4Srv "Dhcpv4Srv", @ref
  141. isc::dhcp::Dhcpv6Srv "Dhcpv6Srv" and the @ref isc::d2::D2Controller
  142. "D2Controller" classes can use. It is expected that the base class (@ref
  143. isc::dhcp::Daemon) will be a small one but will grow over time as the code is
  144. unified. This has been implemented in @ref isc::dhcp::Daemon.<br/><br/>
  145. -# After Kea 0.9 is released, a form of secure socket will be implemented
  146. through which commands can be sent. Whatever the design, it will allow the
  147. sending of configurations and commands in JSON format and the receiving of
  148. responses. Once that is done, Kea will have the same capability the BIND10
  149. framework to send additional parameters. One obvious use case will be to send
  150. a new configuration file name as the parameter for "reload".
  151. */