d2_cfg_mgr.h 11.2 KB
Newer Older
1
// Copyright (C) 2014-2016 Internet Systems Consortium, Inc. ("ISC")
2
//
3 4 5
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6

7 8 9
#ifndef D2_CFG_MGR_H
#define D2_CFG_MGR_H

10
#include <asiolink/io_service.h>
11 12
#include <cc/data.h>
#include <exceptions/exceptions.h>
13
#include <d2/d2_config.h>
14
#include <process/d_cfg_mgr.h>
15 16 17 18 19 20 21

#include <stdint.h>
#include <string>

namespace isc {
namespace d2 {

22 23 24 25
class D2CfgContext;
/// @brief Pointer to a configuration context.
typedef boost::shared_ptr<D2CfgContext> D2CfgContextPtr;

26
/// @brief  DHCP-DDNS Configuration Context
27
///
28 29
/// Implements the storage container for configuration context.
/// It provides a single enclosure for the storage of configuration parameters
30
/// and any other DHCP-DDNS specific information that needs to be accessible
31
/// during configuration parsing as well as to the application as a whole.
32
/// It is derived from the context base class, DCfgContextBase.
33
class D2CfgContext : public process::DCfgContextBase {
34 35 36 37 38 39 40 41
public:
    /// @brief Constructor
    D2CfgContext();

    /// @brief Destructor
    virtual ~D2CfgContext();

    /// @brief Creates a clone of this context object.
42
    ///
43
    /// @return returns a pointer to the new clone.
44 45
    virtual process::DCfgContextBasePtr clone() {
        return (process::DCfgContextBasePtr(new D2CfgContext(*this)));
46 47
    }

48
    /// @brief Fetches a reference to the D2Params
49 50 51 52
    D2ParamsPtr& getD2Params() {
        return (d2_params_);
    }

53 54
    /// @brief Fetches the forward DNS domain list manager.
    ///
55 56
    /// @return returns a pointer to the forward manager.
    DdnsDomainListMgrPtr getForwardMgr() {
57 58 59 60 61
        return (forward_mgr_);
    }

    /// @brief Fetches the reverse DNS domain list manager.
    ///
62 63
    /// @return returns a pointer to the reverse manager.
    DdnsDomainListMgrPtr getReverseMgr() {
64 65 66
        return (reverse_mgr_);
    }

67 68 69 70 71 72 73
    /// @brief Fetches the map of TSIG keys.
    ///
    /// @return returns a pointer to the key map.
    TSIGKeyInfoMapPtr getKeys() {
        return (keys_);
    }

74 75 76 77 78 79 80 81
protected:
    /// @brief Copy constructor for use by derivations in clone().
    D2CfgContext(const D2CfgContext& rhs);

private:
    /// @brief Private assignment operator to avoid potential for slicing.
    D2CfgContext& operator=(const D2CfgContext& rhs);

82 83 84
    /// @brief Global level parameter storage
    D2ParamsPtr d2_params_;

85 86 87 88 89
    /// @brief Forward domain list manager.
    DdnsDomainListMgrPtr forward_mgr_;

    /// @brief Reverse domain list manager.
    DdnsDomainListMgrPtr reverse_mgr_;
90 91 92

    /// @brief Storage for the map of TSIGKeyInfos
    TSIGKeyInfoMapPtr keys_;
93 94
};

95 96 97 98
/// @brief Defines a pointer for DdnsDomain instances.
typedef boost::shared_ptr<DdnsDomainListMgr> DdnsDomainListMgrPtr;


99 100 101 102 103 104 105

/// @brief DHCP-DDNS Configuration Manager
///
/// Provides the mechanisms for managing the DHCP-DDNS application's
/// configuration.  This includes services for parsing sets of configuration
/// values, storing the parsed information in its converted form,
/// and retrieving the information on demand.
106
class D2CfgMgr : public process::DCfgMgrBase {
107
public:
108 109 110 111 112 113 114 115
    /// @brief Reverse zone suffix added to IPv4 addresses for reverse lookups
    /// @todo This should be configurable.
    static const char* IPV4_REV_ZONE_SUFFIX;

    /// @brief Reverse zone suffix added to IPv6 addresses for reverse lookups
    /// @todo This should be configurable.
    static const char* IPV6_REV_ZONE_SUFFIX;

116 117 118 119 120 121 122 123 124 125 126 127 128
    /// @brief Constructor
    D2CfgMgr();

    /// @brief Destructor
    virtual ~D2CfgMgr();

    /// @brief Convenience method that returns the D2 configuration context.
    ///
    /// @return returns a pointer to the configuration context.
    D2CfgContextPtr getD2CfgContext() {
        return (boost::dynamic_pointer_cast<D2CfgContext>(getContext()));
    }

129
    /// @brief Returns whether or not forward updates are enabled.
130
    ///
Vincent Legout's avatar
Vincent Legout committed
131
    /// This method currently uses the presence or absence of Forward DDNS
132 133 134 135
    /// Domains to determine if forward updates are enabled or disabled.
    /// @todo This could be expanded to include the check of a configurable
    /// boolean value.
    ///
136 137 138
    /// @return true if forward updates are enabled, false otherwise.
    bool forwardUpdatesEnabled();

139
    /// @brief Returns whether or not reverse updates are enabled.
140
    ///
141 142 143 144 145
    /// This method currently uses the presence or absence of Reverse DDNS
    /// Domains to determine if reverse updates are enabled or disabled.
    /// @todo This could be expanded to include the check of a configurable
    /// boolean value.
    ///
146 147 148
    /// @return true if reverse updates are enabled, false otherwise.
    bool reverseUpdatesEnabled();

149
    /// @brief Matches a given FQDN to a forward domain.
150
    ///
151
    /// This calls the matchDomain method of the forward domain manager to
152
    /// match the given FQDN to a forward domain.
153 154 155 156 157 158
    ///
    /// @param fqdn is the name for which to look.
    /// @param domain receives the matching domain. Note that it will be reset
    /// upon entry and only set if a match is subsequently found.
    ///
    /// @return returns true if a match is found, false otherwise.
159 160
    /// @throw throws D2CfgError if given an invalid fqdn.
    bool matchForward(const std::string& fqdn, DdnsDomainPtr& domain);
161

162
    /// @brief Matches a given IP address to a reverse domain.
163 164
    ///
    /// This calls the matchDomain method of the reverse domain manager to
165
    /// match the given IPv4 or IPv6 address to a reverse domain.
166
    ///
167
    /// @param ip_address is the name for which to look.
168 169 170 171
    /// @param domain receives the matching domain. Note that it will be reset
    /// upon entry and only set if a match is subsequently found.
    ///
    /// @return returns true if a match is found, false otherwise.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
    /// @throw throws D2CfgError if given an invalid fqdn.
    bool matchReverse(const std::string& ip_address, DdnsDomainPtr& domain);

    /// @brief Generate a reverse order string for the given IP address
    ///
    /// This method creates a string containing the given IP address
    /// contents in reverse order.  This format is used for matching
    /// against reverse DDNS domains in DHCP_DDNS configuration.
    /// After reversing the syllables of the address, it appends the
    /// appropriate suffix.
    ///
    /// @param address string containing a valid IPv4 or IPv6 address.
    ///
    /// @return a std::string containing the reverse order address.
    ///
    /// @throw D2CfgError if given an invalid address.
188
    static std::string reverseIpAddress(const std::string& address);
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206

    /// @brief Generate a reverse order string for the given IP address
    ///
    /// This method creates a string containing the given IP address
    /// contents in reverse order.  This format is used for matching
    /// against reverse DDNS domains in DHCP_DDNS configuration.
    /// After reversing the syllables of the address, it appends the
    /// appropriate suffix.
    ///
    /// Example:
    ///   input:  192.168.1.15
    ///  output:  15.1.168.192.in-addr.arpa.
    ///
    /// @param ioaddr is the IPv4 IOaddress to convert
    ///
    /// @return a std::string containing the reverse order address.
    ///
    /// @throw D2CfgError if not given an IPv4  address.
207
    static std::string reverseV4Address(const isc::asiolink::IOAddress& ioaddr);
208 209 210 211 212 213 214 215 216 217 218 219 220 221

