Browse Source

[2559] Remove the temporary configuration of the lease database

The DHCP6 server had the lease database configuration temporarily
hard-coded.  With the introduction of database configuration
parameters, that is no longer needed.
Stephen Morris 12 years ago
parent
commit
79f0d62ef0

+ 2 - 2
src/bin/dhcp6/ctrl_dhcp6_srv.cc

@@ -149,8 +149,8 @@ void ControlledDhcpv6Srv::disconnectSession() {
     IfaceMgr::instance().set_session_socket(IfaceMgr::INVALID_SOCKET, NULL);
     IfaceMgr::instance().set_session_socket(IfaceMgr::INVALID_SOCKET, NULL);
 }
 }
 
 
-ControlledDhcpv6Srv::ControlledDhcpv6Srv(uint16_t port, const char* dbconfig)
-    : Dhcpv6Srv(port, dbconfig), cc_session_(NULL), config_session_(NULL) {
+ControlledDhcpv6Srv::ControlledDhcpv6Srv(uint16_t port)
+    : Dhcpv6Srv(port), cc_session_(NULL), config_session_(NULL) {
     server_ = this; // remember this instance for use in callback
     server_ = this; // remember this instance for use in callback
 }
 }
 
 

+ 1 - 3
src/bin/dhcp6/ctrl_dhcp6_srv.h

@@ -41,9 +41,7 @@ public:
     /// @brief Constructor
     /// @brief Constructor
     ///
     ///
     /// @param port UDP port to be opened for DHCP traffic
     /// @param port UDP port to be opened for DHCP traffic
-    /// @param dbconfig Lease manager database configuration string
-    ControlledDhcpv6Srv(uint16_t port = DHCP6_SERVER_PORT,
-                        const char* dbconfig = "type=memfile");
+    ControlledDhcpv6Srv(uint16_t port = DHCP6_SERVER_PORT);
 
 
     /// @brief Destructor.
     /// @brief Destructor.
     ~ControlledDhcpv6Srv();
     ~ControlledDhcpv6Srv();

+ 1 - 7
src/bin/dhcp6/dhcp6_srv.cc

