Commit 44faa27e authored by Marcin Siodelski's avatar Marcin Siodelski

[#86,!152] Case insensitive hostname option comparison.

parent 0a42706d
......@@ -62,7 +62,7 @@
#endif
#include <dhcpsrv/memfile_lease_mgr.h>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/bind.hpp>
#include <boost/foreach.hpp>
#include <boost/pointer_cast.hpp>
......@@ -1721,9 +1721,12 @@ Dhcpv4Srv::processHostnameOption(Dhcpv4Exchange& ex) {
// send back a hostname option, send this option with a reserved
// name for this client.
if (should_send_hostname) {
const std::string& hostname =
d2_mgr.qualifyName(ctx->currentHost()->getHostname(),
false);
std::string hostname =
d2_mgr.qualifyName(ctx->currentHost()->getHostname(), false);
// Convert hostname to lower case.
boost::algorithm::to_lower(hostname);
LOG_DEBUG(ddns4_logger, DBG_DHCP4_DETAIL_DATA,
DHCP4_RESERVED_HOSTNAME_ASSIGNED)
.arg(ex.getQuery()->getLabel())
......@@ -1813,6 +1816,9 @@ Dhcpv4Srv::processHostnameOption(Dhcpv4Exchange& ex) {
hostname = sanitizer->scrub(hostname);
}
// Convert hostname to lower case.
boost::algorithm::to_lower(hostname);
if (label_count == 2) {
// If there are two labels, it means that the client has specified
// the unqualified name. We have to concatenate the unqualified name
......
......@@ -1070,7 +1070,8 @@ TEST_F(NameDhcpv4SrvTest, processTwoRequestsHostname) {
IfaceMgrTestConfig test_config(true);
IfaceMgr::instance().openSockets4();
Pkt4Ptr req1 = generatePktWithHostname(DHCPREQUEST, "myhost.example.com.");
// Case in a hostname should be ignored.
Pkt4Ptr req1 = generatePktWithHostname(DHCPREQUEST, "Myhost.Example.Com.");
// Set interface for the incoming packet. The server requires it to
// generate client id.
......@@ -1145,11 +1146,11 @@ TEST_F(NameDhcpv4SrvTest, processRequestRenewFqdn) {
"965B68B6D438D98E680BF10B09F3BCF",
time(NULL), subnet_->getValid(), true);
// Create another Request message with the same FQDN. Server
// should generate no NameChangeRequests.
// Create another Request message with the same FQDN. Case changes in the
// hostname should be ignored. Server should generate no NameChangeRequests.
Pkt4Ptr req2 = generatePktWithFqdn(DHCPREQUEST, Option4ClientFqdn::FLAG_S |
Option4ClientFqdn::FLAG_E,
"myhost.example.com.",
"Myhost.Example.Com.",
Option4ClientFqdn::FULL, true);
ASSERT_NO_THROW(reply = srv_->processRequest(req2));
......@@ -1186,9 +1187,9 @@ TEST_F(NameDhcpv4SrvTest, processRequestRenewHostname) {
"965B68B6D438D98E680BF10B09F3BCF",
time(NULL), subnet_->getValid(), true);
// Create another Request message with the same Hostname. Server
// should generate no NameChangeRequests.
Pkt4Ptr req2 = generatePktWithHostname(DHCPREQUEST, "myhost.example.com.");
// Create another Request message with the same Hostname. Case changes in the
// hostname should be ignored. Server should generate no NameChangeRequests.
Pkt4Ptr req2 = generatePktWithHostname(DHCPREQUEST, "Myhost.Example.Com.");
// Set interface for the incoming packet. The server requires it to
// generate client id.
......
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