mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-29 04:57:52 +00:00
[5469] checkpoint (copied with 4 -> 6)
This commit is contained in:
parent
4a538fe84c
commit
cfe529dff1
@ -1340,13 +1340,17 @@ An example deletion by (subnet-id, identifier-type, identifier) looks as follows
|
||||
<para><command>lease4-get</command> - checks if an IPv4 lease with
|
||||
the specified parameters exists and returns it if it does;</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><command>lease6-get</command> - checks if an IPv6 lease with
|
||||
the specified parameters exists and returns it if it does;</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><command>lease4-get-all</command> - returns all IPv4 leases
|
||||
or IPv4 leases for specified subnets;</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><command>lease6-get</command> - checks if an IPv6 lease with
|
||||
the specified parameters exists and returns it if it does;</para>
|
||||
<para><command>lease6-get-all</command> - returns all IPv6 leases
|
||||
or IPv6 leases for specified subnets;</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><command>lease4-del</command> - attempts to delete an IPv4
|
||||
@ -1663,11 +1667,12 @@ An example result returned when the host was found:
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>lease4-get-all command</title>
|
||||
<para><command>lease4-get-all</command> is used to retrieve all IPv4
|
||||
leases or all leases for the specified set of subnets. All leases are
|
||||
returned when there are no arguments specified with the command as
|
||||
in the following example:
|
||||
<title>lease4-get-all, lease6-get-all commands</title>
|
||||
<para><command>lease4-get-all</command> or
|
||||
<command>lease6-get-all</command> is used to retrieve all
|
||||
IPv4 or IPv6 leases or all leases for the specified set of
|
||||
subnets. All leases are returned when there are no arguments
|
||||
specified with the command as in the following example:
|
||||
<screen>
|
||||
{
|
||||
"command": "lease4-get-all"
|
||||
@ -1680,7 +1685,7 @@ An example result returned when the host was found:
|
||||
leases should be returned, e.g.:
|
||||
<screen>
|
||||
{
|
||||
"command": "lease4-get-all",
|
||||
"command": "lease6-get-all",
|
||||
"arguments": {
|
||||
"subnets": [ 1, 2, 3, 4 ]
|
||||
}
|
||||
@ -1695,38 +1700,45 @@ An example result returned when the host was found:
|
||||
"arguments": {
|
||||
"leases": [
|
||||
{
|
||||
"client-id": "42:42:42:42:42:42:42:42",
|
||||
"cltt": 12345678,
|
||||
"duid": "42:42:42:42:42:42:42:42",
|
||||
"fqdn-fwd": false,
|
||||
"fqdn-rev": true,
|
||||
"hostname": "myhost.example.com.",
|
||||
"hw-address": "08:08:08:08:08:08",
|
||||
"ip-address": "192.0.2.1",
|
||||
"iaid": 1,
|
||||
"ip-address": "2001:db8:2::1",
|
||||
"preferred-lft": 500,
|
||||
"state": 0,
|
||||
"subnet-id": 44,
|
||||
"type": "IA_NA",
|
||||
"valid-lft": 3600
|
||||
},
|
||||
{
|
||||
"client-id": "21:21:21:21:21:21:21:21",
|
||||
"cltt": 12345678,
|
||||
"duid": "21:21:21:21:21:21:21:21",
|
||||
"fqdn-fwd": false,
|
||||
"fqdn-rev": true,
|
||||
"hostname": "",
|
||||
"hw-address": "10:10:10:10:10:10",
|
||||
"ip-address": "192.0.2.2",
|
||||
"iaid": 1,
|
||||
"ip-address": "2001:db8:0:0:2::",
|
||||
"preferred-lft": 500,
|
||||
"prefix-len": 80,
|
||||
"state": 0,
|
||||
"subnet-id": 44,
|
||||
"type": "IA_PD",
|
||||
"valid-lft": 3600
|
||||
}
|
||||
]
|
||||
},
|
||||
"result": 0,
|
||||
"text": "2 IPv4 lease(s) found."
|
||||
"text": "2 IPv6 lease(s) found."
|
||||
}</screen>
|
||||
</para>
|
||||
|
||||
<warning>
|
||||
<para>The <command>lease4-get-command</command> may result in very
|
||||
<para>The <command>lease4-get-command</command> or
|
||||
<command>lease6-get-command</command> may result in very
|
||||
large responses. This may have negative impact on the DHCP server
|
||||
responsiveness while the response is generated and transmitted
|
||||
over the control channel, as the server imposes no restriction
|
||||
|
@ -130,17 +130,18 @@ public:
|
||||
int
|
||||
leaseGetHandler(CalloutHandle& handle);
|
||||
|
||||
/// @brief lease4-get-all command handler
|
||||
/// @brief lease4-get-all, lease6-get-all command handler
|
||||
///
|
||||
/// This command attempts to retrieve all IPv4 leases or all IPv4 leases
|
||||
/// belonging to the particular subnets. If no subnet identifiers are
|
||||
/// provided, it returns all IPv4 leases from the database.
|
||||
/// This command attempts to retrieve all IPv4 or IPv6 leases,
|
||||
/// or all IPv4 or all IPv6 leases belonging to the particular
|
||||
/// subnets. If no subnet identifiers are provided, it returns all
|
||||
/// IPv4 or IPv6 leases from the database.
|
||||
///
|
||||
/// @param handle Callout context - which is expected to contain the
|
||||
/// get command JSON text in the "command" argument
|
||||
/// @return 0 upon success, non-zero otherwise.
|
||||
int
|
||||
lease4GetAllHandler(CalloutHandle& handle);
|
||||
leaseGetAllHandler(CalloutHandle& handle);
|
||||
|
||||
/// @brief lease4-del command handler
|
||||
///
|
||||
@ -469,9 +470,11 @@ LeaseCmdsImpl::leaseGetHandler(CalloutHandle& handle) {
|
||||
}
|
||||
|
||||
int
|
||||
LeaseCmdsImpl::lease4GetAllHandler(CalloutHandle& handle) {
|
||||
LeaseCmdsImpl::leaseGetAllHandler(CalloutHandle& handle) {
|
||||
bool v4 = true;
|
||||
try {
|
||||
extractCommand(handle);
|
||||
v4 = (cmd_name_ == "lease4-get-all");
|
||||
|
||||
ElementPtr leases_json = Element::createList();
|
||||
|
||||
@ -491,11 +494,20 @@ LeaseCmdsImpl::lease4GetAllHandler(CalloutHandle& handle) {
|
||||
isc_throw(BadValue, "listed subnet identifiers must be numbers");
|
||||
}
|
||||
|
||||
Lease4Collection leases =
|
||||
LeaseMgrFactory::instance().getLeases4((*subnet_id)->intValue());
|
||||
for (auto lease = leases.begin(); lease != leases.end(); ++lease) {
|
||||
ElementPtr lease_json = (*lease)->toElement();
|
||||
leases_json->add(lease_json);
|
||||
if (v4) {
|
||||
Lease4Collection leases =
|
||||
LeaseMgrFactory::instance().getLeases4((*subnet_id)->intValue());
|
||||
for (auto lease = leases.begin(); lease != leases.end(); ++lease) {
|
||||
ElementPtr lease_json = (*lease)->toElement();
|
||||
leases_json->add(lease_json);
|
||||
}
|
||||
} else {
|
||||
Lease6Collection leases =
|
||||
LeaseMgrFactory::instance().getLeases6((*subnet_id)->intValue());
|
||||
for (auto lease = leases.begin(); lease != leases.end(); ++lease) {
|
||||
ElementPtr lease_json = (*lease)->toElement();
|
||||
leases_json->add(lease_json);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -505,19 +517,32 @@ LeaseCmdsImpl::lease4GetAllHandler(CalloutHandle& handle) {
|
||||
|
||||
} else {
|
||||
// There is no 'subnets' argument so let's return all leases.
|
||||
Lease4Collection leases = LeaseMgrFactory::instance().getLeases4();
|
||||
for (auto lease = leases.begin(); lease != leases.end(); ++lease) {
|
||||
ElementPtr lease_json = (*lease)->toElement();
|
||||
leases_json->add(lease_json);
|
||||
if (v4) {
|
||||
Lease4Collection leases = LeaseMgrFactory::instance().getLeases4();
|
||||
for (auto lease = leases.begin(); lease != leases.end(); ++lease) {
|
||||
ElementPtr lease_json = (*lease)->toElement();
|
||||
leases_json->add(lease_json);
|
||||
}
|
||||
} else {
|
||||
Lease6Collection leases = LeaseMgrFactory::instance().getLeases6();
|
||||
for (auto lease = leases.begin(); lease != leases.end(); ++lease) {
|
||||
ElementPtr lease_json = (*lease)->toElement();
|
||||
leases_json->add(lease_json);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::ostringstream s;
|
||||
s << leases_json->size() << " IPv4 lease(s) found.";
|
||||
s << leases_json->size()
|
||||
<< " IPv" << (v4 ? "4" : "6")
|
||||
<< " lease(s) found.";
|
||||
ElementPtr args = Element::createMap();
|
||||
args->set("leases", leases_json);
|
||||
ConstElementPtr response = createAnswer(CONTROL_RESULT_SUCCESS,
|
||||
s.str(), args);
|
||||
ConstElementPtr response =
|
||||
createAnswer(leases_json->size() > 0 ?
|
||||
CONTROL_RESULT_SUCCESS :
|
||||
CONTROL_RESULT_EMPTY,
|
||||
s.str(), args);
|
||||
setResponse(handle, response);
|
||||
|
||||
|
||||
@ -782,8 +807,8 @@ LeaseCmds::leaseGetHandler(CalloutHandle& handle) {
|
||||
}
|
||||
|
||||
int
|
||||
LeaseCmds::lease4GetAllHandler(hooks::CalloutHandle& handle) {
|
||||
return (impl_->lease4GetAllHandler(handle));
|
||||
LeaseCmds::leaseGetAllHandler(hooks::CalloutHandle& handle) {
|
||||
return (impl_->leaseGetAllHandler(handle));
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
|
||||
// Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC")
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
@ -131,13 +131,14 @@ public:
|
||||
int
|
||||
leaseGetHandler(hooks::CalloutHandle& handle);
|
||||
|
||||
/// @brief lease4-get-all command handler
|
||||
/// @brief lease4-get-all, lease6-get-all command handler
|
||||
///
|
||||
/// This command attempts to retrieve all IPv4 leases or all IPv4 leases
|
||||
/// belonging to the particular subnets. If no subnet identifiers are
|
||||
/// provided, it returns all IPv4 leases from the database.
|
||||
/// This command attempts to retrieve all IPv4 or IPv6 leases,
|
||||
/// or all IPv4 or all IPv6 leases belonging to the particular
|
||||
/// subnets. If no subnet identifiers are provided, it returns all
|
||||
/// IPv4 or IPv6 leases from the database.
|
||||
///
|
||||
/// Example command for query by (subnet-ids):
|
||||
/// Example command for IPv4 query by (subnet-ids):
|
||||
/// {
|
||||
/// "command": "lease4-get-all",
|
||||
/// "arguments": {
|
||||
@ -145,16 +146,16 @@ public:
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// Example command for retrieving all leases:
|
||||
/// Example command for retrieving all IPv6 leases:
|
||||
/// {
|
||||
/// "command": "lease4-get-all",
|
||||
/// "command": "lease6-get-all",
|
||||
/// }
|
||||
///
|
||||
/// @param handle Callout context - which is expected to contain the
|
||||
/// get command JSON text in the "command" argument
|
||||
/// @return result of the operation.
|
||||
int
|
||||
lease4GetAllHandler(hooks::CalloutHandle& handle);
|
||||
leaseGetAllHandler(hooks::CalloutHandle& handle);
|
||||
|
||||
/// @brief lease4-del command handler
|
||||
///
|
||||
|
@ -53,17 +53,6 @@ int lease4_get(CalloutHandle& handle) {
|
||||
return(lease_cmds.leaseGetHandler(handle));
|
||||
}
|
||||
|
||||
/// @brief This is a command callout for 'lease4-get-all' command.
|
||||
///
|
||||
/// @param handle Callout handle used to retrieve a command and
|
||||
/// provide a response.
|
||||
/// @return 0 if this callout has been invoked successfully,
|
||||
/// 1 otherwise.
|
||||
int lease4_get_all(CalloutHandle& handle) {
|
||||
LeaseCmds lease_cmds;
|
||||
return (lease_cmds.lease4GetAllHandler(handle));
|
||||
}
|
||||
|
||||
/// @brief This is a command callout for 'lease6-get' command.
|
||||
///
|
||||
/// @param handle Callout handle used to retrieve a command and
|
||||
@ -75,6 +64,28 @@ int lease6_get(CalloutHandle& handle) {
|
||||
return(lease_cmds.leaseGetHandler(handle));
|
||||
}
|
||||
|
||||
/// @brief This is a command callout for 'lease4-get-all' command.
|
||||
///
|
||||
/// @param handle Callout handle used to retrieve a command and
|
||||
/// provide a response.
|
||||
/// @return 0 if this callout has been invoked successfully,
|
||||
/// 1 if an error occurs, 2 if empty.
|
||||
int lease4_get_all(CalloutHandle& handle) {
|
||||
LeaseCmds lease_cmds;
|
||||
return (lease_cmds.leaseGetAllHandler(handle));
|
||||
}
|
||||
|
||||
/// @brief This is a command callout for 'lease6-get-all' command.
|
||||
///
|
||||
/// @param handle Callout handle used to retrieve a command and
|
||||
/// provide a response.
|
||||
/// @return 0 if this callout has been invoked successfully,
|
||||
/// 1 if an error occurs, 2 if empty.
|
||||
int lease6_get_all(CalloutHandle& handle) {
|
||||
LeaseCmds lease_cmds;
|
||||
return (lease_cmds.leaseGetAllHandler(handle));
|
||||
}
|
||||
|
||||
/// @brief This is a command callout for 'lease4-del' command.
|
||||
///
|
||||
/// @param handle Callout handle used to retrieve a command and
|
||||
@ -151,6 +162,7 @@ int load(LibraryHandle& handle) {
|
||||
handle.registerCommandCallout("lease4-get", lease4_get);
|
||||
handle.registerCommandCallout("lease4-get-all", lease4_get_all);
|
||||
handle.registerCommandCallout("lease6-get", lease6_get);
|
||||
handle.registerCommandCallout("lease6-get-all", lease6_get_all);
|
||||
handle.registerCommandCallout("lease4-del", lease4_del);
|
||||
handle.registerCommandCallout("lease6-del", lease6_del);
|
||||
handle.registerCommandCallout("lease4-update", lease4_update);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1718,6 +1718,16 @@ CqlLeaseMgr::getLeases6(Lease::Type lease_type, const DUID &duid, uint32_t iaid,
|
||||
return (result);
|
||||
}
|
||||
|
||||
Lease6Collection
|
||||
CqlLeaseMgr::getLeases6(SubnetID) const {
|
||||
isc_throw(NotImplemented, "getLeases6(subnet_id) is not implemented");
|
||||
}
|
||||
|
||||
Lease6Collection
|
||||
CqlLeaseMgr::getLeases6() const {
|
||||
isc_throw(NotImplemented, "getLeases6() is not implemented");
|
||||
}
|
||||
|
||||
void
|
||||
CqlLeaseMgr::getExpiredLeases4(Lease4Collection &expired_leases,
|
||||
const size_t max_leases) const {
|
||||
|
@ -267,6 +267,19 @@ public:
|
||||
const DUID& duid,
|
||||
uint32_t iaid,
|
||||
SubnetID subnet_id) const override;
|
||||
|
||||
/// @brief Returns all IPv6 leases for the particular subnet identifier.
|
||||
///
|
||||
/// @param subnet_id subnet identifier.
|
||||
///
|
||||
/// @return Lease collection (may be empty if no IPv6 lease found).
|
||||
virtual Lease6Collection getLeases6(SubnetID subnet_id) const;
|
||||
|
||||
/// @brief Returns all IPv6 leases.
|
||||
///
|
||||
/// @return Lease collection (may be empty if no IPv6 lease found).
|
||||
virtual Lease6Collection getLeases6() const;
|
||||
|
||||
/// @brief Returns a collection of expired DHCPv6 leases.
|
||||
///
|
||||
/// This method returns at most @c max_leases expired leases. The leases
|
||||
@ -316,7 +329,7 @@ public:
|
||||
/// @param lease6 The lease to be updated.
|
||||
///
|
||||
/// @throw isc::dhcp::NoSuchLease Attempt to update a lease that did not
|
||||
/// exist.
|
||||
|
||||
/// @throw isc::dhcp::DbOperationError An operation on the open database has
|
||||
/// failed.
|
||||
virtual void updateLease6(const Lease6Ptr& lease6) override;
|
||||
|
@ -463,6 +463,10 @@ in the message.
|
||||
A debug message issued when the server is attempting to obtain all IPv4
|
||||
leases from the memory file database.
|
||||
|
||||
% DHCPSRV_MEMFILE_GET6 obtaining all IPv6 leases
|
||||
A debug message issued when the server is attempting to obtain all IPv6
|
||||
leases from the memory file database.
|
||||
|
||||
% 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.
|
||||
@ -510,6 +514,10 @@ lease from the memory file database for a client with the specified IAID
|
||||
A debug message issued when the server is attempting to obtain all IPv4
|
||||
leases for a given subnet identifier from the memory file database.
|
||||
|
||||
% DHCPSRV_MEMFILE_GET_SUBID6 obtaining IPv6 leases for subnet ID %1
|
||||
A debug message issued when the server is attempting to obtain all IPv6
|
||||
leases for a given subnet identifier from the memory file database.
|
||||
|
||||
% DHCPSRV_MEMFILE_GET_SUBID_CLIENTID obtaining IPv4 lease for subnet ID %1 and client ID %2
|
||||
A debug message issued when the server is attempting to obtain an IPv4
|
||||
lease from the memory file database for a client with the specified
|
||||
@ -697,6 +705,10 @@ exit code. This is most likely due to a network issue.
|
||||
A debug message issued when the server is attempting to obtain all IPv4
|
||||
leases from the MySQL database.
|
||||
|
||||
% DHCPSRV_MYSQL_GET6 obtaining all IPv6 leases
|
||||
A debug message issued when the server is attempting to obtain all IPv6
|
||||
leases from the MySQL database.
|
||||
|
||||
% DHCPSRV_MYSQL_GET_ADDR4 obtaining IPv4 lease for address %1
|
||||
A debug message issued when the server is attempting to obtain an IPv4
|
||||
lease from the MySQL database for the specified address.
|
||||
@ -739,6 +751,10 @@ lease from the MySQL database for a client with the specified IAID
|
||||
A debug message issued when the server is attempting to obtain all IPv4
|
||||
leases for a given subnet identifier from the MySQL database.
|
||||
|
||||
% DHCPSRV_MYSQL_GET_SUBID6 obtaining IPv6 leases for subnet ID %1
|
||||
A debug message issued when the server is attempting to obtain all IPv6
|
||||
leases for a given subnet identifier from the MySQL database.
|
||||
|
||||
% DHCPSRV_MYSQL_GET_SUBID_CLIENTID obtaining IPv4 lease for subnet ID %1 and client ID %2
|
||||
A debug message issued when the server is attempting to obtain an IPv4
|
||||
lease from the MySQL database for a client with the specified subnet ID
|
||||
@ -859,6 +875,10 @@ exit code. This is most likely due to a network issue.
|
||||
A debug message issued when the server is attempting to obtain all IPv4
|
||||
leases from the PostgreSQL database.
|
||||
|
||||
% DHCPSRV_PGSQL_GET6 obtaining all IPv6 leases
|
||||
A debug message issued when the server is attempting to obtain all IPv6
|
||||
leases from the PostgreSQL database.
|
||||
|
||||
% DHCPSRV_PGSQL_GET_ADDR4 obtaining IPv4 lease for address %1
|
||||
A debug message issued when the server is attempting to obtain an IPv4
|
||||
lease from the PostgreSQL database for the specified address.
|
||||
@ -901,6 +921,10 @@ lease from the PostgreSQL database for a client with the specified IAID
|
||||
A debug message issued when the server is attempting to obtain all IPv4
|
||||
leases for a given subnet identifier from the PostgreSQL database.
|
||||
|
||||
% DHCPSRV_PGSQL_GET_SUBID6 obtaining IPv6 leases for subnet ID %1
|
||||
A debug message issued when the server is attempting to obtain all IPv6
|
||||
leases for a given subnet identifier from the PostgreSQL database.
|
||||
|
||||
% DHCPSRV_PGSQL_GET_SUBID_CLIENTID obtaining IPv4 lease for subnet ID %1 and client ID %2
|
||||
A debug message issued when the server is attempting to obtain an IPv4
|
||||
lease from the PostgreSQL database for a client with the specified subnet ID
|
||||
|
@ -341,6 +341,18 @@ public:
|
||||
Lease6Ptr getLease6(Lease::Type type, const DUID& duid,
|
||||
uint32_t iaid, SubnetID subnet_id) const;
|
||||
|
||||
/// @brief Returns all IPv6 leases for the particular subnet identifier.
|
||||
///
|
||||
/// @param subnet_id subnet identifier.
|
||||
///
|
||||
/// @return Lease collection (may be empty if no IPv6 lease found).
|
||||
virtual Lease6Collection getLeases6(SubnetID subnet_id) const = 0;
|
||||
|
||||
/// @brief Returns all IPv6 leases.
|
||||
///
|
||||
/// @return Lease collection (may be empty if no IPv6 lease found).
|
||||
virtual Lease6Collection getLeases6() const = 0;
|
||||
|
||||
/// @brief Returns a collection of expired DHCPv6 leases.
|
||||
///
|
||||
/// This method returns at most @c max_leases expired leases. The leases
|
||||
|
@ -831,6 +831,36 @@ Memfile_LeaseMgr::getLeases6(Lease::Type type,
|
||||
return (collection);
|
||||
}
|
||||
|
||||
Lease6Collection
|
||||
Memfile_LeaseMgr::getLeases6(SubnetID subnet_id) const {
|
||||
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_GET_SUBID6)
|
||||
.arg(subnet_id);
|
||||
|
||||
Lease6Collection collection;
|
||||
const Lease6StorageSubnetIdIndex& idx = storage6_.get<SubnetIdIndexTag>();
|
||||
std::pair<Lease6StorageSubnetIdIndex::const_iterator,
|
||||
Lease6StorageSubnetIdIndex::const_iterator> l =
|
||||
idx.equal_range(subnet_id);
|
||||
|
||||
for (auto lease = l.first; lease != l.second; ++lease) {
|
||||
collection.push_back(Lease6Ptr(new Lease6(**lease)));
|
||||
}
|
||||
|
||||
return (collection);
|
||||
}
|
||||
|
||||
Lease6Collection
|
||||
Memfile_LeaseMgr::getLeases6() const {
|
||||
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_GET6);
|
||||
|
||||
Lease6Collection collection;
|
||||
for (auto lease = storage6_.begin(); lease != storage6_.end(); ++lease ) {
|
||||
collection.push_back(Lease6Ptr(new Lease6(**lease)));
|
||||
}
|
||||
|
||||
return (collection);
|
||||
}
|
||||
|
||||
void
|
||||
Memfile_LeaseMgr::getExpiredLeases6(Lease6Collection& expired_leases,
|
||||
const size_t max_leases) const {
|
||||
|
@ -271,6 +271,18 @@ public:
|
||||
uint32_t iaid,
|
||||
SubnetID subnet_id) const;
|
||||
|
||||
/// @brief Returns all IPv6 leases for the particular subnet identifier.
|
||||
///
|
||||
/// @param subnet_id subnet identifier.
|
||||
///
|
||||
/// @return Lease collection (may be empty if no IPv6 lease found).
|
||||
virtual Lease6Collection getLeases6(SubnetID subnet_id) const;
|
||||
|
||||
/// @brief Returns all IPv6 leases.
|
||||
///
|
||||
/// @return Lease collection (may be empty if no IPv6 lease found).
|
||||
virtual Lease6Collection getLeases6() const;
|
||||
|
||||
/// @brief Returns a collection of expired DHCPv6 leases.
|
||||
///
|
||||
/// This method returns at most @c max_leases expired leases. The leases
|
||||
|
@ -153,6 +153,14 @@ tagged_statements = { {
|
||||
"WHERE state != ? AND expire < ? "
|
||||
"ORDER BY expire ASC "
|
||||
"LIMIT ?"},
|
||||
{MySqlLeaseMgr::GET_LEASE6,
|
||||
"SELECT address, duid, valid_lifetime, "
|
||||
"expire, subnet_id, pref_lifetime, "
|
||||
"lease_type, iaid, prefix_len, "
|
||||
"fqdn_fwd, fqdn_rev, hostname, "
|
||||
"hwaddr, hwtype, hwaddr_source, "
|
||||
"state "
|
||||
"FROM lease6"},
|
||||
{MySqlLeaseMgr::GET_LEASE6_ADDR,
|
||||
"SELECT address, duid, valid_lifetime, "
|
||||
"expire, subnet_id, pref_lifetime, "
|
||||
@ -181,6 +189,15 @@ tagged_statements = { {
|
||||
"FROM lease6 "
|
||||
"WHERE duid = ? AND iaid = ? AND subnet_id = ? "
|
||||
"AND lease_type = ?"},
|
||||
{MySqlLeaseMgr::GET_LEASE6_SUBID,
|
||||
"SELECT address, duid, valid_lifetime, "
|
||||
"expire, subnet_id, pref_lifetime, "
|
||||
"lease_type, iaid, prefix_len, "
|
||||
"fqdn_fwd, fqdn_rev, hostname, "
|
||||
"hwaddr, hwtype, hwaddr_source, "
|
||||
"state "
|
||||
"FROM lease6 "
|
||||
"WHERE subnet_id = ?"},
|
||||
{MySqlLeaseMgr::GET_LEASE6_EXPIRE,
|
||||
"SELECT address, duid, valid_lifetime, "
|
||||
"expire, subnet_id, pref_lifetime, "
|
||||
@ -1909,6 +1926,37 @@ MySqlLeaseMgr::getLeases6(Lease::Type lease_type,
|
||||
return (result);
|
||||
}
|
||||
|
||||
Lease6Collection
|
||||
MySqlLeaseMgr::getLeases6(SubnetID subnet_id) const {
|
||||
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MYSQL_GET_SUBID6)
|
||||
.arg(subnet_id);
|
||||
|
||||
// Set up the WHERE clause value
|
||||
MYSQL_BIND inbind[1];
|
||||
memset(inbind, 0, sizeof(inbind));
|
||||
|
||||
// Subnet ID
|
||||
inbind[0].buffer_type = MYSQL_TYPE_LONG;
|
||||
inbind[0].buffer = reinterpret_cast<char*>(&subnet_id);
|
||||
inbind[0].is_unsigned = MLM_TRUE;
|
||||
|
||||
// ... and get the data
|
||||
Lease6Collection result;
|
||||
getLeaseCollection(GET_LEASE6_SUBID, inbind, result);
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
Lease6Collection
|
||||
MySqlLeaseMgr::getLeases6() const {
|
||||
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MYSQL_GET6);
|
||||
|
||||
Lease6Collection result;
|
||||
getLeaseCollection(GET_LEASE6, 0, result);
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
void
|
||||
MySqlLeaseMgr::getExpiredLeases6(Lease6Collection& expired_leases,
|
||||
const size_t max_leases) const {
|
||||
|
@ -268,6 +268,18 @@ public:
|
||||
virtual Lease6Collection getLeases6(Lease::Type type, const DUID& duid,
|
||||
uint32_t iaid, SubnetID subnet_id) const;
|
||||
|
||||
/// @brief Returns all IPv6 leases for the particular subnet identifier.
|
||||
///
|
||||
/// @param subnet_id subnet identifier.
|
||||
///
|
||||
/// @return Lease collection (may be empty if no IPv6 lease found).
|
||||
virtual Lease6Collection getLeases6(SubnetID subnet_id) const;
|
||||
|
||||
/// @brief Returns all IPv6 leases.
|
||||
///
|
||||
/// @return Lease collection (may be empty if no IPv6 lease found).
|
||||
virtual Lease6Collection getLeases6() const;
|
||||
|
||||
/// @brief Returns a collection of expired DHCPv6 leases.
|
||||
///
|
||||
/// This method returns at most @c max_leases expired leases. The leases
|
||||
@ -436,9 +448,11 @@ public:
|
||||
GET_LEASE4_HWADDR_SUBID, // Get lease4 by HW address & subnet ID
|
||||
GET_LEASE4_SUBID, // Get IPv4 leases by subnet ID
|
||||
GET_LEASE4_EXPIRE, // Get lease4 by expiration.
|
||||
GET_LEASE6, // Get all IPv6 leases
|
||||
GET_LEASE6_ADDR, // Get lease6 by address
|
||||
GET_LEASE6_DUID_IAID, // Get lease6 by DUID and IAID
|
||||
GET_LEASE6_DUID_IAID_SUBID, // Get lease6 by DUID, IAID and subnet ID
|
||||
GET_LEASE6_SUBID, // Get IPv6 leases by subnet ID
|
||||
GET_LEASE6_EXPIRE, // Get lease6 by expiration.
|
||||
GET_VERSION, // Obtain version number
|
||||
INSERT_LEASE4, // Add entry to lease4 table
|
||||
|
@ -128,6 +128,15 @@ PgSqlTaggedStatement tagged_statements[] = {
|
||||
"ORDER BY expire "
|
||||
"LIMIT $3"},
|
||||
|
||||
// GET_LEASE6
|
||||
{ 0, { OID_NONE },
|
||||
"get_lease6",
|
||||
"SELECT address, duid, valid_lifetime, "
|
||||
"extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
|
||||
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
|
||||
"state "
|
||||
"FROM lease6"},
|
||||
|
||||
// GET_LEASE6_ADDR
|
||||
{ 2, { OID_VARCHAR, OID_INT2 },
|
||||
"get_lease6_addr",
|
||||
@ -159,6 +168,16 @@ PgSqlTaggedStatement tagged_statements[] = {
|
||||
"WHERE lease_type = $1 "
|
||||
"AND duid = $2 AND iaid = $3 AND subnet_id = $4"},
|
||||
|
||||
// GET_LEASE6_SUBID
|
||||
{ 1, { OID_INT8 },
|
||||
"get_lease6_subid",
|
||||
"SELECT address, duid, valid_lifetime, "
|
||||
"extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
|
||||
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
|
||||
"state "
|
||||
"FROM lease6 "
|
||||
"WHERE subnet_id = $1"},
|
||||
|
||||
// GET_LEASE6_EXPIRE
|
||||
{ 3, { OID_INT8, OID_TIMESTAMP, OID_INT8 },
|
||||
"get_lease6_expire",
|
||||
@ -1205,6 +1224,38 @@ PgSqlLeaseMgr::getLeases6(Lease::Type lease_type, const DUID& duid,
|
||||
return (result);
|
||||
}
|
||||
|
||||
Lease6Collection
|
||||
PgSqlLeaseMgr::getLeases6(SubnetID subnet_id) const {
|
||||
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_PGSQL_GET_SUBID6)
|
||||
.arg(subnet_id);
|
||||
|
||||
// Set up the WHERE clause value
|
||||
PsqlBindArray bind_array;
|
||||
|
||||
// SUBNET_ID
|
||||
std::string subnet_id_str = boost::lexical_cast<std::string>(subnet_id);
|
||||
bind_array.add(subnet_id_str);
|
||||
|
||||
// ... and get the data
|
||||
Lease6Collection result;
|
||||
getLeaseCollection(GET_LEASE6_SUBID, bind_array, result);
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
Lease6Collection
|
||||
PgSqlLeaseMgr::getLeases6() const {
|
||||
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_PGSQL_GET6);
|
||||
|
||||
// Provide empty binding array because our query has no parameters in
|
||||
// WHERE clause.
|
||||
PsqlBindArray bind_array;
|
||||
Lease6Collection result;
|
||||
getLeaseCollection(GET_LEASE6, bind_array, result);
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
void
|
||||
PgSqlLeaseMgr::getExpiredLeases6(Lease6Collection& expired_leases,
|
||||
const size_t max_leases) const {
|
||||
|
@ -161,18 +161,6 @@ public:
|
||||
virtual Lease4Ptr getLease4(const ClientId& client_id, const HWAddr& hwaddr,
|
||||
SubnetID subnet_id) const;
|
||||
|
||||
/// @brief Returns all IPv4 leases for the particular subnet identifier.
|
||||
///
|
||||
/// @param subnet_id subnet identifier.
|
||||
///
|
||||
/// @return Lease collection (may be empty if no IPv4 lease found).
|
||||
virtual Lease4Collection getLeases4(SubnetID subnet_id) const;
|
||||
|
||||
/// @brief Returns all IPv4 leases.
|
||||
///
|
||||
/// @return Lease collection (may be empty if no IPv4 lease found).
|
||||
virtual Lease4Collection getLeases4() const;
|
||||
|
||||
/// @brief Returns existing IPv4 lease for specified client-id
|
||||
///
|
||||
/// There can be at most one lease for a given HW address in a single
|
||||
@ -188,6 +176,18 @@ public:
|
||||
virtual Lease4Ptr getLease4(const ClientId& clientid,
|
||||
SubnetID subnet_id) const;
|
||||
|
||||
/// @brief Returns all IPv4 leases for the particular subnet identifier.
|
||||
///
|
||||
/// @param subnet_id subnet identifier.
|
||||
///
|
||||
/// @return Lease collection (may be empty if no IPv4 lease found).
|
||||
virtual Lease4Collection getLeases4(SubnetID subnet_id) const;
|
||||
|
||||
/// @brief Returns all IPv4 leases.
|
||||
///
|
||||
/// @return Lease collection (may be empty if no IPv4 lease found).
|
||||
virtual Lease4Collection getLeases4() const;
|
||||
|
||||
/// @brief Returns existing IPv6 lease for a given IPv6 address.
|
||||
///
|
||||
/// For a given address, we assume that there will be only one lease.
|
||||
@ -242,6 +242,18 @@ public:
|
||||
virtual Lease6Collection getLeases6(Lease::Type type, const DUID& duid,
|
||||
uint32_t iaid, SubnetID subnet_id) const;
|
||||
|
||||
/// @brief Returns all IPv6 leases for the particular subnet identifier.
|
||||
///
|
||||
/// @param subnet_id subnet identifier.
|
||||
///
|
||||
/// @return Lease collection (may be empty if no IPv6 lease found).
|
||||
virtual Lease6Collection getLeases6(SubnetID subnet_id) const;
|
||||
|
||||
/// @brief Returns all IPv6 leases.
|
||||
///
|
||||
/// @return Lease collection (may be empty if no IPv6 lease found).
|
||||
virtual Lease6Collection getLeases6() const;
|
||||
|
||||
/// @brief Returns a collection of expired DHCPv6 leases.
|
||||
///
|
||||
/// This method returns at most @c max_leases expired leases. The leases
|
||||
@ -427,9 +439,11 @@ public:
|
||||
GET_LEASE4_HWADDR_SUBID, // Get lease4 by HW address & subnet ID
|
||||
GET_LEASE4_SUBID, // Get IPv4 leases by subnet ID
|
||||
GET_LEASE4_EXPIRE, // Get expired lease4
|
||||
GET_LEASE6, // Get all IPv6 leases
|
||||
GET_LEASE6_ADDR, // Get lease6 by address
|
||||
GET_LEASE6_DUID_IAID, // Get lease6 by DUID and IAID
|
||||
GET_LEASE6_DUID_IAID_SUBID, // Get lease6 by DUID, IAID and subnet ID
|
||||
GET_LEASE6_SUBID, // Get IPv6 leases by subnet ID
|
||||
GET_LEASE6_EXPIRE, // Get expired lease6
|
||||
GET_VERSION, // Obtain version number
|
||||
INSERT_LEASE4, // Add entry to lease4 table
|
||||
|
@ -1246,6 +1246,33 @@ GenericLeaseMgrTest::testGetLeases4() {
|
||||
ASSERT_EQ(leases.size(), returned.size());
|
||||
}
|
||||
|
||||
void
|
||||
GenericLeaseMgrTest::testGetLeases6SubnetId() {
|
||||
// Get the leases to be used for the test and add to the database.
|
||||
vector<Lease6Ptr> leases = createLeases6();
|
||||
for (size_t i = 0; i < leases.size(); ++i) {
|
||||
EXPECT_TRUE(lmptr_->addLease(leases[i]));
|
||||
}
|
||||
|
||||
// There should be exactly two leases for the subnet id that the second
|
||||
// lease belongs to.
|
||||
Lease6Collection returned = lmptr_->getLeases6(leases[1]->subnet_id_);
|
||||
ASSERT_EQ(2, returned.size());
|
||||
}
|
||||
|
||||
void
|
||||
GenericLeaseMgrTest::testGetLeases6() {
|
||||
// Get the leases to be used for the test and add to the database
|
||||
vector<Lease6Ptr> leases = createLeases6();
|
||||
for (size_t i = 0; i < leases.size(); ++i) {
|
||||
EXPECT_TRUE(lmptr_->addLease(leases[i]));
|
||||
}
|
||||
|
||||
// All leases should be returned.
|
||||
Lease6Collection returned = lmptr_->getLeases6();
|
||||
ASSERT_EQ(leases.size(), returned.size());
|
||||
}
|
||||
|
||||
void
|
||||
GenericLeaseMgrTest::testGetLeases6DuidIaid() {
|
||||
// Get the leases to be used for the test.
|
||||
|
@ -206,6 +206,12 @@ public:
|
||||
/// @brief Test method which returns all IPv4 leases.
|
||||
void testGetLeases4();
|
||||
|
||||
/// @brief Test method which returns all IPv6 leases for Subnet ID.
|
||||
void testGetLeases6SubnetId();
|
||||
|
||||
/// @brief Test method which returns all IPv6 leases.
|
||||
void testGetLeases6();
|
||||
|
||||
/// @brief Basic Lease4 Checks
|
||||
///
|
||||
/// Checks that the addLease, getLease4(by address), getLease4(hwaddr,subnet_id),
|
||||
|
@ -178,6 +178,22 @@ public:
|
||||
return (leases6_);
|
||||
}
|
||||
|
||||
/// @brief Returns all IPv6 leases for the particular subnet identifier.
|
||||
///
|
||||
/// @param subnet_id subnet identifier.
|
||||
///
|
||||
/// @return Lease collection (may be empty if no IPv6 lease found).
|
||||
virtual Lease6Collection getLeases6(SubnetID) const {
|
||||
return (Lease6Collection());
|
||||
}
|
||||
|
||||
/// @brief Returns all IPv6 leases.
|
||||
///
|
||||
/// @return Lease collection (may be empty if no IPv6 lease found).
|
||||
virtual Lease6Collection getLeases6() const {
|
||||
return (Lease6Collection());
|
||||
}
|
||||
|
||||
|
||||
/// @brief Returns expired DHCPv6 leases.
|
||||
///
|
||||
|
@ -929,6 +929,18 @@ TEST_F(MemfileLeaseMgrTest, getLeases4) {
|
||||
testGetLeases4();
|
||||
}
|
||||
|
||||
// This test checks that all IPv6 leases for a specified subnet id are returned.
|
||||
TEST_F(MemfileLeaseMgrTest, getLeases6SubnetId) {
|
||||
startBackend(V6);
|
||||
testGetLeases6SubnetId();
|
||||
}
|
||||
|
||||
// This test checks that all IPv6 leases are returned.
|
||||
TEST_F(MemfileLeaseMgrTest, getLeases6) {
|
||||
startBackend(V6);
|
||||
testGetLeases6();
|
||||
}
|
||||
|
||||
/// @brief Basic Lease6 Checks
|
||||
///
|
||||
/// Checks that the addLease, getLease6 (by address) and deleteLease (with an
|
||||
|
@ -331,6 +331,16 @@ TEST_F(MySqlLeaseMgrTest, getLeases4) {
|
||||
testGetLeases4();
|
||||
}
|
||||
|
||||
// This test checks that all IPv6 leases for a specified subnet id are returned.
|
||||
TEST_F(MySqlLeaseMgrTest, getLeases6SubnetId) {
|
||||
testGetLeases6SubnetId();
|
||||
}
|
||||
|
||||
// This test checks that all IPv6 leases are returned.
|
||||
TEST_F(MySqlLeaseMgrTest, getLeases6) {
|
||||
testGetLeases6();
|
||||
}
|
||||
|
||||
/// @brief Basic Lease4 Checks
|
||||
///
|
||||
/// Checks that the addLease, getLease4(by address), getLease4(hwaddr,subnet_id),
|
||||
|
@ -290,6 +290,16 @@ TEST_F(PgSqlLeaseMgrTest, getLeases4) {
|
||||
testGetLeases4();
|
||||
}
|
||||
|
||||
// This test checks that all IPv6 leases for a specified subnet id are returned.
|
||||
TEST_F(PgSqlLeaseMgrTest, getLeases6SubnetId) {
|
||||
testGetLeases6SubnetId();
|
||||
}
|
||||
|
||||
// This test checks that all IPv6 leases are returned.
|
||||
TEST_F(PgSqlLeaseMgrTest, getLeases6) {
|
||||
testGetLeases6();
|
||||
}
|
||||
|
||||
/// @brief Basic Lease4 Checks
|
||||
///
|
||||
/// Checks that the addLease, getLease4(by address), getLease4(hwaddr,subnet_id),
|
||||
|
@ -514,7 +514,9 @@ ALTER TABLE dhcp6_options ADD COLUMN user_context TEXT NULL;
|
||||
CREATE INDEX lease4_by_subnet_id ON lease4 (subnet_id);
|
||||
|
||||
# Create for searching leases by subnet identifier and lease type.
|
||||
CREATE INDEX lease6_by_subnet_id_lease_type ON lease6 (subnet_id, lease_type);
|
||||
#CREATE INDEX lease6_by_subnet_id_lease_type ON lease6 (subnet_id, lease_type);
|
||||
# Create for searching leases by subnet identifier.
|
||||
CREATE INDEX lease6_by_subnet_id ON lease6 (subnet_id);
|
||||
|
||||
# Update the schema version number
|
||||
UPDATE schema_version
|
||||
|
@ -28,7 +28,9 @@ ALTER TABLE dhcp6_options ADD COLUMN user_context TEXT NULL;
|
||||
CREATE INDEX lease4_by_subnet_id ON lease4 (subnet_id);
|
||||
|
||||
# Create for searching leases by subnet identifier and lease type.
|
||||
CREATE INDEX lease6_by_subnet_id_lease_type ON lease6 (subnet_id, lease_type);
|
||||
#CREATE INDEX lease6_by_subnet_id_lease_type ON lease6 (subnet_id, lease_type);
|
||||
# Create for searching leases by subnet identifier.
|
||||
CREATE INDEX lease6_by_subnet_id ON lease6 (subnet_id);
|
||||
|
||||
# Update the schema version number
|
||||
UPDATE schema_version
|
||||
|
@ -541,7 +541,9 @@ ALTER TABLE dhcp6_options ADD COLUMN user_context TEXT;
|
||||
CREATE INDEX lease4_by_subnet_id ON lease4 (subnet_id);
|
||||
|
||||
-- Create for searching leases by subnet identifier and lease type.
|
||||
CREATE INDEX lease6_by_subnet_id_lease_type ON lease6 (subnet_id, lease_type);
|
||||
-- CREATE INDEX lease6_by_subnet_id_lease_type ON lease6 (subnet_id, lease_type);
|
||||
-- Create for searching leases by subnet identifier.
|
||||
CREATE INDEX lease6_by_subnet_id ON lease6 (subnet_id);
|
||||
|
||||
-- Set 4.0 schema version.
|
||||
UPDATE schema_version
|
||||
|
@ -30,7 +30,9 @@ ALTER TABLE dhcp6_options ADD COLUMN user_context TEXT;
|
||||
CREATE INDEX lease4_by_subnet_id ON lease4 (subnet_id);
|
||||
|
||||
-- Create for searching leases by subnet identifier and lease type.
|
||||
CREATE INDEX lease6_by_subnet_id_lease_type ON lease6 (subnet_id, lease_type);
|
||||
-- CREATE INDEX lease6_by_subnet_id_lease_type ON lease6 (subnet_id, lease_type);
|
||||
-- Create for searching leases by subnet identifier.
|
||||
CREATE INDEX lease6_by_subnet_id ON lease6 (subnet_id);
|
||||
|
||||
-- Set 4.0 schema version.
|
||||
UPDATE schema_version
|
||||
|
Loading…
x
Reference in New Issue
Block a user