]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[(no branch, rebasing 1815-add-new-drop-points)] [(no branch, rebasing 1815-add-new...
authorFrancis Dupont <fdupont@isc.org>
Thu, 29 Apr 2021 16:00:18 +0000 (18:00 +0200)
committerFrancis Dupont <fdupont@isc.org>
Wed, 19 May 2021 15:20:35 +0000 (17:20 +0200)
src/bin/dhcp4/tests/classify_unittest.cc

index b7f4ab8e76f1badf651d506b5c37e6238c9ef2e9..639e821f4e9ba1790d0cba8e0c3efd4a2d678913 100644 (file)
@@ -83,7 +83,7 @@ namespace {
 ///   - the following class defined: option[93].hex == 0x0009, DROP
 ///
 /// - Configuration 6:
-///   - Used for the DROP class and reservations.
+///   - Used for the DROP class and reservation existence.
 ///   - 1 subnet: 10.0.0.0/24
 ///   - 1 pool: 10.0.0.10-10.0.0.100
 ///   - 1 reservation for HW address 'aa:bb:cc:dd:ee:ff'
@@ -93,6 +93,17 @@ namespace {
 /// @note the reservation includes a hostname because raw reservations are
 /// not yet allowed.
 ///
+/// - Configuration 7:
+///   - Used for the DROP class and reservation class.
+///   - 1 subnet: 10.0.0.0/24
+///   - 1 pool: 10.0.0.10-10.0.0.100
+///   - 1 reservation for HW address 'aa:bb:cc:dd:ee:ff'
+///     setting the allowed class
+///   - the following classes defined:
+///     - allowed
+///     - member('KNOWN') or member('UNKNOWN'), t
+///     not member('allowed') and member('t'), DROP
+///
 const char* CONFIGS[] = {
     // Configuration 0
     "{ \"interfaces-config\": {"
@@ -318,7 +329,7 @@ const char* CONFIGS[] = {
         "\"client-classes\": ["
         "{"
         "   \"name\": \"DROP\","
-        "   \"test\": \"member('UNKNOWN')\""
+        "   \"test\": \"not member('KNOWN')\""
         "}],"
         "\"subnet4\": [ { "
         "    \"subnet\": \"10.0.0.0/24\", "
@@ -328,6 +339,33 @@ const char* CONFIGS[] = {
         "        \"hw-address\": \"aa:bb:cc:dd:ee:ff\","
         "        \"hostname\": \"allowed\" } ]"
         " } ]"
+    "}",
+
+    // Configuration 7
+    "{ \"interfaces-config\": {"
+        "   \"interfaces\": [ \"*\" ]"
+        "},"
+        "\"valid-lifetime\": 600,"
+        "\"client-classes\": ["
+        "{"
+        "   \"name\": \"allowed\""
+        "},"
+        "{"
+        "   \"name\": \"t\","
+        "   \"test\": \"member('KNOWN') or member('UNKNOWN')\""
+        "},"
+        "{"
+        "   \"name\": \"DROP\","
+        "   \"test\": \"not member('allowed') and member('t')\""
+        "}],"
+        "\"subnet4\": [ { "
+        "    \"subnet\": \"10.0.0.0/24\", "
+        "    \"id\": 1,"
+        "    \"pools\": [ { \"pool\": \"10.0.0.10-10.0.0.100\" } ],"
+        "    \"reservations\": [ {"
+        "        \"hw-address\": \"aa:bb:cc:dd:ee:ff\","
+        "        \"client-classes\": [ \"allowed\" ] } ]"
+        " } ]"
     "}"
 };
 
@@ -1196,8 +1234,44 @@ TEST_F(ClassifyTest, dropClass) {
 }
 
 // This test checks the handling for the DROP special class at the host
-// reservation classification point.
-TEST_F(ClassifyTest, dropClassHR) {
+// reservation classification point with KNOWN / UNKNOWN.
+TEST_F(ClassifyTest, dropClassUnknown) {
+    Dhcp4Client client(Dhcp4Client::SELECTING);
+
+    // Configure DHCP server.
+    configure(CONFIGS[6], *client.getServer());
+
+    // Set the HW address to the reservation.
+    client.setHWAddress("aa:bb:cc:dd:ee:ff");
+
+    // Send the discover.
+    client.doDiscover();
+
+    // Reservation match: no drop.
+    EXPECT_TRUE(client.getContext().response_);
+
+    // Retry with another HW address.
+    Dhcp4Client client2(Dhcp4Client::SELECTING);
+    client2.setHWAddress("aa:bb:cc:dd:ee:fe");
+
+    // Send the discover.
+    client2.doDiscover();
+
+    // No reservation, dropped.
+    EXPECT_FALSE(client2.getContext().response_);
+
+    // There should also be pkt4-receive-drop stat bumped up.
+    stats::StatsMgr& mgr = stats::StatsMgr::instance();
+    stats::ObservationPtr drop_stat = mgr.getObservation("pkt4-receive-drop");
+
+    // This statistic must be present and must be set to 1.
+    ASSERT_TRUE(drop_stat);
+    EXPECT_EQ(1, drop_stat->getInteger().first);
+}
+
+// This test checks the handling for the DROP special class at the host
+// reservation classification point with a reserved class.
+TEST_F(ClassifyTest, dropClassReservedClass) {
     Dhcp4Client client(Dhcp4Client::SELECTING);
 
     // Configure DHCP server.