BIND 10 trac1230, updated. 3344e8b8d949fa9b4bcd9cf007f6a234f0fa5b1c [1230] Changes after review:

BIND 10 source code commits bind10-changes at lists.isc.org
Tue Dec 27 11:50:10 UTC 2011


The branch, trac1230 has been updated
       via  3344e8b8d949fa9b4bcd9cf007f6a234f0fa5b1c (commit)
       via  a9f48f11eda70e641b4c4624eef4dbada03828ff (commit)
      from  01a1b2f4d210c62fc1d7a9b53e7967057e93d331 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 3344e8b8d949fa9b4bcd9cf007f6a234f0fa5b1c
Author: Tomek Mrugalski <tomasz at isc.org>
Date:   Tue Dec 27 12:49:43 2011 +0100

    [1230] Changes after review:
    
    - Vector initialization clean-ups
    - Typo in comment

commit a9f48f11eda70e641b4c4624eef4dbada03828ff
Author: Tomek Mrugalski <tomasz at isc.org>
Date:   Fri Dec 23 17:26:24 2011 +0100

    [1230] Changes after review:
    
    - appendRequestedOptions(), assignLease() added in dhcpv4_srv class.
    - dhcpv4_srv now uses hardcoded values from 192.0.2.0/24 range.

-----------------------------------------------------------------------

Summary of changes:
 src/bin/dhcp4/dhcp4_srv.cc                |  114 +++++++++++------------------
 src/bin/dhcp4/dhcp4_srv.h                 |   23 ++++++
 src/bin/dhcp4/tests/dhcp4_srv_unittest.cc |    6 +-
 src/lib/dhcp/pkt4.cc                      |    2 +-
 4 files changed, 70 insertions(+), 75 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc
index 268cc9b..c42ceb3 100644
--- a/src/bin/dhcp4/dhcp4_srv.cc
+++ b/src/bin/dhcp4/dhcp4_srv.cc
@@ -28,13 +28,13 @@ using namespace isc::asiolink;
 
 // These are hardcoded parameters. Currently this is a skeleton server that only
 // grants those options and a single, fixed, hardcoded lease.
-const std::string HARDCODED_LEASE = "10.3.2.222"; // assigned lease
+const std::string HARDCODED_LEASE = "192.0.2.222"; // assigned lease
 const std::string HARDCODED_NETMASK = "255.255.255.0";
 const uint32_t    HARDCODED_LEASE_TIME = 60; // in seconds
