From: Marcin Siodelski Date: Thu, 13 Feb 2014 15:45:57 +0000 (+0100) Subject: [3316] Use OptionVendorClass to encapsulate DHCPv4 option 124. X-Git-Tag: bind10-1.2.0beta1-release~35^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=87f58c5dd3b8555dc0ecb449f1f39e2cc0198806;p=thirdparty%2Fkea.git [3316] Use OptionVendorClass to encapsulate DHCPv4 option 124. --- diff --git a/src/lib/dhcp/option_definition.cc b/src/lib/dhcp/option_definition.cc index c8c836fdcb..4f16c66fa3 100644 --- a/src/lib/dhcp/option_definition.cc +++ b/src/lib/dhcp/option_definition.cc @@ -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))); diff --git a/src/lib/dhcp/option_definition.h b/src/lib/dhcp/option_definition.h index 68f40362c8..3664d9dbc4 100644 --- a/src/lib/dhcp/option_definition.h +++ b/src/lib/dhcp/option_definition.h @@ -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. diff --git a/src/lib/dhcp/std_option_defs.h b/src/lib/dhcp/std_option_defs.h index 865407e72d..d55d2f0790 100644 --- a/src/lib/dhcp/std_option_defs.h +++ b/src/lib/dhcp/std_option_defs.h @@ -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, "" } diff --git a/src/lib/dhcp/tests/libdhcp++_unittest.cc b/src/lib/dhcp/tests/libdhcp++_unittest.cc index f0bd2824a1..f40067f30d 100644 --- a/src/lib/dhcp/tests/libdhcp++_unittest.cc +++ b/src/lib/dhcp/tests/libdhcp++_unittest.cc @@ -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 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));