@@ -50,7 +50,7 @@ using namespace std;
 namespace isc {
 namespace isc {
 namespace dhcp {
 namespace dhcp {
 
 
-Dhcpv6Srv::Dhcpv6Srv(uint16_t port, const char* dbconfig)
+Dhcpv6Srv::Dhcpv6Srv(uint16_t port)
     : alloc_engine_(), serverid_(), shutdown_(true) {
     : alloc_engine_(), serverid_(), shutdown_(true) {
 
 
     LOG_DEBUG(dhcp6_logger, DBG_DHCP6_START, DHCP6_OPEN_SOCKET).arg(port);
     LOG_DEBUG(dhcp6_logger, DBG_DHCP6_START, DHCP6_OPEN_SOCKET).arg(port);
@@ -71,12 +71,6 @@ Dhcpv6Srv::Dhcpv6Srv(uint16_t port, const char* dbconfig)
 
 
         setServerID();
         setServerID();
 
 
-        // Instantiate LeaseMgr
-        LeaseMgrFactory::create(dbconfig);
-        LOG_INFO(dhcp6_logger, DHCP6_DB_BACKEND_STARTED)
-            .arg(LeaseMgrFactory::instance().getType())
-            .arg(LeaseMgrFactory::instance().getName());
-
         // Instantiate allocation engine
         // Instantiate allocation engine
         alloc_engine_.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 100));
         alloc_engine_.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 100));
 
 

+ 1 - 4
src/bin/dhcp6/dhcp6_srv.h

@@ -80,10 +80,7 @@ public:
     /// old or create new DUID.
     /// old or create new DUID.
     ///
     ///
     /// @param port port on will all sockets will listen
     /// @param port port on will all sockets will listen
-    /// @param dbconfig Lease manager configuration string.  The default
-    ///        of the "memfile" manager is used for testing.
-    Dhcpv6Srv(uint16_t port = DHCP6_SERVER_PORT,
-            const char* dbconfig = "type=memfile");
+    Dhcpv6Srv(uint16_t port = DHCP6_SERVER_PORT);
 
 
     /// @brief Destructor. Used during DHCPv6 service shutdown.
     /// @brief Destructor. Used during DHCPv6 service shutdown.
     virtual ~Dhcpv6Srv();
     virtual ~Dhcpv6Srv();

+ 1 - 12
src/bin/dhcp6/main.cc

@@ -36,17 +36,6 @@ using namespace std;
 /// Dhcpv6Srv and other classes, see \ref dhcpv6Session.
 /// Dhcpv6Srv and other classes, see \ref dhcpv6Session.
 
 
 namespace {
 namespace {
-// @todo: Replace the next line by extraction from configuration parameters
-// This is the "dbconfig" string for the MySQL database.  It is likely
-// that a long-term solution will be to create the instance of the lease manager
-// somewhere other than the Dhcpv6Srv constructor, to give time to extract
-// the connection string from the configuration database.
-#ifdef HAVE_MYSQL
-const char* DBCONFIG = "type=mysql name=kea user=kea password=kea host=localhost";
-#else
-const char* DBCONFIG = "type=memfile";
-#endif
-
 const char* const DHCP6_NAME = "b10-dhcp6";
 const char* const DHCP6_NAME = "b10-dhcp6";
 
 
 void
 void
@@ -115,7 +104,7 @@ main(int argc, char* argv[]) {
 
 
     int ret = EXIT_SUCCESS;
     int ret = EXIT_SUCCESS;
     try {
     try {
-        ControlledDhcpv6Srv server(port_number, DBCONFIG);
+        ControlledDhcpv6Srv server(port_number);
         if (!stand_alone) {
         if (!stand_alone) {
             try {
             try {
                 server.establishSession();
                 server.establishSession();

+ 10 - 1
src/bin/dhcp6/tests/dhcp6_srv_unittest.cc

@@ -54,7 +54,16 @@ namespace {
 class NakedDhcpv6Srv: public Dhcpv6Srv {
 class NakedDhcpv6Srv: public Dhcpv6Srv {
     // "naked" Interface Manager, exposes internal members
     // "naked" Interface Manager, exposes internal members
 public:
 public:
-    NakedDhcpv6Srv(uint16_t port):Dhcpv6Srv(port) { }
+    NakedDhcpv6Srv(uint16_t port) : Dhcpv6Srv(port) {
+        // Open the "memfile" database for leases
+        std::string memfile = "type=memfile";
+        LeaseMgrFactory::create(memfile);
+    }
+
+    virtual ~NakedDhcpv6Srv() {
+        // Close the lease database
+        LeaseMgrFactory::destroy();
+    }
 
 
     using Dhcpv6Srv::processSolicit;
     using Dhcpv6Srv::processSolicit;
     using Dhcpv6Srv::processRequest;
     using Dhcpv6Srv::processRequest;

+ 7 - 0
src/lib/dhcpsrv/dhcpsrv_messages.mes

@@ -150,6 +150,13 @@ lease from the memory file database for the specified address.
 A debug message issued when the server is attempting to update IPv6
 A debug message issued when the server is attempting to update IPv6
 lease from the memory file database for the specified address.
 lease from the memory file database for the specified address.
 
 
+% DHCPSRV_MEMFILE_WARNING using early version of memfile - leases will be lost after a restart
+This warning message is issued when the 'memfile' lease database is
+opened.  The current version of memfile does not store anything
+to disk, so lease information will be lost in the event of a restart.
+Using this version of memfile in a production environment is NOT 
+recommended.
+
 % DHCPSRV_MYSQL_ADD_ADDR4 adding IPv4 lease with address %1
 % DHCPSRV_MYSQL_ADD_ADDR4 adding IPv4 lease with address %1
 A debug message issued when the server is about to add an IPv4 lease
 A debug message issued when the server is about to add an IPv4 lease
 with the specified address to the MySQL backend database.
 with the specified address to the MySQL backend database.

+ 1 - 2
src/lib/dhcpsrv/memfile_lease_mgr.cc

@@ -21,8 +21,7 @@ using namespace isc::dhcp;
 
 
 Memfile_LeaseMgr::Memfile_LeaseMgr(const ParameterMap& parameters)
 Memfile_LeaseMgr::Memfile_LeaseMgr(const ParameterMap& parameters)
     : LeaseMgr(parameters) {
     : LeaseMgr(parameters) {
-    std::cout << "Warning: Using memfile database backend. It is usable for limited"
-              << " testing only. Leases will be lost after restart." << std::endl;
+    LOG_WARN(dhcpsrv_logger, DHCPSRV_MEMFILE_WARNING);
 }
 }
 
 
 Memfile_LeaseMgr::~Memfile_LeaseMgr() {
 Memfile_LeaseMgr::~Memfile_LeaseMgr() {