]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[master] Added subnet manipulation support
authorThomas Markwalder <tmark@isc.org>
Thu, 10 Aug 2017 17:54:51 +0000 (13:54 -0400)
committerThomas Markwalder <tmark@isc.org>
Thu, 10 Aug 2017 17:54:51 +0000 (13:54 -0400)
    Merge branch 'trac5314'

1  2 
src/bin/dhcp4/tests/get_config_unittest.cc
src/bin/dhcp6/tests/get_config_unittest.cc
src/lib/config/hooked_command_mgr.cc
src/lib/config/hooked_command_mgr.h
src/lib/dhcpsrv/cfg_subnets4.cc
src/lib/dhcpsrv/cfg_subnets4.h
src/lib/dhcpsrv/cfg_subnets6.cc
src/lib/dhcpsrv/cfg_subnets6.h
src/lib/dhcpsrv/subnet.h
src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc
src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc

index f7c7eccbadeeaadcf8aa02f4ddbc0c11413ab1b3,3eb6a96e86dfd4ee4c559898f9384f2f46ed4202..12e285a51b8b06ff5471ce97e8c804c369d35de6
@@@ -3248,11 -3189,8 +3192,9 @@@ const char* UNPARSED_CONFIGS[] = 
  "        \"subnet6\": [\n"
  "            {\n"
  "                \"id\": 1,\n"
- "                \"interface\": \"\",\n"
- "                \"interface-id\": \"\",\n"
  "                \"option-data\": [\n"
  "                    {\n"
 +"                        \"always-send\": false,\n"
  "                        \"code\": 38,\n"
  "                        \"csv-format\": false,\n"
  "                        \"data\": \"ABCDEF0105\",\n"
  "        \"subnet6\": [\n"
  "            {\n"
  "                \"id\": 1,\n"
- "                \"interface\": \"\",\n"
- "                \"interface-id\": \"\",\n"
  "                \"option-data\": [\n"
  "                    {\n"
 +"                        \"always-send\": false,\n"
  "                        \"code\": 38,\n"
  "                        \"csv-format\": false,\n"
  "                        \"data\": \"0102030405060708090A\",\n"
  "            },\n"
  "            {\n"
  "                \"id\": 2,\n"
- "                \"interface\": \"\",\n"
- "                \"interface-id\": \"\",\n"
  "                \"option-data\": [\n"
  "                    {\n"
 +"                        \"always-send\": false,\n"
  "                        \"code\": 15,\n"
  "                        \"csv-format\": false,\n"
  "                        \"data\": \"FFFEFDFCFB\",\n"
  "                \"pd-pools\": [\n"
  "                    {\n"
  "                        \"delegated-len\": 64,\n"
- "                        \"excluded-prefix\": \"::\",\n"
- "                        \"excluded-prefix-len\": 0,\n"
  "                        \"option-data\": [\n"
  "                            {\n"
 +"                                \"always-send\": false,\n"
  "                                \"code\": 38,\n"
  "                                \"csv-format\": false,\n"
  "                                \"data\": \"112233445566\",\n"
  "                    },\n"
  "                    {\n"
  "                        \"delegated-len\": 64,\n"
- "                        \"excluded-prefix\": \"::\",\n"
- "                        \"excluded-prefix-len\": 0,\n"
  "                        \"option-data\": [\n"
  "                            {\n"
 +"                                \"always-send\": false,\n"
  "                                \"code\": 15,\n"
  "                                \"csv-format\": false,\n"
  "                                \"data\": \"AABBCCDDEE\",\n"
Simple merge
Simple merge
index ef3579ce69691d4880703d82464cbaeb38272865,26b079b2c980463de3ad4aa9bbb150c60158f5e0..f5fcd232c0c4149fabaa48f69e17c7aca763e111
@@@ -34,6 -34,20 +34,20 @@@ CfgSubnets4::add(const Subnet4Ptr& subn
      subnets_.push_back(subnet);
  }
  
 -    const auto& index = subnets_.get<SubnetIdIndexTag>();
