Commit 847cada3 authored by Marcin Siodelski's avatar Marcin Siodelski

[3035] Implemented DHCPv4 Client FQDN option processing.

parent 41c4d829
......@@ -18,7 +18,6 @@
#include <dhcp/hwaddr.h>
#include <dhcp/iface_mgr.h>
#include <dhcp/option4_addrlst.h>
#include <dhcp/option4_client_fqdn.h>
#include <dhcp/option_custom.h>
#include <dhcp/option_int.h>
#include <dhcp/option_int_array.h>
......@@ -672,7 +671,7 @@ Dhcpv4Srv::processClientName(const Pkt4Ptr& query, Pkt4Ptr& answer) {
Option4ClientFqdnPtr fqdn = boost::dynamic_pointer_cast<Option4ClientFqdn>
(query->getOption(DHO_FQDN));
if (fqdn) {
processClientFqdnOption(query, answer);
processClientFqdnOption(fqdn, answer);
} else {
OptionCustomPtr hostname = boost::dynamic_pointer_cast<OptionCustom>
......@@ -685,7 +684,18 @@ Dhcpv4Srv::processClientName(const Pkt4Ptr& query, Pkt4Ptr& answer) {
}
void
Dhcpv4Srv::processClientFqdnOption(const Pkt4Ptr&, Pkt4Ptr&) {
Dhcpv4Srv::processClientFqdnOption(const Option4ClientFqdnPtr& fqdn,
Pkt4Ptr& answer) {
// Create the DHCPv4 Client FQDN Option to be included in the server's
// response to a client.
Option4ClientFqdnPtr fqdn_resp(new Option4ClientFqdn(*fqdn));
// RFC4702, section 4 - set 'NOS' flags to 0.
fqdn_resp->setFlag(Option4ClientFqdn::FLAG_S, 0);
fqdn_resp->setFlag(Option4ClientFqdn::FLAG_O, 0);
fqdn_resp->setFlag(Option4ClientFqdn::FLAG_N, 0);
answer->addOption(fqdn_resp);
}
void
......
......@@ -18,6 +18,7 @@
#include <dhcp/dhcp4.h>
#include <dhcp/pkt4.h>
#include <dhcp/option.h>
#include <dhcp/option4_client_fqdn.h>
#include <dhcpsrv/subnet.h>
#include <dhcpsrv/alloc_engine.h>
#include <hooks/callout_handle.h>
......@@ -289,9 +290,10 @@ protected:
private:
/// @brief Process Client FQDN %Option sent by a client.
///
/// @param query A DISCOVER or REQUEST message from a cient.
/// @param fqdn An DHCPv4 Client FQDN %Option sent by a client.
/// @param [out] answer A response message to be sent to a client.
void processClientFqdnOption(const Pkt4Ptr& query, Pkt4Ptr& answer);
void processClientFqdnOption(const Option4ClientFqdnPtr& fqdn,
Pkt4Ptr& answer);
/// @brief Process Hostname %Option sent by a client.
///
......
......@@ -126,7 +126,9 @@ private:
};
TEST_F(FqdnDhcpv4SrvTest, basic) {
// Test that server confirms to perform the forward and reverse DNS update,
// when client asks for it.
TEST_F(FqdnDhcpv4SrvTest, serverUpdateForward) {
Pkt4Ptr query = generatePktWithFqdn(DHCPREQUEST,
Option4ClientFqdn::FLAG_E |
Option4ClientFqdn::FLAG_S,
......@@ -140,4 +142,53 @@ TEST_F(FqdnDhcpv4SrvTest, basic) {
}
// Test that server generates the fully qualified domain name for the client
// if client supplies the partial name.
TEST_F(FqdnDhcpv4SrvTest, serverUpdateForwardPartialName) {
Pkt4Ptr query = generatePktWithFqdn(DHCPREQUEST,
Option4ClientFqdn::FLAG_E |
Option4ClientFqdn::FLAG_S,
"myhost",
Option4ClientFqdn::PARTIAL,
true);
testProcessFqdn(query,
Option4ClientFqdn::FLAG_E | Option4ClientFqdn::FLAG_S,
"myhost.example.com.");
}
// Test that server generates the fully qualified domain name for the client
// if clietn supplies empty domain name.
TEST_F(FqdnDhcpv4SrvTest, serverUpdateForwardNoName) {
Pkt4Ptr query = generatePktWithFqdn(DHCPREQUEST,
Option4ClientFqdn::FLAG_E |
Option4ClientFqdn::FLAG_S,
"",
Option4ClientFqdn::PARTIAL,
true);
testProcessFqdn(query,
Option4ClientFqdn::FLAG_E | Option4ClientFqdn::FLAG_S,
"myhost.example.com.");
}
// Test that server does not accept delegation of the forward DNS update
// to a client.
TEST_F(FqdnDhcpv4SrvTest, clientUpdateNotAllowed) {
Pkt4Ptr query = generatePktWithFqdn(DHCPREQUEST,
Option4ClientFqdn::FLAG_E,
"myhost.example.com.",
Option4ClientFqdn::PARTIAL,
true);
testProcessFqdn(query, Option4ClientFqdn::FLAG_E |
Option4ClientFqdn::FLAG_S | Option4ClientFqdn::FLAG_O,
"myhost.example.com.");
}
} // end of anonymous namespace
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