Browse Source

[1239] DHCPv4 echo server implemented.

Tomek Mrugalski 13 years ago
parent
commit
e96109294e
3 changed files with 21 additions and 2 deletions
  1. 5 2
      src/bin/dhcp4/dhcp4_srv.cc
  2. 8 0
      src/lib/dhcp/pkt4.cc
  3. 8 0
      src/lib/dhcp/pkt4.h

+ 5 - 2
src/bin/dhcp4/dhcp4_srv.cc

@@ -50,9 +50,12 @@ Dhcpv4Srv::run() {
         boost::shared_ptr<Pkt4> query; // client's message
         boost::shared_ptr<Pkt4> rsp;   // server's response
 
-#if 1
-        // uncomment this once ticket 1239 is merged.
         query = IfaceMgr::instance().receive4();
+
+#if ECHO_SERVER
+	query->repack();
+        IfaceMgr::instance().send(query);
+        continue;
 #endif
 
         if (query) {

+ 8 - 0
src/lib/dhcp/pkt4.cc

@@ -156,6 +156,14 @@ Pkt4::unpack() {
     return (true);
 }
 
+void Pkt4::repack() {
+  cout << "Convering RX packet to TX packet: " << bufferIn_.getLength() << " bytes." << endl;
+
+  vector<uint8_t> buf;
+  bufferIn_.readVector(buf, bufferIn_.getLength());
+  bufferOut_.writeData(&buf[0], bufferIn_.getLength());
+}
+
 std::string
 Pkt4::toText() {
     stringstream tmp;

+ 8 - 0
src/lib/dhcp/pkt4.h

@@ -78,6 +78,14 @@ public:
     bool
     unpack();
 
+    /// @brief Copies content of input buffer to output buffer.
+    ///
+    /// This is mostly a diagnostic function. It is being used for sending
+    /// received packet. Received packet is stored in bufferIn_, but
+    /// transmitted data is stored in bufferOut_. If we want to send packet
+    /// that we just received, a copy between those two buffers is necessary.
+    void repack();
+
     /// @brief Returns text representation of the packet.
     ///
     /// This function is useful mainly for debugging.