Browse Source

[4097a] Split classifyPacket into 2 parts as proposed

Francis Dupont 9 years ago
parent
commit
01dd8b4fa3
2 changed files with 21 additions and 9 deletions
  1. 8 5
      src/bin/dhcp4/dhcp4_srv.cc
  2. 13 4
      src/bin/dhcp4/dhcp4_srv.h

+ 8 - 5
src/bin/dhcp4/dhcp4_srv.cc

@@ -2243,15 +2243,13 @@ Dhcpv4Srv::unpackOptions(const OptionBuffer& buf,
     return (offset);
 }
 
-void Dhcpv4Srv::classifyPacket(const Pkt4Ptr& pkt) {
-    string classes = "";
-
+void Dhcpv4Srv::classifyByVendor(const Pkt4Ptr& pkt, std::string& classes) {
     // Built-in vendor class processing
     boost::shared_ptr<OptionString> vendor_class =
         boost::dynamic_pointer_cast<OptionString>(pkt->getOption(DHO_VENDOR_CLASS_IDENTIFIER));
 
     if (!vendor_class) {
-        goto vendor_class_done;
+        return;
     }
 
     // DOCSIS specific section
@@ -2281,8 +2279,13 @@ void Dhcpv4Srv::classifyPacket(const Pkt4Ptr& pkt) {
         pkt->addClass(VENDOR_CLASS_PREFIX + vendor_class->getValue());
         classes += VENDOR_CLASS_PREFIX + vendor_class->getValue();
     }
+}
+
+void Dhcpv4Srv::classifyPacket(const Pkt4Ptr& pkt) {
+    string classes = "";
 
-vendor_class_done:
+    // First phase: built-in vendor class processing
+    classifyByVendor(pkt, classes);
 
     // Run match expressions
     // Note getClientClassDictionary() cannot be null

+ 13 - 4
src/bin/dhcp4/dhcp4_srv.h

@@ -707,10 +707,11 @@ protected:
     /// @brief Assigns incoming packet to zero or more classes.
     ///
     /// @note It is done in two phases: first the content of the
-    /// vendor-class-identifier option is used as a class. Second
-    /// classification match expressions are evaluated. The resulting
-    /// class will be stored in packet (see @ref isc::dhcp::Pkt4::classes_
-    /// and @ref isc::dhcp::Pkt4::inClass).
+    /// vendor-class-identifier option is used as a class, by
+    /// calling @ref classifyByVendor(). Second classification match
+    /// expressions are evaluated. The resulting class will be stored
+    /// in packet (see @ref isc::dhcp::Pkt4::classes_ and
+    /// @ref isc::dhcp::Pkt4::inClass).
     ///
     /// @param pkt packet to be classified
     void classifyPacket(const Pkt4Ptr& pkt);
@@ -735,6 +736,14 @@ protected:
 
 private:
 
+    /// @brief Assign class using vendor-class-identifier option
+    ///
+    /// @note This is the first part of @ref classifyPacket
+    ///
+    /// @param pkt packet to be classified
+    /// @param classes a reference to added class names for logging
+    void classifyByVendor(const Pkt4Ptr& pkt, std::string& classes);
+
     /// @brief Constructs netmask option based on subnet4
     /// @param subnet subnet for which the netmask will be calculated
     ///