Browse Source

Merge branch 'trac1281'

Tomek Mrugalski 13 years ago
parent
commit
900fc8b420

+ 5 - 0
ChangeLog

@@ -1,3 +1,8 @@
+4XX.	[func]		tomek
+	libdhcp++: Stub interface detection (support for interfaces.txt
+	file) was removed.
+	(Trac #1281, git TBD)
+
 bind10-devel-20120517 released on May 17. 2012
 
 440.	[func]		muks

+ 3 - 5
src/bin/dhcp4/Makefile.am

@@ -18,10 +18,10 @@ man_MANS = b10-dhcp4.8
 EXTRA_DIST = $(man_MANS) b10-dhcp4.xml dhcp4.spec
 
 if ENABLE_MAN
-
 b10-dhcp4.8: b10-dhcp4.xml
-	xsltproc --novalid --xinclude --nonet -o $@ http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $(srcdir)/b10-dhcp4.xml
-
+	xsltproc --novalid --xinclude --nonet -o $@ \
+        http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl \
+	$(srcdir)/b10-dhcp4.xml
 endif
 
 spec_config.h: spec_config.h.pre
@@ -37,7 +37,5 @@ b10_dhcp4_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
 b10_dhcp4_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
 b10_dhcp4_LDADD += $(top_builddir)/src/lib/log/liblog.la
 
-# TODO: config.h.in is wrong because doesn't honor pkgdatadir
-# and can't use @datadir@ because doesn't expand default ${prefix}
 b10_dhcp4dir = $(pkgdatadir)
 b10_dhcp4_DATA = dhcp4.spec

+ 7 - 9
src/bin/dhcp6/Makefile.am

@@ -2,9 +2,8 @@ SUBDIRS = . tests
 
 AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
 AM_CPPFLAGS += -I$(top_srcdir)/src/bin -I$(top_builddir)/src/bin
-AM_CPPFLAGS += -I$(top_srcdir)/src/lib/dns -I$(top_builddir)/src/lib/dns
 AM_CPPFLAGS += -I$(top_srcdir)/src/lib/cc -I$(top_builddir)/src/lib/cc
- AM_CPPFLAGS += $(BOOST_INCLUDES)
+AM_CPPFLAGS += $(BOOST_INCLUDES)
 
 AM_CXXFLAGS = $(B10_CXXFLAGS)
 
@@ -14,16 +13,17 @@ endif
 
 pkglibexecdir = $(libexecdir)/@PACKAGE@
 
-CLEANFILES = *.gcno *.gcda spec_config.h
+CLEANFILES = spec_config.h
 
 man_MANS = b10-dhcp6.8
-EXTRA_DIST = $(man_MANS) b10-dhcp6.xml dhcp6.spec interfaces.txt
+EXTRA_DIST = $(man_MANS) b10-dhcp6.xml dhcp6.spec
 
 if ENABLE_MAN
 
 b10-dhcp6.8: b10-dhcp6.xml
-	xsltproc --novalid --xinclude --nonet -o $@ http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $(srcdir)/b10-dhcp6.xml
-
+	xsltproc --novalid --xinclude --nonet -o $@ \
+        http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl \
+        $(srcdir)/b10-dhcp6.xml
 endif
 
 spec_config.h: spec_config.h.pre
@@ -39,7 +39,5 @@ b10_dhcp6_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
 b10_dhcp6_LDADD += $(top_builddir)/src/lib/log/liblog.la
 b10_dhcp6_LDADD += $(top_builddir)/src/lib/dhcp/libdhcp++.la
 
-# TODO: config.h.in is wrong because doesn't honor pkgdatadir
-# and can't use @datadir@ because doesn't expand default ${prefix}
 b10_dhcp6dir = $(pkgdatadir)
-b10_dhcp6_DATA = dhcp6.spec interfaces.txt
+b10_dhcp6_DATA = dhcp6.spec

+ 0 - 10
src/bin/dhcp6/interfaces.txt

@@ -1,10 +0,0 @@
-eth0 fe80::21e:8cff:fe9b:7349
-
-#
-# only first line is read.
-# please use following format:
-# interface-name link-local-ipv6-address
-#
-# This file will become obsolete once proper interface detection 
-# is implemented.
-#

+ 0 - 14
src/bin/dhcp6/tests/Makefile.am

@@ -1,23 +1,12 @@
 PYCOVERAGE_RUN = @PYCOVERAGE_RUN@
-#PYTESTS = args_test.py bind10_test.py
-# NOTE: this has a generated test found in the builddir
 PYTESTS = dhcp6_test.py
 EXTRA_DIST = $(PYTESTS)
 
-# If necessary (rare cases), explicitly specify paths to dynamic libraries
-# required by loadable python modules.
-LIBRARY_PATH_PLACEHOLDER =
-if SET_ENV_LIBRARY_PATH
-LIBRARY_PATH_PLACEHOLDER += $(ENV_LIBRARY_PATH)=$(abs_top_builddir)/src/lib/cryptolink/.libs:$(abs_top_builddir)/src/lib/dns/.libs:$(abs_top_builddir)/src/lib/dns/python/.libs:$(abs_top_builddir)/src/lib/cc/.libs:$(abs_top_builddir)/src/lib/config/.libs:$(abs_top_builddir)/src/lib/log/.libs:$(abs_top_builddir)/src/lib/util/.libs:$(abs_top_builddir)/src/lib/exceptions/.libs:$(abs_top_builddir)/src/lib/util/io/.libs:$(abs_top_builddir)/src/lib/datasrc/.libs:$$$(ENV_LIBRARY_PATH)
-endif
-
 # test using command-line arguments, so use check-local target instead of TESTS
 check-local:
 	for pytest in $(PYTESTS) ; do \
 	echo Running test: $$pytest ; \
 	PYTHONPATH=$(COMMON_PYTHON_PATH):$(abs_top_srcdir)/src/bin:$(abs_top_builddir)/src/bin/bind10:$(abs_top_builddir)/src/lib/util/io/.libs \
-	$(LIBRARY_PATH_PLACEHOLDER) \
-	BIND10_MSGQ_SOCKET_FILE=$(abs_top_builddir)/msgq_socket \
 		$(PYCOVERAGE_RUN) $(abs_srcdir)/$$pytest || exit ; \
 	done
 
@@ -26,8 +15,6 @@ AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
 AM_CPPFLAGS += -I$(top_builddir)/src/bin # for generated spec_config.h header
 AM_CPPFLAGS += -I$(top_srcdir)/src/bin
 AM_CPPFLAGS += $(BOOST_INCLUDES)
-AM_CPPFLAGS += -DTEST_DATA_DIR=\"$(abs_top_srcdir)/src/lib/testutils/testdata\"
-AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_top_builddir)/src/bin/dhcp6/tests\"
 AM_CPPFLAGS += -DINSTALL_PROG=\"$(abs_top_srcdir)/install-sh\"
 
 CLEANFILES = $(builddir)/interfaces.txt
