BIND 10 pd-ietf-demo2, updated. 67c66cf3dba200a791e6333b4e46bfeb60fad473 Merge branch 'trac3211' into pd-ietf-demo2

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Oct 25 13:03:04 UTC 2013


The branch, pd-ietf-demo2 has been updated
       via  67c66cf3dba200a791e6333b4e46bfeb60fad473 (commit)
       via  73f5dbc9171e68066f78da6a00309321a81e67d8 (commit)
       via  fab2fd65c02fe2e215a004b094916c449f6d994c (commit)
       via  c9c132e4cb353b7fbe16e5c98ef72f8c7e498f81 (commit)
      from  1990382bc3ddab6db6d69baa9650e216d908e27d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 67c66cf3dba200a791e6333b4e46bfeb60fad473
Merge: 73f5dbc fab2fd6
Author: Tomek Mrugalski <tomasz at isc.org>
Date:   Fri Oct 25 15:01:55 2013 +0200

    Merge branch 'trac3211' into pd-ietf-demo2

commit 73f5dbc9171e68066f78da6a00309321a81e67d8
Merge: 1990382 c9c132e
Author: Tomek Mrugalski <tomasz at isc.org>
Date:   Fri Oct 25 15:01:45 2013 +0200

    Merge branch 'trac3207' into pd-ietf-demo2

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog                                |    4 ++
 src/hooks/dhcp/user_chk/pkt_send_co.cc   |   82 +++++++++++++++++++++++-------
 src/lib/dhcp/option_definition.cc        |   29 ++++++++++-
 src/lib/dhcp/option_definition.h         |   18 +++++++
 src/lib/dhcp/std_option_defs.h           |    2 +-
 src/lib/dhcp/tests/libdhcp++_unittest.cc |    5 +-
 6 files changed, 117 insertions(+), 23 deletions(-)

-----------------------------------------------------------------------
diff --git a/ChangeLog b/ChangeLog
index e5e0e5f..0eb01b3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+7XX.	[bug]		tomek
+	libdhcp++: Incoming IAPREFIX option is now parsed properly.
+	(Trac #3211, git ABCD)
+
 700.	[func]		tomek,marcin
 	b10-dhcp4,b10-dhcp6: Support for vendor options has been added. It
 	is now possible to configure vendor options. Server is able to
diff --git a/src/hooks/dhcp/user_chk/pkt_send_co.cc b/src/hooks/dhcp/user_chk/pkt_send_co.cc
index 4e9c6b6..24fc62e 100644
--- a/src/hooks/dhcp/user_chk/pkt_send_co.cc
+++ b/src/hooks/dhcp/user_chk/pkt_send_co.cc
@@ -16,7 +16,9 @@
 
 #include <asiolink/io_address.h>
 #include <hooks/hooks.h>
+#include <dhcp/dhcp4.h>
 #include <dhcp/dhcp6.h>
+#include <dhcp/option_string.h>
 #include <dhcp/option_custom.h>
 #include <dhcp/option6_ia.h>
 #include <dhcp/option6_iaaddr.h>
@@ -43,6 +45,9 @@ extern std::string getAddrStrIA_NA(OptionPtr options);
 extern std::string getAddrStrIA_PD(OptionPtr options);
 extern bool checkIAStatus(boost::shared_ptr<Option6IA>& ia_opt);
 
+extern void add4Options(Pkt4Ptr& response, UserPtr& user);
+extern void add6Options(Pkt6Ptr& response, UserPtr& user);
+
 /// @brief  This callout is called at the "pkt4_send" hook.
 ///
 /// This function searches the UserRegistry for the client indicated by the
@@ -56,18 +61,13 @@ int pkt4_send(CalloutHandle& handle) {
         Pkt4Ptr response;
         handle.getArgument("response4", response);
 
-        // @todo do we need to filter on type?
-#if 0
         uint8_t packet_type = response->getType();
-        std::cout << "PACKET TYPE IS: " <<
-                  static_cast<int>(packet_type) << std::endl;
-
-        if ((packet_type != DHCPOFFER) && (packet_type != DHCPACK)) {
-            std::cout << "SKIPPING PACKET TYPE IS: "
+        if (packet_type == DHCPNAK) {
+            std::cout << "DHCP UserCheckHook : pkt4_send"
+                      << "skipping packet type: "
                       << static_cast<int>(packet_type) << std::endl;
             return (0);
         }
-#endif
 
         // Get the user id saved from the query packet.
         HWAddrPtr hwaddr;
@@ -89,6 +89,7 @@ int pkt4_send(CalloutHandle& handle) {
             // Add the outcome entry to the output file.
             generate_output_record(UserId::HW_ADDRESS_STR, hwaddr->toText(),
                                    addr.toText(), true);
+            add4Options(response, registered_user);
         } else {
             // add default options based
             // then generate not registered output record
@@ -97,6 +98,8 @@ int pkt4_send(CalloutHandle& handle) {
             // Add the outcome entry to the output file.
             generate_output_record(UserId::HW_ADDRESS_STR, hwaddr->toText(),
                                    addr.toText(), false);
+            // @todo store defaults in a defualt user
+            // add4Options(response, default_user4);
         }
     } catch (const std::exception& ex) {
         std::cout << "DHCP UserCheckHook : pkt4_send unexpected error: "
@@ -107,6 +110,51 @@ int pkt4_send(CalloutHandle& handle) {
     return (0);
 }
 
+void add4Options(Pkt4Ptr& response, UserPtr& user) {
+    std::string bootfile = user->getProperty("bootfile");
+    if (!bootfile.empty()) {
+        std::cout << "DHCP UserCheckHook : add4Options "
+              << "adding boot file:" << bootfile << std::endl;
+
+        // Set file field
+        response->setFile((const uint8_t*)(bootfile.c_str()),
+                          bootfile.length());
+
+        // Remove the option if it exists.
+        OptionPtr boot_opt = response->getOption(DHO_BOOT_FILE_NAME);
+        if (boot_opt) {
+            response->delOption(DHO_BOOT_FILE_NAME);
+        }
+
+        // Now add the boot file option.
+        boot_opt.reset(new OptionString(Option::V4, DHO_BOOT_FILE_NAME,
+                                        bootfile));
+
+        response->addOption(boot_opt);
+    }
+    // add next option here
+}
+
+void add6Options(Pkt6Ptr& response, UserPtr& user) {
+    std::string bootfile = user->getProperty("bootfile");
+    if (!bootfile.empty()) {
+        std::cout << "DHCP UserCheckHook : add6Options "
+                  << "adding boot file:" << bootfile << std::endl;
+        OptionPtr vendor = response->getOption(D6O_VENDOR_OPTS);
+        if (vendor) {
+            /// @todo: This will be DOCSIS3_V6_CONFIG_FILE.
+            /// Unfortunately, 3207 was branched from master before
+            /// 3194 was merged in, so this branch does not have
+            /// src/lib/dhcp/docsis3_option_defs.h.
+            vendor->delOption(33);
+            OptionPtr boot_opt(new OptionString(Option::V6, 33,
+                                                bootfile));
+            vendor->addOption(boot_opt);
+        }
+    }
+    // add next option here
+}
+
 /// @brief  This callout is called at the "pkt6_send" hook.
 ///
 /// This function searches the UserRegistry for the client indicated by the
@@ -120,19 +168,13 @@ int pkt6_send(CalloutHandle& handle) {
         Pkt6Ptr response;
         handle.getArgument("response6", response);
 
-        // @todo do we need to filter on type?
-#if 0
         uint8_t packet_type = response->getType();
-        std::cout << "PACKET TYPE IS: " <<
-                  static_cast<int>(packet_type) << std::endl;
-
-        if ((packet_type != DHCPV6_ADVERTISE) &&
-            (packet_type != DHCPV6_REPLY)) {
-            std::cout << "SKIPPING PACKET TYPE IS: "
+        if (packet_type == DHCPV6_DECLINE) {
+            std::cout << "DHCP UserCheckHook : pkt6_send"
+                      << "skipping packet type: "
                       << static_cast<int>(packet_type) << std::endl;
             return (0);
         }
-#endif
 
         // Fetch the lease address as a string
         std::string addr_str = getV6AddrStr(response);
@@ -159,6 +201,7 @@ int pkt6_send(CalloutHandle& handle) {
             // Add the outcome entry to the output file.
             generate_output_record(UserId::DUID_STR, duid->toText(),
                                    addr_str, true);
+            add6Options(response, registered_user);
         } else {
             // add default options based
             // then generate not registered output record
@@ -167,6 +210,8 @@ int pkt6_send(CalloutHandle& handle) {
             // Add the outcome entry to the output file.
             generate_output_record(UserId::DUID_STR, duid->toText(),
                                    addr_str, false);
+            // @todo store defaults in a default user
+            //add6Options(response, default_user6);
         }
     } catch (const std::exception& ex) {
         std::cout << "DHCP UserCheckHook : pkt6_send unexpected error: "
@@ -228,7 +273,8 @@ void generate_output_record(const std::string& id_type_str,
                     << "client=" << id_val_str << std::endl
                     << "addr=" << addr_str << std::endl
                     << "registered=" << (registered ? "yes" : "no")
-                    << std::endl;
+                    << std::endl
+                    << std::endl;   // extra line in between
 
     // @todo Flush is here to ensure output is immediate for demo purposes.
     // Performance would generally dictate not using it.
diff --git a/src/lib/dhcp/option_definition.cc b/src/lib/dhcp/option_definition.cc
index 952c758..be1a5e7 100644
--- a/src/lib/dhcp/option_definition.cc
+++ b/src/lib/dhcp/option_definition.cc
@@ -19,6 +19,7 @@
 #include <dhcp/option6_addrlst.h>
 #include <dhcp/option6_ia.h>
 #include <dhcp/option6_iaaddr.h>
+#include <dhcp/option6_iaprefix.h>
 #include <dhcp/option6_client_fqdn.h>
 #include <dhcp/option_custom.h>
 #include <dhcp/option_definition.h>
@@ -361,6 +362,16 @@ OptionDefinition::haveIAAddr6Format() const {
 }
 
 bool
+OptionDefinition::haveIAPrefix6Format() const {
+    return (haveType(OPT_RECORD_TYPE) &&
+            record_fields_.size() == 4 &&
+            record_fields_[0] == OPT_UINT32_TYPE &&
+            record_fields_[1] == OPT_UINT32_TYPE &&
+            record_fields_[2] == OPT_UINT8_TYPE &&
+            record_fields_[3] == OPT_IPV6_ADDRESS_TYPE);
+}
+
+bool
 OptionDefinition::haveFqdn4Format() const {
     return (haveType(OPT_RECORD_TYPE) &&
             record_fields_.size() == 4 &&
@@ -571,6 +582,20 @@ OptionDefinition::factoryIAAddr6(uint16_t type,
 }
 
 OptionPtr
+OptionDefinition::factoryIAPrefix6(uint16_t type,
+                                 OptionBufferConstIter begin,
+                                 OptionBufferConstIter end) {
+    if (std::distance(begin, end) < Option6IAPrefix::OPTION6_IAPREFIX_LEN) {
+        isc_throw(isc::OutOfRange,
+                  "input option buffer has invalid size, expected at least "
+                  << Option6IAPrefix::OPTION6_IAPREFIX_LEN << " bytes");
+    }
+    boost::shared_ptr<Option6IAPrefix> option(new Option6IAPrefix(type, begin,
+                                                                  end));
+    return (option);
+}
+
+OptionPtr
 OptionDefinition::factorySpecialFormatOption(Option::Universe u,
                                              OptionBufferConstIter begin,
                                              OptionBufferConstIter end,
@@ -593,15 +618,15 @@ OptionDefinition::factorySpecialFormatOption(Option::Universe u,
             // option only for the same reasons as described in
             // for IA_NA and IA_PD above.
             return (factoryIAAddr6(getCode(), begin, end));
+        } else if (getCode() == D6O_IAPREFIX && haveIAPrefix6Format()) {
+            return (factoryIAPrefix6(getCode(), begin, end));
         } else if (getCode() == D6O_CLIENT_FQDN && haveClientFqdnFormat()) {
             // FQDN option requires special processing. Thus, there is
             // a specialized class to handle it.
             return (OptionPtr(new Option6ClientFqdn(begin, end)));
-
         } else if (getCode() == D6O_VENDOR_OPTS && haveVendor6Format()) {
             // Vendor-Specific Information.
             return (OptionPtr(new OptionVendor(Option::V6, begin, end)));
-
         }
     } else {
         if ((getCode() == DHO_FQDN) && haveFqdn4Format()) {
diff --git a/src/lib/dhcp/option_definition.h b/src/lib/dhcp/option_definition.h
index 7db32fa..8f2d367 100644
--- a/src/lib/dhcp/option_definition.h
+++ b/src/lib/dhcp/option_definition.h
@@ -276,6 +276,11 @@ public:
     /// @return true if specified format is IAADDR option format.
     bool haveIAAddr6Format() const;
 
+    /// @brief Check if specified format is IAPREFIX option format.
+    ///
+    /// @return true if specified format is IAPREFIX option format.
+    bool haveIAPrefix6Format() const;
+
     /// @brief Check if specified format is OPTION_CLIENT_FQDN option format.
     ///
     /// @return true of specified format is OPTION_CLIENT_FQDN option format,
@@ -466,6 +471,19 @@ public:
                                     OptionBufferConstIter begin,
                                     OptionBufferConstIter end);
 
+    /// @brief Factory for IAPREFIX-type of option.
+    ///
+    /// @param type option type.
+    /// @param begin iterator pointing to the beginning of the buffer.
+    /// @param end iterator pointing to the end of the buffer.
+    ///
+    /// @throw isc::OutOfRange if provided option buffer is too short or
+    /// too long. Expected size is 25 bytes.
+    /// @throw isc::BadValue if specified universe value is not V6.
+    static OptionPtr factoryIAPrefix6(uint16_t type,
+                                      OptionBufferConstIter begin,
+                                      OptionBufferConstIter end);
+
     /// @brief Factory function to create option with integer value.
     ///
     /// @param u universe (V4 or V6).
diff --git a/src/lib/dhcp/std_option_defs.h b/src/lib/dhcp/std_option_defs.h
index e887760..865407e 100644
--- a/src/lib/dhcp/std_option_defs.h
+++ b/src/lib/dhcp/std_option_defs.h
@@ -220,7 +220,7 @@ RECORD_DECL(IA_NA_RECORDS, OPT_UINT32_TYPE, OPT_UINT32_TYPE, OPT_UINT32_TYPE);
 RECORD_DECL(IA_PD_RECORDS, OPT_UINT32_TYPE, OPT_UINT32_TYPE, OPT_UINT32_TYPE);
 // ia-prefix
 RECORD_DECL(IA_PREFIX_RECORDS, OPT_UINT32_TYPE, OPT_UINT32_TYPE,
-            OPT_UINT8_TYPE, OPT_IPV6_ADDRESS_TYPE, OPT_BINARY_TYPE);
+            OPT_UINT8_TYPE, OPT_IPV6_ADDRESS_TYPE);
 // lq-query
 RECORD_DECL(LQ_QUERY_RECORDS, OPT_UINT8_TYPE, OPT_IPV6_ADDRESS_TYPE);
 // lq-relay-data
diff --git a/src/lib/dhcp/tests/libdhcp++_unittest.cc b/src/lib/dhcp/tests/libdhcp++_unittest.cc
index 46c5947..76d1f64 100644
--- a/src/lib/dhcp/tests/libdhcp++_unittest.cc
+++ b/src/lib/dhcp/tests/libdhcp++_unittest.cc
@@ -23,6 +23,7 @@
 #include <dhcp/option6_client_fqdn.h>
 #include <dhcp/option6_ia.h>
 #include <dhcp/option6_iaaddr.h>
+#include <dhcp/option6_iaprefix.h>
 #include <dhcp/option_custom.h>
 #include <dhcp/option_int.h>
 #include <dhcp/option_int_array.h>
@@ -1043,8 +1044,8 @@ TEST_F(LibDhcpTest, stdOptionDefs6) {
     LibDhcpTest::testStdOptionDefs6(D6O_IA_PD, begin, end,
                                     typeid(Option6IA));
 
-    LibDhcpTest::testStdOptionDefs6(D6O_IAPREFIX, begin, end,
-                                    typeid(OptionCustom));
+    LibDhcpTest::testStdOptionDefs6(D6O_IAPREFIX, begin, begin + 25,
+                                    typeid(Option6IAPrefix));
 
     LibDhcpTest::testStdOptionDefs6(D6O_NIS_SERVERS, begin, end,
                                     typeid(Option6AddrLst));



More information about the bind10-changes mailing list