-const std::string HARDCODED_GATEWAY = "10.3.2.2";
-const std::string HARDCODED_DNS_SERVER = "8.8.8.8";
-const std::string HARDCODED_DOMAIN_NAME = "isc.example.org";
-const std::string HARDCODED_SERVER_ID = "10.3.1.1";
+const std::string HARDCODED_GATEWAY = "192.0.2.1";
+const std::string HARDCODED_DNS_SERVER = "192.0.2.2";
+const std::string HARDCODED_DOMAIN_NAME = "isc.example.com";
+const std::string HARDCODED_SERVER_ID = "192.0.2.1";
 
 Dhcpv4Srv::Dhcpv4Srv(uint16_t port) {
     cout << "Initialization: opening sockets on port " << port << endl;
@@ -169,9 +169,8 @@ void Dhcpv4Srv::copyDefaultFields(const boost::shared_ptr<Pkt4>& question,
     answer->setHops(question->getHops());
 
     // copy MAC address
-    vector<uint8_t> mac;
-    mac.resize(Pkt4::MAX_CHADDR_LEN);
-    memcpy(&mac[0], question->getChaddr(), Pkt4::MAX_CHADDR_LEN);
+    vector<uint8_t> mac(question->getChaddr(),
+                        question->getChaddr() + Pkt4::MAX_CHADDR_LEN);
     answer->setHWAddr(question->getHtype(), question->getHlen(), mac);
 
     // relay address
@@ -188,62 +187,71 @@ void Dhcpv4Srv::copyDefaultFields(const boost::shared_ptr<Pkt4>& question,
 }
 
 void Dhcpv4Srv::appendDefaultOptions(boost::shared_ptr<Pkt4>& msg, uint8_t msg_type) {
+    boost::shared_ptr<Option> opt;
 
     // add Message Type Option (type 53)
-    boost::shared_ptr<Option> opt;
     std::vector<uint8_t> tmp;
     tmp.push_back(static_cast<uint8_t>(msg_type));
     opt = boost::shared_ptr<Option>(new Option(Option::V4, DHO_DHCP_MESSAGE_TYPE, tmp));
     msg->addOption(opt);
 
+    // DHCP Server Identifier (type 54)
+    opt = boost::shared_ptr<Option>
+        (new Option4AddrLst(DHO_DHCP_SERVER_IDENTIFIER, IOAddress(HARDCODED_SERVER_ID)));
+    msg->addOption(opt);
+
     // more options will be added here later
 }
 
 
-boost::shared_ptr<Pkt4>
-Dhcpv4Srv::processDiscover(boost::shared_ptr<Pkt4>& discover) {
-    boost::shared_ptr<Pkt4> offer = boost::shared_ptr<Pkt4>
-        (new Pkt4(DHCPOFFER, discover->getTransid()));
-
+void Dhcpv4Srv::appendRequestedOptions(boost::shared_ptr<Pkt4>& msg) {
     boost::shared_ptr<Option> opt;
 
-    copyDefaultFields(discover, offer);
+    // Domain name (type 15)
+    vector<uint8_t> domain(HARDCODED_DOMAIN_NAME.begin(), HARDCODED_DOMAIN_NAME.end());
+    opt = boost::shared_ptr<Option>(new Option(Option::V4, DHO_DOMAIN_NAME, domain));
+    msg->addOption(opt);
+    // TODO: Add Option_String class
 
-    appendDefaultOptions(offer, DHCPOFFER);
+    // DNS servers (type 6)
+    opt = boost::shared_ptr<Option>
+        (new Option4AddrLst(DHO_DOMAIN_NAME_SERVERS, IOAddress(HARDCODED_DNS_SERVER)));
+    msg->addOption(opt);
+}
 
-    // TODO: Implement actual lease assignment here
-    offer->setYiaddr(IOAddress(HARDCODED_LEASE));
+void Dhcpv4Srv::assignLease(boost::shared_ptr<Pkt4>& msg) {
+    boost::shared_ptr<Option> opt;
 
-    // DHCP Server Identifier (type 54)
-    opt = boost::shared_ptr<Option>
-        (new Option4AddrLst(DHO_DHCP_SERVER_IDENTIFIER, IOAddress(HARDCODED_SERVER_ID)));
-    offer->addOption(opt);
+    // TODO: Implement actual lease assignment here
+    msg->setYiaddr(IOAddress(HARDCODED_LEASE));
 
     // IP Address Lease time (type 51)
     opt = boost::shared_ptr<Option>(new Option(Option::V4, DHO_DHCP_LEASE_TIME));
     opt->setUint32(HARDCODED_LEASE_TIME);
-    offer->addOption(opt);
+    msg->addOption(opt);
+    // TODO: create Option_IntArray that holds list of integers, similar to Option4_AddrLst
 
     // Subnet mask (type 1)
     opt = boost::shared_ptr<Option>
         (new Option4AddrLst(DHO_SUBNET_MASK, IOAddress(HARDCODED_NETMASK)));
-    offer->addOption(opt);
+    msg->addOption(opt);
 
     // Router (type 3)
     opt = boost::shared_ptr<Option>
         (new Option4AddrLst(DHO_ROUTERS, IOAddress(HARDCODED_GATEWAY)));
-    offer->addOption(opt);
+    msg->addOption(opt);
+}
 
-    // Domain name (type 15)
-    vector<uint8_t> domain(HARDCODED_DOMAIN_NAME.begin(), HARDCODED_DOMAIN_NAME.end());
-    opt = boost::shared_ptr<Option>(new Option(Option::V4, DHO_DOMAIN_NAME, domain));
-    offer->addOption(opt);
-    // TODO: Add Option_String class
+boost::shared_ptr<Pkt4>
+Dhcpv4Srv::processDiscover(boost::shared_ptr<Pkt4>& discover) {
+    boost::shared_ptr<Pkt4> offer = boost::shared_ptr<Pkt4>
+        (new Pkt4(DHCPOFFER, discover->getTransid()));
 
-    // DNS servers (type 6)
-    opt = boost::shared_ptr<Option>
-        (new Option4AddrLst(DHO_DOMAIN_NAME_SERVERS, IOAddress(HARDCODED_DNS_SERVER)));
-    offer->addOption(opt);
+    copyDefaultFields(discover, offer);
+    appendDefaultOptions(offer, DHCPOFFER);
+    appendRequestedOptions(offer);
+
+    assignLease(offer);
 
     return (offer);
 }
@@ -253,45 +261,11 @@ Dhcpv4Srv::processRequest(boost::shared_ptr<Pkt4>& request) {
     boost::shared_ptr<Pkt4> ack = boost::shared_ptr<Pkt4>
         (new Pkt4(DHCPACK, request->getTransid()));
 
-    boost::shared_ptr<Option> opt;
-
     copyDefaultFields(request, ack);
-
     appendDefaultOptions(ack, DHCPACK);
+    appendRequestedOptions(ack);
 
-    // TODO: Implement actual lease assignment here
-    ack->setYiaddr(IOAddress(HARDCODED_LEASE));
-
-    // DHCP Server Identifier (type 54)
-    opt = boost::shared_ptr<Option>
-        (new Option4AddrLst(DHO_DHCP_SERVER_IDENTIFIER, IOAddress(HARDCODED_SERVER_ID)));
-    ack->addOption(opt);
-
-    // IP Address Lease time (type 51)
-    opt = boost::shared_ptr<Option>(new Option(Option::V4, DHO_DHCP_LEASE_TIME));
-    opt->setUint32(HARDCODED_LEASE_TIME);
-    ack->addOption(opt);
-    // TODO: create Option_IntArray that holds list of integers, similar to Option4_AddrLst
-
-    // Subnet mask (type 1)
-    opt = boost::shared_ptr<Option>
-        (new Option4AddrLst(DHO_SUBNET_MASK, IOAddress(HARDCODED_NETMASK)));
-    ack->addOption(opt);
-
-    // Router (type 3)
-    opt = boost::shared_ptr<Option>(new Option4AddrLst(DHO_ROUTERS, IOAddress(HARDCODED_GATEWAY)));
-    ack->addOption(opt);
-
-    // Domain name (type 15)
-    vector<uint8_t> domain(HARDCODED_DOMAIN_NAME.begin(), HARDCODED_DOMAIN_NAME.end());
-    opt = boost::shared_ptr<Option>(new Option(Option::V4, DHO_DOMAIN_NAME, domain));
-    ack->addOption(opt);
-    // TODO: Add Option_String class
-
-    // DNS servers (type 6)
-    opt = boost::shared_ptr<Option>
-        (new Option4AddrLst(DHO_DOMAIN_NAME_SERVERS, IOAddress(HARDCODED_DNS_SERVER)));
-    ack->addOption(opt);
+    assignLease(ack);
 
     return (ack);
 }
diff --git a/src/bin/dhcp4/dhcp4_srv.h b/src/bin/dhcp4/dhcp4_srv.h
index 9a48ef0..71e3acf 100644
--- a/src/bin/dhcp4/dhcp4_srv.h
+++ b/src/bin/dhcp4/dhcp4_srv.h
@@ -116,6 +116,29 @@ protected:
     void copyDefaultFields(const boost::shared_ptr<Pkt4>& question,
                            boost::shared_ptr<Pkt4>& answer);
 
+
+    /// @brief Appends options requested by client.
+    ///
+    /// This method assigns options that were requested by client
+    /// or are enforced by server (sent out to all clients).
+    ///
+    /// @param msg outgoing message (options will be added here)
+    void appendRequestedOptions(boost::shared_ptr<Pkt4>& msg);
+
+
+    /// @brief Assigns a lease and appends corresponding options
+    ///
+    /// This method chooses the most appropriate lease for reqesting
+    /// client and assigning it. Options corresponding to the lease
+    /// are added to specific message.
+    ///
+    /// Note: Lease manager is not implemented yet, so this method
+    /// used fixed, hardcoded lease.
+    ///
+    /// @param msg OFFER or ACK message (lease options will be added here)
+    void assignLease(boost::shared_ptr<Pkt4>& msg);
+
+
     /// @brief Appends default options to a message
     ///
     /// @param msg message object (options will be added to it)
diff --git a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
index 48182ac..cfc12fb 100644
--- a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
+++ b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
@@ -111,8 +111,7 @@ TEST_F(Dhcpv4SrvTest, basic) {
 
 TEST_F(Dhcpv4SrvTest, processDiscover) {
     NakedDhcpv4Srv* srv = new NakedDhcpv4Srv();
-    vector<uint8_t> mac;
-    mac.resize(6);
+    vector<uint8_t> mac(6);
     for (int i = 0; i < 6; i++) {
         mac[i] = 255 - i;
     }
@@ -170,8 +169,7 @@ TEST_F(Dhcpv4SrvTest, processDiscover) {
 
 TEST_F(Dhcpv4SrvTest, processRequest) {
     NakedDhcpv4Srv* srv = new NakedDhcpv4Srv();
-    vector<uint8_t> mac;
-    mac.resize(6);
+    vector<uint8_t> mac(6);
     for (int i = 0; i < 6; i++) {
         mac[i] = i*10;
     }
diff --git a/src/lib/dhcp/pkt4.cc b/src/lib/dhcp/pkt4.cc
index 2c2936c..9dbffee 100644
--- a/src/lib/dhcp/pkt4.cc
+++ b/src/lib/dhcp/pkt4.cc
@@ -172,7 +172,7 @@ Pkt4::unpack() {
     size_t opts_len = bufferIn.getLength() - bufferIn.getPosition();
     vector<uint8_t> optsBuffer;
 
-    // fist use of readVector
+    // First use of readVector.
     bufferIn.readVector(optsBuffer, opts_len);
     LibDHCP::unpackOptions4(optsBuffer, options_);
 




More information about the bind10-changes mailing list