From: Tomek Mrugalski Date: Tue, 20 Dec 2011 16:14:30 +0000 (+0100) Subject: Merge branch 'trac1239' into trac1230 X-Git-Tag: trac2351_base~310^2~13^2~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f60bf56ebed7189ad71d6c4ed4044d97b5e5c7a5;p=thirdparty%2Fkea.git Merge branch 'trac1239' into trac1230 Conflicts: ChangeLog src/bin/dhcp4/dhcp4_srv.cc src/bin/dhcp6/dhcp6_srv.cc src/lib/dhcp/iface_mgr.cc src/lib/dhcp/iface_mgr.h --- f60bf56ebed7189ad71d6c4ed4044d97b5e5c7a5 diff --cc ChangeLog index 5109c2692b,3555732242..2fd0c047c6 --- a/ChangeLog +++ b/ChangeLog @@@ -1,9 -1,11 +1,17 @@@ +3XX. [func] tomek + libdhcp++: Interface detection in Linux implemented. libdhcp++ + if now able to detect available network interfaces, its link-layer + addresses, flags and configured IPv4 and IPv6 addresses. + (Trac #1237, git TBD) + + 3XX. [func] tomek + libdhcp++: Transmission and reception of DHCPv4 packets is now + implemented. Low-level hacks are not implemented for transmission + to hosts that don't have IPv4 address yet, so currently the code + is usable for communication with relays only, not hosts on the + same link. + (Trac #1239, #1240, git TBD) + 349. [bug] dvv resolver: If an upstream server responds with FORMERR to an EDNS query, try querying it without EDNS. diff --cc src/bin/dhcp4/dhcp4_srv.cc index 0a1aabad90,d4cae5c9ff..9e290594c2 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@@ -33,10 -35,7 +35,8 @@@ Dhcpv4Srv::Dhcpv4Srv(uint16_t port) /// @todo: instantiate LeaseMgr here once it is imlpemented. IfaceMgr::instance().printIfaces(); - #if 0 + // uncomment this once #1238, #992 and #1239 are merged IfaceMgr::instance().openSockets4(port); - #endif setServerID(); diff --cc src/bin/dhcp6/dhcp6_srv.cc index 9e77f8c548,c559d8cbb3..7d1b549bdc --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@@ -27,28 -27,16 +27,24 @@@ using namespace isc::dhcp using namespace isc::asiolink; Dhcpv6Srv::Dhcpv6Srv(uint16_t port) { - -//void Dhcpv6Srv::Dhcpv6Srv_impl(uint16_t port) { cout << "Initialization" << endl; - // First call to instance() will create IfaceMgr (it's a singleton). - // It may throw something if things go wrong. - IfaceMgr::instance(); + // first call to instance() will create IfaceMgr (it's a singleton) + // it may throw something if things go wrong + try { + IfaceMgr::instance(); + } catch (const std::exception &e) { + cout << "Failed to instantiate InterfaceManager:" << e.what() << ". Aborting." << endl; + shutdown = true; + } + + if (IfaceMgr::instance().countIfaces() == 0) { + cout << "Failed to detect any network interfaces. Aborting." << endl; + shutdown = true; + } // Now try to open IPv6 sockets on detected interfaces. - cout << "Opening sockets on port " << port << endl; - #if 0 - // uncomment this once #1238, #992 and #1239 are merged IfaceMgr::instance().openSockets6(port); - #endif /// @todo: instantiate LeaseMgr here once it is imlpemented. diff --cc src/lib/dhcp/iface_mgr.cc index 770296f0ba,bb8981386d..e3e2a4a6bf --- a/src/lib/dhcp/iface_mgr.cc +++ b/src/lib/dhcp/iface_mgr.cc @@@ -194,17 -192,23 +195,27 @@@ IfaceMgr::stubDetectIfaces() } } +#if !defined(OS_LINUX) && !defined(OS_BSD) +void IfaceMgr::detectIfaces() { + stubDetectIfaces(); +} +#endif + - void IfaceMgr::openSockets6(uint16_t port) { - int sock1, sock2; + bool IfaceMgr::openSockets4(uint16_t port) { + int sock; + int count = 0; - for (IfaceCollection::iterator iface = ifaces_.begin(); - iface != ifaces_.end(); ++iface) { + for (IfaceCollection::iterator iface=ifaces_.begin(); + iface!=ifaces_.end(); + ++iface) { + + cout << "Trying interface " << iface->getFullName() << endl; + -#if 0 + if (iface->flag_loopback_ || + !iface->flag_up_ || + !iface->flag_running_) { + continue; + } -#endif AddressCollection addrs = iface->getAddresses(); diff --cc src/lib/dhcp/iface_mgr.h index 654b8b7bab,e937967045..7caba8ca35 --- a/src/lib/dhcp/iface_mgr.h +++ b/src/lib/dhcp/iface_mgr.h @@@ -325,23 -295,27 +327,28 @@@ public int openSocket(const std::string& ifname, const isc::asiolink::IOAddress& addr, int port); - /// Opens IPv4 sockets on detected interfaces. - /// Opens IPv6 sockets on detected interfaces. -- /// -- /// Will throw exception if socket creation fails. - /// + /// @param port specifies port number (usually DHCP6_SERVER_PORT) /// - /// @param port specifies port number (usually DHCP4_SERVER_PORT) - void openSockets4(uint16_t port); - + /// @return true if any sockets were open + bool openSockets6(uint16_t port = DHCP6_SERVER_PORT); /// @brief Closes all open sockets. /// Is used in destructor, but also from Dhcpv4_srv and Dhcpv6_srv classes. void closeSockets(); + /// @brief returns number of detected interfaces + /// + /// @return number of detected interfaces + uint16_t countIfaces() { return ifaces_.size(); } + + /// Opens IPv4 sockets on detected interfaces. + /// Will throw exception if socket creation fails. + /// - /// @param port specifies port number (usually DHCP6_SERVER_PORT) ++ /// @param port specifies port number (usually DHCP4_SERVER_PORT) + /// + /// @return true if any sockets were open + bool openSockets4(uint16_t port = DHCP4_SERVER_PORT); + // don't use private, we need derived classes in tests protected: diff --cc src/lib/dhcp/tests/iface_mgr_unittest.cc index 06e9df0be8,9ccc55d1ab..2e326bc1ba --- a/src/lib/dhcp/tests/iface_mgr_unittest.cc +++ b/src/lib/dhcp/tests/iface_mgr_unittest.cc @@@ -210,10 -217,10 +217,11 @@@ TEST_F(IfaceMgrTest, getIface) EXPECT_EQ(static_cast(NULL), ifacemgr->getIface("wifi0") ); delete ifacemgr; + } -TEST_F(IfaceMgrTest, detectIfaces) { +#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