Browse Source

[3625] Use common SubnetSelector structure for Subnet4 selection.

Marcin Siodelski 10 years ago
parent
commit
05cb2252bf

+ 2 - 1
src/bin/dhcp4/dhcp4_srv.cc

@@ -33,6 +33,7 @@
 #include <dhcpsrv/lease_mgr.h>
 #include <dhcpsrv/lease_mgr_factory.h>
 #include <dhcpsrv/subnet.h>
+#include <dhcpsrv/subnet_selector.h>
 #include <dhcpsrv/utils.h>
 #include <dhcpsrv/utils.h>
 #include <hooks/callout_handle.h>
@@ -1542,7 +1543,7 @@ Dhcpv4Srv::selectSubnet(const Pkt4Ptr& question) const {
 
     Subnet4Ptr subnet;
 
-    CfgSubnets4::Selector selector;
+    SubnetSelector selector;
     selector.ciaddr_ = question->getCiaddr();
     selector.giaddr_ = question->getGiaddr();
     selector.local_address_ = question->getLocalAddr();

+ 1 - 7
src/lib/dhcpsrv/cfg_subnets4.cc

@@ -32,12 +32,6 @@ const IOAddress BCAST_ADDRESS("255.255.255.255");
 namespace isc {
 namespace dhcp {
 
-CfgSubnets4::Selector::Selector()
-    : ciaddr_(ZERO_ADDRESS), giaddr_(ZERO_ADDRESS),
-      local_address_(ZERO_ADDRESS), remote_address_(ZERO_ADDRESS),
-      client_classes_(ClientClasses()), iface_name_(std::string()) {
-}
-
 void
 CfgSubnets4::add(const Subnet4Ptr& subnet) {
     /// @todo: Check that this new subnet does not cross boundaries of any
@@ -52,7 +46,7 @@ CfgSubnets4::add(const Subnet4Ptr& subnet) {
 }
 
 Subnet4Ptr
-CfgSubnets4::selectSubnet(const Selector& selector) const {
+CfgSubnets4::selectSubnet(const SubnetSelector& selector) const {
     // If relayed message has been received, try to match the giaddr with the
     // relay address specified for a subnet. It is also possible that the relay
     // address will not match with any of the relay addresses accross all

+ 4 - 26
src/lib/dhcpsrv/cfg_subnets4.h

@@ -17,6 +17,7 @@
 
 #include <asiolink/io_address.h>
 #include <dhcpsrv/subnet.h>
+#include <dhcpsrv/subnet_selector.h>
 #include <boost/shared_ptr.hpp>
 
 namespace isc {
@@ -35,30 +36,6 @@ namespace dhcp {
 class CfgSubnets4 {
 public:
 
-    /// @brief Subnet selector used in @c CfgSubnets4::selectSubnet.
-    ///
-    /// This structure holds various parameters extracted from a packet sent
-    /// by a DHCP client used to select the subnet for the client.
-    struct Selector {
-        /// @brief ciaddr from the client's message.
-        asiolink::IOAddress ciaddr_;
-        /// @brief giaddr from the client's message.
-        asiolink::IOAddress giaddr_;
-        /// @brief Address on which the message was received.
-        asiolink::IOAddress local_address_;
-        /// @brief Source address of the message.
-        asiolink::IOAddress remote_address_;
-        /// @brief Classes that the client belongs to.
-        ClientClasses client_classes_;
-        /// @brief Name of the interface on which the message was received.
-        std::string iface_name_;
-
-        /// @brief Default constructor.
-        ///
-        ///  Sets the default values for the @c Selector.
-        Selector();
-    };
-
     /// @brief Adds new subnet to the configuration.
     ///
     /// @param subnet Pointer to the subnet being added.
@@ -114,13 +91,14 @@ public:
     /// @return Pointer to the selected subnet or NULL if no subnet found.
     /// @throw isc::BadValue if the values in the subnet selector are invalid
     /// or they are insufficient to select a subnet.
-    Subnet4Ptr selectSubnet(const Selector& selector) const;
+    Subnet4Ptr selectSubnet(const SubnetSelector& selector) const;
 
     /// @brief Returns pointer to a subnet if provided address is in its range.
     ///
     /// This method returns a pointer to the subnet if the address passed in
     /// parameter is in range with this subnet. This is mainly used for unit
-    /// testing. This method is also called by the @c selectSubnet(Selector).
+    /// testing. This method is also called by the
+    /// @c selectSubnet(SubnetSelector).
     ///
     /// @param address Address for which the subnet is searched.
     /// @param client_classes Optional parameter specifying the classes that

+ 6 - 5
src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc

@@ -18,6 +18,7 @@
 #include <dhcpsrv/cfg_subnets4.h>
 #include <dhcpsrv/subnet.h>
 #include <dhcpsrv/subnet_id.h>
+#include <dhcpsrv/subnet_selector.h>
 #include <gtest/gtest.h>
 
 using namespace isc;
@@ -38,7 +39,7 @@ TEST(CfgSubnets4Test, getSubnetByCiaddr) {
     Subnet4Ptr subnet3(new Subnet4(IOAddress("192.0.2.128"), 26, 1, 2, 3));
 
     // Make sure that initially the subnets don't exist.
-    CfgSubnets4::Selector selector;
+    SubnetSelector selector;
     selector.ciaddr_ = IOAddress("192.0.2.0");
     // Set some unicast local address to simulate a Renew.
     selector.local_address_ = IOAddress("10.0.0.100");
@@ -83,7 +84,7 @@ TEST(CfgSubnets4Test, getSubnetByClasses) {
     cfg.add(subnet2);
     cfg.add(subnet3);
 
-    CfgSubnets4::Selector selector;
+    SubnetSelector selector;
 
     selector.local_address_ = IOAddress("10.0.0.10");
 
@@ -157,7 +158,7 @@ TEST(CfgSubnetsTest, getSubnetByRelayAddress) {
     cfg.add(subnet2);
     cfg.add(subnet3);
 
-    CfgSubnets4::Selector selector;
+    SubnetSelector selector;
 
     // Check that without relay-info specified, subnets are not selected
     selector.giaddr_ = IOAddress("10.0.0.1");
@@ -192,7 +193,7 @@ TEST(CfgSubnetsTest, getSubnetNoCiaddr) {
     Subnet4Ptr subnet3(new Subnet4(IOAddress("192.0.2.128"), 26, 1, 2, 3));
 
     // Make sure that initially the subnets don't exist.
-    CfgSubnets4::Selector selector;
+    SubnetSelector selector;
     selector.remote_address_ = IOAddress("192.0.2.0");
     // Set some unicast local address to simulate a Renew.
     selector.local_address_ = IOAddress("10.0.0.100");
@@ -231,7 +232,7 @@ TEST(CfgSubnetsTest, getSubnetInterface) {
     IfaceMgrTestConfig config(true);
 
     CfgSubnets4 cfg;
-    CfgSubnets4::Selector selector;
+    SubnetSelector selector;
 
     // Initially, there are no subnets configured, so none of the IPv4
     // addresses assigned to eth0 and eth1 can match with any subnet.