]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[extend_host_struct] Fix review comments
authormayya <mayya@itwm.fraunhofer.de>
Mon, 16 Jul 2018 21:55:03 +0000 (23:55 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Mon, 23 Jul 2018 11:40:31 +0000 (13:40 +0200)
15 files changed:
AUTHORS
ChangeLog
src/bin/admin/tests/mysql_tests.sh.in
src/bin/admin/tests/pgsql_tests.sh.in
src/lib/dhcpsrv/dhcpsrv_messages.mes
src/lib/dhcpsrv/host.cc
src/lib/dhcpsrv/host.h
src/lib/dhcpsrv/memfile_lease_mgr.cc
src/lib/dhcpsrv/mysql_host_data_source.cc
src/lib/dhcpsrv/mysql_lease_mgr.cc
src/lib/dhcpsrv/pgsql_host_data_source.cc
src/lib/dhcpsrv/tests/alloc_engine_expiration_unittest.cc
src/lib/dhcpsrv/tests/host_unittest.cc
src/lib/dhcpsrv/testutils/host_data_source_utils.cc
src/lib/dhcpsrv/testutils/host_data_source_utils.h

diff --git a/AUTHORS b/AUTHORS
index 3dde830c387f1f1f4afcfda51526ecce9e2c689d..f76dd4fbda0646cbe7ebb71783ad4dbcb71eaf06 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -171,6 +171,7 @@ We have received the following contributions:
 
  - Sunil Mayya
    2018-07: support for Authentication option in DHCPv6
+   2018-07: support storage of Authentication keys in host structure
 
 Kea uses log4cplus (http://sourceforge.net/projects/log4cplus/) for logging,
 Boost (http://www.boost.org/) library for almost everything, and can use Botan
index 55a15670cc2f76779bfbfa4231b4117be0f2e965..8ab7e2285d0a5e86e7058272654a37375161b8f2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+1434.   [func]      MayyaSunil
+       Code added to support storage of Authentication key host reservation.
+       There is no way to use the code yet.
+       (Github #88, git tbd)
+
 1433.  [func]          marcin
        Implemented state HA state machine pausing in the high
        availability hooks library.
index 259291dec2339f19dea1bf68e1551fadcaf62417..a8dcf2b7cd25c2f890a6e3a89602e071c66a1733 100644 (file)
@@ -165,7 +165,7 @@ EOF
 
     # Second table: hosts
     mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 <<EOF
-    SELECT host_id, dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, dhcp6_subnet_id, ipv4_address, hostname, dhcp4_client_classes, dhcp6_client_classes, dhcp4_next_server, dhcp4_server_hostname, dhcp4_boot_file_name FROM hosts;
+    SELECT host_id, dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, dhcp6_subnet_id, ipv4_address, hostname, dhcp4_client_classes, dhcp6_client_classes, dhcp4_next_server, dhcp4_server_hostname, dhcp4_boot_file_name, auth_key FROM hosts;
 EOF
     ERRCODE=$?
     assert_eq 0 $ERRCODE "hosts table is missing or broken. (expected status code %d, returned %d)"
@@ -400,10 +400,10 @@ EOF
 
     #table: DHCPv4 fixed field colums (upgrade 4.1 -> 5.0)
     # verify that hosts table has columns holding values for DHCPv4 fixed fields
-    qry="select dhcp4_next_server, dhcp4_server_hostname, dhcp4_boot_file_name from hosts";
+    qry="select dhcp4_next_server, dhcp4_server_hostname, dhcp4_boot_file_name, auth_key from hosts";
     count=`mysql_execute "${qry}"`
     ERRCODE=$?
-    assert_eq 0 $ERRCODE "select dhcp4_next_server, dhcp4_server_hostname, dhcp4_boot_file_name failed. (expected status code %d, returned %d)"
+    assert_eq 0 $ERRCODE "select dhcp4_next_server, dhcp4_server_hostname, dhcp4_boot_file_name, auth_key failed. (expected status code %d, returned %d)"
 
     # verify that dhcp4_subnet_id is unsigned
     qry="show columns from hosts like 'dhcp4_subnet_id'"
index 553cc0699ffef876ade211c23aa75705ecb55c14..0584ff2012d780fa819e9eb69a326c6b18b3a5c8 100644 (file)
@@ -165,7 +165,7 @@ pgsql_upgrade_2_0_to_3_0() {
     assert_eq 0 $ERRCODE "lease_hwaddr_source table is missing or broken. (expected status code %d, returned %d)"
 
     # Added hosts table
-    output=`pgsql_execute "select host_id, dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, dhcp6_subnet_id, ipv4_address, hostname, dhcp4_client_classes, dhcp6_client_classes, dhcp4_next_server, dhcp4_server_hostname, dhcp4_boot_file_name from hosts;"`
+    output=`pgsql_execute "select host_id, dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, dhcp6_subnet_id, ipv4_address, hostname, dhcp4_client_classes, dhcp6_client_classes, dhcp4_next_server, dhcp4_server_hostname, dhcp4_boot_file_name, auth_key from hosts;"`
     ERRCODE=$?
     assert_eq 0 $ERRCODE "hosts table is missing or broken. (expected status code %d, returned %d)"
 
index 5801d9825f0b4ee28544c4c3fb6a5f3bbcb24b81..edf22403c73b27e3c84b62575190dcc1c91be29b 100644 (file)
@@ -497,6 +497,10 @@ of leases beginning with the specified address.
 A debug message issued when the server is attempting to obtain all IPv6
 leases from the memory file database.
 
+% DHCPSRV_MEMFILE_GET6_DUID obtaining IPv6 leases for DUID %1
+A debug message issued when the server is attempting to obtain IPv6
+leases from the memory file database for the DUID.
+
 % DHCPSRV_MEMFILE_GET_ADDR4 obtaining IPv4 lease for address %1
 A debug message issued when the server is attempting to obtain an IPv4
 lease from the memory file database for the specified address.
index 4ec23c0d818928882bf5b35d7058e5ab590cd5e4..0244f23aea387212434d0c2f29d886127004fd93 100644 (file)
@@ -10,6 +10,7 @@
 #include <util/encode/hex.h>
 #include <util/strutil.h>
 #include <asiolink/io_address.h>
+#include <boost/random.hpp>
 #include <boost/random/uniform_int_distribution.hpp>
 #include <boost/random/mersenne_twister.hpp>
 #include <exceptions/exceptions.h>
@@ -47,9 +48,9 @@ AuthKey::getRandomKeyString() {
 
 std::string 
 AuthKey::ToText() const {
-    std::ostringstream s;
-    //s << authKey_;
-    return (authKey_);
+    //this will need enhancement if the stored container is not
+    //string
+    return authKey_;
 }
 
 void
@@ -146,7 +147,7 @@ Host::Host(const uint8_t* identifier, const size_t identifier_len,
       server_host_name_(server_host_name), boot_file_name_(boot_file_name),
       host_id_(0), cfg_option4_(new CfgOption()),
       cfg_option6_(new CfgOption()), negative_(false), 
-      key_(auth_key){
+      key_(auth_key) {
 
     // Initialize host identifier.
     setIdentifier(identifier, identifier_len, identifier_type);
@@ -182,7 +183,7 @@ Host::Host(const std::string& identifier, const std::string& identifier_name,
       server_host_name_(server_host_name), boot_file_name_(boot_file_name),
       host_id_(0), cfg_option4_(new CfgOption()),
       cfg_option6_(new CfgOption()), negative_(false),
-      key_(auth_key){
+      key_(auth_key) {
 
     // Initialize host identifier.
     setIdentifier(identifier, identifier_name);
index 065df92400d0005d2124b3a7f00f59a93a1dbae1..06a72795fda6f51d82576b224618b11f48acdc61 100644 (file)
@@ -35,13 +35,11 @@ class AuthKey {
 public:
     /// @brief Length of the key - 128 bits
     const static uint8_t KEY_LEN = 16;
-    
+
     /// @brief Constructor
     ///
     /// Constructor for assigning auth keys in host reservation
-    /// Throws if the key length is greater than 16 bytes 
-    /// appends 0 to the the input if the key value is less 
-    /// than 16 bytes. Provide flexibility to store initialise the value as a string or a vector of bytes.
+    ///  Ensures the key length is not greater than 16 bytes
     /// @param string auth key to be stored
     AuthKey(const std::string key);
     
@@ -50,20 +48,20 @@ public:
     /// Constructor for generating auth keys, with no argument
     /// shall use the internal function for generationg random keys
     AuthKey(void);
-        
+
     // @brief get random string
     ///
-    /// Random string is generated by default will be used for  
+    /// Random string is generated by default will be used for
     /// the keys to be used for signing Reconfigure Message.
     /// @return auth keys
     /// @todo Move randomization function to cryptolink
-    static std::string getRandomKeyString(); 
+    static std::string getRandomKeyString();
 
     /// @brief set auth key value
     ///
-    /// Set the key value. If the value is less than 16 bytes 
-    /// append 0. If the size is greater than 16 bytes, we shall
-    /// throw an exception
+    /// Set the key value.
+    //  If the size is greater than 16 bytes, we resize to 16 Bytes
+    /// Doesnt throw an exception
     /// @param string key to be stored
     void setAuthKey(const std::string& key);
 
@@ -73,13 +71,13 @@ public:
     std::string getAuthKey() {
         return authKey_;
     }
-    
+
     /// @brief return text format for keys
     ///
     /// Although returning member would have sufficed
     /// this is added incase in future authkey is no longer std::string
     std::string ToText() const; 
-    
+
     /// 
     /// @brief equality operator
     ///
@@ -645,7 +643,6 @@ public:
     /// @brief sets key.
     ///
     /// Keys are used for signing the Reconfigure Message.
-    /// The accessor should ensure 128 characters
     void setKey(const AuthKey& key) {
         key_ = key;
     }
@@ -696,7 +693,7 @@ private:
     std::string server_host_name_;
     /// @brief Boot file name (a.k.a. file, carried in DHCPv4 message)
     std::string boot_file_name_;
-            
+
     /// @brief HostID (a unique identifier assigned when the host is stored in
     ///     MySQL, PostgreSQL or Cassandra)
     uint64_t host_id_;
@@ -719,7 +716,6 @@ private:
     //  While sending reconfigure message authentication field 
     /// shall contain MD5 hash computed using this key.
     AuthKey key_;
-
 };
 
 /// @brief Pointer to the @c Host object.
index c1c84b8aeae5a53db4e734215574d59991b28938..dd04ef3dac2f9246392a427705ac6dc6ad26e472 100644 (file)
@@ -1015,6 +1015,20 @@ Memfile_LeaseMgr::getLeases6() const {
    return (collection);
 }
 
+Lease6Collection
+Memfile_LeaseMgr::getLeases6(const DUID& duid) const {
+   LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_GET6_DUID)
+       .arg(duid.toText());
+
+   Lease6Collection collection;
+   for (auto lease = storage6_.begin(); lease != storage6_.end(); ++lease ) {
+       if ( (**lease).duid_->getDuid() == duid.getDuid() )
+            collection.push_back(Lease6Ptr(new Lease6(**lease)));
+   }
+
+   return (collection);
+}
+
 Lease6Collection
 Memfile_LeaseMgr::getLeases6(const asiolink::IOAddress& lower_bound_address,
                              const LeasePageSize& page_size) const {
index e4bc90aaf828759956a17d73dad805120dda7e1d..adb6b3f65153b00f6e6958cd5696d3289d5479f4 100644 (file)
@@ -145,7 +145,7 @@ public:
           dhcp4_next_server_null_(MLM_FALSE),
           dhcp4_server_hostname_null_(MLM_FALSE),
           dhcp4_boot_file_name_null_(MLM_FALSE),
-          auth_key_null_(MLM_FALSE)  {
+          auth_key_null_(MLM_FALSE) {
 
         // Fill arrays with 0 so as they don't include any garbage.
         memset(dhcp_identifier_buffer_, 0, sizeof(dhcp_identifier_buffer_));
@@ -1430,7 +1430,6 @@ public:
 
         ipv6_address_buffer_[ipv6_address_buffer_len_] = '\0';
         std::string address = ipv6_address_buffer_;
-
         IPv6Resrv r(type, IOAddress(address), prefix_len_);
         return (r);
     };
index 663bc0c8c9ea848bbc97337707c737a653588dee..83a2710ca540d8b866cafe60279eb695194778fb 100644 (file)
@@ -184,7 +184,7 @@ tagged_statements = { {
                         "state, user_context "
                             "FROM lease6 "
                             "WHERE address = ? AND lease_type = ?"},
-       {MySqlLeaseMgr::GET_LEASE6_DUID_IAID,
+    {MySqlLeaseMgr::GET_LEASE6_DUID_IAID,
                     "SELECT address, duid, valid_lifetime, "
                         "expire, subnet_id, pref_lifetime, "
                         "lease_type, iaid, prefix_len, "
index efa2c00b0c9172a7009e1298a62592afef92b313..02e2048601596aea1fdad4ca587bdb744d8ee7ab 100644 (file)
@@ -1646,7 +1646,7 @@ TaggedStatementArray tagged_statements = { {
     //PgSqlHostDataSourceImpl::INSERT_V6_RESRV
     // Inserts a single IPv6 reservation into 'reservations' table.
     {5,
-     { OID_VARCHAR, OID_INT2, OID_INT4, OID_INT4, OID_INT4},
+     { OID_VARCHAR, OID_INT2, OID_INT4, OID_INT4, OID_INT4 },
      "insert_v6_resrv",
      "INSERT INTO ipv6_reservations(address, prefix_len, type, "
      "  dhcp6_iaid, host_id) "
index 49d471b52719380b369a11ba1b7ac97d47522441..997fe9549bfe8af66f91fead86924e65514ff24f 100644 (file)
@@ -1590,7 +1590,7 @@ TEST_F(ExpirationAllocEngine6Test, reclaimDeclinedStats) {
 
 // This test verifies that expired leases are reclaimed before they are
 // allocated to another client sending a Request message.
-/TEST_F(ExpirationAllocEngine6Test, reclaimReusedLeases) {
+TEST_F(ExpirationAllocEngine6Test, reclaimReusedLeases) {
     testReclaimReusedLeases(DHCPV6_REQUEST, false);
 }
 
index be5af1bc58c291641db0280afab6e88f66041b10..4847e2a779f906e1035faff4ba1bb91a03d692db 100644 (file)
@@ -1277,10 +1277,12 @@ TEST(AuthKeyTest, basicTest) {
     defaultTestKey.setAuthKey(key16ByteStr);
     ASSERT_EQ(16, defaultTestKey.getAuthKey().size());
     ASSERT_EQ(key16ByteStr, defaultTestKey.getAuthKey());
+    ASSERT_EQ(key16ByteStr, defaultTestKey.ToText());
     
     defaultTestKey.setAuthKey(key18ByteStr);
     ASSERT_EQ(16, defaultTestKey.getAuthKey().size());
     ASSERT_EQ(key16ByteStr, defaultTestKey.getAuthKey());
+    ASSERT_EQ(key16ByteStr, defaultTestKey.ToText());
 
 }
 
index 85b2cad6202f21480ba30dc092eb8083c4bffa5d..d76038b16770315fb672172294fc1a1403eb35b4 100644 (file)
@@ -81,7 +81,7 @@ HostDataSourceUtils::initializeHost4(const std::string& address,
 }
 
 HostPtr
-HostDataSourceUtils::initializeHost6(const std::string address,
+HostDataSourceUtils::initializeHost6(std::string address,
                                      Host::IdentifierType identifier,
                                      bool prefix,
                                      bool new_identifier,
@@ -107,13 +107,11 @@ HostDataSourceUtils::initializeHost6(const std::string address,
     ++subnet4;
     ++subnet6;
 
-    std::string default_string;
     HostPtr host(new Host(&ident[0], ident.size(), identifier, subnet4, subnet6,
-                          IOAddress("0.0.0.0"), default_string,
-                          default_string, default_string,
-                           asiolink:: IOAddress::IPV4_ZERO_ADDRESS(), default_string, default_string,
-                          AuthKey(auth_key)));
-
+                          IOAddress("0.0.0.0")));
+    
+    host->setKey(AuthKey(auth_key));
+    
     if (!prefix) {
         // Create IPv6 reservation (for an address)
         IPv6Resrv resv(IPv6Resrv::TYPE_NA, IOAddress(address), 128);
index 7b1b7789dbaaed6a0acacede386cd2c098d1435e..a252eeb0dc4f415475a1fc29d1a02ca964538736 100644 (file)
@@ -38,7 +38,7 @@ public:
     /// identifier should be generated or the same as previously.
     ///
     /// @return generated Host object
-    static HostPtr initializeHost6(const std::string address, Host::IdentifierType id,
+    static HostPtr initializeHost6(std::string address, Host::IdentifierType id,
                                    bool prefix, bool new_identifier = true, const std::string key = "");
 
     /// @brief Generates a hardware address in text version.