]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5425a] Changes after review:
authorTomek Mrugalski <tomasz@isc.org>
Fri, 26 Jan 2018 23:09:33 +0000 (00:09 +0100)
committerTomek Mrugalski <tomasz@isc.org>
Fri, 26 Jan 2018 23:09:33 +0000 (00:09 +0100)
 - it is now possible to define multiple classes for a pool
 - small doc corrections

24 files changed:
doc/examples/kea4/classify.json
doc/examples/kea6/classify.json
doc/guide/classify.xml
doc/guide/dhcp6-srv.xml
src/bin/dhcp4/dhcp4_lexer.ll
src/bin/dhcp4/dhcp4_parser.yy
src/bin/dhcp4/tests/config_parser_unittest.cc
src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
src/bin/dhcp4/tests/get_config_unittest.cc
src/bin/dhcp4/tests/shared_network_unittest.cc
src/bin/dhcp6/dhcp6_lexer.ll
src/bin/dhcp6/dhcp6_parser.yy
src/bin/dhcp6/tests/classify_unittests.cc
src/bin/dhcp6/tests/config_parser_unittest.cc
src/bin/dhcp6/tests/get_config_unittest.cc
src/bin/dhcp6/tests/shared_network_unittest.cc
src/lib/dhcpsrv/alloc_engine.h
src/lib/dhcpsrv/parsers/dhcp_parsers.cc
src/lib/dhcpsrv/parsers/dhcp_parsers.h
src/lib/dhcpsrv/pool.cc
src/lib/dhcpsrv/pool.h
src/lib/dhcpsrv/subnet.cc
src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc
src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc

index a44b030455c0a3a61c976fc227daa9977c66e61e..44a4bc633ad94e0d02caf31ba677a267e7183d17 100644 (file)
            // This one is for VoIP devices only.
            {
               "pool":  "192.0.4.1 - 192.0.4.200",
-              "client-class": "VoIP"
+              "client-classes": [ "VoIP" ]
            },
 
            // This one doesn't have any client-class specified,
index 151392e84569d52c72e36ff59326468149d0aad6..8169826d22bef019495828ffb5422ea5bfdec458 100644 (file)
@@ -82,7 +82,7 @@
         "pools": [
            {
                "pool": "2001:db8:3::/80",
-               "client-class": "cable-modems"
+               "client-classes": [ "cable-modems" ]
            } ],
          "subnet": "2001:db8:4::/64",
          "interface": "ethY"
index 23009e98f562461651b0b083e335aea58dcab22f..38268029fb09b23f071834517365f518930f9dd4 100644 (file)
@@ -805,8 +805,12 @@ concatenation of the strings</entry></row>
    <title>Configuring Pools With Class Information</title>
      <para>
        Similar to the subnets, it is possible to restrict access to the certain address
-       or prefix pools to the clients belonging to a specific class, using
-       the "client-class" parameter when defining the pool.
+       or prefix pools to the clients belonging to a specific class or
+       classes, using the "client-classes" parameter when defining the
+       pool. As opposed to subnets, the pools scope allows to define
+       more than one class that is allowed. The incoming packet has to
+       belong to only one of the classes listed to be able to get an
+       address from that pool.
      </para>
 
      <para>
@@ -841,7 +845,7 @@ concatenation of the strings</entry></row>
             "pools": [
                 {
                     "pool": "192.0.2.10 - 192.0.2.20",
-                    "client-class": "Client_foo"
+                    "client-classes": [ "Client_foo" ]
                 }
             ]</userinput>
         },
@@ -880,7 +884,7 @@ concatenation of the strings</entry></row>
             "pools": [
                 {
                     "pool": "2001:db8:1::-2001:db8:1::ffff",
-                    "client-class": "Client_foo"
+                    "client-classes": [ "Client_foo" ]
                 }
             ]</userinput>
         },
index 4b667a2a47fe76e92a0080bccd75afb981da189b..ad10322ffc38fac5257b987a9fc2de809f13b5f6 100644 (file)
@@ -1961,7 +1961,7 @@ should include options from the isc option space:
       <para>
       Client classification can also be used to restrict access to specific
       pools within a subnet. This is useful when to segregate clients belonging
-      to the same subnet into different address ranges.
+      to the same subnet into different address or prefix ranges.
       </para>
 
       <para>
