From: Francis Dupont Date: Sat, 23 Jun 2018 11:16:50 +0000 (+0200) Subject: [5440] Checkpoint before giving up X-Git-Tag: 421-create-config-backend-for-dhcpv6-base_base~18^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f141f14efedc5b60d36f9e1e76477ccbbe71f34;p=thirdparty%2Fkea.git [5440] Checkpoint before giving up --- diff --git a/src/bin/dhcp4/dhcp4_messages.mes b/src/bin/dhcp4/dhcp4_messages.mes index f0d486a6c3..83c1e21ba8 100644 --- a/src/bin/dhcp4/dhcp4_messages.mes +++ b/src/bin/dhcp4/dhcp4_messages.mes @@ -98,6 +98,11 @@ client and transaction identification information. The second argument specifies the hostname carried in the Hostname option sent by the client. +% DHCP4_CLIENT_HOSTNAME_EMPTY %1: client sent bogus empty Hostname option +This informational message is issued when the server receives an +empty Hostname option. Such option is bogus (size is required to be +at least one) and is ignored. + % DHCP4_CLIENT_HOSTNAME_PROCESS %1: processing client's Hostname option This debug message is issued when the server starts processing the Hostname option sent in the client's query. The argument includes the client and diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index ab0525ae90..de43e92dd7 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -1679,6 +1679,13 @@ Dhcpv4Srv::processHostnameOption(Dhcpv4Exchange& ex) { OptionStringPtr opt_hostname = boost::dynamic_pointer_cast (ex.getQuery()->getOption(DHO_HOST_NAME)); + // Ignore empty/bogus Hostname option. + if (opt_hostname && opt_hostname->getValue().empty()) { + opt_hostname.reset(); + LOG_INFO(ddns4_logger, DHCP4_CLIENT_HOSTNAME_EMPTY) + .arg(ex.getQuery()->getLabel()); + } + if (opt_hostname) { LOG_DEBUG(ddns4_logger, DBG_DHCP4_DETAIL_DATA, DHCP4_CLIENT_HOSTNAME_DATA) .arg(ex.getQuery()->getLabel()) diff --git a/src/bin/dhcp4/tests/fqdn_unittest.cc b/src/bin/dhcp4/tests/fqdn_unittest.cc index 575020ea21..d66a460d43 100644 --- a/src/bin/dhcp4/tests/fqdn_unittest.cc +++ b/src/bin/dhcp4/tests/fqdn_unittest.cc @@ -412,6 +412,29 @@ public: } + // Create a message holding an empty Hostname option. + Pkt4Ptr generatePktWithEmptyHostname(const uint8_t msg_type) { + + Pkt4Ptr pkt = Pkt4Ptr(new Pkt4(msg_type, 1234)); + pkt->setRemoteAddr(IOAddress("192.0.2.3")); + // For DISCOVER we don't include server id, because client broadcasts + // the message to all servers. + if (msg_type != DHCPDISCOVER) { + pkt->addOption(srv_->getServerID()); + } + + pkt->addOption(generateClientId()); + + // Create Hostname option. + std::string hostname(" "); + OptionPtr opt = createHostname(hostname); + opt->setData(hostname.begin(), hostname.begin()); + pkt->addOption(opt); + + return (pkt); + + } + // Create a message holding of a given type Pkt4Ptr generatePkt(const uint8_t msg_type) { Pkt4Ptr pkt = Pkt4Ptr(new Pkt4(msg_type, 1234)); @@ -813,6 +836,15 @@ TEST_F(NameDhcpv4SrvTest, serverUpdateWrongHostname) { EXPECT_FALSE(hostname); } +// Test that the server skips processing of an empty Hostname option. +TEST_F(NameDhcpv4SrvTest, serverUpdateEmptyHostname) { + Pkt4Ptr query; + ASSERT_NO_THROW(query = generatePktWithEmptyHostname(DHCPREQUEST)); + OptionStringPtr hostname; + ASSERT_NO_THROW(hostname = processHostname(query)); + EXPECT_FALSE(hostname); +} + // Test that server generates the fully qualified domain name for the client // if client supplies the partial name.