From: Tomek Mrugalski Date: Wed, 31 Oct 2018 13:24:05 +0000 (+0100) Subject: [#39,!108] Options order changed: X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=811f1308e96685e24693480cabfbf34b9f118954;p=thirdparty%2Fkea.git [#39,!108] Options order changed: - it is now: host, class, pool, subnet, network, global --- diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index f8fca028f8..e0c286b826 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -1316,38 +1316,13 @@ Dhcpv4Srv::buildCfgOptionList(Dhcpv4Exchange& ex) { return; } - // Firstly, host specific options. + // First: host specific options. const ConstHostPtr& host = ex.getContext()->currentHost(); if (host && !host->getCfgOption4()->empty()) { co_list.push_back(host->getCfgOption4()); } - // Secondly, pool specific options. - Pkt4Ptr resp = ex.getResponse(); - IOAddress addr = IOAddress::IPV4_ZERO_ADDRESS(); - if (resp) { - addr = resp->getYiaddr(); - } - if (!addr.isV4Zero()) { - PoolPtr pool = subnet->getPool(Lease::TYPE_V4, addr, false); - if (pool && !pool->getCfgOption()->empty()) { - co_list.push_back(pool->getCfgOption()); - } - } - - // Thirdly, subnet configured options. - if (!subnet->getCfgOption()->empty()) { - co_list.push_back(subnet->getCfgOption()); - } - - // Forthly, shared network specific options. - SharedNetwork4Ptr network; - subnet->getSharedNetwork(network); - if (network && !network->getCfgOption()->empty()) { - co_list.push_back(network->getCfgOption()); - } - - // Each class in the incoming packet + // Second: each class the incoming packet belongs to. const ClientClasses& classes = ex.getQuery()->getClasses(); for (ClientClasses::const_iterator cclass = classes.cbegin(); cclass != classes.cend(); ++cclass) { @@ -1371,7 +1346,32 @@ Dhcpv4Srv::buildCfgOptionList(Dhcpv4Exchange& ex) { co_list.push_back(ccdef->getCfgOption()); } - // Last global options + // Third: pool specific options. + Pkt4Ptr resp = ex.getResponse(); + IOAddress addr = IOAddress::IPV4_ZERO_ADDRESS(); + if (resp) { + addr = resp->getYiaddr(); + } + if (!addr.isV4Zero()) { + PoolPtr pool = subnet->getPool(Lease::TYPE_V4, addr, false); + if (pool && !pool->getCfgOption()->empty()) { + co_list.push_back(pool->getCfgOption()); + } + } + + // Fourth: subnet configured options. + if (!subnet->getCfgOption()->empty()) { + co_list.push_back(subnet->getCfgOption()); + } + + // Fifth: shared network specific options. + SharedNetwork4Ptr network; + subnet->getSharedNetwork(network); + if (network && !network->getCfgOption()->empty()) { + co_list.push_back(network->getCfgOption()); + } + + // Sixth: global options come last. if (!CfgMgr::instance().getCurrentCfg()->getCfgOption()->empty()) { co_list.push_back(CfgMgr::instance().getCurrentCfg()->getCfgOption()); } diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc index c0adebbba3..cbefd2e885 100644 --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@ -1051,40 +1051,12 @@ void Dhcpv6Srv::buildCfgOptionList(const Pkt6Ptr& question, AllocEngine::ClientContext6& ctx, CfgOptionList& co_list) { - // Firstly, host specific options. + // First: host specific options. if (ctx.currentHost() && !ctx.currentHost()->getCfgOption6()->empty()) { co_list.push_back(ctx.currentHost()->getCfgOption6()); } - // Secondly, pool specific options. Pools are defined within a subnet, so - // if there is no subnet, there is nothing to do. - if (ctx.subnet_) { - BOOST_FOREACH(const AllocEngine::ResourceType& resource, - ctx.allocated_resources_) { - PoolPtr pool = ctx.subnet_->getPool(resource.second == 128 ? - Lease::TYPE_NA : Lease::TYPE_PD, - resource.first, false); - if (pool && !pool->getCfgOption()->empty()) { - co_list.push_back(pool->getCfgOption()); - } - } - }; - - if (ctx.subnet_) { - // Next, subnet configured options. - if (!ctx.subnet_->getCfgOption()->empty()) { - co_list.push_back(ctx.subnet_->getCfgOption()); - } - - // Then, shared network specific options. - SharedNetwork6Ptr network; - ctx.subnet_->getSharedNetwork(network); - if (network && !network->getCfgOption()->empty()) { - co_list.push_back(network->getCfgOption()); - } - } - - // Each class in the incoming packet + // Second: each class the incoming packet belongs to. const ClientClasses& classes = question->getClasses(); for (ClientClasses::const_iterator cclass = classes.cbegin(); cclass != classes.cend(); ++cclass) { @@ -1110,7 +1082,35 @@ Dhcpv6Srv::buildCfgOptionList(const Pkt6Ptr& question, co_list.push_back(ccdef->getCfgOption()); } - // Last global options + // Third: pool specific options. Pools are defined within a subnet, so + // if there is no subnet, there is nothing to do. + if (ctx.subnet_) { + BOOST_FOREACH(const AllocEngine::ResourceType& resource, + ctx.allocated_resources_) { + PoolPtr pool = ctx.subnet_->getPool(resource.second == 128 ? + Lease::TYPE_NA : Lease::TYPE_PD, + resource.first, false); + if (pool && !pool->getCfgOption()->empty()) { + co_list.push_back(pool->getCfgOption()); + } + } + }; + + if (ctx.subnet_) { + // Fourth: subnet configured options. + if (!ctx.subnet_->getCfgOption()->empty()) { + co_list.push_back(ctx.subnet_->getCfgOption()); + } + + // Fifth: shared network specific options. + SharedNetwork6Ptr network; + ctx.subnet_->getSharedNetwork(network); + if (network && !network->getCfgOption()->empty()) { + co_list.push_back(network->getCfgOption()); + } + } + + // Sixth: global options if (!CfgMgr::instance().getCurrentCfg()->getCfgOption()->empty()) { co_list.push_back(CfgMgr::instance().getCurrentCfg()->getCfgOption()); }