Commit 89d8d0bc authored by Francis Dupont's avatar Francis Dupont
Browse files

[5458a] Checkpoint: code and main tests done, todo prefix and all v6 corner cases

parent afa4ef5d
......@@ -805,8 +805,27 @@ Dhcpv6Srv::processPacket(Pkt6Ptr& query, Pkt6Ptr& rsp) {
}
callout_handle->setArgument("leases6", new_leases);
// Two points: check only address? avoid duplicates in deleted_leases?
Lease6CollectionPtr deleted_leases(new Lease6Collection());
// Do global list first
for (auto old_lease : ctx.deleted_leases_) {
if (ctx.new_leases_.empty()) {
deleted_leases->push_back(old_lease);
continue;
}
bool in_new = false;
for (auto const new_lease : ctx.new_leases_) {
if ((new_lease->addr_ == old_lease->addr_) &&
(new_lease->prefixlen_ == old_lease->prefixlen_)) {
in_new = true;
break;
}
}
if (in_new) {
continue;
}
deleted_leases->push_back(old_lease);
}
// Do per IA lists
for (auto const iac : ctx.ias_) {
if (!iac.old_leases_.empty()) {
for (auto old_lease : iac.old_leases_) {
......@@ -2328,10 +2347,12 @@ Dhcpv6Srv::releaseLeases(const Pkt6Ptr& release, Pkt6Ptr& reply,
int general_status = STATUS_Success;
for (OptionCollection::iterator opt = release->options_.begin();
opt != release->options_.end(); ++opt) {
Lease6Ptr old_lease;
switch (opt->second->getType()) {
case D6O_IA_NA: {
OptionPtr answer_opt = releaseIA_NA(ctx.duid_, release, general_status,
boost::dynamic_pointer_cast<Option6IA>(opt->second));
boost::dynamic_pointer_cast<Option6IA>(opt->second),
old_lease);
if (answer_opt) {
reply->addOption(answer_opt);
}
......@@ -2339,7 +2360,8 @@ Dhcpv6Srv::releaseLeases(const Pkt6Ptr& release, Pkt6Ptr& reply,
}
case D6O_IA_PD: {
OptionPtr answer_opt = releaseIA_PD(ctx.duid_, release, general_status,
boost::dynamic_pointer_cast<Option6IA>(opt->second));
boost::dynamic_pointer_cast<Option6IA>(opt->second),
old_lease);
if (answer_opt) {
reply->addOption(answer_opt);
}
......@@ -2350,6 +2372,11 @@ Dhcpv6Srv::releaseLeases(const Pkt6Ptr& release, Pkt6Ptr& reply,
// remaining options are stateless and thus ignored in this context
;
}
// Store the old lease.
if (old_lease) {
ctx.deleted_leases_.push_back(old_lease);
}
}
// To be pedantic, we should also include status code in the top-level
......@@ -2361,7 +2388,8 @@ Dhcpv6Srv::releaseLeases(const Pkt6Ptr& release, Pkt6Ptr& reply,
OptionPtr
Dhcpv6Srv::releaseIA_NA(const DuidPtr& duid, const Pkt6Ptr& query,
int& general_status, boost::shared_ptr<Option6IA> ia) {
int& general_status, boost::shared_ptr<Option6IA> ia,
Lease6Ptr& old_lease) {
LOG_DEBUG(lease6_logger, DBG_DHCP6_DETAIL, DHCP6_PROCESS_IA_NA_RELEASE)
.arg(query->getLabel())
......@@ -2501,6 +2529,8 @@ Dhcpv6Srv::releaseIA_NA(const DuidPtr& duid, const Pkt6Ptr& query,
return (ia_rsp);
} else {
old_lease = lease;
LOG_INFO(lease6_logger, DHCP6_RELEASE_NA)
.arg(query->getLabel())
.arg(lease->addr_.toText())
......@@ -2525,7 +2555,8 @@ Dhcpv6Srv::releaseIA_NA(const DuidPtr& duid, const Pkt6Ptr& query,
OptionPtr
Dhcpv6Srv::releaseIA_PD(const DuidPtr& duid, const Pkt6Ptr& query,
int& general_status, boost::shared_ptr<Option6IA> ia) {
int& general_status, boost::shared_ptr<Option6IA> ia,
Lease6Ptr& old_lease) {
// Release can be done in one of two ways:
// Approach 1: extract address from client's IA_NA and see if it belongs
// to this particular client.
......@@ -2659,6 +2690,8 @@ Dhcpv6Srv::releaseIA_PD(const DuidPtr& duid, const Pkt6Ptr& query,
general_status = STATUS_UnspecFail;
} else {
old_lease = lease;
LOG_INFO(lease6_logger, DHCP6_RELEASE_PD)
.arg(query->getLabel())
.arg(lease->addr_.toText())
......@@ -2975,7 +3008,8 @@ Dhcpv6Srv::declineLeases(const Pkt6Ptr& decline, Pkt6Ptr& reply,
switch (opt->second->getType()) {
case D6O_IA_NA: {
OptionPtr answer_opt = declineIA(decline, ctx.duid_, general_status,
boost::dynamic_pointer_cast<Option6IA>(opt->second));
boost::dynamic_pointer_cast<Option6IA>(opt->second),
ctx.deleted_leases_);
if (answer_opt) {
// We have an answer, let's use it.
......@@ -3000,7 +3034,8 @@ Dhcpv6Srv::declineLeases(const Pkt6Ptr& decline, Pkt6Ptr& reply,
OptionPtr
Dhcpv6Srv::declineIA(const Pkt6Ptr& decline, const DuidPtr& duid,
int& general_status, boost::shared_ptr<Option6IA> ia) {
int& general_status, boost::shared_ptr<Option6IA> ia,
Lease6Collection& old_leases) {
LOG_DEBUG(lease6_logger, DBG_DHCP6_DETAIL, DHCP6_DECLINE_PROCESS_IA)
.arg(decline->getLabel())
......@@ -3106,6 +3141,8 @@ Dhcpv6Srv::declineIA(const Pkt6Ptr& decline, const DuidPtr& duid,
// declineLease returns false only when hook callouts set the next
// step status to drop. We just propagate the bad news here.
return (OptionPtr());
} else {
old_leases.push_back(lease);
}
}
......
......@@ -457,10 +457,12 @@ protected:
/// @param query client's message
/// @param general_status a global status (it may be updated in case of errors)
/// @param ia IA_NA option that is being released
/// @param old_lease a pointer to the lease being released
/// @return IA_NA option (server's response)
OptionPtr releaseIA_NA(const DuidPtr& duid, const Pkt6Ptr& query,
int& general_status,
boost::shared_ptr<Option6IA> ia);
boost::shared_ptr<Option6IA> ia,
Lease6Ptr& old_lease);
/// @brief Releases specific IA_PD option
///
......@@ -473,10 +475,12 @@ protected:
/// @param query client's message
/// @param general_status a global status (it may be updated in case of errors)
/// @param ia IA_PD option that is being released
/// @param old_lease a pointer to the lease being released
/// @return IA_PD option (server's response)
OptionPtr releaseIA_PD(const DuidPtr& duid, const Pkt6Ptr& query,
int& general_status,
boost::shared_ptr<Option6IA> ia);
boost::shared_ptr<Option6IA> ia,
Lease6Ptr& old_lease);
/// @brief Copies required options from client message to server answer.
///
......@@ -771,10 +775,11 @@ protected:
/// @param duid client's duid (used to verify if the client owns the lease)
/// @param general_status [out] status in top-level message (may be updated)
/// @param ia specific IA_NA option to process.
/// @param old_leases a collection of leases being declined.
/// @return IA_NA option with response (to be included in Reply message)
OptionPtr
declineIA(const Pkt6Ptr& decline, const DuidPtr& duid, int& general_status,
boost::shared_ptr<Option6IA> ia);
boost::shared_ptr<Option6IA> ia, Lease6Collection& old_leases);
/// @brief Declines specific IPv6 lease.
///
......
This diff is collapsed.
......@@ -445,7 +445,7 @@ AllocEngine::ClientContext6::ClientContext6(const Subnet6Ptr& subnet,
duid_(duid), hwaddr_(), host_identifiers_(), hosts_(),
fwd_dns_update_(fwd_dns), rev_dns_update_(rev_dns), committed_(false),
hostname_(hostname), callout_handle_(callout_handle),
allocated_resources_(), new_leases_(), ias_() {
allocated_resources_(), new_leases_(), deleted_leases_(), ias_() {
// Initialize host identifiers.
if (duid) {
......
......@@ -384,6 +384,9 @@ public:
/// @brief A collection of newly allocated leases.
Lease6Collection new_leases_;
/// @brief A collection of old leases that the client had before.
Lease6Collection deleted_leases_;
//@}
/// @brief Parameters pertaining to individual IAs.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment