]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3316] Use OptionVendorClass to encapsulate DHCPv4 option 124.
authorMarcin Siodelski <marcin@isc.org>
Thu, 13 Feb 2014 15:45:57 +0000 (16:45 +0100)
committerMarcin Siodelski <marcin@isc.org>
Thu, 13 Feb 2014 15:45:57 +0000 (16:45 +0100)
src/lib/dhcp/option_definition.cc
src/lib/dhcp/option_definition.h
src/lib/dhcp/std_option_defs.h
src/lib/dhcp/tests/libdhcp++_unittest.cc

index c8c836fdcbcd4014edeba3b58a0a6062a1e2940a..4f16c66fa38a0f37cc879cb1e5581009d403b17d 100644 (file)
@@ -400,6 +400,14 @@ OptionDefinition::haveVendor6Format() const {
     return  (getType() == OPT_UINT32_TYPE && !getEncapsulatedSpace().empty());
 }
 
+bool
+OptionDefinition::haveVendorClass4Format() const {
+    return (haveType(OPT_RECORD_TYPE) &&
+            (record_fields_.size() == 2) &&
+            (record_fields_[0] == OPT_UINT32_TYPE) &&
+            (record_fields_[1] == OPT_BINARY_TYPE));
+}
+
 bool
 OptionDefinition::haveVendorClass6Format() const {
     return (haveType(OPT_RECORD_TYPE) &&
@@ -669,7 +677,10 @@ OptionDefinition::factorySpecialFormatOption(Option::Universe u,
     } else {
         if ((getCode() == DHO_FQDN) && haveFqdn4Format()) {
             return (OptionPtr(new Option4ClientFqdn(begin, end)));
-
+            // V-I VendorClass
+        } else if ((getCode() == DHO_VIVCO_SUBOPTIONS) &&
+                   haveVendorClass4Format()) {
+            return (OptionPtr(new OptionVendorClass(Option::V4, begin, end)));
         } else if (getCode() == DHO_VIVSO_SUBOPTIONS && haveVendor4Format()) {
             // Vendor-Specific Information.
             return (OptionPtr(new OptionVendor(Option::V4, begin, end)));
index 68f40362c8322e6bac798c97b3c062e3aecc37d2..3664d9dbc414d7b21df6063557680b9933237182 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2014 Internet Systems Consortium, Inc. ("ISC")
 //
 // Permission to use, copy, modify, and/or distribute this software for any
 // purpose with or without fee is hereby granted, provided that the above
@@ -324,6 +324,11 @@ public:
     /// Vendor-Specific Information %Option.
     bool haveVendor6Format() const;
 
+    /// @brief Check if the option has format of DHCPv4 V-I Vendor Class option.
+    ///
+    /// @return true if the option has the format of DHCPv4 Vendor Class option.
+    bool haveVendorClass4Format() const;
+
     /// @brief Check if the option has format of DHCPv6 Vendor Class option.
     ///
     /// @return true if option has the format of DHCPv6 Vendor Class option.
index 865407e72ded2181bc56d1dacea94d36f022a7d2..d55d2f079012a5254671114fe26fc8b0361c5a87 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2014 Internet Systems Consortium, Inc. ("ISC")
 //
 // Permission to use, copy, modify, and/or distribute this software for any
 // purpose with or without fee is hereby granted, provided that the above
@@ -67,6 +67,11 @@ struct OptionDefParams {
 RECORD_DECL(FQDN_RECORDS, OPT_UINT8_TYPE, OPT_UINT8_TYPE, OPT_UINT8_TYPE,
             OPT_FQDN_TYPE);
 
+// V-I Vendor Class record fields.
+//
+// Opaque data is represented here by the binary data field.
+RECORD_DECL(VIVCO_RECORDS, OPT_UINT32_TYPE, OPT_BINARY_TYPE);
+
 /// @brief Definitions of standard DHCPv4 options.
 const OptionDefParams OPTION_DEF_PARAMS4[] = {
     { "subnet-mask", DHO_SUBNET_MASK, OPT_IPV4_ADDRESS_TYPE, false, NO_RECORD_DEF, "" },
@@ -191,8 +196,8 @@ const OptionDefParams OPTION_DEF_PARAMS4[] = {
     // dedicated classes to handle them. Until that happens
     // let's treat them as 'binary' options.
     { "domain-search", DHO_DOMAIN_SEARCH, OPT_BINARY_TYPE, false, NO_RECORD_DEF, "" },
-    { "vivco-suboptions", DHO_VIVCO_SUBOPTIONS,
-      OPT_BINARY_TYPE, false, NO_RECORD_DEF, "" },
+    { "vivco-suboptions", DHO_VIVCO_SUBOPTIONS, OPT_RECORD_TYPE,
+      false, RECORD_DEF(VIVCO_RECORDS), "" },
     { "vivso-suboptions", DHO_VIVSO_SUBOPTIONS, OPT_BINARY_TYPE,
       false, NO_RECORD_DEF, "" }
 
index f0bd2824a1d01ca8fd3c56f712f853e9f3f50067..f40067f30dbaef55327d49cf8089bae96a0c9bd6 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2013 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2014 Internet Systems Consortium, Inc. ("ISC")
 //
 // Permission to use, copy, modify, and/or distribute this software for any
 // purpose with or without fee is hereby granted, provided that the above
@@ -942,8 +942,14 @@ TEST_F(LibDhcpTest, stdOptionDefs4) {
     LibDhcpTest::testStdOptionDefs4(DHO_DOMAIN_SEARCH, begin, end,
                                     typeid(Option));
 
-    LibDhcpTest::testStdOptionDefs4(DHO_VIVCO_SUBOPTIONS, begin, end,
-                                    typeid(Option));
+    // V-I Vendor option requires specially crafted data.
+    const char vivco_data[] = {
+        1, 2, 3, 4, // enterprise id
+        3, 1, 2, 3  // first byte is opaque data length, the rest is opaque data
+    };
+    std::vector<uint8_t> vivco_buf(vivco_data, vivco_data + sizeof(vivco_data));
+    LibDhcpTest::testStdOptionDefs4(DHO_VIVCO_SUBOPTIONS, vivco_buf.begin(),
+                                    vivco_buf.end(), typeid(OptionVendorClass));
 
     LibDhcpTest::testStdOptionDefs4(DHO_VIVSO_SUBOPTIONS, begin, end,
                                     typeid(OptionVendor));