]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#4373] Added SFLQ tables for postreSQL
authorThomas Markwalder <tmark@isc.org>
Sun, 8 Mar 2026 15:59:26 +0000 (11:59 -0400)
committerThomas Markwalder <tmark@isc.org>
Tue, 31 Mar 2026 14:33:50 +0000 (14:33 +0000)
new file:   upgrade_032_to_033.sh.in

/src/bin/admin/tests/mysql_tests.sh.in
    Added test one function shortcut

/src/bin/admin/tests/pgsql_tests.sh.in
    Added test one function shortcut
    Updated version number
    Added pgsql_upgrade_32_to_33_test()

/src/lib/pgsql/pgsql_connection.h
    Updated version number

/src/share/database/scripts/pgsql/dhcpdb_create.pgsql
/src/share/database/scripts/pgsql/dhcpdb_drop.pgsql
    Added SFLQ tables

/src/share/database/scripts/pgsql/meson.build
    Added upgrade_032_to_033.sh.in

src/bin/admin/tests/mysql_tests.sh.in
src/bin/admin/tests/pgsql_tests.sh.in
src/share/database/scripts/pgsql/dhcpdb_create.pgsql
src/share/database/scripts/pgsql/dhcpdb_drop.pgsql
src/share/database/scripts/pgsql/upgrade_032_to_033.sh.in

index 69edab84ffd0b866a43f5a844454526114b46932..6971c4cfe34b5e21c1e5bcd96be6c72927223c8d 100755 (executable)
@@ -4069,6 +4069,13 @@ mysql_migrate_dhcpX_options_client_classes() {
     test_finish 0
 }
 
