Coverage Report

Created: 2026-02-14 07:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/kea/src/lib/config/unix_command_mgr.h
Line
Count
Source
1
// Copyright (C) 2015-2025 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
#ifndef UNIX_COMMAND_MGR_H
8
#define UNIX_COMMAND_MGR_H
9
10
#include <asiolink/io_service.h>
11
#include <cc/data.h>
12
#include <config/unix_command_config.h>
13
14
#include <exceptions/exceptions.h>
15
#include <boost/noncopyable.hpp>
16
#include <boost/shared_ptr.hpp>
17
18
namespace isc {
19
namespace config {
20
21
/// @brief An exception indicating a problem with socket operation
22
class SocketError : public Exception {
23
public:
24
    SocketError(const char* file, size_t line, const char* what) :
25
0
        isc::Exception(file, line, what) { }
26
};
27
28
class UnixCommandMgrImpl;
29
30
/// @brief Unix Commands Manager implementation for the Kea servers.
31
///
32
/// This class receives and responds to commands over unix domain sockets.
33
class UnixCommandMgr : public boost::noncopyable {
34
public:
35
36
    /// @brief UnixCommandMgr is a singleton class. This method
37
    /// returns reference to its sole instance.
38
    ///
39
    /// @return the only existing instance of the manager.
40
    static UnixCommandMgr& instance();
41
42
    /// @brief Sets IO service to be used by the unix command manager.
43
    ///
44
    /// The server should use this method to provide the Unix Command
45
    /// Manager with the common IO service used by the server.
46
    /// @param io_service Pointer to the IO service.
47
    void setIOService(const asiolink::IOServicePtr& io_service);
48
49
    /// @brief Override default connection timeout.
50
    ///
51
    /// @param timeout New connection timeout in milliseconds.
52
    void setConnectionTimeout(const long timeout);
53
54
    /// @brief Use external sockets flag.
55
    ///
56
    /// Add sockets as external sockets of the interface manager
57
    /// so available I/O on them makes a waiting select to return.
58
    ///
59
    /// @param use_external True (default) add external sockets.
60
    void addExternalSockets(bool use_external = true);
61
62
    /// @brief Opens unix control socket with parameters specified in socket_info
63
    /// (required parameters: socket-type: unix, socket-name:/unix/path).
64
    ///
65
    /// @throw BadSocketInfo When socket configuration is invalid.
66
    /// @throw SocketError When socket operation fails.
67
    ///
68
    /// @param config Configuration information for the unix control socket.
69
    void openCommandSockets(const isc::data::ConstElementPtr config);
70
71
    /// @brief Opens unix control socket with parameters specified in socket_info
72
    /// (required parameters: socket-type: unix, socket-name:/unix/path).
73
    ///
74
    /// Creates acceptor, or reuses the existing one.
75
    ///
76
    /// @note This function in used internally by @ref openCommandSockets and it
77
    /// should not be used directly, except for unit tests.
78
    ///
79
    /// @throw BadSocketInfo When socket configuration is invalid.
80
    /// @throw SocketError When socket operation fails.
81
    ///
82
    /// @param config Configuration information for the unix control socket.
83
    void openCommandSocket(const isc::data::ConstElementPtr config);
84
85
    /// @brief Shuts down any open unix control sockets.
86
    ///
87
    /// @note This function in used internally by @ref closeCommandSockets and it
88
    /// should not be used directly, except for unit tests.
89
    ///
90
    /// @param info Configuration information for the unix control socket.
91
    void closeCommandSocket(UnixSocketInfoPtr info = UnixSocketInfoPtr());
92
93
    /// @brief Shuts down any open unix control sockets.
94
    void closeCommandSockets();
95
96
    /// @brief Returns unix control socket descriptor.
97
    ///
98
    /// This method should be used only in tests.
99
    ///
100
    /// @param info Configuration information for the unix control socket.
101
    ///
102
    /// @return The file descriptor of the specified unix control socket.
103
    int getControlSocketFD(UnixSocketInfoPtr info = UnixSocketInfoPtr());
104
105
private:
106
107
    /// @brief Private constructor.
108
    UnixCommandMgr();
109
110
    /// @brief Pointer to the implementation of the @ref UnixCommandMgr.
111
    boost::shared_ptr<UnixCommandMgrImpl> impl_;
112
};
113
114
} // end of isc::config namespace
115
} // end of isc namespace
116
#endif