2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-29 04:57:52 +00:00

[extend_host_struct] Fix review comments

This commit is contained in:
mayya 2018-07-16 23:55:03 +02:00 committed by Tomek Mrugalski
parent 3606c3ba9c
commit 2ff46b2dd5
15 changed files with 57 additions and 37 deletions

View File

@ -171,6 +171,7 @@ We have received the following contributions:
- Sunil Mayya - Sunil Mayya
2018-07: support for Authentication option in DHCPv6 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, Kea uses log4cplus (http://sourceforge.net/projects/log4cplus/) for logging,
Boost (http://www.boost.org/) library for almost everything, and can use Botan Boost (http://www.boost.org/) library for almost everything, and can use Botan

View File

@ -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 1433. [func] marcin
Implemented state HA state machine pausing in the high Implemented state HA state machine pausing in the high
availability hooks library. availability hooks library.

View File

@ -165,7 +165,7 @@ EOF
# Second table: hosts # Second table: hosts
mysql -u$db_user -p$db_password $db_name >/dev/null 2>&1 <<EOF 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 EOF
ERRCODE=$? ERRCODE=$?
assert_eq 0 $ERRCODE "hosts table is missing or broken. (expected status code %d, returned %d)" 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) #table: DHCPv4 fixed field colums (upgrade 4.1 -> 5.0)
# verify that hosts table has columns holding values for DHCPv4 fixed fields # 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}"` count=`mysql_execute "${qry}"`
ERRCODE=$? 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 # verify that dhcp4_subnet_id is unsigned
qry="show columns from hosts like 'dhcp4_subnet_id'" qry="show columns from hosts like 'dhcp4_subnet_id'"

View 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)" assert_eq 0 $ERRCODE "lease_hwaddr_source table is missing or broken. (expected status code %d, returned %d)"
# Added hosts table # 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=$? ERRCODE=$?
assert_eq 0 $ERRCODE "hosts table is missing or broken. (expected status code %d, returned %d)" assert_eq 0 $ERRCODE "hosts table is missing or broken. (expected status code %d, returned %d)"

View 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 A debug message issued when the server is attempting to obtain all IPv6
leases from the memory file database. 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 % DHCPSRV_MEMFILE_GET_ADDR4 obtaining IPv4 lease for address %1
A debug message issued when the server is attempting to obtain an IPv4 A debug message issued when the server is attempting to obtain an IPv4
lease from the memory file database for the specified address. lease from the memory file database for the specified address.

View File