+ ConstSubnet4Ptr
+ CfgSubnets4::getBySubnetId(const SubnetID& subnet_id) const {
++    const auto& index = subnets_.get<SubnetSubnetIdIndexTag>();
+     auto subnet_it = index.find(subnet_id);
+     return ((subnet_it != index.cend()) ? (*subnet_it) : ConstSubnet4Ptr());
+ }
+ ConstSubnet4Ptr
+ CfgSubnets4::getByPrefix(const std::string& subnet_text) const {
+     const auto& index = subnets_.get<SubnetPrefixIndexTag>();
+     auto subnet_it = index.find(subnet_text);
+     return ((subnet_it != index.cend()) ? (*subnet_it) : ConstSubnet4Ptr());
+ }
  Subnet4Ptr
  CfgSubnets4::selectSubnet4o6(const SubnetSelector& selector) const {
  
Simple merge
index 03ec44f84e5b6b8bb6d1ed429ea8549147c511bc,491fdb227e4c07a8ec5d1ed9c194e858f27afcaa..111fed0997523bda5b6e859908509314bd488533
@@@ -33,6 -33,20 +33,20 @@@ CfgSubnets6::add(const Subnet6Ptr& subn
      subnets_.push_back(subnet);
  }
  
 -    const auto& index = subnets_.get<SubnetIdIndexTag>();
+ ConstSubnet6Ptr
+ CfgSubnets6::getBySubnetId(const SubnetID& subnet_id) const {
++    const auto& index = subnets_.get<SubnetSubnetIdIndexTag>();
+     auto subnet_it = index.find(subnet_id);
+     return ((subnet_it != index.cend()) ? (*subnet_it) : ConstSubnet6Ptr());
+ }
+ ConstSubnet6Ptr
+ CfgSubnets6::getByPrefix(const std::string& subnet_text) const {
+     const auto& index = subnets_.get<SubnetPrefixIndexTag>();
+     auto subnet_it = index.find(subnet_text);
+     return ((subnet_it != index.cend()) ? (*subnet_it) : ConstSubnet6Ptr());
+ }
  Subnet6Ptr
  CfgSubnets6::selectSubnet(const SubnetSelector& selector) const {
      Subnet6Ptr subnet;
Simple merge
index 5fc2112d1553da25dd8af1e7380bfa77f64d9391,638eb11cf816a43833c3104c87b509ac7f3f6b4a..3d91ae8bb9074784053d76280fd3dde677e408ed
@@@ -710,8 -738,77 +738,77 @@@ typedef boost::shared_ptr<const Subnet6
  /// @brief A pointer to a Subnet6 object
  typedef boost::shared_ptr<Subnet6> Subnet6Ptr;
  
- /// @brief A collection of Subnet6 objects
- typedef std::vector<Subnet6Ptr> Subnet6Collection;
+ /// @name Definition of the multi index container holding subnet information
+ ///
+ //@{
+ /// @brief Tag for the random access index.
+ struct SubnetRandomAccessIndexTag { };
+ /// @brief Tag for the index for searching by subnet identifier.
 -struct SubnetIdIndexTag { };
++struct SubnetSubnetIdIndexTag { };
+ /// @brief Tag for the index for searching by subnet prefix.
+ struct SubnetPrefixIndexTag { };
+ /// @brief Multi index container holding subnets.
+ ///
+ /// This multi index container can hold pointers to @ref Subnet4 or
+ /// @ref Subnet6 objects representing subnets. It provides indexes for
+ /// subnet lookups using subnet properties such as: subnet identifier
+ /// or subnet prefix. It also provides a random access index which
+ /// allows for using the container like a vector.
+ ///
+ /// The random access index is used by the DHCP servers which perform
+ /// a full scan on subnets to find the one that matches some specific
+ /// criteria for subnet selection.
+ ///
+ /// The remaining indexes are used for searching for a specific subnet
+ /// as a result of receiving a command over the control API, e.g.
+ /// when 'subnet-get' command is received.
+ ///
+ /// @todo We should consider optimizing subnet selection by leveraging
+ /// the indexing capabilities of this container, e.g. searching for
+ /// a subnet by interface name, relay address etc.
+ ///
+ /// @tparam SubnetType Type of the subnet: @ref Subnet4 or @ref Subnet6.
+ template<typename SubnetType>
+ using SubnetCollection = boost::multi_index_container<
+     // Multi index container holds pointers to the subnets.
+     boost::shared_ptr<SubnetType>,
+     // The following holds all indexes.
+     boost::multi_index::indexed_by<
+         // First is the random access index allowing for accessing
+         // objects just like we'd do with a vector.
+         boost::multi_index::random_access<
+             boost::multi_index::tag<SubnetRandomAccessIndexTag>
+         >,
+         // Second index allows for searching using subnet identifier.
+         boost::multi_index::ordered_unique<
 -            boost::multi_index::tag<SubnetIdIndexTag>,
++            boost::multi_index::tag<SubnetSubnetIdIndexTag>,
+             boost::multi_index::const_mem_fun<Subnet, SubnetID, &Subnet::getID>
+         >,
+         // Third index allows for searching using an output from toText function.
+         boost::multi_index::ordered_unique<
+             boost::multi_index::tag<SubnetPrefixIndexTag>,
+             boost::multi_index::const_mem_fun<Subnet, std::string, &Subnet::toText>
+         >
+     >
+ >;
+ /// @brief A collection of @c Subnet4 objects
+ ///
+ /// This container provides a set of indexes which can be used to retrieve
+ /// subnets by various properties.
+ typedef SubnetCollection<Subnet4> Subnet4Collection;
+ /// @brief A collection of @c Subnet6 objects
+ ///
+ /// This container provides a set of indexes which can be used to retrieve
+ /// subnets by various properties.
+ typedef SubnetCollection<Subnet6> Subnet6Collection;
+ //@}
  
  } // end of isc::dhcp namespace
  } // end of isc namespace