Browse Source

[3082] Return instance of the Option4ClientFqdn for option 81.

Marcin Siodelski 11 years ago
parent
commit
cf24637df0

+ 1 - 1
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)

+ 16 - 0
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 <dhcp/dhcp4.h>
 #include <dhcp/dhcp6.h>
 #include <dhcp/option4_addrlst.h>
+#include <dhcp/option4_client_fqdn.h>
 #include <dhcp/option6_addrlst.h>
 #include <dhcp/option6_ia.h>
 #include <dhcp/option6_iaaddr.h>
@@ -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<typename T>
 T OptionDefinition::lexicalCastWithRangeCheck(const std::string& value_str) const {
     // Lexical cast in case of our data types make sense only

+ 15 - 0
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

+ 2 - 1
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[] = {

+ 3 - 2
src/lib/dhcp/tests/libdhcp++_unittest.cc

@@ -18,6 +18,7 @@
 #include <dhcp/dhcp6.h>
 #include <dhcp/libdhcp++.h>
 #include <dhcp/option4_addrlst.h>
+#include <dhcp/option4_client_fqdn.h>
 #include <dhcp/option6_addrlst.h>
 #include <dhcp/option6_ia.h>
 #include <dhcp/option6_iaaddr.h>
@@ -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");