Browse Source

[1238] IPv4 socket cleanup in IfaceMgr

Tomek Mrugalski 13 years ago
parent
commit
cbe600decb
2 changed files with 18 additions and 33 deletions
  1. 15 31
      src/bin/dhcp6/iface_mgr.cc
  2. 3 2
      src/bin/dhcp6/tests/iface_mgr_unittest.cc

+ 15 - 31
src/bin/dhcp6/iface_mgr.cc

@@ -300,42 +300,16 @@ IfaceMgr::openSocket4(Iface& iface, const IOAddress& addr, int port) {
                   << "/port=" << port);
     }
 
-#if defined(SO_BINDTODEVICE)
-#if 0
-    /// For some reason that doesn't work. It's not a big deal as this is
-    /// Linux only feature. We can use IP_PKTINFO to check that we received
-    /// packet over proper interface.
-
-    // Bind this socket to this interface.
-    const char* ifname = iface.getName().c_str();
-    int len = strlen(ifname);
-    if (setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE,
-                   ifname, len) < 0) {
-        isc_throw(Unexpected, "setsockopt: SO_BINDTODEVICE failed.");
-    }
-#endif
-#endif
-
+    // if there is no support for IP_PKTINFO, we are really out of luck
+    // it will be difficult to undersand, where this packet came from
+#if defined(IP_PKTINFO)
     int flag = 1;
-#ifdef IP_RECVPKTINFO
-    if (setsockopt(sock, IPPROTO_IP, IP_RECVPKTINFO,
-                   &flag, sizeof(flag)) != 0) {
-        close(sock);
-        isc_throw(Unexpected, "setsockopt: IP_RECVPKTINFO failed.")
-    }
-#elif defined(IP_PKTINFO)
-    /* RFC2292 - an old way */
-    if (setsockopt(sock, IPPROTO_IP, IP_PKTINFO,
-                   &flag, sizeof(flag)) != 0) {
+    if (setsockopt(sock, IPPROTO_IP, IP_PKTINFO, &flag, sizeof(flag)) != 0) {
         close(sock);
         isc_throw(Unexpected, "setsockopt: IP_PKTINFO: failed.");
     }
-#else
-    // "Neither IP_RECVPKTINFO nor IP_PKTINFO defined. Cannot continue"
-    flag = 1; // just to avoid compilation warnings about unused flag variable
 #endif
 
-
     cout << "Created socket " << sock << " on " << iface.getName() << "/" <<
         addr.toText() << "/port=" << port << endl;
 
@@ -528,9 +502,19 @@ IfaceMgr::send(boost::shared_ptr<Pkt6>& pkt) {
     return (result);
 }
 
+bool
+IfaceMgr::send(boost::shared_ptr<Pkt4>& )
+{
+    /// TODO: Implement this (ticket #1240)
+    isc_throw(Unexpected, "Pkt4 send not implemented yet.");
+}
+
+
 boost::shared_ptr<Pkt4>
 IfaceMgr::receive4() {
-    // TODO: To be implemented
+    isc_throw(Unexpected, "Pkt4 reception not implemented yet.");
+
+    // TODO: To be implemented (ticket #1239)
     return (boost::shared_ptr<Pkt4>()); // NULL
 }
 

+ 3 - 2
src/bin/dhcp6/tests/iface_mgr_unittest.cc

@@ -371,9 +371,9 @@ TEST_F(IfaceMgrTest, socket4) {
     createLoInterfacesTxt();
     NakedIfaceMgr* ifacemgr = new NakedIfaceMgr();
 
-    // let's assume that every supported OS have lo interface
+    // Let's assume that every supported OS have lo interface.
     IOAddress loAddr("127.0.0.1");
-    // use unprivileged port (it's convenient for running tests as non-root)
+    // Use unprivileged port (it's convenient for running tests as non-root).
     int socket1 = 0;
 
     EXPECT_NO_THROW(
@@ -385,6 +385,7 @@ TEST_F(IfaceMgrTest, socket4) {
     Pkt4 pkt(DHCPDISCOVER, 1234);
     pkt.setIface(LOOPBACK);
 
+    // Expect that we get the socket that we just opened.
     EXPECT_EQ(socket1, ifacemgr->getSocket(pkt));
 
     close(socket1);