2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-30 05:27:55 +00:00

[#2596] Checkpoint for #2595 update

This commit is contained in:
Francis Dupont 2022-10-17 01:16:32 +02:00
parent 7676832dd7
commit 72fa5ea938
7 changed files with 42 additions and 36 deletions

View File

@ -1924,7 +1924,7 @@ AllocEngine::reuseExpiredLease(Lease6Ptr& expired, ClientContext6& ctx,
if (!ctx.fake_allocation_) {
// Add(update) the extended information on the lease.
static_cast<void>(updateLease6ExtendedInfo(expired, ctx));
updateLease6ExtendedInfo(expired, ctx);
// for REQUEST we do update the lease
LeaseMgrFactory::instance().updateLease6(expired);
@ -2085,7 +2085,7 @@ Lease6Ptr AllocEngine::createLease6(ClientContext6& ctx,
if (!ctx.fake_allocation_) {
// Add(update) the extended information on the lease.
static_cast<void>(updateLease6ExtendedInfo(lease, ctx));
updateLease6ExtendedInfo(lease, ctx);
// That is a real (REQUEST) allocation
bool status = LeaseMgrFactory::instance().addLease(lease);
@ -2401,7 +2401,8 @@ AllocEngine::extendLease6(ClientContext6& ctx, Lease6Ptr lease) {
}
// @todo should we call storeLease6ExtendedInfo() here ?
if (updateLease6ExtendedInfo(lease, ctx)) {
updateLease6ExtendedInfo(lease, ctx);
if (lease->extended_info_action_ == ExtendedInfoAction::ACTION_UPDATE) {
changed = true;
}
@ -3145,7 +3146,10 @@ void AllocEngine::reclaimLeaseInDatabase(const LeasePtrType& lease,
lease->fqdn_fwd_ = false;
lease->fqdn_rev_ = false;
lease->state_ = Lease::STATE_EXPIRED_RECLAIMED;
lease->setContext(ElementPtr());
if (lease->getContext()) {
lease->extended_info_action_ = ExtendedInfoAction::ACTION_DELETE;
lease->setContext(ElementPtr());
}
lease_update_fun(lease);
} else {
@ -4043,7 +4047,7 @@ AllocEngine::createLease4(const ClientContext4& ctx, const IOAddress& addr,
lease->hostname_ = ctx.hostname_;
// Add(update) the extended information on the lease.
static_cast<void>(updateLease4ExtendedInfo(lease, ctx));
updateLease4ExtendedInfo(lease, ctx);
// Let's execute all callouts registered for lease4_select
if (ctx.callout_handle_ &&
@ -4623,28 +4627,27 @@ AllocEngine::updateLease4Information(const Lease4Ptr& lease,
}
// Add(update) the extended information on the lease.
if (updateLease4ExtendedInfo(lease, ctx)) {
updateLease4ExtendedInfo(lease, ctx);
if (lease->extended_info_action_ == ExtendedInfoAction::ACTION_UPDATE) {
changed = true;
}
return (changed);
}
bool
void
AllocEngine::updateLease4ExtendedInfo(const Lease4Ptr& lease,
const AllocEngine::ClientContext4& ctx) const {
bool changed = false;
// If storage is not enabled then punt.
if (!ctx.subnet_->getStoreExtendedInfo()) {
return (changed);
return;
}
// Look for relay agent information option (option 82)
OptionPtr rai = ctx.query_->getOption(DHO_DHCP_AGENT_OPTIONS);
if (!rai) {
// Pkt4 doesn't have it, so nothing to store (or update).
return (changed);
return;
}
// Create a StringElement with the hex string for relay-agent-info.
@ -4693,30 +4696,26 @@ AllocEngine::updateLease4ExtendedInfo(const Lease4Ptr& lease,
// Add/replace the extended info entry.
ConstElementPtr old_extended_info = mutable_isc->get("relay-agent-info");
if (!old_extended_info || (*old_extended_info != *extended_info)) {
changed = true;
lease->extended_info_action_ = ExtendedInfoAction::ACTION_UPDATE;
mutable_isc->set("relay-agent-info", extended_info);
mutable_user_context->set("ISC", mutable_isc);
}
// Update the lease's user_context.
lease->setContext(mutable_user_context);
return (changed);
}
bool
AllocEngine::updateLease6ExtendedInfo(const Lease6Ptr& lease,
const AllocEngine::ClientContext6& ctx) const {
bool changed = false;
// If storage is not enabled then punt.
if (!ctx.subnet_->getStoreExtendedInfo()) {
return (changed);
return;
}
// If we do not have relay information, then punt.
if (ctx.query_->relay_info_.empty()) {
return (changed);
return;
}
// We need to convert the vector of RelayInfo instances in
@ -4802,15 +4801,13 @@ AllocEngine::updateLease6ExtendedInfo(const Lease6Ptr& lease,
// Add/replace the extended info entry.
ConstElementPtr old_extended_info = mutable_isc->get("relay-info");
if (!old_extended_info || (*old_extended_info != *extended_info)) {
changed = true;
lease->extended_info_action_ = ExtendedInfoAction::ACTION_UPDATE;
mutable_isc->set("relay-info", extended_info);
mutable_user_context->set("ISC", mutable_isc);
}
// Update the lease's user context.
lease->setContext(mutable_user_context);
return (changed);
}
void

View File

@ -1898,9 +1898,7 @@ protected:
/// @param [out] lease A pointer to the lease to be updated.
/// @param ctx A context containing information from the server about the
/// client and its message.
/// @return True if there was a significant (e.g. other than cltt) change,
/// false otherwise.
bool updateLease4ExtendedInfo(const Lease4Ptr& lease,
void updateLease4ExtendedInfo(const Lease4Ptr& lease,
const ClientContext4& ctx) const;
/// @brief Stores additional client query parameters on a V6 lease
@ -1918,9 +1916,7 @@ protected:
/// @param [out] lease A pointer to the lease to be updated.
/// @param ctx A context containing information from the server about the
/// client and its message.
/// @return True if there was a significant (e.g. other than cltt) change,
/// false otherwise.
bool updateLease6ExtendedInfo(const Lease6Ptr& lease,
void updateLease6ExtendedInfo(const Lease6Ptr& lease,
const ClientContext6& ctx) const;
private:

View File

@ -44,7 +44,8 @@ Lease::Lease(const isc::asiolink::IOAddress& addr,
reuseable_valid_lft_(0),
cltt_(cltt), current_cltt_(cltt), subnet_id_(subnet_id),
hostname_(boost::algorithm::to_lower_copy(hostname)), fqdn_fwd_(fqdn_fwd),
fqdn_rev_(fqdn_rev), hwaddr_(hwaddr), state_(STATE_DEFAULT) {
fqdn_rev_(fqdn_rev), hwaddr_(hwaddr), state_(STATE_DEFAULT),
extended_info_action_(ExtendedInfoAction::ACTION_IGNORE) {
}

View File

@ -184,6 +184,16 @@ struct Lease : public isc::data::UserContext, public isc::data::CfgToElement {
/// belonging to this class.
uint32_t state_;
/// @brief Action on extended info tables.
typedef enum {
ACTION_IGNORE, ///< ignore extended info,
ACTION_DELETE, ///< delete reference to the lease
ACTION_UPDATE ///< update extended info tables.
} ExtendedInfoAction;
/// @brief Record the action on extended info tables in the lease.
ExtendedInfoAction extended_info_action_;
/// @brief Convert Lease to Printable Form
///
/// @return String form of the lease

View File

@ -3851,8 +3851,10 @@ TEST_F(AllocEngine4Test, updateExtendedInfo4) {
}
// Call AllocEngine::updateLease4ExtendeInfo().
bool ret = false;
ASSERT_NO_THROW_LOG(ret = engine.callUpdateLease4ExtendedInfo(lease, ctx));
ASSERT_NO_THROW_LOG(engine.callUpdateLease4ExtendedInfo(lease, ctx));
bool ret = (lease->extended_info_action_ == ExtendedInfoAction::ACTION_UPDATE);
// Reset the lease action.
lease->extended_info_action_ = ExtendedInfoAction::ACTION_IGNORE;
ASSERT_EQ(scenario.exp_ret, ret);
// Verify the lease has the expected user context content.

View File

@ -4299,8 +4299,10 @@ TEST_F(AllocEngine6ExtendedInfoTest, updateExtendedInfo6) {
ctx.query_->relay_info_ = scenario.relays_;
// Call AllocEngine::updateLease6ExtendeInfo().
bool ret;
ASSERT_NO_THROW_LOG(ret = engine_.callUpdateLease6ExtendedInfo(lease, ctx));
ASSERT_NO_THROW_LOG(engine_.callUpdateLease6ExtendedInfo(lease, ctx));
bool ret = (lease->extended_info_action_ == ExtendedInfoAction::ACTION_UPDATE);
// Reset the lease action.
lease->extended_info_action_ = ExtendedInfoAction::ACTION_IGNORE;
ASSERT_EQ(scenario.exp_ret, ret);
// Verify the lease has the expected user context content.

View File

@ -93,8 +93,7 @@ public:
/// @brief Wrapper method for invoking AllocEngine4::updateLease4ExtendedInfo().
/// @param lease lease to update
/// @param ctx current packet processing context
/// @return true if extended information was changed
bool callUpdateLease4ExtendedInfo(const Lease4Ptr& lease,
void callUpdateLease4ExtendedInfo(const Lease4Ptr& lease,
AllocEngine::ClientContext4& ctx) const {
return (updateLease4ExtendedInfo(lease, ctx));
}
@ -102,8 +101,7 @@ public:
/// @brief Wrapper method for invoking AllocEngine6::updateLease6ExtendedInfo().
/// @param lease lease to update
/// @param ctx current packet processing context
/// @return true if extended information was changed
bool callUpdateLease6ExtendedInfo(const Lease6Ptr& lease,
void callUpdateLease6ExtendedInfo(const Lease6Ptr& lease,
AllocEngine::ClientContext6& ctx) const {
return (updateLease6ExtendedInfo(lease, ctx));
}