Kea 2.7.4
|
Kea is capable of sending dynamic DNS updates to DNS Servers, based on lease changes made by Kea's DHCP servers. When DDNS updating is enabled, the DHCP servers generate requests to update DNS as they make lease changes. These requests, implemented by isc::dhcp_ddns::NameChangeRequest (NCR), are sent to a separate process, informally known as D2. D2 processes these requests by carrying out DDNS conversations with the appropriate DNS servers such that they update the DNS data.
The design documentation for D2 can be found here: D2 Design.
The implementation is split in several libraries which can be used separately (linked only when required):
This document contains several UML diagrams, and a few conventions used within these diagrams are worth noting:
D2's core application classes are DDNS-specific derivations of the CPL as show in the diagram below:
D2Process
(see src/bin/d2/d2_controller.h).D2CfgContext
(see src/lib/d2srv/d2_cfg_mgr.h).D2's configuration management uses the same underlying mechanisms as Kea's DHCP servers. It's configuration information is organized into a hierarchical data model which is mirrored in the implementation by a hierarchy of parser classes and the runtime classes they instantiate.
D2's data model is organized as follows:
The runtime classes that embody this model are shown in the following diagram:
DCfgContextBase
. It houses the "global" configuration for an instance of D2 (see src/lib/d2srv/d2_cfg_mgr.h).The parsing classes, as one would expect, parallel the runtime classes quite closely. The parsers are named for the runtime class they instantiate and are either designed to parse a single occurrence of that class or list of that class. The parser classes are shown in the diagram below:
For more details on the parsers see src/lib/d2srv/d2_config.h.
The underlying common libraries for configuration parsing support configuration input in JSON format, that complies with a fixed set of generic constructs that may be described by a spec file (also JSON).
D2 is designed to receive requests from Kea's DHCP servers, asynchronously and store them in queue to be processed. The classes responsible for this are shown in the diagram below:
D2Process
, it listens for NameChangeRequests
and queues them for processing. It also provides services for adding, finding, and removing queue entries. It owns the interface used to receive requests and thus shields the remainder of D2 from any specific knowledge or interaction with this interface (see src/bin/d2/d2_queue_mgr.h).D2QueueMgr is state-driven, albeit with a very simple state model. The states are defined by isc::d2::D2QueueMgr::State (see src/bin/d2/d2_queue_mgr.h).
The DDNS protocol can lead to a multiple step conversation between the updater and the DNS server to update entries for a single client. In addition, NameChangeRequests
can request changes be made for both forward and reverse DNS. In order to carry out the appropriate conversation, D2 wraps each request in a stateful transaction.
Working such transactions serially can be inefficient, especially if those requests involve different DNS servers. Therefore, D2 has been designed to work on more than one transaction at a time by creating and managing a list of transactions.
The classes which are responsible for carrying out this work are shown in the following diagram:
D2Process
, orchestrates the fulfillment of each request by managing the execution of its transaction. Its high level method isc::d2::D2UpdateMgr::sweep() is meant to be called whenever IO events occur (see src/bin/d2/d2_update_mgr.h). The following steps are performed each time the method is called:Now that all of the primary components have been introduced it is worth while discussing D2's main event loop. As mentioned earlier D2 is constructed around the CPL which is designed to be driven by asynchronous IO processed by a common IO service thread (isc::asiolink::io_service). Any IO that needs to be performed by the application thread uses this service to do so. This organizes the IO event processing into a single event loop centered around the service. (This does not preclude spinning off worker threads to conduct other tasks, with their own io_service instances). D2's main event loop, implemented in isc::d2::D2Process::run() may be paraphrased as follows:
There are two types of NameChangeRequests:
an "Add" that is issued when DNS entries need to be added for new or updated lease, and a "Remove" that is issued when DNS entries need to be removed for obsolete or expired lease. The DDNS protocol dictates the steps that should be followed in both cases.
D2's design addresses this by calling for two types of transactions: one for adding entries and one for removing them, each with their own state model. The transaction classes are shown in the following diagram:
NameChangeRequest
to add entries (see src/bin/d2/nc_add.h).NameChangeRequest
to remove entries (see src/bin/d2/nc_remove.h).The state models for these two transactions implement DDNS with conflict resolution as described in RFC 4703.
The state model for isc::d2::NameAddTransaction is diagrammed below:
The state model for isc::d2::NameRemoveTransaction is depicted next:
D2 implements a abstract state-machine through a light weight set of classes. At construction, the model's dictionary of events and states is initialized. This allows, the deriving class the ability to bind a method of its choosing to each state as that state's handler. Each handler contains the knowledge of how to respond to the "posted" event and including posting other events and transitioning to other states.
Executing the model consists of beginning at the current state with the posted event and continuing until the model needs to wait for an IO-based event or it has reached the end of the state model. These classes will likely move to a common library.
The following sequence chart depicts the typically sequence of events that occur when D2UpdateMgr creates and starts executing a transaction: