]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5440] Checkpoint before giving up
authorFrancis Dupont <fdupont@isc.org>
Sat, 23 Jun 2018 11:16:50 +0000 (13:16 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Wed, 16 Jan 2019 09:46:16 +0000 (10:46 +0100)
src/bin/dhcp4/dhcp4_messages.mes
src/bin/dhcp4/dhcp4_srv.cc
src/bin/dhcp4/tests/fqdn_unittest.cc

index f0d486a6c30f11712fb343c4c092f442ae939a57..83c1e21ba8d56c7e49e9b8e48d56902302062980 100644 (file)
@@ -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
index ab0525ae900f555df5182dd294526ac5e063952b..de43e92dd700be7d36a9884dff8ca402dd787992 100644 (file)
@@ -1679,6 +1679,13 @@ Dhcpv4Srv::processHostnameOption(Dhcpv4Exchange& ex) {
     OptionStringPtr opt_hostname = boost::dynamic_pointer_cast<OptionString>
         (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())
index 575020ea2118a5c9b27268cac38258bc3bd19125..d66a460d4363a4e31e063c15615e10feb5a327dd 100644 (file)
@@ -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.