@ -10,6 +10,7 @@
#include <util/encode/hex.h> #include <util/encode/hex.h>
#include <util/strutil.h> #include <util/strutil.h>
#include <asiolink/io_address.h> #include <asiolink/io_address.h>
#include <boost/random.hpp>
#include <boost/random/uniform_int_distribution.hpp> #include <boost/random/uniform_int_distribution.hpp>
#include <boost/random/mersenne_twister.hpp> #include <boost/random/mersenne_twister.hpp>
#include <exceptions/exceptions.h> #include <exceptions/exceptions.h>
@ -47,9 +48,9 @@ AuthKey::getRandomKeyString() {
std::string std::string
AuthKey::ToText() const { AuthKey::ToText() const {
std::ostringstream s; //this will need enhancement if the stored container is not
//s << authKey_; //string
return (authKey_); return authKey_;
} }
void 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), server_host_name_(server_host_name), boot_file_name_(boot_file_name),
host_id_(0), cfg_option4_(new CfgOption()), host_id_(0), cfg_option4_(new CfgOption()),
cfg_option6_(new CfgOption()), negative_(false), cfg_option6_(new CfgOption()), negative_(false),
key_(auth_key){ key_(auth_key) {
// Initialize host identifier. // Initialize host identifier.
setIdentifier(identifier, identifier_len, identifier_type); 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), server_host_name_(server_host_name), boot_file_name_(boot_file_name),
host_id_(0), cfg_option4_(new CfgOption()), host_id_(0), cfg_option4_(new CfgOption()),
cfg_option6_(new CfgOption()), negative_(false), cfg_option6_(new CfgOption()), negative_(false),
key_(auth_key){ key_(auth_key) {
// Initialize host identifier. // Initialize host identifier.
setIdentifier(identifier, identifier_name); setIdentifier(identifier, identifier_name);

View File

@ -39,9 +39,7 @@ public:
/// @brief Constructor /// @brief Constructor
/// ///
/// Constructor for assigning auth keys in host reservation /// Constructor for assigning auth keys in host reservation
/// Throws if the key length is greater than 16 bytes /// Ensures the key length is not 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.
/// @param string auth key to be stored /// @param string auth key to be stored
AuthKey(const std::string key); AuthKey(const std::string key);
@ -61,9 +59,9 @@ public:
/// @brief set auth key value /// @brief set auth key value
/// ///
/// Set the key value. If the value is less than 16 bytes /// Set the key value.
/// append 0. If the size is greater than 16 bytes, we shall // If the size is greater than 16 bytes, we resize to 16 Bytes
/// throw an exception /// Doesnt throw an exception
/// @param string key to be stored /// @param string key to be stored
void setAuthKey(const std::string& key); void setAuthKey(const std::string& key);
@ -645,7 +643,6 @@ public:
/// @brief sets key. /// @brief sets key.
/// ///
/// Keys are used for signing the Reconfigure Message. /// Keys are used for signing the Reconfigure Message.
/// The accessor should ensure 128 characters
void setKey(const AuthKey& key) { void setKey(const AuthKey& key) {
key_ = key; key_ = key;
} }
@ -719,7 +716,6 @@ private:
// While sending reconfigure message authentication field // While sending reconfigure message authentication field
/// shall contain MD5 hash computed using this key. /// shall contain MD5 hash computed using this key.
AuthKey key_; AuthKey key_;
}; };
/// @brief Pointer to the @c Host object. /// @brief Pointer to the @c Host object.

View File

@ -1015,6 +1015,20 @@ Memfile_LeaseMgr::getLeases6() const {
return (collection); 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 Lease6Collection
Memfile_LeaseMgr::getLeases6(const asiolink::IOAddress& lower_bound_address, Memfile_LeaseMgr::getLeases6(const asiolink::IOAddress& lower_bound_address,
const LeasePageSize& page_size) const { const LeasePageSize& page_size) const {

View File

@ -145,7 +145,7 @@ public:
dhcp4_next_server_null_(MLM_FALSE), dhcp4_next_server_null_(MLM_FALSE),
dhcp4_server_hostname_null_(MLM_FALSE), dhcp4_server_hostname_null_(MLM_FALSE),
dhcp4_boot_file_name_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. // Fill arrays with 0 so as they don't include any garbage.
memset(dhcp_identifier_buffer_, 0, sizeof(dhcp_identifier_buffer_)); memset(dhcp_identifier_buffer_, 0, sizeof(dhcp_identifier_buffer_));
@ -1430,7 +1430,6 @@ public:
ipv6_address_buffer_[ipv6_address_buffer_len_] = '\0'; ipv6_address_buffer_[ipv6_address_buffer_len_] = '\0';
std::string address = ipv6_address_buffer_; std::string address = ipv6_address_buffer_;
IPv6Resrv r(type, IOAddress(address), prefix_len_); IPv6Resrv r(type, IOAddress(address), prefix_len_);
return (r); return (r);
}; };

View File

@ -184,7 +184,7 @@ tagged_statements = { {
"state, user_context " "state, user_context "
"FROM lease6 " "FROM lease6 "
"WHERE address = ? AND lease_type = ?"}, "WHERE address = ? AND lease_type = ?"},
{MySqlLeaseMgr::GET_LEASE6_DUID_IAID, {MySqlLeaseMgr::GET_LEASE6_DUID_IAID,
"SELECT address, duid, valid_lifetime, " "SELECT address, duid, valid_lifetime, "
"expire, subnet_id, pref_lifetime, " "expire, subnet_id, pref_lifetime, "
"lease_type, iaid, prefix_len, " "lease_type, iaid, prefix_len, "

View File

@ -1646,7 +1646,7 @@ TaggedStatementArray tagged_statements = { {
//PgSqlHostDataSourceImpl::INSERT_V6_RESRV //PgSqlHostDataSourceImpl::INSERT_V6_RESRV
// Inserts a single IPv6 reservation into 'reservations' table. // Inserts a single IPv6 reservation into 'reservations' table.
{5, {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_v6_resrv",
"INSERT INTO ipv6_reservations(address, prefix_len, type, " "INSERT INTO ipv6_reservations(address, prefix_len, type, "
" dhcp6_iaid, host_id) " " dhcp6_iaid, host_id) "

View File

@ -1590,7 +1590,7 @@ TEST_F(ExpirationAllocEngine6Test, reclaimDeclinedStats) {
// This test verifies that expired leases are reclaimed before they are // This test verifies that expired leases are reclaimed before they are
// allocated to another client sending a Request message. // allocated to another client sending a Request message.
/TEST_F(ExpirationAllocEngine6Test, reclaimReusedLeases) { TEST_F(ExpirationAllocEngine6Test, reclaimReusedLeases) {
testReclaimReusedLeases(DHCPV6_REQUEST, false); testReclaimReusedLeases(DHCPV6_REQUEST, false);
} }

View File

@ -1277,10 +1277,12 @@ TEST(AuthKeyTest, basicTest) {
defaultTestKey.setAuthKey(key16ByteStr); defaultTestKey.setAuthKey(key16ByteStr);
ASSERT_EQ(16, defaultTestKey.getAuthKey().size()); ASSERT_EQ(16, defaultTestKey.getAuthKey().size());
ASSERT_EQ(key16ByteStr, defaultTestKey.getAuthKey()); ASSERT_EQ(key16ByteStr, defaultTestKey.getAuthKey());
ASSERT_EQ(key16ByteStr, defaultTestKey.ToText());
defaultTestKey.setAuthKey(key18ByteStr); defaultTestKey.setAuthKey(key18ByteStr);
ASSERT_EQ(16, defaultTestKey.getAuthKey().size()); ASSERT_EQ(16, defaultTestKey.getAuthKey().size());
ASSERT_EQ(key16ByteStr, defaultTestKey.getAuthKey()); ASSERT_EQ(key16ByteStr, defaultTestKey.getAuthKey());
ASSERT_EQ(key16ByteStr, defaultTestKey.ToText());
} }

View File

@ -81,7 +81,7 @@ HostDataSourceUtils::initializeHost4(const std::string& address,
} }
HostPtr HostPtr
HostDataSourceUtils::initializeHost6(const std::string address, HostDataSourceUtils::initializeHost6(std::string address,
Host::IdentifierType identifier, Host::IdentifierType identifier,
bool prefix, bool prefix,
bool new_identifier, bool new_identifier,
@ -107,12 +107,10 @@ HostDataSourceUtils::initializeHost6(const std::string address,
++subnet4; ++subnet4;
++subnet6; ++subnet6;
std::string default_string;
HostPtr host(new Host(&ident[0], ident.size(), identifier, subnet4, subnet6, HostPtr host(new Host(&ident[0], ident.size(), identifier, subnet4, subnet6,
IOAddress("0.0.0.0"), default_string, IOAddress("0.0.0.0")));
default_string, default_string,
asiolink:: IOAddress::IPV4_ZERO_ADDRESS(), default_string, default_string, host->setKey(AuthKey(auth_key));
AuthKey(auth_key)));
if (!prefix) { if (!prefix) {
// Create IPv6 reservation (for an address) // Create IPv6 reservation (for an address)

View File

@ -38,7 +38,7 @@ public:
/// identifier should be generated or the same as previously. /// identifier should be generated or the same as previously.
/// ///
/// @return generated Host object /// @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 = ""); bool prefix, bool new_identifier = true, const std::string key = "");
/// @brief Generates a hardware address in text version. /// @brief Generates a hardware address in text version.