index d5d88ff41ae63c9feeef56ea46fd2810946915f0..809692e349f8ce6678883356260e0b3267fced11 100644 (file)
@@ -813,6 +813,7 @@ ControlCharacterFill            [^"\\]|\\{JSONEscapeSequence}
 \"client-classes\" {
     switch(driver.ctx_) {
     case isc::dhcp::Parser4Context::DHCP4:
+    case isc::dhcp::Parser4Context::POOLS:
     case isc::dhcp::Parser4Context::RESERVATIONS:
         return isc::dhcp::Dhcp4Parser::make_CLIENT_CLASSES(driver.loc_);
     default:
@@ -823,7 +824,6 @@ ControlCharacterFill            [^"\\]|\\{JSONEscapeSequence}
 \"client-class\" {
     switch(driver.ctx_) {
     case isc::dhcp::Parser4Context::SUBNET4:
-    case isc::dhcp::Parser4Context::POOLS:
     case isc::dhcp::Parser4Context::SHARED_NETWORK:
     case isc::dhcp::Parser4Context::CLIENT_CLASSES:
         return isc::dhcp::Dhcp4Parser::make_CLIENT_CLASS(driver.loc_);
index 9c5f94262a3ef7e5c24b7b55f7755158e843488a..ad4ec6ef78ee29d68a9b2e99ad6002e2d6ae43e3 100644 (file)
@@ -1344,7 +1344,7 @@ pool_params: pool_param
 
 pool_param: pool_entry
           | option_data_list
-          | client_class
+          | client_class_names_list
           | user_context
           | comment
           | unknown_map_entry
@@ -1459,7 +1459,7 @@ not_empty_reservation_params: reservation_param
 
 /// @todo probably need to add mac-address as well here
 reservation_param: duid
-                 | reservation_client_classes
+                 | client_class_names_list
                  | client_id_value
                  | circuit_id_value
                  | flex_id_value
@@ -1555,7 +1555,7 @@ hostname: HOSTNAME {
     ctx.leave();
 };
 
-reservation_client_classes: CLIENT_CLASSES {
+client_class_names_list: CLIENT_CLASSES {
     ElementPtr c(new ListElement(ctx.loc2pos(@1)));
     ctx.stack_.back()->set("client-classes", c);
     ctx.stack_.push_back(c);
index da4b250be76cf2159af0ce0c6ab28f55bf53cc30..5bfdd6a584fccc31f82cf45b459fd0f0fbbd2a93 100644 (file)
@@ -4168,15 +4168,15 @@ TEST_F(Dhcp4ParserTest, classifyPools) {
         "\"subnet4\": [ { "
         "    \"pools\": [ { "
         "        \"pool\": \"192.0.2.1 - 192.0.2.100\", "
-        "        \"client-class\": \"alpha\" "
+        "        \"client-classes\": [ \"alpha\" ] "
         "     },"
         "     {"
         "        \"pool\": \"192.0.3.101 - 192.0.3.150\", "
-        "        \"client-class\": \"beta\" "
+        "        \"client-classes\": [ \"beta\" ] "
         "     },"
         "     {"
         "        \"pool\": \"192.0.4.101 - 192.0.4.150\", "
-        "        \"client-class\": \"gamma\" "
+        "        \"client-classes\": [ \"gamma\", \"alpha\" ] "
         "     },"
         "     {"
         "        \"pool\": \"192.0.5.101 - 192.0.5.150\" "
@@ -4200,13 +4200,13 @@ TEST_F(Dhcp4ParserTest, classifyPools) {
     ASSERT_EQ(4, pools.size()); // We expect 4 pools
 
     // Let's check if client belonging to alpha class is supported in pool[0]
-    // and not supported in any other pool (except pool[3], which allows
-    // everyone).
+    // and pool[2] (which allows 2 classes)  and not supported in any other
+    // pool (except pool[3], which allows everyone).
     ClientClasses classes;
     classes.insert("alpha");
     EXPECT_TRUE(pools.at(0)->clientSupported(classes));
     EXPECT_FALSE(pools.at(1)->clientSupported(classes));
-    EXPECT_FALSE(pools.at(2)->clientSupported(classes));
+    EXPECT_TRUE(pools.at(2)->clientSupported(classes));
     EXPECT_TRUE(pools.at(3)->clientSupported(classes));
 
     // Let's check if client belonging to beta class is supported in pool[1]
index f650d33867f0acbfe3779d4ac5ae2d42c55d0fde..363e216fb13c2a3378dfa9df777a085d75ca886f 100644 (file)
@@ -2337,9 +2337,9 @@ TEST_F(Dhcpv4SrvTest, clientPoolClassify) {
         "\"subnet4\": [ "
         "{   \"pools\": [ { "
         "      \"pool\": \"192.0.2.1 - 192.0.2.100\", "
-        "      \"client-class\": \"foo\" }, "
+        "      \"client-classes\": [ \"foo\" ] }, "
         "    { \"pool\": \"192.0.3.1 - 192.0.3.100\", "
-        "      \"client-class\": \"xyzzy\" } ], "
+        "      \"client-classes\": [ \"xyzzy\" ] } ], "
         "    \"subnet\": \"192.0.0.0/16\" } "
         "],"
         "\"valid-lifetime\": 4000 }";
index d06bd40017b1c70fa8170bb8605b1cdeffca8354..6f03a434e7ddfb677ab887d3359eb17a19e8982b 100644 (file)
@@ -1245,15 +1245,15 @@ const char* EXTRACTED_CONFIGS[] = {
 "            {\n"
 "                \"pools\": [\n"
 "                    {\n"
-"                        \"client-class\": \"alpha\",\n"
+"                        \"client-classes\": [ \"alpha\" ],\n"
 "                        \"pool\": \"192.0.2.1 - 192.0.2.100\"\n"
 "                    },\n"
 "                    {\n"
-"                        \"client-class\": \"beta\",\n"
+"                        \"client-classes\": [ \"beta\" ],\n"
 "                        \"pool\": \"192.0.3.101 - 192.0.3.150\"\n"
 "                    },\n"
 "                    {\n"
-"                        \"client-class\": \"gamma\",\n"
+"                        \"client-classes\": [ \"gamma\", \"alpha\" ],\n"
 "                        \"pool\": \"192.0.4.101 - 192.0.4.150\"\n"
 "                    },\n"
 "                    {\n"
@@ -5267,17 +5267,17 @@ const char* UNPARSED_CONFIGS[] = {
 "                \"option-data\": [ ],\n"
 "                \"pools\": [\n"
 "                    {\n"
-"                        \"client-class\": \"alpha\",\n"
+"                        \"client-classes\": [ \"alpha\" ],\n"
 "                        \"option-data\": [ ],\n"
 "                        \"pool\": \"192.0.2.1-192.0.2.100\"\n"
 "                    },\n"
 "                    {\n"
-"                        \"client-class\": \"beta\",\n"
+"                        \"client-classes\": [ \"beta\" ],\n"
 "                        \"option-data\": [ ],\n"
 "                        \"pool\": \"192.0.3.101-192.0.3.150\"\n"
 "                    },\n"
 "                    {\n"
-"                        \"client-class\": \"gamma\",\n"
+"                        \"client-classes\": [ \"alpha\", \"gamma\" ],\n"
 "                        \"option-data\": [ ],\n"
 "                        \"pool\": \"192.0.4.101-192.0.4.150\"\n"
 "                    },\n"
index 64240ec6f5a9041cbc6937bf629188a2e6e80d3c..5d42ef69824e250585534f2d653f52b668d1c22d 100644 (file)
@@ -891,7 +891,7 @@ const char* NETWORKS_CONFIG[] = {
     "                    \"pools\": ["
     "                        {"
     "                            \"pool\": \"192.0.2.1 - 192.0.2.63\","
-    "                            \"client-class\": \"a-devices\""
+    "                            \"client-classes\": [ \"a-devices\" ]"
     "                        },"
     "                        {"
     "                            \"pool\": \"192.0.2.100 - 192.0.2.100\""
@@ -931,11 +931,11 @@ const char* NETWORKS_CONFIG[] = {
     "                    \"pools\": ["
     "                        {"
     "                            \"pool\": \"192.0.2.1 - 192.0.2.63\","
-    "                            \"client-class\": \"a-devices\""
+    "                            \"client-classes\": [ \"a-devices\" ]"
     "                        },"
     "                        {"
     "                            \"pool\": \"192.0.2.100 - 192.0.2.100\","
-    "                            \"client-class\": \"b-devices\""
+    "                            \"client-classes\": [ \"b-devices\" ]"
     "                        }"
     "                    ]"
     "                }"
@@ -969,7 +969,7 @@ const char* NETWORKS_CONFIG[] = {
     "            \"pools\": ["
     "                {"
     "                    \"pool\": \"192.0.2.1 - 192.0.2.63\","
-    "                    \"client-class\": \"a-devices\""
+    "                    \"client-classes\": [ \"a-devices\" ]"
     "                },"
     "                {"
     "                    \"pool\": \"192.0.2.100 - 192.0.2.100\""
@@ -1004,11 +1004,11 @@ const char* NETWORKS_CONFIG[] = {
     "            \"pools\": ["
     "                {"
     "                    \"pool\": \"192.0.2.1 - 192.0.2.63\","
-    "                    \"client-class\": \"a-devices\""
+    "                    \"client-classes\": [ \"a-devices\" ]"
     "                },"
     "                {"
     "                    \"pool\": \"192.0.2.100 - 192.0.2.100\","
-    "                    \"client-class\": \"b-devices\""
+    "                    \"client-classes\": [ \"b-devices\" ]"
     "                }"
     "            ]"
     "        }"
index 58808613eaa1476a0922ad99248794ef0e430c41..cc09bcae74c9043241d0e5c5555ecec2c2f93d9c 100644 (file)
@@ -1068,6 +1068,8 @@ ControlCharacterFill            [^"\\]|\\{JSONEscapeSequence}
 \"client-classes\" {
     switch(driver.ctx_) {
     case isc::dhcp::Parser6Context::DHCP6:
+    case isc::dhcp::Parser6Context::POOLS:
+    case isc::dhcp::Parser6Context::PD_POOLS:
     case isc::dhcp::Parser6Context::RESERVATIONS:
         return isc::dhcp::Dhcp6Parser::make_CLIENT_CLASSES(driver.loc_);
     default:
@@ -1078,8 +1080,6 @@ ControlCharacterFill            [^"\\]|\\{JSONEscapeSequence}
 \"client-class\" {
     switch(driver.ctx_) {
     case isc::dhcp::Parser6Context::SUBNET6:
-    case isc::dhcp::Parser6Context::POOLS:
-    case isc::dhcp::Parser6Context::PD_POOLS:
     case isc::dhcp::Parser6Context::CLIENT_CLASSES:
     case isc::dhcp::Parser6Context::SHARED_NETWORK:
         return isc::dhcp::Dhcp6Parser::make_CLIENT_CLASS(driver.loc_);
index 5fd8df6db60b1d51779c3c5272380a4f6e73d265..e2e5e942a07fe77b86981fb84e97f9e080c1081a 100644 (file)
@@ -1307,7 +1307,7 @@ pool_params: pool_param
 
 pool_param: pool_entry
           | option_data_list
-          | client_class
+          | client_class_names_list
           | user_context
           | comment
           | unknown_map_entry
@@ -1428,7 +1428,7 @@ pd_pool_param: pd_prefix
              | pd_prefix_len
              | pd_delegated_len
              | option_data_list
-             | client_class
+             | client_class_names_list
              | excluded_prefix
              | excluded_prefix_len
              | user_context
@@ -1516,7 +1516,7 @@ not_empty_reservation_params: reservation_param
 
 /// @todo probably need to add mac-address as well here
 reservation_param: duid
-                 | reservation_client_classes
+                 | client_class_names_list
                  | ip_addresses
                  | prefixes
                  | hw_address
@@ -1580,7 +1580,7 @@ flex_id_value: FLEX_ID {
     ctx.leave();
 };
 
-reservation_client_classes: CLIENT_CLASSES {
+client_class_names_list: CLIENT_CLASSES {
     ElementPtr c(new ListElement(ctx.loc2pos(@1)));
     ctx.stack_.back()->set("client-classes", c);
     ctx.stack_.push_back(c);
@@ -1664,6 +1664,7 @@ client_class_test: TEST {
     ctx.leave();
 };
 
+
 // --- end of client classes ---------------------------------
 
 // --- server-id ---------------------------------------------
index e09ad8ea6fd28cf7e9cb689f157fa053a7f7f8da..63aba1e9c56d86602fa9ca85f3919db9a1edb79d 100644 (file)
@@ -645,11 +645,11 @@ TEST_F(ClassifyTest, clientClassifyPool) {
         " {  \"pools\": [ "
         "    { "
         "       \"pool\": \"2001:db8:1::/64\", "
-        "       \"client-class\": \"foo\" "
+        "       \"client-classes\": [ \"foo\" ] "
         "    }, "
         "    { "
         "       \"pool\": \"2001:db8:2::/64\", "
-        "       \"client-class\": \"xyzzy\" "
+        "       \"client-classes\": [ \"xyzzy\" ] "
         "    } "
         "   ], "
         "   \"subnet\": \"2001:db8:2::/40\" "
index ead3a0d9585b170c279d1a554024a1c234b5c9dd..02fc8ea7f7e63b8ca685efe07156f69986d83953 100644 (file)
@@ -4222,15 +4222,15 @@ TEST_F(Dhcp6ParserTest, classifyPools) {
         "\"subnet6\": [ { "
         "    \"pools\": [ { "
         "        \"pool\": \"2001:db8:1::/80\", "
-        "        \"client-class\": \"alpha\" "
+        "        \"client-classes\": [ \"alpha\" ] "
         "     },"
         "     {"
         "        \"pool\": \"2001:db8:2::/80\", "
-        "        \"client-class\": \"beta\" "
+        "        \"client-classes\": [ \"beta\" ] "
         "     },"
         "     {"
         "        \"pool\": \"2001:db8:3::/80\", "
-        "        \"client-class\": \"gamma\" "
+        "        \"client-classes\": [ \"gamma\" ] "
         "     },"
         "     {"
         "         \"pool\": \"2001:db8:4::/80\" "
@@ -4313,20 +4313,20 @@ TEST_F(Dhcp6ParserTest, classifyPdPools) {
         "    \"pd-pools\": [ { "
         "        \"prefix-len\": 48, "
         "        \"delegated-len\": 64, "
-        "        \"prefix\": \"2001:db8:1::\", "
-        "        \"client-class\": \"alpha\" "
+        "        \"prefix\": \"2001:db8:1::\", \n"
+        "        \"client-classes\": [ \"alpha\" ]\n "
         "     },"
         "     {"
         "        \"prefix-len\": 48, "
         "        \"delegated-len\": 64, "
         "        \"prefix\": \"2001:db8:2::\", "
-        "        \"client-class\": \"beta\" "
+        "        \"client-classes\": [ \"beta\" ]\n "
         "     },"
         "     {"
         "        \"prefix-len\": 48, "
         "        \"delegated-len\": 64, "
         "        \"prefix\": \"2001:db8:3::\", "
-        "        \"client-class\": \"gamma\" "
+        "        \"client-classes\": [ \"gamma\" ]\n "
         "     },"
         "     {"
         "        \"prefix-len\": 48, "
index 1759c8373b29d4f899bc057f11b4a8997ab55522..c283f851552d33a95367743d1c99464ce1b725fa 100644 (file)
@@ -1028,15 +1028,15 @@ const char* EXTRACTED_CONFIGS[] = {
 "            {\n"
 "                \"pools\": [\n"
 "                    {\n"
-"                        \"client-class\": \"alpha\",\n"
+"                        \"client-classes\": [ \"alpha\" ],\n"
 "                        \"pool\": \"2001:db8:1::/80\"\n"
 "                    },\n"
 "                    {\n"
-"                        \"client-class\": \"beta\",\n"
+"                        \"client-classes\": [ \"beta\" ],\n"
 "                        \"pool\": \"2001:db8:2::/80\"\n"
 "                    },\n"
 "                    {\n"
-"                        \"client-class\": \"gamma\",\n"
+"                        \"client-classes\": [ \"gamma\" ],\n"
 "                        \"pool\": \"2001:db8:3::/80\"\n"
 "                    },\n"
 "                    {\n"
@@ -1061,19 +1061,19 @@ const char* EXTRACTED_CONFIGS[] = {
 "            {\n"
 "                \"pd-pools\": [\n"
 "                    {\n"
-"                        \"client-class\": \"alpha\",\n"
+"                        \"client-classes\": [ \"alpha\" ],\n"
 "                        \"delegated-len\": 64,\n"
 "                        \"prefix\": \"2001:db8:1::\",\n"
 "                        \"prefix-len\": 48\n"
 "                    },\n"
 "                    {\n"
-"                        \"client-class\": \"beta\",\n"
+"                        \"client-classes\": [ \"beta\" ],\n"
 "                        \"delegated-len\": 64,\n"
 "                        \"prefix\": \"2001:db8:2::\",\n"
 "                        \"prefix-len\": 48\n"
 "                    },\n"
 "                    {\n"
-"                        \"client-class\": \"gamma\",\n"
+"                        \"client-classes\": [ \"gamma\" ],\n"
 "                        \"delegated-len\": 64,\n"
 "                        \"prefix\": \"2001:db8:3::\",\n"
 "                        \"prefix-len\": 48\n"
@@ -4595,17 +4595,17 @@ const char* UNPARSED_CONFIGS[] = {
 "                \"pd-pools\": [ ],\n"
 "                \"pools\": [\n"
 "                    {\n"
-"                        \"client-class\": \"alpha\",\n"
+"                        \"client-classes\": [ \"alpha\" ],\n"
 "                        \"option-data\": [ ],\n"
 "                        \"pool\": \"2001:db8:1::/80\"\n"
 "                    },\n"
 "                    {\n"
-"                        \"client-class\": \"beta\",\n"
+"                        \"client-classes\": [ \"beta\" ],\n"
 "                        \"option-data\": [ ],\n"
 "                        \"pool\": \"2001:db8:2::/80\"\n"
 "                    },\n"
 "                    {\n"
-"                        \"client-class\": \"gamma\",\n"
+"                        \"client-classes\": [ \"gamma\" ],\n"
 "                        \"option-data\": [ ],\n"
 "                        \"pool\": \"2001:db8:3::/80\"\n"
 "                    },\n"
@@ -4684,21 +4684,21 @@ const char* UNPARSED_CONFIGS[] = {
 "                \"option-data\": [ ],\n"
 "                \"pd-pools\": [\n"
 "                    {\n"
-"                        \"client-class\": \"alpha\",\n"
+"                        \"client-classes\": [ \"alpha\" ],\n"
 "                        \"delegated-len\": 64,\n"
 "                        \"option-data\": [ ],\n"
 "                        \"prefix\": \"2001:db8:1::\",\n"
 "                        \"prefix-len\": 48\n"
 "                    },\n"
 "                    {\n"
-"                        \"client-class\": \"beta\",\n"
+"                        \"client-classes\": [ \"beta\" ],\n"
 "                        \"delegated-len\": 64,\n"
 "                        \"option-data\": [ ],\n"
 "                        \"prefix\": \"2001:db8:2::\",\n"
 "                        \"prefix-len\": 48\n"
 "                    },\n"
 "                    {\n"
-"                        \"client-class\": \"gamma\",\n"
+"                        \"client-classes\": [ \"gamma\" ],\n"
 "                        \"delegated-len\": 64,\n"
 "                        \"option-data\": [ ],\n"
 "                        \"prefix\": \"2001:db8:3::\",\n"
index 32fa5d53ec60a8b9d8298ced8e88ee4ac0e1292e..adb24fede983240892d040457969c795cd4b222b 100644 (file)
@@ -984,7 +984,7 @@ const char* NETWORKS_CONFIG[] = {
     "                    \"pools\": ["
     "                        {"
     "                            \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\","
-    "                            \"client-class\": \"a-devices\""
+    "                            \"client-classes\": [ \"a-devices\" ]"
     "                        },"
     "                        {"
     "                            \"pool\": \"2001:db8:1::50 - 2001:db8:1::50\""
@@ -1021,11 +1021,11 @@ const char* NETWORKS_CONFIG[] = {
     "                    \"pools\": ["
     "                        {"
     "                            \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\","
-    "                            \"client-class\": \"a-devices\""
+    "                            \"client-classes\": [ \"a-devices\" ]"
     "                        },"
     "                        {"
     "                            \"pool\": \"2001:db8:1::50 - 2001:db8:1::50\","
-    "                            \"client-class\": \"b-devices\""
+    "                            \"client-classes\": [ \"b-devices\" ]"
     "                        }"
     "                    ]"
     "                }"
@@ -1055,7 +1055,7 @@ const char* NETWORKS_CONFIG[] = {
     "            \"pools\": ["
     "                {"
     "                    \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\","
-    "                    \"client-class\": \"a-devices\""
+    "                    \"client-classes\": [ \"a-devices\" ]"
     "                },"
     "                {"
     "                    \"pool\": \"2001:db8:1::50 - 2001:db8:1::50\""
@@ -1089,11 +1089,11 @@ const char* NETWORKS_CONFIG[] = {
     "                    \"pools\": ["
     "                        {"
     "                            \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\","
-    "                            \"client-class\": \"a-devices\""
+    "                            \"client-classes\": [ \"a-devices\" ]"
     "                        },"
     "                        {"
     "                            \"pool\": \"2001:db8:1::50 - 2001:db8:1::50\","
-    "                            \"client-class\": \"b-devices\""
+    "                            \"client-classes\": [ \"b-devices\" ]"
     "                        }"
     "                    ]"
     "                }"
index ba8d95bc0d749663fafe29f90d6e93067348b04c..9d16dd6069bf5cafce7edfca04cd534d2276937a 100644 (file)
@@ -83,7 +83,6 @@ protected:
         ///
         /// @param subnet next address will be returned from pool of that subnet
         /// @param client_classes list of classes client belongs to
-
         /// @param duid Client's DUID
         /// @param hint client's hint
         ///
index b10d7e7edaabab48f339aed5c6369888b803f8b2..84054da52ab2c47d746592185ac747fc9cb0af91 100644 (file)
@@ -379,11 +379,13 @@ PoolParser::parse(PoolStoragePtr pools,
     }
 
     // Client-class.
-    ConstElementPtr client_class = pool_structure->get("client-class");
-    if (client_class) {
-        string cclass = client_class->stringValue();
-        if (!cclass.empty()) {
-            pool->allowClientClass(cclass);
+    ConstElementPtr class_list = pool_structure->get("client-classes");
+    if (class_list) {
+        BOOST_FOREACH(ConstElementPtr c, class_list->listValue()) {
+            string cclass = c->stringValue();
+            if (!cclass.empty()) {
+                pool->allowClientClass(cclass);
+            }
         }
     }
 }
@@ -855,7 +857,7 @@ PdPoolParser::parse(PoolStoragePtr pools, ConstElementPtr pd_pool_) {
         user_context_ = user_context;
     }
 
-    ConstElementPtr client_class = pd_pool_->get("client-class");
+    ConstElementPtr client_class = pd_pool_->get("client-classes");
     if (client_class) {
         client_class_ = client_class;
     }
@@ -884,10 +886,13 @@ PdPoolParser::parse(PoolStoragePtr pools, ConstElementPtr pd_pool_) {
     }
 
 
+    // If present, this is a list of class names
     if (client_class_) {
-        string cclass = client_class_->stringValue();
-        if (!cclass.empty()) {
-            pool_->allowClientClass(cclass);
+        BOOST_FOREACH(ConstElementPtr c, client_class_->listValue()) {
+            string cclass = c->stringValue();
+            if (!cclass.empty()) {
+                pool_->allowClientClass(cclass);
+            }
         }
     }
         
index e195cd4bad33a934fef07c21fe8efa36df84007b..45d30ddb7444984950bd145617e32a8a54e1ce08 100644 (file)
@@ -651,8 +651,14 @@ private:
     /// A storage for pool specific option values.
     CfgOptionPtr options_;
 
+    /// @brief User context (optional, may be null)
+    ///
+    /// User context is arbitrary user data, to be used by hooks.
     isc::data::ConstElementPtr user_context_;
 
+    /// @brief List of client classes a client has to be belong to to use this pd-pool
+    ///
+    /// If empty, everyone is allowed. This is a white-list
     isc::data::ConstElementPtr client_class_;
 
 };
index dc169b0baebbc2ff42d20fa9e040a1074484e81e..f648a0e98ad6a6dd4364e381b1692c4d64d593ce 100644 (file)
@@ -111,11 +111,12 @@ Pool::toElement() const {
 
     // Set client-class
     const ClientClasses& cclasses = getClientClasses();
-    if (cclasses.size() > 1) {
-        isc_throw(ToElementError, "client-class has too many items: "
-                  << cclasses.size());
-    } else if (!cclasses.empty()) {
-        map->set("client-class", Element::create(*cclasses.cbegin()));
+    if (!cclasses.empty()) {
+        ElementPtr list = Element::createList();
+        for (auto c : cclasses) {
+            list->add(Element::create(c));
+        }
+        map->set("client-classes", list);
     }
 
     return (map);
@@ -340,6 +341,7 @@ Pool6::toElement() const {
                 isc_throw(ToElementError, "invalid prefix range "
                           << prefix.toText() << "-" << last.toText());
             }
+            map->set("prefix-len", Element::create(prefix_len));
 
             // Set delegated-len
             uint8_t len = getLength();
@@ -354,10 +356,13 @@ Pool6::toElement() const {
                 uint8_t xlen = xopt->getExcludedPrefixLength();
                 map->set("excluded-prefix-len",
                          Element::create(static_cast<int>(xlen)));
-            } else {
-                map->set("excluded-prefix", Element::create(std::string("::")));
-                map->set("excluded-prefix-len", Element::create(0));
             }
+            // Let's not insert empty excluded-prefix values. If we ever
+            // decide to insert it after all, here's the code to do it:
+            // else {
+            //   map->set("excluded-prefix", Element::create(std::string("::")));
+            //   map->set("excluded-prefix-len", Element::create(0));
+            // }
 
             break;
         }
index 46423f6fa873d990b3c7955d816f3f068dd185c3..bba123cfcf214cb30ac353ee14b5a5942c9c9752 100644 (file)
@@ -100,8 +100,7 @@ public:
     /// @brief Checks whether this pool supports client that belongs to
     /// specified classes.
     ///
-    /// @todo: currently doing the same than network which
-    /// is known to be improved.
+    /// @todo: currently doing the same as network which needs improving.
     ///
     /// @param client_classes list of all classes the client belongs to
     /// @return true if client can be supported, false otherwise
@@ -204,6 +203,9 @@ protected:
 
     /// @brief Optional definition of a client class
     ///
+    /// If empty, all classes are allowed. If non-empty, only those listed
+    /// here are allowed.
+    ///
     /// @ref Network::white_list_
     ClientClasses white_list_;
 
index 3b27412280167372c7c8bdc1514b46b4962b5b64..f2be770b3bc4e9dbdd43ab57904e055616c69010 100644 (file)
@@ -707,97 +707,18 @@ Subnet6::toElement() const {
     // Set pools
     const PoolCollection& pools = getPools(Lease::TYPE_NA);
     ElementPtr pool_list = Element::createList();
-    for (PoolCollection::const_iterator pool = pools.cbegin();
-         pool != pools.cend(); ++pool) {
-        // Prepare the map for a pool (@todo move this code to pool.cc)
-        ElementPtr pool_map = Element::createMap();
-        // Set user-context
-        (*pool)->contextToElement(pool_map);
-        // Set pool
-        const IOAddress& first = (*pool)->getFirstAddress();
-        const IOAddress& last = (*pool)->getLastAddress();
-        std::string range = first.toText() + "-" + last.toText();
-        // Try to output a prefix (vs a range)
-        int prefix_len = prefixLengthFromRange(first, last);
-        if (prefix_len >= 0) {
-            std::ostringstream oss;
-            oss << first.toText() << "/" << prefix_len;
-            range = oss.str();
-        }
-        pool_map->set("pool", Element::create(range));
-        // Set pool options
-        ConstCfgOptionPtr opts = (*pool)->getCfgOption();
-        pool_map->set("option-data", opts->toElement());
-        // Set client-class
-        const ClientClasses& cclasses = (*pool)->getClientClasses();
-        if (cclasses.size() > 1) {
-            isc_throw(ToElementError, "client-class has too many items: "
-                      << cclasses.size());
-        } else if (!cclasses.empty()) {
-            pool_map->set("client-class", Element::create(*cclasses.cbegin()));
-        }
-        // Push on the pool list
-        pool_list->add(pool_map);
+    for (auto pool : pools) {
+        pool_list->add(pool->toElement());
     }
     map->set("pools", pool_list);
+
     // Set pd-pools
     const PoolCollection& pdpools = getPools(Lease::TYPE_PD);
     ElementPtr pdpool_list = Element::createList();
-    for (PoolCollection::const_iterator pool = pdpools.cbegin();
-         pool != pdpools.cend(); ++pool) {
-        // Get it as a Pool6 (@todo move this code to pool.cc)
-        const Pool6* pdpool = dynamic_cast<Pool6*>(pool->get());
-        if (!pdpool) {
-            isc_throw(ToElementError, "invalid pd-pool pointer");
-        }
-        // Prepare the map for a pd-pool
-        ElementPtr pool_map = Element::createMap();
-        // Set user-context
-        pdpool->contextToElement(pool_map);
-        // Set prefix
-        const IOAddress& prefix = pdpool->getFirstAddress();
-        pool_map->set("prefix", Element::create(prefix.toText()));
-        // Set prefix-len (get it from min - max)
-        const IOAddress& last = pdpool->getLastAddress();
-        int prefix_len = prefixLengthFromRange(prefix, last);
-        if (prefix_len < 0) {
-            // The pool is bad: give up
-            isc_throw(ToElementError, "invalid prefix range "
-                      << prefix.toText() << "-" << last.toText());
-        }
-        pool_map->set("prefix-len", Element::create(prefix_len));
-        // Set delegated-len
-        uint8_t len = pdpool->getLength();
-        pool_map->set("delegated-len",
-                      Element::create(static_cast<int>(len)));
-
-        // Set excluded prefix
-        const Option6PDExcludePtr& xopt =
-            pdpool->getPrefixExcludeOption();
-        if (xopt) {
-            const IOAddress& xprefix =
-                xopt->getExcludedPrefix(prefix, len);
-            pool_map->set("excluded-prefix",
-                          Element::create(xprefix.toText()));
-            uint8_t xlen = xopt->getExcludedPrefixLength();
-            pool_map->set("excluded-prefix-len",
-                          Element::create(static_cast<int>(xlen)));
-        }
-
-        // Set pool options
-        ConstCfgOptionPtr opts = pdpool->getCfgOption();
-        pool_map->set("option-data", opts->toElement());
-        // Set client-class
-        const ClientClasses& cclasses = pdpool->getClientClasses();
-        if (cclasses.size() > 1) {
-            isc_throw(ToElementError, "client-class has too many items: "
-                      << cclasses.size());
-        } else if (!cclasses.empty()) {
-            pool_map->set("client-class", Element::create(*cclasses.cbegin()));
-        }
-        // Push on the pool list
-        pdpool_list->add(pool_map);
+    for (auto pool : pdpools) {
+        pdpool_list->add(pool->toElement());
     }
+
     map->set("pd-pools", pdpool_list);
 
     return (map);
index fb2f22a554c23768b213ca697a1cc289a42f1c49..f4aa2c9f9db8d9f0bb390fe38823347c4e441e01 100644 (file)
@@ -858,7 +858,7 @@ TEST(CfgSubnets4Test, unparsePool) {
         "        },{\n"
         "            \"option-data\": [ ],\n"
         "            \"pool\": \"192.0.2.64/26\"\n,"
-        "            \"client-class\": \"bar\",\n"
+        "            \"client-classes\": [ \"bar\" ],\n"
         "            \"user-context\": { \"foo\": \"bar\" }\n"
         "        }\n"
         "    ]\n"
index 5565387d262052d652f5140c932b37ea796887fc..cd9be4f0b5d9b647696e8bc1a661d1655bccb8dc 100644 (file)
@@ -542,7 +542,7 @@ TEST(CfgSubnets6Test, unparsePool) {
         "            \"option-data\": [ ]\n"
         "        },{\n"
         "            \"pool\": \"2001:db8:1:1::/64\",\n"
-        "            \"client-class\": \"bar\",\n"
+        "            \"client-classes\": [ \"bar\" ],\n"
         "            \"user-context\": { \"foo\": \"bar\" },\n"
         "            \"option-data\": [ ]\n"
         "        }\n"
@@ -601,7 +601,7 @@ TEST(CfgSubnets6Test, unparsePdPool) {
         "            \"excluded-prefix\": \"2001:db8:3::\",\n"
         "            \"excluded-prefix-len\": 64,\n"
         "            \"option-data\": [ ],\n"
-        "            \"client-class\": \"bar\"\n"
+        "            \"client-classes\": [ \"bar\" ]\n"
         "        }\n"
         "    ],\n"
         "    \"option-data\": [ ]\n"