]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2902] Set valid destination HW address when replying to the DHCP4 client.
authorMarcin Siodelski <marcin@isc.org>
Mon, 29 Apr 2013 17:05:22 +0000 (19:05 +0200)
committerMarcin Siodelski <marcin@isc.org>
Mon, 29 Apr 2013 17:05:22 +0000 (19:05 +0200)
src/bin/dhcp4/dhcp4_srv.cc
src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
src/lib/dhcp/pkt_filter_lpf.cc

index b0908bb75497b810fe19f8058de9638bcbc45af8..41233e2f4e867ec26f97f20c67197100cbd8b293 100644 (file)
@@ -371,6 +371,17 @@ Dhcpv4Srv::copyDefaultFields(const Pkt4Ptr& question, Pkt4Ptr& answer) {
     if (client_id) {
         answer->addOption(client_id);
     }
+
+    // If src/dest HW addresses are used by the packet filtering class
+    // we need to copy them as well.
+    HWAddrPtr src_hw_addr = question->getLocalHWAddr();
+    HWAddrPtr dst_hw_addr = question->getRemoteHWAddr();
+    if (src_hw_addr) {
+        answer->setRemoteHWAddr(src_hw_addr);
+    }
+    if (dst_hw_addr) {
+        answer->setLocalHWAddr(dst_hw_addr);
+    }
 }
 
 void
index daa94d72fa5e1c2f4346732b8e732e4fe620aa30..f74c2408d5f3245025ae71fe2e7e53b2edc2cc8d 100644 (file)
@@ -173,6 +173,11 @@ public:
         EXPECT_EQ(q->getIface(),  a->getIface());
         EXPECT_EQ(q->getIndex(),  a->getIndex());
         EXPECT_EQ(q->getGiaddr(), a->getGiaddr());
+        // When processing an incoming packet the remote address
+        // is copied as a src address, and the source address is
+        // copied as a remote address to the response.
+        EXPECT_TRUE(q->getLocalHWAddr() == a->getRemoteHWAddr());
+        EXPECT_TRUE(q->getRemoteHWAddr() == a->getLocalHWAddr());
 
         // Check that bare minimum of required options are there.
         // We don't check options requested by a client. Those
@@ -374,12 +379,19 @@ public:
             mac[i] = i*10;
         }
 
+        vector<uint8_t> dst_mac(6);
+        for (int i = 0; i < 6; i++) {
+            dst_mac[i] = i * 20;
+        }
+
         boost::shared_ptr<Pkt4> req(new Pkt4(msg_type, 1234));
         boost::shared_ptr<Pkt4> rsp;
 
         req->setIface("eth0");
         req->setIndex(17);
+        req->setRemoteHWAddr(1, 6, dst_mac);
         req->setHWAddr(1, 6, mac);
+        req->setLocalHWAddr(1, 6, mac);
         req->setRemoteAddr(IOAddress(client_addr));
         req->setGiaddr(relay_addr);
 
index beffa8b8fffea758b9145d5f40e0bead2bbdcb79..59637078dc331bf1289fbdd3c0cf2e470b5b61ae 100644 (file)
@@ -153,6 +153,8 @@ PktFilterLPF::receive(const Iface& iface, const SocketInfo& socket_info) {
     pkt->setRemoteAddr(dummy_pkt->getRemoteAddr());
     pkt->setLocalPort(dummy_pkt->getLocalPort());
     pkt->setRemotePort(dummy_pkt->getRemotePort());
+    pkt->setLocalHWAddr(dummy_pkt->getLocalHWAddr());
+    pkt->setRemoteHWAddr(dummy_pkt->getRemoteHWAddr());
 
     return (pkt);
 }
@@ -163,9 +165,12 @@ PktFilterLPF::send(const Iface& iface, uint16_t sockfd, const Pkt4Ptr& pkt) {
     OutputBuffer buf(14);
 
     // Ethernet frame header
-    std::vector<uint8_t> dest_addr = pkt->getHWAddr()->hwaddr_;
-    if (dest_addr.empty()) {
+    HWAddrPtr hwaddr = pkt->getRemoteHWAddr();
+    std::vector<uint8_t> dest_addr;
+    if (!hwaddr) {
         dest_addr.resize(HWAddr::ETHERNET_HWADDR_LEN);
+    } else {
+        dest_addr = pkt->getRemoteHWAddr()->hwaddr_;
     }
     writeEthernetHeader(iface.getMac(), &dest_addr[0], buf);