]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2902] Do not use the broadcast address as source in server's response.
authorMarcin Siodelski <marcin@isc.org>
Thu, 25 Apr 2013 18:42:53 +0000 (20:42 +0200)
committerMarcin Siodelski <marcin@isc.org>
Thu, 25 Apr 2013 18:42:53 +0000 (20:42 +0200)
src/lib/dhcp/pkt_filter_lpf.cc
src/lib/dhcp/tests/pkt_filter_lpf_unittest.cc

index 62022198bee049d0c0873fc001e98bbc58458f4f..a86be04e0dc2c358fa78ea9d2b9110fb11351487 100644 (file)
@@ -110,6 +110,20 @@ PktFilterLPF::send(const Iface& iface, uint16_t sockfd, const Pkt4Ptr& pkt) {
     }
     writeEthernetHeader(iface.getMac(), &dest_addr[0], buf);
 
+    // It is likely that the local address in pkt object is set to
+    // broadcast address. This is the case if server received the
+    // client's packet on broadcast address. Therefore, we need to
+    // correct it here and assign the actual source address.
+    if (pkt->getLocalAddr().toText() == "255.255.255.255") {
+        const Iface::SocketCollection& sockets = iface.getSockets();
+        for (Iface::SocketCollection::const_iterator it = sockets.begin();
+             it != sockets.end(); ++it) {
+            if (sockfd == it->sockfd_) {
+                pkt->setLocalAddr(it->addr_);
+            }
+        }
+    }
+
     // IP and UDP header
     writeIpUdpHeader(pkt, buf);
 
index d74c3a75b1ec46382486b3a7cf2cdc92f34aa7b9..dd9884079650fe24da15168cdb2ebf62dc471b00 100644 (file)
@@ -139,7 +139,12 @@ TEST_F(PktFilterLPFTest, DISABLED_send) {
     ASSERT_TRUE(pkt);
 
     // Set required fields.
-    pkt->setLocalAddr(IOAddress("127.0.0.1"));
+    // By setting the local address to broadcast we simulate the
+    // typical scenario when client's request was send to broadcast
+    // address and server by default used it as a source address
+    // in its response. The send() function should be able to detect
+    // it and correct the source address.
+    pkt->setLocalAddr(IOAddress("255.255.255.255"));
     pkt->setRemotePort(PORT);
     pkt->setLocalPort(PORT + 1);
     pkt->setIndex(ifindex_);