]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2260] Added iaid check
authorFrancis Dupont <fdupont@isc.org>
Fri, 10 Jul 2026 14:46:21 +0000 (16:46 +0200)
committerFrancis Dupont <fdupont@isc.org>
Fri, 10 Jul 2026 14:46:21 +0000 (16:46 +0200)
src/hooks/dhcp/lease_cmds/lease_cmds.cc
src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds4_unittest.cc
src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds6_unittest.cc

index a2c5530a11b7e7434beba7fe2e0e0920087a04af..2f27036d78dc3bb46a4542088015621b0d5e8007 100644 (file)
@@ -766,8 +766,19 @@ LeaseCmdsImpl::getParameters(bool v6, const ConstElementPtr& params) {
     }
     x.subnet_id = static_cast<SubnetID>(tmp128);
 
-    if (params->contains("iaid")) {
-        x.iaid = params->get("iaid")->intValue();
+    tmp = params->get("iaid");
+    if (tmp) {
+        if (!v6) {
+            isc_throw(BadValue, "'iaid' parameter is specific to DHCPv6.");
+        }
+        if (tmp->getType() != Element::integer) {
+            isc_throw(BadValue, "'iaid' parameter is not integer.");
+        }
+        tmp128 = tmp->intValue();
+        if ((tmp128 < uint32_min) || (tmp128 > uint32_max)) {
+            isc_throw(BadValue, "'iaid' parameter is not a 32 bit unsigned integer.");
+        }
+        x.iaid = static_cast<uint32_t>(tmp128);
     }
 
     // No address specified. Ok, so it must be identifier based query.
index 92d3cf01a61cfcfd46b1bbf26aa40be7be592459..7425bc576a5fe558f981124530c8b6b2a1693060 100644 (file)
@@ -1270,6 +1270,7 @@ void Lease4CmdsTest::testLease4GetBadParam() {
     // Structure detailing a test scenario.
     struct Scenario {
         string name_;                // name
+        bool add_subnet_id_;         // set to true to add a subnet-id
         string param_;               // parameter entry to test
         string exp_rsp_;             // expected response
     };
@@ -1278,42 +1279,59 @@ void Lease4CmdsTest::testLease4GetBadParam() {
     std::vector<Scenario> scenarios = {
         {
             "Invalid family",
+            false,
             "\"ip-address\": \"2001:db8:1::1\"",
             "Invalid IPv4 address specified: 2001:db8:1::1"
         },
         {
             "Bad address",
+            false,
             "\"ip-address\": \"221B Baker St.\"",
             "Failed to convert string to address '221B Baker St.': Invalid argument"
         },
         {
             "Not numeric subnet id",
+            false,
             "\"subnet-id\": \"foo\"",
             "'subnet-id' parameter is not integer."
         },
         {
             "Negative subnet id",
+            false,
             "\"subnet-id\": -1",
             "'subnet-id' parameter is not a 32 bit unsigned integer."
         },
         {
             "Too large subnet id",
+            false,
             "\"subnet-id\": 4294967297",
             "'subnet-id' parameter is not a 32 bit unsigned integer."
+        },
+        {
+            "IAID is v6 only",
+            true,
+            "\"iaid\": 0",
+            "'iaid' parameter is specific to DHCPv6."
         }
     };
 
     string prefix_cmd =
         "{\n"
         "    \"command\": \"lease4-get\",\n"
-        "    \"arguments\": {"
+        "    \"arguments\": {\n"
         "        ";
+    string subnet_id = "        \"subnet-id\": 1\n,";
     string end_cmd =
+        "\n"
         "    }\n"
-        "}";
+        "}\n";
     for (auto const& scenario : scenarios) {
         SCOPED_TRACE(scenario.name_);
-        string cmd = prefix_cmd + scenario.param_ + end_cmd;
+        string cmd = prefix_cmd;
+        if (scenario.add_subnet_id_) {
+            cmd += subnet_id;
+        }
+        cmd += scenario.param_ + end_cmd;
         testCommand(cmd, CONTROL_RESULT_ERROR, scenario.exp_rsp_);
     }
 }
index 7ea368b38581c1c5269319f0ba8af8e7e3a8208b..7ae572b4345e7f6a3cdc8e99210cb4f0fd224c11 100644 (file)
@@ -1523,6 +1523,7 @@ void Lease6CmdsTest::testLease6GetBadParam() {
     // Structure detailing a test scenario.
     struct Scenario {
         string name_;                // name
+        bool add_subnet_id_;         // set to true to add a subnet-id
         string param_;               // parameter entry to test
         string exp_rsp_;             // expected response
     };
@@ -1531,42 +1532,71 @@ void Lease6CmdsTest::testLease6GetBadParam() {
     std::vector<Scenario> scenarios = {
         {
             "Invalid family",
+            false,
             "\"ip-address\": \"192.0.2.1\"",
             "Invalid IPv6 address specified: 192.0.2.1"
         },
         {
             "Bad address",
+            false,
             "\"ip-address\": \"221B Baker St.\"",
             "Failed to convert string to address '221B Baker St.': Invalid argument"
         },
         {
             "Not numeric subnet id",
+            false,
             "\"subnet-id\": \"foo\"",
             "'subnet-id' parameter is not integer."
         },
         {
             "Negative subnet id",
+            false,
             "\"subnet-id\": -1",
             "'subnet-id' parameter is not a 32 bit unsigned integer."
         },
         {
             "Too large subnet id",
+            false,
             "\"subnet-id\": 4294967297",
             "'subnet-id' parameter is not a 32 bit unsigned integer."
+        },
+        {
+            "Not numeric iaid",
+            true,
+            "\"iaid\": true",
+            "'iaid' parameter is not integer."
+        },
+        {
+            "Negative iaid",
+            true,
+            "\"iaid\": -1",
+            "'iaid' parameter is not a 32 bit unsigned integer."
+        },
+        {
+            "Too large iaid",
+            true,
+            "\"iaid\": 4294967297",
+            "'iaid' parameter is not a 32 bit unsigned integer."
         }
     };
 
     string prefix_cmd =
         "{\n"
         "    \"command\": \"lease6-get\",\n"
-        "    \"arguments\": {"
+        "    \"arguments\": {\n"
         "        ";
+    string subnet_id = "        \"subnet-id\": 1\n,";
     string end_cmd =
+        "\n"
         "    }\n"
-        "}";
+        "}\n";
     for (auto const& scenario : scenarios) {
         SCOPED_TRACE(scenario.name_);
-        string cmd = prefix_cmd + scenario.param_ + end_cmd;
+        string cmd = prefix_cmd;
+        if (scenario.add_subnet_id_) {
+            cmd += subnet_id;
+        }
+        cmd += scenario.param_ + end_cmd;
         testCommand(cmd, CONTROL_RESULT_ERROR, scenario.exp_rsp_);
     }
 }