Browse Source

[2765] Fixed failing unit tests for the raw sockets using LPF.

Marcin Siodelski 11 years ago
parent
commit
721815f9c7
2 changed files with 20 additions and 8 deletions
  1. 10 3
      src/lib/dhcp/pkt_filter_lpf.cc
  2. 10 5
      src/lib/dhcp/tests/pkt_filter_lpf_unittest.cc

+ 10 - 3
src/lib/dhcp/pkt_filter_lpf.cc

@@ -230,9 +230,16 @@ PktFilterLPF::send(const Iface& iface, uint16_t sockfd, const Pkt4Ptr& pkt) {
 
     OutputBuffer buf(14);
 
-    HWAddrPtr hwaddr(new HWAddr(iface.getMac(), iface.getMacLen(),
-                                iface.getHWType()));
-    pkt->setLocalHWAddr(hwaddr);
+    // Some interfaces may have no HW address - e.g. loopback interface.
+    // For these interfaces the HW address length is 0. If this is the case,
+    // then we will rely on the functions which construct the IP/UDP headers
+    // to provide a default HW addres. Otherwise, create the HW address
+    // object using the HW address of the interface.
+    if (iface.getMacLen() > 0) {
+        HWAddrPtr hwaddr(new HWAddr(iface.getMac(), iface.getMacLen(),
+                                    iface.getHWType()));
+        pkt->setLocalHWAddr(hwaddr);
+    }
 
 
     // Ethernet frame header.

+ 10 - 5
src/lib/dhcp/tests/pkt_filter_lpf_unittest.cc

@@ -183,7 +183,11 @@ TEST_F(PktFilterLPFTest, DISABLED_send) {
     // Open socket. We don't check that the socket has appropriate
     // options and family set because we have checked that in the
     // openSocket test already.
-    socket_ = pkt_filter.openSocket(iface, addr, PORT, false, false).sockfd_;
+
+    SocketInfo sock_info =
+        pkt_filter.openSocket(iface, addr, PORT, false, false);
+    socket_ = sock_info.sockfd_;
+
     ASSERT_GE(socket_, 0);
 
     // Send the packet over the socket.
@@ -193,7 +197,7 @@ TEST_F(PktFilterLPFTest, DISABLED_send) {
     fd_set readfds;
     FD_ZERO(&readfds);
     FD_SET(socket_, &readfds);
-    
+
     struct timeval timeout;
     timeout.tv_sec = 5;
     timeout.tv_usec = 0;
@@ -273,15 +277,16 @@ TEST_F(PktFilterLPFTest, DISABLED_receive) {
     // Open socket. We don't check that the socket has appropriate
     // options and family set because we have checked that in the
     // openSocket test already.
-    socket_ = pkt_filter.openSocket(iface, addr, PORT, false, false).sockfd_;
+    SocketInfo sock_info =
+        pkt_filter.openSocket(iface, addr, PORT, false, false);
+    socket_ = sock_info.sockfd_;
     ASSERT_GE(socket_, 0);
 
     // Send the packet over the socket.
     ASSERT_NO_THROW(pkt_filter.send(iface, socket_, pkt));
 
     // Receive the packet.
-    SocketInfo socket_info(socket_, IOAddress("127.0.0.1"), PORT);
-    Pkt4Ptr rcvd_pkt = pkt_filter.receive(iface, socket_info);
+    Pkt4Ptr rcvd_pkt = pkt_filter.receive(iface, sock_info);
     // Check that the packet has been correctly received.
     ASSERT_TRUE(rcvd_pkt);