cfgmgr.h 6.49 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
// Copyright (C) 2012 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.

#ifndef CFGMGR_H
#define CFGMGR_H

#include <string>
#include <map>
#include <vector>
#include <boost/shared_ptr.hpp>
22
#include <boost/noncopyable.hpp>
23 24
#include <asiolink/io_address.h>
#include <util/buffer.h>
25
#include <dhcp/option.h>
26 27
#include <dhcp/pool.h>
#include <dhcp/subnet.h>
28 29 30 31

namespace isc {
namespace dhcp {

32

33 34 35 36 37 38 39 40
/// @brief Configuration Manager
///
/// This singleton class holds the whole configuration for DHCPv4 and DHCPv6
/// servers. It currently holds information about zero or more subnets6.
/// Each subnet may contain zero or more pools. Pool4 and Pool6 is the most
/// basic "chunk" of configuration. It contains a range of assigneable
/// addresses.
///
41
/// Below is a sketch of configuration inheritance (not implemented yet).
42 43
/// Let's investigate the following configuration:
///
44
/// preferred-lifetime 500;
45 46 47 48 49 50 51 52
/// valid-lifetime 1000;
/// subnet6 2001:db8:1::/48 {
///     pool6 2001::db8:1::1 - 2001::db8:1::ff;
/// };
/// subnet6 2001:db8:2::/48 {
///     valid-lifetime 2000;
///     pool6 2001::db8:2::1 - 2001::db8:2::ff;
/// };
53
/// Parameters defined in a global scope are applicable to everything until
54
/// they are overwritten in a smaller scope, in this case subnet6.
55 56 57 58 59 60 61
/// In the example above, the first subnet6 has preferred lifetime of 500s
/// and a valid lifetime of 1000s. The second subnet has preferred lifetime
/// of 500s, but valid lifetime of 2000s.
///
/// Parameter inheritance is likely to be implemented in configuration handling
/// routines, so there is no storage capability in a global scope for
/// subnet-specific parameters.
62 63 64
///
/// @todo: Implement Subnet4 support (ticket #2237)
/// @todo: Implement option definition support
65
/// @todo: Implement parameter inheritance
66 67
class CfgMgr : public boost::noncopyable {
public:
68 69 70 71 72

    /// @brief returns a single instance of Configuration Manager
    ///
    /// CfgMgr is a singleton and this method is the only way of
    /// accessing it.
73 74
    static CfgMgr& instance();

75
    /// @brief get IPv6 subnet by address
76 77 78 79 80 81
    ///
    /// Finds a matching subnet, based on an address. This can be used
    /// in two cases: when trying to find an appropriate lease based on
    /// a) relay link address (that must be the address that is on link)
    /// b) our global address on the interface the message was received on
    ///    (for directly connected clients)
82 83
    ///
    /// @param hint an address that belongs to a searched subnet
84 85
    Subnet6Ptr getSubnet6(const isc::asiolink::IOAddress& hint);

86
    /// @brief get IPv6 subnet by interface-id
87
    ///
88 89 90
    /// Another possibility to find a subnet is based on interface-id.
    ///
    /// @param interface_id content of interface-id option returned by a relay
91
    /// @todo This method is not currently supported.
92
    Subnet6Ptr getSubnet6(OptionPtr interface_id);
93

94
    /// @brief adds an IPv6 subnet
95 96
    void addSubnet6(const Subnet6Ptr& subnet);

97 98 99 100
    /// @todo: Add subnet6 removal routines. Currently it is not possible
    /// to remove subnets. The only case where subnet6 removal would be
    /// needed is a dynamic server reconfiguration - a use case that is not
    /// planned to be supported any time soon.
101

102
    /// @brief removes all IPv6 subnets
103
    ///
104
    /// This method removes all existing IPv6 subnets. It is used during
105 106 107 108 109 110 111
    /// reconfiguration - old configuration is wiped and new definitions
    /// are used to recreate subnets.
    ///
    /// @todo Implement more intelligent approach. Note that comparison
    /// between old and new configuration is tricky. For example: is
    /// 2000::/64 and 2000::/48 the same subnet or is it something
    /// completely new?
112
    void deleteSubnets6();
113

114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
    /// @brief get IPv4 subnet by address
    ///
    /// Finds a matching subnet, based on an address. This can be used
    /// in two cases: when trying to find an appropriate lease based on
    /// a) relay link address (that must be the address that is on link)
    /// b) our global address on the interface the message was received on
    ///    (for directly connected clients)
    ///
    /// @param hint an address that belongs to a searched subnet
    Subnet4Ptr getSubnet4(const isc::asiolink::IOAddress& hint);

    /// @brief adds a subnet4
    void addSubnet4(const Subnet4Ptr& subnet);

    /// @brief removes all IPv4 subnets
129 130 131 132 133 134 135 136 137 138
    ///
    /// This method removes all existing IPv4 subnets. It is used during
    /// reconfiguration - old configuration is wiped and new definitions
    /// are used to recreate subnets.
    ///
    /// @todo Implement more intelligent approach. Note that comparison
    /// between old and new configuration is tricky. For example: is
    /// 192.0.2.0/23 and 192.0.2.0/24 the same subnet or is it something
    /// completely new?
    void deleteSubnets4();
139 140 141
protected:

    /// @brief Protected constructor.
142 143 144 145 146
    ///
    /// This constructor is protected for 2 reasons. First, it forbids any
    /// instantiations of this class (CfgMgr is a singleton). Second, it
    /// allows derived class to instantiate it. That is useful for testing
    /// purposes.
147 148
    CfgMgr();

149
    /// @brief virtual desctructor
150 151
    virtual ~CfgMgr();

152
    /// @brief a container for IPv6 subnets.
153 154 155 156 157
    ///
    /// That is a simple vector of pointers. It does not make much sense to
    /// optimize access time (e.g. using a map), because typical search
    /// pattern will use calling inRange() method on each subnet until
    /// a match is found.
158
    Subnet6Collection subnets6_;
159 160 161 162 163 164 165 166

    /// @brief a container for IPv4 subnets.
    ///
    /// That is a simple vector of pointers. It does not make much sense to
    /// optimize access time (e.g. using a map), because typical search
    /// pattern will use calling inRange() method on each subnet until
    /// a match is found.
    Subnet4Collection subnets4_;
167
};
168 169 170 171 172

} // namespace isc::dhcp
} // namespace isc

#endif