]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
Merge branch 'isc-master' into cassandra-host-data-source
authorAndrei Pavel <andrei.pavel@qualitance.com>
Thu, 17 Aug 2017 17:30:41 +0000 (20:30 +0300)
committerAndrei Pavel <andrei.pavel@qualitance.com>
Thu, 17 Aug 2017 17:30:41 +0000 (20:30 +0300)
24 files changed:
1  2 
AUTHORS
configure.ac
doc/guide/admin.xml
doc/guide/dhcp4-srv.xml
doc/guide/dhcp6-srv.xml
src/bin/admin/admin-utils.sh
src/bin/admin/kea-admin.in
src/bin/admin/tests/cql_tests.sh.in
src/lib/dhcpsrv/Makefile.am
src/lib/dhcpsrv/cfg_option.cc
src/lib/dhcpsrv/cql_connection.cc
src/lib/dhcpsrv/cql_lease_mgr.cc
src/lib/dhcpsrv/cql_lease_mgr.h
src/lib/dhcpsrv/dhcpsrv_messages.mes
src/lib/dhcpsrv/host.h
src/lib/dhcpsrv/host_data_source_factory.cc
src/lib/dhcpsrv/lease_mgr.h
src/lib/dhcpsrv/mysql_host_data_source.cc
src/lib/dhcpsrv/parsers/dbaccess_parser.cc
src/lib/dhcpsrv/tests/Makefile.am
src/lib/dhcpsrv/tests/cql_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/generic_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/generic_host_data_source_unittest.h
src/share/database/scripts/mysql/Makefile.am

