Browse Source

[3486] DHCPv6 now processed vendor-class option properly.

Tomek Mrugalski 10 years ago
parent
commit
62409cd953
3 changed files with 39 additions and 2 deletions
  1. 6 0
      ChangeLog
  2. 1 2
      src/bin/dhcp6/dhcp6_srv.cc
  3. 32 0
      src/bin/dhcp6/tests/dhcp6_srv_unittest.cc

+ 6 - 0
ChangeLog

@@ -1,3 +1,9 @@
+8xx.	[bug]		tomek
+	DHCPv6 component now processes incoming vendor-class options
+	properly (packets are classified as VENDOR_CLASS_[content of the
+	vendor-class option]).
+	(Trac #3486, git tbd)
+
 848.	[func]		fdupont
 	Added truncated HMAC support to TSIG, as per RFC 4635.
 	(Trac #3593, git ae3a9cd1a0d2dc07b7092368149381d69bc2c61a)

+ 1 - 2
src/bin/dhcp6/dhcp6_srv.cc

@@ -2555,8 +2555,7 @@ void Dhcpv6Srv::classifyPacket(const Pkt6Ptr& pkt) {
         classes << VENDOR_CLASS_PREFIX << DOCSIS3_CLASS_EROUTER;
 
     } else {
-        classes << vclass->getTuple(0).getText();
-
+        classes << VENDOR_CLASS_PREFIX << vclass->getTuple(0).getText();
     }
 
     // If there is no class identified, leave.

+ 32 - 0
src/bin/dhcp6/tests/dhcp6_srv_unittest.cc

@@ -25,6 +25,7 @@
 #include <dhcp/option_int_array.h>
 #include <dhcp/option_string.h>
 #include <dhcp/option_vendor.h>
+#include <dhcp/option_vendor_class.h>
 #include <dhcp/iface_mgr.h>
 #include <dhcp6/json_config_parser.h>
 #include <dhcp/dhcp6.h>
@@ -1849,6 +1850,37 @@ TEST_F(Dhcpv6SrvTest, clientClassify2) {
     EXPECT_TRUE(srv_.selectSubnet(sol));
 }
 
+// Tests whether a packet with custom vendor-class (not erouter or docsis)
+// is classified properly.
+TEST_F(Dhcpv6SrvTest, clientClassification3) {
+    NakedDhcpv6Srv srv(0);
+
+    // Let's create a SOLICIT.
+    Pkt6Ptr sol = Pkt6Ptr(new Pkt6(DHCPV6_SOLICIT, 1234));
+    sol->setRemoteAddr(IOAddress("2001:db8:1::3"));
+    sol->addOption(generateIA(D6O_IA_NA, 234, 1500, 3000));
+    OptionPtr clientid = generateClientId();
+    sol->addOption(clientid);
+
+    // Now let's add a vendor-class with id=1234 and content "foo"
+    OptionVendorClassPtr vendor_class(new OptionVendorClass(Option::V6, 1234));
+    OpaqueDataTuple tuple(OpaqueDataTuple::LENGTH_2_BYTES);
+    tuple = "foo";
+    vendor_class->addTuple(tuple);
+    sol->addOption(vendor_class);
+
+    // Now the server classifies the packet.
+    srv.classifyPacket(sol);
+
+    // The packet should now belong to VENDOR_CLASS_foo.
+    EXPECT_TRUE(sol->inClass(srv.VENDOR_CLASS_PREFIX + "foo"));
+
+    // It should not belong to "foo"
+    EXPECT_FALSE(sol->inClass("foo"));
+
+}
+
+
 // This test checks that the server will handle a Solicit with the Vendor Class
 // having a length of 4 (enterprise-id only).
 TEST_F(Dhcpv6SrvTest, cableLabsShortVendorClass) {