Browse Source

[5227] Did easy DHCPv4 options

Francis Dupont 7 years ago
parent
commit
bb0206cb84
4 changed files with 162 additions and 35 deletions
  1. 21 0
      doc/guide/dhcp4-srv.xml
  2. 23 22
      src/lib/dhcp/dhcp4.h
  3. 28 1
      src/lib/dhcp/std_option_defs.h
  4. 90 12
      src/lib/dhcp/tests/libdhcp++_unittest.cc

+ 21 - 0
doc/guide/dhcp4-srv.xml

@@ -1293,6 +1293,11 @@ It is a part of the DDNS/D2 configuration
 It is merely echoed by the server
 <row><entry>dhcp-agent-options</entry><entry>82</entry><entry>empty</entry><entry>false</entry><entry>false</entry></row>
 -->
+<row><entry>nds-server</entry><entry>85</entry><entry>ipv4-address</entry><entry>true</entry><entry>false</entry></row>
+<row><entry>nds-tree-name</entry><entry>86</entry><entry>string</entry><entry>false</entry><entry>false</entry></row>
+<row><entry>nds-context</entry><entry>87</entry><entry>string</entry><entry>false</entry><entry>false</entry></row>
+<row><entry>bcms-controller-names</entry><entry>88</entry><entry>fqdn</entry><entry>true</entry><entry>false</entry></row>
+<row><entry>bcms-controller-address</entry><entry>89</entry><entry>ipv4-address</entry><entry>true</entry><entry>false</entry></row>
 <!-- Authentication option requires special processing
 <row><entry>authenticate</entry><entry>90</entry><entry>binary</entry><entry>false</entry><entry>false</entry></row>
 -->
@@ -1303,10 +1308,26 @@ It is merely echoed by the server
 <row><entry>client-system</entry><entry>93</entry><entry>uint16</entry><entry>true</entry><entry>false</entry></row>
 <row><entry>client-ndi</entry><entry>94</entry><entry>record (uint8, uint8, uint8)</entry><entry>false</entry><entry>false</entry></row>
 <row><entry>uuid-guid</entry><entry>97</entry><entry>record (uint8, binary)</entry><entry>false</entry><entry>false</entry></row>
+<row><entry>uap-servers</entry><entry>98</entry><entry>string</entry><entry>false</entry><entry>false</entry></row>
+<row><entry>geoconf-civic</entry><entry>99</entry><entry>binary</entry><entry>false</entry><entry>false</entry></row>
+<row><entry>pcode</entry><entry>100</entry><entry>string</entry><entry>false</entry><entry>false</entry></row>
+<row><entry>tcode</entry><entry>101</entry><entry>string</entry><entry>false</entry><entry>false</entry></row>
+<row><entry>netinfo-server-address</entry><entry>112</entry><entry>ipv4-address</entry><entry>true</entry><entry>false</entry></row>
+<row><entry>netinfo-server-tag</entry><entry>113</entry><entry>string</entry><entry>false</entry><entry>false</entry></row>
+<row><entry>default-url</entry><entry>114</entry><entry>string</entry><entry>false</entry><entry>false</entry></row>
+<row><entry>auto-config</entry><entry>116</entry><entry>uint8</entry><entry>false</entry><entry>false</entry></row>
+<row><entry>name-service-search</entry><entry>117</entry><entry>uint16</entry><entry>true</entry><entry>false</entry></row>
 <row><entry>subnet-selection</entry><entry>118</entry><entry>ipv4-address</entry><entry>false</entry><entry>false</entry></row>
 <row><entry>domain-search</entry><entry>119</entry><entry>fqdn</entry><entry>true</entry><entry>false</entry></row>
 <row><entry>vivco-suboptions</entry><entry>124</entry><entry>binary</entry><entry>false</entry><entry>false</entry></row>
 <row><entry>vivso-suboptions</entry><entry>125</entry><entry>binary</entry><entry>false</entry><entry>false</entry></row>
