From: Marcin Siodelski Date: Thu, 30 Oct 2014 13:53:42 +0000 (+0100) Subject: [3625] Use common SubnetSelector structure for Subnet4 selection. X-Git-Tag: trac3629a_base^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=05cb2252bf1f00b8dace35461b8095dd656c4bee;p=thirdparty%2Fkea.git [3625] Use common SubnetSelector structure for Subnet4 selection. --- diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index 5682b9c665..41fcc1c916 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -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(); diff --git a/src/lib/dhcpsrv/cfg_subnets4.cc b/src/lib/dhcpsrv/cfg_subnets4.cc index d79d1cfd60..9a17444ee5 100644 --- a/src/lib/dhcpsrv/cfg_subnets4.cc +++ b/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 diff --git a/src/lib/dhcpsrv/cfg_subnets4.h b/src/lib/dhcpsrv/cfg_subnets4.h index db2330b3b0..c59ad7f3ca 100644 --- a/src/lib/dhcpsrv/cfg_subnets4.h +++ b/src/lib/dhcpsrv/cfg_subnets4.h @@ -17,6 +17,7 @@ #include #include +#include #include 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 diff --git a/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc b/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc index cc584239b6..85816aebd4 100644 --- a/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include 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.