From: Francis Dupont Date: Wed, 20 Sep 2017 20:48:58 +0000 (+0200) Subject: [5073a] Main code finished X-Git-Tag: trac5363_base~6^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=743182ec976d6e751d3025c680498cc9486d8347;p=thirdparty%2Fkea.git [5073a] Main code finished --- diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index b4d61b3b22..17623639a8 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -2858,9 +2858,9 @@ Dhcpv4Srv::deferredUnpack(Pkt4Ptr& query) if (!def) { def = LibDHCP::getRuntimeOptionDef(DHCP4_OPTION_SPACE, code); } - // Option 43 has a last resort definition - if ((code == DHO_VENDOR_ENCAPSULATED_OPTIONS) && !def) { - def = LibDHCP::last_resort_option43_def; + // Finish by last resort definition + if (!def) { + def = LibDHCP::getLastResortOptionDef(DHCP4_OPTION_SPACE, code); } // If not defined go to the next option if (!def) { diff --git a/src/bin/dhcp4/tests/config_parser_unittest.cc b/src/bin/dhcp4/tests/config_parser_unittest.cc index 19a4fecc78..ba548bcfff 100644 --- a/src/bin/dhcp4/tests/config_parser_unittest.cc +++ b/src/bin/dhcp4/tests/config_parser_unittest.cc @@ -3179,7 +3179,6 @@ TEST_F(Dhcp4ParserTest, domainSearchOption) { " domain-search option")); } -#if 0 // The goal of this test is to verify that the standard option can // be configured to encapsulate multiple other options. TEST_F(Dhcp4ParserTest, stdOptionDataEncapsulate) { @@ -3430,7 +3429,7 @@ TEST_F(Dhcp4ParserTest, vendorOptionsCsv) { CfgMgr::instance().getStagingCfg()->getCfgOption()->get(5678, 100); ASSERT_FALSE(desc2.option_); } -#endif + // Tests of the hooks libraries configuration. All tests have the pre- // condition (checked in the test fixture's SetUp() method) that no hooks diff --git a/src/bin/dhcp4/tests/get_config_unittest.cc b/src/bin/dhcp4/tests/get_config_unittest.cc index fdd8d3ac67..c47c9d7810 100644 --- a/src/bin/dhcp4/tests/get_config_unittest.cc +++ b/src/bin/dhcp4/tests/get_config_unittest.cc @@ -881,8 +881,34 @@ const char* EXTRACTED_CONFIGS[] = { // CONFIGURATION 32 "{\n" " \"interfaces-config\": {\n" -" \"interfaces\": [ \"eth0\", \"eth1\" ]\n" +" \"interfaces\": [ \"*\" ]\n" " },\n" +" \"option-data\": [\n" +" {\n" +" \"data\": \"1234\",\n" +" \"name\": \"foo\",\n" +" \"space\": \"vendor-encapsulated-options-space\"\n" +" },\n" +" {\n" +" \"data\": \"192.168.2.1\",\n" +" \"name\": \"foo2\",\n" +" \"space\": \"vendor-encapsulated-options-space\"\n" +" }\n" +" ],\n" +" \"option-def\": [\n" +" {\n" +" \"code\": 1,\n" +" \"name\": \"foo\",\n" +" \"space\": \"vendor-encapsulated-options-space\",\n" +" \"type\": \"uint32\"\n" +" },\n" +" {\n" +" \"code\": 2,\n" +" \"name\": \"foo2\",\n" +" \"space\": \"vendor-encapsulated-options-space\",\n" +" \"type\": \"ipv4-address\"\n" +" }\n" +" ],\n" " \"rebind-timer\": 2000,\n" " \"renew-timer\": 1000,\n" " \"valid-lifetime\": 4000\n" @@ -890,13 +916,143 @@ const char* EXTRACTED_CONFIGS[] = { // CONFIGURATION 33 "{\n" " \"interfaces-config\": {\n" +" \"interfaces\": [ \"*\" ]\n" +" },\n" +" \"option-data\": [\n" +" {\n" +" \"csv-format\": false,\n" +" \"name\": \"vendor-encapsulated-options\"\n" +" },\n" +" {\n" +" \"data\": \"1234\",\n" +" \"name\": \"foo\",\n" +" \"space\": \"vendor-encapsulated-options-space\"\n" +" },\n" +" {\n" +" \"code\": 2,\n" +" \"csv-format\": true,\n" +" \"data\": \"192.168.2.1\",\n" +" \"name\": \"foo2\",\n" +" \"space\": \"vendor-encapsulated-options-space\"\n" +" }\n" +" ],\n" +" \"option-def\": [\n" +" {\n" +" \"code\": 1,\n" +" \"name\": \"foo\",\n" +" \"space\": \"vendor-encapsulated-options-space\",\n" +" \"type\": \"uint32\"\n" +" },\n" +" {\n" +" \"code\": 2,\n" +" \"name\": \"foo2\",\n" +" \"space\": \"vendor-encapsulated-options-space\",\n" +" \"type\": \"ipv4-address\"\n" +" }\n" +" ],\n" +" \"rebind-timer\": 2000,\n" +" \"renew-timer\": 1000,\n" +" \"subnet4\": [\n" +" {\n" +" \"pools\": [\n" +" {\n" +" \"pool\": \"192.0.2.1 - 192.0.2.100\"\n" +" }\n" +" ],\n" +" \"subnet\": \"192.0.2.0/24\"\n" +" }\n" +" ],\n" +" \"valid-lifetime\": 3000\n" +" }\n", + // CONFIGURATION 34 +"{\n" +" \"interfaces-config\": {\n" +" \"interfaces\": [ \"*\" ]\n" +" },\n" +" \"option-data\": [\n" +" {\n" +" \"code\": 100,\n" +" \"csv-format\": false,\n" +" \"data\": \"ABCDEF0105\",\n" +" \"name\": \"option-one\",\n" +" \"space\": \"vendor-4491\"\n" +" },\n" +" {\n" +" \"code\": 100,\n" +" \"csv-format\": false,\n" +" \"data\": \"1234\",\n" +" \"name\": \"option-two\",\n" +" \"space\": \"vendor-1234\"\n" +" }\n" +" ],\n" +" \"rebind-timer\": 2000,\n" +" \"renew-timer\": 1000,\n" +" \"subnet4\": [\n" +" {\n" +" \"pools\": [\n" +" {\n" +" \"pool\": \"192.0.2.1-192.0.2.10\"\n" +" }\n" +" ],\n" +" \"subnet\": \"192.0.2.0/24\"\n" +" }\n" +" ],\n" +" \"valid-lifetime\": 4000\n" +" }\n", + // CONFIGURATION 35 +"{\n" +" \"interfaces-config\": {\n" +" \"interfaces\": [ \"*\" ]\n" +" },\n" +" \"option-data\": [\n" +" {\n" +" \"code\": 100,\n" +" \"data\": \"this is a string vendor-opt\",\n" +" \"name\": \"foo\",\n" +" \"space\": \"vendor-4491\"\n" +" }\n" +" ],\n" +" \"option-def\": [\n" +" {\n" +" \"code\": 100,\n" +" \"name\": \"foo\",\n" +" \"space\": \"vendor-4491\",\n" +" \"type\": \"string\"\n" +" }\n" +" ],\n" +" \"rebind-timer\": 2000,\n" +" \"renew-timer\": 1000,\n" +" \"subnet4\": [\n" +" {\n" +" \"pools\": [\n" +" {\n" +" \"pool\": \"192.0.2.1 - 192.0.2.100\"\n" +" }\n" +" ],\n" +" \"subnet\": \"192.0.2.0/24\"\n" +" }\n" +" ],\n" +" \"valid-lifetime\": 4000\n" +" }\n", + // CONFIGURATION 36 +"{\n" +" \"interfaces-config\": {\n" +" \"interfaces\": [ \"eth0\", \"eth1\" ]\n" +" },\n" +" \"rebind-timer\": 2000,\n" +" \"renew-timer\": 1000,\n" +" \"valid-lifetime\": 4000\n" +" }\n", + // CONFIGURATION 37 +"{\n" +" \"interfaces-config\": {\n" " \"interfaces\": [ \"eth0\", \"*\", \"eth1\" ]\n" " },\n" " \"rebind-timer\": 2000,\n" " \"renew-timer\": 1000,\n" " \"valid-lifetime\": 4000\n" " }\n", - // CONFIGURATION 34 + // CONFIGURATION 38 "{\n" " \"dhcp-ddns\": {\n" " \"always-include-fqdn\": true,\n" @@ -931,7 +1087,7 @@ const char* EXTRACTED_CONFIGS[] = { " ],\n" " \"valid-lifetime\": 4000\n" " }\n", - // CONFIGURATION 35 + // CONFIGURATION 39 "{\n" " \"interfaces-config\": {\n" " \"interfaces\": [ \"*\" ]\n" @@ -956,7 +1112,7 @@ const char* EXTRACTED_CONFIGS[] = { " ],\n" " \"valid-lifetime\": 4000\n" " }\n", - // CONFIGURATION 36 + // CONFIGURATION 40 "{\n" " \"interfaces-config\": {\n" " \"interfaces\": [ \"*\" ]\n" @@ -1054,7 +1210,7 @@ const char* EXTRACTED_CONFIGS[] = { " ],\n" " \"valid-lifetime\": 4000\n" " }\n", - // CONFIGURATION 37 + // CONFIGURATION 41 "{\n" " \"interfaces-config\": {\n" " \"interfaces\": [ \"*\" ]\n" @@ -1095,7 +1251,7 @@ const char* EXTRACTED_CONFIGS[] = { " ],\n" " \"valid-lifetime\": 4000\n" " }\n", - // CONFIGURATION 38 + // CONFIGURATION 42 "{\n" " \"rebind-timer\": 2000,\n" " \"renew-timer\": 1000,\n" @@ -1138,21 +1294,21 @@ const char* EXTRACTED_CONFIGS[] = { " ],\n" " \"valid-lifetime\": 4000\n" " }\n", - // CONFIGURATION 39 + // CONFIGURATION 43 "{\n" " \"interfaces-config\": {\n" " \"interfaces\": [ \"*\" ]\n" " },\n" " \"subnet4\": [ ]\n" " }\n", - // CONFIGURATION 40 + // CONFIGURATION 44 "{\n" " \"interfaces-config\": {\n" " \"interfaces\": [ \"*\" ]\n" " },\n" " \"subnet4\": [ ]\n" " }\n", - // CONFIGURATION 41 + // CONFIGURATION 45 "{\n" " \"decline-probation-period\": 12345,\n" " \"interfaces-config\": {\n" @@ -1160,7 +1316,7 @@ const char* EXTRACTED_CONFIGS[] = { " },\n" " \"subnet4\": [ ]\n" " }\n", - // CONFIGURATION 42 + // CONFIGURATION 46 "{\n" " \"expired-leases-processing\": {\n" " \"flush-reclaimed-timer-wait-time\": 35,\n" @@ -1175,7 +1331,7 @@ const char* EXTRACTED_CONFIGS[] = { " },\n" " \"subnet4\": [ ]\n" " }\n", - // CONFIGURATION 43 + // CONFIGURATION 47 "{\n" " \"interfaces-config\": {\n" " \"interfaces\": [ \"*\" ]\n" @@ -1194,7 +1350,7 @@ const char* EXTRACTED_CONFIGS[] = { " ],\n" " \"valid-lifetime\": 4000\n" " }\n", - // CONFIGURATION 44 + // CONFIGURATION 48 "{\n" " \"interfaces-config\": {\n" " \"interfaces\": [ \"*\" ]\n" @@ -1214,7 +1370,7 @@ const char* EXTRACTED_CONFIGS[] = { " ],\n" " \"valid-lifetime\": 4000\n" " }\n", - // CONFIGURATION 45 + // CONFIGURATION 49 "{\n" " \"interfaces-config\": {\n" " \"interfaces\": [ \"*\" ]\n" @@ -1234,7 +1390,7 @@ const char* EXTRACTED_CONFIGS[] = { " ],\n" " \"valid-lifetime\": 4000\n" " }\n", - // CONFIGURATION 46 + // CONFIGURATION 50 "{\n" " \"interfaces-config\": {\n" " \"interfaces\": [ \"*\" ]\n" @@ -1255,7 +1411,7 @@ const char* EXTRACTED_CONFIGS[] = { " ],\n" " \"valid-lifetime\": 4000\n" " }\n", - // CONFIGURATION 47 + // CONFIGURATION 51 "{\n" " \"interfaces-config\": {\n" " \"interfaces\": [ \"*\" ]\n" @@ -1275,7 +1431,7 @@ const char* EXTRACTED_CONFIGS[] = { " ],\n" " \"valid-lifetime\": 4000\n" " }\n", - // CONFIGURATION 48 + // CONFIGURATION 52 "{\n" " \"client-classes\": [\n" " {\n" @@ -1305,7 +1461,7 @@ const char* EXTRACTED_CONFIGS[] = { " ],\n" " \"valid-lifetime\": 4000\n" " }\n", - // CONFIGURATION 49 + // CONFIGURATION 53 "{\n" " \"interfaces-config\": {\n" " \"interfaces\": [ \"*\" ]\n" @@ -1324,7 +1480,7 @@ const char* EXTRACTED_CONFIGS[] = { " ],\n" " \"valid-lifetime\": 4000\n" " }\n", - // CONFIGURATION 50 + // CONFIGURATION 54 "{\n" " \"interfaces-config\": {\n" " \"interfaces\": [ \"*\" ]\n" @@ -1344,7 +1500,7 @@ const char* EXTRACTED_CONFIGS[] = { " ],\n" " \"valid-lifetime\": 4000\n" " }\n", - // CONFIGURATION 51 + // CONFIGURATION 55 "{\n" " \"interfaces-config\": {\n" " \"interfaces\": [ \"*\" ]\n" @@ -1368,7 +1524,7 @@ const char* EXTRACTED_CONFIGS[] = { " ],\n" " \"valid-lifetime\": 4000\n" " }\n", - // CONFIGURATION 52 + // CONFIGURATION 56 "{\n" " \"interfaces-config\": {\n" " \"interfaces\": [ \"*\" ]\n" @@ -3938,14 +4094,50 @@ const char* UNPARSED_CONFIGS[] = { " \"hooks-libraries\": [ ],\n" " \"host-reservation-identifiers\": [ \"hw-address\", \"duid\", \"circuit-id\", \"client-id\" ],\n" " \"interfaces-config\": {\n" -" \"interfaces\": [ \"eth0\", \"eth1\" ],\n" +" \"interfaces\": [ \"*\" ],\n" " \"re-detect\": false\n" " },\n" " \"lease-database\": {\n" " \"type\": \"memfile\"\n" " },\n" -" \"option-data\": [ ],\n" -" \"option-def\": [ ],\n" +" \"option-data\": [\n" +" {\n" +" \"always-send\": false,\n" +" \"code\": 1,\n" +" \"csv-format\": true,\n" +" \"data\": \"1234\",\n" +" \"name\": \"foo\",\n" +" \"space\": \"vendor-encapsulated-options-space\"\n" +" },\n" +" {\n" +" \"always-send\": false,\n" +" \"code\": 2,\n" +" \"csv-format\": true,\n" +" \"data\": \"192.168.2.1\",\n" +" \"name\": \"foo2\",\n" +" \"space\": \"vendor-encapsulated-options-space\"\n" +" }\n" +" ],\n" +" \"option-def\": [\n" +" {\n" +" \"array\": false,\n" +" \"code\": 1,\n" +" \"encapsulate\": \"\",\n" +" \"name\": \"foo\",\n" +" \"record-types\": \"\",\n" +" \"space\": \"vendor-encapsulated-options-space\",\n" +" \"type\": \"uint32\"\n" +" },\n" +" {\n" +" \"array\": false,\n" +" \"code\": 2,\n" +" \"encapsulate\": \"\",\n" +" \"name\": \"foo2\",\n" +" \"record-types\": \"\",\n" +" \"space\": \"vendor-encapsulated-options-space\",\n" +" \"type\": \"ipv4-address\"\n" +" }\n" +" ],\n" " \"shared-networks\": [ ],\n" " \"subnet4\": [ ]\n" " }\n", @@ -3981,49 +4173,374 @@ const char* UNPARSED_CONFIGS[] = { " \"hooks-libraries\": [ ],\n" " \"host-reservation-identifiers\": [ \"hw-address\", \"duid\", \"circuit-id\", \"client-id\" ],\n" " \"interfaces-config\": {\n" -" \"interfaces\": [ \"*\", \"eth0\", \"eth1\" ],\n" -" \"re-detect\": false\n" -" },\n" -" \"lease-database\": {\n" -" \"type\": \"memfile\"\n" -" },\n" -" \"option-data\": [ ],\n" -" \"option-def\": [ ],\n" -" \"shared-networks\": [ ],\n" -" \"subnet4\": [ ]\n" -" }\n", - // CONFIGURATION 34 -"{\n" -" \"decline-probation-period\": 86400,\n" -" \"dhcp-ddns\": {\n" -" \"always-include-fqdn\": true,\n" -" \"enable-updates\": true,\n" -" \"generated-prefix\": \"test.prefix\",\n" -" \"max-queue-size\": 2048,\n" -" \"ncr-format\": \"JSON\",\n" -" \"ncr-protocol\": \"UDP\",\n" -" \"override-client-update\": true,\n" -" \"override-no-update\": true,\n" -" \"qualifying-suffix\": \"test.suffix.\",\n" -" \"replace-client-name\": \"when-present\",\n" -" \"sender-ip\": \"192.168.2.2\",\n" -" \"sender-port\": 778,\n" -" \"server-ip\": \"192.168.2.1\",\n" -" \"server-port\": 777\n" -" },\n" -" \"dhcp4o6-port\": 0,\n" -" \"echo-client-id\": true,\n" -" \"expired-leases-processing\": {\n" -" \"flush-reclaimed-timer-wait-time\": 25,\n" -" \"hold-reclaimed-time\": 3600,\n" -" \"max-reclaim-leases\": 100,\n" -" \"max-reclaim-time\": 250,\n" -" \"reclaim-timer-wait-time\": 10,\n" -" \"unwarned-reclaim-cycles\": 5\n" -" },\n" -" \"hooks-libraries\": [ ],\n" -" \"host-reservation-identifiers\": [ \"hw-address\", \"duid\", \"circuit-id\", \"client-id\" ],\n" -" \"interfaces-config\": {\n" +" \"interfaces\": [ \"*\" ],\n" +" \"re-detect\": false\n" +" },\n" +" \"lease-database\": {\n" +" \"type\": \"memfile\"\n" +" },\n" +" \"option-data\": [\n" +" {\n" +" \"always-send\": false,\n" +" \"code\": 43,\n" +" \"csv-format\": false,\n" +" \"data\": \"0104000004D20204C0A80201\",\n" +" \"name\": \"vendor-encapsulated-options\",\n" +" \"space\": \"dhcp4\"\n" +" },\n" +" {\n" +" \"always-send\": false,\n" +" \"code\": 1,\n" +" \"csv-format\": true,\n" +" \"data\": \"1234\",\n" +" \"name\": \"foo\",\n" +" \"space\": \"vendor-encapsulated-options-space\"\n" +" },\n" +" {\n" +" \"always-send\": false,\n" +" \"code\": 2,\n" +" \"csv-format\": true,\n" +" \"data\": \"192.168.2.1\",\n" +" \"name\": \"foo2\",\n" +" \"space\": \"vendor-encapsulated-options-space\"\n" +" }\n" +" ],\n" +" \"option-def\": [\n" +" {\n" +" \"array\": false,\n" +" \"code\": 1,\n" +" \"encapsulate\": \"\",\n" +" \"name\": \"foo\",\n" +" \"record-types\": \"\",\n" +" \"space\": \"vendor-encapsulated-options-space\",\n" +" \"type\": \"uint32\"\n" +" },\n" +" {\n" +" \"array\": false,\n" +" \"code\": 2,\n" +" \"encapsulate\": \"\",\n" +" \"name\": \"foo2\",\n" +" \"record-types\": \"\",\n" +" \"space\": \"vendor-encapsulated-options-space\",\n" +" \"type\": \"ipv4-address\"\n" +" }\n" +" ],\n" +" \"shared-networks\": [ ],\n" +" \"subnet4\": [\n" +" {\n" +" \"4o6-interface\": \"\",\n" +" \"4o6-interface-id\": \"\",\n" +" \"4o6-subnet\": \"\",\n" +" \"id\": 1,\n" +" \"match-client-id\": true,\n" +" \"next-server\": \"0.0.0.0\",\n" +" \"option-data\": [ ],\n" +" \"pools\": [\n" +" {\n" +" \"option-data\": [ ],\n" +" \"pool\": \"192.0.2.1-192.0.2.100\"\n" +" }\n" +" ],\n" +" \"rebind-timer\": 2000,\n" +" \"relay\": {\n" +" \"ip-address\": \"0.0.0.0\"\n" +" },\n" +" \"renew-timer\": 1000,\n" +" \"reservation-mode\": \"all\",\n" +" \"reservations\": [ ],\n" +" \"subnet\": \"192.0.2.0/24\",\n" +" \"valid-lifetime\": 3000\n" +" }\n" +" ]\n" +" }\n", + // CONFIGURATION 34 +"{\n" +" \"decline-probation-period\": 86400,\n" +" \"dhcp-ddns\": {\n" +" \"always-include-fqdn\": false,\n" +" \"enable-updates\": false,\n" +" \"generated-prefix\": \"myhost\",\n" +" \"max-queue-size\": 1024,\n" +" \"ncr-format\": \"JSON\",\n" +" \"ncr-protocol\": \"UDP\",\n" +" \"override-client-update\": false,\n" +" \"override-no-update\": false,\n" +" \"qualifying-suffix\": \"\",\n" +" \"replace-client-name\": \"never\",\n" +" \"sender-ip\": \"0.0.0.0\",\n" +" \"sender-port\": 0,\n" +" \"server-ip\": \"127.0.0.1\",\n" +" \"server-port\": 53001\n" +" },\n" +" \"dhcp4o6-port\": 0,\n" +" \"echo-client-id\": true,\n" +" \"expired-leases-processing\": {\n" +" \"flush-reclaimed-timer-wait-time\": 25,\n" +" \"hold-reclaimed-time\": 3600,\n" +" \"max-reclaim-leases\": 100,\n" +" \"max-reclaim-time\": 250,\n" +" \"reclaim-timer-wait-time\": 10,\n" +" \"unwarned-reclaim-cycles\": 5\n" +" },\n" +" \"hooks-libraries\": [ ],\n" +" \"host-reservation-identifiers\": [ \"hw-address\", \"duid\", \"circuit-id\", \"client-id\" ],\n" +" \"interfaces-config\": {\n" +" \"interfaces\": [ \"*\" ],\n" +" \"re-detect\": false\n" +" },\n" +" \"lease-database\": {\n" +" \"type\": \"memfile\"\n" +" },\n" +" \"option-data\": [\n" +" {\n" +" \"always-send\": false,\n" +" \"code\": 100,\n" +" \"csv-format\": false,\n" +" \"data\": \"1234\",\n" +" \"space\": \"vendor-1234\"\n" +" },\n" +" {\n" +" \"always-send\": false,\n" +" \"code\": 100,\n" +" \"csv-format\": false,\n" +" \"data\": \"ABCDEF0105\",\n" +" \"space\": \"vendor-4491\"\n" +" }\n" +" ],\n" +" \"option-def\": [ ],\n" +" \"shared-networks\": [ ],\n" +" \"subnet4\": [\n" +" {\n" +" \"4o6-interface\": \"\",\n" +" \"4o6-interface-id\": \"\",\n" +" \"4o6-subnet\": \"\",\n" +" \"id\": 1,\n" +" \"match-client-id\": true,\n" +" \"next-server\": \"0.0.0.0\",\n" +" \"option-data\": [ ],\n" +" \"pools\": [\n" +" {\n" +" \"option-data\": [ ],\n" +" \"pool\": \"192.0.2.1-192.0.2.10\"\n" +" }\n" +" ],\n" +" \"rebind-timer\": 2000,\n" +" \"relay\": {\n" +" \"ip-address\": \"0.0.0.0\"\n" +" },\n" +" \"renew-timer\": 1000,\n" +" \"reservation-mode\": \"all\",\n" +" \"reservations\": [ ],\n" +" \"subnet\": \"192.0.2.0/24\",\n" +" \"valid-lifetime\": 4000\n" +" }\n" +" ]\n" +" }\n", + // CONFIGURATION 35 +"{\n" +" \"decline-probation-period\": 86400,\n" +" \"dhcp-ddns\": {\n" +" \"always-include-fqdn\": false,\n" +" \"enable-updates\": false,\n" +" \"generated-prefix\": \"myhost\",\n" +" \"max-queue-size\": 1024,\n" +" \"ncr-format\": \"JSON\",\n" +" \"ncr-protocol\": \"UDP\",\n" +" \"override-client-update\": false,\n" +" \"override-no-update\": false,\n" +" \"qualifying-suffix\": \"\",\n" +" \"replace-client-name\": \"never\",\n" +" \"sender-ip\": \"0.0.0.0\",\n" +" \"sender-port\": 0,\n" +" \"server-ip\": \"127.0.0.1\",\n" +" \"server-port\": 53001\n" +" },\n" +" \"dhcp4o6-port\": 0,\n" +" \"echo-client-id\": true,\n" +" \"expired-leases-processing\": {\n" +" \"flush-reclaimed-timer-wait-time\": 25,\n" +" \"hold-reclaimed-time\": 3600,\n" +" \"max-reclaim-leases\": 100,\n" +" \"max-reclaim-time\": 250,\n" +" \"reclaim-timer-wait-time\": 10,\n" +" \"unwarned-reclaim-cycles\": 5\n" +" },\n" +" \"hooks-libraries\": [ ],\n" +" \"host-reservation-identifiers\": [ \"hw-address\", \"duid\", \"circuit-id\", \"client-id\" ],\n" +" \"interfaces-config\": {\n" +" \"interfaces\": [ \"*\" ],\n" +" \"re-detect\": false\n" +" },\n" +" \"lease-database\": {\n" +" \"type\": \"memfile\"\n" +" },\n" +" \"option-data\": [\n" +" {\n" +" \"always-send\": false,\n" +" \"code\": 100,\n" +" \"csv-format\": true,\n" +" \"data\": \"this is a string vendor-opt\",\n" +" \"name\": \"foo\",\n" +" \"space\": \"vendor-4491\"\n" +" }\n" +" ],\n" +" \"option-def\": [\n" +" {\n" +" \"array\": false,\n" +" \"code\": 100,\n" +" \"encapsulate\": \"\",\n" +" \"name\": \"foo\",\n" +" \"record-types\": \"\",\n" +" \"space\": \"vendor-4491\",\n" +" \"type\": \"string\"\n" +" }\n" +" ],\n" +" \"shared-networks\": [ ],\n" +" \"subnet4\": [\n" +" {\n" +" \"4o6-interface\": \"\",\n" +" \"4o6-interface-id\": \"\",\n" +" \"4o6-subnet\": \"\",\n" +" \"id\": 1,\n" +" \"match-client-id\": true,\n" +" \"next-server\": \"0.0.0.0\",\n" +" \"option-data\": [ ],\n" +" \"pools\": [\n" +" {\n" +" \"option-data\": [ ],\n" +" \"pool\": \"192.0.2.1-192.0.2.100\"\n" +" }\n" +" ],\n" +" \"rebind-timer\": 2000,\n" +" \"relay\": {\n" +" \"ip-address\": \"0.0.0.0\"\n" +" },\n" +" \"renew-timer\": 1000,\n" +" \"reservation-mode\": \"all\",\n" +" \"reservations\": [ ],\n" +" \"subnet\": \"192.0.2.0/24\",\n" +" \"valid-lifetime\": 4000\n" +" }\n" +" ]\n" +" }\n", + // CONFIGURATION 36 +"{\n" +" \"decline-probation-period\": 86400,\n" +" \"dhcp-ddns\": {\n" +" \"always-include-fqdn\": false,\n" +" \"enable-updates\": false,\n" +" \"generated-prefix\": \"myhost\",\n" +" \"max-queue-size\": 1024,\n" +" \"ncr-format\": \"JSON\",\n" +" \"ncr-protocol\": \"UDP\",\n" +" \"override-client-update\": false,\n" +" \"override-no-update\": false,\n" +" \"qualifying-suffix\": \"\",\n" +" \"replace-client-name\": \"never\",\n" +" \"sender-ip\": \"0.0.0.0\",\n" +" \"sender-port\": 0,\n" +" \"server-ip\": \"127.0.0.1\",\n" +" \"server-port\": 53001\n" +" },\n" +" \"dhcp4o6-port\": 0,\n" +" \"echo-client-id\": true,\n" +" \"expired-leases-processing\": {\n" +" \"flush-reclaimed-timer-wait-time\": 25,\n" +" \"hold-reclaimed-time\": 3600,\n" +" \"max-reclaim-leases\": 100,\n" +" \"max-reclaim-time\": 250,\n" +" \"reclaim-timer-wait-time\": 10,\n" +" \"unwarned-reclaim-cycles\": 5\n" +" },\n" +" \"hooks-libraries\": [ ],\n" +" \"host-reservation-identifiers\": [ \"hw-address\", \"duid\", \"circuit-id\", \"client-id\" ],\n" +" \"interfaces-config\": {\n" +" \"interfaces\": [ \"eth0\", \"eth1\" ],\n" +" \"re-detect\": false\n" +" },\n" +" \"lease-database\": {\n" +" \"type\": \"memfile\"\n" +" },\n" +" \"option-data\": [ ],\n" +" \"option-def\": [ ],\n" +" \"shared-networks\": [ ],\n" +" \"subnet4\": [ ]\n" +" }\n", + // CONFIGURATION 37 +"{\n" +" \"decline-probation-period\": 86400,\n" +" \"dhcp-ddns\": {\n" +" \"always-include-fqdn\": false,\n" +" \"enable-updates\": false,\n" +" \"generated-prefix\": \"myhost\",\n" +" \"max-queue-size\": 1024,\n" +" \"ncr-format\": \"JSON\",\n" +" \"ncr-protocol\": \"UDP\",\n" +" \"override-client-update\": false,\n" +" \"override-no-update\": false,\n" +" \"qualifying-suffix\": \"\",\n" +" \"replace-client-name\": \"never\",\n" +" \"sender-ip\": \"0.0.0.0\",\n" +" \"sender-port\": 0,\n" +" \"server-ip\": \"127.0.0.1\",\n" +" \"server-port\": 53001\n" +" },\n" +" \"dhcp4o6-port\": 0,\n" +" \"echo-client-id\": true,\n" +" \"expired-leases-processing\": {\n" +" \"flush-reclaimed-timer-wait-time\": 25,\n" +" \"hold-reclaimed-time\": 3600,\n" +" \"max-reclaim-leases\": 100,\n" +" \"max-reclaim-time\": 250,\n" +" \"reclaim-timer-wait-time\": 10,\n" +" \"unwarned-reclaim-cycles\": 5\n" +" },\n" +" \"hooks-libraries\": [ ],\n" +" \"host-reservation-identifiers\": [ \"hw-address\", \"duid\", \"circuit-id\", \"client-id\" ],\n" +" \"interfaces-config\": {\n" +" \"interfaces\": [ \"*\", \"eth0\", \"eth1\" ],\n" +" \"re-detect\": false\n" +" },\n" +" \"lease-database\": {\n" +" \"type\": \"memfile\"\n" +" },\n" +" \"option-data\": [ ],\n" +" \"option-def\": [ ],\n" +" \"shared-networks\": [ ],\n" +" \"subnet4\": [ ]\n" +" }\n", + // CONFIGURATION 38 +"{\n" +" \"decline-probation-period\": 86400,\n" +" \"dhcp-ddns\": {\n" +" \"always-include-fqdn\": true,\n" +" \"enable-updates\": true,\n" +" \"generated-prefix\": \"test.prefix\",\n" +" \"max-queue-size\": 2048,\n" +" \"ncr-format\": \"JSON\",\n" +" \"ncr-protocol\": \"UDP\",\n" +" \"override-client-update\": true,\n" +" \"override-no-update\": true,\n" +" \"qualifying-suffix\": \"test.suffix.\",\n" +" \"replace-client-name\": \"when-present\",\n" +" \"sender-ip\": \"192.168.2.2\",\n" +" \"sender-port\": 778,\n" +" \"server-ip\": \"192.168.2.1\",\n" +" \"server-port\": 777\n" +" },\n" +" \"dhcp4o6-port\": 0,\n" +" \"echo-client-id\": true,\n" +" \"expired-leases-processing\": {\n" +" \"flush-reclaimed-timer-wait-time\": 25,\n" +" \"hold-reclaimed-time\": 3600,\n" +" \"max-reclaim-leases\": 100,\n" +" \"max-reclaim-time\": 250,\n" +" \"reclaim-timer-wait-time\": 10,\n" +" \"unwarned-reclaim-cycles\": 5\n" +" },\n" +" \"hooks-libraries\": [ ],\n" +" \"host-reservation-identifiers\": [ \"hw-address\", \"duid\", \"circuit-id\", \"client-id\" ],\n" +" \"interfaces-config\": {\n" " \"interfaces\": [ \"*\" ],\n" " \"re-detect\": false\n" " },\n" @@ -4060,7 +4577,7 @@ const char* UNPARSED_CONFIGS[] = { " }\n" " ]\n" " }\n", - // CONFIGURATION 35 + // CONFIGURATION 39 "{\n" " \"decline-probation-period\": 86400,\n" " \"dhcp-ddns\": {\n" @@ -4128,7 +4645,7 @@ const char* UNPARSED_CONFIGS[] = { " }\n" " ]\n" " }\n", - // CONFIGURATION 36 + // CONFIGURATION 40 "{\n" " \"decline-probation-period\": 86400,\n" " \"dhcp-ddns\": {\n" @@ -4347,7 +4864,7 @@ const char* UNPARSED_CONFIGS[] = { " }\n" " ]\n" " }\n", - // CONFIGURATION 37 + // CONFIGURATION 41 "{\n" " \"decline-probation-period\": 86400,\n" " \"dhcp-ddns\": {\n" @@ -4445,7 +4962,7 @@ const char* UNPARSED_CONFIGS[] = { " }\n" " ]\n" " }\n", - // CONFIGURATION 38 + // CONFIGURATION 42 "{\n" " \"decline-probation-period\": 86400,\n" " \"dhcp-ddns\": {\n" @@ -4585,7 +5102,7 @@ const char* UNPARSED_CONFIGS[] = { " }\n" " ]\n" " }\n", - // CONFIGURATION 39 + // CONFIGURATION 43 "{\n" " \"decline-probation-period\": 86400,\n" " \"dhcp-ddns\": {\n" @@ -4628,7 +5145,7 @@ const char* UNPARSED_CONFIGS[] = { " \"shared-networks\": [ ],\n" " \"subnet4\": [ ]\n" " }\n", - // CONFIGURATION 40 + // CONFIGURATION 44 "{\n" " \"decline-probation-period\": 86400,\n" " \"dhcp-ddns\": {\n" @@ -4671,7 +5188,7 @@ const char* UNPARSED_CONFIGS[] = { " \"shared-networks\": [ ],\n" " \"subnet4\": [ ]\n" " }\n", - // CONFIGURATION 41 + // CONFIGURATION 45 "{\n" " \"decline-probation-period\": 12345,\n" " \"dhcp-ddns\": {\n" @@ -4714,7 +5231,7 @@ const char* UNPARSED_CONFIGS[] = { " \"shared-networks\": [ ],\n" " \"subnet4\": [ ]\n" " }\n", - // CONFIGURATION 42 + // CONFIGURATION 46 "{\n" " \"decline-probation-period\": 86400,\n" " \"dhcp-ddns\": {\n" @@ -4757,7 +5274,7 @@ const char* UNPARSED_CONFIGS[] = { " \"shared-networks\": [ ],\n" " \"subnet4\": [ ]\n" " }\n", - // CONFIGURATION 43 + // CONFIGURATION 47 "{\n" " \"decline-probation-period\": 86400,\n" " \"dhcp-ddns\": {\n" @@ -4825,7 +5342,7 @@ const char* UNPARSED_CONFIGS[] = { " }\n" " ]\n" " }\n", - // CONFIGURATION 44 + // CONFIGURATION 48 "{\n" " \"decline-probation-period\": 86400,\n" " \"dhcp-ddns\": {\n" @@ -4893,7 +5410,7 @@ const char* UNPARSED_CONFIGS[] = { " }\n" " ]\n" " }\n", - // CONFIGURATION 45 + // CONFIGURATION 49 "{\n" " \"decline-probation-period\": 86400,\n" " \"dhcp-ddns\": {\n" @@ -4961,7 +5478,7 @@ const char* UNPARSED_CONFIGS[] = { " }\n" " ]\n" " }\n", - // CONFIGURATION 46 + // CONFIGURATION 50 "{\n" " \"decline-probation-period\": 86400,\n" " \"dhcp-ddns\": {\n" @@ -5029,7 +5546,7 @@ const char* UNPARSED_CONFIGS[] = { " }\n" " ]\n" " }\n", - // CONFIGURATION 47 + // CONFIGURATION 51 "{\n" " \"decline-probation-period\": 86400,\n" " \"dhcp-ddns\": {\n" @@ -5097,7 +5614,7 @@ const char* UNPARSED_CONFIGS[] = { " }\n" " ]\n" " }\n", - // CONFIGURATION 48 + // CONFIGURATION 52 "{\n" " \"client-classes\": [\n" " {\n" @@ -5191,7 +5708,7 @@ const char* UNPARSED_CONFIGS[] = { " }\n" " ]\n" " }\n", - // CONFIGURATION 49 + // CONFIGURATION 53 "{\n" " \"decline-probation-period\": 86400,\n" " \"dhcp-ddns\": {\n" @@ -5259,7 +5776,7 @@ const char* UNPARSED_CONFIGS[] = { " }\n" " ]\n" " }\n", - // CONFIGURATION 50 + // CONFIGURATION 54 "{\n" " \"decline-probation-period\": 86400,\n" " \"dhcp-ddns\": {\n" @@ -5328,7 +5845,7 @@ const char* UNPARSED_CONFIGS[] = { " }\n" " ]\n" " }\n", - // CONFIGURATION 51 + // CONFIGURATION 55 "{\n" " \"decline-probation-period\": 86400,\n" " \"dhcp-ddns\": {\n" @@ -5401,7 +5918,7 @@ const char* UNPARSED_CONFIGS[] = { " }\n" " ]\n" " }\n", - // CONFIGURATION 52 + // CONFIGURATION 56 "{\n" " \"decline-probation-period\": 86400,\n" " \"dhcp-ddns\": {\n" diff --git a/src/lib/dhcp/libdhcp++.cc b/src/lib/dhcp/libdhcp++.cc index 6e513992f5..ae430fa487 100644 --- a/src/lib/dhcp/libdhcp++.cc +++ b/src/lib/dhcp/libdhcp++.cc @@ -54,15 +54,15 @@ VendorOptionDefContainers LibDHCP::vendor4_defs_; // Static container with vendor option definitions for DHCPv6. VendorOptionDefContainers LibDHCP::vendor6_defs_; +// Static container with last resort option definitions for DHCPv4. +OptionDefContainerPtr LibDHCP::lastresort_defs_(new OptionDefContainer()); + // Static container with option definitions created in runtime. StagedValue LibDHCP::runtime_option_defs_; // Null container. const OptionDefContainerPtr null_option_def_container_(new OptionDefContainer()); -// Option 43 definition. -OptionDefinitionPtr LibDHCP::last_resort_option43_def; - // Those two vendor classes are used for cable modems: /// DOCSIS3.0 compatible cable modem @@ -86,6 +86,7 @@ LibDHCP::getOptionDefs(const std::string& space) { initVendorOptsDocsis4(); initStdOptionDefs6(); initVendorOptsDocsis6(); + initLastResortOptionDefs(); } if (space == DHCP4_OPTION_SPACE) { @@ -260,6 +261,38 @@ LibDHCP::commitRuntimeOptionDefs() { runtime_option_defs_.commit(); } +OptionDefinitionPtr +LibDHCP::getLastResortOptionDef(const std::string& space, const uint16_t code) { + OptionDefContainerPtr container = getLastResortOptionDefs(space); + const OptionDefContainerTypeIndex& index = container->get<1>(); + const OptionDefContainerTypeRange& range = index.equal_range(code); + if (range.first != range.second) { + return (*range.first); + } + + return (OptionDefinitionPtr()); +} + +OptionDefinitionPtr +LibDHCP::getLastResortOptionDef(const std::string& space, const std::string& name) { + OptionDefContainerPtr container = getLastResortOptionDefs(space); + const OptionDefContainerNameIndex& index = container->get<2>(); + const OptionDefContainerNameRange& range = index.equal_range(name); + if (range.first != range.second) { + return (*range.first); + } + + return (OptionDefinitionPtr()); +} + +OptionDefContainerPtr +LibDHCP::getLastResortOptionDefs(const std::string& space) { + if (space == DHCP4_OPTION_SPACE) { + return (lastresort_defs_); + } + return (null_option_def_container_); +} + bool LibDHCP::deferOption(const std::string& space, const uint16_t code) { return ((space == DHCP4_OPTION_SPACE) && @@ -831,11 +864,6 @@ void LibDHCP::initStdOptionDefs4() { initOptionSpace(v4option_defs_, STANDARD_V4_OPTION_DEFINITIONS, STANDARD_V4_OPTION_DEFINITIONS_SIZE); - last_resort_option43_def.reset(new OptionDefinition( - LAST_RESORT_OPTION43_DEFINITION.name, - LAST_RESORT_OPTION43_DEFINITION.code, - LAST_RESORT_OPTION43_DEFINITION.type, - LAST_RESORT_OPTION43_DEFINITION.array)); } void @@ -854,6 +882,12 @@ LibDHCP::initStdOptionDefs6() { V4V6_BIND_OPTION_DEFINITIONS_SIZE); } +void +LibDHCP::initLastResortOptionDefs() { + initOptionSpace(lastresort_defs_, LAST_RESORT_V4_OPTION_DEFINITIONS, + LAST_RESORT_V4_OPTION_DEFINITIONS_SIZE); +} + void LibDHCP::initVendorOptsDocsis4() { initOptionSpace(vendor4_defs_[VENDOR_ID_CABLE_LABS], DOCSIS3_V4_DEFS, diff --git a/src/lib/dhcp/libdhcp++.h b/src/lib/dhcp/libdhcp++.h index 7d859b36f5..b3f8d7f452 100644 --- a/src/lib/dhcp/libdhcp++.h +++ b/src/lib/dhcp/libdhcp++.h @@ -113,6 +113,33 @@ public: static OptionDefContainerPtr getRuntimeOptionDefs(const std::string& space); + /// @brief Returns last resort option definition by space and option code. + /// + /// @param space Option space name. + /// @param code Option code. + /// + /// @return Pointer to option definition or NULL if it doesn't exist. + static OptionDefinitionPtr getLastResortOptionDef(const std::string& space, + const uint16_t code); + + /// @brief Returns last resort option definition by space and option name. + /// + /// @param space Option space name. + /// @param name Option name. + /// + /// @return Pointer to option definition or NULL if it doesn't exist. + static OptionDefinitionPtr getLastResortOptionDef(const std::string& space, + const std::string& name); + + /// @brief Returns last resort option definitions for specified option + /// space name. + /// + /// @param space Option space name. + /// + /// @return Pointer to the container holding option definitions or NULL. + static OptionDefContainerPtr + getLastResortOptionDefs(const std::string& space); + /// @brief Checks if an option unpacking has to be deferred. /// /// DHCPv4 option 43 and 224-254 unpacking is done after classification. @@ -123,9 +150,6 @@ public: /// @return True if option processing should be deferred. static bool deferOption(const std::string& space, const uint16_t code); - /// @brief Last resort definition for DHCPv4 option 43 - static OptionDefinitionPtr last_resort_option43_def; - /// @brief Factory function to create instance of option. /// /// Factory method creates instance of specified option. The option @@ -357,6 +381,8 @@ private: /// is incorrect. This is a programming error. static void initStdOptionDefs6(); + static void initLastResortOptionDefs(); + static void initVendorOptsDocsis4(); static void initVendorOptsDocsis6(); @@ -385,6 +411,9 @@ private: /// Container for v6 vendor option definitions static VendorOptionDefContainers vendor6_defs_; + /// Container with DHCPv4 last resort option definitions. + static OptionDefContainerPtr lastresort_defs_; + /// Container for additional option definitions created in runtime. static util::StagedValue runtime_option_defs_; }; diff --git a/src/lib/dhcp/std_option_defs.h b/src/lib/dhcp/std_option_defs.h index 22701cb5c8..04f8488ec3 100644 --- a/src/lib/dhcp/std_option_defs.h +++ b/src/lib/dhcp/std_option_defs.h @@ -216,12 +216,14 @@ const OptionDefParams STANDARD_V4_OPTION_DEFINITIONS[] = { const int STANDARD_V4_OPTION_DEFINITIONS_SIZE = sizeof(STANDARD_V4_OPTION_DEFINITIONS) / sizeof(STANDARD_V4_OPTION_DEFINITIONS[0]); -/// Last resort definition for option 43 -const OptionDefParams LAST_RESORT_OPTION43_DEFINITION = { - "vendor-encapsulated-options", DHO_VENDOR_ENCAPSULATED_OPTIONS, - OPT_EMPTY_TYPE, false, NO_RECORD_DEF, "vendor-encapsulated-options-space" +/// Last resort definitions (only option 43 for now). +const OptionDefParams LAST_RESORT_V4_OPTION_DEFINITIONS[] = { + { "vendor-encapsulated-options", DHO_VENDOR_ENCAPSULATED_OPTIONS, + OPT_EMPTY_TYPE, false, NO_RECORD_DEF, "vendor-encapsulated-options-space" } }; +const int LAST_RESORT_V4_OPTION_DEFINITIONS_SIZE = 1; + /// Start Definition of DHCPv6 options // client-fqdn diff --git a/src/lib/dhcpsrv/cfg_option.cc b/src/lib/dhcpsrv/cfg_option.cc index 5d6c153918..1fac24d5b8 100644 --- a/src/lib/dhcpsrv/cfg_option.cc +++ b/src/lib/dhcpsrv/cfg_option.cc @@ -211,6 +211,9 @@ CfgOption::toElement() const { if (!def) { def = LibDHCP::getRuntimeOptionDef(*name, code); } + if (!def) { + def = LibDHCP::getLastResortOptionDef(*name, code); + } if (def) { map->set("name", Element::create(def->getName())); } diff --git a/src/lib/dhcpsrv/parsers/option_data_parser.cc b/src/lib/dhcpsrv/parsers/option_data_parser.cc index b18e198a60..2773498276 100644 --- a/src/lib/dhcpsrv/parsers/option_data_parser.cc +++ b/src/lib/dhcpsrv/parsers/option_data_parser.cc @@ -215,6 +215,11 @@ OptionDataParser::findOptionDefinition(const std::string& option_space, def = LibDHCP::getRuntimeOptionDef(option_space, search_key); } + if (!def) { + // Finish by last resort definitions. + def = LibDHCP::getLastResortOptionDef(option_space, search_key); + } + return (def); } diff --git a/src/lib/eval/eval_context.cc b/src/lib/eval/eval_context.cc index 322e2e25e6..562a67481b 100644 --- a/src/lib/eval/eval_context.cc +++ b/src/lib/eval/eval_context.cc @@ -89,6 +89,10 @@ EvalContext::convertOptionName(const std::string& option_name, option_def = LibDHCP::getRuntimeOptionDef(global_space, option_name); } + if (!option_def) { + option_def = LibDHCP::getLastResortOptionDef(global_space, option_name); + } + if (!option_def) { error(loc, "option '" + option_name + "' is not defined"); }