mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-30 05:27:55 +00:00
[4097a] Optimized the no configured options cases
This commit is contained in:
parent
fd12a6d69f
commit
f397db49d4
@ -827,7 +827,7 @@ Dhcpv4Srv::buildCfgOptionList(Dhcpv4Exchange& ex) {
|
|||||||
|
|
||||||
// First subnet configured options
|
// First subnet configured options
|
||||||
Subnet4Ptr subnet = ex.getContext()->subnet_;
|
Subnet4Ptr subnet = ex.getContext()->subnet_;
|
||||||
if (subnet) {
|
if (subnet && !subnet->getCfgOption()->empty()) {
|
||||||
co_list.push_back(subnet->getCfgOption());
|
co_list.push_back(subnet->getCfgOption());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -845,11 +845,17 @@ Dhcpv4Srv::buildCfgOptionList(Dhcpv4Exchange& ex) {
|
|||||||
.arg(*cclass);
|
.arg(*cclass);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (ccdef->getCfgOption()->empty()) {
|
||||||
|
// Skip classes which don't configure options
|
||||||
|
continue;
|
||||||
|
}
|
||||||
co_list.push_back(ccdef->getCfgOption());
|
co_list.push_back(ccdef->getCfgOption());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Last global options
|
// Last global options
|
||||||
co_list.push_back(CfgMgr::instance().getCurrentCfg()->getCfgOption());
|
if (!CfgMgr::instance().getCurrentCfg()->getCfgOption()->empty()) {
|
||||||
|
co_list.push_back(CfgMgr::instance().getCurrentCfg()->getCfgOption());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -865,6 +871,12 @@ Dhcpv4Srv::appendRequestedOptions(Dhcpv4Exchange& ex) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unlikely short cut
|
||||||
|
const CfgOptionList& co_list = ex.getCfgOptionList();
|
||||||
|
if (co_list.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Pkt4Ptr query = ex.getQuery();
|
Pkt4Ptr query = ex.getQuery();
|
||||||
|
|
||||||
// try to get the 'Parameter Request List' option which holds the
|
// try to get the 'Parameter Request List' option which holds the
|
||||||
@ -888,7 +900,6 @@ Dhcpv4Srv::appendRequestedOptions(Dhcpv4Exchange& ex) {
|
|||||||
// Add nothing when it is already there
|
// Add nothing when it is already there
|
||||||
if (!resp->getOption(*opt)) {
|
if (!resp->getOption(*opt)) {
|
||||||
// Iterate on the configured option list
|
// Iterate on the configured option list
|
||||||
const CfgOptionList& co_list = ex.getCfgOptionList();
|
|
||||||
for (CfgOptionList::const_iterator copts = co_list.begin();
|
for (CfgOptionList::const_iterator copts = co_list.begin();
|
||||||
copts != co_list.end(); ++copts) {
|
copts != co_list.end(); ++copts) {
|
||||||
OptionDescriptor desc = (*copts)->get("dhcp4", *opt);
|
OptionDescriptor desc = (*copts)->get("dhcp4", *opt);
|
||||||
@ -915,6 +926,12 @@ Dhcpv4Srv::appendRequestedVendorOptions(Dhcpv4Exchange& ex) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unlikely short cut
|
||||||
|
const CfgOptionList& co_list = ex.getCfgOptionList();
|
||||||
|
if (co_list.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Try to get the vendor option
|
// Try to get the vendor option
|
||||||
boost::shared_ptr<OptionVendor> vendor_req = boost::dynamic_pointer_cast<
|
boost::shared_ptr<OptionVendor> vendor_req = boost::dynamic_pointer_cast<
|
||||||
OptionVendor>(ex.getQuery()->getOption(DHO_VIVSO_SUBOPTIONS));
|
OptionVendor>(ex.getQuery()->getOption(DHO_VIVSO_SUBOPTIONS));
|
||||||
@ -944,7 +961,6 @@ Dhcpv4Srv::appendRequestedVendorOptions(Dhcpv4Exchange& ex) {
|
|||||||
for (std::vector<uint8_t>::const_iterator code = requested_opts.begin();
|
for (std::vector<uint8_t>::const_iterator code = requested_opts.begin();
|
||||||
code != requested_opts.end(); ++code) {
|
code != requested_opts.end(); ++code) {
|
||||||
if (!vendor_rsp->getOption(*code)) {
|
if (!vendor_rsp->getOption(*code)) {
|
||||||
const CfgOptionList& co_list = ex.getCfgOptionList();
|
|
||||||
for (CfgOptionList::const_iterator copts = co_list.begin();
|
for (CfgOptionList::const_iterator copts = co_list.begin();
|
||||||
copts != co_list.end(); ++copts) {
|
copts != co_list.end(); ++copts) {
|
||||||
OptionDescriptor desc = (*copts)->get(vendor_id, *code);
|
OptionDescriptor desc = (*copts)->get(vendor_id, *code);
|
||||||
@ -981,6 +997,12 @@ Dhcpv4Srv::appendBasicOptions(Dhcpv4Exchange& ex) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unlikely short cut
|
||||||
|
const CfgOptionList& co_list = ex.getCfgOptionList();
|
||||||
|
if (co_list.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Pkt4Ptr resp = ex.getResponse();
|
Pkt4Ptr resp = ex.getResponse();
|
||||||
|
|
||||||
// Try to find all 'required' options in the outgoing
|
// Try to find all 'required' options in the outgoing
|
||||||
@ -989,7 +1011,6 @@ Dhcpv4Srv::appendBasicOptions(Dhcpv4Exchange& ex) {
|
|||||||
OptionPtr opt = resp->getOption(required_options[i]);
|
OptionPtr opt = resp->getOption(required_options[i]);
|
||||||
if (!opt) {
|
if (!opt) {
|
||||||
// Check whether option has been configured.
|
// Check whether option has been configured.
|
||||||
const CfgOptionList& co_list = ex.getCfgOptionList();
|
|
||||||
for (CfgOptionList::const_iterator copts = co_list.begin();
|
for (CfgOptionList::const_iterator copts = co_list.begin();
|
||||||
copts != co_list.end(); ++copts) {
|
copts != co_list.end(); ++copts) {
|
||||||
OptionDescriptor desc = (*copts)->get("dhcp4", required_options[i]);
|
OptionDescriptor desc = (*copts)->get("dhcp4", required_options[i]);
|
||||||
|
@ -895,7 +895,7 @@ Dhcpv6Srv::buildCfgOptionList(const Pkt6Ptr& question,
|
|||||||
AllocEngine::ClientContext6& ctx,
|
AllocEngine::ClientContext6& ctx,
|
||||||
CfgOptionList& co_list) {
|
CfgOptionList& co_list) {
|
||||||
// First subnet configured options
|
// First subnet configured options
|
||||||
if (ctx.subnet_) {
|
if (ctx.subnet_ && !ctx.subnet_->getCfgOption()->empty()) {
|
||||||
co_list.push_back(ctx.subnet_->getCfgOption());
|
co_list.push_back(ctx.subnet_->getCfgOption());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -912,11 +912,17 @@ Dhcpv6Srv::buildCfgOptionList(const Pkt6Ptr& question,
|
|||||||
.arg(*cclass);
|
.arg(*cclass);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (ccdef->getCfgOption()->empty()) {
|
||||||
|
// Skip classes which don't configure options
|
||||||
|
continue;
|
||||||
|
}
|
||||||
co_list.push_back(ccdef->getCfgOption());
|
co_list.push_back(ccdef->getCfgOption());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Last global options
|
// Last global options
|
||||||
co_list.push_back(CfgMgr::instance().getCurrentCfg()->getCfgOption());
|
if (!CfgMgr::instance().getCurrentCfg()->getCfgOption()->empty()) {
|
||||||
|
co_list.push_back(CfgMgr::instance().getCurrentCfg()->getCfgOption());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -930,7 +936,7 @@ Dhcpv6Srv::appendRequestedOptions(const Pkt6Ptr& question, Pkt6Ptr& answer,
|
|||||||
(question->getOption(D6O_ORO));
|
(question->getOption(D6O_ORO));
|
||||||
|
|
||||||
// Option ORO not found? We're done here then.
|
// Option ORO not found? We're done here then.
|
||||||
if (!option_oro) {
|
if (!option_oro || co_list.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -968,7 +974,7 @@ Dhcpv6Srv::appendRequestedVendorOptions(const Pkt6Ptr& question,
|
|||||||
// Try to get the vendor option
|
// Try to get the vendor option
|
||||||
boost::shared_ptr<OptionVendor> vendor_req =
|
boost::shared_ptr<OptionVendor> vendor_req =
|
||||||
boost::dynamic_pointer_cast<OptionVendor>(question->getOption(D6O_VENDOR_OPTS));
|
boost::dynamic_pointer_cast<OptionVendor>(question->getOption(D6O_VENDOR_OPTS));
|
||||||
if (!vendor_req) {
|
if (!vendor_req || co_list.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,11 @@ OptionDescriptor::equals(const OptionDescriptor& other) const {
|
|||||||
CfgOption::CfgOption() {
|
CfgOption::CfgOption() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
CfgOption::empty() const {
|
||||||
|
return (options_.empty() && vendor_options_.empty());
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CfgOption::equals(const CfgOption& other) const {
|
CfgOption::equals(const CfgOption& other) const {
|
||||||
return (options_.equals(other.options_) &&
|
return (options_.equals(other.options_) &&
|
||||||
|
@ -202,6 +202,11 @@ public:
|
|||||||
/// @brief default constructor
|
/// @brief default constructor
|
||||||
CfgOption();
|
CfgOption();
|
||||||
|
|
||||||
|
/// @brief Indicates the object is empty
|
||||||
|
///
|
||||||
|
/// @return true when the object is empty
|
||||||
|
bool empty() const;
|
||||||
|
|
||||||
/// @name Methods and operators used for comparing objects.
|
/// @name Methods and operators used for comparing objects.
|
||||||
///
|
///
|
||||||
//@{
|
//@{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright (C) 2013-2014 Internet Systems Consortium, Inc. ("ISC")
|
// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
|
||||||
//
|
//
|
||||||
// Permission to use, copy, modify, and/or distribute this software for any
|
// Permission to use, copy, modify, and/or distribute this software for any
|
||||||
// purpose with or without fee is hereby granted, provided that the above
|
// purpose with or without fee is hereby granted, provided that the above
|
||||||
@ -39,6 +39,13 @@ public:
|
|||||||
/// Pointer to the container.
|
/// Pointer to the container.
|
||||||
typedef boost::shared_ptr<ContainerType> ItemsContainerPtr;
|
typedef boost::shared_ptr<ContainerType> ItemsContainerPtr;
|
||||||
|
|
||||||
|
/// @brief Indicates the container is empty
|
||||||
|
///
|
||||||
|
/// @return true when the confainer is empty
|
||||||
|
bool empty() const {
|
||||||
|
return (option_space_map_.empty());
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief Adds a new item to the option_space.
|
/// @brief Adds a new item to the option_space.
|
||||||
///
|
///
|
||||||
/// @param item reference to the item being added.
|
/// @param item reference to the item being added.
|
||||||
|
@ -28,6 +28,27 @@ using namespace isc::dhcp;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
// This test verifies the empty predicate.
|
||||||
|
TEST(CfgOptionTest, empty) {
|
||||||
|
CfgOption cfg1;
|
||||||
|
CfgOption cfg2;
|
||||||
|
|
||||||
|
// Initially the option configurations should be empty.
|
||||||
|
ASSERT_TRUE(cfg1.empty());
|
||||||
|
ASSERT_TRUE(cfg2.empty());
|
||||||
|
|
||||||
|
// Add an option to each configuration
|
||||||
|
OptionPtr option(new Option(Option::V6, 1));
|
||||||
|
ASSERT_NO_THROW(cfg1.add(option, false, "dhcp6"));
|
||||||
|
ASSERT_NO_THROW(cfg2.add(option, true, "isc"));
|
||||||
|
|
||||||
|
// The first option configuration has an option
|
||||||
|
ASSERT_FALSE(cfg1.empty());
|
||||||
|
|
||||||
|
// The second option configuration has a vendor option
|
||||||
|
ASSERT_FALSE(cfg2.empty());
|
||||||
|
}
|
||||||
|
|
||||||
// This test verifies that the option configurations can be compared.
|
// This test verifies that the option configurations can be compared.
|
||||||
TEST(CfgOptionTest, equals) {
|
TEST(CfgOptionTest, equals) {
|
||||||
CfgOption cfg1;
|
CfgOption cfg1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user