    /// @brief Generate a reverse order string for the given IP address
    ///
    /// This method creates a string containing the given IPv6 address
    /// contents in reverse order.  This format is used for matching
    /// against reverse DDNS domains in DHCP_DDNS configuration.
    /// After reversing the syllables of the address, it appends the
    /// appropriate suffix.
    ///
    /// IPv6 example:
    /// input:  2001:db8:302:99::
    /// output:
    ///0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.9.9.0.0.2.0.3.0.8.B.D.0.1.0.0.2.ip6.arpa.
    ///
222
    /// @param ioaddr string containing a valid IPv6 address.
223 224 225 226
    ///
    /// @return a std::string containing the reverse order address.
    ///
    /// @throw D2CfgError if not given an IPv6 address.
227
    static std::string reverseV6Address(const isc::asiolink::IOAddress& ioaddr);
228

229 230 231 232
    /// @brief Convenience method fetches the D2Params from context
    /// @return reference to const D2ParamsPtr
    const D2ParamsPtr& getD2Params();

233 234 235 236 237 238
    /// @brief Returns configuration summary in the textual format.
    ///
    /// @param selection Bitfield which describes the parts of the configuration
    /// to be returned. This parameter is ignored for the D2.
    ///
    /// @return Summary of the configuration in the textual format.
239
    virtual std::string getConfigSummary(const uint32_t selection);
240

241
protected:
242 243 244 245
    /// @brief Performs the parsing of the given "params" element.
    ///
    /// Iterates over the set of parameters, creating a parser based on the
    /// parameter's id and then invoking its build method passing in the
246
    /// parameter's configuration value.
247
    ///
248 249 250 251
    /// It then fetches the parameters, validating their values and if
    /// valid instantiates a D2Params instance.  Invalid values result in
    /// a throw.
    ///
252
    /// @param params_config set of scalar configuration elements to parse
253 254 255 256 257 258 259
    ///
    /// @throw D2CfgError if any of the following are true:
    /// -# ip_address is 0.0.0.0 or ::
    /// -# port is 0
    /// -# dns_server_timeout is < 1
    /// -# ncr_protocol is invalid, currently only NCR_UDP is supported
    /// -# ncr_format is invalid, currently only FMT_JSON is supported
260 261
    virtual void buildParams(isc::data::ConstElementPtr params_config);

262 263
    /// @brief Given an element_id returns an instance of the appropriate
    /// parser.
264 265 266
    ///
    /// It is responsible for top-level or outermost DHCP-DDNS configuration
    /// elements (see dhcp-ddns.spec):
267 268 269 270 271 272 273 274
    ///     -# ip_address
    ///     -# port
    ///     -# dns_server_timeout
    ///     -# ncr_protocol
    ///     -# ncr_format
    ///     -# tsig_keys
    ///     -# forward_ddns
    ///     -# reverse_ddns
275 276 277
    ///
    /// @param element_id is the string name of the element as it will appear
    /// in the configuration set.
278 279
    /// @param pos position within the configuration text (or file) of element
    /// to be parsed.  This is passed for error messaging.
280 281 282 283
    ///
    /// @return returns a ParserPtr to the parser instance.
    /// @throw throws DCfgMgrBaseError if an error occurs.
    virtual isc::dhcp::ParserPtr
284 285 286
    createConfigParser(const std::string& element_id,
                       const isc::data::Element::Position& pos =
                       isc::data::Element::Position());
287

288 289 290 291 292 293 294 295 296
    /// @brief Creates an new, blank D2CfgContext context
    ///
    /// This method is used at the beginning of configuration process to
    /// create a fresh, empty copy of a D2CfgContext. This new context will
    /// be populated during the configuration process and will replace the
    /// existing context provided the configuration process completes without
    /// error.
    ///
    /// @return Returns a DCfgContextBasePtr to the new context instance.
297
    virtual process::DCfgContextBasePtr createNewContext();
298 299 300 301 302 303 304 305 306 307
};

/// @brief Defines a shared pointer to D2CfgMgr.
typedef boost::shared_ptr<D2CfgMgr> D2CfgMgrPtr;


}; // end of isc::d2 namespace
}; // end of isc namespace

#endif // D2_CFG_MGR_H