@@ -50,7 +37,6 @@ dhcp6_unittests_SOURCES += dhcp6_srv_unittest.cc
 dhcp6_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
 dhcp6_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
 dhcp6_unittests_LDADD = $(GTEST_LDADD)
-dhcp6_unittests_LDADD += $(SQLITE_LIBS)
 dhcp6_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
 dhcp6_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libdhcp++.la
 dhcp6_unittests_LDADD += $(top_builddir)/src/lib/log/liblog.la

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

@@ -35,7 +35,6 @@ using namespace isc::util;
 // namespace has to be named, because friends are defined in Dhcpv6Srv class
 // Maybe it should be isc::test?
 namespace {
-const char* const INTERFACE_FILE = "interfaces.txt";
 
 class NakedDhcpv6Srv: public Dhcpv6Srv {
     // "naked" Interface Manager, exposes internal fields
@@ -54,18 +53,10 @@ public:
 
 class Dhcpv6SrvTest : public ::testing::Test {
 public:
+    // these are empty for now, but let's keep them around
     Dhcpv6SrvTest() {
-        unlink(INTERFACE_FILE);
-        fstream fakeifaces(INTERFACE_FILE, ios::out | ios::trunc);
-        if (if_nametoindex("lo") > 0) {
-            fakeifaces << "lo ::1";
-        } else if (if_nametoindex("lo0") > 0) {
-            fakeifaces << "lo0 ::1";
-        }
-        fakeifaces.close();
     }
     ~Dhcpv6SrvTest() {
-        unlink(INTERFACE_FILE);
     };
 };
 

+ 8 - 5
src/bin/dhcp6/tests/dhcp6_test.py

@@ -26,8 +26,14 @@ import isc
 
 class TestDhcpv6Daemon(unittest.TestCase):
     def setUp(self):
-        # redirect stdout to a pipe so we can check that our
-        # process spawning is doing the right thing with stdout
+
+        # Let's print this out before we redirect out stdout.
+        print("Please ignore any socket errors. Purpose of this test is to")
+        print("verify that DHCPv6 process could be started, not that socket")
+        print("could be bound. Binding fails when run as non-root user.")
+
+        # Redirect stdout to a pipe so we can check that our
+        # process spawning is doing the right thing with stdout.
         self.old_stdout = os.dup(sys.stdout.fileno())
         self.pipes = os.pipe()
         os.dup2(self.pipes[1], sys.stdout.fileno())
@@ -36,9 +42,6 @@ class TestDhcpv6Daemon(unittest.TestCase):
         # to the main program ASAP in each test... this prevents
         # hangs reading from the child process (as the pipe is only
         # open in the child), and also insures nice pretty output
-        print("Please ignore any socket errors. Purpose of this test is to")
-        print("verify that DHCPv6 process could be started, not that socket")
-        print("could be bound. Binding fails when run as non-root user.")
 
     def tearDown(self):
         # clean up our stdout munging

+ 28 - 18
src/lib/dhcp/iface_mgr.cc

@@ -18,6 +18,7 @@
 #include <string.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <net/if.h>
 
 #include <dhcp/dhcp4.h>
 #include <dhcp/dhcp6.h>
@@ -168,39 +169,48 @@ IfaceMgr::~IfaceMgr() {
 }
 
 void IfaceMgr::stubDetectIfaces() {
-    string ifaceName, linkLocal;
+    string ifaceName;
+    const string v4addr("127.0.0.1"), v6addr("::1");
 
     // This is a stub implementation for interface detection. Actual detection
-    // is faked by reading a text file. It will eventually be removed once
-    // we have actual implementations for all supported systems.
+    // is faked by detecting loopback interface (lo or lo0). It will eventually
+    // be removed once we have actual implementations for all supported systems.
 
-    cout << "Interface detection is not implemented yet. "
-         << "Reading interfaces.txt file instead." << endl;
-    cout << "Please use format: interface-name link-local-address" << endl;
+    cout << "Interface detection is not implemented on this Operating System yet. "
+         << endl;
 
     try {
-        ifstream interfaces("interfaces.txt");
-
-        if (!interfaces.good()) {
-            cout << "interfaces.txt file is not available. Stub interface detection skipped." << endl;
-            return;
+        if (if_nametoindex("lo") > 0) {
+            ifaceName = "lo";
+            // this is Linux-like OS
+        } else if (if_nametoindex("lo0") > 0) {
+            ifaceName = "lo0";
+            // this is BSD-like OS
+        } else {
+            // we give up. What OS is this, anyway? Solaris? Hurd?
+            isc_throw(NotImplemented,
+                      "Interface detection on this OS is not supported.");
         }
-        interfaces >> ifaceName;
-        interfaces >> linkLocal;
-
-        cout << "Detected interface " << ifaceName << "/" << linkLocal << endl;
 
         Iface iface(ifaceName, if_nametoindex(ifaceName.c_str()));
         iface.flag_up_ = true;
         iface.flag_running_ = true;
+
+        // note that we claim that this is not a loopback. iface_mgr tries to open a
+        // socket on all interaces that are up, running and not loopback. As this is
+        // the only interface we were able to detect, let's pretend this is a normal
+        // interface.
         iface.flag_loopback_ = false;
         iface.flag_multicast_ = true;
         iface.flag_broadcast_ = true;
         iface.setHWType(HWTYPE_ETHERNET);
-        IOAddress addr(linkLocal);
-        iface.addAddress(addr);
+
+        iface.addAddress(IOAddress(v4addr));
+        iface.addAddress(IOAddress(v6addr));
         addInterface(iface);
-        interfaces.close();
+
+        cout << "Detected interface " << ifaceName << "/" << v4addr << "/"
+             << v6addr << endl;
     } catch (const std::exception& ex) {
         // TODO: deallocate whatever memory we used
         // not that important, since this function is going to be

+ 0 - 1
src/lib/dhcp/tests/Makefile.am

@@ -2,7 +2,6 @@ SUBDIRS = .
 
 AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
 AM_CPPFLAGS += $(BOOST_INCLUDES)
-AM_CPPFLAGS += -DTEST_DATA_DIR=\"$(abs_top_srcdir)/src/lib/testutils/testdata\"
 AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_top_builddir)/src/lib/dhcp/tests\"
 AM_CPPFLAGS += -DINSTALL_PROG=\"$(abs_top_srcdir)/install-sh\"
 

+ 12 - 61
src/lib/dhcp/tests/iface_mgr_unittest.cc

@@ -35,7 +35,6 @@ const size_t buf_size = 32;
 char LOOPBACK[buf_size] = "lo";
 
 namespace {
-const char* const INTERFACE_FILE = TEST_DATA_BUILDDIR "/interfaces.txt";
 
 class NakedIfaceMgr: public IfaceMgr {
     // "naked" Interface Manager, exposes internal fields
@@ -47,18 +46,11 @@ public:
 // dummy class for now, but this will be expanded when needed
 class IfaceMgrTest : public ::testing::Test {
 public:
+    // these are empty for now, but let's keep them around
     IfaceMgrTest() {
     }
 
-    void createLoInterfacesTxt() {
-        unlink(INTERFACE_FILE);
-        fstream fakeifaces(INTERFACE_FILE, ios::out|ios::trunc);
-        fakeifaces << LOOPBACK << " ::1";
-        fakeifaces.close();
-    }
-
     ~IfaceMgrTest() {
-        unlink(INTERFACE_FILE);
     }
 };
 
@@ -151,9 +143,6 @@ TEST_F(IfaceMgrTest, dhcp6Sniffer) {
 
 TEST_F(IfaceMgrTest, basic) {
     // checks that IfaceManager can be instantiated
-    createLoInterfacesTxt();
-
-    createLoInterfacesTxt();
 
     IfaceMgr & ifacemgr = IfaceMgr::instance();
     ASSERT_TRUE(&ifacemgr != 0);
@@ -173,16 +162,17 @@ TEST_F(IfaceMgrTest, ifaceClass) {
 // is implemented.
 TEST_F(IfaceMgrTest, getIface) {
 
-    createLoInterfacesTxt();
-
     cout << "Interface checks. Please ignore socket binding errors." << endl;
     NakedIfaceMgr* ifacemgr = new NakedIfaceMgr();
 
     // interface name, ifindex
-    IfaceMgr::Iface iface1("lo1", 1);
-    IfaceMgr::Iface iface2("eth5", 2);
-    IfaceMgr::Iface iface3("en3", 5);
-    IfaceMgr::Iface iface4("e1000g0", 3);
+    IfaceMgr::Iface iface1("lo1", 100);
+    IfaceMgr::Iface iface2("eth9", 101);
+    IfaceMgr::Iface iface3("en3", 102);
+    IfaceMgr::Iface iface4("e1000g4", 103);
+    cout << "This test assumes that there are less than 100 network interfaces"
+         << " in the tested system and there are no lo1, eth9, en3, e1000g4"
+         << " or wifi15 interfaces present." << endl;
 
     // note: real interfaces may be detected as well
     ifacemgr->getIfacesLst().push_back(iface1);
@@ -200,65 +190,30 @@ TEST_F(IfaceMgrTest, getIface) {
 
 
     // check that interface can be retrieved by ifindex
-    IfaceMgr::Iface* tmp = ifacemgr->getIface(5);
-    // ASSERT_NE(NULL, tmp); is not supported. hmmmm.
+    IfaceMgr::Iface* tmp = ifacemgr->getIface(102);
     ASSERT_TRUE(tmp != NULL);
 
     EXPECT_EQ("en3", tmp->getName());
-    EXPECT_EQ(5, tmp->getIndex());
+    EXPECT_EQ(102, tmp->getIndex());
 
     // check that interface can be retrieved by name
     tmp = ifacemgr->getIface("lo1");
     ASSERT_TRUE(tmp != NULL);
 
     EXPECT_EQ("lo1", tmp->getName());
-    EXPECT_EQ(1, tmp->getIndex());
+    EXPECT_EQ(100, tmp->getIndex());
 
     // check that non-existing interfaces are not returned
-    EXPECT_EQ(static_cast<void*>(NULL), ifacemgr->getIface("wifi0") );
+    EXPECT_EQ(static_cast<void*>(NULL), ifacemgr->getIface("wifi15") );
 
     delete ifacemgr;
 
 }
 
-#if !defined(OS_LINUX)
-TEST_F(IfaceMgrTest, detectIfaces_stub) {
-
-    // test detects that interfaces can be detected
-    // there is no code for that now, but interfaces are
-    // read from file
-    fstream fakeifaces(INTERFACE_FILE, ios::out|ios::trunc);
-    fakeifaces << "eth0 fe80::1234";
-    fakeifaces.close();
-
-    // this is not usable on systems that don't have eth0
-    // interfaces. Nevertheless, this fake interface should
-    // be on list, but if_nametoindex() will fail.
-
-    NakedIfaceMgr* ifacemgr = new NakedIfaceMgr();
-
-    ASSERT_TRUE(ifacemgr->getIface("eth0") != NULL);
-
-    IfaceMgr::Iface* eth0 = ifacemgr->getIface("eth0");
-
-    // there should be one address
-    IfaceMgr::AddressCollection addrs = eth0->getAddresses();
-    ASSERT_EQ(1, addrs.size());
-
-    IOAddress addr = *addrs.begin();
-
-    EXPECT_STREQ("fe80::1234", addr.toText().c_str());
-
-    delete ifacemgr;
-}
-#endif
-
 TEST_F(IfaceMgrTest, sockets6) {
     // testing socket operation in a portable way is tricky
     // without interface detection implemented
 
-    createLoInterfacesTxt();
-
     NakedIfaceMgr* ifacemgr = new NakedIfaceMgr();
 
     IOAddress loAddr("::1");
@@ -320,7 +275,6 @@ TEST_F(IfaceMgrTest, sendReceive6) {
 
     // testing socket operation in a portable way is tricky
     // without interface detection implemented
-    createLoInterfacesTxt();
 
     NakedIfaceMgr* ifacemgr = new NakedIfaceMgr();
 
@@ -378,7 +332,6 @@ TEST_F(IfaceMgrTest, sendReceive4) {
 
     // testing socket operation in a portable way is tricky
     // without interface detection implemented
-    createLoInterfacesTxt();
 
     NakedIfaceMgr* ifacemgr = new NakedIfaceMgr();
 
@@ -469,7 +422,6 @@ TEST_F(IfaceMgrTest, sendReceive4) {
 
 TEST_F(IfaceMgrTest, socket4) {
 
-    createLoInterfacesTxt();
     NakedIfaceMgr* ifacemgr = new NakedIfaceMgr();
 
     // Let's assume that every supported OS have lo interface.
@@ -585,7 +537,6 @@ TEST_F(IfaceMgrTest, socketInfo) {
     EXPECT_EQ(DHCP4_SERVER_PORT + 9, sock2.port_);
 
     // now let's test if IfaceMgr handles socket info properly
-    createLoInterfacesTxt();
     NakedIfaceMgr* ifacemgr = new NakedIfaceMgr();
     IfaceMgr::Iface* loopback = ifacemgr->getIface(LOOPBACK);
     ASSERT_TRUE(loopback);