]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
Merge branch 'trac1239' into trac1230
authorTomek Mrugalski <tomasz@isc.org>
Tue, 20 Dec 2011 16:14:30 +0000 (17:14 +0100)
committerTomek Mrugalski <tomasz@isc.org>
Tue, 20 Dec 2011 16:14:30 +0000 (17:14 +0100)
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

1  2 
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
src/lib/dhcp/tests/iface_mgr_unittest.cc

diff --cc ChangeLog
index 5109c2692b89d0faf0b2b01bf166c5a66eb1d94f,355573224251fe25f78a15a7b4cabe679f0fa149..2fd0c047c6f6b8cc886d0a01a33ca50f9d3ffc89
+++ 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.
index 0a1aabad905194c639a7412cb57b526ec27ef9e9,d4cae5c9ffba401b8a2bdd038ad9827be4b68d3a..9e290594c299dc2b6c4aa8073ccebfe0a187c68a
@@@ -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();
  
index 9e77f8c54821e3d0ea63d5f37d62455d071e9214,c559d8cbb38f8cab3e6c618d4ad7d287c69a50c8..7d1b549bdcbb47f265a1f5a58221177fde967d0a
@@@ -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.
  
index 770296f0ba8988a67c7b6e5d69e586c8472de1e2,bb8981386d58b5d9873763a0327f7283b1be499c..e3e2a4a6bfd52bc929fbc72fc8ce6c0c3c840847
@@@ -194,17 -192,23 +195,27 @@@ IfaceMgr::stubDetectIfaces() 
      }
  }
  
- void IfaceMgr::openSockets6(uint16_t port) {
-     int sock1, sock2;
 +#if !defined(OS_LINUX) && !defined(OS_BSD)
 +void IfaceMgr::detectIfaces() {
 +    stubDetectIfaces();
 +}
 +#endif
 +
+ 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();
  
index 654b8b7baba8caabc41c79030b305b8d7e7eba65,e937967045883a0e05a8dc1b97cc3171e81f5c41..7caba8ca3501a76eedf2233dc1f53a9207f57d06
@@@ -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();
  
 -    /// @param port specifies port number (usually DHCP6_SERVER_PORT)
 +    /// @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 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:
  
index 06e9df0be897145c13b36b368fcc06ba272d8da0,9ccc55d1ab610b7eb943ff8d8c2133fb9cfedf22..2e326bc1ba675ab8d6dba6c8f2a79e3dcdc00403
@@@ -210,10 -217,10 +217,11 @@@ TEST_F(IfaceMgrTest, getIface) 
      EXPECT_EQ(static_cast<void*>(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