Commit b524d5e0 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[1708] msgq connection in dhcp{4,6} is now optional.

parent ed478d28
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)
......
......@@ -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;
......
......@@ -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()
......@@ -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;
......
......@@ -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()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment