From: Marcin Siodelski Date: Mon, 12 Aug 2013 10:01:56 +0000 (+0200) Subject: [3082] Return instance of the Option4ClientFqdn for option 81. X-Git-Tag: bind10-1.2.0beta1-release~259^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cf24637df0959a2b68f2bde161790a73e3270abd;p=thirdparty%2Fkea.git [3082] Return instance of the Option4ClientFqdn for option 81. --- diff --git a/src/lib/dhcp/option4_client_fqdn.cc b/src/lib/dhcp/option4_client_fqdn.cc index 3e797d540e..eb97522667 100644 --- a/src/lib/dhcp/option4_client_fqdn.cc +++ b/src/lib/dhcp/option4_client_fqdn.cc @@ -237,7 +237,7 @@ Option4ClientFqdnImpl::parseASCIIDomainName(OptionBufferConstIter first, domain_name_.reset(new isc::dns::Name(domain_name)); domain_name_type_ = domain_name[domain_name.length() - 1] == '.' ? Option4ClientFqdn::FULL : Option4ClientFqdn::PARTIAL; - } + } } Option4ClientFqdn::Option4ClientFqdn(const uint8_t flag, const Rcode& rcode) diff --git a/src/lib/dhcp/option_definition.cc b/src/lib/dhcp/option_definition.cc index bf2c5fb4a8..1b87bff6ed 100644 --- a/src/lib/dhcp/option_definition.cc +++ b/src/lib/dhcp/option_definition.cc @@ -12,8 +12,10 @@ // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. +#include #include #include +#include #include #include #include @@ -184,6 +186,10 @@ OptionDefinition::optionFactory(Option::Universe u, uint16_t type, // for IA_NA and IA_PD above. return (factoryIAAddr6(type, begin, end)); } + } else { + if ((code_ == DHO_FQDN) && haveFqdn4Format()) { + return (OptionPtr(new Option4ClientFqdn(begin, end))); + } } } return (OptionPtr(new OptionCustom(*this, u, begin, end))); @@ -341,6 +347,16 @@ OptionDefinition::haveIAAddr6Format() const { return (haveIAx6Format(OPT_IPV6_ADDRESS_TYPE)); } +bool +OptionDefinition::haveFqdn4Format() const { + return (haveType(OPT_RECORD_TYPE) && + record_fields_.size() == 4 && + record_fields_[0] == OPT_UINT8_TYPE && + record_fields_[1] == OPT_UINT8_TYPE && + record_fields_[2] == OPT_UINT8_TYPE && + record_fields_[3] == OPT_FQDN_TYPE); +} + template T OptionDefinition::lexicalCastWithRangeCheck(const std::string& value_str) const { // Lexical cast in case of our data types make sense only diff --git a/src/lib/dhcp/option_definition.h b/src/lib/dhcp/option_definition.h index dcfc3c7a9a..0472d012fd 100644 --- a/src/lib/dhcp/option_definition.h +++ b/src/lib/dhcp/option_definition.h @@ -275,6 +275,21 @@ public: /// @return true if specified format is IAADDR option format. bool haveIAAddr6Format() const; + /// @brief Check if option has format of the DHCPv4 Client FQDN + /// %Option. + /// + /// The encoding of the domain-name carried by the FQDN option is + /// conditional and is specified in the flags field of the option. + /// The domain-name can be encoded in the ASCII format or canonical + /// wire format. The ASCII format is deprecated, therefore canonical + /// format is selected for the FQDN option definition and this function + /// returns true if the option definition comprises the domain-name + /// field encoded in canonical format. + /// + /// @return true if option has the format of DHCPv4 Client FQDN + /// %Option. + bool haveFqdn4Format() const; + /// @brief Option factory. /// /// This function creates an instance of DHCP option using diff --git a/src/lib/dhcp/std_option_defs.h b/src/lib/dhcp/std_option_defs.h index 9bd19a1102..00acdab5d1 100644 --- a/src/lib/dhcp/std_option_defs.h +++ b/src/lib/dhcp/std_option_defs.h @@ -62,7 +62,8 @@ struct OptionDefParams { // RFC 1035, section 3.1. The latter could be handled // by OPT_FQDN_TYPE but we can't use it here because // clients may request ASCII encoding. -RECORD_DECL(FQDN_RECORDS, OPT_UINT8_TYPE, OPT_UINT8_TYPE, OPT_STRING_TYPE); +RECORD_DECL(FQDN_RECORDS, OPT_UINT8_TYPE, OPT_UINT8_TYPE, OPT_UINT8_TYPE, + OPT_FQDN_TYPE); /// @brief Definitions of standard DHCPv4 options. const OptionDefParams OPTION_DEF_PARAMS4[] = { diff --git a/src/lib/dhcp/tests/libdhcp++_unittest.cc b/src/lib/dhcp/tests/libdhcp++_unittest.cc index d523158dd6..e4d723fd9c 100644 --- a/src/lib/dhcp/tests/libdhcp++_unittest.cc +++ b/src/lib/dhcp/tests/libdhcp++_unittest.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -733,8 +734,8 @@ TEST_F(LibDhcpTest, stdOptionDefs4) { LibDhcpTest::testStdOptionDefs4(DHO_USER_CLASS, begin, end, typeid(Option)); - LibDhcpTest::testStdOptionDefs4(DHO_FQDN, begin, end, - typeid(OptionCustom)); + LibDhcpTest::testStdOptionDefs4(DHO_FQDN, begin, begin + 3, + typeid(Option4ClientFqdn)); LibDhcpTest::testStdOptionDefs4(DHO_DHCP_AGENT_OPTIONS, begin, end, typeid(Option), "dhcp-agent-options-space");