+# Handy shortcut for running a single test.
+if [ $# -gt 0 ]; then
+    echo "RUNNING ${1} only"
+    ${1}
+    exit $?
+fi
+
 # Run tests.
 mysql_db_init_test
 mysql_host_reservation_init_test
index 6dea37452594f71ca307f3582bacc959ac7b8792..6acbd1dbc1d1340cac6017bce616ffcd2099b446 100755 (executable)
@@ -1098,6 +1098,77 @@ pgsql_upgrade_32_to_33_test() {
     run_command \
         pgsql_execute "${qry}"
     assert_eq 3 "${EXIT_CODE}" "select isJsonSupported() should have failed. (expected status code %d, returned %d)"
+
+    # Makse sure all four SFLQ tables exist.
+    check_table_column start_address flq_pool4
+    check_table_column address free_lease4
+    check_table_column start_address flq_pool6
+    check_table_column address free_lease4
+
+#    # Verify incrementV6Prefix.
+#    qry="select inet6_ntoa(incrementV6Prefix(inet6_aton('1020:3040:5060:70FF:90A0:B0C0:0DE0:F000'), 64))"
+#    run_command \
+#        pgsql_execute "${qry}"
+#    assert_eq 0 "${EXIT_CODE}" "select incrementV6Prefix failed. (expected status code %d, returned %d)"
+#    count=$(echo "${OUTPUT}" | grep -Fci "1020:3040:5060:7100:90a0:b0c0:de0:f000")
+#    assert_eq 1 "${count}" "incrementV6Prefix output is wrong. (expected count %d, actual %d)"
+#
+#    # Verify createShareFlqPool4.
+#    qry="call createShareFlqPool4(inet_aton('127.0.0.0'), inet_aton('127.0.0.1'), 0, 0)"
+#    run_command \
+#        pgsql_execute "${qry}"
+#    assert_eq 0 "${EXIT_CODE}" "call createShareFlqPool4 failed. (expected status code %d, returned %d)"
+#
+#    qry="select count(start_address) from flq_pool4 where start_address = inet_aton('127.0.0.0')\
+#         and end_address = inet_aton('127.0.0.1')"
+#    run_command \
+#        pgsql_execute "${qry}"
+#    assert_eq 0 "${EXIT_CODE}" "select from flq_pool4 failed. (expected status code %d, returned %d)"
+#    count="${OUTPUT}"
+#    assert_eq 1 "${count}" "flq_pool4 content wrong. (expected count %d, actual %d)"
+#
+#    qry="select count(address) from free_lease4 join flq_pool4 where\
+#         address >= flq_pool4.start_address and address <= flq_pool4.end_address"
+#    run_command \
+#        pgsql_execute "${qry}"
+#    assert_eq 0 "${EXIT_CODE}" "select from free_lease4 failed. (expected status code %d, returned %d)"
+#    count="${OUTPUT}"
+#    assert_eq 2 "${count}" "free_lease4 content wrong. (expected count %d, actual %d)"
+#
+#    # Verify pickFreeLease4.
+#    qry="select inet_ntoa(pickFreeLease4(inet_aton('127.0.0.0'),inet_aton('127.0.0.1')))"
+#    run_command \
+#        pgsql_execute "${qry}"
+#    assert_eq 0 "${EXIT_CODE}" "select from pickFreeLease4 failed. (expected status code %d, returned %d)"
+#    assert_str_eq '127.0.0.0' "${OUTPUT}"
+#
+#    # Verify createShareFlqPool6.
+#    qry="call createShareFlqPool6('3001::', '3001::1', 2, 1, 128, 0)"
+#    run_command \
+#        pgsql_execute "${qry}"
+#    assert_eq 0 "${EXIT_CODE}" "call createShareFlqPool6 failed. (expected status code %d, returned %d)"
+#
+#    qry="select count(start_address) from flq_pool6 where start_address = '3001::'\
+#         and end_address = '3001::1'"
+#    run_command \
+#        pgsql_execute "${qry}"
+#    assert_eq 0 "${EXIT_CODE}" "select from flq_pool6 failed. (expected status code %d, returned %d)"
+#    count="${OUTPUT}"
+#    assert_eq 1 "${count}" "flq_pool6 content wrong. (expected count %d, actual %d)"
+#
+#    qry="select count(address) from free_lease6 join flq_pool6 where\
+#         address >= flq_pool6.start_address and address <= flq_pool6.end_address"
+#    run_command \
+#        pgsql_execute "${qry}"
+#    assert_eq 0 "${EXIT_CODE}" "select from free_lease6 failed. (expected status code %d, returned %d)"
+#    count="${OUTPUT}"
+#
+#    # Verify pickFreeLease6.
+#    qry="select pickFreeLease6('3001::', '3001::1')"
+#    run_command \
+#        pgsql_execute "${qry}"
+#    assert_eq 0 "${EXIT_CODE}" "select from pickFreeLease6 failed. (expected status code %d, returned %d)"
+#    assert_str_eq '3001::' "${OUTPUT}"
 }
 
 pgsql_upgrade_test() {
@@ -3151,6 +3222,13 @@ pgsql_migrate_dhcpX_options_client_classes() {
     test_finish 0
 }
 
+# Handy shortcut for running a single test.
+if [ $# -gt 0 ]; then
+    echo "RUNNING ${1} only"
+    ${1}
+    exit $?
+fi
+
 # Run tests.
 pgsql_db_init_test
 pgsql_db_version_test
index 199e099949c748cec9d585700f83e80eaf6f6156..dc6aa8fbc5c18b3030ae8c92918b412aa502ef6c 100644 (file)
@@ -6816,6 +6816,52 @@ BEGIN
 END;
 $lease6_ADEL$ LANGUAGE plpgsql;
 
+-- Create the SFLQ tables.
+
+DROP TABLE IF EXISTS flq_pool4;
+CREATE TABLE IF NOT EXISTS flq_pool4 (
+    id SERIAL PRIMARY KEY NOT NULL,
+    start_address INET NOT NULL,
+    end_address INET NOT NULL,
+    last_returned_address INET NOT NULL DEFAULT '0.0.0.0',
+    subnet_id BIGINT NOT NULL,
+    created_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
+    modification_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
+);
+
+CREATE UNIQUE INDEX flq_pool4_start_end_address ON flq_pool4 (start_address, end_address);
+CREATE INDEX flq_pool4_by_subnet_id ON flq_pool4 (subnet_id);
+
+DROP TABLE IF EXISTS free_lease4;
+CREATE TABLE IF NOT EXISTS free_lease4 (
+    address INET PRIMARY KEY NOT NULL,
+    modification_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
+);
+
+DROP TABLE IF EXISTS flq_pool6;
+CREATE TABLE IF NOT EXISTS flq_pool6 (
+    id SERIAL PRIMARY KEY NOT NULL,
+    start_address INET NOT NULL,
+    end_address INET NOT NULL,
+    lease_type SMALLINT NOT NULL,
+    delegated_len SMALLINT NOT NULL,
+    last_returned_address INET NOT NULL DEFAULT ('::'),
+    subnet_id BIGINT NOT NULL,
+    created_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
+    modification_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
+);
+
+CREATE UNIQUE INDEX flq_pool6_start_end_address ON flq_pool6 (start_address, end_address);
+CREATE INDEX flq_pool6_by_subnet_id ON flq_pool6 (subnet_id);
+
+DROP TABLE IF EXISTS free_lease6;
+CREATE TABLE IF NOT EXISTS free_lease6 (
+    lease_type SMALLINT NOT NULL,
+    address INET NOT NULL,
+    modification_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
+    PRIMARY KEY (address, lease_type)
+);
+
 -- Update the schema version number.
 UPDATE schema_version
     SET version = '33', minor = '0';
index c644898d08f054cbf65e93565074862633686170..7462ea031179b30c4e9168088e7e0ef944751c49 100644 (file)
@@ -248,3 +248,11 @@ DROP FUNCTION IF EXISTS json_cast(json_candidate TEXT);
 -- v6 BLQ cross-tables
 DROP TABLE IF EXISTS lease6_relay_id;
 DROP TABLE IF EXISTS lease6_remote_id;
+
+-- Drop SFLQ tables and procedures
+DROP PROCEDURE IF EXISTS createShareFlqPool4;
+DROP PROCEDURE IF EXISTS createShareFlqPool6;
+DROP TABLE IF EXISTS free_lease4;
+DROP TABLE IF EXISTS flq_pool4;
+DROP TABLE IF EXISTS free_lease6;
+DROP TABLE IF EXISTS flq_pool6;
index 804093db73f66cafe35b02a7f268e2a5e843d7c3..665ec2d55dc9564c5a9081bb1557ac011dd75fad 100755 (executable)
@@ -102,6 +102,52 @@ BEGIN
 END;
 \$lease6_ADEL\$ LANGUAGE plpgsql;
 
+-- Create the SFLQ tables.
+
+DROP TABLE IF EXISTS flq_pool4;
+CREATE TABLE IF NOT EXISTS flq_pool4 (
+    id SERIAL PRIMARY KEY NOT NULL,
+    start_address INET NOT NULL,
+    end_address INET NOT NULL,
+    last_returned_address INET NOT NULL DEFAULT '0.0.0.0',
+    subnet_id BIGINT NOT NULL,
+    created_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
+    modification_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
+);
+
+CREATE UNIQUE INDEX flq_pool4_start_end_address ON flq_pool4 (start_address, end_address);
+CREATE INDEX flq_pool4_by_subnet_id ON flq_pool4 (subnet_id);
+
+DROP TABLE IF EXISTS free_lease4;
+CREATE TABLE IF NOT EXISTS free_lease4 (
+    address INET PRIMARY KEY NOT NULL,
+    modification_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
+);
+
+DROP TABLE IF EXISTS flq_pool6;
+CREATE TABLE IF NOT EXISTS flq_pool6 (
+    id SERIAL PRIMARY KEY NOT NULL,
+    start_address INET NOT NULL,
+    end_address INET NOT NULL,
+    lease_type SMALLINT NOT NULL,
+    delegated_len SMALLINT NOT NULL,
+    last_returned_address INET NOT NULL DEFAULT ('::'),
+    subnet_id BIGINT NOT NULL,
+    created_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
+    modification_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
+);
+
+CREATE UNIQUE INDEX flq_pool6_start_end_address ON flq_pool6 (start_address, end_address);
+CREATE INDEX flq_pool6_by_subnet_id ON flq_pool6 (subnet_id);
+
+DROP TABLE IF EXISTS free_lease6;
+CREATE TABLE IF NOT EXISTS free_lease6 (
+    lease_type SMALLINT NOT NULL,
+    address INET NOT NULL,
+    modification_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
+    PRIMARY KEY (address, lease_type)
+);
+
 -- Update the schema version number.
 UPDATE schema_version
     SET version = '33', minor = '0';