+<row><entry>pana-agent</entry><entry>136</entry><entry>ipv4-address</entry><entry>true</entry><entry>false</entry></row>
+<row><entry>v4-lost</entry><entry>137</entry><entry>fqdn</entry><entry>false</entry><entry>false</entry></row>
+<row><entry>capwap-ac-v4</entry><entry>138</entry><entry>ipv4-address</entry><entry>true</entry><entry>false</entry></row>
+<row><entry>sip-ua-cs-domains</entry><entry>142</entry><entry>fqdn</entry><entry>true</entry><entry>false</entry></row>
+<row><entry>v4-portparams</entry><entry>159</entry><entry>record (uint8, uint8, uint16)</entry><entry>false</entry><entry>false</entry></row>
+<row><entry>v4-captive-portal</entry><entry>160</entry><entry>string</entry><entry>false</entry><entry>false</entry></row>
+<row><entry>v4-access-domain</entry><entry>213</entry><entry>fqdn</entry><entry>false</entry><entry>false</entry></row>
           </tbody>
           </tgroup>
         </table>

+ 23 - 22
src/lib/dhcp/dhcp4.h

@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2004-2016 Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (C) 2004-2017 Internet Systems Consortium, Inc. ("ISC")
  * Copyright (c) 1995-2003 by Internet Software Consortium
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
@@ -146,16 +146,16 @@ enum DHCPOptionType {
     DHO_USER_CLASS                   = 77,
 //  DHO_DIRECTORY_AGENT              = 78,
 //  DHO_SERVICE_SCOPE                = 79,
-//  DHO_RAPID_COMMIT                 = 80,,
+//  DHO_RAPID_COMMIT                 = 80,
     DHO_FQDN                         = 81,
     DHO_DHCP_AGENT_OPTIONS           = 82,
 //  DHO_ISNS                         = 83,
     // 84 is removed/unassigned
-//  DHO_NDS_SERVERS                  = 85,
-//  DHO_NDS_TREE_NAME                = 86,
-//  DHO_NDS_CONTEXT                  = 87,
-//  DHO_BCMCS_DOMAIN_NAME_LIST       = 88,
-//  DHO_BCMCS_IPV4_ADDR              = 89,
+    DHO_NDS_SERVERS                  = 85,
+    DHO_NDS_TREE_NAME                = 86,
+    DHO_NDS_CONTEXT                  = 87,
+    DHO_BCMCS_DOMAIN_NAME_LIST       = 88,
+    DHO_BCMCS_IPV4_ADDR              = 89,
     DHO_AUTHENTICATE                 = 90,  /* RFC3118, was 210 */
     DHO_CLIENT_LAST_TRANSACTION_TIME = 91,
     DHO_ASSOCIATED_IP                = 92,
@@ -164,17 +164,17 @@ enum DHCPOptionType {
 //  DHO_LDAP                         = 95,
     // 96 is removed/unassigned
     DHO_UUID_GUID                    = 97, /* RFC4578 */
-//  DHO_USER_AUTH                    = 98,
-//  DHO_GEOCONF_CIVIC                = 99,
-//  DHO_PCODE                        = 100,
-//  DHO_TCODE                        = 101,
+    DHO_USER_AUTH                    = 98,
+    DHO_GEOCONF_CIVIC                = 99,
+    DHO_PCODE                        = 100,
+    DHO_TCODE                        = 101,
     // 102-111 are removed/unassigned
-//  DHO_NETINFO_ADDR                 = 112,
-//  DHO_NETINFO_TAG                  = 113,
-//  DHO_URL                          = 114,
+    DHO_NETINFO_ADDR                 = 112,
+    DHO_NETINFO_TAG                  = 113,
+    DHO_URL                          = 114,
     // 115 is removed/unassigned
-//  DHO_AUTO_CONFIG                  = 116,
-//  DHO_NAME_SERVICE_SEARCH          = 117,
+    DHO_AUTO_CONFIG                  = 116,
+    DHO_NAME_SERVICE_SEARCH          = 117,
     DHO_SUBNET_SELECTION             = 118, /* RFC3011 */
     DHO_DOMAIN_SEARCH                = 119, /* RFC3397 */
 //  DHO_SIP_SERVERS                  = 120,
@@ -185,12 +185,12 @@ enum DHCPOptionType {
     DHO_VIVSO_SUBOPTIONS             = 125,
     // 126-127 are removed/unassigned
     // 128-135 have multiple definitions including PXE
-//  DHO_PANA_AGENT                   = 136,
-//  DHO_V4_LOST                      = 137,
-//  DHO_CAPWAP_AC_V4                 = 138,
+    DHO_PANA_AGENT                   = 136,
+    DHO_V4_LOST                      = 137,
+    DHO_CAPWAP_AC_V4                 = 138,
 //  DHO_IPV4_ADDR_MOS                = 139,
 //  DHO_IPV4_FQDN_MOS                = 140,
-//  DHO_SIP_UA_CONF_SERVICE_DOMAINS  = 141,
+    DHO_SIP_UA_CONF_SERVICE_DOMAINS  = 141,
 //  DHO_IPV4_ADDR_ANDSF              = 142,
     // 143 is removed/unassigned
 //  DHO_GEOLOC                       = 144,
@@ -206,10 +206,11 @@ enum DHCPOptionType {
 //  DHO_DHCP_STATE                   = 156,
 //  DHO_DATA_SOURCE                  = 157,
 //  DHO_V4_PCP_SERVER                = 158,
-//  DHO_V4_PORTPARAMS                = 159,
+    DHO_V4_PORTPARAMS                = 159,
+    DHO_V4_CAPTIVE_PORTAL            = 160,
     // 160-211 are removed/unassigned
 //  DHO_6RD                          = 212,
-//  DHO_V4_ACCESS_DOMAIN             = 213,
+    DHO_V4_ACCESS_DOMAIN             = 213,
     // 214-219 are removed/unassigned
 //  DHO_SUBNET_ALLOC                 = 220,
 //  DHO_VSS                          = 221,

+ 28 - 1
src/lib/dhcp/std_option_defs.h

@@ -60,6 +60,11 @@ RECORD_DECL(CLIENT_NDI_RECORDS, OPT_UINT8_TYPE, OPT_UINT8_TYPE, OPT_UINT8_TYPE);
 // A client identifer: a 1 byte type field followed by opaque data depending on the type
 RECORD_DECL(UUID_GUID_RECORDS, OPT_UINT8_TYPE, OPT_BINARY_TYPE);
 
+// RFC7618 DHCPv4 Port Parameter option.
+//
+// PSID offset, PSID-len and PSID
+RECORD_DECL(V4_PORTPARAMS_RECORDS, OPT_UINT8_TYPE, OPT_UINT8_TYPE, OPT_UINT16_TYPE);
+
 /// @brief Definitions of standard DHCPv4 options.
 const OptionDefParams STANDARD_V4_OPTION_DEFINITIONS[] = {
     { "subnet-mask", DHO_SUBNET_MASK, OPT_IPV4_ADDRESS_TYPE, false, NO_RECORD_DEF, "" },
@@ -177,6 +182,11 @@ const OptionDefParams STANDARD_V4_OPTION_DEFINITIONS[] = {
     { "fqdn", DHO_FQDN, OPT_RECORD_TYPE, false, RECORD_DEF(FQDN_RECORDS), "" },
     { "dhcp-agent-options", DHO_DHCP_AGENT_OPTIONS,
       OPT_EMPTY_TYPE, false, NO_RECORD_DEF, "dhcp-agent-options-space" },
+    { "nds-servers", DHO_NDS_SERVERS, OPT_IPV4_ADDRESS_TYPE, true, NO_RECORD_DEF, "" },
+    { "nds-tree-name", DHO_NDS_TREE_NAME, OPT_STRING_TYPE, false, NO_RECORD_DEF, "" },
+    { "nds-context", DHO_NDS_CONTEXT, OPT_STRING_TYPE, false, NO_RECORD_DEF, "" },
+    { "bcms-controller-names", DHO_BCMCS_DOMAIN_NAME_LIST, OPT_FQDN_TYPE, true, NO_RECORD_DEF, "" },
+    { "bcms-controller-address", DHO_BCMCS_IPV4_ADDR, OPT_IPV4_ADDRESS_TYPE, true, NO_RECORD_DEF, "" },
     // Unfortunatelly the AUTHENTICATE option contains a 64-bit
     // data field called 'replay-detection' that can't be added
     // as a record field to a custom option. Also, there is no
@@ -190,6 +200,15 @@ const OptionDefParams STANDARD_V4_OPTION_DEFINITIONS[] = {
     { "client-system", DHO_SYSTEM, OPT_UINT16_TYPE, true, NO_RECORD_DEF, "" },
     { "client-ndi", DHO_NDI, OPT_RECORD_TYPE, false, RECORD_DEF(CLIENT_NDI_RECORDS), "" },
     { "uuid-guid", DHO_UUID_GUID, OPT_RECORD_TYPE, false, RECORD_DEF(UUID_GUID_RECORDS), "" },
+    { "uap-servers", DHO_USER_AUTH, OPT_STRING_TYPE, false, NO_RECORD_DEF, "" },
+    { "geoconf-civic", DHO_GEOCONF_CIVIC, OPT_BINARY_TYPE, false, NO_RECORD_DEF, "" },
+    { "pcode", DHO_PCODE, OPT_STRING_TYPE, false, NO_RECORD_DEF, "" },
+    { "tcode", DHO_TCODE, OPT_STRING_TYPE, false, NO_RECORD_DEF, "" },
+    { "netinfo-server-address", DHO_NETINFO_ADDR, OPT_IPV4_ADDRESS_TYPE, true, NO_RECORD_DEF, "" },
+    { "netinfo-server-tag", DHO_NETINFO_TAG, OPT_STRING_TYPE, false, NO_RECORD_DEF, "" },
+    { "default-url", DHO_URL, OPT_STRING_TYPE, false, NO_RECORD_DEF, "" },
+    { "auto-config", DHO_AUTO_CONFIG, OPT_UINT8_TYPE, false, NO_RECORD_DEF, "" },
+    { "name-service-search", DHO_NAME_SERVICE_SEARCH, OPT_UINT16_TYPE, true, NO_RECORD_DEF, "" },
     { "subnet-selection", DHO_SUBNET_SELECTION,
       OPT_IPV4_ADDRESS_TYPE, false, NO_RECORD_DEF, "" },
     { "domain-search", DHO_DOMAIN_SEARCH, OPT_FQDN_TYPE, true, NO_RECORD_DEF, "" },
@@ -208,7 +227,15 @@ const OptionDefParams STANDARD_V4_OPTION_DEFINITIONS[] = {
     /// ok to specify multiple instances of the "vivso-suboptions" which will be
     /// combined in a single option by the server before responding to a client.
     { "vivso-suboptions", DHO_VIVSO_SUBOPTIONS, OPT_UINT32_TYPE,
-      false, NO_RECORD_DEF, "" }
+      false, NO_RECORD_DEF, "" },
+    { "pana-agent", DHO_PANA_AGENT, OPT_IPV4_ADDRESS_TYPE, true, NO_RECORD_DEF, "" },
+    { "v4-lost", DHO_V4_LOST, OPT_FQDN_TYPE, false, NO_RECORD_DEF, "" },
+    { "capwap-ac-v4", DHO_CAPWAP_AC_V4, OPT_IPV4_ADDRESS_TYPE, true, NO_RECORD_DEF, "" },
+    { "sip-ua-cs-domains", DHO_SIP_UA_CONF_SERVICE_DOMAINS, OPT_FQDN_TYPE, true, NO_RECORD_DEF, "" },
+    { "v4-portparams", DHO_V4_PORTPARAMS, OPT_RECORD_TYPE, false,
+      RECORD_DEF(V4_PORTPARAMS_RECORDS), "" },
+    { "v4-captive-portal", DHO_V4_CAPTIVE_PORTAL, OPT_STRING_TYPE, false, NO_RECORD_DEF, "" },
+    { "v4-access-domain", DHO_V4_ACCESS_DOMAIN, OPT_FQDN_TYPE, false, NO_RECORD_DEF, "" }
 
         // @todo add definitions for all remaining options.
 };

+ 90 - 12
src/lib/dhcp/tests/libdhcp++_unittest.cc

@@ -1297,6 +1297,36 @@ TEST_F(LibDhcpTest, stdOptionDefs4) {
                                     typeid(OptionCustom),
                                     "dhcp-agent-options-space");
 
+    LibDhcpTest::testStdOptionDefs4(DHO_NDS_SERVERS, begin, end,
+                                    typeid(Option4AddrLst));
+
+    LibDhcpTest::testStdOptionDefs4(DHO_NDS_TREE_NAME, begin, end,
+                                    typeid(OptionString));
+
+    LibDhcpTest::testStdOptionDefs4(DHO_NDS_CONTEXT, begin, end,
+                                    typeid(OptionString));
+
+    // Prepare buffer holding an array of FQDNs.
+    const char fqdn_data[] = {
+        8, 109, 121, 100, 111, 109, 97, 105, 110, // "mydomain"
+        7, 101, 120, 97, 109, 112, 108, 101,      // "example"
+        3, 99, 111, 109,                          // "com"
+        0,
+        7, 101, 120, 97, 109, 112, 108, 101,      // "example"
+        3, 99, 111, 109,                          // "com"
+        0
+    };
+    // Initialize a vector with the FQDN data.
+    std::vector<uint8_t> fqdn_buf(fqdn_data, fqdn_data + sizeof(fqdn_data));
+
+    LibDhcpTest::testStdOptionDefs4(DHO_BCMCS_DOMAIN_NAME_LIST,
+                                    fqdn_buf.begin(),
+                                    fqdn_buf.end(),
+                                    typeid(OptionCustom));
+
+    LibDhcpTest::testStdOptionDefs4(DHO_BCMCS_IPV4_ADDR, begin, end,
+                                    typeid(Option4AddrLst));
+
     LibDhcpTest::testStdOptionDefs4(DHO_AUTHENTICATE, begin, end,
                                     typeid(Option));
 
@@ -1307,6 +1337,12 @@ TEST_F(LibDhcpTest, stdOptionDefs4) {
     LibDhcpTest::testStdOptionDefs4(DHO_ASSOCIATED_IP, begin, end,
                                     typeid(Option4AddrLst));
 
+    LibDhcpTest::testStdOptionDefs4(DHO_AUTO_CONFIG, begin, begin + 1,
+                                    typeid(OptionInt<uint8_t>));
+
+    LibDhcpTest::testStdOptionDefs4(DHO_NAME_SERVICE_SEARCH, begin, begin + 4,
+                                    typeid(OptionIntArray<uint16_t>));
+
     LibDhcpTest::testStdOptionDefs4(DHO_SUBNET_SELECTION, begin, end,
                                     typeid(OptionCustom));
 
@@ -1319,18 +1355,26 @@ TEST_F(LibDhcpTest, stdOptionDefs4) {
     LibDhcpTest::testStdOptionDefs4(DHO_UUID_GUID, begin, begin + 17,
                                     typeid(OptionCustom));
 
-    // Prepare buffer holding an array of FQDNs.
-    const char fqdn_data[] = {
-        8, 109, 121, 100, 111, 109, 97, 105, 110, // "mydomain"
-        7, 101, 120, 97, 109, 112, 108, 101,      // "example"
-        3, 99, 111, 109,                          // "com"
-        0,
-        7, 101, 120, 97, 109, 112, 108, 101,      // "example"
-        3, 99, 111, 109,                          // "com"
-        0
-    };
-    // Initialize a vector with the FQDN data.
-    std::vector<uint8_t> fqdn_buf(fqdn_data, fqdn_data + sizeof(fqdn_data));
+    LibDhcpTest::testStdOptionDefs4(DHO_USER_AUTH, begin, end,
+                                    typeid(OptionString));
+
+    LibDhcpTest::testStdOptionDefs4(DHO_GEOCONF_CIVIC, begin, end,
+                                    typeid(Option));
+
+    LibDhcpTest::testStdOptionDefs4(DHO_PCODE, begin, end,
+                                    typeid(OptionString));
+
+    LibDhcpTest::testStdOptionDefs4(DHO_TCODE, begin, end,
+                                    typeid(OptionString));
+
+    LibDhcpTest::testStdOptionDefs4(DHO_NETINFO_ADDR, begin, end,
+                                    typeid(Option4AddrLst));
+
+    LibDhcpTest::testStdOptionDefs4(DHO_NETINFO_TAG, begin, end,
+                                    typeid(OptionString));
+
+    LibDhcpTest::testStdOptionDefs4(DHO_URL, begin, end,
+                                    typeid(OptionString));
 
     LibDhcpTest::testStdOptionDefs4(DHO_DOMAIN_SEARCH, fqdn_buf.begin(),
                                     fqdn_buf.end(), typeid(OptionCustom));
@@ -1354,6 +1398,40 @@ TEST_F(LibDhcpTest, stdOptionDefs4) {
 
     LibDhcpTest::testStdOptionDefs4(DHO_VIVSO_SUBOPTIONS, vivsio_buf.begin(),
                                     vivsio_buf.end(), typeid(OptionVendor));
+
+    LibDhcpTest::testStdOptionDefs4(DHO_PANA_AGENT, begin, end,
+                                    typeid(Option4AddrLst));
+
+    // Prepare buffer holding one FQDN.
+    const char fqdn1_data[] = {
+        8, 109, 121, 100, 111, 109, 97, 105, 110, // "mydomain"
+        7, 101, 120, 97, 109, 112, 108, 101,      // "example"
+        3, 99, 111, 109,                          // "com"
+        0
+    };
+    // Initialize a vector with the FQDN data.
+    std::vector<uint8_t> fqdn1_buf(fqdn1_data,
+                                   fqdn1_data + sizeof(fqdn1_data));
+
+    LibDhcpTest::testStdOptionDefs4(DHO_V4_LOST, fqdn1_buf.begin(),
+                                    fqdn1_buf.end(), typeid(OptionCustom));
+
+    LibDhcpTest::testStdOptionDefs4(DHO_CAPWAP_AC_V4, begin, end,
+                                    typeid(Option4AddrLst));
+
+    LibDhcpTest::testStdOptionDefs4(DHO_SIP_UA_CONF_SERVICE_DOMAINS,
+                                    fqdn_buf.begin(),
+                                    fqdn_buf.end(),
+                                    typeid(OptionCustom));
+
+    LibDhcpTest::testStdOptionDefs4(DHO_V4_PORTPARAMS, begin, begin + 4,
+                                    typeid(OptionCustom));
+
+    LibDhcpTest::testStdOptionDefs4(DHO_V4_CAPTIVE_PORTAL, begin, end,
+                                    typeid(OptionString));
+
+    LibDhcpTest::testStdOptionDefs4(DHO_V4_ACCESS_DOMAIN, fqdn1_buf.begin(),
+                                    fqdn1_buf.end(), typeid(OptionCustom));
 }
 
 // Test that definitions of standard options have been initialized