From: Tomek Mrugalski Date: Tue, 27 Dec 2011 13:48:29 +0000 (+0100) Subject: [1230] Generic DHCPv6 server clean-up: X-Git-Tag: trac2351_base~310^2~13^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=de6f226ae7bc45d144b6e012884bfd28ca74e350;p=thirdparty%2Fkea.git [1230] Generic DHCPv6 server clean-up: - DHCPv6 server now sends DNS-SERVERS option - refactored processSolicit(), processRequest() - added appendDefaultOptions(), appendRequestedOptions(), assignLeases() - many parameters are now const & - const HARDCODDED_* parameters added for similar customizations - IfaceMgr::openSockets6() now skips loopback, down, or unicast interfaces. --- diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc index 7d1b549bdc..4e69f05153 100644 --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -26,21 +27,28 @@ using namespace isc; using namespace isc::dhcp; using namespace isc::asiolink; +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) { cout << "Initialization" << endl; // first call to instance() will create IfaceMgr (it's a singleton) // it may throw something if things go wrong try { - IfaceMgr::instance(); + IfaceMgr::instance(); } catch (const std::exception &e) { - cout << "Failed to instantiate InterfaceManager:" << e.what() << ". Aborting." << endl; - shutdown = true; + cout << "Failed to instantiate InterfaceManager:" << e.what() << ". Aborting." << endl; + shutdown = true; } if (IfaceMgr::instance().countIfaces() == 0) { - cout << "Failed to detect any network interfaces. Aborting." << endl; - shutdown = true; + cout << "Failed to detect any network interfaces. Aborting." << endl; + shutdown = true; } // Now try to open IPv6 sockets on detected interfaces. @@ -115,8 +123,9 @@ Dhcpv6Srv::run() { cout << "Replying with:" << rsp->getType() << endl; cout << rsp->toText(); cout << "----" << endl; - if (rsp->pack()) { - cout << "#### pack successful." << endl; + if (!rsp->pack()) { + cout << "Failed to assemble response packet." << endl; + continue; } IfaceMgr::instance().send(rsp); } @@ -149,18 +158,45 @@ Dhcpv6Srv::setServerID() { 0, 14)); } -boost::shared_ptr -Dhcpv6Srv::processSolicit(boost::shared_ptr solicit) { +void Dhcpv6Srv::copyDefaultOptions(const boost::shared_ptr& question, + boost::shared_ptr& answer) { + // add client-id + boost::shared_ptr