Skip to content

Commit 66a216e

Browse files
author
Razvan Becheriu
committed
[3826] addressed review comments
1 parent 4c40c4e commit 66a216e

File tree

16 files changed

+204
-37
lines changed

16 files changed

+204
-37
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2382. [build] razvan
2+
Implemented the 'lease6-get-by-hw-address' command used to query
3+
IPv6 leases by HW Address.
4+
(Gitlab #3826)
5+
16
Kea 3.1.0 (development) released on July 30, 2025
27

38
2381. [build] razvan

src/bin/admin/tests/mysql_tests.sh.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ mysql_db_version_test() {
157157
run_command \
158158
"${kea_admin}" db-version mysql -u "${db_user}" -p "${db_password}" -n "${db_name}"
159159
version="${OUTPUT}"
160-
assert_str_eq "31.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
160+
assert_str_eq "32.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
161161

162162
# Let's wipe the whole database
163163
mysql_wipe
@@ -1200,7 +1200,7 @@ mysql_upgrade_test() {
12001200

12011201
# Verify that the upgraded schema reports the latest version.
12021202
version=$("${kea_admin}" db-version mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}")
1203-
assert_str_eq "31.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
1203+
assert_str_eq "32.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
12041204

12051205
# Let's check that the new tables are indeed there.
12061206

src/bin/admin/tests/pgsql_tests.sh.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pgsql_db_version_test() {
158158
run_command \
159159
"${kea_admin}" db-version pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}"
160160
version="${OUTPUT}"
161-
assert_str_eq "30.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
161+
assert_str_eq "31.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
162162

163163
# Let's wipe the whole database
164164
pgsql_wipe
@@ -1171,7 +1171,7 @@ pgsql_upgrade_test() {
11711171

11721172
# Verify upgraded schema reports the latest version.
11731173
version=$("${kea_admin}" db-version pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}")
1174-
assert_str_eq "30.0" "${version}" 'Expected kea-admin to return %s, returned value was %s'
1174+
assert_str_eq "31.0" "${version}" 'Expected kea-admin to return %s, returned value was %s'
11751175

11761176
# Check 1.0 to 2.0 upgrade
11771177
pgsql_upgrade_1_0_to_2_0_test

src/hooks/dhcp/lease_cmds/lease_cmds.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,6 +1597,10 @@ LeaseCmdsImpl::leaseGetByHwAddressHandler(CalloutHandle& handle) {
15971597
isc_throw(BadValue, "'hw-address' parameter must be a string");
15981598
}
15991599

1600+
if (!v4 && hw_address->stringValue().empty()) {
1601+
isc_throw(BadValue, "'hw-address' parameter must not be empty");
1602+
}
1603+
16001604
HWAddr hwaddr = HWAddr::fromText(hw_address->stringValue());
16011605

16021606
ElementPtr leases_json = Element::createList();

src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds4_unittest.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,6 +1794,16 @@ void Lease4CmdsTest::testLease4GetByHwAddressFind0() {
17941794
"}";
17951795
string exp_rsp = "0 IPv4 lease(s) found.";
17961796
testCommand(cmd, CONTROL_RESULT_EMPTY, exp_rsp);
1797+
1798+
// Empty HWAddr.
1799+
cmd =
1800+
"{\n"
1801+
" \"command\": \"lease4-get-by-hw-address\",\n"
1802+
" \"arguments\": {"
1803+
" \"hw-address\": \"\"\n"
1804+
" }\n"
1805+
"}";
1806+
testCommand(cmd, CONTROL_RESULT_EMPTY, exp_rsp);
17971807
}
17981808

17991809
void Lease4CmdsTest::testLease4GetByHwAddressFind2() {

src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds6_unittest.cc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,6 +2014,17 @@ void Lease6CmdsTest::testLease6GetByHwAddressParams() {
20142014
exp_rsp = "'hw-address' parameter must be a string";
20152015
testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp);
20162016

2017+
// Empty HWAddr.
2018+
cmd =
2019+
"{\n"
2020+
" \"command\": \"lease6-get-by-hw-address\",\n"
2021+
" \"arguments\": {"
2022+
" \"hw-address\": \"\"\n"
2023+
" }\n"
2024+
"}";
2025+
exp_rsp = "'hw-address' parameter must not be empty";
2026+
testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp);
2027+
20172028
// Simply bad value.
20182029
cmd =
20192030
"{\n"
@@ -2071,10 +2082,10 @@ void Lease6CmdsTest::testLease6GetByHwAddressFind2() {
20712082
// Let's check if the response makes any sense.
20722083
ConstElementPtr lease = leases->get(0);
20732084
ASSERT_TRUE(lease);
2074-
checkLease6(lease, "2001:db8:1::1", 0, 66, "42:42:42:42:42:42:42:42", "08:08:08:08:08:08");
2085+
checkLease6(lease, "2001:db8:2::1", 0, 99, "42:42:42:42:42:42:42:42", "08:08:08:08:08:08");
20752086
lease = leases->get(1);
20762087
ASSERT_TRUE(lease);
2077-
checkLease6(lease, "2001:db8:2::1", 0, 99, "42:42:42:42:42:42:42:42", "08:08:08:08:08:08");
2088+
checkLease6(lease, "2001:db8:1::1", 0, 66, "42:42:42:42:42:42:42:42", "08:08:08:08:08:08");
20782089
}
20792090

20802091
void Lease6CmdsTest::testLease6GetByDuidParams() {

src/lib/dhcpsrv/memfile_lease_mgr.cc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,13 +1459,11 @@ Memfile_LeaseMgr::getLease6Internal(Lease::Type type,
14591459
void
14601460
Memfile_LeaseMgr::getLease6Internal(const HWAddr& hwaddr,
14611461
Lease6Collection& collection) const {
1462-
// Using composite index by 'hw address' and 'subnet id'. It is
1463-
// ok to use it for searching by the 'hw address' only.
1464-
const Lease6StorageHWAddressSubnetIdIndex& idx =
1465-
storage6_.get<HWAddressSubnetIdIndexTag>();
1466-
std::pair<Lease6StorageHWAddressSubnetIdIndex::const_iterator,
1467-
Lease6StorageHWAddressSubnetIdIndex::const_iterator> l
1468-
= idx.equal_range(boost::make_tuple(hwaddr.hwaddr_));
1462+
const Lease6StorageHWAddressIndex& idx =
1463+
storage6_.get<HWAddressIndexTag>();
1464+
std::pair<Lease6StorageHWAddressIndex::const_iterator,
1465+
Lease6StorageHWAddressIndex::const_iterator> l
1466+
= idx.equal_range(hwaddr.hwaddr_);
14691467

14701468
BOOST_FOREACH(auto const& lease, l) {
14711469
collection.push_back(Lease6Ptr(new Lease6(*lease)));

src/lib/dhcpsrv/memfile_lease_storage.h

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ struct ExpirationIndexTag { };
3737
/// @brief Tag for indexes by HW address, subnet-id tuple.
3838
struct HWAddressSubnetIdIndexTag { };
3939

40+
/// @brief Tag for indexes by HW address.
41+
struct HWAddressIndexTag { };
42+
4043
/// @brief Tag for indexes by client-id, subnet-id tuple.
4144
struct ClientIdSubnetIdIndexTag { };
4245

@@ -176,25 +179,15 @@ typedef boost::multi_index_container<
176179
>
177180
>,
178181

179-
// Specification of the eight index starts here.
180-
boost::multi_index::ordered_non_unique<
181-
boost::multi_index::tag<HWAddressSubnetIdIndexTag>,
182-
// This is a composite index that combines two attributes of the
183-
// Lease6 object: hardware address and subnet id.
184-
boost::multi_index::composite_key<
185-
Lease6,
186-
// The hardware address is held in the hwaddr_ member of the
187-
// Lease4 object, which is a HWAddr object. Boost does not
188-
// provide a key extractor for getting a member of a member,
189-
// so we need a simple method for that.
190-
boost::multi_index::const_mem_fun<Lease, const std::vector<uint8_t>&,
191-
&Lease::getHWAddrVector>,
192-
// The subnet id is held in the subnet_id_ member of Lease6
193-
// class. Note that the subnet_id_ is defined in the base
194-
// class (Lease) so we have to point to this class rather
195-
// than derived class: Lease6.
196-
boost::multi_index::member<Lease, SubnetID, &Lease::subnet_id_>
197-
>
182+
// Specification of the eighth index starts here.
183+
boost::multi_index::hashed_non_unique<
184+
boost::multi_index::tag<HWAddressIndexTag>,
185+
// The hardware address is held in the hwaddr_ member of the
186+
// Lease6 object, which is a HWAddr object. Boost does not
187+
// provide a key extractor for getting a member of a member,
188+
// so we need a simple method for that.
189+
boost::multi_index::const_mem_fun<Lease, const std::vector<uint8_t>&,
190+
&Lease::getHWAddrVector>
198191
>
199192
>
200193
> Lease6Storage; // Specify the type name of this container.
@@ -364,9 +357,9 @@ typedef Lease6Storage::index<DuidIaidTypeIndexTag>::type Lease6StorageDuidIaidTy
364357
/// @brief DHCPv6 lease storage index by expiration time.
365358
typedef Lease6Storage::index<ExpirationIndexTag>::type Lease6StorageExpirationIndex;
366359

367-
/// @brief DHCPv6 lease storage index by HW address and subnet-id.
368-
typedef Lease6Storage::index<HWAddressSubnetIdIndexTag>::type
369-
Lease6StorageHWAddressSubnetIdIndex;
360+
/// @brief DHCPv6 lease storage index by HW address.
361+
typedef Lease6Storage::index<HWAddressIndexTag>::type
362+
Lease6StorageHWAddressIndex;
370363

371364
/// @brief DHCPv6 lease storage index by subnet-id.
372365
typedef Lease6Storage::index<SubnetIdIndexTag>::type Lease6StorageSubnetIdIndex;

src/lib/mysql/mysql_constants.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const int MLM_MYSQL_FETCH_FAILURE = 0;
5252

5353
/// @name Current database schema version values.
5454
//@{
55-
const uint32_t MYSQL_SCHEMA_VERSION_MAJOR = 31;
55+
const uint32_t MYSQL_SCHEMA_VERSION_MAJOR = 32;
5656
const uint32_t MYSQL_SCHEMA_VERSION_MINOR = 0;
5757

5858
//@}

src/lib/pgsql/pgsql_connection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace isc {
1818
namespace db {
1919

2020
/// @brief Define the PostgreSQL backend version.
21-
const uint32_t PGSQL_SCHEMA_VERSION_MAJOR = 30;
21+
const uint32_t PGSQL_SCHEMA_VERSION_MAJOR = 31;
2222
const uint32_t PGSQL_SCHEMA_VERSION_MINOR = 0;
2323

2424
// Maximum number of parameters that can be used a statement

0 commit comments

Comments
 (0)