config-backend.dox 9.68 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

/**

17
 @page configBackend Kea Configuration Backends
18

19
@section configBackendIntro Introduction
20 21

Kea is a flexible DHCP protocol engine. It offers a selection of lease database
22
backends, extensibility via the hooks API and the definition of custom options.
23
Depending on the environment, one lease database backend may be better than
24 25 26 27 28 29 30 31 32 33 34 35
other. Similarly, because the best way of configuring the server can depend on
the environment, Kea provides different ways of obtaining configuration
information, through the Configuration Backend. Since the means by which
configuration information is received cannot be part of the configuration itself, it
has to be chosen at the compilation time (when configuring the sources).

This page explains the background to the Configuration Backend and how
it is implemented. It is aimed at people who want to develop and
maintain their own backends.

@section configBackendMotivation Motivation for Different Backends

36
BIND10 (the project under which the first stages of Kea were developed)
37 38 39 40 41 42 43 44
used to maintain an extensive framework that was responsible for the
configuration of components.  After BIND10 was cancelled, two projects
were created: <a href="http://kea.isc.org">Kea</a> (focused on DHCP)
and <a href="http://www.bundy-dns.de">Bundy</a> (aimed at DNS). The
Kea team decided to remove the BIND10 framework, while the Bundy team
decided to keep it. However, even though the Kea team is focused on a
backend that reads a JSON configuration file from disk, it decided to
make it easy for others to use different backends.
45 46

While ISC currently (May 2014) plans to maintain only one configuration backend
47 48 49
(a JSON file read from disk), there may be other organizations (e.g.
the Bundy project community) that will maintain other backends. It is quite
possible that additional backends (e.g. using LDAP or XML) will be
50 51
developed and maintained by other organizations.

52 53
@section configBackendAdding How to Add a New Configuration Backend

54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
The configuration backend concept was designed to make external (i.e. not
maintained by ISC) configurations backends easy to maintain. In particular,
the set of patches vs. separate files required strongly favors separate
files. This is important if an external organization wants to develop its
own configuration backend and then needs to apply it every ISC release
of Kea.

The following steps are needed to add new configuration backend (it is assumed
that the modified component is DHCPv4. Similar approach applies to other
components):

-# Modify AC_ARG_WITH(kea-config,...) macro in configure.ac
-# Add your own AM_CONDITIONAL(CONFIG_BACKEND_FOO, ...) macro in configure.ac
-# Add your own conditional AC_DEFINE(CONFIG_BACKEND_FOO, ...) invocation
   in configure.ac
-# Modify sanity check in configure.ac to allow your configuration backend name.
-# Modify src/bin/dhcp4/Makefile.am to include your own backend
   implementation (e.g. foo_controller.cc).
-# Write your own implementation of isc::dhcp::ControlledDhcpv4Srv::init(),
   isc::dhcp::ControlledDhcpv4Srv::init() and isc::dhcp::ControlledDhcpv4Srv::cleanup().

Optionally you can also:

-# Modify src/bin/dhcp4/tests/Makefile.am to include foo_controller_unittest.cc if
   selected backend is foo.
-# Implement unit-tests for your backend in foo_controller_unittest.cc file.
80

81
@section configBackendJSONDesign The JSON Configuration Backend
82

83 84
The following are some considerations that shaped the design of the configuration
backend framework.
85

86 87
-# A new parameter called --with-kea-config will be implemented in the
   configure script. It will allow the selection at compilation time of how the
88
   servers will be configured. For the next 2-3 months (until around June 2014),
89
   there will be two values: JSON (read from file) and BUNDY (use the BUNDY/BIND10 framework).
90
   Once the file based configuration is implemented and the Kea team is ready to switch
91
   (i.e. enough confidence, Forge tests updated for new configuration
92
   mechanism), the Bundy/BIND10 framework will be removed from the Kea repository. Other projects
93
   (e.g. Bundy) who want to maintain it, are advised to just revert the single
94
   commit that will bring the Bundy framework back to their repositories.
95 96 97 98
   This switchable backend concept is quite simple. There are just different
   implementations of ControlledXSrv class, so it is a matter of compiling/linking
   one file or another. Hence it is easy to remove the old backend (and for
   Bundy to keep it if they desire so). It is also easy for other
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
   organizations to add and maintain their own backends (e.g. LDAP).

-# Each backend must use the common code for configuration and command
   processing callbacks. They all assume that JSON formatted parameters are sent
   and they are expected to return well formatted JSON responses. The exact
   format of configuration and commands is module specific.

-# After Kea 0.9 is released, a form of secure socket will be implemented
   through which commands can be sent. Whatever the design, it will allow the
   sending of configurations and commands in JSON format and the receiving of
   responses.  Once that is done, Kea will have the same capability the BIND10
   framework to send additional parameters. One obvious use case will be to send
   a new configuration file name as the parameter for "reload".

-# A command handler needs to be added for reading the configuration from a
   file. Its main responsibility is to load the configuration and process
   it. The JSON backend must call that handler when starting up the server.

-# Extend the existing JSON parser. The current JSON parser in @ref
   isc::data::Element::fromJSON() needs to be extended to allow optional
   preprocessing.  For now that capability will simply remove whole-line
   comments staring with the hash character, but it is expected to grow over
   time (in-line comments and file inclusions are the obvious envisaged
   additions).

-# Implement a common base class for the Kea4, Kea6, and D2 servers. Some
   operations will be common for all three components: logger initialization,
   handling and, at some future point, control socket. This calls for a small
   base class that @ref isc::dhcp::Dhcpv4Srv "Dhcpv4Srv", @ref
   isc::dhcp::Dhcpv6Srv "Dhcpv6Srv" and the @ref isc::d2::D2Controller
   "D2Controller" classes can use.  It is expected that the base class (@ref
   isc::dhcp::Daemon) will be a small one but will grow over time as the code is
   unified.

133
-# A way is needed to initialize stand-alone logging (i.e. each
134 135
   Kea component will initialize it on its own).

136 137 138
-# The current format of the BIND10 configuration file, b10-config.db will be
   retained as the configuration file format.  This is slight change
   from the BIND10 days, as then a subset of the configuration was received by
139 140
   the daemon processes. To take a specific example, the following is how
   b10-config.db looks today:
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
   @code
   {
     "Init": { ... }
     "Dhcp4": {
       "subnet4" { subnet definitions here },
       "option-data" { option data here },
       "interfaces": [ "eth0" ],
       ...
    },
     "Dhcp6": {
       "subnet6" { subnet definitions here },
       "option-data" { option data here },
       "interfaces": [ "eth0" ],
       ...
     },
     "Logging": {
       "Loggers": [{"name": *, "severity": "DEBUG" }]
      }
   }
   @endcode
161 162 163 164 165 166
   <br/>
   The Kea components used to receive only relevant parts of it (e.g. Kea4
   received config that contained content of the Dhcp4 element). Now they
   will receive all of it. The modification in the code to handle this
   is really minor: just iterate over the top level elements and pick the appropriate
   tree (or get the element by name). Also, that approach makes the logging
167 168
   initialization code very easy to share among Kea4, Kea6 and D2.

169 170 171 172
-# The .spec files used in BIND 10 by the control program to validate commands
   will be retained. They will be kept and maintained even though no use of
   them is planned. At some future time syntax validation may be implemented,
   although it is out of scope for Kea 0.9 (and probably
173 174
   for 1.0 as it is pretty big task).

175 176 177 178
-# Addition of a shell script to start/stop Kea4,Kea6 and D2. There will be a script that will
   start, stop and reconfigure the daemons. Its only
   job will be to pass the configuration file to each daemon and remember its PID file, so
   that sending signals will be be possible (for configuration reload or shutdown). Optionally,
179
   it could also print out a status based on PID, but that may be tricky to
180
   implement in a portable way. The minimum set of commands will be:
181
   -# Start the processes
182
      - eventually based on configuration, initially start them all
183 184 185
      - it could launch a nanny script which restarts them on a crash (past 0.9)
   -# Prompt the processes to reload configuration
      - for now it will be a matter of sending singal to the right process
186
      - this could also decide if D2 should still be running or not, and react accordingly (post 0.9)
187 188
   -# Stop the processes in an orderly fashion
   -# Perhaps return status of each process
189
*/