Kea 2.7.5
|
In many cases it is useful to manage certain aspects of the DHCP servers while they are running. In Kea, this may be done via the Control Channel. Control Channel allows an external entity (e.g. a tool run by a sysadmin or a script) to issue commands to the server which can influence its behavior or retrieve information from it. Several notable examples envisioned are: reconfiguration, statistics retrieval and manipulation, and shutdown.
Communication over Control Channel is conducted using JSON structures. The supported communication channel is UNIX stream and HTTP/HTTPS sockets.
If configured, Kea will open a socket and will listen for any incoming connections. A process connecting to this socket is expected to send JSON commands structured as follows:
The server will process the incoming command and then send a response of the form:
Here are two examples of how to access the UNIX Control Channel:
Control Channel is implemented in isc::config::CommandMgr. It is a singleton class that allows registration of callbacks that handle specific commands. It internally supports a single command: list-commands
that returns a list of supported commands. This component is expected to be shared among all daemons.
There are 3 main methods that are expected to be used by developers:
Kea servers use CommandMgr
to register handlers for various commands they support natively. However, it is possible extend a set of supported commands using hooks framework. See Using Callouts as Command handlers how to implement support for your own control commands in Kea.
UNIX Control Channel is implemented in isc::config::UnixCommandMgr. It is a singleton class providing two methods for managing control sockets. They are not expected to be used directly.
The isc::config::UnixCommandMgr is implemented using boost ASIO and uses asynchronous calls to accept new connections and receive commands from the controlling clients. ASIO uses IO service object to run asynchronous calls. Thus, before the server can use the isc::config::UnixCommandMgr it must provide it with a common instance of the isc::asiolink::IOService object using isc::config::UnixCommandMgr::setIOService. The server's main loop must contain calls to isc::asiolink::IOService::run or isc::asiolink::IOService::poll or their variants to invoke Command Manager's handlers as required for processing control requests.
The control channel utilities are not thread safe but they are used only by the main thread so in most cases it does not matter. For instance the assumption that only at most one command can be executed at a given time can be done. Of course this has its limit: when the command changes the configuration or is incompatible with a simultaneous packet processing the multi-threading mode must be checked and service threads stopped.