]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[1651] Changes after second review (DHCPv4 msgq integration)
authorTomek Mrugalski <tomasz@isc.org>
Tue, 12 Jun 2012 17:39:43 +0000 (19:39 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Tue, 12 Jun 2012 17:39:43 +0000 (19:39 +0200)
src/bin/dhcp4/ctrl_dhcp4_srv.cc
src/bin/dhcp4/ctrl_dhcp4_srv.h
src/bin/dhcp4/main.cc
src/lib/dhcp/iface_mgr.cc
src/lib/dhcp/iface_mgr.h

index b8749b7790f9b2acb75f7345612075e95d5858ec..048883f1a0b35f78a3e8361825a455372c78a951 100644 (file)
 #include <cc/session.h>
 #include <config/ccsession.h>
 #include <util/buffer.h>
-#include <log/dummylog.h>
 #include <dhcp4/spec_config.h>
 #include <dhcp4/ctrl_dhcp4_srv.h>
 #include <dhcp/iface_mgr.h>
 #include <asiolink/asiolink.h>
-#include <log/logger_support.h>
-
-const char* const DHCP4_NAME = "b10-dhcp4";
 
 using namespace std;
 using namespace isc::util;
@@ -60,6 +56,11 @@ ControlledDhcpv4Srv::dhcp4CommandHandler(const string& command, ConstElementPtr
     if (command == "shutdown") {
         if (ControlledDhcpv4Srv::server_) {
             ControlledDhcpv4Srv::server_->shutdown();
+        } else {
+            cout << "Server not initialized yet or already shut down." << endl;
+            ConstElementPtr answer = isc::config::createAnswer(1,
+                                     "Shutdown failure.");
+            return (answer);
         }
         ConstElementPtr answer = isc::config::createAnswer(0,
                                  "Shutting down.");
@@ -118,16 +119,13 @@ void ControlledDhcpv4Srv::disconnectSession() {
         delete cc_session_;
         cc_session_ = NULL;
     }
+
+    // deregister session socket
+    IfaceMgr::instance().set_session_socket(IfaceMgr::INVALID_SOCKET, NULL);
 }
 
-ControlledDhcpv4Srv::ControlledDhcpv4Srv(uint16_t port /*= DHCP4_SERVER_PORT*/,
-                                             bool verbose /* false */)
+ControlledDhcpv4Srv::ControlledDhcpv4Srv(uint16_t port /*= DHCP4_SERVER_PORT*/)
     :Dhcpv4Srv(port), cc_session_(NULL), config_session_(NULL) {
-
-    // Initialize logging.  If verbose, we'll use maximum verbosity.
-    isc::log::initLogger(DHCP4_NAME,
-                         (verbose ? isc::log::DEBUG : isc::log::INFO),
-                         isc::log::MAX_DEBUG_LEVEL, NULL);
     server_ = this; // remember this instance for use in callback
 }
 
@@ -147,7 +145,7 @@ isc::data::ConstElementPtr
 ControlledDhcpv4Srv::execDhcpv4ServerCommand(const std::string& command_id,
                                              isc::data::ConstElementPtr args) {
     try {
-        return dhcp4CommandHandler(command_id, args);
+        return (dhcp4CommandHandler(command_id, args));
     } catch (const Exception& ex) {
         ConstElementPtr answer = isc::config::createAnswer(1, ex.what());
         return (answer);
index 237335e684296e5b94a5c0a5a142b1dfbd7af175..08bf61d6ec7d15d636a9b46aaed37a974bca0c78 100644 (file)
@@ -41,9 +41,7 @@ public:
     /// @brief Constructor
     ///
     /// @param port UDP port to be opened for DHCP traffic
-    /// @param verbose should server print out additional commands?
-    ControlledDhcpv4Srv(uint16_t port = DHCP4_SERVER_PORT,
-                        bool verbose = false);
+    ControlledDhcpv4Srv(uint16_t port = DHCP4_SERVER_PORT);
 
     /// @brief Destructor.
     ~ControlledDhcpv4Srv();
@@ -52,12 +50,16 @@ public:
     ///
     /// Creates session that will be used to receive commands and updated
     /// configuration from boss (or indirectly from user via bindctl).
+    ///
+    /// Integrate the asynchronous I/O model of BIND 10 configuration
+    /// control with the "select" model of the DHCP server.  This is
+    /// fully explained in \ref dhcpv4Session.
     void establishSession();
 
     /// @brief Terminates existing msgq session.
     ///
     /// This method terminates existing session with msgq. After calling
-    /// it, not further messages over msgq (commands or configuration updates)
+    /// it, no further messages over msgq (commands or configuration updates)
     /// may be received.
     ///
     /// It is ok to call this method when session is disconnected already.
@@ -76,12 +78,12 @@ public:
     execDhcpv4ServerCommand(const std::string& command,
                             isc::data::ConstElementPtr args);
 
+protected:
     /// @brief Static pointer to the sole instance of the DHCP server.
     ///
     /// This is required for config and command handlers to gain access to
     /// the server
     static ControlledDhcpv4Srv* server_;
-protected:
 
     /// @brief A callback for handling incoming configuration updates.
     ///
index 5a641fcaae28213dd3b220965eac7e3bd50fe511..b45468d32d8ee93e538130c529a52580af8fd3e0 100644 (file)
 #include <iostream>
 #include <exceptions/exceptions.h>
 #include <log/dummylog.h>
+#include <log/logger_support.h>
 #include <dhcp4/ctrl_dhcp4_srv.h>
 #include <dhcp/iface_mgr.h>
 
 using namespace std;
 using namespace isc::dhcp;
 
+
+
 /// This file contains entry point (main() function) for standard DHCPv4 server
 /// component for BIND10 framework. It parses command-line arguments and
 /// instantiates ControlledDhcpv4Srv class that is responsible for establishing
@@ -33,6 +36,8 @@ using namespace isc::dhcp;
 
 namespace {
 
+const char* const DHCP4_NAME = "b10-dhcp4";
+
 void
 usage() {
     cerr << "Usage:  b10-dhcp4 [-v]"
@@ -47,18 +52,22 @@ main(int argc, char* argv[]) {
     int ch;
     bool verbose_mode = false; // should server be verbose?
 
-    while ((ch = getopt(argc, argv, ":v")) != -1) {
+    while ((ch = getopt(argc, argv, "v")) != -1) {
         switch (ch) {
         case 'v':
             verbose_mode = true;
             isc::log::denabled = true;
             break;
-        case ':':
         default:
             usage();
         }
     }
 
+    // Initialize logging.  If verbose, we'll use maximum verbosity.
+    isc::log::initLogger(DHCP4_NAME,
+                         (verbose_mode ? isc::log::DEBUG : isc::log::INFO),
+                         isc::log::MAX_DEBUG_LEVEL, NULL);
+
     cout << "b10-dhcp4: My pid is " << getpid() << endl;
 
     if (argc - optind > 0) {
@@ -66,13 +75,12 @@ main(int argc, char* argv[]) {
     }
 
     int ret = 0;
-    ControlledDhcpv4Srv* server = NULL;
 
     try {
 
         cout << "[b10-dhcp4] Initiating DHCPv4 server operation." << endl;
 
-        server = new ControlledDhcpv4Srv(DHCP4_SERVER_PORT, verbose_mode);
+        ControlledDhcpv4Srv* server = new ControlledDhcpv4Srv(DHCP4_SERVER_PORT);
         server->run();
         delete server;
 
index 447b1620e144b2d3ec3fffb9b79d8dbf9496b34b..e07068810915994f0d8e9fc12cf11b0949f3ba1b 100644 (file)
@@ -123,7 +123,7 @@ bool IfaceMgr::Iface::delSocket(uint16_t sockfd) {
 IfaceMgr::IfaceMgr()
     :control_buf_len_(CMSG_SPACE(sizeof(struct in6_pktinfo))),
      control_buf_(new char[control_buf_len_]),
-     session_socket_(InvalidSocket), session_callback_(NULL)
+     session_socket_(INVALID_SOCKET), session_callback_(NULL)
 {
 
     cout << "IfaceMgr initialization." << endl;
@@ -718,7 +718,7 @@ IfaceMgr::receive4(uint32_t timeout) {
     }
 
     // if there is session socket registered...
-    if (session_socket_ != InvalidSocket) {
+    if (session_socket_ != INVALID_SOCKET) {
         // at it to the set as well
         FD_SET(session_socket_, &sockets);
         if (maxfd < session_socket_)
@@ -747,8 +747,7 @@ IfaceMgr::receive4(uint32_t timeout) {
     }
 
     // Let's find out which socket has the data
-
-    if ((session_socket_ != InvalidSocket) && (FD_ISSET(session_socket_, &sockets))) {
+    if ((session_socket_ != INVALID_SOCKET) && (FD_ISSET(session_socket_, &sockets))) {
         // something received over session socket
         cout << "BIND10 command or config available over session socket." << endl;
 
index 1b2c487ad4af950b24b800af4cd89c94ecccd1f0..7fa2e855f445227f038d08334ef130ce63ad2261 100644 (file)
@@ -415,7 +415,7 @@ public:
     }
 
     /// A value of socket descriptor representing "not specified" state.
-    static const int InvalidSocket = -1;
+    static const int INVALID_SOCKET = -1;
 
     // don't use private, we need derived classes in tests
 protected: