Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lib] Extend host structure to support auth keys for reconfiguration. #88

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
1433. [func] MayyaSunil
Code added to support storage of Authentication key host reservation.
There is no way to use the code yet.
1432. [func] MayyaSunil
Code added to handle Authentication option in DHCPv6. There
is no way to use this code yet.
Expand Down
6 changes: 3 additions & 3 deletions src/bin/admin/tests/mysql_tests.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -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'"
Expand Down
2 changes: 1 addition & 1 deletion src/bin/admin/tests/pgsql_tests.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)"

Expand Down
24 changes: 22 additions & 2 deletions src/lib/dhcpsrv/cql_host_data_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ class CqlHostExchange : public virtual CqlExchange {
/// @brief Boot file name (file).
std::string host_ipv4_boot_file_name_;

/// @brief Key for authentication
std::string auth_key_;

/// @brief Name reserved for the host
std::string hostname_;

Expand Down Expand Up @@ -431,6 +434,7 @@ StatementMap CqlHostExchange::tagged_statements_ = {
"host_ipv4_next_server, "
"host_ipv4_server_hostname, "
"host_ipv4_boot_file_name, "
"auth_key, "
"hostname, "
"user_context, "
"host_ipv4_client_classes, "
Expand All @@ -455,7 +459,7 @@ StatementMap CqlHostExchange::tagged_statements_ = {
// host
"?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "
// denormalized reservation, option
"?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? "
"?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? "
") "
"IF NOT EXISTS "
}},
Expand All @@ -472,6 +476,7 @@ StatementMap CqlHostExchange::tagged_statements_ = {
"host_ipv4_next_server, "
"host_ipv4_server_hostname, "
"host_ipv4_boot_file_name, "
"auth_key, "
"hostname, "
"user_context, "
"host_ipv4_client_classes, "
Expand Down Expand Up @@ -505,6 +510,7 @@ StatementMap CqlHostExchange::tagged_statements_ = {
"host_ipv4_next_server, "
"host_ipv4_server_hostname, "
"host_ipv4_boot_file_name, "
"auth_key, "
"hostname, "
"user_context, "
"host_ipv4_client_classes, "
Expand Down Expand Up @@ -541,6 +547,7 @@ StatementMap CqlHostExchange::tagged_statements_ = {
"host_ipv4_next_server, "
"host_ipv4_server_hostname, "
"host_ipv4_boot_file_name, "
"auth_key, "
"hostname, "
"user_context, "
"host_ipv4_client_classes, "
Expand Down Expand Up @@ -576,6 +583,7 @@ StatementMap CqlHostExchange::tagged_statements_ = {
"host_ipv4_next_server, "
"host_ipv4_server_hostname, "
"host_ipv4_boot_file_name, "
"auth_key, "
"hostname, "
"user_context, "
"host_ipv4_client_classes, "
Expand Down Expand Up @@ -613,6 +621,7 @@ StatementMap CqlHostExchange::tagged_statements_ = {
"host_ipv4_next_server, "
"host_ipv4_server_hostname, "
"host_ipv4_boot_file_name, "
"auth_key, "
"hostname, "
"user_context, "
"host_ipv4_client_classes, "
Expand Down Expand Up @@ -650,6 +659,7 @@ StatementMap CqlHostExchange::tagged_statements_ = {
"host_ipv4_next_server, "
"host_ipv4_server_hostname, "
"host_ipv4_boot_file_name, "
"auth_key, "
"hostname, "
"user_context, "
"host_ipv4_client_classes, "
Expand Down Expand Up @@ -686,6 +696,7 @@ StatementMap CqlHostExchange::tagged_statements_ = {
"host_ipv4_next_server, "
"host_ipv4_server_hostname, "
"host_ipv4_boot_file_name, "
"auth_key, "
"hostname, "
"user_context, "
"host_ipv4_client_classes, "
Expand Down Expand Up @@ -722,6 +733,7 @@ StatementMap CqlHostExchange::tagged_statements_ = {
"host_ipv4_next_server, "
"host_ipv4_server_hostname, "
"host_ipv4_boot_file_name, "
"auth_key, "
"hostname, "
"user_context, "
"host_ipv4_client_classes, "
Expand Down Expand Up @@ -758,6 +770,7 @@ CqlHostExchange::CqlHostExchange()
host_ipv6_subnet_id_(0), host_ipv4_address_(0), host_ipv4_next_server_(0),
host_ipv4_server_hostname_(NULL_DHCP4_SERVER_HOSTNAME),
host_ipv4_boot_file_name_(NULL_DHCP4_BOOT_FILE_NAME),
auth_key_(""),
user_context_(NULL_USER_CONTEXT),
reserved_ipv6_prefix_length_(NULL_RESERVED_IPV6_PREFIX_LENGTH),
reserved_ipv6_prefix_address_type_(NULL_RESERVED_IPV6_PREFIX_ADDRESS_TYPE),
Expand Down Expand Up @@ -795,6 +808,8 @@ CqlHostExchange::createBindForSelect(AnyArray& data, StatementTag /* not used */
data.add(&host_ipv4_server_hostname_);
// host_ipv4_boot_file_name: text
data.add(&host_ipv4_boot_file_name_);
// auth_key: text
data.add(&auth_key_);
// hostname: text
data.add(&hostname_);
// user_context: text
Expand Down Expand Up @@ -888,6 +903,9 @@ CqlHostExchange::prepareExchange(const HostPtr& host,
// host_ipv4_boot_file_name: text
host_ipv4_boot_file_name_ = host->getBootFileName();

// auth_key: varchar
auth_key_ = host->getKey().ToText();

// hostname: text
hostname_ = host->getHostname();
if (hostname_.size() > HOSTNAME_MAX_LENGTH) {
Expand Down Expand Up @@ -1050,6 +1068,7 @@ CqlHostExchange::createBindForMutation(const HostPtr& host,
data.add(&host_ipv4_next_server_);
data.add(&host_ipv4_server_hostname_);
data.add(&host_ipv4_boot_file_name_);
data.add(&auth_key_);
data.add(&hostname_);
data.add(&user_context_);
data.add(&host_ipv4_client_classes_);
Expand Down Expand Up @@ -1168,7 +1187,8 @@ CqlHostExchange::retrieve() {
ipv4_reservation, hostname_,
host_ipv4_client_classes_, host_ipv6_client_classes_,
static_cast<uint32_t>(host_ipv4_next_server_),
host_ipv4_server_hostname_, host_ipv4_boot_file_name_);
host_ipv4_server_hostname_, host_ipv4_boot_file_name_,
AuthKey(auth_key_));

// Set the user context if there is one.
if (!user_context_.empty()) {
Expand Down
34 changes: 33 additions & 1 deletion src/lib/dhcpsrv/cql_lease_mgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,7 @@ class CqlLease6Exchange : public CqlLeaseExchange {
static constexpr StatementTag DELETE_LEASE6 = "DELETE_LEASE6";
static constexpr StatementTag GET_LEASE6_EXPIRE = "GET_LEASE6_EXPIRE";
static constexpr StatementTag GET_LEASE6_ADDR = "GET_LEASE6_ADDR";
static constexpr StatementTag GET_LEASE6_DUID = "GET_LEASE6_DUID";
static constexpr StatementTag GET_LEASE6_DUID_IAID = "GET_LEASE6_DUID_IAID";
static constexpr StatementTag GET_LEASE6_DUID_IAID_SUBID = "GET_LEASE6_DUID_IAID_SUBID";
static constexpr StatementTag GET_LEASE6_LIMIT = "GET_LEASE6_LIMIT";
Expand Down Expand Up @@ -941,6 +942,7 @@ constexpr StatementTag CqlLease6Exchange::UPDATE_LEASE6;
constexpr StatementTag CqlLease6Exchange::DELETE_LEASE6;
constexpr StatementTag CqlLease6Exchange::GET_LEASE6_EXPIRE;
constexpr StatementTag CqlLease6Exchange::GET_LEASE6_ADDR;
constexpr StatementTag CqlLease6Exchange::GET_LEASE6_DUID;
constexpr StatementTag CqlLease6Exchange::GET_LEASE6_DUID_IAID;
constexpr StatementTag CqlLease6Exchange::GET_LEASE6_DUID_IAID_SUBID;
constexpr StatementTag CqlLease6Exchange::GET_LEASE6_LIMIT;
Expand Down Expand Up @@ -1003,7 +1005,7 @@ StatementMap CqlLease6Exchange::tagged_statements_ = {
"LIMIT ? "
"ALLOW FILTERING "}},

// Gets an IPv6 lease with specified IPv4 address
// Gets an IPv6 lease with specified IPv6 address
{GET_LEASE6_ADDR,
{GET_LEASE6_ADDR,
"SELECT "
Expand All @@ -1015,6 +1017,17 @@ StatementMap CqlLease6Exchange::tagged_statements_ = {
"AND lease_type = ? "
"ALLOW FILTERING "}},

// Gets an IPv6 lease with specified duid
{GET_LEASE6_DUID,
{GET_LEASE6_DUID,
"SELECT "
"address, valid_lifetime, expire, subnet_id, pref_lifetime, duid, iaid, "
"lease_type, prefix_len, fqdn_fwd, fqdn_rev, hostname, hwaddr, hwtype, "
"hwaddr_source, state "
"FROM lease6 "
"WHERE duid = ? "
"ALLOW FILTERING "}},

// Gets an IPv6 lease(s) with specified duid and iaid
{GET_LEASE6_DUID_IAID,
{GET_LEASE6_DUID_IAID,
Expand Down Expand Up @@ -2280,6 +2293,25 @@ CqlLeaseMgr::getLease6(Lease::Type lease_type, const IOAddress &addr) const {
return (result);
}

Lease6Collection
CqlLeaseMgr::getLeases6(const DUID& duid) const {

// Set up the WHERE clause value
AnyArray data;

CassBlob duid_data(duid.getDuid());

data.add(&duid_data);

// Get the data.
Lease6Collection result;
std::unique_ptr<CqlLease6Exchange> exchange6(new CqlLease6Exchange(dbconn_));
exchange6->getLeaseCollection(CqlLease6Exchange::GET_LEASE6_DUID, data, result);

return (result);

}

Lease6Collection
CqlLeaseMgr::getLeases6(Lease::Type lease_type, const DUID &duid, uint32_t iaid) const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_GET_IAID_DUID)
Expand Down
5 changes: 5 additions & 0 deletions src/lib/dhcpsrv/cql_lease_mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ class CqlLeaseMgr : public LeaseMgr {
/// this backend.
virtual Lease6Collection getLeases6() const override;

/// @brief Returns all IPv6 leases.
///
/// @return Lease collection (may be empty if no IPv6 lease found).
virtual Lease6Collection getLeases6(const DUID& duid) const;

/// @brief Returns range of IPv6 leases using paging.
///
/// This method implements paged browsing of the lease database. The first
Expand Down
12 changes: 12 additions & 0 deletions src/lib/dhcpsrv/dhcpsrv_messages.mes
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -757,6 +761,10 @@ of leases beginning with the specified address.
A debug message issued when the server is attempting to obtain an IPv6
lease from the MySQL database for the specified address.

% DHCPSRV_MYSQL_GET_DUID obtaining IPv6 lease for duid %1,
A debug message issued when the server is attempting to obtain an IPv6
lease from the MySQL database for the specified duid.

% DHCPSRV_MYSQL_GET_CLIENTID obtaining IPv4 leases for client ID %1
A debug message issued when the server is attempting to obtain a set
of IPv4 leases from the MySQL database for a client with the specified
Expand Down Expand Up @@ -954,6 +962,10 @@ A debug message issued when the server is attempting to obtain a set of IPv6
leases from the PostgreSQL database for a client with the specified IAID
(Identity Association ID) and DUID (DHCP Unique Identifier).

% DHCPSRV_PGSQL_GET_DUID obtaining IPv6 leases for DUID %1,
A debug message issued when the server is attempting to obtain a set of IPv6
leases from the PostgreSQL database for a client with the specified DUID (DHCP Unique Identifier).

% DHCPSRV_PGSQL_GET_IAID_SUBID_DUID obtaining IPv4 leases for IAID %1, Subnet ID %2, DUID %3, and lease type %4
A debug message issued when the server is attempting to obtain an IPv6
lease from the PostgreSQL database for a client with the specified IAID
Expand Down
Loading