From: Marcin Siodelski Date: Mon, 5 Nov 2012 08:43:20 +0000 (+0100) Subject: [2417] Append configured DHCPv6 options to server's response. X-Git-Tag: trac2487_base~18^2^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b966ebcc19a55c4d01825010ee1e707ba95293e8;p=thirdparty%2Fkea.git [2417] Append configured DHCPv6 options to server's response. --- diff --git a/src/bin/dhcp6/config_parser.cc b/src/bin/dhcp6/config_parser.cc index e5a2be3d12..de60697d3c 100644 --- a/src/bin/dhcp6/config_parser.cc +++ b/src/bin/dhcp6/config_parser.cc @@ -602,7 +602,7 @@ private: << " be equal to zero. Option code '0' is reserved in" << " DHCPv6."); } else if (option_code > std::numeric_limits::max()) { - isc_throw(Dhcp6ConfigError, "Parser error: value of 'code' must not"ciwtezcowy + isc_throw(Dhcp6ConfigError, "Parser error: value of 'code' must not" << " exceed " << std::numeric_limits::max()); } // Check the option name has been specified, is non-empty and does not diff --git a/src/bin/dhcp6/dhcp6_messages.mes b/src/bin/dhcp6/dhcp6_messages.mes index ffca69a986..071a3c7632 100644 --- a/src/bin/dhcp6/dhcp6_messages.mes +++ b/src/bin/dhcp6/dhcp6_messages.mes @@ -110,6 +110,10 @@ This is a debug message issued during the IPv6 DHCP server startup. It lists some information about the parameters with which the server is running. +% DHCP6_NO_SUBNET_FOR_ADDRESS fail to find subnet for address: %1 +This warning message indicates that server does not support subnet +that received DHCPv6 packet comes from. + % DHCP6_CONFIG_LOAD_FAIL failed to load configuration: %1 This critical error message indicates that the initial DHCPv6 configuration has failed. The server will start, but nothing will be diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc index 79b58238f6..6a3174bc63 100644 --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@ -24,11 +24,16 @@ #include #include #include +#include #include +#include +#include #include #include #include +#include + using namespace isc; using namespace isc::asiolink; using namespace isc::dhcp; @@ -289,23 +294,63 @@ void Dhcpv6Srv::copyDefaultOptions(const Pkt6Ptr& question, Pkt6Ptr& answer) { // TODO: Should throw if there is no client-id (except anonymous INF-REQUEST) } -void Dhcpv6Srv::appendDefaultOptions(const Pkt6Ptr& /*question*/, Pkt6Ptr& answer) { - // TODO: question is currently unused, but we need it at least to know - // message type we are answering - +void Dhcpv6Srv::appendDefaultOptions(const Pkt6Ptr& question, Pkt6Ptr& answer) { // add server-id answer->addOption(getServerID()); -} + // Get the subnet object. It holds options to be sent to the client + // that belongs to the particular subnet. + Subnet6Ptr subnet = CfgMgr::instance().getSubnet6(question->getRemoteAddr()); + // Warn if subnet is not supported and quit. + if (!subnet) { + LOG_WARN(dhcp6_logger, DHCP6_NO_SUBNET_FOR_ADDRESS) + .arg(question->getRemoteAddr().toText()); + return; + } + // Add DNS_SERVERS option. It should have been configured. + const Subnet::OptionContainer& options = subnet->getOptions(); + const Subnet::OptionContainerTypeIndex& idx = options.get<1>(); + const Subnet::OptionContainerTypeRange range = + idx.equal_range(D6O_NAME_SERVERS); + // In theory we may have multiple options with the same + // option code. They are not differentiated right now + // until support for option spaces is implemented. + // Until that's the case, simply add the first found option. + if (std::distance(range.first, range.second) > 0) { + answer->addOption(range.first->option); + } +} -void Dhcpv6Srv::appendRequestedOptions(const Pkt6Ptr& /*question*/, Pkt6Ptr& answer) { - // TODO: question is currently unused, but we need to extract ORO from it - // and act on its content. Now we just send DNS-SERVERS option. +void Dhcpv6Srv::appendRequestedOptions(const Pkt6Ptr& question, Pkt6Ptr& answer) { + // Get the subnet for a particular address. + Subnet6Ptr subnet = CfgMgr::instance().getSubnet6(question->getRemoteAddr()); + if (!subnet) { + LOG_WARN(dhcp6_logger, DHCP6_NO_SUBNET_FOR_ADDRESS) + .arg(question->getRemoteAddr().toText()); + return; + } - // add dns-servers option - boost::shared_ptr