From: Tomek Mrugalski Date: Tue, 30 Oct 2012 18:16:55 +0000 (+0100) Subject: [2414] Allocation Engine is now used in dhcp6_srv. X-Git-Tag: trac2487_base~1^2~31^2~27 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f63a6cabd8ecfca7465f1856a3836bdd72ea34f3;p=thirdparty%2Fkea.git [2414] Allocation Engine is now used in dhcp6_srv. --- diff --git a/src/bin/dhcp6/dhcp6_messages.mes b/src/bin/dhcp6/dhcp6_messages.mes index 2399c19036..ea0cb2a069 100644 --- a/src/bin/dhcp6/dhcp6_messages.mes +++ b/src/bin/dhcp6/dhcp6_messages.mes @@ -50,7 +50,7 @@ The IPv6 DHCP server tried to receive a packet but an error occured during this attempt. The reason for the error is included in the message. -% DHCP6_PACKET_RECEIVED %1 (type %2) packet received +% DHCP6_PACKET_RECEIVED %1 packet received A debug message noting that the server has received the specified type of packet. Note that a packet marked as UNKNOWN may well be a valid DHCP packet, just a type not expected by the server (e.g. it will report @@ -66,10 +66,10 @@ This error is output if the server failed to assemble the data to be returned to the client into a valid packet. The reason is most likely to be to a programming error: please raise a bug report. -% DHCP6_QUERY_DATA received packet length %1, data length %2, data is <%3> +% DHCP6_QUERY_DATA received packet length %1, data length %2, data is %3 A debug message listing the data received from the client or relay. -% DHCP6_RESPONSE_DATA responding with packet type %1 data is <%2> +% DHCP6_RESPONSE_DATA responding with packet type %1 data is %2 A debug message listing the data returned to the client. % DHCP6_SERVER_FAILED server failed: %1 diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc index 74949ed36e..c801afcaf4 100644 --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@ -28,6 +28,12 @@ #include #include #include +#include +#include +#include + +// @todo: Replace this with MySQL_LeaseMgr once it is merged +#include using namespace isc; using namespace isc::asiolink; @@ -35,20 +41,9 @@ using namespace isc::dhcp; using namespace isc::util; using namespace std; -const std::string HARDCODED_LEASE = "2001:db8:1::1234:abcd"; -const uint32_t HARDCODED_T1 = 1500; // in seconds -const uint32_t HARDCODED_T2 = 2600; // in seconds -const uint32_t HARDCODED_PREFERRED_LIFETIME = 3600; // in seconds -const uint32_t HARDCODED_VALID_LIFETIME = 7200; // in seconds const std::string HARDCODED_DNS_SERVER = "2001:db8:1::1"; Dhcpv6Srv::Dhcpv6Srv(uint16_t port) { - if (port == 0) { - // used for testing purposes. Some tests, e.g. configuration parser, - // require Dhcpv6Srv object, but they don't really need it to do - // anything. This speed up and simplifies the tests. - return; - } LOG_DEBUG(dhcp6_logger, DBG_DHCP6_START, DHCP6_OPEN_SOCKET).arg(port); @@ -56,13 +51,18 @@ Dhcpv6Srv::Dhcpv6Srv(uint16_t port) { // it may throw something if things go wrong try { - if (IfaceMgr::instance().countIfaces() == 0) { - LOG_ERROR(dhcp6_logger, DHCP6_NO_INTERFACES); - shutdown_ = true; - return; - } + // used for testing purposes. Some tests, e.g. configuration parser, + // require Dhcpv6Srv object, but they don't really need it to do + // anything. This speed up and simplifies the tests. + if (port) { + if (IfaceMgr::instance().countIfaces() == 0) { + LOG_ERROR(dhcp6_logger, DHCP6_NO_INTERFACES); + shutdown_ = true; + return; + } - IfaceMgr::instance().openSockets6(port); + IfaceMgr::instance().openSockets6(port); + } setServerID(); @@ -74,11 +74,20 @@ Dhcpv6Srv::Dhcpv6Srv(uint16_t port) { return; } + // Instantiate LeaseMgr + // @todo: Replace this with MySQL_LeaseMgr once it is merged + new isc::dhcp::test::Memfile_LeaseMgr(""); + + // Instantiate allocation engine + alloc_engine_ = new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 100); + shutdown_ = false; } Dhcpv6Srv::~Dhcpv6Srv() { IfaceMgr::instance().closeSockets(); + + LeaseMgr::destroy_instance(); } void Dhcpv6Srv::shutdown() { @@ -108,10 +117,9 @@ bool Dhcpv6Srv::run() { continue; } LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, DHCP6_PACKET_RECEIVED) - .arg(serverReceivedPacketName(query->getType())) - .arg(query->getType()); + .arg(serverReceivedPacketName(query->getType())); LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL_DATA, DHCP6_QUERY_DATA) - .arg(query->getType()) + .arg(static_cast(query->getType())) .arg(query->getBuffer().getLength()) .arg(query->toText()); @@ -301,33 +309,112 @@ void Dhcpv6Srv::appendRequestedOptions(const Pkt6Ptr& /*question*/, Pkt6Ptr& ans answer->addOption(dnsservers); } +OptionPtr Dhcpv6Srv::createStatusCode(uint16_t code, const std::string& text) { + + // @todo: Implement Option6_StatusCode and rewrite this code here + vector data(text.c_str(), text.c_str() + text.length()); + data.insert(data.begin(), static_cast(code % 256)); + data.insert(data.begin(), static_cast(code >> 8)); + OptionPtr status(new Option(Option::V6, D6O_STATUS_CODE, data)); + return (status); +} + +Subnet6Ptr Dhcpv6Srv::getSubnet(const Pkt6Ptr& question) { + Subnet6Ptr subnet = CfgMgr::instance().getSubnet6(question->getRemoteAddr()); + + return (subnet); +} + void Dhcpv6Srv::assignLeases(const Pkt6Ptr& question, Pkt6Ptr& answer) { - /// TODO Rewrite this once LeaseManager is implemented. - - // answer client's IA (this is mostly a dummy, - // so let's answer only first IA and hope there is only one) - boost::shared_ptr