Commit c0554a39 authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[3035] Basic implementation of the function which computes DHCID.

parent ecd5a9bc
......@@ -56,6 +56,7 @@ nodist_b10_dhcp4_SOURCES = dhcp4_messages.h dhcp4_messages.cc
EXTRA_DIST += dhcp4_messages.mes
b10_dhcp4_LDADD = $(top_builddir)/src/lib/dhcp/libb10-dhcp++.la
b10_dhcp4_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libb10-dhcp_ddns.la
b10_dhcp4_LDADD += $(top_builddir)/src/lib/util/libb10-util.la
b10_dhcp4_LDADD += $(top_builddir)/src/lib/dhcpsrv/libb10-dhcpsrv.la
b10_dhcp4_LDADD += $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
......
......@@ -43,6 +43,7 @@
using namespace isc;
using namespace isc::asiolink;
using namespace isc::dhcp;
using namespace isc::dhcp_ddns;
using namespace isc::hooks;
using namespace isc::log;
using namespace std;
......@@ -568,6 +569,47 @@ Dhcpv4Srv::srvidToString(const OptionPtr& srvid) {
return (addrs[0].toText());
}
isc::dhcp_ddns::D2Dhcid
Dhcpv4Srv::computeDhcid(const Pkt4Ptr& query, const Pkt4Ptr& answer) {
std::vector<uint8_t> dhcid_data(1);
OptionPtr client_id = answer->getOption(DHO_DHCP_CLIENT_IDENTIFIER);
if (client_id) {
dhcid_data.push_back(1);
dhcid_data.insert(dhcid_data.end(), client_id->getData().begin(),
client_id->getData().end());
} else {
HWAddrPtr hwaddr = query->getHWAddr();
dhcid_data.push_back(0);
dhcid_data.push_back(hwaddr->htype_);
dhcid_data.insert(dhcid_data.end(), hwaddr->hwaddr_.begin(),
hwaddr->hwaddr_.end());
}
std::string domain_name;
Option4ClientFqdnPtr fqdn = boost::dynamic_pointer_cast<Option4ClientFqdn>
(answer->getOption(DHO_FQDN));
if (fqdn) {
domain_name = fqdn->getDomainName();
} else {
OptionCustomPtr hostname = boost::dynamic_pointer_cast<OptionCustom>
(answer->getOption(DHO_HOST_NAME));
if (hostname) {
domain_name = hostname->readString();
}
}
try {
OptionDataTypeUtil::writeFqdn(domain_name, dhcid_data, true);
} catch (const Exception& ex) {
;
}
D2Dhcid dhcid(dhcid_data);
return (dhcid);
}
void
Dhcpv4Srv::copyDefaultFields(const Pkt4Ptr& question, Pkt4Ptr& answer) {
answer->setIface(question->getIface());
......
......@@ -19,6 +19,7 @@
#include <dhcp/pkt4.h>
#include <dhcp/option.h>
#include <dhcp/option4_client_fqdn.h>
#include <dhcp_ddns/ncr_msg.h>
#include <dhcpsrv/subnet.h>
#include <dhcpsrv/alloc_engine.h>
#include <hooks/callout_handle.h>
......@@ -376,6 +377,16 @@ protected:
/// @return string representation
static std::string srvidToString(const OptionPtr& opt);
/// @brief Computes DHCID using options stored in the response message
/// to a client.
///
/// @param query An object encapsulating client's message to the server.
/// @param answer An object encapsulating response message being sent to
/// a client.
/// @return An object encapsulating DHCID to be used for DNS updates.
static isc::dhcp_ddns::D2Dhcid computeDhcid(const Pkt4Ptr& query,
const Pkt4Ptr& answer);
/// @brief Selects a subnet for a given client's packet.
///
/// @param question client's message
......
......@@ -82,6 +82,7 @@ dhcp4_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libb10-asiolink.la
dhcp4_unittests_LDADD += $(top_builddir)/src/lib/cc/libb10-cc.la
dhcp4_unittests_LDADD += $(top_builddir)/src/lib/config/libb10-cfgclient.la
dhcp4_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libb10-dhcp++.la
dhcp4_unittests_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libb10-dhcp_ddns.la
dhcp4_unittests_LDADD += $(top_builddir)/src/lib/dhcpsrv/libb10-dhcpsrv.la
dhcp4_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
dhcp4_unittests_LDADD += $(top_builddir)/src/lib/log/libb10-log.la
......
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