]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3316] Merge branch 'master' into trac3316
authorMarcin Siodelski <marcin@isc.org>
Tue, 18 Feb 2014 14:11:27 +0000 (15:11 +0100)
committerMarcin Siodelski <marcin@isc.org>
Tue, 18 Feb 2014 14:11:27 +0000 (15:11 +0100)
Conflicts:
src/bin/dhcp4/tests/dhcp4_test_utils.h
src/bin/dhcp6/tests/dhcp6_srv_unittest.cc
src/bin/dhcp6/tests/dhcp6_test_utils.h

1  2 
src/bin/dhcp4/dhcp4_srv.cc
src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
src/bin/dhcp4/tests/dhcp4_test_utils.h
src/bin/dhcp6/dhcp6_srv.cc
src/bin/dhcp6/tests/dhcp6_srv_unittest.cc
src/bin/dhcp6/tests/dhcp6_test_utils.h
src/bin/dhcp6/tests/wireshark.cc
src/lib/dhcp/std_option_defs.h
src/lib/dhcp/tests/Makefile.am

Simple merge
index 0cc07b4747379df1037f170dbcae33e1fe9442b2,ba787aa4d66703c0d02bf6f58ce3861f9e77c8a2..af2d0adac1d0b179d2b444e1271439603c07be3d
@@@ -3305,10 -3305,74 +3305,74 @@@ TEST_F(Dhcpv4SrvTest, clientClassificat
  
      srv.classifyPacket(dis2);
  
 -    EXPECT_TRUE(dis2->inClass("eRouter1.0"));
 -    EXPECT_FALSE(dis2->inClass("docsis3.0"));
 +    EXPECT_TRUE(dis2->inClass(srv.VENDOR_CLASS_PREFIX + "eRouter1.0"));
 +    EXPECT_FALSE(dis2->inClass(srv.VENDOR_CLASS_PREFIX + "docsis3.0"));
  }
  
+ // Checks if the client-class field is indeed used for subnet selection.
+ // Note that packet classification is already checked in Dhcpv4SrvTest
+ // .clientClassification above.
+ TEST_F(Dhcpv4SrvTest, clientClassify2) {
+     NakedDhcpv4Srv srv(0);
+     ConstElementPtr status;
+     // This test configures 2 subnets. We actually only need the
+     // first one, but since there's still this ugly hack that picks
+     // the pool if there is only one, we must use more than one
+     // subnet. That ugly hack will be removed in #3242, currently
+     // under review.
+     // The second subnet does not play any role here. The client's
+     // IP address belongs to the first subnet, so only that first
+     // subnet it being tested.
+     string config = "{ \"interfaces\": [ \"*\" ],"
+         "\"rebind-timer\": 2000, "
+         "\"renew-timer\": 1000, "
+         "\"subnet4\": [ "
+         "{   \"pool\": [ \"192.0.2.1 - 192.0.2.100\" ],"
+         "    \"client-class\": \"foo\", "
+         "    \"subnet\": \"192.0.2.0/24\" }, "
+         "{   \"pool\": [ \"192.0.3.1 - 192.0.3.100\" ],"
+         "    \"client-class\": \"xyzzy\", "
+         "    \"subnet\": \"192.0.3.0/24\" } "
+         "],"
+         "\"valid-lifetime\": 4000 }";
+     ElementPtr json = Element::fromJSON(config);
+     EXPECT_NO_THROW(status = configureDhcp4Server(srv, json));
+     // check if returned status is OK
+     ASSERT_TRUE(status);
+     comment_ = config::parseAnswer(rcode_, status);
+     ASSERT_EQ(0, rcode_);
+     Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234));
+     dis->setRemoteAddr(IOAddress("192.0.2.1"));
+     dis->setCiaddr(IOAddress("192.0.2.1"));
+     dis->setIface("eth0");
+     OptionPtr clientid = generateClientId();
+     dis->addOption(clientid);
+     // This discover does not belong to foo class, so it will not
+     // be serviced
+     EXPECT_FALSE(srv.selectSubnet(dis));
+     // Let's add the packet to bar class and try again.
+     dis->addClass("bar");
+     // Still not supported, because it belongs to wrong class.
+     EXPECT_FALSE(srv.selectSubnet(dis));
+     // Let's add it to maching class.
+     dis->addClass("foo");
+     // This time it should work
+     EXPECT_TRUE(srv.selectSubnet(dis));
+ }
  // This test verifies that the direct message is dropped when it has been
  // received by the server via an interface for which there is no subnet
  // configured. It also checks that the message is not dropped (is processed)
index cbe6b8ddfae26d9229caaba3ba7594d6c8d3bf56,5090c7ddd2ced10fa3132d9a5d46e8a03894a60a..025ac4eb097dd4cba9db8a0a25de1c5411029779
@@@ -199,8 -199,7 +199,8 @@@ public
      using Dhcpv4Srv::classifyPacket;
      using Dhcpv4Srv::accept;
      using Dhcpv4Srv::acceptMessageType;
+     using Dhcpv4Srv::selectSubnet;
 +    using Dhcpv4Srv::VENDOR_CLASS_PREFIX;
  };
  
  class Dhcpv4SrvTest : public ::testing::Test {
Simple merge
index bac697369fd4710b4e821855ca7dfaf23e08f8b6,ea3692e005ed04c3343379367ebb32c42217a359..290011827853b7e598021dc570bbdd587bb891d2
@@@ -1734,35 -1736,76 +1736,101 @@@ TEST_F(Dhcpv6SrvTest, clientClassificat
  
      srv.classifyPacket(sol2);
  
 -    EXPECT_TRUE(sol2->inClass("eRouter1.0"));
 -    EXPECT_FALSE(sol2->inClass("docsis3.0"));
 +    EXPECT_TRUE(sol2->inClass(srv.VENDOR_CLASS_PREFIX + "eRouter1.0"));
 +    EXPECT_FALSE(sol2->inClass(srv.VENDOR_CLASS_PREFIX + "docsis3.0"));
  }
  
+ // Checks if the client-class field is indeed used for subnet selection.
+ // Note that packet classification is already checked in Dhcpv6SrvTest
+ // .clientClassification above.
+ TEST_F(Dhcpv6SrvTest, clientClassify2) {
+     NakedDhcpv6Srv srv(0);
+     ConstElementPtr status;
+     // This test configures 2 subnets. We actually only need the
+     // first one, but since there's still this ugly hack that picks
+     // the pool if there is only one, we must use more than one
+     // subnet. That ugly hack will be removed in #3242, currently
+     // under review.
+     // The second subnet does not play any role here. The client's
+     // IP address belongs to the first subnet, so only that first
+     // subnet it being tested.
+     string config = "{ \"interfaces\": [ \"*\" ],"
+         "\"preferred-lifetime\": 3000,"
+         "\"rebind-timer\": 2000, "
+         "\"renew-timer\": 1000, "
+         "\"subnet6\": [ "
+         " {  \"pool\": [ \"2001:db8:1::/64\" ],"
+         "    \"subnet\": \"2001:db8:1::/48\", "
+         "    \"client-class\": \"foo\" "
+         " }, "
+         " {  \"pool\": [ \"2001:db8:2::/64\" ],"
+         "    \"subnet\": \"2001:db8:2::/48\", "
+         "    \"client-class\": \"xyzzy\" "
+         " } "
+         "],"
+         "\"valid-lifetime\": 4000 }";
+     ElementPtr json = Element::fromJSON(config);
+     EXPECT_NO_THROW(status = configureDhcp6Server(srv, json));
+     // check if returned status is OK
+     ASSERT_TRUE(status);
+     comment_ = config::parseAnswer(rcode_, status);
+     ASSERT_EQ(0, rcode_);
+     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);
+     // This discover does not belong to foo class, so it will not
+     // be serviced
+     EXPECT_FALSE(srv.selectSubnet(sol));
+     // Let's add the packet to bar class and try again.
+     sol->addClass("bar");
+     // Still not supported, because it belongs to wrong class.
+     EXPECT_FALSE(srv.selectSubnet(sol));
+     // Let's add it to maching class.
+     sol->addClass("foo");
+     // This time it should work
+     EXPECT_TRUE(srv.selectSubnet(sol));
+ }
 +// 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) {
 +    NakedDhcpv6Srv srv(0);
 +
 +    // Create a simple Solicit with the 4-byte long vendor class option.
 +    Pkt6Ptr sol = captureCableLabsShortVendorClass();
 +
 +    // Simulate that we have received that traffic
 +    srv.fakeReceive(sol);
 +
 +    // Server will now process to run its normal loop, but instead of calling
 +    // IfaceMgr::receive6(), it will read all packets from the list set by
 +    // fakeReceive()
 +    srv.run();
 +
 +    // Get Advertise...
 +    ASSERT_FALSE(srv.fake_sent_.empty());
 +    Pkt6Ptr adv = srv.fake_sent_.front();
 +    ASSERT_TRUE(adv);
 +
 +    // This is sent back to client, so port is 546
 +    EXPECT_EQ(DHCP6_CLIENT_PORT, adv->getRemotePort());
 +
 +}
  
  /// @todo: Add more negative tests for processX(), e.g. extend sanityCheck() test
  /// to call processX() methods.
index 971ddb58ecabe756e6cfe7dcc9e1cdcb8f82a720,beac1ef3e999bf018028b1df926a3ffdac31b7a3..f680e335c91f5c12767109f23ceefd842d1e2526
@@@ -477,11 -504,10 +505,11 @@@ public
      // see wireshark.cc for descriptions
      // The descriptions are too large and too closely related to the
      // code, so it is kept in .cc rather than traditionally in .h
-     Pkt6Ptr captureSimpleSolicit();
-     Pkt6Ptr captureRelayedSolicit();
-     Pkt6Ptr captureDocsisRelayedSolicit();
-     Pkt6Ptr captureeRouterRelayedSolicit();
-     Pkt6Ptr captureCableLabsShortVendorClass();
+     isc::dhcp::Pkt6Ptr captureSimpleSolicit();
+     isc::dhcp::Pkt6Ptr captureRelayedSolicit();
+     isc::dhcp::Pkt6Ptr captureDocsisRelayedSolicit();
+     isc::dhcp::Pkt6Ptr captureeRouterRelayedSolicit();
++    isc::dhcp::Pkt6Ptr captureCableLabsShortVendorClass();
  
      /// @brief Auxiliary method that sets Pkt6 fields
      ///
Simple merge
Simple merge
Simple merge