diff --cc AUTHORS
index ad2aabdd859e90acb125c6416b250476dd4456db,cad9cfbd9f75ccdf591a8a97786a04ec611f58af..d38073e35c9750188f6706b0249ce5b1b66a679e
+++ b/AUTHORS
@@@ -132,9 -152,8 +152,9 @@@ Kea uses log4cplus (http://sourceforge.
  Boost (http://www.boost.org/) library for almost everything, and can use Botan
  (http://botan.randombit.net/) or OpenSSL (https://www.openssl.org/) for
  cryptographic operations. It can also optionally use PostgreSQL
 -(http://www.postgresql.org/) and/or MySQL (http://www.mysql.com/) as a database.
 +(http://www.postgresql.org/) and/or MySQL (http://www.mysql.com/) and/or
 +Cassandra (http://cassandra.apache.org/) as a database.
  
- Kea can use googletest for unit-tests (http://code.google.com/p/googletest/).
+ Kea can use googletest for unit-tests (https://github.com/google/googletest).
  
- Kea uses ISC Forge (http://kea.isc.org/wiki/IscForge) for conformance testing.
+ Kea uses ISC Forge (https://github.com/isc-projects/forge/) for conformance testing.
diff --cc configure.ac
index 0dbbe0e05aa19ee7a378b16c4f2963373b1442b4,bba2cc942ae3069bd1d0c8c83a282c344259b5f7..9ed9366c341aea705eb2a9ddac2c71936b9c2c91
@@@ -1654,8 -1706,7 +1706,8 @@@ AC_CONFIG_FILES([Makefil
                   src/share/Makefile
                   src/share/database/Makefile
                   src/share/database/scripts/Makefile
+                  src/share/database/scripts/cql/Makefile
++                 src/share/database/scripts/cql/upgrade_1.0_to_2.0.sh
                   src/share/database/scripts/mysql/Makefile
                   src/share/database/scripts/mysql/upgrade_1.0_to_2.0.sh
                   src/share/database/scripts/mysql/upgrade_2.0_to_3.0.sh
Simple merge
index 0a1307edb6bd2b0584c1a5f73a2e56d667b183f4,49597a559a3e4d37116ad9db527010cfafba0acc..6bfcce0ccbb7849ad5060e8b780c2538b84c4340
@@@ -455,10 -459,11 +467,15 @@@ be followed by a comma and another obje
    the DHCPv4 server.  In this case, set the value to the empty string:
  <screen>
  "Dhcp4": { "lease-database": { <userinput>"host" : ""</userinput>, ... }, ... }
 +</screen>
 +  For Cassandra:
 +<screen>
 +"Dhcp4": { "lease-database": { <userinput>"contact_points": ""</userinput>, ... }, ... }
+ </screen>
+   Should the database use a port different than default, it may be
+   specified as well:
+ <screen>
+ "Dhcp4": { "lease-database": { <userinput>"port" : 12345</userinput>, ... }, ... }
  </screen>
    Should the database be located on a different system, you may need to specify a longer interval
    for the connection timeout:
index 8b4260f4b0e3c12f1a6fe89c3694db5629c15500,198d3dc4238e9d974d780e50f069b68981a8e418..f3f0d71bc31cab7f058c35b180f3e33365d8cfe7
@@@ -450,10 -454,11 +462,15 @@@ be followed by a comma and another obje
    the DHCPv6 server.  In this case, set the value to the empty string:
  <screen>
  "Dhcp6": { "lease-database": { <userinput>"host" : ""</userinput>, ... }, ... }
 +</screen>
 +  For Cassandra:
 +<screen>
 +"Dhcp6": { "lease-database": { <userinput>"contact_points": ""</userinput>, ... }, ... }
+ </screen>
+   Should the database use a port different than default, it may be
+   specified as well:
+ <screen>
+ "Dhcp4": { "lease-database": { <userinput>"port" : 12345</userinput>, ... }, ... }
  </screen>
    Should the database be located on a different system, you may need to specify a longer interval
    for the connection timeout:
Simple merge
Simple merge
index 6d282b0683e981626a85b06c287eb25e6f1e9c89,7f8794f2e28ac6cb36ed9bddf726eca4368f8aa8..0478fd87f80342f1c81efe58a76abf7a94dcc561
@@@ -80,9 -81,9 +80,9 @@@ cql_lease_version_test() 
      $keaadmin lease-init cql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir
      assert_eq 0 $? "kea-admin lease-init cql failed, expected exit code: %d, actual: %d"
  
-     # Verfiy that kea-admin lease-version returns the correct version.
+     # Verify that kea-admin lease-version returns the correct version.
      version=$($keaadmin lease-version cql -u $db_user -p $db_password -n $db_name)
 -    assert_str_eq "1.0" $version "Expected kea-admin to return %s, returned value was %s"
 +    assert_str_eq "2.0" $version "Expected kea-admin to return %s, returned value was %s"
  
      # Wipe the database.
      cql_execute_script $db_scripts_dir/cql/dhcpdb_drop.cql
Simple merge
Simple merge
index b4e20c78567e4f1a537550ee40e81ee5353827e9,6959d227a3de6b82b0d62c60190d1ff73081fb83..4e6a410c84b53cad222b8cf2fe0d42f63c118aaa
@@@ -72,12 -67,12 +72,12 @@@ CqlConnection::openDatabase() 
      CassError rc;
      // Set up the values of the parameters
      const char* contact_points = "127.0.0.1";
 -    string scontact_points;
 +    std::string scontact_points;
      try {
-         scontact_points = getParameter("contact_points");
+         scontact_points = getParameter("contact-points");
          contact_points = scontact_points.c_str();
      } catch (...) {
 -        // No host. Fine, we'll use "localhost".
 +        // No host. Fine, we'll use "127.0.0.1".
      }
  
      const char* port = NULL;
index 7175dd23eae24beeba7099aa74afb51336dbbf10,c3030f1b04ca7341f1730b11404bf980c5aa8703..35a79f90b56e4ff0fa783ded5a41e0c9e723c692
@@@ -1768,9 -1882,19 +1768,19 @@@ CqlLeaseMgr::deleteExpiredReclaimedLeas
              result++;
          }
      }
 -    return (result);
 +    return result;
  }
  
+ size_t
+ CqlLeaseMgr::wipeLeases4(const SubnetID& /*subnet_id*/) {
+     isc_throw(NotImplemented, "wipeLeases4 is not implemented for Cassandra backend");
+ }
+ size_t
+ CqlLeaseMgr::wipeLeases6(const SubnetID& /*subnet_id*/) {
+     isc_throw(NotImplemented, "wipeLeases6 is not implemented for Cassandra backend");
+ }
  std::string
  CqlLeaseMgr::getName() const {
      std::string name = "";
index bd5c4b9743c72ccf186545091af420c6ca30cbf6,bff24148a43268664a249dc6688b9169ba1ac75f..ad1f4312a3ebfb8bf12d9e6287c067c0af87c42b
@@@ -322,8 -377,30 +322,30 @@@ public
      /// time will not be deleted.
      ///
      /// @return Number of leases deleted.
 -    virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t );
 +    virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t secs);
  
+     /// @brief Removes specified IPv4 leases.
+     ///
+     /// This rather dangerous method is able to remove all leases from specified
+     /// subnet.
+     ///
+     /// @todo: Not implemented yet.
+     ///
+     /// @param subnet_id identifier of the subnet
+     /// @return number of leases removed.
+     virtual size_t wipeLeases4(const SubnetID& subnet_id);
+     /// @brief Removed specified IPv6 leases.
+     ///
+     /// This rather dangerous method is able to remove all leases from specified
+     /// subnet.
+     ///
+     /// @todo: Not implemented yet.
+     ///
+     /// @param subnet_id identifier of the subnet
+     /// @return number of leases removed.
+     virtual size_t wipeLeases6(const SubnetID& subnet_id);
      /// @brief Return backend type
      ///
      /// @return Type of the backend.
Simple merge
Simple merge
Simple merge
index 2056b94b830c1b686365b7ff5ccefb31f16d9d66,e4231dc1e28b54e2c370b77342b13760391cf2a4..6a6d0d944d88d7c7e86400951a38a61bbba98017
@@@ -50,11 -55,11 +55,12 @@@ DbAccessParser::parse(CfgDbAccessPtr& c
  
      int64_t lfc_interval = 0;
      int64_t timeout = 0;
+     int64_t port = 0;
      // 2. Update the copy with the passed keywords.
-     BOOST_FOREACH(ConfigPair param, config_value->mapValue()) {
+     BOOST_FOREACH(ConfigPair param, database_config->mapValue()) {
          try {
 -            if ((param.first == "persist") || (param.first == "readonly")) {
 +            if ((param.first == "persist") || (param.first == "readonly") ||
 +                (param.first == "tcp-nodelay")) {
                  values_copy[param.first] = (param.second->boolValue() ?
                                              "true" : "false");
  
                  values_copy[param.first] =
                      boost::lexical_cast<std::string>(timeout);
  
 +            } else if (param.first == "reconnect-wait-time") {
 +                timeout = param.second->intValue();
 +                values_copy[param.first] =
 +                    boost::lexical_cast<std::string>(timeout);
 +
 +            } else if (param.first == "request-timeout") {
 +                timeout = param.second->intValue();
 +                values_copy[param.first] =
 +                    boost::lexical_cast<std::string>(timeout);
 +
 +            } else if (param.first == "tcp-keepalive") {
 +                timeout = param.second->intValue();
 +                values_copy[param.first] =
 +                    boost::lexical_cast<std::string>(timeout);
 +
+             } else if (param.first == "port") {
+                 port = param.second->intValue();
+                 values_copy[param.first] =
+                     boost::lexical_cast<std::string>(port);
              } else {
                  values_copy[param.first] = param.second->stringValue();
              }
Simple merge
index a556b9959bb8aa8018a86cef2d9c445d1709816a,3da3658d1e935fd04cb061e37b43deaf2789e3dd..a8902cc346bf36c7bafef5331acf0f1aeb7a841d
@@@ -687,4 -643,14 +687,15 @@@ TEST_F(CqlLeaseMgrTest, deleteExpiredRe
      testDeleteExpiredReclaimedLeases4();
  }
  
 -}; // Of anonymous namespace
+ // Tests that leases from specific subnet can be removed.
+ TEST_F(CqlLeaseMgrTest, DISABLED_wipeLeases4) {
+     testWipeLeases4();
+ }
+ // Tests that leases from specific subnet can be removed.
+ TEST_F(CqlLeaseMgrTest, DISABLED_wipeLeases6) {
+     testWipeLeases6();
+ }
 +}  // namespace
++
index d5f6c135bf1e377d9aa84a3ece2e26424e445373,75e46c14b4bf644b0cce4a6a18b9d15799bc8930..bc431ed938cc798bcdb3fa3518268fe7598a86ba
@@@ -1499,6 -1463,198 +1499,199 @@@ GenericHostDataSourceTest::testMessageF
      ASSERT_NO_FATAL_FAILURE(compareHosts(host, from_hds));
  }
  
 -}; // namespace test
 -}; // namespace dhcp
 -}; // namespace isc
+ void GenericHostDataSourceTest::testDeleteByAddr4() {
+     // Make sure we have a pointer to the host data source.
+     ASSERT_TRUE(hdsptr_);
+     // Let's create a v4 host...
+     HostPtr host1 = initializeHost4("192.0.2.1", Host::IDENT_HWADDR);
+     SubnetID subnet1 = host1->getIPv4SubnetID();
+     // ... and add it to the data source.
+     ASSERT_NO_THROW(hdsptr_->add(host1));
+     // And then try to retrieve it back.
+     ConstHostPtr before = hdsptr_->get4(subnet1, IOAddress("192.0.2.1"));
+     // Now try to delete it: del(subnet-id, addr4)
+     EXPECT_TRUE(hdsptr_->del(subnet1, IOAddress("192.0.2.1")));
+     // Check if it's still there.
+     ConstHostPtr after = hdsptr_->get4(subnet1, IOAddress("192.0.2.1"));
+     // Make sure the host was there before...
+     EXPECT_TRUE(before);
+     // ... and that it's gone after deletion.
+     EXPECT_FALSE(after);
+ }
+ void GenericHostDataSourceTest::testDeleteById4() {
+     // Make sure we have a pointer to the host data source.
+     ASSERT_TRUE(hdsptr_);
+     // Let's create a v4 host...
+     HostPtr host1 = initializeHost4("192.0.2.1", Host::IDENT_HWADDR);
+     SubnetID subnet1 = host1->getIPv4SubnetID();
+     // ... and add it to the data source.
+     ASSERT_NO_THROW(hdsptr_->add(host1));
+     // And then try to retrieve it back.
+     ConstHostPtr before = hdsptr_->get4(subnet1,
+                                         host1->getIdentifierType(),
+                                         &host1->getIdentifier()[0],
+                                         host1->getIdentifier().size());
+     // Now try to delete it: del4(subnet4-id, identifier-type, identifier)
+     EXPECT_TRUE(hdsptr_->del4(subnet1, host1->getIdentifierType(),
+                               &host1->getIdentifier()[0],
+                               host1->getIdentifier().size()));
+     // Check if it's still there.
+     ConstHostPtr after = hdsptr_->get4(subnet1,
+                                        host1->getIdentifierType(),
+                                        &host1->getIdentifier()[0],
+                                        host1->getIdentifier().size());
+     // Make sure the host was there before...
+     EXPECT_TRUE(before);
+     // ... and that it's gone after deletion.
+     EXPECT_FALSE(after);
+ }
+ // Test checks when a IPv4 host with options is deleted that the options are
+ // deleted as well.
+ void GenericHostDataSourceTest::testDeleteById4Options() {
+     // Make sure we have a pointer to the host data source.
+     ASSERT_TRUE(hdsptr_);
+     // Let's create a v4 host...
+     HostPtr host1 = initializeHost4("192.0.2.1", Host::IDENT_HWADDR);
+     // Add a bunch of DHCPv4 and DHCPv6 options for the host.
+     ASSERT_NO_THROW(addTestOptions(host1, true, DHCP4_ONLY));
+     // Insert host and the options into respective tables.
+     SubnetID subnet1 = host1->getIPv4SubnetID();
+     // ... and add it to the data source.
+     ASSERT_NO_THROW(hdsptr_->add(host1));
+     // There must be some options
+     EXPECT_NE(0, countDBOptions4());
+     // And then try to retrieve it back.
+     ConstHostPtr before = hdsptr_->get4(subnet1,
+                                         host1->getIdentifierType(),
+                                         &host1->getIdentifier()[0],
+                                         host1->getIdentifier().size());
+     // Now try to delete it: del4(subnet4-id, identifier-type, identifier)
+     EXPECT_TRUE(hdsptr_->del4(subnet1, host1->getIdentifierType(),
+                               &host1->getIdentifier()[0],
+                               host1->getIdentifier().size()));
+     // Check if it's still there.
+     ConstHostPtr after = hdsptr_->get4(subnet1,
+                                        host1->getIdentifierType(),
+                                        &host1->getIdentifier()[0],
+                                        host1->getIdentifier().size());
+     // Make sure the host was there before...
+     EXPECT_TRUE(before);
+     // ... and that it's gone after deletion.
+     EXPECT_FALSE(after);
+     // Check the options are indeed gone.
+     EXPECT_EQ(0, countDBOptions4());
+ }
+ void GenericHostDataSourceTest::testDeleteById6() {
+     // Make sure we have a pointer to the host data source.
+     ASSERT_TRUE(hdsptr_);
+     // Let's create a v6 host...
+     HostPtr host1 = initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
+     SubnetID subnet1 = host1->getIPv6SubnetID();
+     // ... and add it to the data source.
+     ASSERT_NO_THROW(hdsptr_->add(host1));
+     // And then try to retrieve it back.
+     ConstHostPtr before = hdsptr_->get6(subnet1,
+                                         host1->getIdentifierType(),
+                                         &host1->getIdentifier()[0],
+                                         host1->getIdentifier().size());
+     // Now try to delete it: del4(subnet4-id, identifier-type, identifier)
+     EXPECT_TRUE(hdsptr_->del6(subnet1, host1->getIdentifierType(),
+                               &host1->getIdentifier()[0],
+                               host1->getIdentifier().size()));
+     // Check if it's still there.
+     ConstHostPtr after = hdsptr_->get6(subnet1,
+                                        host1->getIdentifierType(),
+                                        &host1->getIdentifier()[0],
+                                        host1->getIdentifier().size());
+     // Make sure the host was there before...
+     EXPECT_TRUE(before);
+     // ... and that it's gone after deletion.
+     EXPECT_FALSE(after);
+ }
+ void GenericHostDataSourceTest::testDeleteById6Options() {
+     // Make sure we have a pointer to the host data source.
+     ASSERT_TRUE(hdsptr_);
+     // Let's create a v6 host...
+     HostPtr host1 = initializeHost6("2001:db8::1", Host::IDENT_DUID, false);
+     SubnetID subnet1 = host1->getIPv6SubnetID();
+     ASSERT_NO_THROW(addTestOptions(host1, true, DHCP6_ONLY));
+     // ... and add it to the data source.
+     ASSERT_NO_THROW(hdsptr_->add(host1));
+     // Check that the options are stored...
+     EXPECT_NE(0, countDBOptions6());
+     // ... and so are v6 reservations.
+     EXPECT_NE(0, countDBReservations6());
+     // And then try to retrieve it back.
+     ConstHostPtr before = hdsptr_->get6(subnet1,
+                                         host1->getIdentifierType(),
+                                         &host1->getIdentifier()[0],
+                                         host1->getIdentifier().size());
+     // Now try to delete it: del4(subnet4-id, identifier-type, identifier)
+     EXPECT_TRUE(hdsptr_->del6(subnet1, host1->getIdentifierType(),
+                               &host1->getIdentifier()[0],
+                               host1->getIdentifier().size()));
+     // Check if it's still there.
+     ConstHostPtr after = hdsptr_->get6(subnet1,
+                                        host1->getIdentifierType(),
+                                        &host1->getIdentifier()[0],
+                                        host1->getIdentifier().size());
+     // Make sure the host was there before...
+     EXPECT_TRUE(before);
+     // ... and that it's gone after deletion.
+     EXPECT_FALSE(after);
+     // Check the options are indeed gone.
+     EXPECT_EQ(0, countDBOptions6());
+     // Check the options are indeed gone.
+     EXPECT_EQ(0, countDBReservations6());
+ }
 +}  // namespace test
 +}  // namespace dhcp
 +}  // namespace isc
++
index 8e8ac1d200dd92b2bdb3d6dc3fc78ce86443308f,dea04b2df2670f8c7fccf5aa68859a231fdf5a84..cbd9d26f20a79c152113fa645912b615c0d98b19
@@@ -8,5 -8,7 +8,6 @@@ sqlscripts_DATA += upgrade_2.0_to_3.0.s
  sqlscripts_DATA += upgrade_3.0_to_4.0.sh
  sqlscripts_DATA += upgrade_4.0_to_4.1.sh
  sqlscripts_DATA += upgrade_4.1_to_5.0.sh
+ sqlscripts_DATA += upgrade_5.0_to_5.1.sh
  
 -
  EXTRA_DIST = ${sqlscripts_DATA}