From: Marcin Siodelski Date: Tue, 4 Dec 2018 09:10:30 +0000 (+0100) Subject: [#86,!152] Case insensitive hostname option comparison. X-Git-Tag: 174-warning-for-unused-trace-levels_base~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=44faa27e6d7c197de32b9d89cef039b20574d6f5;p=thirdparty%2Fkea.git [#86,!152] Case insensitive hostname option comparison. --- diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index 7aa26f2faf..d619f7c95c 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -62,7 +62,7 @@ #endif #include -#include +#include #include #include #include @@ -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 diff --git a/src/bin/dhcp4/tests/fqdn_unittest.cc b/src/bin/dhcp4/tests/fqdn_unittest.cc index f5c0c510ce..575020ea21 100644 --- a/src/bin/dhcp4/tests/fqdn_unittest.cc +++ b/src/bin/dhcp4/tests/fqdn_unittest.cc @@ -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.