From: Razvan Becheriu Date: Fri, 20 Jan 2023 12:35:28 +0000 (+0200) Subject: [#1518] reverted v4 changes which add persistent options if subnet is null X-Git-Tag: Kea-2.3.4~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=35cb6108a7bd4944cc1858a79bc7cf2913c04ef6;p=thirdparty%2Fkea.git [#1518] reverted v4 changes which add persistent options if subnet is null --- diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index 09c6d443da..0dac581215 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -1736,38 +1736,41 @@ Dhcpv4Srv::buildCfgOptionList(Dhcpv4Exchange& ex) { // Retrieve subnet. Subnet4Ptr subnet = ex.getContext()->subnet_; + if (!subnet) { + // All methods using the CfgOptionList object return soon when + // there is no subnet so do the same + return; + } + // Firstly, host specific options. const ConstHostPtr& host = ex.getContext()->currentHost(); if (host && !host->getCfgOption4()->empty()) { co_list.push_back(host->getCfgOption4()); } - // Secondly, pool specific options. Pools are defined within a subnet, so - // if there is no subnet, there is nothing to do. - if (subnet) { - 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()); - } + // 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()); - } + // Thirdly, subnet configured options. + if (!subnet->getCfgOption()->empty()) { + co_list.push_back(subnet->getCfgOption()); + } - // Fourthly, shared network specific options. - SharedNetwork4Ptr network; - subnet->getSharedNetwork(network); - if (network && !network->getCfgOption()->empty()) { - co_list.push_back(network->getCfgOption()); - } + // Fourthly, 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 @@ -1804,6 +1807,17 @@ Dhcpv4Srv::buildCfgOptionList(Dhcpv4Exchange& ex) { void Dhcpv4Srv::appendRequestedOptions(Dhcpv4Exchange& ex) { + // Get the subnet relevant for the client. We will need it + // to get the options associated with it. + Subnet4Ptr subnet = ex.getContext()->subnet_; + // If we can't find the subnet for the client there is no way + // to get the options to be sent to a client. We don't log an + // error because it will be logged by the assignLease method + // anyway. + if (!subnet) { + return; + } + // Unlikely short cut const CfgOptionList& co_list = ex.getCfgOptionList(); if (co_list.empty()) {