]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[1708] msgq connection in dhcp{4,6} is now optional.
authorTomek Mrugalski <tomasz@isc.org>
Fri, 22 Jun 2012 14:14:23 +0000 (16:14 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Fri, 22 Jun 2012 14:14:23 +0000 (16:14 +0200)
ChangeLog
src/bin/dhcp4/main.cc
src/bin/dhcp4/tests/dhcp4_test.py
src/bin/dhcp6/main.cc
src/bin/dhcp6/tests/dhcp6_test.py

index 8fb267fc41ec5243111f9d3cced1ba01db5b781a..a8d0f49fe04a2e17b1a8f3774ba9104463137225 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+451.   [func]          tomek
+       b10-dhcp6: DHCPv6 server component is now integrated into
+       BIND10 framework. It can be started from BIND10 (using bindctl)
+       and can receive commands. The only supported command for now
+       is 'Dhcp6 shutdown'.
+       b10-dhcp4: Command line-switch '-s' to disable msgq was added.
+       b10-dhcp6: Command line-switch '-s' to disable msgq was added.
+       (Trac #1708, git tbd)
+
 450.   [func]*         tomek
        b10-dhcp4: DHCPv4 server component is now integrated into
        BIND10 framework. It can be started from BIND10 (using bindctl)
index ab3ae1bc1d5e7e35d81b2d6ad1de880f4803c4bc..472f46f4674b1baff10e2e400d14f42ebba5cb60 100644 (file)
@@ -39,6 +39,7 @@ usage() {
     cerr << "Usage:  b10-dhcp4 [-v]"
          << endl;
     cerr << "\t-v: verbose output" << endl;
+    cerr << "\t-s: stand-alone mode (don't connect to BIND10)" << endl;
     cerr << "\t-p number: specify non-standard port number 1-65535 "
          << "(useful for testing only)" << endl;
     exit(EXIT_FAILURE);
@@ -51,13 +52,17 @@ main(int argc, char* argv[]) {
     bool verbose_mode = false; // should server be verbose?
     int port_number = DHCP4_SERVER_PORT; // The default. any other values are
                                          // useful for testing only.
+    bool stand_alone = false; // should be connect to BIND10 msgq?
 
-    while ((ch = getopt(argc, argv, "vp:")) != -1) {
+    while ((ch = getopt(argc, argv, "vsp:")) != -1) {
         switch (ch) {
         case 'v':
             verbose_mode = true;
             isc::log::denabled = true;
             break;
+        case 's':
+            stand_alone = true;
+            break;
         case 'p':
             port_number = strtol(optarg, NULL, 10);
             if (port_number == 0) {
@@ -77,8 +82,9 @@ main(int argc, char* argv[]) {
                          (verbose_mode ? isc::log::DEBUG : isc::log::INFO),
                          isc::log::MAX_DEBUG_LEVEL, NULL);
 
-    cout << "b10-dhcp4: My pid=" << getpid() << ", binding to port " 
-         << port_number << ", verbose " << (verbose_mode?"yes":"no") << endl;
+    cout << "b10-dhcp4: My pid=" << getpid() << ", binding to port "
+         << port_number << ", verbose " << (verbose_mode?"yes":"no")
+         << ", stand-alone=" << (stand_alone?"yes":"no") << endl;
 
     if (argc - optind > 0) {
         usage();
@@ -92,6 +98,20 @@ main(int argc, char* argv[]) {
 
         /// @todo: pass verbose to the actul server once logging is implemented
         ControlledDhcpv4Srv* server = new ControlledDhcpv4Srv(port_number);
+
+        if (!stand_alone) {
+            try {
+                server->establishSession();
+            } catch (const std::exception& ex) {
+                cerr << "Failed to establish BIND10 session. "
+                    "Running in stand-alone mode:" << ex.what() << endl;
+                // Let's continue. It is useful to have the ability to run
+                // DHCP server in stand-alone mode, e.g. for testing
+            }
+        } else {
+            cout << "Skipping connection to the BIND10 msgq." << endl;
+        }
+
         server->run();
         delete server;
         server = NULL;
index 18d23fff8d7de72a14fdc9df0f649e777b66f865..065c80c2ad7d6d6fd6d693d54238ecc054b3e9f4 100644 (file)
@@ -166,5 +166,18 @@ class TestDhcpv4Daemon(unittest.TestCase):
         # Check that there is an error message about invalid port number printed on stderr
         self.assertEqual( str(output).count("opening sockets on port 10057"), 1)
 
+    def test_skip_msgq(self):
+        print("Check that connection to BIND10 msgq can be disabled.")
+
+        (returncode, output, error) = self.runDhcp4(['../b10-dhcp4', '-s', '-p', '10057'])
+
+        # When invalid port number is specified, return code must not be success
+        # TODO: Temporarily commented out as socket binding on systems that do not have
+        #       interface detection implemented currently fails.
+        # self.assertTrue(returncode == 0)
+
+        # Check that there is an error message about invalid port number printed on stderr
+        self.assertEqual( str(output).count("Skipping connection to the BIND10 msgq."), 1)
+
 if __name__ == '__main__':
     unittest.main()
index 1cd52913bff35caa4e46e616e236e39759726357..96e2dd14ddd41d298905c028792d006a50879679 100644 (file)
@@ -39,6 +39,7 @@ usage() {
     cerr << "Usage: b10-dhcp6 [-v]"
          << endl;
     cerr << "\t-v: verbose output" << endl;
+    cerr << "\t-s: stand-alone mode (don't connect to BIND10)" << endl;
     cerr << "\t-p number: specify non-standard port number 1-65535 "
          << "(useful for testing only)" << endl;
     exit(EXIT_FAILURE);
@@ -51,13 +52,17 @@ main(int argc, char* argv[]) {
     int port_number = DHCP6_SERVER_PORT; // The default. Any other values are
                                          // useful for testing only.
     bool verbose_mode = false; // Should server be verbose?
+    bool stand_alone = false; // should be connect to BIND10 msgq?
 
-    while ((ch = getopt(argc, argv, "vp:")) != -1) {
+    while ((ch = getopt(argc, argv, "vsp:")) != -1) {
         switch (ch) {
         case 'v':
             verbose_mode = true;
             isc::log::denabled = true;
             break;
+        case 's':
+            stand_alone = true;
+            break;
         case 'p':
             port_number = strtol(optarg, NULL, 10);
             if (port_number == 0) {
@@ -78,7 +83,8 @@ main(int argc, char* argv[]) {
                          isc::log::MAX_DEBUG_LEVEL, NULL);
 
     cout << "b10-dhcp6: My pid=" << getpid() << ", binding to port "
-         << port_number << ", verbose " << (verbose_mode?"yes":"no") << endl;
+         << port_number << ", verbose " << (verbose_mode?"yes":"no")
+         << ", stand-alone=" << (stand_alone?"yes":"no") << endl;
 
     if (argc - optind > 0) {
         usage();
@@ -90,18 +96,26 @@ main(int argc, char* argv[]) {
 
         cout << "b10-dhcp6: Initiating DHCPv6 server operation." << endl;
 
+        /// @todo: pass verbose to the actual server once logging is implemented
         ControlledDhcpv6Srv* server = new ControlledDhcpv6Srv(port_number);
+
+        if (!stand_alone) {
+            try {
+                server->establishSession();
+            } catch (const std::exception& ex) {
+                cerr << "Failed to establish BIND10 session. "
+                    "Running in stand-alone mode:" << ex.what() << endl;
+                // Let's continue. It is useful to have the ability to run 
+                // DHCP server in stand-alone mode, e.g. for testing
+            }
+        } else {
+            cout << "Skipping connection to the BIND10 msgq." << endl;
+        }
+
         server->run();
         delete server;
         server = NULL;
 
-        cout << "[b10-dhcp6] Initiating DHCPv6 operation." << endl;
-
-        /// @todo: pass verbose to the actual server once logging is implemented
-        Dhcpv6Srv* srv = new Dhcpv6Srv(port_number);
-
-        srv->run();
-
     } catch (const std::exception& ex) {
         cerr << "[b10-dhcp6] Server failed: " << ex.what() << endl;
         ret = EXIT_FAILURE;
index 230588fd7320384685c42cd565b6da75bad5065b..e84bad198cf911cdae585b2fa205182a7abc96b6 100644 (file)
@@ -158,7 +158,7 @@ class TestDhcpv6Daemon(unittest.TestCase):
     def test_portnumber_nonroot(self):
         print("Check that specifying unprivileged port number will work.")
 
-        (returncode, output, error) = self.runCommand(['../b10-dhcp6', '-p', '10057'])
+        (returncode, output, error) = self.runCommand(['../b10-dhcp6', '-p', '10547'])
 
         # When invalid port number is specified, return code must not be success
         # TODO: Temporarily commented out as socket binding on systems that do not have
@@ -166,7 +166,21 @@ class TestDhcpv6Daemon(unittest.TestCase):
         # self.assertTrue(returncode == 0)
 
         # Check that there is a message on stdout about opening proper port
-        self.assertEqual( str(output).count("opening sockets on port 10057"), 1)
+        self.assertEqual( str(output).count("opening sockets on port 10547"), 1)
+
+    def test_skip_msgq(self):
+        print("Check that connection to BIND10 msgq can be disabled.")
+
+        (returncode, output, error) = self.runDhcp4(['../b10-dhcp6', '-s', '-p', '10547'])
+
+        # When invalid port number is specified, return code must not be success
+        # TODO: Temporarily commented out as socket binding on systems that do not have
+        #       interface detection implemented currently fails.
+        # self.assertTrue(returncode == 0)
+
+        # Check that there is an error message about invalid port number printed on stderr
+        self.assertEqual( str(output).count("Skipping connection to the BIND10 msgq."), 1)
+
 
 if __name__ == '__main__':
     unittest.main()