cfgmgr.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef CFGMGR_H
  15. #define CFGMGR_H
  16. #include <string>
  17. #include <map>
  18. #include <vector>
  19. #include <boost/shared_ptr.hpp>
  20. #include <boost/noncopyable.hpp>
  21. #include <asiolink/io_address.h>
  22. #include <util/buffer.h>
  23. #include <dhcp/option.h>
  24. #include <dhcp/pool.h>
  25. #include <dhcp/subnet.h>
  26. namespace isc {
  27. namespace dhcp {
  28. /// @brief Configuration Manager
  29. ///
  30. /// This singleton class holds the whole configuration for DHCPv4 and DHCPv6
  31. /// servers. It currently holds information about zero or more subnets6.
  32. /// Each subnet may contain zero or more pools. Pool4 and Pool6 is the most
  33. /// basic "chunk" of configuration. It contains a range of assigneable
  34. /// addresses.
  35. ///
  36. /// Below is a sketch of configuration inheritance (not implemented yet).
  37. /// Let's investigate the following configuration:
  38. ///
  39. /// preferred-lifetime 500;
  40. /// valid-lifetime 1000;
  41. /// subnet6 2001:db8:1::/48 {
  42. /// pool6 2001::db8:1::1 - 2001::db8:1::ff;
  43. /// };
  44. /// subnet6 2001:db8:2::/48 {
  45. /// valid-lifetime 2000;
  46. /// pool6 2001::db8:2::1 - 2001::db8:2::ff;
  47. /// };
  48. /// Parameters defined in a global scope are applicable to everything until
  49. /// they are overwritten in a smaller scope, in this case subnet6.
  50. /// In the example above, the first subnet6 has preferred lifetime of 500s
  51. /// and a valid lifetime of 1000s. The second subnet has preferred lifetime
  52. /// of 500s, but valid lifetime of 2000s.
  53. ///
  54. /// Parameter inheritance is likely to be implemented in configuration handling
  55. /// routines, so there is no storage capability in a global scope for
  56. /// subnet-specific parameters.
  57. ///
  58. /// @todo: Implement Subnet4 support (ticket #2237)
  59. /// @todo: Implement option definition support
  60. /// @todo: Implement parameter inheritance
  61. class CfgMgr : public boost::noncopyable {
  62. public:
  63. /// @brief returns a single instance of Configuration Manager
  64. ///
  65. /// CfgMgr is a singleton and this method is the only way of
  66. /// accessing it.
  67. static CfgMgr& instance();
  68. /// @brief get IPv6 subnet by address
  69. ///
  70. /// Finds a matching subnet, based on an address. This can be used
  71. /// in two cases: when trying to find an appropriate lease based on
  72. /// a) relay link address (that must be the address that is on link)
  73. /// b) our global address on the interface the message was received on
  74. /// (for directly connected clients)
  75. ///
  76. /// @param hint an address that belongs to a searched subnet
  77. Subnet6Ptr getSubnet6(const isc::asiolink::IOAddress& hint);
  78. /// @brief get IPv6 subnet by interface-id
  79. ///
  80. /// Another possibility to find a subnet is based on interface-id.
  81. ///
  82. /// @param interface_id content of interface-id option returned by a relay
  83. /// @todo This method is not currently supported.
  84. Subnet6Ptr getSubnet6(OptionPtr interface_id);
  85. /// @brief adds an IPv6 subnet
  86. void addSubnet6(const Subnet6Ptr& subnet);
  87. /// @todo: Add subnet6 removal routines. Currently it is not possible
  88. /// to remove subnets. The only case where subnet6 removal would be
  89. /// needed is a dynamic server reconfiguration - a use case that is not
  90. /// planned to be supported any time soon.
  91. /// @brief removes all subnets
  92. ///
  93. /// This method removes all existing subnets. It is used during
  94. /// reconfiguration - old configuration is wiped and new definitions
  95. /// are used to recreate subnets.
  96. ///
  97. /// @todo Implement more intelligent approach. Note that comparison
  98. /// between old and new configuration is tricky. For example: is
  99. /// 2000::/64 and 2000::/48 the same subnet or is it something
  100. /// completely new?
  101. void deleteSubnets6() {
  102. subnets6_.clear();
  103. }
  104. /// @brief get IPv4 subnet by address
  105. ///
  106. /// Finds a matching subnet, based on an address. This can be used
  107. /// in two cases: when trying to find an appropriate lease based on
  108. /// a) relay link address (that must be the address that is on link)
  109. /// b) our global address on the interface the message was received on
  110. /// (for directly connected clients)
  111. ///
  112. /// @param hint an address that belongs to a searched subnet
  113. Subnet4Ptr getSubnet4(const isc::asiolink::IOAddress& hint);
  114. /// @brief adds a subnet4
  115. void addSubnet4(const Subnet4Ptr& subnet);
  116. /// @brief removes all IPv4 subnets
  117. void removeSubnets4();
  118. protected:
  119. /// @brief Protected constructor.
  120. ///
  121. /// This constructor is protected for 2 reasons. First, it forbids any
  122. /// instantiations of this class (CfgMgr is a singleton). Second, it
  123. /// allows derived class to instantiate it. That is useful for testing
  124. /// purposes.
  125. CfgMgr();
  126. /// @brief virtual desctructor
  127. virtual ~CfgMgr();
  128. /// @brief a container for IPv6 subnets.
  129. ///
  130. /// That is a simple vector of pointers. It does not make much sense to
  131. /// optimize access time (e.g. using a map), because typical search
  132. /// pattern will use calling inRange() method on each subnet until
  133. /// a match is found.
  134. Subnet6Collection subnets6_;
  135. /// @brief a container for IPv4 subnets.
  136. ///
  137. /// That is a simple vector of pointers. It does not make much sense to
  138. /// optimize access time (e.g. using a map), because typical search
  139. /// pattern will use calling inRange() method on each subnet until
  140. /// a match is found.
  141. Subnet4Collection subnets4_;
  142. };
  143. } // namespace isc::dhcp
  144. } // namespace isc
  145. #endif