Commit 0bc02588 authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[master] Merge branch 'trac3968'

parents bf156060 1756b9df
......@@ -265,21 +265,57 @@ ALTER TABLE lease6
# by the expiration time. One of the applications is to retrieve all
# expired leases. However, these indexes can be also used to retrieve
# leases in a given state regardless of the expiration time.
CREATE INDEX lease4_by_state_expire ON lease4 (state, expire);
CREATE INDEX lease6_by_state_expire ON lease6 (state, expire);
CREATE INDEX lease4_by_state_expire ON lease4 (state ASC, expire ASC);
CREATE INDEX lease6_by_state_expire ON lease6 (state ASC, expire ASC);
# Create table holding mapping of the lease states to their names.
# This is not used in queries from the DHCP server but rather in
# direct queries from the lease database management tools.
CREATE TABLE IF NOT EXISTS lease_state (
state INT UNSIGNED PRIMARY KEY NOT NULL,
name VARCHAR(64) NOT NULL);
name VARCHAR(64) NOT NULL
) ENGINE=INNODB;
# Insert currently defined state names.
INSERT INTO lease_state VALUES (0, "default");
INSERT INTO lease_state VALUES (1, "declined");
INSERT INTO lease_state VALUES (2, "expired-reclaimed");
# Add a constraint that any state value added to the lease4 must
# map to a value in the lease_state table.
ALTER TABLE lease4
ADD CONSTRAINT fk_lease4_state FOREIGN KEY (state)
REFERENCES lease_state (state);
# Add a constraint that any state value added to the lease6 must
# map to a value in the lease_state table.
ALTER TABLE lease6
ADD CONSTRAINT fk_lease6_state FOREIGN KEY (state)
REFERENCES lease_state (state);
# Add a constraint that lease type in the lease6 table must map
# to a lease type defined in the lease6_types table.
ALTER TABLE lease6
ADD CONSTRAINT fk_lease6_type FOREIGN KEY (lease_type)
REFERENCES lease6_types (lease_type);
# Modify the name of one of the HW address sources, and add a new one.
UPDATE lease_hwaddr_source
SET name = 'HWADDR_SOURCE_DOCSIS_CMTS'
WHERE hwaddr_source = 64;
INSERT INTO lease_hwaddr_source VALUES (128, 'HWADDR_SOURCE_DOCSIS_MODEM');
# Add UNSIGNED to match with the lease6.
ALTER TABLE lease_hwaddr_source
MODIFY COLUMN hwaddr_source INT UNSIGNED NOT NULL;
# Add a constraint that non-null hwaddr_source in the lease6 table
# must map to an entry in the lease_hwaddr_source.
ALTER TABLE lease6
ADD CONSTRAINT fk_lease6_hwaddr_source FOREIGN KEY (hwaddr_source)
REFERENCES lease_hwaddr_source (hwaddr_source);
# FUNCTION that returns a result set containing the column names for lease4 dumps
DROP PROCEDURE IF EXISTS lease4DumpHeader;
DELIMITER $$
......
......@@ -28,21 +28,57 @@ ALTER TABLE lease6
# by the expiration time. One of the applications is to retrieve all
# expired leases. However, these indexes can be also used to retrieve
# leases in a given state regardless of the expiration time.
CREATE INDEX lease4_by_state_expire ON lease4 (state, expire);
CREATE INDEX lease6_by_state_expire ON lease6 (state, expire);
CREATE INDEX lease4_by_state_expire ON lease4 (state ASC, expire ASC);
CREATE INDEX lease6_by_state_expire ON lease6 (state ASC, expire ASC);
# Create table holding mapping of the lease states to their names.
# This is not used in queries from the DHCP server but rather in
# direct queries from the lease database management tools.
CREATE TABLE IF NOT EXISTS lease_state (
state INT UNSIGNED PRIMARY KEY NOT NULL,
name VARCHAR(64) NOT NULL);
name VARCHAR(64) NOT NULL
) ENGINE=INNODB;
# Insert currently defined state names.
INSERT INTO lease_state VALUES (0, "default");
INSERT INTO lease_state VALUES (1, "declined");
INSERT INTO lease_state VALUES (2, "expired-reclaimed");
# Add a constraint that any state value added to the lease4 must
# map to a value in the lease_state table.
ALTER TABLE lease4
ADD CONSTRAINT fk_lease4_state FOREIGN KEY (state)
REFERENCES lease_state (state);
# Add a constraint that any state value added to the lease6 must
# map to a value in the lease_state table.
ALTER TABLE lease6
ADD CONSTRAINT fk_lease6_state FOREIGN KEY (state)
REFERENCES lease_state (state);
# Add a constraint that lease type in the lease6 table must map
# to a lease type defined in the lease6_types table.
ALTER TABLE lease6
ADD CONSTRAINT fk_lease6_type FOREIGN KEY (lease_type)
REFERENCES lease6_types (lease_type);
# Modify the name of one of the HW address sources, and add a new one.
UPDATE lease_hwaddr_source
SET name = 'HWADDR_SOURCE_DOCSIS_CMTS'
WHERE hwaddr_source = 64;
INSERT INTO lease_hwaddr_source VALUES (128, 'HWADDR_SOURCE_DOCSIS_MODEM');
# Add UNSIGNED to match with the lease6.
ALTER TABLE lease_hwaddr_source
MODIFY COLUMN hwaddr_source INT UNSIGNED NOT NULL DEFAULT 0;
# Add a constraint that non-null hwaddr_source in the lease6 table
# must map to an entry in the lease_hwaddr_source.
ALTER TABLE lease6
ADD CONSTRAINT fk_lease6_hwaddr_source FOREIGN KEY (hwaddr_source)
REFERENCES lease_hwaddr_source (hwaddr_source);
# FUNCTION that returns a result set containing the column names for lease4 dumps
DROP PROCEDURE IF EXISTS lease4DumpHeader;
DELIMITER $$
......
-- Copyright (C) 2012-2013 Internet Systems Consortium.
-- Copyright (C) 2012-2015 Internet Systems Consortium.
-- Permission to use, copy, modify, and distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
......@@ -13,7 +13,7 @@
-- NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
-- WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-- This is the BIND 10 DHCP schema specification for PostgreSQL.
-- This is the Kea DHCP schema specification for PostgreSQL.
-- The schema is reasonably portable (with the exception of some field types
-- specification, which are PostgreSQL-specific). Minor changes might be needed
......@@ -50,41 +50,6 @@ CREATE INDEX lease4_by_hwaddr_subnet_id ON lease4 (hwaddr, subnet_id);
-- index by client_id and subnet_id
CREATE INDEX lease4_by_client_id_subnet_id ON lease4 (client_id, subnet_id);
--
-- FUNCTION that returns a result set containing the column names for lease4 dumps
DROP FUNCTION IF EXISTS lease4DumpHeader();
CREATE FUNCTION lease4DumpHeader() RETURNS text AS $$
select cast('address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname' as text) as result;
$$ LANGUAGE SQL;
--
--
-- FUNCTION that returns a result set containing the data for lease4 dumps
DROP FUNCTION IF EXISTS lease4DumpData();
CREATE FUNCTION lease4DumpData() RETURNS
table (address inet,
hwaddr text,
client_id text,
valid_lifetime bigint,
expire timestamp with time zone,
subnet_id bigint,
fqdn_fwd int,
fqdn_rev int,
hostname text
) as $$
SELECT ('0.0.0.0'::inet + address),
encode(hwaddr,'hex'),
encode(client_id,'hex'),
valid_lifetime,
expire,
subnet_id,
fqdn_fwd::int,
fqdn_rev::int,
hostname
from lease4;
$$ LANGUAGE SQL;
--
-- Holds the IPv6 leases.
-- N.B. The use of a VARCHAR for the address is temporary for development:
-- it will eventually be replaced by BINARY(16).
......@@ -138,11 +103,100 @@ START TRANSACTION;
INSERT INTO schema_version VALUES (1, 0);
COMMIT;
--
-- Schema 2.0 specification starts here.
--
-- Add state column to the lease4 table.
ALTER TABLE lease4
ADD COLUMN state INT8 DEFAULT 0;
-- Add state column to the lease6 table.
ALTER TABLE lease6
ADD COLUMN state INT8 DEFAULT 0;
-- Create indexes for querying leases in a given state and segregated
-- by the expiration time. One of the applications is to retrieve all
-- expired leases. However, these indexes can be also used to retrieve
-- leases in a given state regardless of the expiration time.
CREATE INDEX lease4_by_state_expire ON lease4 (state ASC, expire ASC);
CREATE INDEX lease6_by_state_expire ON lease6 (state ASC, expire ASC);
-- Create table holding mapping of the lease states to their names.
-- This is not used in queries from the DHCP server but rather in
-- direct queries from the lease database management tools.
CREATE TABLE lease_state (
state INT8 PRIMARY KEY NOT NULL,
name VARCHAR(64) NOT NULL);
-- Insert currently defined state names.
START TRANSACTION;
INSERT INTO lease_state VALUES (0, 'default');
INSERT INTO lease_state VALUES (1, 'declined');
INSERT INTO lease_state VALUES (2, 'expired-reclaimed');
COMMIT;
-- Add a constraint that any state value added to the lease4 must
-- map to a value in the lease_state table.
ALTER TABLE lease4
ADD CONSTRAINT fk_lease4_state FOREIGN KEY (state)
REFERENCES lease_state (state);
-- Add a constraint that any state value added to the lease6 must
-- map to a value in the lease_state table.
ALTER TABLE lease6
ADD CONSTRAINT fk_lease6_state FOREIGN KEY (state)
REFERENCES lease_state (state);
-- Add a constraint that lease type in the lease6 table must map
-- to a lease type defined in the lease6_types table.
ALTER TABLE lease6
ADD CONSTRAINT fk_lease6_type FOREIGN KEY (lease_type)
REFERENCES lease6_types (lease_type);
--
-- FUNCTION that returns a result set containing the column names for lease4 dumps
DROP FUNCTION IF EXISTS lease4DumpHeader();
CREATE FUNCTION lease4DumpHeader() RETURNS text AS $$
select cast('address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state' as text) as result;
$$ LANGUAGE SQL;
--
--
-- FUNCTION that returns a result set containing the data for lease4 dumps
DROP FUNCTION IF EXISTS lease4DumpData();
CREATE FUNCTION lease4DumpData() RETURNS
table (address inet,
hwaddr text,
client_id text,
valid_lifetime bigint,
expire timestamp with time zone,
subnet_id bigint,
fqdn_fwd int,
fqdn_rev int,
hostname text,
state text
) as $$
SELECT ('0.0.0.0'::inet + l.address),
encode(l.hwaddr,'hex'),
encode(l.client_id,'hex'),
l.valid_lifetime,
l.expire,
l.subnet_id,
l.fqdn_fwd::int,
l.fqdn_rev::int,
l.hostname,
s.name
FROM lease4 l
left outer join lease_state s on (l.state = s.state);
$$ LANGUAGE SQL;
--
--
-- FUNCTION that returns a result set containing the column names for lease6 dumps
DROP FUNCTION IF EXISTS lease6DumpHeader();
CREATE FUNCTION lease6DumpHeader() RETURNS text AS $$
select cast('address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname' as text) as result;
select cast('address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,state' as text) as result;
$$ LANGUAGE SQL;
--
......@@ -162,7 +216,8 @@ CREATE FUNCTION lease6DumpData() RETURNS
prefix_len smallint,
fqdn_fwd int,
fqdn_rev int,
hostname text
hostname text,
state text
) AS $$
SELECT (l.address,
encode(l.duid,'hex'),
......@@ -175,11 +230,22 @@ CREATE FUNCTION lease6DumpData() RETURNS
l.prefix_len,
l.fqdn_fwd::int,
l.fqdn_rev::int,
l.hostname)
FROM lease6 l left outer join lease6_types t on (l.lease_type = t.lease_type);
l.hostname,
s.name)
FROM lease6 l
left outer join lease6_types t on (l.lease_type = t.lease_type)
left outer join lease_state s on (l.state = s.state);
$$ LANGUAGE SQL;
--
-- Set 2.0 schema version.
START TRANSACTION;
UPDATE schema_version
SET version = '2', minor = '0';
COMMIT;
-- Schema 2.0 specification ends here.
-- Notes:
-- Indexes
......@@ -192,9 +258,6 @@ $$ LANGUAGE SQL;
-- The most likely additional indexes will cover the following columns:
-- expire
-- To speed up the deletion of expired leases from the database.
-- hwaddr and client_id
-- For lease stability: if a client requests a new lease, try to find an
-- existing or recently expired lease for it so that it can keep using the
......@@ -202,8 +265,8 @@ $$ LANGUAGE SQL;
-- Field Sizes
-- ===========
-- If any of the VARxxx field sizes are altered, the lengths in the MySQL
-- backend source file (mysql_lease_mgr.cc) must be correspondingly changed.
-- If any of the VARxxx field sizes are altered, the lengths in the PgSQL
-- backend source file (pgsql_lease_mgr.cc) must be correspondingly changed.
-- Portability
-- ===========
......
address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,hwtype,hwaddr_source,state
10,3230,30,2015-04-04 01:15:30,40,50,IA_TA,60,70,1,1,one.example.com,3830,90,,default
11,,30,2015-05-05 02:30:45,40,50,IA_TA,60,70,1,1,,3830,90,HWADDR_SOURCE_RAW,declined
12,3231,30,2015-06-06 11:01:07,40,50,IA_TA,60,70,1,1,three.example.com,3830,90,HWADDR_SOURCE_DUID,expired-reclaimed
10,3230,30,2015-04-04 01:15:30,40,50,IA_TA,60,70,1,1,one.example.com,3830,90,HWADDR_SOURCE_REMOTE_ID,default
address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname
0.0.0.10,20,30,40,<timestamp1>,50,1,1,one.example.com
0.0.0.11,,013233,40,<timestamp2>,50,1,1,
0.0.0.12,22,,40,<timestamp3>,50,1,1,three.example.com
address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state
0.0.0.10,20,30,40,<timestamp1>,50,1,1,one.example.com,default
0.0.0.11,,013233,40,<timestamp2>,50,1,1,,declined
0.0.0.12,22,,40,<timestamp3>,50,1,1,three.example.com,expired-reclaimed
address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname
12,21,30,<timestamp3>,40,50,IA_TA,60,70,1,1,three.example.com
11,,30,<timestamp2>,40,50,IA_TA,60,70,1,1,
10,20,30,<timestamp1>,40,50,IA_TA,60,70,1,1,one.example.com
address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,state
12,21,30,<timestamp3>,40,50,IA_TA,60,70,1,1,three.example.com,expired-reclaimed
11,,30,<timestamp2>,40,50,IA_TA,60,70,1,1,,declined
10,20,30,<timestamp1>,40,50,IA_TA,60,70,1,1,one.example.com,default
......@@ -395,7 +395,7 @@ mysql_lease6_dump_test() {
# Insert the reference record
insert_sql="\
insert into lease6 values(10,20,30,\"2015-04-04 01:15:30\",40,50,1,60,70,1,1,\"one.example.com\",80,90,0,0);\
insert into lease6 values(10,20,30,\"2015-04-04 01:15:30\",40,50,1,60,70,1,1,\"one.example.com\",80,90,16,0);\
insert into lease6 values(11,NULL,30,\"2015-05-05 02:30:45\",40,50,1,60,70,1,1,\"\",80,90,1,1);\
insert into lease6 values(12,21,30,\"2015-06-06 11:01:07\",40,50,1,60,70,1,1,\"three.example.com\",80,90,4,2);"
......
......@@ -68,17 +68,21 @@ pgsql_lease_init_test() {
assert_eq 0 $? "schema_version table check failed, expected exit code: %d, actual: %d"
# Check lease4 table
RESULT=`pgsql_execute "SELECT address, hwaddr, client_id, valid_lifetime, expire, subnet_id, fqdn_fwd, fqdn_rev, hostname FROM lease4;"`
RESULT=`pgsql_execute "SELECT address, hwaddr, client_id, valid_lifetime, expire, subnet_id, fqdn_fwd, fqdn_rev, hostname, state FROM lease4;"`
assert_eq 0 $? "lease4 table check failed, expected exit code: %d, actual: %d"
# Check lease6 table
RESULT=`pgsql_execute "SELECT address, duid, valid_lifetime, expire, subnet_id, pref_lifetime, lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname FROM lease6;"`
RESULT=`pgsql_execute "SELECT address, duid, valid_lifetime, expire, subnet_id, pref_lifetime, lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, state FROM lease6;"`
assert_eq 0 $? "lease6 table check failed, expected exit code: %d, actual: %d"
# Check lease6_types table
RESULT=`pgsql_execute "SELECT lease_type, name FROM lease6_types;"`
assert_eq 0 $? "lease6_types table check failed, expected exit code: %d, actual: %d"
# Check lease_state table
RESULT=`pgsql_execute "SELECT state, name FROM lease_state;"`
assert_eq 0 $? "lease_state table check failed, expected exit code: %d, actual: %d"
# Trying to create it again should fail. This verifies the db present
# check
echo ""
......@@ -104,7 +108,7 @@ pgsql_lease_version_test() {
# Verfiy that kea-admin lease-version returns the correct version
version=$(${keaadmin} lease-version pgsql -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"
# Let's wipe the whole database
pgsql_wipe
......@@ -195,9 +199,9 @@ pgsql_lease4_dump_test() {
# Insert the reference records
insert_sql="\
insert into lease4 values(10,E'\\x20',E'\\x30',40,'$timestamp1',50,'t','t','one.example.com');\
insert into lease4 values(11,'',E'\\x0123',40,'$timestamp2',50,'t','t','');\
insert into lease4 values(12,E'\\x22','',40,'$timestamp3',50,'t','t','three.example.com');"
insert into lease4 values(10,E'\\x20',E'\\x30',40,'$timestamp1',50,'t','t','one.example.com', 0);\
insert into lease4 values(11,'',E'\\x0123',40,'$timestamp2',50,'t','t','', 1);\
insert into lease4 values(12,E'\\x22','',40,'$timestamp3',50,'t','t','three.example.com', 2);"
pgsql_execute "$insert_sql"
ERRCODE=$?
......@@ -290,9 +294,9 @@ pgsql_lease6_dump_test() {
# Insert the reference records
insert_sql="\
insert into lease6 values(10,E'\\x20',30,'$timestamp1',40,50,1,60,70,'t','t','one.example.com');\
insert into lease6 values(11,'',30,'$timestamp2',40,50,1,60,70,'t','t','');\
insert into lease6 values(12,E'\\x21',30,'$timestamp3',40,50,1,60,70,'t','t','three.example.com');"
insert into lease6 values(10,E'\\x20',30,'$timestamp1',40,50,1,60,70,'t','t','one.example.com', 0);\
insert into lease6 values(11,'',30,'$timestamp2',40,50,1,60,70,'t','t','', 1);\
insert into lease6 values(12,E'\\x21',30,'$timestamp3',40,50,1,60,70,'t','t','three.example.com', 2);"
pgsql_execute "$insert_sql"
ERRCODE=$?
......
......@@ -546,6 +546,28 @@ A debug message issued when the server is attempting to obtain a set
of IPv4 leases from the PostgreSQL database for a client with the specified
client identification.
% DHCPSRV_PGSQL_GET_EXPIRED4 obtaining maximum %1 of expired IPv4 leases
A debug message issued when the server is attempting to obtain expired
IPv4 leases to reclaim them. The maximum number of leases to be retrieved
is logged in the message.
% DHCPSRV_PGSQL_GET_EXPIRED6 obtaining maximum %1 of expired IPv6 leases
A debug message issued when the server is attempting to obtain expired
IPv6 leases to reclaim them. The maximum number of leases to be retrieved
is logged in the message.
% DHCPSRV_PGSQL_DELETE_EXPIRED_RECLAIMED4 deleting reclaimed IPv4 leases that expired more than %1 seconds ago
A debug message issued when the server is removing reclaimed DHCPv4
leases which have expired longer than a specified period of time.
The argument is the amount of time Kea waits after a reclaimed
lease expires before considering its removal.
% DHCPSRV_PGSQL_DELETE_EXPIRED_RECLAIMED6 deleting reclaimed IPv6 leases that expired more than %1 seconds ago
A debug message issued when the server is removing reclaimed DHCPv6
leases which have expired longer than a specified period of time.
The argument is the amount of time Kea waits after a reclaimed
lease expires before considering its removal.
% DHCPSRV_PGSQL_GET_HWADDR obtaining IPv4 leases for hardware address %1
A debug message issued when the server is attempting to obtain a set
of IPv4 leases from the PostgreSQL database for a client with the specified
......
......@@ -143,7 +143,7 @@ TaggedStatement tagged_statements[] = {
"state "
"FROM lease4 "
"WHERE state != ? AND expire < ? "
"ORDER BY expire "
"ORDER BY expire ASC "
"LIMIT ?"},
{MySqlLeaseMgr::GET_LEASE6_ADDR,
"SELECT address, duid, valid_lifetime, "
......@@ -182,7 +182,7 @@ TaggedStatement tagged_statements[] = {
"state "
"FROM lease6 "
"WHERE state != ? AND expire < ? "
"ORDER BY expire "
"ORDER BY expire ASC "
"LIMIT ?"},
{MySqlLeaseMgr::GET_VERSION,
"SELECT version, minor FROM schema_version"},
......
......@@ -24,6 +24,7 @@
#include <iostream>
#include <iomanip>
#include <limits>
#include <sstream>
#include <string>
#include <time.h>
......@@ -49,7 +50,7 @@ using namespace std;
namespace {
// Maximum number of parameters used in any single query
const size_t MAX_PARAMETERS_IN_QUERY = 13;
const size_t MAX_PARAMETERS_IN_QUERY = 14;
/// @brief Defines a single query
struct TaggedStatement {
......@@ -91,17 +92,29 @@ TaggedStatement tagged_statements[] = {
"delete_lease4",
"DELETE FROM lease4 WHERE address = $1"},
// DELETE_LEASE4_STATE_EXPIRED
{ 2, { OID_INT8, OID_TIMESTAMP },
"delete_lease4_state_expired",
"DELETE FROM lease4 "
"WHERE state = $1 AND expire < $2"},
// DELETE_LEASE6
{ 1, { OID_VARCHAR },
"delete_lease6",
"DELETE FROM lease6 WHERE address = $1"},
// DELETE_LEASE6_STATE_EXPIRED
{ 2, { OID_INT8, OID_TIMESTAMP },
"delete_lease6_state_expired",
"DELETE FROM lease6 "
"WHERE state = $1 AND expire < $2"},
// GET_LEASE4_ADDR
{ 1, { OID_INT8 },
"get_lease4_addr",
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname "
"fqdn_fwd, fqdn_rev, hostname, state "
"FROM lease4 "
"WHERE address = $1"},
......@@ -110,7 +123,7 @@ TaggedStatement tagged_statements[] = {
"get_lease4_clientid",
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname "
"fqdn_fwd, fqdn_rev, hostname, state "
"FROM lease4 "
"WHERE client_id = $1"},
......@@ -119,7 +132,7 @@ TaggedStatement tagged_statements[] = {
"get_lease4_clientid_subid",
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname "
"fqdn_fwd, fqdn_rev, hostname, state "
"FROM lease4 "
"WHERE client_id = $1 AND subnet_id = $2"},
......@@ -128,7 +141,7 @@ TaggedStatement tagged_statements[] = {
"get_lease4_hwaddr",
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname "
"fqdn_fwd, fqdn_rev, hostname, state "
"FROM lease4 "
"WHERE hwaddr = $1"},
......@@ -137,16 +150,28 @@ TaggedStatement tagged_statements[] = {
"get_lease4_hwaddr_subid",
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname "
"fqdn_fwd, fqdn_rev, hostname, state "
"FROM lease4 "
"WHERE hwaddr = $1 AND subnet_id = $2"},
// GET_LEASE4_EXPIRE
{ 3, { OID_INT8, OID_TIMESTAMP, OID_INT8 },
"get_lease4_expire",
"SELECT address, hwaddr, client_id, "
"valid_lifetime, extract(epoch from expire)::bigint, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, state "
"FROM lease4 "
"WHERE state != $1 AND expire < $2 "
"ORDER BY expire "
"LIMIT $3"},
// GET_LEASE6_ADDR
{ 2, { OID_VARCHAR, OID_INT2 },
"get_lease6_addr",
"SELECT address, duid, valid_lifetime, "
"extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname "
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
"state "
"FROM lease6 "
"WHERE address = $1 AND lease_type = $2"},
......@@ -155,7 +180,8 @@ TaggedStatement tagged_statements[] = {
"get_lease6_duid_iaid",
"SELECT address, duid, valid_lifetime, "
"extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname "
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
"state "
"FROM lease6 "
"WHERE duid = $1 AND iaid = $2 AND lease_type = $3"},
......@@ -164,53 +190,70 @@ TaggedStatement tagged_statements[] = {
"get_lease6_duid_iaid_subid",
"SELECT address, duid, valid_lifetime, "
"extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname "
"lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
"state "
"FROM lease6 "
"WHERE lease_type = $1 "
"AND duid = $2 AND iaid = $3 AND subnet_id = $4"},
// GET_LEASE6_EXPIRE
{ 3, { OID_INT8, OID_TIMESTAMP, OID_INT8 },
"get_lease6_expire",
"SELECT address, duid, valid_lifetime, "
"extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
"lease_type, iaid, prefix_len, "
"fqdn_fwd, fqdn_rev, hostname, state "
"state "
"FROM lease6 "
"WHERE state != $1 AND expire < $2 "
"ORDER BY expire "
"LIMIT $3"},
// GET_VERSION
{ 0, { OID_NONE },
"get_version",
"SELECT version, minor FROM schema_version"},
// INSERT_LEASE4
{ 9, { OID_INT8, OID_BYTEA, OID_BYTEA, OID_INT8, OID_TIMESTAMP, OID_INT8,
OID_BOOL, OID_BOOL, OID_VARCHAR },
{ 10, { OID_INT8, OID_BYTEA, OID_BYTEA, OID_INT8, OID_TIMESTAMP, OID_INT8,
OID_BOOL, OID_BOOL, OID_VARCHAR, OID_INT8, OID_INT8 },
"insert_lease4",
"INSERT INTO lease4(address, hwaddr, client_id, "
"valid_lifetime, expire, subnet_id, fqdn_fwd, fqdn_rev, hostname) "
"VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)"},
"valid_lifetime, expire, subnet_id, fqdn_fwd, fqdn_rev, hostname, "