Commit 08343129 authored by Andrei Pavel's avatar Andrei Pavel Committed by Tomek Mrugalski
Browse files

solved Cassandra unit tests & added documentation

parent 829cac98
...@@ -1329,11 +1329,11 @@ if test "x$enable_generate_docs" != xno ; then ...@@ -1329,11 +1329,11 @@ if test "x$enable_generate_docs" != xno ; then
else else
AC_MSG_CHECKING([if $XSLTPROC works]) AC_MSG_CHECKING([if $XSLTPROC works])
# run xsltproc to see if works # run xsltproc to see if works
$XSLTPROC --novalid --xinclude --nonet http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $XSLTPROC --novalid --xinclude http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl
if test $? -ne 0 ; then if test $? -ne 0 ; then
AC_MSG_ERROR("Error with $XSLTPROC using release/xsl/current/manpages/docbook.xsl") AC_MSG_ERROR("Error with $XSLTPROC using release/xsl/current/manpages/docbook.xsl")
fi fi
$XSLTPROC --novalid --xinclude --nonet http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl $XSLTPROC --novalid --xinclude http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl
if test $? -ne 0 ; then if test $? -ne 0 ; then
AC_MSG_ERROR("Error with $XSLTPROC using release/xsl/current/html/docbook.xsl") AC_MSG_ERROR("Error with $XSLTPROC using release/xsl/current/html/docbook.xsl")
fi fi
......
...@@ -94,10 +94,10 @@ ...@@ -94,10 +94,10 @@
<listitem> <listitem>
<simpara> <simpara>
<command>lease-dump</command> &mdash; <command>lease-dump</command> &mdash;
Dumps the contents of the lease database (for MySQL or PostgreSQL Dumps the contents of the lease database (for MySQL, PostgreSQL or
backends) to CSV text file. The first line of the file contains CQL backends) to CSV text file. The first line of the file contains
the column names. This is meant to be used as a diagnostic the column names. This is meant to be used as a diagnostic tool
tool that provides a portable, human-readable form of lease data. that provides a portable, human-readable form of lease data.
</simpara> </simpara>
</listitem> </listitem>
</itemizedlist> </itemizedlist>
...@@ -128,6 +128,14 @@ ...@@ -128,6 +128,14 @@
database. database.
</simpara> </simpara>
</listitem> </listitem>
<listitem>
<simpara>
<command>cql</command> &mdash;
Lease information is stored in a CQL database.
</simpara>
</listitem>
</itemizedlist> </itemizedlist>
Additional parameters may be needed, depending on your setup Additional parameters may be needed, depending on your setup
...@@ -484,6 +492,122 @@ $ <userinput>kea-admin lease-init pgsql -u <replaceable>database-user</replaceab ...@@ -484,6 +492,122 @@ $ <userinput>kea-admin lease-init pgsql -u <replaceable>database-user</replaceab
</para> </para>
</section> </section>
</section> <!-- end of PostgreSQL sections --> </section> <!-- end of PostgreSQL sections -->
<section>
<title>CQL</title>
<para>
The CQL database must be properly set up if you want Kea to store
information in CQL. This section can be safely ignored if you chose to
store the data in other backends.
</para>
<section id="cql-database-create">
<title>First Time Creation of Kea Database</title>
<para>
If you are setting up the CQL database for the first time, you need to
create the keyspace area within CQL. This needs to be done manually:
<command>kea-admin</command> is not able to do this for you.
</para>
<para>
To create the database:
<orderedlist>
<listitem>
<para>
Export CQLSH_HOST environemnt variable:
<screen>
$ <userinput>export CQLSH_HOST=localhost</userinput>
</screen>
</para>
</listitem>
<listitem>
<para>
Log into CQL:
<screen>
$ <userinput>cqlsh</userinput>
cql>
</screen>
</para>
</listitem>
<listitem>
<para>
Create the CQL keyspace:
<screen>
cql> <userinput>CREATE KEYSPACE keyspace-name WITH replication = {'class' : 'SimpleStrategy','replication_factor' : 1};</userinput>
</screen>
(<replaceable>keyspace-name</replaceable> is the name you have
chosen for the keyspace)
</para>
</listitem>
<listitem>
<para>
At this point, you may elect to create the database tables.
(Alternatively, you can exit CQL and create the tables using the
<command>kea-admin</command> tool, as explained below) To do this:
<screen>
<userinput>cqslh -k <replaceable>keyspace-name</replaceable> -f <replaceable>path-to-kea</replaceable>/share/kea/scripts/cql/dhcpdb_create.cql</userinput>
</screen>
(<replaceable>path-to-kea</replaceable> is the location where you
installed Kea)
</para>
</listitem>
</orderedlist>
</para>
<para>
If you elected not to create the tables in step 4, you can do
so now by running the <command>kea-admin</command> tool:
<screen>
$ <userinput>kea-admin lease-init cql -n <replaceable>database-name</replaceable></userinput>
</screen>
(Do not do this if you did create the tables in step 4.)
<command>kea-admin</command> implements rudimentary checks:
it will refuse to initialize a database that contains any
existing tables. If you want to start from scratch, you
must remove all data manually. (This process is a manual
operation on purpose to avoid possibly irretrievable mistakes
by <command>kea-admin</command>)
</para>
</section>
<section id="cql-upgrade">
<title>Upgrading a CQL Database from an Earlier Version of Kea</title>
<para>
Sometimes a new Kea version may use newer database schema, so
there will be a need to upgrade the existing database. This can
be done using the <command>kea-admin lease-upgrade</command>
command.
</para>
<para>
To check the current version of the database, use the following command:
<screen>
$ <userinput>kea-admin lease-version cql -n <replaceable>database-name</replaceable></userinput>
</screen>
(See <xref linkend="kea-database-version"/> for a discussion
about versioning) If the version does not match the minimum
required for the new version of Kea (as described in the
release notes), the database needs to be upgraded.
</para>
<para>
Before upgrading, please make sure that the database is
backed up. The upgrade process does not discard any data but,
depending on the nature of the changes, it may be impossible
to subsequently downgrade to an earlier version. To perform
an upgrade, issue the following command:
<screen>
$ <userinput>kea-admin lease-upgrade cql -n <replaceable>database-name</replaceable></userinput>
</screen>
</para>
</section>
</section> <!-- end of CQL sections -->
<section> <section>
<title>Limitations related to the use of the SQL databases</title> <title>Limitations related to the use of the SQL databases</title>
......
...@@ -301,8 +301,8 @@ be followed by a comma and another object definition.</para> ...@@ -301,8 +301,8 @@ be followed by a comma and another object definition.</para>
<section> <section>
<title>Lease Storage</title> <title>Lease Storage</title>
<para>All leases issued by the server are stored in the lease database. <para>All leases issued by the server are stored in the lease database.
Currently there are three database backends available: Currently there are four database backends available: memfile (which is the
memfile (which is the default backend), MySQL and PostgreSQL.</para> default backend), MySQL, PostgreSQL and CQL.</para>
<section> <section>
<title>Memfile, Basic Storage for Leases</title> <title>Memfile, Basic Storage for Leases</title>
...@@ -441,8 +441,10 @@ be followed by a comma and another object definition.</para> ...@@ -441,8 +441,10 @@ be followed by a comma and another object definition.</para>
"Dhcp4": { "lease-database": { <userinput>"type": "mysql"</userinput>, ... }, ... } "Dhcp4": { "lease-database": { <userinput>"type": "mysql"</userinput>, ... }, ... }
</screen> </screen>
Next, the name of the database to hold the leases must be set: this is the Next, the name of the database to hold the leases must be set: this is the
name used when the lease database was created (see <xref linkend="mysql-database-create"/> name used when the lease database was created
or <xref linkend="pgsql-database-create"/>). (see <xref linkend="mysql-database-create"/>,
<xref linkend="pgsql-database-create"/> or
<xref linkend="cql-database-create"/>).
<screen> <screen>
"Dhcp4": { "lease-database": { <userinput>"name": "<replaceable>database-name</replaceable>" </userinput>, ... }, ... } "Dhcp4": { "lease-database": { <userinput>"name": "<replaceable>database-name</replaceable>" </userinput>, ... }, ... }
</screen> </screen>
......
...@@ -306,8 +306,8 @@ be followed by a comma and another object definition.</para> ...@@ -306,8 +306,8 @@ be followed by a comma and another object definition.</para>
<section> <section>
<title>Lease Storage</title> <title>Lease Storage</title>
<para>All leases issued by the server are stored in the lease database. <para>All leases issued by the server are stored in the lease database.
Currently there are three database backends available: Currently there are four database backends available: memfile (which is the
memfile (which is the default backend), MySQL and PostgreSQL.</para> default backend), MySQL, PostgreSQL and CQL.</para>
<section> <section>
<title>Memfile, Basic Storage for Leases</title> <title>Memfile, Basic Storage for Leases</title>
...@@ -435,13 +435,15 @@ be followed by a comma and another object definition.</para> ...@@ -435,13 +435,15 @@ be followed by a comma and another object definition.</para>
<para>Lease database configuration is controlled through the <para>Lease database configuration is controlled through the
Dhcp6/lease-database parameters. The type of the database must be set to Dhcp6/lease-database parameters. The type of the database must be set to
"memfile", "mysql" or "postgresql", e.g. "memfile", "mysql", "postgresql" or "cql", e.g.
<screen> <screen>
"Dhcp6": { "lease-database": { <userinput>"type": "mysql"</userinput>, ... }, ... } "Dhcp6": { "lease-database": { <userinput>"type": "mysql"</userinput>, ... }, ... }
</screen> </screen>
Next, the name of the database is to hold the leases must be set: this is the Next, the name of the database is to hold the leases must be set: this is the
name used when the lease database was created (see <xref linkend="mysql-database-create"/> name used when the lease database was created
or <xref linkend="pgsql-database-create"/>). (see <xref linkend="mysql-database-create"/>,
<xref linkend="pgsql-database-create"/>
or <xref linkend="cql-database-create"/>).
<screen> <screen>
"Dhcp6": { "lease-database": { <userinput>"name": "<replaceable>database-name</replaceable>" </userinput>, ... }, ... } "Dhcp6": { "lease-database": { <userinput>"name": "<replaceable>database-name</replaceable>" </userinput>, ... }, ... }
</screen> </screen>
...@@ -3568,8 +3570,8 @@ should include options from the isc option space: ...@@ -3568,8 +3570,8 @@ should include options from the isc option space:
that are stored in the lease database. Removing non-last subnet will that are stored in the lease database. Removing non-last subnet will
cause the configuration information to mismatch data in the lease cause the configuration information to mismatch data in the lease
database. It is possible to manually update subnet-id fields in database. It is possible to manually update subnet-id fields in
MySQL or PostgreSQL database, but it is awkward and error prone MySQL, PostgreSQL or CQL database, but it is awkward and
process. A better reconfiguration support is planned. error prone process. A better reconfiguration support is planned.
</para> </para>
</listitem> </listitem>
......
...@@ -367,7 +367,7 @@ Debian and Ubuntu: ...@@ -367,7 +367,7 @@ Debian and Ubuntu:
<para> <para>
<userinput>./configure</userinput> when it succeeds displays a report <userinput>./configure</userinput> when it succeeds displays a report
with the building parameters. This report is saved into with the building parameters. This report is saved into
<filename>config.report</filename> and embedded into executable <filename>config.report</filename> and embedded into executable
binaries, e.g., <userinput>kea-dhcp4</userinput>. binaries, e.g., <userinput>kea-dhcp4</userinput>.
</para> </para>
......
...@@ -88,6 +88,14 @@ ...@@ -88,6 +88,14 @@
built without PostgreSQL support. built without PostgreSQL support.
</simpara> </simpara>
</listitem> </listitem>
<listitem>
<simpara>
In order to store lease information in a CQL database, Kea requires CQL
headers and libraries. This is an optional dependency in that Kea can be
built without CQL support.
</simpara>
</listitem>
</itemizedlist> </itemizedlist>
</section> </section>
......
...@@ -489,10 +489,10 @@ cql_dump() { ...@@ -489,10 +489,10 @@ cql_dump() {
select_where_clause="" select_where_clause=""
if [ $dump_type -eq 4 ]; then if [ $dump_type -eq 4 ]; then
dump_qry="SELECT address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state FROM keatest.lease4" dump_qry="SELECT address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state FROM lease4"
select_where_clause=" WHERE address = 0" # invalid address select_where_clause=" WHERE address = 0" # invalid address
elif [ $dump_type -eq 6 ]; then elif [ $dump_type -eq 6 ]; then
dump_qry="SELECT address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,hwtype,hwaddr_source,state FROM keatest.lease6" dump_qry="SELECT address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,hwtype,hwaddr_source,state FROM lease6"
select_where_clause=" WHERE address = '::'" # invalid address select_where_clause=" WHERE address = '::'" # invalid address
fi fi
......
...@@ -98,7 +98,7 @@ CqlConnection::openDatabase() { ...@@ -98,7 +98,7 @@ CqlConnection::openDatabase() {
skeyspace = getParameter("keyspace"); skeyspace = getParameter("keyspace");
keyspace = skeyspace.c_str(); keyspace = skeyspace.c_str();
} catch (...) { } catch (...) {
// No database name. Fine, we'll use default "keatest". // No keyspace name. Fine, we'll use default "keatest".
} }
cluster_ = cass_cluster_new(); cluster_ = cass_cluster_new();
......
...@@ -258,7 +258,8 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = { ...@@ -258,7 +258,8 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = {
// DELETE_LEASE4 // DELETE_LEASE4
{ delete_lease4_params, { delete_lease4_params,
"delete_lease4", "delete_lease4",
"DELETE FROM lease4 WHERE address = ?" }, "DELETE FROM lease4 WHERE address = ? "
"IF EXISTS" },
// DELETE_LEASE4_STATE_EXPIRED // DELETE_LEASE4_STATE_EXPIRED
{ delete_expired_lease4_params, { delete_expired_lease4_params,
...@@ -267,12 +268,14 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = { ...@@ -267,12 +268,14 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = {
"valid_lifetime, expire, subnet_id, " "valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, state " "fqdn_fwd, fqdn_rev, hostname, state "
"FROM lease4 " "FROM lease4 "
"WHERE state = ? AND expire < ? ALLOW FILTERING" }, "WHERE state = ? AND expire < ? "
"ALLOW FILTERING" },
// DELETE_LEASE6 // DELETE_LEASE6
{ delete_lease6_params, { delete_lease6_params,
"delete_lease6", "delete_lease6",
"DELETE FROM lease6 WHERE address = ?" }, "DELETE FROM lease6 WHERE address = ? "
"IF EXISTS" },
// DELETE_LEASE6_STATE_EXPIRED // DELETE_LEASE6_STATE_EXPIRED
{ delete_expired_lease6_params, { delete_expired_lease6_params,
...@@ -282,7 +285,8 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = { ...@@ -282,7 +285,8 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = {
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, " "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, state " "hwaddr, hwtype, hwaddr_source, state "
"FROM lease6 " "FROM lease6 "
"WHERE state = ? AND expire < ? ALLOW FILTERING" }, "WHERE state = ? AND expire < ? "
"ALLOW FILTERING" },
// GET_LEASE4_ADDR // GET_LEASE4_ADDR
{ get_lease4_addr_params, { get_lease4_addr_params,
...@@ -309,7 +313,8 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = { ...@@ -309,7 +313,8 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = {
"valid_lifetime, expire, subnet_id, " "valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, state " "fqdn_fwd, fqdn_rev, hostname, state "
"FROM lease4 " "FROM lease4 "
"WHERE client_id = ? AND subnet_id = ? ALLOW FILTERING" }, "WHERE client_id = ? AND subnet_id = ? "
"ALLOW FILTERING" },
// GET_LEASE4_HWADDR // GET_LEASE4_HWADDR
{ get_lease4_hwaddr_params, { get_lease4_hwaddr_params,
...@@ -327,7 +332,8 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = { ...@@ -327,7 +332,8 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = {
"valid_lifetime, expire, subnet_id, " "valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, state " "fqdn_fwd, fqdn_rev, hostname, state "
"FROM lease4 " "FROM lease4 "
"WHERE hwaddr = ? AND subnet_id = ? ALLOW FILTERING" }, "WHERE hwaddr = ? AND subnet_id = ? "
"ALLOW FILTERING" },
// GET_LEASE4_EXPIRE // GET_LEASE4_EXPIRE
{ get_lease4_expired_params, { get_lease4_expired_params,
...@@ -337,7 +343,8 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = { ...@@ -337,7 +343,8 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = {
"fqdn_fwd, fqdn_rev, hostname, state " "fqdn_fwd, fqdn_rev, hostname, state "
"FROM lease4 " "FROM lease4 "
"WHERE state = ? AND expire < ? " "WHERE state = ? AND expire < ? "
"LIMIT ? ALLOW FILTERING" }, "LIMIT ? "
"ALLOW FILTERING" },
// GET_LEASE6_ADDR // GET_LEASE6_ADDR
{ get_lease6_addr_params, { get_lease6_addr_params,
...@@ -347,7 +354,8 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = { ...@@ -347,7 +354,8 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = {
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, " "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, state " "hwaddr, hwtype, hwaddr_source, state "
"FROM lease6 " "FROM lease6 "
"WHERE address = ? AND lease_type = ? ALLOW FILTERING" }, "WHERE address = ? AND lease_type = ? "
"ALLOW FILTERING" },
// GET_LEASE6_DUID_IAID // GET_LEASE6_DUID_IAID
{ get_lease6_duid_iaid_params, { get_lease6_duid_iaid_params,
...@@ -357,7 +365,8 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = { ...@@ -357,7 +365,8 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = {
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, " "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, state " "hwaddr, hwtype, hwaddr_source, state "
"FROM lease6 " "FROM lease6 "
"WHERE duid = ? AND iaid = ? AND lease_type = ? ALLOW FILTERING" }, "WHERE duid = ? AND iaid = ? AND lease_type = ? "
"ALLOW FILTERING" },
// GET_LEASE6_DUID_IAID_SUBID // GET_LEASE6_DUID_IAID_SUBID
{ get_lease6_duid_iaid_subid_params, { get_lease6_duid_iaid_subid_params,
...@@ -367,7 +376,8 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = { ...@@ -367,7 +376,8 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = {
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, " "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, state " "hwaddr, hwtype, hwaddr_source, state "
"FROM lease6 " "FROM lease6 "
"WHERE duid = ? AND iaid = ? AND subnet_id = ? AND lease_type = ? ALLOW FILTERING" }, "WHERE duid = ? AND iaid = ? AND subnet_id = ? AND lease_type = ? "
"ALLOW FILTERING" },
// GET_LEASE6_EXPIRE // GET_LEASE6_EXPIRE
{ get_lease6_expired_params, { get_lease6_expired_params,
...@@ -377,9 +387,9 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = { ...@@ -377,9 +387,9 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = {
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, " "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
"hwaddr, hwtype, hwaddr_source, state " "hwaddr, hwtype, hwaddr_source, state "
"FROM lease6 " "FROM lease6 "
//"WHERE state != ? AND expire < ? ORDER BY expire ASC "
"WHERE state = ? AND expire < ? " "WHERE state = ? AND expire < ? "
"LIMIT ? ALLOW FILTERING" }, "LIMIT ? "
"ALLOW FILTERING" },
// GET_VERSION // GET_VERSION
{ get_version_params, { get_version_params,
...@@ -393,7 +403,7 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = { ...@@ -393,7 +403,7 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = {
"valid_lifetime, expire, subnet_id, fqdn_fwd, fqdn_rev, hostname, " "valid_lifetime, expire, subnet_id, fqdn_fwd, fqdn_rev, hostname, "
"state) " "state) "
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) " "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) "
}, "IF NOT EXISTS" },
// INSERT_LEASE6 // INSERT_LEASE6
{ insert_lease6_params, { insert_lease6_params,
...@@ -403,7 +413,7 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = { ...@@ -403,7 +413,7 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = {
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, hwaddr, " "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, hwaddr, "
"hwtype, hwaddr_source, state) " "hwtype, hwaddr_source, state) "
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) " "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) "
}, "IF NOT EXISTS" },
// UPDATE_LEASE4 // UPDATE_LEASE4
{ update_lease4_params, { update_lease4_params,
...@@ -412,7 +422,7 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = { ...@@ -412,7 +422,7 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = {
"client_id = ?, valid_lifetime = ?, expire = ?, " "client_id = ?, valid_lifetime = ?, expire = ?, "
"subnet_id = ?, fqdn_fwd = ?, fqdn_rev = ?, hostname = ?, state = ? " "subnet_id = ?, fqdn_fwd = ?, fqdn_rev = ?, hostname = ?, state = ? "
"WHERE address = ? " "WHERE address = ? "
}, "IF EXISTS" },
// UPDATE_LEASE6 // UPDATE_LEASE6
{ update_lease6_params, { update_lease6_params,
...@@ -423,7 +433,7 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = { ...@@ -423,7 +433,7 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = {
"prefix_len = ?, fqdn_fwd = ?, fqdn_rev = ?, hostname = ?, " "prefix_len = ?, fqdn_fwd = ?, fqdn_rev = ?, hostname = ?, "
"hwaddr = ?, hwtype = ?, hwaddr_source = ?, state = ? " "hwaddr = ?, hwtype = ?, hwaddr_source = ?, state = ? "
"WHERE address = ? " "WHERE address = ? "
}, "IF EXISTS" },
// End of list sentinel // End of list sentinel
{ NULL, NULL, NULL } { NULL, NULL, NULL }
...@@ -501,12 +511,12 @@ public: ...@@ -501,12 +511,12 @@ public:
/// all variables are initialized/set in the methods before they are used. /// all variables are initialized/set in the methods before they are used.
CqlLease4Exchange() : addr4_(0), client_id_length_(0), CqlLease4Exchange() : addr4_(0), client_id_length_(0),
client_id_null_(false) { client_id_null_(false) {
const size_t MAX_COLUMNS = 11U; const size_t MAX_COLUMNS = 12U;
memset(client_id_buffer_, 0, sizeof(client_id_buffer_)); memset(client_id_buffer_, 0, sizeof(client_id_buffer_));
// Set the column names // Set the column names
size_t offset = 0U; size_t offset = 0U;
BOOST_STATIC_ASSERT(11U == MAX_COLUMNS); BOOST_STATIC_ASSERT(12U == MAX_COLUMNS);
parameters_.push_back(ExchangeColumnInfoPtr(new ExchangeColumnInfo("address", parameters_.push_back(ExchangeColumnInfoPtr(new ExchangeColumnInfo("address",
offset++, EXCHANGE_DATA_TYPE_IO_IN_OUT, EXCHANGE_DATA_TYPE_INT32))); offset++, EXCHANGE_DATA_TYPE_IO_IN_OUT, EXCHANGE_DATA_TYPE_INT32)));
parameters_.push_back(ExchangeColumnInfoPtr(new ExchangeColumnInfo("hwaddr", parameters_.push_back(ExchangeColumnInfoPtr(new ExchangeColumnInfo("hwaddr",
...@@ -529,6 +539,8 @@ public: ...@@ -529,6 +539,8 @@ public:
offset++, EXCHANGE_DATA_TYPE_IO_IN_OUT, EXCHANGE_DATA_TYPE_INT32))); offset++, EXCHANGE_DATA_TYPE_IO_IN_OUT, EXCHANGE_DATA_TYPE_INT32)));
parameters_.push_back(ExchangeColumnInfoPtr(new ExchangeColumnInfo("limit", parameters_.push_back(ExchangeColumnInfoPtr(new ExchangeColumnInfo("limit",
offset++, EXCHANGE_DATA_TYPE_IO_IN_OUT, EXCHANGE_DATA_TYPE_INT32))); offset++, EXCHANGE_DATA_TYPE_IO_IN_OUT, EXCHANGE_DATA_TYPE_INT32)));
parameters_.push_back(ExchangeColumnInfoPtr(new ExchangeColumnInfo("[applied]",
offset++, EXCHANGE_DATA_TYPE_IO_IN_OUT, EXCHANGE_DATA_TYPE_BOOL)));
BOOST_ASSERT(parameters_.size() == MAX_COLUMNS); BOOST_ASSERT(parameters_.size() == MAX_COLUMNS);
} }
...@@ -553,7 +565,18 @@ public: ...@@ -553,7 +565,18 @@ public:
data.add(&addr4_); data.add(&addr4_);
// hwaddr: blob // hwaddr: blob
hwaddr_ = lease_->hwaddr_->hwaddr_; HWAddrPtr hwaddr = lease_->hwaddr_;
if (hwaddr) {
if (hwaddr->hwaddr_.size() > HWAddr::MAX_HWADDR_LEN) {
isc_throw(DbOperationError, "Hardware address length " <<
lease_->hwaddr_->hwaddr_.size() <<
" exceeds maximum allowed of " <<
HWAddr::MAX_HWADDR_LEN);
}
hwaddr_ = hwaddr->hwaddr_;
} else {
hwaddr_.clear();
}
hwaddr_length_ = hwaddr_.size(); hwaddr_length_ = hwaddr_.size();
data.add(&hwaddr_); data.add(&hwaddr_);
...@@ -622,7 +645,6 @@ public: ...@@ -622,7 +645,6 @@ public:
/// Creates a CQL_BIND array to receive Lease4 data from the database. /// Creates a CQL_BIND array to receive Lease4 data from the database.
Lease4Ptr createBindForReceive(const CassRow* row) { Lease4Ptr createBindForReceive(const CassRow* row) {
try { try {
unsigned char* hwaddr_buffer = NULL; unsigned char* hwaddr_buffer = NULL;
const char* client_id_buffer = NULL; const char* client_id_buffer = NULL;
const char* hostname_buffer = NULL; const char* hostname_buffer = NULL;
...@@ -669,8 +691,8 @@ public: ...@@ -669,8 +691,8 @@ public:
data.add(reinterpret_cast<void*>(&state_)); data.add(reinterpret_cast<void*>(&state_));
size.add(NULL); size.add(NULL);
for (int i = 0; i < 10; i++) { for (size_t i = 0; i < data.size(); i++) {