summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRazvan Becheriu <razvan@isc.org>2023-03-13 19:00:19 +0100
committerRazvan Becheriu <razvan@isc.org>2023-05-09 13:26:04 +0200
commitfa5492d4b7064e425ecb5313d2496acef736d363 (patch)
treeb4937ab7b6657708a9d703fe1247c20c9dbecc89
parent[#2838] fixing Sphinx error in ARM (diff)
downloadkea-fa5492d4b7064e425ecb5313d2496acef736d363.tar.xz
kea-fa5492d4b7064e425ecb5313d2496acef736d363.zip
[#2786] 255 bytes client_id and 130 bytes duid
-rw-r--r--src/bin/admin/tests/data/lease6_dump_test.reference.csv6
-rw-r--r--src/bin/admin/tests/memfile_tests.sh.in2
-rw-r--r--src/bin/admin/tests/mysql_tests.sh.in83
-rw-r--r--src/bin/admin/tests/pgsql_tests.sh.in108
-rw-r--r--src/bin/dhcp4/client_handler.cc30
-rw-r--r--src/bin/dhcp4/client_handler.h16
-rw-r--r--src/bin/dhcp4/dhcp4_srv.cc4
-rw-r--r--src/bin/dhcp4/tests/config_parser_unittest.cc8
-rw-r--r--src/bin/dhcp4/tests/decline_unittest.cc90
-rw-r--r--src/bin/dhcp4/tests/dhcp4_srv_unittest.cc10
-rw-r--r--src/bin/dhcp4/tests/dhcp4_test_utils.h5
-rw-r--r--src/bin/dhcp4/tests/hooks_unittest.cc24
-rw-r--r--src/bin/dhcp6/dhcp6_srv.cc6
-rw-r--r--src/bin/dhcp6/tests/decline_unittest.cc83
-rw-r--r--src/bin/dhcp6/tests/dhcp6_test_utils.h5
-rw-r--r--src/hooks/dhcp/run_script/run_script.cc19
-rw-r--r--src/hooks/dhcp/run_script/run_script.h10
-rw-r--r--src/hooks/dhcp/run_script/run_script_callouts.cc2
-rw-r--r--src/hooks/dhcp/run_script/tests/run_script_unittests.cc20
-rw-r--r--src/lib/dhcp/duid.cc112
-rw-r--r--src/lib/dhcp/duid.h186
-rw-r--r--src/lib/dhcp/duid_factory.cc9
-rw-r--r--src/lib/dhcp/tests/duid_unittest.cc111
-rw-r--r--src/lib/dhcp_ddns/tests/ncr_unittests.cc15
-rw-r--r--src/lib/dhcpsrv/allocator.h8
-rw-r--r--src/lib/dhcpsrv/flq_allocator.cc4
-rw-r--r--src/lib/dhcpsrv/flq_allocator.h4
-rw-r--r--src/lib/dhcpsrv/host.cc2
-rw-r--r--src/lib/dhcpsrv/iterative_allocator.cc4
-rw-r--r--src/lib/dhcpsrv/iterative_allocator.h15
-rw-r--r--src/lib/dhcpsrv/lease.cc2
-rw-r--r--src/lib/dhcpsrv/mysql_host_data_source.cc6
-rw-r--r--src/lib/dhcpsrv/mysql_lease_mgr.cc16
-rw-r--r--src/lib/dhcpsrv/parsers/host_reservation_parser.cc7
-rw-r--r--src/lib/dhcpsrv/pgsql_host_data_source.cc2
-rw-r--r--src/lib/dhcpsrv/random_allocator.cc4
-rw-r--r--src/lib/dhcpsrv/random_allocator.h15
-rw-r--r--src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc2
-rw-r--r--src/lib/dhcpsrv/tests/csv_lease_file6_unittest.cc19
-rw-r--r--src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc15
-rw-r--r--src/lib/dhcpsrv/tests/host_unittest.cc16
-rw-r--r--src/lib/dhcpsrv/tests/lease_unittest.cc2
-rw-r--r--src/share/database/scripts/mysql/dhcpdb_create.mysql285
-rw-r--r--src/share/database/scripts/mysql/upgrade_001.0_to_002.0.sh.in6
-rw-r--r--src/share/database/scripts/mysql/upgrade_002.0_to_003.0.sh.in124
-rw-r--r--src/share/database/scripts/mysql/upgrade_003.0_to_004.0.sh.in6
-rw-r--r--src/share/database/scripts/mysql/upgrade_004.0_to_004.1.sh.in5
-rw-r--r--src/share/database/scripts/mysql/upgrade_004.1_to_005.0.sh.in5
-rw-r--r--src/share/database/scripts/mysql/upgrade_005.0_to_005.1.sh.in5
-rw-r--r--src/share/database/scripts/mysql/upgrade_005.1_to_005.2.sh.in5
-rw-r--r--src/share/database/scripts/mysql/upgrade_005.2_to_006.0.sh.in5
-rw-r--r--src/share/database/scripts/mysql/upgrade_006.0_to_007.0.sh.in5
-rw-r--r--src/share/database/scripts/mysql/upgrade_007.0_to_008.0.sh.in6
-rw-r--r--src/share/database/scripts/mysql/upgrade_008.0_to_008.1.sh.in4
-rw-r--r--src/share/database/scripts/mysql/upgrade_008.1_to_008.2.sh.in5
-rw-r--r--src/share/database/scripts/mysql/upgrade_008.2_to_009.0.sh.in4
-rw-r--r--src/share/database/scripts/mysql/upgrade_009.0_to_009.1.sh.in4
-rw-r--r--src/share/database/scripts/mysql/upgrade_009.1_to_009.2.sh.in4
-rw-r--r--src/share/database/scripts/mysql/upgrade_009.2_to_009.3.sh.in4
-rw-r--r--src/share/database/scripts/mysql/upgrade_009.3_to_009.4.sh.in4
-rw-r--r--src/share/database/scripts/mysql/upgrade_009.4_to_009.5.sh.in4
-rw-r--r--src/share/database/scripts/mysql/upgrade_009.5_to_009.6.sh.in3
-rw-r--r--src/share/database/scripts/mysql/upgrade_009.6_to_010.0.sh.in3
-rw-r--r--src/share/database/scripts/mysql/upgrade_010_to_011.sh.in3
-rw-r--r--src/share/database/scripts/mysql/upgrade_011_to_012.sh.in3
-rw-r--r--src/share/database/scripts/mysql/upgrade_012_to_013.sh.in3
-rw-r--r--src/share/database/scripts/mysql/upgrade_013_to_014.sh.in2
-rw-r--r--src/share/database/scripts/mysql/upgrade_014_to_015.sh.in2
-rw-r--r--src/share/database/scripts/mysql/upgrade_015_to_016.sh.in3
-rw-r--r--src/share/database/scripts/mysql/upgrade_016_to_017.sh.in135
-rw-r--r--src/share/database/scripts/pgsql/dhcpdb_create.pgsql134
-rw-r--r--src/share/database/scripts/pgsql/upgrade_001.0_to_002.0.sh.in8
-rw-r--r--src/share/database/scripts/pgsql/upgrade_003.1_to_003.2.sh.in2
-rw-r--r--src/share/database/scripts/pgsql/upgrade_003.2_to_003.3.sh.in2
-rw-r--r--src/share/database/scripts/pgsql/upgrade_003.3_to_004.0.sh.in2
-rw-r--r--src/share/database/scripts/pgsql/upgrade_004.0_to_005.0.sh.in2
-rw-r--r--src/share/database/scripts/pgsql/upgrade_005.0_to_005.1.sh.in4
-rw-r--r--src/share/database/scripts/pgsql/upgrade_005.1_to_006.0.sh.in4
-rw-r--r--src/share/database/scripts/pgsql/upgrade_006.0_to_006.1.sh.in2
-rw-r--r--src/share/database/scripts/pgsql/upgrade_006.1_to_006.2.sh.in4
-rw-r--r--src/share/database/scripts/pgsql/upgrade_006.2_to_007.0.sh.in67
-rw-r--r--src/share/database/scripts/pgsql/upgrade_007_to_008.sh.in8
-rw-r--r--src/share/database/scripts/pgsql/upgrade_008_to_009.sh.in6
-rw-r--r--src/share/database/scripts/pgsql/upgrade_009_to_010.sh.in7
-rw-r--r--src/share/database/scripts/pgsql/upgrade_010_to_011.sh.in6
-rw-r--r--src/share/database/scripts/pgsql/upgrade_011_to_012.sh.in6
-rw-r--r--src/share/database/scripts/pgsql/upgrade_012_to_013.sh.in6
-rw-r--r--src/share/database/scripts/pgsql/upgrade_013_to_014.sh.in6
-rw-r--r--src/share/database/scripts/pgsql/upgrade_014_to_015.sh.in8
-rw-r--r--src/share/database/scripts/pgsql/upgrade_015_to_016.sh.in8
90 files changed, 1297 insertions, 749 deletions
diff --git a/src/bin/admin/tests/data/lease6_dump_test.reference.csv b/src/bin/admin/tests/data/lease6_dump_test.reference.csv
index 1e85864d29..39c443bdb1 100644
--- a/src/bin/admin/tests/data/lease6_dump_test.reference.csv
+++ b/src/bin/admin/tests/data/lease6_dump_test.reference.csv
@@ -1,4 +1,4 @@
address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,state,user_context,hwtype,hwaddr_source
-::10,32:30,30,1642000000,40,50,1,60,70,1,1,one.example.com,38:30,0,,90,16
-::11,32:31,30,1643210000,40,50,1,60,70,1,1,,38:30,1,{ },90,1
-::12,32:32,30,1643212345,40,50,1,60,70,1,1,three&#x2cexample&#x2ccom,38:30,2,{ "a": 1&#x2c "b": "c" },90,4
+::10,32:30:33,30,1642000000,40,50,1,60,70,1,1,one.example.com,38:30,0,,90,16
+::11,32:31:33,30,1643210000,40,50,1,60,70,1,1,,38:30,1,{ },90,1
+::12,32:32:33,30,1643212345,40,50,1,60,70,1,1,three&#x2cexample&#x2ccom,38:30,2,{ "a": 1&#x2c "b": "c" },90,4
diff --git a/src/bin/admin/tests/memfile_tests.sh.in b/src/bin/admin/tests/memfile_tests.sh.in
index f5b06c7510..24483bf9e9 100644
--- a/src/bin/admin/tests/memfile_tests.sh.in
+++ b/src/bin/admin/tests/memfile_tests.sh.in
@@ -71,7 +71,7 @@ memfile_data_v4() {
printf '0.0.0.10,32:30,33:30,40,1678900000,50,1,1,one&#x2cexample&#x2ccom,0,{"a":1&#x2c"b":2}'
}
memfile_data_v6() {
- printf '::10,32:30,30,1678900000,40,50,1,60,70,1,1,one&#x2cexample&#x2ccom,38:30,0,{"a":1&#x2c"b":2},90,16'
+ printf '::10,32:30:33,30,1678900000,40,50,1,60,70,1,1,one&#x2cexample&#x2ccom,38:30,0,{"a":1&#x2c"b":2},90,16'
}
# @}
diff --git a/src/bin/admin/tests/mysql_tests.sh.in b/src/bin/admin/tests/mysql_tests.sh.in
index b46a967722..6a74cab3ce 100644
--- a/src/bin/admin/tests/mysql_tests.sh.in
+++ b/src/bin/admin/tests/mysql_tests.sh.in
@@ -390,7 +390,7 @@ mysql_upgrade_12_to_13_test() {
}
mysql_upgrade_13_to_14_test() {
- # Check function source code
+ # Check function source code
run_command \
mysql_execute "select action_statement from information_schema.TRIGGERS where trigger_schema = '${db_name}' and trigger_name = 'dhcp4_shared_network_BDEL'";
@@ -399,7 +399,7 @@ mysql_upgrade_13_to_14_test() {
count=$(echo "${OUTPUT}" | grep -Eci 'UPDATE dhcp4_subnet SET shared_network_name = NULL') || true
assert_eq 1 "${count}" "function func_dhcp4_shared_network_BDEL() is missing changed line. (expected count %d, returned %d)"
- # Check function source code
+ # Check function source code
run_command \
mysql_execute "select action_statement from information_schema.TRIGGERS where trigger_schema = '${db_name}' and trigger_name = 'dhcp6_shared_network_BDEL'";
@@ -1431,6 +1431,26 @@ SET @disable_audit = 0;"
# Check upgrade from 16.0 to 17.0.
mysql_upgrade_16_to_17_test
+ # lease4 client_id should support 255 long strings.
+ qry="insert into lease4 (address, client_id, subnet_id) values (1, '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345', 1);"
+ run_statement "lease4_255_long_client_id" "$qry"
+
+ # lease4 relay_id should support 255 long strings.
+ qry="insert into lease4 (address, remote_id, subnet_id) values (2, '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345', 1);"
+ run_statement "lease4_255_long_relay_id" "$qry"
+
+ # lease4 remote_id should support 255 long strings.
+ qry="insert into lease4 (address, remote_id, subnet_id) values (3, '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345', 1);"
+ run_statement "lease4_255_long_remote_id" "$qry"
+
+ # hosts dhcp_identifier should support 255 long strings.
+ qry="insert into hosts (dhcp_identifier, dhcp_identifier_type) values ('123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345', 0);"
+ run_statement "hosts_255_long_dhcp_identifier" "$qry"
+
+ #lease6 duid should support 130 long strings.
+ qry="insert into lease6 values('::10',12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890,30,(SELECT FROM_UNIXTIME(1642000000)),40,50,1,60,70,1,1,'one.example.com',80,90,16,0,NULL);"
+ run_statement "lease6_130_long_duid" "$qry"
+
# Let's wipe the whole database
mysql_wipe
@@ -1535,9 +1555,9 @@ mysql_lease6_dump_test() {
# Insert the reference record
insert_sql="\
-insert into lease6 values('::10',20,30,(SELECT FROM_UNIXTIME(1642000000)),40,50,1,60,70,1,1,'one.example.com',80,90,16,0,NULL);\
-insert into lease6 values('::11',21,30,(SELECT FROM_UNIXTIME(1643210000)),40,50,1,60,70,1,1,'',80,90,1,1,'{ }');\
-insert into lease6 values('::12',22,30,(SELECT FROM_UNIXTIME(1643212345)),40,50,1,60,70,1,1,'three,example,com',80,90,4,2,'{ \"a\": 1, \"b\": \"c\" }');"
+insert into lease6 values('::10',203,30,(SELECT FROM_UNIXTIME(1642000000)),40,50,1,60,70,1,1,'one.example.com',80,90,16,0,NULL);\
+insert into lease6 values('::11',213,30,(SELECT FROM_UNIXTIME(1643210000)),40,50,1,60,70,1,1,'',80,90,1,1,'{ }');\
+insert into lease6 values('::12',223,30,(SELECT FROM_UNIXTIME(1643212345)),40,50,1,60,70,1,1,'three,example,com',80,90,4,2,'{ \"a\": 1, \"b\": \"c\" }');"
run_command \
mysql_execute "$insert_sql"
@@ -2161,13 +2181,13 @@ mysql_unused_subnet_id_test() {
# that reservation_mode values in subnet and shared network tables are
# converted to new reservations flags.
mysql_reservation_mode_upgrade_test() {
- test_start "mysql_reservation_mode_upgrade_test"
+ test_start "mysql.reservation_mode_upgrade_test"
# Let's wipe the whole database
mysql_wipe
# We need to create an older database with lease data so we can
- # verify the upgrade mechanisms which convert subnet id values
+ # verify the upgrade mechanisms which convert reservations values
#
# Initialize database to schema 1.0.
mysql -u"${db_user}" -p"${db_password}" "${db_name}" < "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
@@ -2317,13 +2337,14 @@ mysql_reservation_mode_upgrade_test() {
mysql_client_class_test() {
table_prefix="$1"
- test_start "mysql_client_classes_test.${table_prefix}"
+ test_start "mysql.client_classes_test.${table_prefix}"
# Let's wipe the whole database
mysql_wipe
# We need to create an older database with lease data so we can
- # verify the upgrade mechanisms which convert subnet id values
+ # verify the upgrade mechanisms which validates client classes and
+ # dependencies behave correctly
#
# Initialize database to schema 1.0.
mysql -u"${db_user}" -p"${db_password}" "${db_name}" < "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
@@ -2442,7 +2463,7 @@ mysql_client_class_test() {
# the tag column in the dhcp4_server and dhcp6_server tables.
mysql_shrink_server_tag_test() {
- test_start "mysql_shrink_server_tag_test"
+ test_start "mysql.shrink_server_tag_test"
mysql_wipe
@@ -2481,6 +2502,47 @@ mysql_shrink_server_tag_test() {
test_finish 0
}
+# Verifies that you can upgrade from earlier version and that initial EMPTY DUID
+# (0x00) value in lease6 table is updated to proper value (0x000000).
+mysql_update_empty_duid_test() {
+ test_start "mysql.update_empty_duid_test"
+
+ # Let's wipe the whole database
+ mysql_wipe
+
+ # We need to create an older database with lease data so we can
+ # verify the upgrade mechanisms which convert empty duid values
+ #
+ # Initialize database to schema 1.0.
+ mysql -u"${db_user}" -p"${db_password}" "${db_name}" < "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.mysql"
+
+ # Now upgrade to schema 16.0
+ mysql_upgrade_schema_to_version 16.0
+
+ sql=\
+"insert into lease6 values('::10',203,30,(SELECT FROM_UNIXTIME(1642000000)),40,50,1,60,70,1,1,'one.example.com',80,90,16,0,NULL);\
+ insert into lease6 values('::11',UNHEX('00'),30,(SELECT FROM_UNIXTIME(1643210000)),40,50,1,60,70,1,1,'',80,90,1,1,'{ }');"
+
+ run_statement "insert v6 leases" "$sql"
+
+ # Ok, we have a 14.0 database with leases. Let's upgrade it to latest version.
+ run_command \
+ "${kea_admin}" db-upgrade mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}"
+
+ # leases count for declined state should be 1 with DUID updated (0x000000)
+ qry="select count(*) from lease6 where address = '::11' and duid = 0x000000 and state = 1";
+ run_statement "#2" "$qry" 1
+
+ # leases count for non declined state should be 1 with DUID unchanged (0x323033)
+ qry="select count(*) from lease6 where address = '::10' and duid = 0x323033 and state = 0";
+ run_statement "#3" "$qry" 1
+
+ # Let's wipe the whole database
+ mysql_wipe
+
+ test_finish 0
+}
+
# Run tests.
mysql_db_init_test
mysql_host_reservation_init_test
@@ -2504,3 +2566,4 @@ mysql_reservation_mode_upgrade_test
mysql_client_class_test dhcp4
mysql_client_class_test dhcp6
mysql_shrink_server_tag_test
+mysql_update_empty_duid_test
diff --git a/src/bin/admin/tests/pgsql_tests.sh.in b/src/bin/admin/tests/pgsql_tests.sh.in
index 51af1343d9..d7c616bad7 100644
--- a/src/bin/admin/tests/pgsql_tests.sh.in
+++ b/src/bin/admin/tests/pgsql_tests.sh.in
@@ -151,7 +151,7 @@ pgsql_db_version_test() {
test_finish 0
}
-pgsql_upgrade_1_0_to_2_0() {
+pgsql_upgrade_1_0_to_2_0_test() {
# Added state column to lease4
run_command \
pgsql_execute "select state from lease4;"
@@ -180,7 +180,7 @@ pgsql_upgrade_1_0_to_2_0() {
assert_eq 0 "${EXIT_CODE}" "function lease6DumpData() broken or missing. (expected status code %d, returned %d)"
}
-pgsql_upgrade_2_0_to_3_0() {
+pgsql_upgrade_2_0_to_3_0_test() {
# Added hwaddr, hwtype, and hwaddr_source columns to lease6 table
run_command \
pgsql_execute "select hwaddr, hwtype, hwaddr_source from lease6;"
@@ -266,7 +266,7 @@ pgsql_upgrade_2_0_to_3_0() {
assert_eq 1 "${OUTPUT}" "lease_hwaddr_source does not contain entry for HWADDR_SOURCE_UNKNOWN. (record count %d, expected %d)"
}
-pgsql_upgrade_3_0_to_6_1() {
+pgsql_upgrade_3_0_to_6_1_test() {
# Added user_context to lease4
run_command \
pgsql_execute "select user_context from lease4;"
@@ -283,7 +283,7 @@ pgsql_upgrade_3_0_to_6_1() {
assert_eq 0 "${EXIT_CODE}" "logs table is missing or broken. (expected status code %d, returned %d)"
}
-pgsql_upgrade_6_1_to_6_2() {
+pgsql_upgrade_6_1_to_6_2_test() {
insert_sql="\
insert into hosts(dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, ipv4_address) values (decode('010101010101', 'hex'), 0, 1, x'FFAF0002'::int);\
insert into hosts(dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, ipv4_address) values (decode('010101010102', 'hex'), 0, 1, x'FFAF0002'::int);"
@@ -292,7 +292,7 @@ insert into hosts(dhcp_identifier, dhcp_identifier_type, dhcp4_subnet_id, ipv4_a
assert_eq 0 "${EXIT_CODE}" "insert into hosts failed, expected exit code %d, actual %d"
}
-pgsql_upgrade_6_2_to_7_0() {
+pgsql_upgrade_6_2_to_7_0_test() {
# dhcp4_server should have a single entry for 'all'
select_sql="SELECT id, tag, description, modification_ts from dhcp4_server where id = 1 and tag = 'all';"
run_command \
@@ -327,7 +327,7 @@ select get_session_big_int('kea.bigint'); \
assert_str_eq " booya f t 0 1984 " "${clean_out}" "session variable output incorrect"
}
-pgsql_upgrade_7_0_to_8_0() {
+pgsql_upgrade_7_0_to_8_0_test() {
run_command \
pgsql_execute "$session_sql"
@@ -417,7 +417,7 @@ pgsql_upgrade_7_0_to_8_0() {
assert_str_eq '' "${OUTPUT}"
}
-pgsql_upgrade_8_0_to_9_0() {
+pgsql_upgrade_8_0_to_9_0_test() {
run_command \
pgsql_execute "$session_sql"
@@ -427,10 +427,9 @@ pgsql_upgrade_8_0_to_9_0() {
pgsql_execute "select gmt_epoch(now());"
assert_eq 0 "${EXIT_CODE}" "function gmt_epoch() broken or missing. (expected status code %d, returned %d)"
-
}
-pgsql_upgrade_9_0_to_10_0() {
+pgsql_upgrade_9_0_to_10_test() {
run_command \
pgsql_execute "$session_sql"
@@ -445,7 +444,7 @@ pgsql_upgrade_9_0_to_10_0() {
assert_eq 1 "${count}" "func_dhcp6_client_class_check_dependency_BINS is missing RETURN NEW. (expected count %d, returned %d)"
}
-pgsql_upgrade_10_0_to_11_0() {
+pgsql_upgrade_10_to_11_test() {
run_command \
pgsql_execute "$session_sql"
@@ -460,7 +459,7 @@ pgsql_upgrade_10_0_to_11_0() {
assert_eq 1 "${count}" "function createOptionAuditDHCP6() is missing changed line. (expected count %d, returned %d)"
}
-pgsql_upgrade_11_0_to_12_0() {
+pgsql_upgrade_11_to_12_test() {
run_command \
pgsql_execute "$session_sql"
@@ -848,6 +847,7 @@ pgsql_upgrade_test() {
pgsql_execute_script "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.pgsql"
assert_eq 0 "${EXIT_CODE}" "cannot initialize the database, expected exit code: %d, actual: %d"
+ # Ok, we have a 1.0 database. Let's upgrade it to the latest version.
run_command \
"${kea_admin}" db-upgrade pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}"
assert_eq 0 "${EXIT_CODE}" "db-upgrade failed, expected exit code: %d, actual: %d"
@@ -857,42 +857,42 @@ pgsql_upgrade_test() {
assert_str_eq "16.0" "${version}" 'Expected kea-admin to return %s, returned value was %s'
# Check 1.0 to 2.0 upgrade
- pgsql_upgrade_1_0_to_2_0
+ pgsql_upgrade_1_0_to_2_0_test
# Check 2.0 to 3.0 upgrade
- pgsql_upgrade_2_0_to_3_0
+ pgsql_upgrade_2_0_to_3_0_test
# Check 3.0 to 6.1 upgrade
- pgsql_upgrade_3_0_to_6_1
+ pgsql_upgrade_3_0_to_6_1_test
# Check 6.1 to 6.2 upgrade
- pgsql_upgrade_6_1_to_6_2
+ pgsql_upgrade_6_1_to_6_2_test
# Check 6.2 to 7.0 upgrade
- pgsql_upgrade_6_2_to_7_0
+ pgsql_upgrade_6_2_to_7_0_test
# Check 7.0 to 8.0 upgrade
- pgsql_upgrade_7_0_to_8_0
+ pgsql_upgrade_7_0_to_8_0_test
# Check 8.0 to 9.0 upgrade
- pgsql_upgrade_8_0_to_9_0
+ pgsql_upgrade_8_0_to_9_0_test
- # Check 9.0 to 10.0 upgrade
- pgsql_upgrade_9_0_to_10_0
+ # Check 9.0 to 10 upgrade
+ pgsql_upgrade_9_0_to_10_test
# Check 10.0 to 11.0 upgrade
- pgsql_upgrade_10_0_to_11_0
+ pgsql_upgrade_10_to_11_test
# Check 11.0 to 12.0 upgrade
- pgsql_upgrade_11_0_to_12_0
+ pgsql_upgrade_11_to_12_test
- # Check 12 to 13 upgrade
+ # Check 12.0 to 13.0 upgrade
pgsql_upgrade_12_to_13_test
- # Check 13 to 14 upgrade
+ # Check 13.0 to 14.0 upgrade
pgsql_upgrade_13_to_14_test
- # Check 14 to 15 upgrade
+ # Check 14.0 to 15.0 upgrade
pgsql_upgrade_14_to_15_test
# Check 15 to 16 upgrade
@@ -1024,9 +1024,9 @@ pgsql_lease6_dump_test() {
# Because shell evaluates the double quoted string one more time, they need to be doubled.
# Otherwise, the value is interpreted as ASCII instead of raw bytes.
insert_sql="\
-insert into lease6 values('::10',E'\\\\x3230',30,TO_TIMESTAMP(1642000000),40,50,1,60,70,'t','t','one.example.com',0,decode(encode('80','hex'),'hex'),90,16,''); \
-insert into lease6 values('::11',E'\\\\x3231',30,TO_TIMESTAMP(1643210000),40,50,1,60,70,'t','t','',1,decode(encode('80','hex'),'hex'),90,1,'{ }'); \
-insert into lease6 values('::12',E'\\\\x3232',30,TO_TIMESTAMP(1643212345),40,50,1,60,70,'t','t','three,example,com',2,decode(encode('80','hex'),'hex'),90,4,'{ \"a\": 1, \"b\": \"c\" }');"
+insert into lease6 values('::10',E'\\\\x323033',30,TO_TIMESTAMP(1642000000),40,50,1,60,70,'t','t','one.example.com',0,decode(encode('80','hex'),'hex'),90,16,''); \
+insert into lease6 values('::11',E'\\\\x323133',30,TO_TIMESTAMP(1643210000),40,50,1,60,70,'t','t','',1,decode(encode('80','hex'),'hex'),90,1,'{ }'); \
+insert into lease6 values('::12',E'\\\\x323233',30,TO_TIMESTAMP(1643212345),40,50,1,60,70,'t','t','three,example,com',2,decode(encode('80','hex'),'hex'),90,4,'{ \"a\": 1, \"b\": \"c\" }');"
run_command \
pgsql_execute "$insert_sql"
@@ -1332,7 +1332,7 @@ pgsql_lease6_stat_per_type() {
# leases count for declined state should be 0
qry="select leases from lease6_stat where subnet_id = 1 and lease_type = $ltype and state = 0";
- run_statement "#6" "$qry" 0
+ run_statement "#8" "$qry" 0
}
# Verifies that lease6_stat triggers operation correctly
@@ -1403,7 +1403,7 @@ pgsql_lease_stat_upgrade_test() {
insert into lease6 (address, lease_type, subnet_id, state) values (666,1,40,2);"
run_statement "insert v6 leases" "$qry"
- # Ok, we have a 2.0 database with leases. Let's upgrade it to 4.0
+ # Ok, we have a 2.0 database with leases. Let's upgrade it to latest version.
run_command \
"${kea_admin}" db-upgrade pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}"
@@ -1512,7 +1512,7 @@ pgsql_lease_stat_upgrade_test() {
}
pgsql_lease_stat_recount_test() {
- test_start "pgsql_lease_stat_recount_test"
+ test_start "pgsql.lease_stat_recount_test"
# Let's wipe the whole database
pgsql_wipe
@@ -1648,7 +1648,7 @@ pgsql_unused_subnet_id_test() {
run_statement "insert options" "$qry"
- # Ok, we have a 4.0 database with hosts and options. Let's upgrade it to 5.0
+ # Ok, we have a 4.0 database with hosts and options. Let's upgrade it to latest version.
run_command \
"${kea_admin}" db-upgrade pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}"
@@ -1693,6 +1693,49 @@ pgsql_unused_subnet_id_test() {
test_finish 0
}
+# Verifies that you can upgrade from earlier version and that initial EMPTY DUID
+# (0x00) value in lease6 table is updated to proper value (0x000000).
+pgsql_update_empty_duid_test() {
+ test_start "pgsql.update_empty_duid_test"
+
+ # Let's wipe the whole database
+ pgsql_wipe
+
+ # We need to create an older database with lease data so we can
+ # verify the upgrade mechanisms which prepopulate the lease stat
+ # tables.
+ #
+ # Initialize database to schema 1.0.
+ pgsql_execute_script "@abs_top_srcdir@/src/bin/admin/tests/dhcpdb_create_1.0.pgsql"
+ assert_eq 0 "${EXIT_CODE}" "cannot initialize 1.0 database, expected exit code: %d, actual: %d"
+
+ # Now upgrade to schema 15.0
+ pgsql_upgrade_schema_to_version 15.0
+
+ qry=\
+"insert into lease6 values('::10',E'\\\\x323033',30,TO_TIMESTAMP(1642000000),40,50,1,60,70,'t','t','one.example.com',0,decode(encode('80','hex'),'hex'),90,16,''); \
+ insert into lease6 values('::11',E'\\\\x00',30,TO_TIMESTAMP(1643210000),40,50,1,60,70,'t','t','',1,decode(encode('80','hex'),'hex'),90,1,'{ }');"
+
+ run_statement "insert v6 leases" "$qry"
+
+ # Ok, we have a 14.0 database with leases. Let's upgrade it to latest version.
+ run_command \
+ "${kea_admin}" db-upgrade pgsql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}"
+
+ # leases count for declined state should be 1 with DUID updated (0x000000)
+ qry="select count(*) from lease6 where address = '::11' and duid = E'\\\\x000000' and state = 1";
+ run_statement "#2" "$qry" 1
+
+ # leases count for non declined state should be 1 with DUID unchanged (0x323033)
+ qry="select count(*) from lease6 where address = '::10' and duid = E'\\\\x323033' and state = 0";
+ run_statement "#3" "$qry" 1
+
+ # Let's wipe the whole database
+ pgsql_wipe
+
+ test_finish 0
+}
+
# Run tests.
pgsql_db_init_test
pgsql_db_version_test
@@ -1710,3 +1753,4 @@ pgsql_lease6_stat_test
pgsql_lease_stat_upgrade_test
pgsql_lease_stat_recount_test
pgsql_unused_subnet_id_test
+pgsql_update_empty_duid_test
diff --git a/src/bin/dhcp4/client_handler.cc b/src/bin/dhcp4/client_handler.cc
index 58c071d0a7..b45e9a8cc1 100644
--- a/src/bin/dhcp4/client_handler.cc
+++ b/src/bin/dhcp4/client_handler.cc
@@ -19,7 +19,7 @@ using namespace isc::log;
namespace isc {
namespace dhcp {
-ClientHandler::Client::Client(Pkt4Ptr query, DuidPtr client_id,
+ClientHandler::Client::Client(Pkt4Ptr query, ClientIdPtr client_id,
HWAddrPtr hwaddr)
: query_(query), htype_(HTYPE_ETHER), thread_(this_thread::get_id()) {
// Sanity checks.
@@ -32,7 +32,7 @@ ClientHandler::Client::Client(Pkt4Ptr query, DuidPtr client_id,
}
if (client_id) {
- duid_ = client_id->getDuid();
+ client_id_ = client_id->getClientId();
}
if (hwaddr && !hwaddr->hwaddr_.empty()) {
htype_ = hwaddr->htype_;
@@ -47,13 +47,13 @@ ClientHandler::ClientByIdContainer ClientHandler::clients_client_id_;
ClientHandler::ClientByHWAddrContainer ClientHandler::clients_hwaddr_;
ClientHandler::ClientPtr
-ClientHandler::lookup(const DuidPtr& duid) {
+ClientHandler::lookup(const ClientIdPtr& client_id) {
// Sanity check.
- if (!duid) {
+ if (!client_id) {
isc_throw(InvalidParameter, "null duid in ClientHandler::lookup");
}
- auto it = clients_client_id_.find(duid->getDuid());
+ auto it = clients_client_id_.find(client_id->getClientId());
if (it == clients_client_id_.end()) {
return (ClientPtr());
}
@@ -102,14 +102,14 @@ ClientHandler::addByHWAddr(const ClientPtr& client) {
}
void
-ClientHandler::del(const DuidPtr& duid) {
+ClientHandler::del(const ClientIdPtr& client_id) {
// Sanity check.
- if (!duid) {
+ if (!client_id) {
isc_throw(InvalidParameter, "null duid in ClientHandler::del");
}
// Assume erase will never fail so not checking its result.
- clients_client_id_.erase(duid->getDuid());
+ clients_client_id_.erase(client_id->getClientId());
}
void
@@ -177,15 +177,15 @@ ClientHandler::tryLock(Pkt4Ptr query, ContinuationPtr cont) {
// Get identifiers.
OptionPtr opt_client_id = query->getOption(DHO_DHCP_CLIENT_IDENTIFIER);
- DuidPtr duid;
+ ClientIdPtr client_id;
if (opt_client_id) {
- duid.reset(new ClientId(opt_client_id->getData()));
+ client_id.reset(new ClientId(opt_client_id->getData()));
}
HWAddrPtr hwaddr = query->getHWAddr();
if (hwaddr && hwaddr->hwaddr_.empty()) {
hwaddr.reset();
}
- if (!duid && !hwaddr) {
+ if (!client_id && !hwaddr) {
// Can't do something useful: cross fingers.
return (true);
}
@@ -194,17 +194,17 @@ ClientHandler::tryLock(Pkt4Ptr query, ContinuationPtr cont) {
ClientPtr holder_hw;
Pkt4Ptr next_query_id;
Pkt4Ptr next_query_hw;
- client_.reset(new Client(query, duid, hwaddr));
+ client_.reset(new Client(query, client_id, hwaddr));
{
lock_guard<mutex> lk(mutex_);
// Try first duid.
- if (duid) {
+ if (client_id) {
// Try to acquire the by-client-id lock and return the holder
// when it failed.
- holder_id = lookup(duid);
+ holder_id = lookup(client_id);
if (!holder_id) {
- locked_client_id_ = duid;
+ locked_client_id_ = client_id;
lockById();
} else if (cont) {
next_query_id = holder_id->next_query_;
diff --git a/src/bin/dhcp4/client_handler.h b/src/bin/dhcp4/client_handler.h
index 9b2b0c0e2d..9f1937eee6 100644
--- a/src/bin/dhcp4/client_handler.h
+++ b/src/bin/dhcp4/client_handler.h
@@ -49,13 +49,13 @@ private:
/// @param client_id The client ID.
/// @param hwaddr The hardware address.
/// @throw if the query is null or client_id and hwaddr are null.
- Client(Pkt4Ptr query, DuidPtr client_id, HWAddrPtr hwaddr);
+ Client(Pkt4Ptr query, ClientIdPtr client_id, HWAddrPtr hwaddr);
/// @brief The query being processed.
Pkt4Ptr query_;
/// @brief Cached binary client ID.
- std::vector<uint8_t> duid_;
+ std::vector<uint8_t> client_id_;
/// @brief Cached hardware type.
uint16_t htype_;
@@ -96,7 +96,7 @@ private:
// Client ID binary content as a member of the Client object.
boost::multi_index::member<
- Client, std::vector<uint8_t>, &Client::duid_
+ Client, std::vector<uint8_t>, &Client::client_id_
>
>
>
@@ -132,9 +132,9 @@ private:
///
/// The mutex must be held by the caller.
///
- /// @param duid The duid of the query from the client.
+ /// @param client_id The duid of the query from the client.
/// @return The client found in the by client id container or null.
- static ClientPtr lookup(const DuidPtr& duid);
+ static ClientPtr lookup(const ClientIdPtr& client_id);
/// @brief Lookup a client by hwaddr.
///
@@ -162,8 +162,8 @@ private:
///
/// The mutex must be held by the caller.
///
- /// @param duid The duid to delete from the by id client container.
- static void del(const DuidPtr& duid);
+ /// @param client_id The duid to delete from the by id client container.
+ static void del(const ClientIdPtr& client_id);
/// @brief Delete a client by hwaddr.
///
@@ -236,7 +236,7 @@ private:
ClientPtr client_;
/// @brief Client ID locked by this handler.
- DuidPtr locked_client_id_;
+ ClientIdPtr locked_client_id_;
/// @brief Hardware address locked by this handler.
HWAddrPtr locked_hwaddr_;
diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc
index 66659fa2c9..76259767f9 100644
--- a/src/bin/dhcp4/dhcp4_srv.cc
+++ b/src/bin/dhcp4/dhcp4_srv.cc
@@ -407,7 +407,7 @@ Dhcpv4Exchange::setHostIdentifiers(AllocEngine::ClientContext4Ptr context) {
case Host::IDENT_DUID:
if (context->clientid_) {
- const std::vector<uint8_t>& vec = context->clientid_->getDuid();
+ const std::vector<uint8_t>& vec = context->clientid_->getClientId();
if (!vec.empty()) {
// Client identifier type = DUID? Client identifier holding a DUID
// comprises Type (1 byte), IAID (4 bytes), followed by the actual
@@ -439,7 +439,7 @@ Dhcpv4Exchange::setHostIdentifiers(AllocEngine::ClientContext4Ptr context) {
case Host::IDENT_CLIENT_ID:
if (context->clientid_) {
- const std::vector<uint8_t>& vec = context->clientid_->getDuid();
+ const std::vector<uint8_t>& vec = context->clientid_->getClientId();
if (!vec.empty()) {
context->addHostIdentifier(id_type, vec);
}
diff --git a/src/bin/dhcp4/tests/config_parser_unittest.cc b/src/bin/dhcp4/tests/config_parser_unittest.cc
index 271185129a..e297063b3e 100644
--- a/src/bin/dhcp4/tests/config_parser_unittest.cc
+++ b/src/bin/dhcp4/tests/config_parser_unittest.cc
@@ -5229,14 +5229,14 @@ TEST_F(Dhcp4ParserTest, reservations) {
// Check that we can find reservation using client identifier.
ClientIdPtr client_id = ClientId::fromText("05:01:02:03:04:05:06");
- host = hosts_cfg->get4(542, Host::IDENT_CLIENT_ID, &client_id->getDuid()[0],
- client_id->getDuid().size());
+ host = hosts_cfg->get4(542, Host::IDENT_CLIENT_ID, &client_id->getClientId()[0],
+ client_id->getClientId().size());
ASSERT_TRUE(host);
EXPECT_EQ("192.0.4.103", host->getIPv4Reservation().toText());
// But this reservation should not be returned for other subnet.
- host = hosts_cfg->get4(234, Host::IDENT_CLIENT_ID, &client_id->getDuid()[0],
- client_id->getDuid().size());
+ host = hosts_cfg->get4(234, Host::IDENT_CLIENT_ID, &client_id->getClientId()[0],
+ client_id->getClientId().size());
EXPECT_FALSE(host);
}
diff --git a/src/bin/dhcp4/tests/decline_unittest.cc b/src/bin/dhcp4/tests/decline_unittest.cc
index b694bab394..b34d6e007b 100644
--- a/src/bin/dhcp4/tests/decline_unittest.cc
+++ b/src/bin/dhcp4/tests/decline_unittest.cc
@@ -48,10 +48,52 @@ const char* DECLINE_CONFIGS[] = {
" \"data\": \"10.0.0.200,10.0.0.201\""
" } ]"
" } ]"
- "}"
+ "}",
+// Configuration 1
+ "{ \"interfaces-config\": {"
+ " \"interfaces\": [ \"*\" ]"
+ "},"
+ "\"lease-database\": {"
+ "\"type\": \"mysql\","
+ "\"name\": \"keatest\","
+ "\"user\": \"keatest\","
+ "\"password\": \"keatest\""
+ "},"
+ "\"valid-lifetime\": 600,"
+ "\"subnet4\": [ { "
+ " \"subnet\": \"10.0.0.0/24\", "
+ " \"id\": 1,"
+ " \"pools\": [ { \"pool\": \"10.0.0.10-10.0.0.100\" } ],"
+ " \"option-data\": [ {"
+ " \"name\": \"routers\","
+ " \"data\": \"10.0.0.200,10.0.0.201\""
+ " } ]"
+ " } ]"
+ "}",
+// Configuration 2
+ "{ \"interfaces-config\": {"
+ " \"interfaces\": [ \"*\" ]"
+ "},"
+ "\"lease-database\": {"
+ "\"type\": \"postgresql\","
+ "\"name\": \"keatest\","
+ "\"user\": \"keatest\","
+ "\"password\": \"keatest\""
+ "},"
+ "\"valid-lifetime\": 600,"
+ "\"subnet4\": [ { "
+ " \"subnet\": \"10.0.0.0/24\", "
+ " \"id\": 1,"
+ " \"pools\": [ { \"pool\": \"10.0.0.10-10.0.0.100\" } ],"
+ " \"option-data\": [ {"
+ " \"name\": \"routers\","
+ " \"data\": \"10.0.0.200,10.0.0.201\""
+ " } ]"
+ " } ]"
+ "}",
};
-};
+}
namespace isc {
namespace dhcp {
@@ -83,7 +125,8 @@ Dhcpv4SrvTest::acquireAndDecline(Dhcp4Client& client,
const std::string& client_id_1,
const std::string& hw_address_2,
const std::string& client_id_2,
- ExpectedResult expected_result) {
+ ExpectedResult expected_result,
+ uint8_t config_index) {
// Set this global statistic explicitly to zero.
isc::stats::StatsMgr::instance().setValue("declined-addresses",
@@ -93,7 +136,7 @@ Dhcpv4SrvTest::acquireAndDecline(Dhcp4Client& client,
CfgMgr::instance().clear();
// Configure DHCP server.
- configure(DECLINE_CONFIGS[0], *client.getServer());
+ configure(DECLINE_CONFIGS[config_index], *client.getServer());
// Explicitly set the client id.
client.includeClientId(client_id_1);
// Explicitly set the HW address.
@@ -149,6 +192,13 @@ Dhcpv4SrvTest::acquireAndDecline(Dhcp4Client& client,
if (expected_result == SHOULD_PASS) {
EXPECT_EQ(Lease::STATE_DECLINED, lease->state_);
+ ASSERT_TRUE(lease->hwaddr_);
+ ASSERT_TRUE(lease->hwaddr_->hwaddr_.empty());
+ ASSERT_FALSE(lease->client_id_);
+ ASSERT_TRUE(lease->hostname_.empty());
+ ASSERT_FALSE(lease->fqdn_fwd_);
+ ASSERT_FALSE(lease->fqdn_rev_);
+
// The decline succeeded, so the declined-addresses statistic should
// be increased by one
EXPECT_EQ(after, before + 1);
@@ -158,6 +208,12 @@ Dhcpv4SrvTest::acquireAndDecline(Dhcp4Client& client,
// the decline was supposed, to be rejected.
EXPECT_EQ(Lease::STATE_DEFAULT, lease->state_);
+ ASSERT_TRUE(lease->hwaddr_);
+ ASSERT_FALSE(lease->hwaddr_->hwaddr_.empty());
+ ASSERT_TRUE(lease->client_id_);
+ ASSERT_FALSE(lease->fqdn_fwd_);
+ ASSERT_FALSE(lease->fqdn_rev_);
+
// The decline failed, so the declined-addresses should be the same
// as before
EXPECT_EQ(before, after);
@@ -165,9 +221,9 @@ Dhcpv4SrvTest::acquireAndDecline(Dhcp4Client& client,
}
}
-}; // end of isc::dhcp::test namespace
-}; // end of isc::dhcp namespace
-}; // end of isc namespace
+} // end of isc::dhcp::test namespace
+} // end of isc::dhcp namespace
+} // end of isc namespace
namespace {
@@ -192,13 +248,29 @@ public:
};
// This test checks that the client can acquire and decline the lease.
-TEST_F(DeclineTest, declineNoIdentifierChange) {
+TEST_F(DeclineTest, declineNoIdentifierChangeMemfile) {
Dhcp4Client client(Dhcp4Client::SELECTING);
acquireAndDecline(client, "01:02:03:04:05:06", "12:14",
"01:02:03:04:05:06", "12:14",
SHOULD_PASS);
}
+// This test checks that the client can acquire and decline the lease.
+TEST_F(DeclineTest, declineNoIdentifierChangeMySQL) {
+ Dhcp4Client client(Dhcp4Client::SELECTING);
+ acquireAndDecline(client, "01:02:03:04:05:06", "12:14",
+ "01:02:03:04:05:06", "12:14",
+ SHOULD_PASS, 1);
+}
+
+// This test checks that the client can acquire and decline the lease.
+TEST_F(DeclineTest, declineNoIdentifierChangePgSQL) {
+ Dhcp4Client client(Dhcp4Client::SELECTING);
+ acquireAndDecline(client, "01:02:03:04:05:06", "12:14",
+ "01:02:03:04:05:06", "12:14",
+ SHOULD_PASS, 2);
+}
+
// This test verifies the decline correctness in the following case:
// - Client acquires new lease using HW address only
// - Client sends the DHCPDECLINE with valid HW address and without
@@ -289,4 +361,4 @@ TEST_F(DeclineTest, declineNonMatchingIPAddress) {
EXPECT_EQ(Lease::STATE_DEFAULT, lease->state_);
}
-}; // end of anonymous namespace
+} // end of anonymous namespace
diff --git a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
index 56e4209b5b..3d327dbb2d 100644
--- a/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
+++ b/src/bin/dhcp4/tests/dhcp4_srv_unittest.cc
@@ -1806,7 +1806,7 @@ TEST_F(Dhcpv4SrvTest, DiscoverCache) {
uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER));
Lease4Ptr used(new Lease4(IOAddress("192.0.2.106"), hwaddr2,
- &client_id_->getDuid()[0], client_id_->getDuid().size(),
+ &client_id_->getClientId()[0], client_id_->getClientId().size(),
temp_valid, temp_timestamp, subnet_->getID()));
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(used));
@@ -1967,7 +1967,7 @@ TEST_F(Dhcpv4SrvTest, RenewBasic) {
uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER));
Lease4Ptr used(new Lease4(IOAddress("192.0.2.106"), hwaddr2,
- &client_id_->getDuid()[0], client_id_->getDuid().size(),
+ &client_id_->getClientId()[0], client_id_->getClientId().size(),
temp_valid, temp_timestamp, subnet_->getID()));
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(used));
@@ -2054,8 +2054,8 @@ void prepare(struct ctx& c) {
c.hwaddr.reset(new HWAddr(hwaddr_data, sizeof(hwaddr_data), HTYPE_ETHER));
c.used.reset(new Lease4(c.addr, c.hwaddr,
- &c.test->client_id_->getDuid()[0],
- c.test->client_id_->getDuid().size(),
+ &c.test->client_id_->getClientId()[0],
+ c.test->client_id_->getClientId().size(),
c.temp_valid, c.temp_timestamp,
c.test->subnet_->getID()));
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(c.used));
@@ -2312,7 +2312,7 @@ TEST_F(Dhcpv4SrvTest, RenewCache) {
uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER));
Lease4Ptr used(new Lease4(IOAddress("192.0.2.106"), hwaddr2,
- &client_id_->getDuid()[0], client_id_->getDuid().size(),
+ &client_id_->getClientId()[0], client_id_->getClientId().size(),
temp_valid, temp_timestamp, subnet_->getID()));
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(used));
diff --git a/src/bin/dhcp4/tests/dhcp4_test_utils.h b/src/bin/dhcp4/tests/dhcp4_test_utils.h
index 0de05c6f87..fa4cf7e0c7 100644
--- a/src/bin/dhcp4/tests/dhcp4_test_utils.h
+++ b/src/bin/dhcp4/tests/dhcp4_test_utils.h
@@ -639,12 +639,15 @@ public:
/// @param expected_result SHOULD_PASS if the lease is expected to
/// be successfully declined, or SHOULD_FAIL if the lease is expected
/// to not be declined.
+ /// @param config_index specifies which config index should be used:
+ /// 0 - memfile, 1 - mysql, 2 - pgsql
void acquireAndDecline(Dhcp4Client& client,
const std::string& hw_address_1,
const std::string& client_id_1,
const std::string& hw_address_2,
const std::string& client_id_2,
- ExpectedResult expected_result);
+ ExpectedResult expected_result,
+ uint8_t config_index = 0);
/// @brief Checks if received relay agent info option is echoed back to the
/// client.
diff --git a/src/bin/dhcp4/tests/hooks_unittest.cc b/src/bin/dhcp4/tests/hooks_unittest.cc
index af533abb76..6d5f8cb5cc 100644
--- a/src/bin/dhcp4/tests/hooks_unittest.cc
+++ b/src/bin/dhcp4/tests/hooks_unittest.cc
@@ -2303,7 +2303,7 @@ TEST_F(HooksDhcpv4SrvTest, lease4RenewSimple) {
uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe };
HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER));
Lease4Ptr used(new Lease4(IOAddress("192.0.2.106"), hwaddr2,
- &client_id_->getDuid()[0], client_id_->getDuid().size(),
+ &client_id_->getClientId()[0], client_id_->getClientId().size(),
temp_valid, temp_timestamp, subnet_->getID()));
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(used));
@@ -2401,7 +2401,7 @@ TEST_F(HooksDhcpv4SrvTest, lease4RenewSkip) {
uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe };
HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER));
Lease4Ptr used(new Lease4(IOAddress("192.0.2.106"), hwaddr2,
- &client_id_->getDuid()[0], client_id_->getDuid().size(),
+ &client_id_->getClientId()[0], client_id_->getClientId().size(),
temp_valid, temp_timestamp, subnet_->getID()));
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(used));
@@ -2469,8 +2469,8 @@ TEST_F(HooksDhcpv4SrvTest, lease4ReleaseSimple) {
// Let's create a lease and put it in the LeaseMgr
uint8_t mac_addr[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe };
HWAddrPtr hw(new HWAddr(mac_addr, sizeof(mac_addr), HTYPE_ETHER));
- Lease4Ptr used(new Lease4(addr, hw, &client_id_->getDuid()[0],
- client_id_->getDuid().size(), temp_valid,
+ Lease4Ptr used(new Lease4(addr, hw, &client_id_->getClientId()[0],
+ client_id_->getClientId().size(), temp_valid,
temp_timestamp, subnet_->getID()));
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(used));
@@ -2556,8 +2556,8 @@ TEST_F(HooksDhcpv4SrvTest, lease4ReleaseSimpleInfiniteLease) {
// Let's create a lease and put it in the LeaseMgr
uint8_t mac_addr[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe };
HWAddrPtr hw(new HWAddr(mac_addr, sizeof(mac_addr), HTYPE_ETHER));
- Lease4Ptr used(new Lease4(addr, hw, &client_id_->getDuid()[0],
- client_id_->getDuid().size(), temp_valid,
+ Lease4Ptr used(new Lease4(addr, hw, &client_id_->getClientId()[0],
+ client_id_->getClientId().size(), temp_valid,
temp_timestamp, subnet_->getID()));
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(used));
@@ -2642,8 +2642,8 @@ TEST_F(HooksDhcpv4SrvTest, lease4ReleaseSimpleNoDelete) {
// Let's create a lease and put it in the LeaseMgr
uint8_t mac_addr[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe };
HWAddrPtr hw(new HWAddr(mac_addr, sizeof(mac_addr), HTYPE_ETHER));
- Lease4Ptr used(new Lease4(addr, hw, &client_id_->getDuid()[0],
- client_id_->getDuid().size(), temp_valid,
+ Lease4Ptr used(new Lease4(addr, hw, &client_id_->getClientId()[0],
+ client_id_->getClientId().size(), temp_valid,
temp_timestamp, subnet_->getID()));
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(used));
@@ -2729,8 +2729,8 @@ TEST_F(HooksDhcpv4SrvTest, lease4ReleaseSkip) {
// Let's create a lease and put it in the LeaseMgr
uint8_t mac_addr[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe };
HWAddrPtr hw(new HWAddr(mac_addr, sizeof(mac_addr), HTYPE_ETHER));
- Lease4Ptr used(new Lease4(addr, hw, &client_id_->getDuid()[0],
- client_id_->getDuid().size(), temp_valid,
+ Lease4Ptr used(new Lease4(addr, hw, &client_id_->getClientId()[0],
+ client_id_->getClientId().size(), temp_valid,
temp_timestamp, subnet_->getID()));
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(used));
@@ -2793,8 +2793,8 @@ TEST_F(HooksDhcpv4SrvTest, lease4ReleaseDrop) {
// Let's create a lease and put it in the LeaseMgr
uint8_t mac_addr[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe };
HWAddrPtr hw(new HWAddr(mac_addr, sizeof(mac_addr), HTYPE_ETHER));
- Lease4Ptr used(new Lease4(addr, hw, &client_id_->getDuid()[0],
- client_id_->getDuid().size(), temp_valid,
+ Lease4Ptr used(new Lease4(addr, hw, &client_id_->getClientId()[0],
+ client_id_->getClientId().size(), temp_valid,
temp_timestamp, subnet_->getID()));
ASSERT_TRUE(LeaseMgrFactory::instance().addLease(used));
diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc
index 4675a0ba09..63efc5d866 100644
--- a/src/bin/dhcp6/dhcp6_srv.cc
+++ b/src/bin/dhcp6/dhcp6_srv.cc
@@ -1909,10 +1909,10 @@ void Dhcpv6Srv::sanityCheckDUID(const OptionPtr& opt, const std::string& opt_nam
// The client-id or server-id has to have at least 3 bytes of useful data:
// two for duid type and one more for actual duid value.
uint16_t len = opt->len() - opt->getHeaderLen();
- if (len < 3 || len > DUID::MAX_DUID_LEN || opt->getData().empty()) {
+ if (len < DUID::MIN_DUID_LEN || len > DUID::MAX_DUID_LEN) {
isc_throw(RFCViolation, "Received invalid DUID for " << opt_name << ", received "
- << len << " byte(s). It must be at least 3 and no more than "
- << DUID::MAX_DUID_LEN);
+ << len << " byte(s). It must be at least " << DUID::MIN_DUID_LEN
+ << " and no more than " << DUID::MAX_DUID_LEN);
}
}
diff --git a/src/bin/dhcp6/tests/decline_unittest.cc b/src/bin/dhcp6/tests/decline_unittest.cc
index dd7f584f08..375053eab8 100644
--- a/src/bin/dhcp6/tests/decline_unittest.cc
+++ b/src/bin/dhcp6/tests/decline_unittest.cc
@@ -41,6 +41,46 @@ const char* DECLINE_CONFIGS[] = {
" \"interface-id\": \"\","
" \"interface\": \"eth0\""
" } ],"
+ "\"valid-lifetime\": 4000 }",
+// Configuration 1
+ "{ \"interfaces-config\": {"
+ " \"interfaces\": [ \"*\" ]"
+ "},"
+ "\"lease-database\": {"
+ "\"type\": \"mysql\","
+ "\"name\": \"keatest\","
+ "\"user\": \"keatest\","
+ "\"password\": \"keatest\""
+ "},"
+ "\"preferred-lifetime\": 3000,"
+ "\"rebind-timer\": 2000, "
+ "\"renew-timer\": 1000, "
+ "\"subnet6\": [ { "
+ " \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ],"
+ " \"subnet\": \"2001:db8:1::/48\", "
+ " \"interface-id\": \"\","
+ " \"interface\": \"eth0\""
+ " } ],"
+ "\"valid-lifetime\": 4000 }",
+// Configuration 2
+ "{ \"interfaces-config\": {"
+ " \"interfaces\": [ \"*\" ]"
+ "},"
+ "\"lease-database\": {"
+ "\"type\": \"postgresql\","
+ "\"name\": \"keatest\","
+ "\"user\": \"keatest\","
+ "\"password\": \"keatest\""
+ "},"
+ "\"preferred-lifetime\": 3000,"
+ "\"rebind-timer\": 2000, "
+ "\"renew-timer\": 1000, "
+ "\"subnet6\": [ { "
+ " \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ],"
+ " \"subnet\": \"2001:db8:1::/48\", "
+ " \"interface-id\": \"\","
+ " \"interface\": \"eth0\""
+ " } ],"
"\"valid-lifetime\": 4000 }"
};
@@ -59,7 +99,7 @@ public:
uint32_t na_iaid_;
};
-};
+}
namespace isc {
namespace dhcp {
@@ -72,7 +112,8 @@ Dhcpv6SrvTest::acquireAndDecline(Dhcp6Client& client,
const std::string& duid2,
const uint32_t iaid2,
AddressInclusion addr_type,
- ExpectedResult expected_result) {
+ ExpectedResult expected_result,
+ uint8_t config_index) {
// Set this global statistic explicitly to zero.
StatsMgr::instance().setValue("declined-addresses", static_cast<int64_t>(0));
@@ -80,7 +121,7 @@ Dhcpv6SrvTest::acquireAndDecline(Dhcp6Client& client,
client.requestAddress(iaid1);
// Configure the server with a configuration.
- ASSERT_NO_THROW(configure(DECLINE_CONFIGS[0], *client.getServer()));
+ ASSERT_NO_THROW(configure(DECLINE_CONFIGS[config_index], *client.getServer()));
// Let's get the subnet-id and generate statistics name out of it.
const Subnet6Collection* subnets =
@@ -170,6 +211,14 @@ Dhcpv6SrvTest::acquireAndDecline(Dhcp6Client& client,
if (expected_result == SHOULD_PASS) {
EXPECT_EQ(Lease::STATE_DECLINED, lease->state_);
+ ASSERT_FALSE(lease->hwaddr_);
+ ASSERT_TRUE(lease->duid_);
+ ASSERT_EQ(*lease->duid_, DUID::EMPTY());
+ ASSERT_EQ(lease->preferred_lft_, 0);
+ ASSERT_TRUE(lease->hostname_.empty());
+ ASSERT_FALSE(lease->fqdn_fwd_);
+ ASSERT_FALSE(lease->fqdn_rev_);
+
// The decline succeeded, so the declined-addresses statistic should
// be increased by one
EXPECT_EQ(after, before + 1);
@@ -178,6 +227,13 @@ Dhcpv6SrvTest::acquireAndDecline(Dhcp6Client& client,
// the decline was supposed, to be rejected.
EXPECT_EQ(Lease::STATE_DEFAULT, lease->state_);
+ ASSERT_TRUE(lease->hwaddr_);
+ ASSERT_TRUE(lease->duid_);
+ ASSERT_NE(*lease->duid_, DUID::EMPTY());
+ ASSERT_NE(lease->preferred_lft_, 0);
+ ASSERT_FALSE(lease->fqdn_fwd_);
+ ASSERT_FALSE(lease->fqdn_rev_);
+
// The decline failed, so the declined-addresses should be the same
// as before
EXPECT_EQ(before, after);
@@ -186,15 +242,28 @@ Dhcpv6SrvTest::acquireAndDecline(Dhcp6Client& client,
}
// This test checks that the client can acquire and decline the lease.
-TEST_F(DeclineTest, basic) {
+TEST_F(DeclineTest, basicMemfile) {
Dhcp6Client client;
acquireAndDecline(client, "01:02:03:04:05:06", 1234, "01:02:03:04:05:06",
1234, VALID_ADDR, SHOULD_PASS);
}
-};
-};
-};
+// This test checks that the client can acquire and decline the lease.
+TEST_F(DeclineTest, basicMySQL) {
+ Dhcp6Client client;
+ acquireAndDecline(client, "01:02:03:04:05:06", 1234, "01:02:03:04:05:06",
+ 1234, VALID_ADDR, SHOULD_PASS, 1);
+}
+
+TEST_F(DeclineTest, basicPgSQL) {
+ Dhcp6Client client;
+ acquireAndDecline(client, "01:02:03:04:05:06", 1234, "01:02:03:04:05:06",
+ 1234, VALID_ADDR, SHOULD_PASS, 2);
+}
+
+}
+}
+}
namespace {
diff --git a/src/bin/dhcp6/tests/dhcp6_test_utils.h b/src/bin/dhcp6/tests/dhcp6_test_utils.h
index 161fb5ae6c..93aadb968d 100644
--- a/src/bin/dhcp6/tests/dhcp6_test_utils.h
+++ b/src/bin/dhcp6/tests/dhcp6_test_utils.h
@@ -777,13 +777,16 @@ public:
/// @param expected_result SHOULD_PASS if the lease is expected to
/// be successfully declined, or SHOULD_FAIL if the lease is expected
/// to not be declined.
+ /// @param config_index specifies which config index should be used:
+ /// 0 - memfile, 1 - mysql, 2 - pgsql
void acquireAndDecline(Dhcp6Client& client,
const std::string& duid1,
const uint32_t iaid1,
const std::string& duid2,
const uint32_t iaid2,
AddressInclusion addr_type,
- ExpectedResult expected_result);
+ ExpectedResult expected_result,
+ uint8_t config_index = 0);
/// @brief Performs basic (positive) RENEW test
///
diff --git a/src/hooks/dhcp/run_script/run_script.cc b/src/hooks/dhcp/run_script/run_script.cc
index ab710f18da..a6e070cf71 100644
--- a/src/hooks/dhcp/run_script/run_script.cc
+++ b/src/hooks/dhcp/run_script/run_script.cc
@@ -101,6 +101,19 @@ RunScriptImpl::extractHWAddr(ProcessEnvVars& vars,
}
void
+RunScriptImpl::extractClientId(ProcessEnvVars& vars,
+ const ClientIdPtr client_id,
+ const string& prefix,
+ const string& suffix) {
+ if (client_id) {
+ RunScriptImpl::extractString(vars, client_id->toText(),
+ prefix, suffix);
+ } else {
+ RunScriptImpl::extractString(vars, "", prefix, suffix);
+ }
+}
+
+void
RunScriptImpl::extractDUID(ProcessEnvVars& vars,
const DuidPtr duid,
const string& prefix,
@@ -228,8 +241,8 @@ RunScriptImpl::extractLease4(ProcessEnvVars& vars,
prefix + "_SUBNET_ID", suffix);
RunScriptImpl::extractInteger(vars, lease4->valid_lft_,
prefix + "_VALID_LIFETIME", suffix);
- RunScriptImpl::extractDUID(vars, lease4->client_id_,
- prefix + "_CLIENT_ID", suffix);
+ RunScriptImpl::extractClientId(vars, lease4->client_id_,
+ prefix + "_CLIENT_ID", suffix);
} else {
RunScriptImpl::extractString(vars, "", prefix + "_ADDRESS", suffix);
RunScriptImpl::extractString(vars, "", prefix + "_CLTT", suffix);
@@ -238,7 +251,7 @@ RunScriptImpl::extractLease4(ProcessEnvVars& vars,
RunScriptImpl::extractString(vars, "", prefix + "_STATE", suffix);
RunScriptImpl::extractString(vars, "", prefix + "_SUBNET_ID", suffix);
RunScriptImpl::extractString(vars, "", prefix + "_VALID_LIFETIME", suffix);
- RunScriptImpl::extractDUID(vars, DuidPtr(), prefix + "_CLIENT_ID", suffix);
+ RunScriptImpl::extractClientId(vars, ClientIdPtr(), prefix + "_CLIENT_ID", suffix);
}
}
diff --git a/src/hooks/dhcp/run_script/run_script.h b/src/hooks/dhcp/run_script/run_script.h
index c66c82e4b7..404796b91d 100644
--- a/src/hooks/dhcp/run_script/run_script.h
+++ b/src/hooks/dhcp/run_script/run_script.h
@@ -84,6 +84,16 @@ public:
const std::string& prefix = "",
const std::string& suffix = "");
+ /// @brief Extract ClientId data and append to environment.
+ ///
+ /// @param client_id The client id to be exported to target script environment.
+ /// @param prefix The prefix for the name of the environment variable.
+ /// @param suffix The suffix for the name of the environment variable.
+ static void extractClientId(isc::asiolink::ProcessEnvVars& vars,
+ const isc::dhcp::ClientIdPtr client_id,
+ const std::string& prefix = "",
+ const std::string& suffix = "");
+
/// @brief Extract DUID data and append to environment.
///
/// @param duid The duid to be exported to target script environment.
diff --git a/src/hooks/dhcp/run_script/run_script_callouts.cc b/src/hooks/dhcp/run_script/run_script_callouts.cc
index 3712000e2f..09717b5127 100644
--- a/src/hooks/dhcp/run_script/run_script_callouts.cc
+++ b/src/hooks/dhcp/run_script/run_script_callouts.cc
@@ -155,7 +155,7 @@ int lease4_renew(CalloutHandle& handle) {
RunScriptImpl::extractSubnet4(vars, subnet4, "SUBNET4");
ClientIdPtr clientid;
handle.getArgument("clientid", clientid);
- RunScriptImpl::extractDUID(vars, clientid, "PKT4_CLIENT_ID");
+ RunScriptImpl::extractClientId(vars, clientid, "PKT4_CLIENT_ID");
HWAddrPtr hwaddr;
handle.getArgument("hwaddr", hwaddr);
RunScriptImpl::extractHWAddr(vars, hwaddr, "PKT4_HWADDR");
diff --git a/src/hooks/dhcp/run_script/tests/run_script_unittests.cc b/src/hooks/dhcp/run_script/tests/run_script_unittests.cc
index cab5e0865b..09024197d3 100644
--- a/src/hooks/dhcp/run_script/tests/run_script_unittests.cc
+++ b/src/hooks/dhcp/run_script/tests/run_script_unittests.cc
@@ -81,12 +81,20 @@ generateHWAddr() {
return (HWAddrPtr(new HWAddr({0, 1, 2 ,3}, HTYPE_ETHER)));
}
+/// @brief Generate a valid ClientId.
+///
+/// @return The generated ClientId.
+ClientIdPtr
+generateClientId() {
+ return (ClientIdPtr(new ClientId({0, 1, 2, 3, 4, 5, 6})));
+}
+
/// @brief Generate a valid DUID.
///
/// @return The generated DUID.
-ClientIdPtr
+DuidPtr
generateDUID() {
- return (ClientIdPtr(new ClientId({0, 1, 2, 3, 4, 5, 6})));
+ return (DuidPtr(new DUID({0, 1, 2, 3, 4, 5, 6})));
}
/// @brief Generate a valid Option.
@@ -151,7 +159,7 @@ generateSubnet6() {
Lease4Ptr
generateLease4() {
HWAddrPtr hwaddr = generateHWAddr();
- ClientIdPtr clientid = generateDUID();
+ ClientIdPtr clientid = generateClientId();
Lease4Ptr lease4(new Lease4(IOAddress("192.168.0.1"), hwaddr, clientid,
2, 3, 4, false, false, "test.hostname"));
@@ -182,8 +190,8 @@ generateLease6() {
Pkt4Ptr
generatePkt4() {
// A dummy MAC address, padded with 0s
- const uint8_t dummyChaddr[16] = {0, 1, 2, 3, 4, 5, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0 };
+ const uint8_t dummyChaddr[16] = { 0, 1, 2, 3, 4, 5, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0 };
// Let's use some creative test content here (128 chars + \0)
const uint8_t dummyFile[] = "Lorem ipsum dolor sit amet, consectetur "
@@ -836,7 +844,7 @@ TEST_F(RunScriptTest, lease4Renew) {
handle.setArgument("query4", pkt4);
Subnet4Ptr subnet4 = generateSubnet4();
handle.setArgument("subnet4", subnet4);
- ClientIdPtr clientid = generateDUID();
+ ClientIdPtr clientid = generateClientId();
handle.setArgument("clientid", clientid);
HWAddrPtr hwaddr = generateHWAddr();
handle.setArgument("hwaddr", hwaddr);
diff --git a/src/lib/dhcp/duid.cc b/src/lib/dhcp/duid.cc
index 011325785d..06850dd6c7 100644
--- a/src/lib/dhcp/duid.cc
+++ b/src/lib/dhcp/duid.cc
@@ -9,7 +9,6 @@
#include <dhcp/duid.h>
#include <exceptions/exceptions.h>
#include <util/io_utilities.h>
-#include <util/strutil.h>
#include <iomanip>
#include <cctype>
#include <sstream>
@@ -20,37 +19,24 @@
namespace isc {
namespace dhcp {
-DUID::DUID(const std::vector<uint8_t>& duid) {
- if (duid.size() > MAX_DUID_LEN) {
- isc_throw(isc::BadValue, "DUID size is " << duid.size()
- << " bytes, exceeds maximum of " << MAX_DUID_LEN);
- }
- if (duid.empty()) {
- isc_throw(isc::BadValue, "Empty DUIDs are not allowed");
- }
- duid_ = duid;
+IdentifierBaseType::~IdentifierBaseType() {
}
-DUID::DUID(const uint8_t* data, size_t len) {
- if (len > MAX_DUID_LEN) {
- isc_throw(isc::BadValue, "DUID size is " << len
- << " bytes, exceeds maximum of " << MAX_DUID_LEN);
- }
- if (len == 0) {
- isc_throw(isc::BadValue, "Empty DUIDs/Client-ids not allowed");
- }
+DUID::DUID(const std::vector<uint8_t>& data) : IdentifierType<3, 130>(data) {
+}
- duid_ = std::vector<uint8_t>(data, data + len);
+DUID::DUID(const uint8_t* data, size_t len) : IdentifierType<3, 130>(data, len) {
}
const std::vector<uint8_t>& DUID::getDuid() const {
- return (duid_);
+ return (data_);
}
+
DUID::DUIDType DUID::getType() const {
- if (duid_.size() < 2) {
+ if (data_.size() < 2) {
return (DUID_UNKNOWN);
}
- uint16_t type = (duid_[0] << 8) + duid_[1];
+ uint16_t type = (data_[0] << 8) + data_[1];
if (type < DUID_MAX) {
return (static_cast<DUID::DUIDType>(type));
} else {
@@ -60,90 +46,28 @@ DUID::DUIDType DUID::getType() const {
DUID
DUID::fromText(const std::string& text) {
- std::vector<uint8_t> binary;
- util::str::decodeFormattedHexString(text, binary);
- return (DUID(binary));
+ return (DUID(IdentifierType::fromText(text)));
}
const DUID&
DUID::EMPTY() {
- static std::vector<uint8_t> empty_duid(1,0);
- static DUID empty(empty_duid);
- return (empty);
-}
-
-std::string DUID::toText() const {
- std::stringstream tmp;
- tmp << std::hex;
- bool delim = false;
- for (std::vector<uint8_t>::const_iterator it = duid_.begin();
- it != duid_.end(); ++it) {
- if (delim) {
- tmp << ":";
- }
- tmp << std::setw(2) << std::setfill('0') << static_cast<unsigned int>(*it);
- delim = true;
- }
- return (tmp.str());
-}
-
-bool DUID::operator==(const DUID& other) const {
- return (this->duid_ == other.duid_);
+ static DUID empty({0, 0, 0});
+ return (empty);
}
-bool DUID::operator!=(const DUID& other) const {
- return (this->duid_ != other.duid_);
+ClientId::ClientId(const std::vector<uint8_t>& data) : IdentifierType<2, 255>(data) {
}
-// Constructor based on vector<uint8_t>
-ClientId::ClientId(const std::vector<uint8_t>& clientid)
- : DUID(clientid) {
- if (clientid.size() < MIN_CLIENT_ID_LEN) {
- isc_throw(isc::BadValue, "client-id is too short (" << clientid.size()
- << "), at least 2 is required");
- }
-}
-
-// Constructor based on C-style data
-ClientId::ClientId(const uint8_t *clientid, size_t len)
- : DUID(clientid, len) {
- if (len < MIN_CLIENT_ID_LEN) {
- isc_throw(isc::BadValue, "client-id is too short (" << len
- << "), at least 2 is required");
- }
+ClientId::ClientId(const uint8_t *data, size_t len) : IdentifierType<2, 255>(data, len) {
}
-// Returns a copy of client-id data
const std::vector<uint8_t>& ClientId::getClientId() const {
- return (duid_);
-}
-
-// Returns the Client ID in text form
-std::string ClientId::toText() const {
-
- // As DUID is a private base class of ClientId, we can't access
- // its public toText() method through inheritance: instead we
- // need the interface of a ClientId::toText() that calls the
- // equivalent method in the base class.
- return (DUID::toText());
-}
-
-ClientIdPtr
-ClientId::fromText(const std::string& text) {
- std::vector<uint8_t> binary;
- util::str::decodeFormattedHexString(text, binary);
- return (ClientIdPtr(new ClientId(binary)));
-}
-
-// Compares two client-ids
-bool ClientId::operator==(const ClientId& other) const {
- return (this->duid_ == other.duid_);
+ return (data_);
}
-// Compares two client-ids
-bool ClientId::operator!=(const ClientId& other) const {
- return (this->duid_ != other.duid_);
+ClientIdPtr ClientId::fromText(const std::string& text) {
+ return (ClientIdPtr(new ClientId(IdentifierType::fromText(text))));
}
-}; // end of isc::dhcp namespace
-}; // end of isc namespace
+} // namespace dhcp
+} // namespace isc
diff --git a/src/lib/dhcp/duid.h b/src/lib/dhcp/duid.h
index 5ce8b2b0a9..b61b22aae1 100644
--- a/src/lib/dhcp/duid.h
+++ b/src/lib/dhcp/duid.h
@@ -8,6 +8,7 @@
#define DUID_H
#include <asiolink/io_address.h>
+#include <util/strutil.h>
#include <boost/shared_ptr.hpp>
#include <vector>
#include <stdint.h>
@@ -16,6 +17,116 @@
namespace isc {
namespace dhcp {
+/// @brief Base type used to define a common smart pointer for all derived types.
+class IdentifierBaseType {
+protected:
+ /// @brief Pure virtual destructor.
+ ///
+ /// This class can not be instantiated.
+ virtual ~IdentifierBaseType() = 0;
+};
+
+/// @brief Shared pointer to a IdentifierType
+typedef boost::shared_ptr<IdentifierBaseType> IdentifierBaseTypePtr;
+
+template<size_t min_size, size_t max_size>
+class IdentifierType : public IdentifierBaseType {
+public:
+
+ /// @brief Constructor from vector
+ ///
+ /// @param data The data used to create the IdentifierType
+ IdentifierType(const std::vector<uint8_t>& data) {
+ if (data.size() < min_size) {
+ isc_throw(isc::BadValue, "identifier is too short (" << data.size()
+ << "), at least "<< min_size << " is required");
+ }
+ if (data.size() > max_size) {
+ isc_throw(isc::BadValue, "identifier is too large (" << data.size()
+ << "), at most " << max_size << " is required");
+ }
+ data_ = data;
+ }
+
+ /// @brief Constructor from array and array size
+ ///
+ /// @param data The data used to create the Identifier
+ /// @param len The data len used to create the Identifier
+ IdentifierType(const uint8_t* data, size_t len) {
+ if (len < min_size) {
+ isc_throw(isc::BadValue, "identifier is too short (" << len
+ << "), at least "<< min_size << " is required");
+ }
+ if (len > max_size) {
+ isc_throw(isc::BadValue, "identifier is too large (" << len
+ << "), at most " << max_size << " is required");
+ }
+ data_ = std::vector<uint8_t>(data, data + len);
+ }
+
+ /// @brief Return the minimum size of the acceptable data.
+ ///
+ /// @return the minimum size of the acceptable data.
+ static constexpr size_t getMinSize() {
+ return (min_size);
+ }
+
+ /// @brief Return the maximum size of the acceptable data.
+ ///
+ /// @return the maximum size of the acceptable data.
+ static constexpr size_t getMaxSize() {
+ return (max_size);
+ }
+
+ /// @brief Returns textual representation of the identifier (e.g. 00:01:02:03:ff)
+ ///
+ /// @return textual representation of the identifier (e.g. 00:01:02:03:ff)
+ std::string toText() const {
+ std::stringstream tmp;
+ tmp << std::hex;
+ bool delim = false;
+ for (auto const data : data_) {
+ if (delim) {
+ tmp << ":";
+ }
+ tmp << std::setw(2) << std::setfill('0') << static_cast<unsigned int>(data);
+ delim = true;
+ }
+ return (tmp.str());
+ }
+
+ /// @brief This static function parses an Identifier specified in the
+ /// textual format.
+ ///
+ /// @param text Identifier in the hexadecimal format with digits
+ /// representing individual bytes separated by colons.
+ /// @return The data resulted from parsing the textual format.
+ static std::vector<uint8_t> fromText(const std::string& text) {
+ std::vector<uint8_t> binary;
+ util::str::decodeFormattedHexString(text, binary);
+ return (binary);
+ }
+
+ /// @brief Compares two identifiers for equality
+ ///
+ /// @return True if the two identifiers are equal, false otherwise.
+ bool operator==(const IdentifierType& other) const {
+ return (data_ == other.data_);
+ }
+
+ /// @brief Compares two identifiers for inequality
+ ///
+ /// @return True if the two identifiers are different, false otherwise.
+ bool operator!=(const IdentifierType& other) const {
+ return (data_ != other.data_);
+ }
+
+protected:
+
+ /// @brief The actual content of the Identifier
+ std::vector<uint8_t> data_;
+};
+
/// @brief Shared pointer to a DUID
class DUID;
typedef boost::shared_ptr<DUID> DuidPtr;
@@ -24,15 +135,16 @@ typedef boost::shared_ptr<DUID> DuidPtr;
///
/// This class holds DUID, that is used in client-id, server-id and
/// several other options. It is used to identify DHCPv6 entity.
-class DUID {
- public:
- /// @brief maximum duid size
- /// As defined in RFC 8415, section 11.1
- static const size_t MAX_DUID_LEN = 128;
+class DUID : public IdentifierType<3, 130> {
+public:
/// @brief minimum duid size
/// The minimal DUID size specified in RFC 8415 is 1.
- static const size_t MIN_DUID_LEN = 1;
+ static constexpr size_t MIN_DUID_LEN = IdentifierType::getMinSize();
+
+ /// @brief maximum duid size
+ /// As defined in RFC 8415, section 11.1
+ static constexpr size_t MAX_DUID_LEN = IdentifierType::getMaxSize();
/// @brief specifies DUID type
typedef enum {
@@ -45,10 +157,15 @@ class DUID {
} DUIDType;
/// @brief Constructor from vector
- DUID(const std::vector<uint8_t>& duid);
+ ///
+ /// @param data The data used to create the DUID
+ DUID(const std::vector<uint8_t>& data);
/// @brief Constructor from array and array size
- DUID(const uint8_t* duid, size_t len);
+ ///
+ /// @param data The data used to create the DUID
+ /// @param len The data len used to create the DUID
+ DUID(const uint8_t* data, size_t len);
/// @brief Returns a const reference to the actual DUID value
///
@@ -83,20 +200,6 @@ class DUID {
///
/// @throw isc::BadValue if parsing the DUID failed.
static DUID fromText(const std::string& text);
-
- /// @brief Returns textual representation of a DUID (e.g. 00:01:02:03:ff)
- std::string toText() const;
-
- /// @brief Compares two DUIDs for equality
- bool operator==(const DUID& other) const;
-
- /// @brief Compares two DUIDs for inequality
- bool operator!=(const DUID& other) const;
-
- protected:
-
- /// The actual content of the DUID
- std::vector<uint8_t> duid_;
};
/// @brief Forward declaration to the @c ClientId class.
@@ -108,30 +211,31 @@ typedef boost::shared_ptr<ClientId> ClientIdPtr;
///
/// This class is intended to be a generic IPv4 client identifier. It can hold
/// a client-id
-class ClientId : public DUID {
+class ClientId : public IdentifierType<2, 255> {
public:
/// @brief Minimum size of a client ID
///
/// Excerpt from RFC2132, section 9.14.
/// The code for this option is 61, and its minimum length is 2.
- static const size_t MIN_CLIENT_ID_LEN = 2;
+ static constexpr size_t MIN_CLIENT_ID_LEN = IdentifierType::getMinSize();
/// @brief Maximum size of a client ID
///
- /// This is the same as the maximum size of the underlying DUID.
- ///
- /// @note RFC 2131 does not specify an upper length of a client ID, the
- /// value chosen here just being that of the underlying DUID. For
- /// some backend database, there may be a possible (minor)
- /// performance enhancement if this were smaller.
- static const size_t MAX_CLIENT_ID_LEN = DUID::MAX_DUID_LEN;
+ /// @note RFC 2131 does not specify an upper length of a client ID, but the
+ /// byte used to specify the option size byte can only go up to 255.
+ static constexpr size_t MAX_CLIENT_ID_LEN = IdentifierType::getMaxSize();
/// @brief Constructor based on vector<uint8_t>
- ClientId(const std::vector<uint8_t>& clientid);
+ ///
+ /// @param data The data used to create the ClientId
+ ClientId(const std::vector<uint8_t>& data);
/// @brief Constructor based on array and array size
- ClientId(const uint8_t* clientid, size_t len);
+ ///
+ /// @param data The data used to create the ClientId
+ /// @param len The data len used to create the ClientId
+ ClientId(const uint8_t* data, size_t len);
/// @brief Returns reference to the client-id data.
///
@@ -143,14 +247,10 @@ public:
/// @return A reference to a vector holding a client identifier.
const std::vector<uint8_t>& getClientId() const;
- /// @brief Returns textual representation of a DUID (e.g. 00:01:02:03:ff)
- std::string toText() const;
-
/// @brief Create client identifier from the textual format.
///
/// This static function creates the instance of the @c ClientId from the
- /// textual format. Internally it calls @c DUID::fromText. The format of
- /// the input must match the format of the DUID in @c DUID::fromText.
+ /// textual format.
///
/// @param text Client identifier in the textual format.
///
@@ -158,15 +258,9 @@ public:
/// @throw isc::BadValue if parsing the client identifier failed.
/// @throw isc::OutOfRange if the client identifier is truncated.
static ClientIdPtr fromText(const std::string& text);
-
- /// @brief Compares two client-ids for equality
- bool operator==(const ClientId& other) const;
-
- /// @brief Compares two client-ids for inequality
- bool operator!=(const ClientId& other) const;
};
-}; // end of isc::dhcp namespace
-}; // end of isc namespace
+} // namespace dhcp
+} // namespace isc
#endif /* DUID_H */
diff --git a/src/lib/dhcp/duid_factory.cc b/src/lib/dhcp/duid_factory.cc
index c9d8b6e231..bd2e236765 100644
--- a/src/lib/dhcp/duid_factory.cc
+++ b/src/lib/dhcp/duid_factory.cc
@@ -151,7 +151,7 @@ DUIDFactory::createEN(const uint32_t enterprise_id,
// Render DUID.
std::vector<uint8_t> duid_out(DUID_TYPE_LEN + ENTERPRISE_ID_LEN);
- writeUint16(DUID::DUID_EN, &duid_out[0], 2);
+ writeUint16(DUID::DUID_EN, &duid_out[0], DUID_TYPE_LEN);
writeUint32(enterprise_id_out, &duid_out[2], ENTERPRISE_ID_LEN);
// If no identifier specified, we'll have to use the one from the
@@ -379,7 +379,7 @@ DUIDFactory::readFromFile() {
duid_.reset();
std::ostringstream duid_str;
- if (isStored()) {
+ if (isStored()) {
std::ifstream ifs;
ifs.open(storage_location_.c_str(), std::ifstream::in);
if (ifs.good()) {
@@ -405,6 +405,5 @@ DUIDFactory::readFromFile() {
}
}
-
-}; // end of isc::dhcp namespace
-}; // end of isc namespace
+} // end of isc::dhcp namespace
+} // end of isc namespace
diff --git a/src/lib/dhcp/tests/duid_unittest.cc b/src/lib/dhcp/tests/duid_unittest.cc
index afbfee1415..d7fbb05ca7 100644
--- a/src/lib/dhcp/tests/duid_unittest.cc
+++ b/src/lib/dhcp/tests/duid_unittest.cc
@@ -23,20 +23,9 @@ using namespace isc;
using namespace isc::dhcp;
using namespace isc::asiolink;
-// don't import the entire boost namespace. It will unexpectedly hide uint8_t
-// for some systems.
-using boost::scoped_ptr;
-
namespace {
-// This is a workaround for strange linking problems with gtest:
-// libdhcp___unittests-duid_unittest.o: In function `Compare<long unsigned int, long unsigned int>':
-// ~/gtest-1.6.0/include/gtest/gtest.h:1353: undefined reference to `isc::dhcp::ClientId::MAX_CLIENT_ID_LEN'
-// collect2: ld returned 1 exit status
-
-const size_t MAX_DUID_LEN = DUID::MAX_DUID_LEN;
-const size_t MAX_CLIENT_ID_LEN = DUID::MAX_DUID_LEN;
-
+using namespace isc::dhcp;
// This test verifies if the constructors are working as expected
// and process passed parameters.
@@ -46,8 +35,8 @@ TEST(DuidTest, constructor) {
vector<uint8_t> data2(data1, data1 + sizeof(data1));
- scoped_ptr<DUID> duid1(new DUID(data1, sizeof(data1)));
- scoped_ptr<DUID> duid2(new DUID(data2));
+ boost::scoped_ptr<DUID> duid1(new DUID(data1, sizeof(data1)));
+ boost::scoped_ptr<DUID> duid2(new DUID(data2));
vector<uint8_t> vecdata = duid1->getDuid();
EXPECT_TRUE(data2 == vecdata);
@@ -64,39 +53,40 @@ TEST(DuidTest, constructor) {
TEST(DuidTest, size) {
// Ensure that our size constant is RFC-compliant.
- ASSERT_EQ(128, MAX_DUID_LEN);
+ ASSERT_EQ(130, DUID::MAX_DUID_LEN);
- uint8_t data[MAX_DUID_LEN + 1];
+ uint8_t data[DUID::MAX_DUID_LEN + 1];
vector<uint8_t> data2;
- for (uint8_t i = 0; i < MAX_DUID_LEN + 1; ++i) {
+ for (uint8_t i = 0; i < DUID::MAX_DUID_LEN + 1; ++i) {
data[i] = i;
- if (i < MAX_DUID_LEN)
+ if (i < DUID::MAX_DUID_LEN) {
data2.push_back(i);
+ }
}
- ASSERT_EQ(data2.size(), MAX_DUID_LEN);
+ ASSERT_EQ(data2.size(), DUID::MAX_DUID_LEN);
- scoped_ptr<DUID> duidmaxsize1(new DUID(data, MAX_DUID_LEN));
- scoped_ptr<DUID> duidmaxsize2(new DUID(data2));
+ boost::scoped_ptr<DUID> duidmaxsize1(new DUID(data, DUID::MAX_DUID_LEN));
+ boost::scoped_ptr<DUID> duidmaxsize2(new DUID(data2));
EXPECT_THROW(
- scoped_ptr<DUID> toolarge1(new DUID(data, MAX_DUID_LEN + 1)),
+ boost::scoped_ptr<DUID> toolarge1(new DUID(data, DUID::MAX_DUID_LEN + 1)),
BadValue);
// that's one too much
data2.push_back(128);
EXPECT_THROW(
- scoped_ptr<DUID> toolarge2(new DUID(data2)),
+ boost::scoped_ptr<DUID> toolarge2(new DUID(data2)),
BadValue);
// empty duids are not allowed
vector<uint8_t> empty;
EXPECT_THROW(
- scoped_ptr<DUID> emptyDuid(new DUID(empty)),
+ boost::scoped_ptr<DUID> emptyDuid(new DUID(empty)),
BadValue);
EXPECT_THROW(
- scoped_ptr<DUID> emptyDuid2(new DUID(data, 0)),
+ boost::scoped_ptr<DUID> emptyDuid2(new DUID(data, 0)),
BadValue);
}
@@ -109,11 +99,11 @@ TEST(DuidTest, getType) {
uint8_t uuid[] = {0, 4, 2, 3, 4, 5, 6};
uint8_t invalid[] = {0,55, 2, 3, 4, 5, 6};
- scoped_ptr<DUID> duid_llt(new DUID(llt, sizeof(llt)));
- scoped_ptr<DUID> duid_en(new DUID(en, sizeof(en)));
- scoped_ptr<DUID> duid_ll(new DUID(ll, sizeof(ll)));
- scoped_ptr<DUID> duid_uuid(new DUID(uuid, sizeof(uuid)));
- scoped_ptr<DUID> duid_invalid(new DUID(invalid, sizeof(invalid)));
+ boost::scoped_ptr<DUID> duid_llt(new DUID(llt, sizeof(llt)));
+ boost::scoped_ptr<DUID> duid_en(new DUID(en, sizeof(en)));
+ boost::scoped_ptr<DUID> duid_ll(new DUID(ll, sizeof(ll)));
+ boost::scoped_ptr<DUID> duid_uuid(new DUID(uuid, sizeof(uuid)));
+ boost::scoped_ptr<DUID> duid_invalid(new DUID(invalid, sizeof(invalid)));
EXPECT_EQ(DUID::DUID_LLT, duid_llt->getType());
EXPECT_EQ(DUID::DUID_EN, duid_en->getType());
@@ -125,7 +115,7 @@ TEST(DuidTest, getType) {
// This test checks that the DUID instance can be created from the textual
// format and that error is reported if the textual format is invalid.
TEST(DuidTest, fromText) {
- scoped_ptr<DUID> duid;
+ boost::scoped_ptr<DUID> duid;
// DUID with only decimal digits.
ASSERT_NO_THROW(
duid.reset(new DUID(DUID::fromText("00:01:02:03:04:05:06")))
@@ -169,9 +159,11 @@ TEST(DuidTest, empty) {
// This method must return something
ASSERT_TRUE(empty);
- // Ok, technically empty is not really empty, it's just a single
- // byte with value of 0.
- EXPECT_EQ("00", empty->toText());
+ // Ok, technically empty is not really empty, it's just type 0 (DUID_UNKNOWN)
+ // followed by a single byte with value of 0.
+ EXPECT_EQ(empty->getDuid().size(), 3);
+ EXPECT_EQ(empty->getDuid(), std::vector<uint8_t>({0, 0, 0}));
+ EXPECT_EQ("00:00:00", empty->toText());
EXPECT_TRUE(*empty == DUID::EMPTY());
@@ -188,10 +180,10 @@ TEST(DuidTest, operators) {
uint8_t data3[] = {0, 1, 2, 3, 4, 5, 7}; // last digit different
uint8_t data4[] = {0, 1, 2, 3, 4, 5, 6}; // the same as 1
- scoped_ptr<DUID> duid1(new DUID(data1, sizeof(data1)));
- scoped_ptr<DUID> duid2(new DUID(data2, sizeof(data2)));
- scoped_ptr<DUID> duid3(new DUID(data3, sizeof(data3)));
- scoped_ptr<DUID> duid4(new DUID(data4, sizeof(data4)));
+ boost::scoped_ptr<DUID> duid1(new DUID(data1, sizeof(data1)));
+ boost::scoped_ptr<DUID> duid2(new DUID(data2, sizeof(data2)));
+ boost::scoped_ptr<DUID> duid3(new DUID(data3, sizeof(data3)));
+ boost::scoped_ptr<DUID> duid4(new DUID(data4, sizeof(data4)));
EXPECT_TRUE(*duid1 == *duid4);
EXPECT_FALSE(*duid1 == *duid2);
@@ -212,12 +204,12 @@ TEST(ClientIdTest, constructor) {
vector<uint8_t> data2(data1, data1 + sizeof(data1));
// checks for C-style constructor (uint8_t * + len)
- scoped_ptr<ClientId> id1(new ClientId(data1, sizeof(data1)));
+ boost::scoped_ptr<ClientId> id1(new ClientId(data1, sizeof(data1)));
vector<uint8_t> vecdata = id1->getClientId();
EXPECT_TRUE(data2 == vecdata);
// checks for vector-based constructor
- scoped_ptr<ClientId> id2(new ClientId(data2));
+ boost::scoped_ptr<ClientId> id2(new ClientId(data2));
vecdata = id2->getClientId();
EXPECT_TRUE(data2 == vecdata);
}
@@ -225,48 +217,49 @@ TEST(ClientIdTest, constructor) {
// Check that client-id sizes are reasonable
TEST(ClientIdTest, size) {
// Ensure that our size constant is RFC-compliant.
- ASSERT_EQ(128, MAX_CLIENT_ID_LEN);
+ ASSERT_EQ(255, ClientId::MAX_CLIENT_ID_LEN);
- uint8_t data[MAX_CLIENT_ID_LEN + 1];
+ uint8_t data[ClientId::MAX_CLIENT_ID_LEN + 1];
vector<uint8_t> data2;
- for (uint8_t i = 0; i < MAX_CLIENT_ID_LEN + 1; ++i) {
- data[i] = i;
- if (i < MAX_CLIENT_ID_LEN)
+ for (uint16_t i = 0; i < ClientId::MAX_CLIENT_ID_LEN + 1; ++i) {
+ data[i] = static_cast<uint8_t>(i);
+ if (i < ClientId::MAX_CLIENT_ID_LEN) {
data2.push_back(i);
+ }
}
- ASSERT_EQ(data2.size(), MAX_CLIENT_ID_LEN);
+ ASSERT_EQ(data2.size(), ClientId::MAX_CLIENT_ID_LEN);
- scoped_ptr<ClientId> duidmaxsize1(new ClientId(data, MAX_CLIENT_ID_LEN));
- scoped_ptr<ClientId> duidmaxsize2(new ClientId(data2));
+ boost::scoped_ptr<ClientId> duidmaxsize1(new ClientId(data, ClientId::MAX_CLIENT_ID_LEN));
+ boost::scoped_ptr<ClientId> duidmaxsize2(new ClientId(data2));
EXPECT_THROW(
- scoped_ptr<ClientId> toolarge1(new ClientId(data, MAX_CLIENT_ID_LEN + 1)),
+ boost::scoped_ptr<ClientId> toolarge1(new ClientId(data, ClientId::MAX_CLIENT_ID_LEN + 1)),
BadValue);
// that's one too much
- data2.push_back(128);
+ data2.push_back(0);
EXPECT_THROW(
- scoped_ptr<ClientId> toolarge2(new ClientId(data2)),
+ boost::scoped_ptr<ClientId> toolarge2(new ClientId(data2)),
BadValue);
// empty client-ids are not allowed
vector<uint8_t> empty;
EXPECT_THROW(
- scoped_ptr<ClientId> empty_client_id1(new ClientId(empty)),
+ boost::scoped_ptr<ClientId> empty_client_id1(new ClientId(empty)),
BadValue);
EXPECT_THROW(
- scoped_ptr<ClientId> empty_client_id2(new ClientId(data, 0)),
+ boost::scoped_ptr<ClientId> empty_client_id2(new ClientId(data, 0)),
BadValue);
// client-id must be at least 2 bytes long
vector<uint8_t> shorty(1,17); // just a single byte with value 17
EXPECT_THROW(
- scoped_ptr<ClientId> too_short_client_id1(new ClientId(shorty)),
+ boost::scoped_ptr<ClientId> too_short_client_id1(new ClientId(shorty)),
BadValue);
EXPECT_THROW(
- scoped_ptr<ClientId> too_short_client_id1(new ClientId(data, 1)),
+ boost::scoped_ptr<ClientId> too_short_client_id1(new ClientId(data, 1)),
BadValue);
}
@@ -277,10 +270,10 @@ TEST(ClientIdTest, operators) {
uint8_t data3[] = {0, 1, 2, 3, 4, 5, 7}; // last digit different
uint8_t data4[] = {0, 1, 2, 3, 4, 5, 6}; // the same as 1
- scoped_ptr<ClientId> id1(new ClientId(data1, sizeof(data1)));
- scoped_ptr<ClientId> id2(new ClientId(data2, sizeof(data2)));
- scoped_ptr<ClientId> id3(new ClientId(data3, sizeof(data3)));
- scoped_ptr<ClientId> id4(new ClientId(data4, sizeof(data4)));
+ boost::scoped_ptr<ClientId> id1(new ClientId(data1, sizeof(data1)));
+ boost::scoped_ptr<ClientId> id2(new ClientId(data2, sizeof(data2)));
+ boost::scoped_ptr<ClientId> id3(new ClientId(data3, sizeof(data3)));
+ boost::scoped_ptr<ClientId> id4(new ClientId(data4, sizeof(data4)));
EXPECT_TRUE(*id1 == *id4);
EXPECT_FALSE(*id1 == *id2);
diff --git a/src/lib/dhcp_ddns/tests/ncr_unittests.cc b/src/lib/dhcp_ddns/tests/ncr_unittests.cc
index 6ac2d09384..08aacbfb77 100644
--- a/src/lib/dhcp_ddns/tests/ncr_unittests.cc
+++ b/src/lib/dhcp_ddns/tests/ncr_unittests.cc
@@ -339,6 +339,7 @@ class DhcidTest : public ::testing::Test {
public:
/// @brief Constructor
DhcidTest() {
+ // 0x000000066d79686f7374076578616d706c6503636f6d00
const uint8_t fqdn_data[] = {
6, 109, 121, 104, 111, 115, 116, // myhost.
7, 101, 120, 97, 109, 112, 108, 101, // example.
@@ -386,16 +387,16 @@ TEST_F(DhcidTest, fromMinDUID) {
D2Dhcid dhcid;
// Create DUID.
- uint8_t duid_data[] = { 1 };
- DUID duid(duid_data, sizeof(duid_data));
+ std::vector<uint8_t> duid_data(DUID::MIN_DUID_LEN, 1);
+ DUID duid(&duid_data[0], duid_data.size());
// Create DHCID.
ASSERT_NO_THROW(dhcid.fromDUID(duid, wire_fqdn_));
// The reference DHCID (represented as string of hexadecimal digits)
// has been calculated using one of the online calculators.
- std::string dhcid_ref = "000201F89004F73E60CAEDFF514E11CB91D"
- "1F45C8F0A55D4BC4C688484A819F8EA4074";
+ std::string dhcid_ref = "000201202F813E7D9C88BADA41250F2A662"
+ "97742BB9B3EB37C0981D4A905745A30BDD3";
// Make sure that the DHCID is valid.
EXPECT_EQ(dhcid_ref, dhcid.toStr());
@@ -406,7 +407,7 @@ TEST_F(DhcidTest, fromMaxDUID) {
D2Dhcid dhcid;
// Create DUID.
- std::vector<uint8_t> duid_data(128, 1);
+ std::vector<uint8_t> duid_data(DUID::MAX_DUID_LEN, 1);
DUID duid(&duid_data[0], duid_data.size());
// Create DHCID.
@@ -414,8 +415,8 @@ TEST_F(DhcidTest, fromMaxDUID) {
// The reference DHCID (represented as string of hexadecimal digits)
// has been calculated using one of the online calculators.
- std::string dhcid_ref = "00020137D8FBDC0585B44DFA03FAD2E36C6"
- "159737D545A12EFB40B0D88D110A5748234";
+ std::string dhcid_ref = "0002015B9022851B4015AD78187BB9BDB98"
+ "7708C5EEA74140B28095ED36FE1EAFEE3F6";
// Make sure that the DHCID is valid.
EXPECT_EQ(dhcid_ref, dhcid.toStr());
diff --git a/src/lib/dhcpsrv/allocator.h b/src/lib/dhcpsrv/allocator.h
index a94bd81a2d..66f2302dbc 100644
--- a/src/lib/dhcpsrv/allocator.h
+++ b/src/lib/dhcpsrv/allocator.h
@@ -100,7 +100,7 @@ public:
/// @return the next address.
virtual isc::asiolink::IOAddress
pickAddress(const ClientClasses& client_classes,
- const DuidPtr& duid,
+ const IdentifierBaseTypePtr& duid,
const asiolink::IOAddress& hint) {
util::MultiThreadingLock lock(mutex_);
return (pickAddressInternal(client_classes, duid, hint));
@@ -130,7 +130,7 @@ public:
virtual isc::asiolink::IOAddress
pickPrefix(const ClientClasses& client_classes,
Pool6Ptr& pool,
- const DuidPtr& duid,
+ const IdentifierBaseTypePtr& duid,
PrefixLenMatchType prefix_length_match,
const asiolink::IOAddress& hint,
uint8_t hint_prefix_length) {
@@ -186,7 +186,7 @@ private:
/// @return the next address.
virtual isc::asiolink::IOAddress
pickAddressInternal(const ClientClasses& client_classes,
- const DuidPtr& duid,
+ const IdentifierBaseTypePtr& duid,
const isc::asiolink::IOAddress& hint) = 0;
/// @brief Picks a delegated prefix.
@@ -209,7 +209,7 @@ private:
virtual isc::asiolink::IOAddress
pickPrefixInternal(const ClientClasses& client_classes,
Pool6Ptr& pool,
- const DuidPtr& duid,
+ const IdentifierBaseTypePtr& duid,
PrefixLenMatchType prefix_length_match,
const isc::asiolink::IOAddress& hint,
uint8_t hint_prefix_length) = 0;
diff --git a/src/lib/dhcpsrv/flq_allocator.cc b/src/lib/dhcpsrv/flq_allocator.cc
index 0ce83ff2fc..7f5181052e 100644
--- a/src/lib/dhcpsrv/flq_allocator.cc
+++ b/src/lib/dhcpsrv/flq_allocator.cc
@@ -36,7 +36,7 @@ FreeLeaseQueueAllocator::FreeLeaseQueueAllocator(Lease::Type type, const WeakSub
IOAddress
FreeLeaseQueueAllocator::pickAddressInternal(const ClientClasses& client_classes,
- const DuidPtr&,
+ const IdentifierBaseTypePtr&,
const IOAddress&) {
auto subnet = subnet_.lock();
auto pools = subnet->getPools(pool_type_);
@@ -81,7 +81,7 @@ FreeLeaseQueueAllocator::pickAddressInternal(const ClientClasses& client_classes
IOAddress
FreeLeaseQueueAllocator::pickPrefixInternal(const ClientClasses& client_classes,
Pool6Ptr& pool6,
- const DuidPtr&,
+ const IdentifierBaseTypePtr&,
PrefixLenMatchType prefix_length_match,
const IOAddress&,
uint8_t hint_prefix_length) {
diff --git a/src/lib/dhcpsrv/flq_allocator.h b/src/lib/dhcpsrv/flq_allocator.h
index e3b9cf89ab..e001c95d5e 100644
--- a/src/lib/dhcpsrv/flq_allocator.h
+++ b/src/lib/dhcpsrv/flq_allocator.h
@@ -92,7 +92,7 @@ private:
///
/// @return next offered address.
virtual asiolink::IOAddress pickAddressInternal(const ClientClasses& client_classes,
- const DuidPtr& duid,
+ const IdentifierBaseTypePtr& duid,
const asiolink::IOAddress& hint);
/// @brief Returns next available delegated prefix from the queue.
@@ -113,7 +113,7 @@ private:
virtual isc::asiolink::IOAddress
pickPrefixInternal(const ClientClasses& client_classes,
Pool6Ptr& pool,
- const DuidPtr& duid,
+ const IdentifierBaseTypePtr& duid,
PrefixLenMatchType prefix_length_match,
const isc::asiolink::IOAddress& hint,
uint8_t hint_prefix_length);
diff --git a/src/lib/dhcpsrv/host.cc b/src/lib/dhcpsrv/host.cc
index 328e4ac932..35c0bb7655 100644
--- a/src/lib/dhcpsrv/host.cc
+++ b/src/lib/dhcpsrv/host.cc
@@ -215,6 +215,8 @@ Host::getIdentifierMaxLength(const IdentifierType& type) {
return (HWAddr::MAX_HWADDR_LEN);
case IDENT_DUID:
return (DUID::MAX_DUID_LEN);
+ case IDENT_CLIENT_ID:
+ return (ClientId::MAX_CLIENT_ID_LEN);
default:
// In fact it is backend dependent but for compatibility we take
// the lowest value.
diff --git a/src/lib/dhcpsrv/iterative_allocator.cc b/src/lib/dhcpsrv/iterative_allocator.cc
index a31c70181e..8a66cb7430 100644
--- a/src/lib/dhcpsrv/iterative_allocator.cc
+++ b/src/lib/dhcpsrv/iterative_allocator.cc
@@ -88,7 +88,7 @@ IterativeAllocator::increaseAddress(const IOAddress& address,
IOAddress
IterativeAllocator::pickAddressInternal(const ClientClasses& client_classes,
- const DuidPtr&,
+ const IdentifierBaseTypePtr&,
const IOAddress&) {
// Let's get the last allocated address. It is usually set correctly,
// but there are times when it won't be (like after removing a pool or
@@ -198,7 +198,7 @@ IterativeAllocator::pickAddressInternal(const ClientClasses& client_classes,
IOAddress
IterativeAllocator::pickPrefixInternal(const ClientClasses& client_classes,
Pool6Ptr& pool6,
- const DuidPtr&,
+ const IdentifierBaseTypePtr&,
PrefixLenMatchType prefix_length_match,
const IOAddress&,
uint8_t hint_prefix_length) {
diff --git a/src/lib/dhcpsrv/iterative_allocator.h b/src/lib/dhcpsrv/iterative_allocator.h
index 7be2ea9725..ef08090299 100644
--- a/src/lib/dhcpsrv/iterative_allocator.h
+++ b/src/lib/dhcpsrv/iterative_allocator.h
@@ -50,7 +50,7 @@ private:
///
/// @return next offered address.
virtual asiolink::IOAddress pickAddressInternal(const ClientClasses& client_classes,
- const DuidPtr& duid,
+ const IdentifierBaseTypePtr& duid,
const asiolink::IOAddress& hint);
/// @brief Picks a delegated prefix.
@@ -68,13 +68,12 @@ private:
/// pool will suffice.
///
/// @return the next prefix.
- virtual isc::asiolink::IOAddress
- pickPrefixInternal(const ClientClasses& client_classes,
- Pool6Ptr& pool,
- const DuidPtr& duid,
- PrefixLenMatchType prefix_length_match,
- const isc::asiolink::IOAddress& hint,
- uint8_t hint_prefix_length);
+ virtual asiolink::IOAddress pickPrefixInternal(const ClientClasses& client_classes,
+ Pool6Ptr& pool,
+ const IdentifierBaseTypePtr& duid,
+ PrefixLenMatchType prefix_length_match,
+ const asiolink::IOAddress& hint,
+ uint8_t hint_prefix_length);
/// @brief Convenience function returning subnet allocation state instance.
///
diff --git a/src/lib/dhcpsrv/lease.cc b/src/lib/dhcpsrv/lease.cc
index 2d58063638..1d74b72a15 100644
--- a/src/lib/dhcpsrv/lease.cc
+++ b/src/lib/dhcpsrv/lease.cc
@@ -558,7 +558,7 @@ Lease6::decline(uint32_t probation_period) {
hostname_ = string("");
fqdn_fwd_ = false;
fqdn_rev_ = false;
- state_ = Lease::STATE_DECLINED;
+ state_ = STATE_DECLINED;
}
std::string
diff --git a/src/lib/dhcpsrv/mysql_host_data_source.cc b/src/lib/dhcpsrv/mysql_host_data_source.cc
index 938c6a61a1..26d1530cd3 100644
--- a/src/lib/dhcpsrv/mysql_host_data_source.cc
+++ b/src/lib/dhcpsrv/mysql_host_data_source.cc
@@ -266,7 +266,7 @@ public:
bind_[0].buffer = reinterpret_cast<char*>(&host_id_);
bind_[0].is_unsigned = MLM_TRUE;
- // dhcp_identifier : VARBINARY(128) NOT NULL
+ // dhcp_identifier : VARBINARY(255) NOT NULL
dhcp_identifier_length_ = host->getIdentifier().size();
memcpy(static_cast<void*>(dhcp_identifier_buffer_),
&(host->getIdentifier())[0],
@@ -422,7 +422,7 @@ public:
bind_[0].buffer = reinterpret_cast<char*>(&host_id_);
bind_[0].is_unsigned = MLM_TRUE;
- // dhcp_identifier : VARBINARY(128) NOT NULL
+ // dhcp_identifier : VARBINARY(255) NOT NULL
dhcp_identifier_length_ = sizeof(dhcp_identifier_buffer_);
bind_[1].buffer_type = MYSQL_TYPE_BLOB;
bind_[1].buffer = reinterpret_cast<char*>(dhcp_identifier_buffer_);
@@ -718,7 +718,7 @@ private:
/// Buffer holding client's identifier (e.g. DUID, HW address)
/// in the binary format.
- uint8_t dhcp_identifier_buffer_[DUID::MAX_DUID_LEN];
+ uint8_t dhcp_identifier_buffer_[ClientId::MAX_CLIENT_ID_LEN];
/// Length of a data in the dhcp_identifier_buffer_.
unsigned long dhcp_identifier_length_;
diff --git a/src/lib/dhcpsrv/mysql_lease_mgr.cc b/src/lib/dhcpsrv/mysql_lease_mgr.cc
index 3e5d61f7ff..f26c7cedf1 100644
--- a/src/lib/dhcpsrv/mysql_lease_mgr.cc
+++ b/src/lib/dhcpsrv/mysql_lease_mgr.cc
@@ -630,7 +630,7 @@ public:
bind_[1].is_null = &hwaddr_null_;
}
- // client_id: varbinary(128)
+ // client_id: varbinary(255)
if (lease_->client_id_) {
client_id_ = lease_->client_id_->getClientId();
client_id_length_ = client_id_.size();
@@ -742,7 +742,7 @@ public:
bind_[10].buffer_type = MYSQL_TYPE_NULL;
}
- // relay_id: varbinary(128)
+ // relay_id: varbinary(255)
relay_id_ = lease_->relay_id_;
if (!relay_id_.empty()) {
bind_[11].buffer_type = MYSQL_TYPE_BLOB;
@@ -757,7 +757,7 @@ public:
bind_[11].is_null = &relay_id_null_;
}
- // remote_id: varbinary(128)
+ // remote_id: varbinary(255)
remote_id_ = lease_->remote_id_;
if (!remote_id_.empty()) {
bind_[12].buffer_type = MYSQL_TYPE_BLOB;
@@ -819,7 +819,7 @@ public:
// bind_[1].is_null = &MLM_FALSE; // commented out for performance
// reasons, see memset() above
- // client_id: varbinary(128)
+ // client_id: varbinary(255)
client_id_length_ = sizeof(client_id_buffer_);
bind_[2].buffer_type = MYSQL_TYPE_BLOB;
bind_[2].buffer = reinterpret_cast<char*>(client_id_buffer_);
@@ -892,7 +892,7 @@ public:
bind_[10].length = &user_context_length_;
bind_[10].is_null = &user_context_null_;
- // relay_id: varbinary(128)
+ // relay_id: varbinary(255)
relay_id_length_ = sizeof(relay_id_buffer_);
bind_[11].buffer_type = MYSQL_TYPE_BLOB;
bind_[11].buffer = reinterpret_cast<char*>(relay_id_buffer_);
@@ -900,7 +900,7 @@ public:
bind_[11].length = &relay_id_length_;
bind_[11].is_null = &relay_id_null_;
- // remote_id: varbinary(128)
+ // remote_id: varbinary(255)
remote_id_length_ = sizeof(remote_id_buffer_);
bind_[12].buffer_type = MYSQL_TYPE_BLOB;
bind_[12].buffer = reinterpret_cast<char*>(remote_id_buffer_);
@@ -1159,7 +1159,7 @@ public:
// bind_[0].is_null = &MLM_FALSE; // commented out for performance
// reasons, see memset() above
- // duid: varchar(128)
+ // duid: varchar(130)
if (!lease_->duid_) {
isc_throw(DbOperationError, "lease6 for address " << addr6_
<< " is missing mandatory client-id.");
@@ -1399,7 +1399,7 @@ public:
// bind_[0].is_null = &MLM_FALSE; // commented out for performance
// reasons, see memset() above
- // client_id: varbinary(128)
+ // duid: varbinary(130)
duid_length_ = sizeof(duid_buffer_);
bind_[1].buffer_type = MYSQL_TYPE_BLOB;
bind_[1].buffer = reinterpret_cast<char*>(duid_buffer_);
diff --git a/src/lib/dhcpsrv/parsers/host_reservation_parser.cc b/src/lib/dhcpsrv/parsers/host_reservation_parser.cc
index 38a8915b41..da0086e90c 100644
--- a/src/lib/dhcpsrv/parsers/host_reservation_parser.cc
+++ b/src/lib/dhcpsrv/parsers/host_reservation_parser.cc
@@ -299,8 +299,7 @@ HostReservationParser6::parseInternal(const SubnetID& subnet_id,
// as the lexical cast would expect a character, e.g.
// 'a', instead of prefix length, e.g. '64'.
try {
- prefix_len = boost::lexical_cast<
- unsigned int>(prefix.substr(len_pos + 1));
+ prefix_len = boost::lexical_cast<unsigned int>(prefix.substr(len_pos + 1));
} catch (const boost::bad_lexical_cast&) {
isc_throw(DhcpConfigError, "prefix length value '"
@@ -318,8 +317,8 @@ HostReservationParser6::parseInternal(const SubnetID& subnet_id,
// Create a reservation for an address or prefix.
host->addReservation(IPv6Resrv(resrv_type,
- IOAddress(prefix),
- prefix_len));
+ IOAddress(prefix),
+ prefix_len));
} catch (const std::exception& ex) {
// Append line number where the error occurred.
diff --git a/src/lib/dhcpsrv/pgsql_host_data_source.cc b/src/lib/dhcpsrv/pgsql_host_data_source.cc
index 7757977ba8..7bf9988f1c 100644
--- a/src/lib/dhcpsrv/pgsql_host_data_source.cc
+++ b/src/lib/dhcpsrv/pgsql_host_data_source.cc
@@ -56,7 +56,7 @@ const size_t OPTION_VALUE_MAX_LEN = 4096;
const uint8_t MAX_IDENTIFIER_TYPE = static_cast<uint8_t>(Host::LAST_IDENTIFIER_TYPE);
/// @brief Maximum length of DHCP identifier value.
-const size_t DHCP_IDENTIFIER_MAX_LEN = 128;
+const size_t DHCP_IDENTIFIER_MAX_LEN = ClientId::MAX_CLIENT_ID_LEN;
/// @brief This class provides mechanisms for sending and retrieving
/// information from the 'hosts' table.
diff --git a/src/lib/dhcpsrv/random_allocator.cc b/src/lib/dhcpsrv/random_allocator.cc
index dd67545229..f838b8cf3c 100644
--- a/src/lib/dhcpsrv/random_allocator.cc
+++ b/src/lib/dhcpsrv/random_allocator.cc
@@ -25,7 +25,7 @@ RandomAllocator::RandomAllocator(Lease::Type type, const WeakSubnetPtr& subnet)
IOAddress
RandomAllocator::pickAddressInternal(const ClientClasses& client_classes,
- const DuidPtr&,
+ const IdentifierBaseTypePtr&,
const IOAddress&) {
auto subnet = subnet_.lock();
auto pools = subnet->getPools(pool_type_);
@@ -86,7 +86,7 @@ RandomAllocator::pickAddressInternal(const ClientClasses& client_classes,
IOAddress
RandomAllocator::pickPrefixInternal(const ClientClasses& client_classes,
Pool6Ptr& pool6,
- const DuidPtr&,
+ const IdentifierBaseTypePtr&,
PrefixLenMatchType prefix_length_match,
const IOAddress&,
uint8_t hint_prefix_length) {
diff --git a/src/lib/dhcpsrv/random_allocator.h b/src/lib/dhcpsrv/random_allocator.h
index 9064830297..759005e0a6 100644
--- a/src/lib/dhcpsrv/random_allocator.h
+++ b/src/lib/dhcpsrv/random_allocator.h
@@ -55,7 +55,7 @@ private:
///
/// @return next offered address.
virtual asiolink::IOAddress pickAddressInternal(const ClientClasses& client_classes,
- const DuidPtr& duid,
+ const IdentifierBaseTypePtr& duid,
const asiolink::IOAddress& hint);
/// @brief Picks a delegated prefix.
@@ -73,13 +73,12 @@ private:
/// pool will suffice.
///
/// @return the next prefix.
- virtual isc::asiolink::IOAddress
- pickPrefixInternal(const ClientClasses& client_classes,
- Pool6Ptr& pool,
- const DuidPtr& duid,
- PrefixLenMatchType prefix_length_match,
- const isc::asiolink::IOAddress& hint,
- uint8_t hint_prefix_length);
+ virtual asiolink::IOAddress pickPrefixInternal(const ClientClasses& client_classes,
+ Pool6Ptr& pool,
+ const IdentifierBaseTypePtr& duid,
+ PrefixLenMatchType prefix_length_match,
+ const asiolink::IOAddress& hint,
+ uint8_t hint_prefix_length);
/// @brief Convenience function returning pool allocation state instance.
///
diff --git a/src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc b/src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc
index 942944b2d7..37756b9672 100644
--- a/src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc
+++ b/src/lib/dhcpsrv/tests/alloc_engine4_unittest.cc
@@ -3002,7 +3002,7 @@ TEST_F(AllocEngine4Test, findReservation) {
"", false);
ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234));
ctx.addHostIdentifier(Host::IDENT_HWADDR, hwaddr_->hwaddr_);
- ctx.addHostIdentifier(Host::IDENT_DUID, clientid_->getDuid());
+ ctx.addHostIdentifier(Host::IDENT_DUID, clientid_->getClientId());
// There is no reservation in the database so no host should be returned.
ASSERT_NO_THROW(engine.findReservation(ctx));
diff --git a/src/lib/dhcpsrv/tests/csv_lease_file6_unittest.cc b/src/lib/dhcpsrv/tests/csv_lease_file6_unittest.cc
index 35aea7f43d..dcba91f489 100644
--- a/src/lib/dhcpsrv/tests/csv_lease_file6_unittest.cc
+++ b/src/lib/dhcpsrv/tests/csv_lease_file6_unittest.cc
@@ -115,9 +115,9 @@ CSVLeaseFile6Test::writeSampleFile() const {
"3000:1::,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,0,200,8,0,2,"
"16,64,0,0,,,1,{ \"foobar\": true },,"
"1,0\n"
- "2001:db8:1::2,00,200,200,8,100,0,7,0,1,1,host.example.com,,0,,"
+ "2001:db8:1::2,00:00:00,200,200,8,100,0,7,0,1,1,host.example.com,,0,,"
"1,0\n"
- "2001:db8:1::3,00,200,200,8,100,0,7,0,1,1,host.example.com,,1,,"
+ "2001:db8:1::3,00:00:00,200,200,8,100,0,7,0,1,1,host.example.com,,1,,"
"1,0\n");
}
@@ -239,7 +239,7 @@ TEST_F(CSVLeaseFile6Test, parse) {
// Verify that the lease is correct.
EXPECT_EQ("2001:db8:1::3", lease->addr_.toText());
ASSERT_TRUE(lease->duid_);
- EXPECT_EQ("00", lease->duid_->toText());
+ EXPECT_EQ("00:00:00", lease->duid_->toText());
EXPECT_EQ(Lease::STATE_DECLINED, lease->state_);
}
@@ -325,7 +325,6 @@ TEST_F(CSVLeaseFile6Test, recreate) {
checkStats(lf, 0, 0, 0, 5, 4, 1);
}
-
EXPECT_EQ("address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,"
"lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,"
"state,user_context,hwtype,hwaddr_source\n"
@@ -335,7 +334,7 @@ TEST_F(CSVLeaseFile6Test, recreate) {
",300,300,6,150,0,8,128,0,0,,,0,,,\n"
"3000:1:1::,00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f,"
"300,300,10,150,2,7,64,0,0,,,0,{ \"foobar\": true },,\n"
- "2001:db8:2::10,00,300,300,6,150,0,8,128,0,0,,,1,,,\n",
+ "2001:db8:2::10,00:00:00,300,300,6,150,0,8,128,0,0,,,1,,,\n",
io_.readFile());
}
@@ -519,7 +518,6 @@ TEST_F(CSVLeaseFile6Test, downGrade) {
EXPECT_EQ(util::VersionedCSVFile::NEEDS_DOWNGRADE,
lf.getInputSchemaState());
-
Lease6Ptr lease;
{
SCOPED_TRACE("First lease valid");
@@ -558,11 +556,11 @@ TEST_F(CSVLeaseFile6Test, declinedLeaseTest) {
"pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,"
"fqdn_rev,hostname,hwaddr,state,user_context,"
"hwtype,hwaddr_source\n"
- "2001:db8:1::1,00,"
+ "2001:db8:1::1,00:00:00,"
"200,200,8,100,0,7,0,1,1,host.example.com,,0,,,\n"
"2001:db8:1::1,,"
"200,200,8,100,0,7,0,1,1,host.example.com,,0,,,\n"
- "2001:db8:1::1,00,"
+ "2001:db8:1::1,00:00:00,"
"200,200,8,100,0,7,0,1,1,host.example.com,,1,,,\n");
CSVLeaseFile6 lf(filename_);
@@ -585,7 +583,7 @@ TEST_F(CSVLeaseFile6Test, declinedLeaseTest) {
EXPECT_FALSE(lf.next(lease));
EXPECT_FALSE(lease);
EXPECT_EQ(lf.getReadErrs(), 2);
- EXPECT_EQ(lf.getReadMsg(), "Empty DUIDs are not allowed");
+ EXPECT_EQ(lf.getReadMsg(), "identifier is too short (0), at least 3 is required");
}
{
@@ -712,9 +710,6 @@ TEST_F(CSVLeaseFile6Test, embeddedEscapes) {
EXPECT_EQ(context_str, lease->getContext()->str());
}
-
-
-
/// @todo Currently we don't check invalid lease attributes, such as invalid
/// lease type, invalid preferred lifetime vs valid lifetime etc. The Lease6
/// should be extended with the function that validates lease attributes. Once
diff --git a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc
index c656f34a22..d6c46cc520 100644
--- a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc
+++ b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc
@@ -1200,13 +1200,14 @@ GenericLeaseMgrTest::testGetLease4ClientIdSize() {
// Intermediate client_id_max is to overcome problem if
// ClientId::MAX_CLIENT_ID_LEN is used in an EXPECT_EQ.
int client_id_max = ClientId::MAX_CLIENT_ID_LEN;
- EXPECT_EQ(128, client_id_max);
+ EXPECT_EQ(255, client_id_max);
int client_id_min = ClientId::MIN_CLIENT_ID_LEN;
EXPECT_EQ(2, client_id_min); // See RFC2132, section 9.14
- for (uint8_t i = client_id_min; i <= client_id_max; i += 16) {
- vector<uint8_t> clientid_vec(i, i);
+ for (uint16_t i = client_id_min; i <= client_id_max; i += 16) {
+ uint8_t data = static_cast<uint8_t>(i);
+ vector<uint8_t> clientid_vec(data, data);
leases[1]->client_id_.reset(new ClientId(clientid_vec));
EXPECT_TRUE(lmptr_->addLease(leases[1]));
Lease4Collection returned = lmptr_->getLease4(*leases[1]->client_id_);
@@ -1525,10 +1526,10 @@ GenericLeaseMgrTest::testGetLeases6DuidSize() {
// Now add leases with increasing DUID size can be retrieved.
// For speed, go from 0 to 128 is steps of 16.
int duid_max = DUID::MAX_DUID_LEN;
- EXPECT_EQ(128, duid_max);
+ EXPECT_EQ(130, duid_max);
int duid_min = DUID::MIN_DUID_LEN;
- EXPECT_EQ(1, duid_min);
+ EXPECT_EQ(3, duid_min);
for (uint8_t i = duid_min; i <= duid_max; i += 16) {
vector<uint8_t> duid_vec(i, i);
@@ -1768,10 +1769,10 @@ GenericLeaseMgrTest::testGetLease6DuidIaidSubnetIdSize() {
// Now add leases with increasing DUID size can be retrieved.
// For speed, go from 0 to 128 is steps of 16.
int duid_max = DUID::MAX_DUID_LEN;
- EXPECT_EQ(128, duid_max);
+ EXPECT_EQ(130, duid_max);
int duid_min = DUID::MIN_DUID_LEN;
- EXPECT_EQ(1, duid_min);
+ EXPECT_EQ(3, duid_min);
for (uint8_t i = duid_min; i <= duid_max; i += 16) {
vector<uint8_t> duid_vec(i, i);
diff --git a/src/lib/dhcpsrv/tests/host_unittest.cc b/src/lib/dhcpsrv/tests/host_unittest.cc
index 4d82c0527b..836824f68d 100644
--- a/src/lib/dhcpsrv/tests/host_unittest.cc
+++ b/src/lib/dhcpsrv/tests/host_unittest.cc
@@ -194,9 +194,9 @@ public:
// This test verifies that expected identifier max length is returned.
TEST_F(HostTest, getIdentifierMaxLength) {
EXPECT_EQ(20, Host::getIdentifierMaxLength(Host::IDENT_HWADDR));
- EXPECT_EQ(128, Host::getIdentifierMaxLength(Host::IDENT_DUID));
+ EXPECT_EQ(130, Host::getIdentifierMaxLength(Host::IDENT_DUID));
EXPECT_EQ(128, Host::getIdentifierMaxLength(Host::IDENT_CIRCUIT_ID));
- EXPECT_EQ(128, Host::getIdentifierMaxLength(Host::IDENT_CLIENT_ID));
+ EXPECT_EQ(255, Host::getIdentifierMaxLength(Host::IDENT_CLIENT_ID));
EXPECT_EQ(128, Host::getIdentifierMaxLength(Host::IDENT_FLEX));
}
@@ -317,12 +317,12 @@ TEST_F(HostTest, createFromDUIDString) {
too_long += ":50:51:52:53:54:55:56:57:58:59:5a:5b:5c:5d:5e:5f";
too_long += ":60:61:62:63:64:65:66:67:68:69:6a:6b:6c:6d:6e:6f";
too_long += ":70:71:72:73:74:75:76:77:78:79:7a:7b:7c:7d:7e:7f";
- too_long += ":ff";
- expected = "too long client identifier type duid length 129";
+ too_long += ":80:81:ff";
+ expected = "too long client identifier type duid length 131";
EXPECT_THROW_MSG(Host(too_long, "duid", SubnetID(1), SubnetID(2),
IOAddress("192.0.2.3"), "somehost.example.org"),
isc::BadValue, expected);
- expected = "too long client identifier type circuit-id length 129";
+ expected = "too long client identifier type circuit-id length 131";
EXPECT_THROW_MSG(Host(too_long, "circuit-id", SubnetID(1), SubnetID(2),
IOAddress("192.0.2.3"), "somehost.example.org"),
isc::BadValue, expected);
@@ -409,11 +409,11 @@ TEST_F(HostTest, createFromDuidBinary) {
EXPECT_EQ("me.example.org", host->getHostname());
EXPECT_FALSE(host->getContext());
- uint8_t too_long[129];
- for (uint8_t i = 0; i < 129; ++i) {
+ uint8_t too_long[DUID::MAX_DUID_LEN + 1];
+ for (uint8_t i = 0; i < sizeof(too_long); ++i) {
too_long[i] = i;
}
- string expected = "too long client identifier type duid length 129";
+ string expected = "too long client identifier type duid length 131";
EXPECT_THROW_MSG(host.reset(new Host(too_long,
sizeof(too_long),
Host::IDENT_DUID,
diff --git a/src/lib/dhcpsrv/tests/lease_unittest.cc b/src/lib/dhcpsrv/tests/lease_unittest.cc
index 7c024491ba..2321d8ecc5 100644
--- a/src/lib/dhcpsrv/tests/lease_unittest.cc
+++ b/src/lib/dhcpsrv/tests/lease_unittest.cc
@@ -1005,7 +1005,7 @@ TEST(Lease6Test, decline) {
lease.decline(123);
ASSERT_TRUE(lease.duid_);
- ASSERT_EQ("00", lease.duid_->toText());
+ ASSERT_EQ("00:00:00", lease.duid_->toText());
ASSERT_FALSE(lease.hwaddr_);
EXPECT_EQ(0, lease.preferred_lft_);
diff --git a/src/share/database/scripts/mysql/dhcpdb_create.mysql b/src/share/database/scripts/mysql/dhcpdb_create.mysql
index b0b60b6651..442c4a8fd8 100644
--- a/src/share/database/scripts/mysql/dhcpdb_create.mysql
+++ b/src/share/database/scripts/mysql/dhcpdb_create.mysql
@@ -43,7 +43,6 @@ CREATE TABLE lease4 (
hostname VARCHAR(255) # The FQDN of the client
) ENGINE = INNODB;
-
# Create search indexes for lease4 table
# index by hwaddr and subnet_id
CREATE INDEX lease4_by_hwaddr_subnet_id ON lease4 (hwaddr, subnet_id);
@@ -71,7 +70,7 @@ CREATE TABLE lease6 (
) ENGINE = INNODB;
-# Create search indexes for lease4 table
+# Create search indexes for lease6 table
# index by iaid, subnet_id, and duid
CREATE INDEX lease6_by_iaid_subnet_id_duid ON lease6 (iaid, subnet_id, duid);
@@ -103,9 +102,9 @@ START TRANSACTION;
INSERT INTO schema_version VALUES (1, 0);
COMMIT;
-# This line concludes database initialization to version 1.0.
+# This line concludes the schema initialization to version 1.0.
-# This line starts database upgrade to version 2.0.
+# This line starts the schema upgrade to version 2.0.
ALTER TABLE lease6
ADD COLUMN hwaddr varbinary(20), # Hardware/MAC address, typically only 6
# bytes is used, but some hardware (e.g.
@@ -146,12 +145,14 @@ INSERT INTO lease_hwaddr_source VALUES (32, 'HWADDR_SOURCE_SUBSCRIBER_ID');
# Hardware address extracted from docsis options
INSERT INTO lease_hwaddr_source VALUES (64, 'HWADDR_SOURCE_DOCSIS');
+# Update the schema version number
UPDATE schema_version
-SET version = '2', minor = '0';
+ SET version = '2', minor = '0';
-# This line concludes database upgrade to version 2.0.
+# This line concludes the schema upgrade to version 2.0.
+
+# This line starts the schema upgrade to version 3.0.
-# This line starts database upgrade to version 3.0.
# Upgrade extending MySQL schema with the ability to store hosts.
CREATE TABLE IF NOT EXISTS hosts (
@@ -234,11 +235,14 @@ END
$$
DELIMITER ;
+# Update the schema version number
UPDATE schema_version
-SET version = '3', minor = '0';
-# This line concludes database upgrade to version 3.0.
+ SET version = '3', minor = '0';
+
+# This line concludes the schema upgrade to version 3.0.
+
+# This line starts the schema upgrade to version 4.0.
-# This line starts database upgrade to version 4.0.
# Upgrade extending MySQL schema with the state columns for lease tables.
# Add state column to the lease4 table.
@@ -377,9 +381,11 @@ DELIMITER ;
# Update the schema version number
UPDATE schema_version
-SET version = '4', minor = '0';
+ SET version = '4', minor = '0';
+
+# This line concludes the schema upgrade to version 4.0.
-# This line concludes database upgrade to version 4.0.
+# This line starts the schema upgrade to version 4.1.
# In the event hardware address cannot be determined, we need to satisfy
# foreign key constraint between lease6 and lease_hardware_source
@@ -387,9 +393,11 @@ INSERT INTO lease_hwaddr_source VALUES (0, 'HWADDR_SOURCE_UNKNOWN');
# Update the schema version number
UPDATE schema_version
-SET version = '4', minor = '1';
+ SET version = '4', minor = '1';
-# This line concludes database upgrade to version 4.1.
+# This line concludes the schema upgrade to version 4.1.
+
+# This line starts the schema upgrade to version 5.
# Update index used for searching DHCPv4 reservations by identifier and subnet id.
# This index is now unique (to prevent duplicates) and includes DHCPv4 subnet
@@ -470,8 +478,6 @@ ALTER TABLE dhcp6_options
ALTER TABLE ipv6_reservations
MODIFY reservation_id INT UNSIGNED NOT NULL AUTO_INCREMENT;
-# This line concludes database upgrade to version 7.0.
-
# Add columns holding reservations for siaddr, sname and file fields
# carried within DHCPv4 message.
ALTER TABLE hosts ADD COLUMN dhcp4_next_server INT UNSIGNED NULL;
@@ -480,8 +486,11 @@ ALTER TABLE hosts ADD COLUMN dhcp4_boot_file_name VARCHAR(128) NULL;
# Update the schema version number
UPDATE schema_version
-SET version = '5', minor = '0';
-# This line concludes database upgrade to version 5.0.
+ SET version = '5', minor = '0';
+
+# This line concludes the schema upgrade to version 5.0.
+
+# This line starts the schema upgrade to version 5.1.
# Add missing 'client-id' and new 'flex-id' host identifier types.
INSERT INTO host_identifier_type VALUES (3, 'client-id');
@@ -503,8 +512,11 @@ DELIMITER ;
# Update the schema version number
UPDATE schema_version
-SET version = '5', minor = '1';
-# This line concludes database upgrade to version 5.1.
+ SET version = '5', minor = '1';
+
+# This line concludes the schema upgrade to version 5.1.
+
+# This line starts the schema upgrade to version 5.2.
# Make subnet_id column types consistent with lease table columns
ALTER TABLE dhcp4_options MODIFY dhcp4_subnet_id INT UNSIGNED;
@@ -512,9 +524,11 @@ ALTER TABLE dhcp6_options MODIFY dhcp6_subnet_id INT UNSIGNED;
# Update the schema version number
UPDATE schema_version
-SET version = '5', minor = '2';
+ SET version = '5', minor = '2';
+
+# This line concludes the schema upgrade to version 5.2.
-# This line concludes database upgrade to version 5.2.
+# This line starts the schema upgrade to version 6.0.
# Add user context into table holding hosts
ALTER TABLE hosts ADD COLUMN user_context TEXT NULL;
@@ -676,9 +690,11 @@ DELIMITER ;
# Update the schema version number
UPDATE schema_version
-SET version = '6', minor = '0';
+ SET version = '6', minor = '0';
-# This line concludes database upgrade to version 6.0.
+# This line concludes the schema upgrade to version 6.0.
+
+# This line starts the schema upgrade to version 7.0.
# Add user context into tables holding leases
ALTER TABLE lease4 ADD COLUMN user_context TEXT NULL;
@@ -769,7 +785,6 @@ CREATE INDEX timestamp_index ON logs (timestamp);
ALTER TABLE hosts
ADD COLUMN auth_key VARCHAR(16) NULL;
-
# Add scope for shared network specific options.
INSERT INTO dhcp_option_scope (scope_id, scope_name)
VALUES(4, "shared-network");
@@ -836,7 +851,6 @@ CREATE TABLE IF NOT EXISTS dhcp4_audit (
ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB;
-
-- -----------------------------------------------------
-- Table `dhcp4_global_parameter`
-- -----------------------------------------------------
@@ -1018,7 +1032,6 @@ CREATE TABLE IF NOT EXISTS dhcp4_subnet_server (
ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB;
-
# Modify the primary key to BINGINT as other tables have.
ALTER TABLE dhcp4_options MODIFY option_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT;
@@ -1331,10 +1344,11 @@ DELIMITER ;
# Update the schema version number
UPDATE schema_version
-SET version = '7', minor = '0';
+ SET version = '7', minor = '0';
-# This line concludes database upgrade to version 7.0.
+# This line concludes the schema upgrade to version 7.0.
+# This line starts the schema upgrade to version 8.0.
ALTER TABLE dhcp4_options
MODIFY COLUMN modification_ts TIMESTAMP NOT NULL
@@ -1871,7 +1885,6 @@ ALTER TABLE dhcp6_global_parameter
ADD CONSTRAINT fk_dhcp6_global_parameter_type FOREIGN KEY (parameter_type)
REFERENCES parameter_data_type (id);
-
-- Rename dhcp6_subnet_id column of dhcp6_pool and dhcp6_pd_pool
ALTER TABLE dhcp6_pool
@@ -2290,9 +2303,11 @@ DELIMITER ;
# Update the schema version number
UPDATE schema_version
-SET version = '8', minor = '0';
+ SET version = '8', minor = '0';
-# This line concludes database upgrade to version 8.0.
+# This line concludes the schema upgrade to version 8.0.
+
+# This line starts the schema upgrade to version 8.1.
# Add lifetime bounds
ALTER TABLE dhcp4_shared_network
@@ -2375,9 +2390,11 @@ ALTER TABLE hosts
# Update the schema version number
UPDATE schema_version
-SET version = '8', minor = '1';
+ SET version = '8', minor = '1';
+
+# This line concludes the schema upgrade to version 8.1.
-# This line concludes database upgrade to version 8.1.
+# This line starts the schema upgrade to version 8.2.
# Drop existing trigger on the dhcp4_shared_network table.
DROP TRIGGER dhcp4_shared_network_ADEL;
@@ -2631,7 +2648,6 @@ CREATE TRIGGER dhcp4_options_ADEL AFTER DELETE ON dhcp4_options
END $$
DELIMITER ;
-
-- -----------------------------------------------------
--
-- New version of the createOptionAuditDHCP4 stored
@@ -2779,9 +2795,11 @@ DELIMITER ;
# Update the schema version number
UPDATE schema_version
-SET version = '8', minor = '2';
+ SET version = '8', minor = '2';
-# This line concludes database upgrade to version 8.2.
+# This line concludes the schema upgrade to version 8.2.
+
+# This line starts the schema upgrade to version 9.0.
# Create hostname index for host reservations
CREATE INDEX hosts_by_hostname ON hosts (hostname);
@@ -2794,9 +2812,11 @@ CREATE INDEX lease6_by_hostname ON lease6 (hostname);
# Update the schema version number
UPDATE schema_version
-SET version = '9', minor = '0';
+ SET version = '9', minor = '0';
+
+# This line concludes the schema upgrade to version 9.0.
-# This line concludes database upgrade to version 9.0.
+# This line starts the schema upgrade to version 9.1.
# Add new DDNS related columns to shared networks and subnets
ALTER TABLE dhcp4_shared_network
@@ -2833,9 +2853,11 @@ ALTER TABLE dhcp6_subnet
# Update the schema version number
UPDATE schema_version
-SET version = '9', minor = '1';
+ SET version = '9', minor = '1';
-# This line concludes database upgrade to version 9.1.
+# This line concludes the schema upgrade to version 9.1.
+
+# This line starts the schema upgrade to version 9.2.
# Add missing indexes (foreign keys) to the dhcp4_options table.
ALTER TABLE dhcp4_options ADD CONSTRAINT fk_dhcp4_options_shared_network
@@ -2876,9 +2898,11 @@ ALTER TABLE dhcp6_options ADD CONSTRAINT fk_dhcp6_options_pd_pool
# Update the schema version number
UPDATE schema_version
-SET version = '9', minor = '2';
+ SET version = '9', minor = '2';
+
+# This line concludes the schema upgrade to version 9.2.
-# This line concludes database upgrade to version 9.2.
+# This line starts the schema upgrade to version 9.3.
# Fix stat_lease4_update trigger
DROP TRIGGER stat_lease4_update;
@@ -2978,9 +3002,11 @@ DELIMITER ;
# Update the schema version number
UPDATE schema_version
-SET version = '9', minor = '3';
+ SET version = '9', minor = '3';
+
+# This line concludes the schema upgrade to version 9.3.
-# This line concludes database upgrade to version 9.3.
+# This line starts the schema upgrade to version 9.4.
# Starting from this version we allow specifying multiple IP reservations
# for the same address in certain DHCP configurations. The server may check
@@ -3024,9 +3050,11 @@ ALTER TABLE dhcp6_options ADD CONSTRAINT fk_dhcp6_options_Host
# Update the schema version number
UPDATE schema_version
-SET version = '9', minor = '4';
+ SET version = '9', minor = '4';
-# This line concludes database upgrade to version 9.4.
+# This line concludes the schema upgrade to version 9.4.
+
+# This line starts the schema upgrade to version 9.5.
# Add new reservations flags.
ALTER TABLE dhcp4_subnet
@@ -3057,9 +3085,11 @@ ALTER TABLE dhcp6_shared_network DROP COLUMN reservation_mode;
# Update the schema version number
UPDATE schema_version
-SET version = '9', minor = '5';
+ SET version = '9', minor = '5';
+
+# This line concludes the schema upgrade to version 9.5.
-# This line concludes database upgrade to version 9.5.
+# This line starts the schema upgrade to version 9.6.
# Add new lease cache parameters.
ALTER TABLE dhcp4_subnet
@@ -3086,7 +3116,9 @@ ALTER TABLE logs
UPDATE schema_version
SET version = '9', minor = '6';
-# This line concludes database upgrade to version 9.6.
+# This line concludes the schema upgrade to version 9.6.
+
+# This line starts the schema upgrade to version 10.
-- -----------------------------------------------------------------------
-- Create a table holding the DHCPv4 client classes. Most table
@@ -4015,7 +4047,9 @@ ALTER TABLE dhcp6_option_def
UPDATE schema_version
SET version = '10', minor = '0';
-# This line concludes database upgrade to version 10.
+# This line concludes the schema upgrade to version 10.
+
+# This line starts the schema upgrade to version 11.
# Reverse index order to improve reclamation query performance
# Add a constraint that any state value added to the lease4 must
@@ -4045,7 +4079,9 @@ ALTER TABLE dhcp6_client_class
UPDATE schema_version
SET version = '11', minor = '0';
-# This line concludes database upgrade to version 11.
+# This line concludes the schema upgrade to version 11.
+
+# This line starts the schema upgrade to version 12.
# Ensure that dhcp_client_class is NULL when an option does not
# belong to any client class. Later, we will add foreign keys for
@@ -5066,7 +5102,6 @@ UPDATE schema_version
-- This line starts the schema upgrade to version 15.
-- Add cancelled (aka never-send) column to option tables.
-
ALTER TABLE dhcp4_options
ADD COLUMN cancelled TINYINT(1) NOT NULL DEFAULT 0;
@@ -5094,7 +5129,7 @@ UPDATE schema_version
-- Add relay and remote id columns to DHCPv4 leases.
--
-- Note: these columns are only used for indexes, in particular they are
--- not exported by lease4 dump as values are also in the user context
+-- not exported by lease4 dump as values are also in the user context
ALTER TABLE lease4
ADD COLUMN relay_id VARBINARY(128) DEFAULT NULL,
ADD COLUMN remote_id VARBINARY(128) DEFAULT NULL;
@@ -5129,6 +5164,148 @@ UPDATE schema_version
-- This line concludes the schema upgrade to version 17.
+-- This line starts the schema upgrade to version 18.
+
+-- Extend lease4 client_id to 255 bytes.
+ALTER TABLE lease4
+ MODIFY COLUMN client_id VARBINARY(255);
+
+-- Extend hosts dhcp_identifier to 255 bytes.
+ALTER TABLE hosts
+ MODIFY COLUMN dhcp_identifier VARBINARY(255) NOT NULL;
+
+-- Extend hosts relay_id to 255 bytes.
+ALTER TABLE lease4
+ MODIFY COLUMN relay_id VARBINARY(255) DEFAULT NULL;
+
+-- Extend hosts remote_id to 255 bytes.
+ALTER TABLE lease4
+ MODIFY COLUMN remote_id VARBINARY(255) DEFAULT NULL;
+
+-- Extend lease6 duid to 130 bytes.
+ALTER TABLE lease6
+ MODIFY COLUMN duid VARBINARY(130);
+
+UPDATE lease6 SET duid = UNHEX('000000') WHERE duid = UNHEX('00');
+
+-- Drop and create lease4Upload stored procedure with 255 bytes long client_id.
+DROP PROCEDURE IF EXISTS lease4Upload;
+
+-- Create a procedure that inserts a v4 lease from memfile data.
+DELIMITER $$
+CREATE PROCEDURE lease4Upload(
+ IN address VARCHAR(15),
+ IN hwaddr VARCHAR(20),
+ IN client_id VARCHAR(255),
+ IN valid_lifetime INT UNSIGNED,
+ IN expire BIGINT UNSIGNED,
+ IN subnet_id INT UNSIGNED,
+ IN fqdn_fwd TINYINT,
+ IN fqdn_rev TINYINT,
+ IN hostname VARCHAR(255),
+ IN state INT UNSIGNED,
+ IN user_context TEXT
+)
+BEGIN
+ INSERT INTO lease4 (
+ address,
+ hwaddr,
+ client_id,
+ valid_lifetime,
+ expire,
+ subnet_id,
+ fqdn_fwd,
+ fqdn_rev,
+ hostname,
+ state,
+ user_context
+ ) VALUES (
+ INET_ATON(address),
+ UNHEX(REPLACE(hwaddr, ':', '')),
+ UNHEX(REPLACE(client_id, ':', '')),
+ valid_lifetime,
+ FROM_UNIXTIME(expire),
+ subnet_id,
+ fqdn_fwd,
+ fqdn_rev,
+ REPLACE(hostname, '&#x2c', ','),
+ state,
+ REPLACE(user_context, '&#x2c', ',')
+ );
+END $$
+DELIMITER ;
+
+-- Drop and create lease6Upload stored procedure with 130 bytes long duid.
+DROP PROCEDURE IF EXISTS lease6Upload;
+
+-- Create a procedure that inserts a v6 lease from memfile data.
+DELIMITER $$
+CREATE PROCEDURE lease6Upload(
+ IN address VARCHAR(39),
+ IN duid VARCHAR(130),
+ IN valid_lifetime INT UNSIGNED,
+ IN expire BIGINT UNSIGNED,
+ IN subnet_id INT UNSIGNED,
+ IN pref_lifetime INT UNSIGNED,
+ IN lease_type TINYINT,
+ IN iaid INT UNSIGNED,
+ IN prefix_len TINYINT UNSIGNED,
+ IN fqdn_fwd TINYINT,
+ IN fqdn_rev TINYINT,
+ IN hostname VARCHAR(255),
+ IN hwaddr VARCHAR(64),
+ IN state INT UNSIGNED,
+ IN user_context TEXT,
+ IN hwtype SMALLINT,
+ IN hwaddr_source INT UNSIGNED
+)
+BEGIN
+ INSERT INTO lease6 (
+ address,
+ duid,
+ valid_lifetime,
+ expire,
+ subnet_id,
+ pref_lifetime,
+ lease_type,
+ iaid,
+ prefix_len,
+ fqdn_fwd,
+ fqdn_rev,
+ hostname,
+ hwaddr,
+ state,
+ user_context,
+ hwtype,
+ hwaddr_source
+ ) VALUES (
+ address,
+ UNHEX(REPLACE(duid, ':', '')),
+ valid_lifetime,
+ FROM_UNIXTIME(expire),
+ subnet_id,
+ pref_lifetime,
+ lease_type,
+ iaid,
+ prefix_len,
+ fqdn_fwd,
+ fqdn_rev,
+ REPLACE(hostname, '&#x2c', ','),
+ UNHEX(REPLACE(hwaddr, ':', '')),
+ state,
+ REPLACE(user_context, '&#x2c', ','),
+ hwtype,
+ hwaddr_source
+ );
+END $$
+DELIMITER ;
+
+-- Update the schema version number.
+UPDATE schema_version
+ SET version = '18', minor = '0';
+
+-- This line concludes the schema upgrade to version 18.
+
# Notes:
#
# Indexes
diff --git a/src/share/database/scripts/mysql/upgrade_001.0_to_002.0.sh.in b/src/share/database/scripts/mysql/upgrade_001.0_to_002.0.sh.in
index a5f8fe5f0e..a8d36ea614 100644
--- a/src/share/database/scripts/mysql/upgrade_001.0_to_002.0.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_001.0_to_002.0.sh.in
@@ -53,6 +53,10 @@ INSERT INTO lease_hwaddr_source VALUES (16, 'HWADDR_SOURCE_REMOTE_ID');
INSERT INTO lease_hwaddr_source VALUES (32, 'HWADDR_SOURCE_SUBSCRIBER_ID');
INSERT INTO lease_hwaddr_source VALUES (64, 'HWADDR_SOURCE_DOCSIS');
+# Update the schema version number
UPDATE schema_version
-SET version = '2', minor = '0';
+ SET version = '2', minor = '0';
+
+# This line concludes the schema upgrade to version 2.0.
+
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_002.0_to_003.0.sh.in b/src/share/database/scripts/mysql/upgrade_002.0_to_003.0.sh.in
index 60807a8685..0fcb1eb4fa 100644
--- a/src/share/database/scripts/mysql/upgrade_002.0_to_003.0.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_002.0_to_003.0.sh.in
@@ -35,74 +35,74 @@ fi
mysql "$@" <<EOF
CREATE TABLE IF NOT EXISTS hosts (
-host_id INT UNSIGNED NOT NULL AUTO_INCREMENT ,
-dhcp_identifier VARBINARY(128) NOT NULL ,
-dhcp_identifier_type TINYINT NOT NULL ,
-dhcp4_subnet_id INT UNSIGNED NULL ,
-dhcp6_subnet_id INT UNSIGNED NULL ,
-ipv4_address INT UNSIGNED NULL ,
-hostname VARCHAR(255) NULL ,
-dhcp4_client_classes VARCHAR(255) NULL ,
-dhcp6_client_classes VARCHAR(255) NULL ,
-PRIMARY KEY (host_id) ,
-INDEX key_dhcp4_identifier_subnet_id (dhcp_identifier ASC, dhcp_identifier_type ASC) ,
-INDEX key_dhcp6_identifier_subnet_id (dhcp_identifier ASC, dhcp_identifier_type ASC, dhcp6_subnet_id ASC)
+ host_id INT UNSIGNED NOT NULL AUTO_INCREMENT ,
+ dhcp_identifier VARBINARY(128) NOT NULL ,
+ dhcp_identifier_type TINYINT NOT NULL ,
+ dhcp4_subnet_id INT UNSIGNED NULL ,
+ dhcp6_subnet_id INT UNSIGNED NULL ,
+ ipv4_address INT UNSIGNED NULL ,
+ hostname VARCHAR(255) NULL ,
+ dhcp4_client_classes VARCHAR(255) NULL ,
+ dhcp6_client_classes VARCHAR(255) NULL ,
+ PRIMARY KEY (host_id) ,
+ INDEX key_dhcp4_identifier_subnet_id (dhcp_identifier ASC, dhcp_identifier_type ASC) ,
+ INDEX key_dhcp6_identifier_subnet_id (dhcp_identifier ASC, dhcp_identifier_type ASC, dhcp6_subnet_id ASC)
) ENGINE = INNODB;
CREATE TABLE IF NOT EXISTS ipv6_reservations (
-reservation_id INT NOT NULL AUTO_INCREMENT ,
-address VARCHAR(39) NOT NULL ,
-prefix_len TINYINT(3) UNSIGNED NOT NULL DEFAULT 128 ,
-type TINYINT(4) UNSIGNED NOT NULL DEFAULT 0 ,
-dhcp6_iaid INT UNSIGNED NULL ,
-host_id INT UNSIGNED NOT NULL ,
-PRIMARY KEY (reservation_id) ,
-INDEX fk_ipv6_reservations_host_idx (host_id ASC) ,
-CONSTRAINT fk_ipv6_reservations_Host
-FOREIGN KEY (host_id )
-REFERENCES hosts (host_id )
-ON DELETE NO ACTION
-ON UPDATE NO ACTION
+ reservation_id INT NOT NULL AUTO_INCREMENT ,
+ address VARCHAR(39) NOT NULL ,
+ prefix_len TINYINT(3) UNSIGNED NOT NULL DEFAULT 128 ,
+ type TINYINT(4) UNSIGNED NOT NULL DEFAULT 0 ,
+ dhcp6_iaid INT UNSIGNED NULL ,
+ host_id INT UNSIGNED NOT NULL ,
+ PRIMARY KEY (reservation_id) ,
+ INDEX fk_ipv6_reservations_host_idx (host_id ASC) ,
+ CONSTRAINT fk_ipv6_reservations_Host
+ FOREIGN KEY (host_id )
+ REFERENCES hosts (host_id )
+ ON DELETE NO ACTION
+ ON UPDATE NO ACTION
) ENGINE = INNODB;
CREATE TABLE IF NOT EXISTS dhcp4_options (
-option_id INT UNSIGNED NOT NULL AUTO_INCREMENT ,
-code TINYINT UNSIGNED NOT NULL ,
-value BLOB NULL ,
-formatted_value TEXT NULL ,
-space VARCHAR(128) NULL ,
-persistent TINYINT(1) NOT NULL DEFAULT 0 ,
-dhcp_client_class VARCHAR(128) NULL ,
-dhcp4_subnet_id INT NULL ,
-host_id INT UNSIGNED NULL ,
-PRIMARY KEY (option_id) ,
-UNIQUE INDEX option_id_UNIQUE (option_id ASC) ,
-INDEX fk_options_host1_idx (host_id ASC) ,
-CONSTRAINT fk_options_host1
-FOREIGN KEY (host_id )
-REFERENCES hosts (host_id )
-ON DELETE NO ACTION
-ON UPDATE NO ACTION
+ option_id INT UNSIGNED NOT NULL AUTO_INCREMENT ,
+ code TINYINT UNSIGNED NOT NULL ,
+ value BLOB NULL ,
+ formatted_value TEXT NULL ,
+ space VARCHAR(128) NULL ,
+ persistent TINYINT(1) NOT NULL DEFAULT 0 ,
+ dhcp_client_class VARCHAR(128) NULL ,
+ dhcp4_subnet_id INT NULL ,
+ host_id INT UNSIGNED NULL ,
+ PRIMARY KEY (option_id) ,
+ UNIQUE INDEX option_id_UNIQUE (option_id ASC) ,
+ INDEX fk_options_host1_idx (host_id ASC) ,
+ CONSTRAINT fk_options_host1
+ FOREIGN KEY (host_id )
+ REFERENCES hosts (host_id )
+ ON DELETE NO ACTION
+ ON UPDATE NO ACTION
) ENGINE = INNODB;
CREATE TABLE IF NOT EXISTS dhcp6_options (
-option_id INT UNSIGNED NOT NULL AUTO_INCREMENT ,
-code INT UNSIGNED NOT NULL ,
-value BLOB NULL ,
-formatted_value TEXT NULL ,
-space VARCHAR(128) NULL ,
-persistent TINYINT(1) NOT NULL DEFAULT 0 ,
-dhcp_client_class VARCHAR(128) NULL ,
-dhcp6_subnet_id INT NULL ,
-host_id INT UNSIGNED NULL ,
-PRIMARY KEY (option_id) ,
-UNIQUE INDEX option_id_UNIQUE (option_id ASC) ,
-INDEX fk_options_host1_idx (host_id ASC) ,
-CONSTRAINT fk_options_host10
-FOREIGN KEY (host_id )
-REFERENCES hosts (host_id )
-ON DELETE NO ACTION
-ON UPDATE NO ACTION
+ option_id INT UNSIGNED NOT NULL AUTO_INCREMENT ,
+ code INT UNSIGNED NOT NULL ,
+ value BLOB NULL ,
+ formatted_value TEXT NULL ,
+ space VARCHAR(128) NULL ,
+ persistent TINYINT(1) NOT NULL DEFAULT 0 ,
+ dhcp_client_class VARCHAR(128) NULL ,
+ dhcp6_subnet_id INT NULL ,
+ host_id INT UNSIGNED NULL ,
+ PRIMARY KEY (option_id) ,
+ UNIQUE INDEX option_id_UNIQUE (option_id ASC) ,
+ INDEX fk_options_host1_idx (host_id ASC) ,
+ CONSTRAINT fk_options_host10
+ FOREIGN KEY (host_id )
+ REFERENCES hosts (host_id )
+ ON DELETE NO ACTION
+ ON UPDATE NO ACTION
) ENGINE = INNODB;
DELIMITER $$
@@ -114,6 +114,10 @@ END
$$
DELIMITER ;
+# Update the schema version number
UPDATE schema_version
-SET version = '3', minor = '0';
+ SET version = '3', minor = '0';
+
+# This line concludes the schema upgrade to version 3.0.
+
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_003.0_to_004.0.sh.in b/src/share/database/scripts/mysql/upgrade_003.0_to_004.0.sh.in
index 7c4296a95f..d7895389b0 100644
--- a/src/share/database/scripts/mysql/upgrade_003.0_to_004.0.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_003.0_to_004.0.sh.in
@@ -168,6 +168,8 @@ DELIMITER ;
# Update the schema version number
UPDATE schema_version
-SET version = '4', minor = '0';
-# This line concludes database upgrade to version 4.0.
+ SET version = '4', minor = '0';
+
+# This line concludes the schema upgrade to version 4.0.
+
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_004.0_to_004.1.sh.in b/src/share/database/scripts/mysql/upgrade_004.0_to_004.1.sh.in
index 8e14a574c8..e654bddf19 100644
--- a/src/share/database/scripts/mysql/upgrade_004.0_to_004.1.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_004.0_to_004.1.sh.in
@@ -98,7 +98,8 @@ DELIMITER ;
# Update the schema version number
UPDATE schema_version
-SET version = '4', minor = '1';
-# This line concludes database upgrade to version 4.1.
+ SET version = '4', minor = '1';
+
+# This line concludes the schema upgrade to version 4.1.
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_004.1_to_005.0.sh.in b/src/share/database/scripts/mysql/upgrade_004.1_to_005.0.sh.in
index e9a6d37a88..b2ae2b4281 100644
--- a/src/share/database/scripts/mysql/upgrade_004.1_to_005.0.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_004.1_to_005.0.sh.in
@@ -122,7 +122,8 @@ ALTER TABLE hosts ADD COLUMN dhcp4_boot_file_name VARCHAR(128) NULL;
# Update the schema version number
UPDATE schema_version
-SET version = '5', minor = '0';
-# This line concludes database upgrade to version 5.0.
+ SET version = '5', minor = '0';
+
+# This line concludes the schema upgrade to version 5.0.
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_005.0_to_005.1.sh.in b/src/share/database/scripts/mysql/upgrade_005.0_to_005.1.sh.in
index f18215675a..018d9e0477 100644
--- a/src/share/database/scripts/mysql/upgrade_005.0_to_005.1.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_005.0_to_005.1.sh.in
@@ -55,7 +55,8 @@ DELIMITER ;
# Update the schema version number
UPDATE schema_version
-SET version = '5', minor = '1';
-# This line concludes database upgrade to version 5.1.
+ SET version = '5', minor = '1';
+
+# This line concludes the schema upgrade to version 5.1.
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_005.1_to_005.2.sh.in b/src/share/database/scripts/mysql/upgrade_005.1_to_005.2.sh.in
index 25c15d2b18..2d6b0b032f 100644
--- a/src/share/database/scripts/mysql/upgrade_005.1_to_005.2.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_005.1_to_005.2.sh.in
@@ -41,7 +41,8 @@ ALTER TABLE dhcp6_options MODIFY dhcp6_subnet_id INT UNSIGNED;
# Update the schema version number
UPDATE schema_version
-SET version = '5', minor = '2';
-# This line concludes database upgrade to version 5.2.
+ SET version = '5', minor = '2';
+
+# This line concludes the schema upgrade to version 5.2.
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_005.2_to_006.0.sh.in b/src/share/database/scripts/mysql/upgrade_005.2_to_006.0.sh.in
index d69d33991f..1b685c1b92 100644
--- a/src/share/database/scripts/mysql/upgrade_005.2_to_006.0.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_005.2_to_006.0.sh.in
@@ -210,7 +210,8 @@ INSERT INTO lease6_stat (subnet_id, lease_type, state, leases)
# Update the schema version number
UPDATE schema_version
-SET version = '6', minor = '0';
-# This line concludes database upgrade to version 6.0.
+ SET version = '6', minor = '0';
+
+# This line concludes the schema upgrade to version 6.0.
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_006.0_to_007.0.sh.in b/src/share/database/scripts/mysql/upgrade_006.0_to_007.0.sh.in
index 1e19e88e5f..7710b49d9e 100644
--- a/src/share/database/scripts/mysql/upgrade_006.0_to_007.0.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_006.0_to_007.0.sh.in
@@ -361,7 +361,6 @@ CREATE TABLE IF NOT EXISTS dhcp4_subnet_server (
ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB;
-
# Modify the primary key to BINGINT as other tables have.
#
ALTER TABLE dhcp4_options MODIFY option_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT;
@@ -657,8 +656,8 @@ DELIMITER ;
# Update the schema version number
UPDATE schema_version
-SET version = '7', minor = '0';
+ SET version = '7', minor = '0';
-# This line concludes database upgrade to version 7.0.
+# This line concludes the schema upgrade to version 7.0.
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_007.0_to_008.0.sh.in b/src/share/database/scripts/mysql/upgrade_007.0_to_008.0.sh.in
index 5488795369..8608dafb96 100644
--- a/src/share/database/scripts/mysql/upgrade_007.0_to_008.0.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_007.0_to_008.0.sh.in
@@ -35,7 +35,6 @@ fi
mysql "$@" <<EOF
-
ALTER TABLE dhcp4_options
MODIFY COLUMN modification_ts TIMESTAMP NOT NULL
DEFAULT CURRENT_TIMESTAMP;
@@ -570,7 +569,6 @@ ALTER TABLE dhcp6_global_parameter
ADD CONSTRAINT fk_dhcp6_global_parameter_type FOREIGN KEY (parameter_type)
REFERENCES parameter_data_type (id);
-
-- Rename dhcp6_subnet_id column of dhcp6_pool and dhcp6_pd_pool
ALTER TABLE dhcp6_pool
@@ -989,8 +987,8 @@ DELIMITER ;
# Update the schema version number
UPDATE schema_version
-SET version = '8', minor = '0';
+ SET version = '8', minor = '0';
-# This line concludes database upgrade to version 8.0.
+# This line concludes the schema upgrade to version 8.0.
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_008.0_to_008.1.sh.in b/src/share/database/scripts/mysql/upgrade_008.0_to_008.1.sh.in
index 817b186ef5..14d4f46a3a 100644
--- a/src/share/database/scripts/mysql/upgrade_008.0_to_008.1.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_008.0_to_008.1.sh.in
@@ -116,8 +116,8 @@ ALTER TABLE hosts
# Update the schema version number
UPDATE schema_version
-SET version = '8', minor = '1';
+ SET version = '8', minor = '1';
-# This line concludes database upgrade to version 8.1.
+# This line concludes the schema upgrade to version 8.1.
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_008.1_to_008.2.sh.in b/src/share/database/scripts/mysql/upgrade_008.1_to_008.2.sh.in
index f47d6f1fec..e4e3cdbbb7 100644
--- a/src/share/database/scripts/mysql/upgrade_008.1_to_008.2.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_008.1_to_008.2.sh.in
@@ -340,7 +340,6 @@ CREATE TRIGGER dhcp4_options_ADEL AFTER DELETE ON dhcp4_options
END $$
DELIMITER ;
-
-- -----------------------------------------------------
--
-- New version of the createOptionAuditDHCP4 stored
@@ -488,9 +487,9 @@ DELIMITER ;
# Update the schema version number
UPDATE schema_version
-SET version = '8', minor = '2';
+ SET version = '8', minor = '2';
-# This line concludes database upgrade to version 8.2.
+# This line concludes the schema upgrade to version 8.2.
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_008.2_to_009.0.sh.in b/src/share/database/scripts/mysql/upgrade_008.2_to_009.0.sh.in
index 220ff5922e..bdf2e4e2c5 100644
--- a/src/share/database/scripts/mysql/upgrade_008.2_to_009.0.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_008.2_to_009.0.sh.in
@@ -54,8 +54,8 @@ CREATE INDEX lease6_by_hostname ON lease6 (hostname);
# Update the schema version number
UPDATE schema_version
-SET version = '9', minor = '0';
+ SET version = '9', minor = '0';
-# This line concludes database upgrade to version 9.0.
+# This line concludes the schema upgrade to version 9.0.
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_009.0_to_009.1.sh.in b/src/share/database/scripts/mysql/upgrade_009.0_to_009.1.sh.in
index 75f6832e01..139893b100 100644
--- a/src/share/database/scripts/mysql/upgrade_009.0_to_009.1.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_009.0_to_009.1.sh.in
@@ -70,8 +70,8 @@ ALTER TABLE dhcp6_subnet
# Update the schema version number
UPDATE schema_version
-SET version = '9', minor = '1';
+ SET version = '9', minor = '1';
-# This line concludes database upgrade to version 9.1.
+# This line concludes the schema upgrade to version 9.1.
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_009.1_to_009.2.sh.in b/src/share/database/scripts/mysql/upgrade_009.1_to_009.2.sh.in
index 61f81fd591..3fff88c76e 100644
--- a/src/share/database/scripts/mysql/upgrade_009.1_to_009.2.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_009.1_to_009.2.sh.in
@@ -74,8 +74,8 @@ ALTER TABLE dhcp6_options ADD CONSTRAINT fk_dhcp6_options_pd_pool
# Update the schema version number
UPDATE schema_version
-SET version = '9', minor = '2';
+ SET version = '9', minor = '2';
-# This line concludes database upgrade to version 9.2.
+# This line concludes the schema upgrade to version 9.2.
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_009.2_to_009.3.sh.in b/src/share/database/scripts/mysql/upgrade_009.2_to_009.3.sh.in
index 1cf5af6bb3..e9169c11c5 100644
--- a/src/share/database/scripts/mysql/upgrade_009.2_to_009.3.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_009.2_to_009.3.sh.in
@@ -133,8 +133,8 @@ DELIMITER ;
# Update the schema version number
UPDATE schema_version
-SET version = '9', minor = '3';
+ SET version = '9', minor = '3';
-# This line concludes database upgrade to version 9.3.
+# This line concludes the schema upgrade to version 9.3.
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_009.3_to_009.4.sh.in b/src/share/database/scripts/mysql/upgrade_009.3_to_009.4.sh.in
index 6bf1452f1d..269e4afe7b 100644
--- a/src/share/database/scripts/mysql/upgrade_009.3_to_009.4.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_009.3_to_009.4.sh.in
@@ -77,8 +77,8 @@ ALTER TABLE dhcp6_options ADD CONSTRAINT fk_dhcp6_options_Host
# Update the schema version number
UPDATE schema_version
-SET version = '9', minor = '4';
+ SET version = '9', minor = '4';
-# This line concludes database upgrade to version 9.4.
+# This line concludes the schema upgrade to version 9.4.
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_009.4_to_009.5.sh.in b/src/share/database/scripts/mysql/upgrade_009.4_to_009.5.sh.in
index 77d03b09c9..9ef28f6f52 100644
--- a/src/share/database/scripts/mysql/upgrade_009.4_to_009.5.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_009.4_to_009.5.sh.in
@@ -163,8 +163,8 @@ SET @disable_audit = 0;
# Update the schema version number
UPDATE schema_version
-SET version = '9', minor = '5';
+ SET version = '9', minor = '5';
-# This line concludes database upgrade to version 9.5.
+# This line concludes the schema upgrade to version 9.5.
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_009.5_to_009.6.sh.in b/src/share/database/scripts/mysql/upgrade_009.5_to_009.6.sh.in
index 8b720559a4..d97335b6cd 100644
--- a/src/share/database/scripts/mysql/upgrade_009.5_to_009.6.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_009.5_to_009.6.sh.in
@@ -66,5 +66,6 @@ ALTER TABLE logs
UPDATE schema_version
SET version = '9', minor = '6';
-# This line concludes database upgrade to version 9.6.
+# This line concludes the schema upgrade to version 9.6.
+
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_009.6_to_010.0.sh.in b/src/share/database/scripts/mysql/upgrade_009.6_to_010.0.sh.in
index 12edfa79c4..937ff22bdb 100644
--- a/src/share/database/scripts/mysql/upgrade_009.6_to_010.0.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_009.6_to_010.0.sh.in
@@ -1025,5 +1025,6 @@ ALTER TABLE dhcp6_option_def
UPDATE schema_version
SET version = '10', minor = '0';
-# This line concludes database upgrade to version 10.
+# This line concludes the schema upgrade to version 10.
+
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_010_to_011.sh.in b/src/share/database/scripts/mysql/upgrade_010_to_011.sh.in
index 5a3312a23e..7351e6ec56 100644
--- a/src/share/database/scripts/mysql/upgrade_010_to_011.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_010_to_011.sh.in
@@ -81,5 +81,6 @@ ALTER TABLE dhcp6_client_class
UPDATE schema_version
SET version = '11', minor = '0';
--- This line concludes database upgrade to version 11.0
+-- This line concludes the schema upgrade to version 11.0
+
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_011_to_012.sh.in b/src/share/database/scripts/mysql/upgrade_011_to_012.sh.in
index 71e0633114..b591d6c741 100644
--- a/src/share/database/scripts/mysql/upgrade_011_to_012.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_011_to_012.sh.in
@@ -83,5 +83,6 @@ ALTER TABLE dhcp6_options
UPDATE schema_version
SET version = '12', minor = '0';
--- This line concludes database upgrade to version 12.
+-- This line concludes the schema upgrade to version 12.
+
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_012_to_013.sh.in b/src/share/database/scripts/mysql/upgrade_012_to_013.sh.in
index 30e8c87eab..76969bb08d 100644
--- a/src/share/database/scripts/mysql/upgrade_012_to_013.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_012_to_013.sh.in
@@ -261,5 +261,6 @@ DELIMITER ;
UPDATE schema_version
SET version = '13', minor = '0';
--- This line concludes database upgrade to version 13.
+-- This line concludes the schema upgrade to version 13.
+
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_013_to_014.sh.in b/src/share/database/scripts/mysql/upgrade_013_to_014.sh.in
index 9688639f4c..c897517485 100644
--- a/src/share/database/scripts/mysql/upgrade_013_to_014.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_013_to_014.sh.in
@@ -52,7 +52,6 @@ then
fi
mysql "$@" <<EOF
--- This line starts the schema upgrade to version 14.
-- Modify shared-network-name foreign key constraint on dhcp4_subnet to not perform
-- the update when the network is deleted the cascaded update will not execute
@@ -823,4 +822,5 @@ UPDATE schema_version
SET version = '14', minor = '0';
-- This line concludes the schema upgrade to version 14.
+
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_014_to_015.sh.in b/src/share/database/scripts/mysql/upgrade_014_to_015.sh.in
index 3bc0afde19..bc58082dad 100644
--- a/src/share/database/scripts/mysql/upgrade_014_to_015.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_014_to_015.sh.in
@@ -55,7 +55,6 @@ mysql "$@" <<EOF
-- This line starts the schema upgrade to version 15.
-- Add cancelled (aka never-send) column to option tables.
-
ALTER TABLE dhcp4_options
ADD COLUMN cancelled TINYINT(1) NOT NULL DEFAULT 0;
@@ -77,4 +76,5 @@ UPDATE schema_version
SET version = '15', minor = '0';
-- This line concludes the schema upgrade to version 15.
+
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_015_to_016.sh.in b/src/share/database/scripts/mysql/upgrade_015_to_016.sh.in
index fe89202c76..c2969e3a4b 100644
--- a/src/share/database/scripts/mysql/upgrade_015_to_016.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_015_to_016.sh.in
@@ -57,7 +57,7 @@ mysql "$@" <<EOF
-- Add relay and remote id columns to DHCPv4 leases.
--
-- Note: these columns are only used for indexes, in particular they are
--- not exported by lease4 dump as values are also in the user context
+-- not exported by lease4 dump as values are also in the user context
ALTER TABLE lease4
ADD COLUMN relay_id VARBINARY(128) DEFAULT NULL,
ADD COLUMN remote_id VARBINARY(128) DEFAULT NULL;
@@ -71,4 +71,5 @@ UPDATE schema_version
SET version = '16', minor = '0';
-- This line concludes the schema upgrade to version 16.
+
EOF
diff --git a/src/share/database/scripts/mysql/upgrade_016_to_017.sh.in b/src/share/database/scripts/mysql/upgrade_016_to_017.sh.in
index 31e4e1a30f..8a44660301 100644
--- a/src/share/database/scripts/mysql/upgrade_016_to_017.sh.in
+++ b/src/share/database/scripts/mysql/upgrade_016_to_017.sh.in
@@ -66,9 +66,144 @@ ALTER TABLE dhcp6_subnet ADD COLUMN pd_allocator TEXT NULL;
ALTER TABLE dhcp6_shared_network ADD COLUMN allocator TEXT NULL;
ALTER TABLE dhcp6_shared_network ADD COLUMN pd_allocator TEXT NULL;
+-- Extend lease4 client_id to 255 bytes.
+ALTER TABLE lease4
+ MODIFY COLUMN client_id VARBINARY(255);
+
+-- Extend hosts dhcp_identifier to 255 bytes.
+ALTER TABLE hosts
+ MODIFY COLUMN dhcp_identifier VARBINARY(255) NOT NULL;
+
+-- Extend hosts relay_id to 255 bytes.
+ALTER TABLE lease4
+ MODIFY COLUMN relay_id VARBINARY(255) DEFAULT NULL;
+
+-- Extend hosts remote_id to 255 bytes.
+ALTER TABLE lease4
+ MODIFY COLUMN remote_id VARBINARY(255) DEFAULT NULL;
+
+-- Extend lease6 duid to 130 bytes.
+ALTER TABLE lease6
+ MODIFY COLUMN duid VARBINARY(130);
+
+UPDATE lease6 SET duid = UNHEX('000000') WHERE duid = UNHEX('00');
+
+-- Drop and create lease4Upload stored procedure with 255 bytes long client_id.
+DROP PROCEDURE IF EXISTS lease4Upload;
+
+-- Create a procedure that inserts a v4 lease from memfile data.
+DELIMITER $$
+CREATE PROCEDURE lease4Upload(
+ IN address VARCHAR(15),
+ IN hwaddr VARCHAR(20),
+ IN client_id VARCHAR(255),
+ IN valid_lifetime INT UNSIGNED,
+ IN expire BIGINT UNSIGNED,
+ IN subnet_id INT UNSIGNED,
+ IN fqdn_fwd TINYINT,
+ IN fqdn_rev TINYINT,
+ IN hostname VARCHAR(255),
+ IN state INT UNSIGNED,
+ IN user_context TEXT
+)
+BEGIN
+ INSERT INTO lease4 (
+ address,
+ hwaddr,
+ client_id,
+ valid_lifetime,
+ expire,
+ subnet_id,
+ fqdn_fwd,
+ fqdn_rev,
+ hostname,
+ state,
+ user_context
+ ) VALUES (
+ INET_ATON(address),
+ UNHEX(REPLACE(hwaddr, ':', '')),
+ UNHEX(REPLACE(client_id, ':', '')),
+ valid_lifetime,
+ FROM_UNIXTIME(expire),
+ subnet_id,
+ fqdn_fwd,
+ fqdn_rev,
+ REPLACE(hostname, '&#x2c', ','),
+ state,
+ REPLACE(user_context, '&#x2c', ',')
+ );
+END $$
+DELIMITER ;
+
+-- Drop and create lease6Upload stored procedure with 130 bytes long duid.
+DROP PROCEDURE IF EXISTS lease6Upload;
+
+-- Create a procedure that inserts a v6 lease from memfile data.
+DELIMITER $$
+CREATE PROCEDURE lease6Upload(
+ IN address VARCHAR(39),
+ IN duid VARCHAR(130),
+ IN valid_lifetime INT UNSIGNED,
+ IN expire BIGINT UNSIGNED,
+ IN subnet_id INT UNSIGNED,
+ IN pref_lifetime INT UNSIGNED,
+ IN lease_type TINYINT,
+ IN iaid INT UNSIGNED,
+ IN prefix_len TINYINT UNSIGNED,
+ IN fqdn_fwd TINYINT,
+ IN fqdn_rev TINYINT,
+ IN hostname VARCHAR(255),
+ IN hwaddr VARCHAR(64),
+ IN state INT UNSIGNED,
+ IN user_context TEXT,
+ IN hwtype SMALLINT,
+ IN hwaddr_source INT UNSIGNED
+)
+BEGIN
+ INSERT INTO lease6 (
+ address,
+ duid,
+ valid_lifetime,
+ expire,
+ subnet_id,
+ pref_lifetime,
+ lease_type,
+ iaid,
+ prefix_len,
+ fqdn_fwd,
+ fqdn_rev,
+ hostname,
+ hwaddr,
+ state,
+ user_context,
+ hwtype,
+ hwaddr_source
+ ) VALUES (
+ address,
+ UNHEX(REPLACE(duid, ':', '')),
+ valid_lifetime,
+ FROM_UNIXTIME(expire),
+ subnet_id,
+ pref_lifetime,
+ lease_type,
+ iaid,
+ prefix_len,
+ fqdn_fwd,
+ fqdn_rev,
+ REPLACE(hostname, '&#x2c', ','),
+ UNHEX(REPLACE(hwaddr, ':', '')),
+ state,
+ REPLACE(user_context, '&#x2c', ','),
+ hwtype,
+ hwaddr_source
+ );
+END $$
+DELIMITER ;
+
-- Update the schema version number.
UPDATE schema_version
SET version = '17', minor = '0';
-- This line concludes the schema upgrade to version 17.
+
EOF
diff --git a/src/share/database/scripts/pgsql/dhcpdb_create.pgsql b/src/share/database/scripts/pgsql/dhcpdb_create.pgsql
index f172b5169c..7aa29edeee 100644
--- a/src/share/database/scripts/pgsql/dhcpdb_create.pgsql
+++ b/src/share/database/scripts/pgsql/dhcpdb_create.pgsql
@@ -88,9 +88,7 @@ CREATE TABLE schema_version (
INSERT INTO schema_version VALUES (1, 0);
---
--- Schema 2.0 specification starts here.
---
+-- Upgrade to schema 2.0 begins here:
-- Add state column to the lease4 table.
ALTER TABLE lease4
@@ -635,7 +633,6 @@ CREATE TRIGGER stat_lease4_update
AFTER UPDATE ON lease4
FOR EACH ROW EXECUTE PROCEDURE proc_stat_lease4_update();
-
--
-- Create the v4 delete trigger procedure
CREATE OR REPLACE FUNCTION proc_stat_lease4_delete() RETURNS trigger AS $stat_lease4_delete$
@@ -870,7 +867,7 @@ CREATE INDEX address_id ON logs (address);
-- Create auth_key in hosts table for storing keys for DHCPv6 reconfigure.
ALTER TABLE hosts ADD COLUMN auth_key VARCHAR(16) DEFAULT NULL;
--- Set schema 5.0 version
+-- Set schema 5.0 version.
UPDATE schema_version
SET version = '5', minor = '0';
@@ -881,7 +878,7 @@ UPDATE schema_version
-- Put the auth key in hexadecimal (double size but far more user friendly).
ALTER TABLE hosts ALTER COLUMN auth_key TYPE VARCHAR(32);
--- Set schema 5.1 version
+-- Set schema 5.1 version.
UPDATE schema_version
SET version = '5', minor = '1';
@@ -1005,6 +1002,8 @@ UPDATE schema_version
-- Schema 6.1 specification ends here.
+-- Upgrade to schema 6.2 begins here:
+
-- Starting from this version we allow specifying multiple IP reservations
-- for the same address in certain DHCP configurations. The server may check
-- uniqueness of the IP addresses on its own. This is no longer checked at
@@ -1023,14 +1022,15 @@ ALTER TABLE ipv6_reservations DROP CONSTRAINT IF EXISTS key_dhcp6_address_prefix
CREATE INDEX key_dhcp6_address_prefix_len
ON ipv6_reservations (address ASC, prefix_len ASC);
--- Update the schema version number
+-- Set schema 6.2 version.
UPDATE schema_version
SET version = '6', minor = '2';
-- Schema 6.2 specification ends here.
--- This starts schema update to 7.0. It adds a lot (20+) of tables for the config backend.
+-- Upgrade to schema 7.0 begins here:
+-- Add a lot (20+) of tables for the config backend.
-- Adding on update trigger in MySQL is as easy as using this column definition in CREATE TABLE:
-- modification_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
@@ -1049,7 +1049,6 @@ CREATE OR REPLACE FUNCTION modification_ts_update()
-- Second, we need to specify which language it was written in.
$modification_ts_update$ LANGUAGE plpgsql;
-
-- Create table modification and insert values for modification types.
CREATE TABLE modification (
id smallint NOT NULL,
@@ -1058,8 +1057,6 @@ CREATE TABLE modification (
);
INSERT INTO modification VALUES (0,'create'), (1,'update'), (2,'delete');
-
-
-- Now create the table that holds different parameter data types.
CREATE TABLE parameter_data_type (
id smallint NOT NULL,
@@ -1072,8 +1069,6 @@ INSERT INTO parameter_data_type VALUES
(2,'boolean'),
(4,'string');
-
-
-- This table doesn't exist in MySQL. However, it's nice to have an enum that explains what the values
-- in ddns_replace_client_name field in the dhcp{4,6}_shared_network table means.
CREATE TABLE ddns_replace_client_name_types (
@@ -1087,8 +1082,6 @@ INSERT INTO ddns_replace_client_name_types (type, name) VALUES
(2, 'RCM_WHEN_PRESENT'),
(3, 'RCM_WHEN_NOT_PRESENT');
-
-
-- Create table for DHCPv6 servers
CREATE TABLE dhcp6_server (
id SERIAL PRIMARY KEY NOT NULL,
@@ -1148,8 +1141,6 @@ CREATE TRIGGER dhcp6_shared_network_modification_ts_update
AFTER UPDATE ON dhcp6_shared_network
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-
-- Now we need to create a relationship between defined shared networks and the servers
CREATE TABLE dhcp6_shared_network_server (
shared_network_id BIGINT NOT NULL,
@@ -1212,8 +1203,6 @@ CREATE TRIGGER dhcp6_subnet_modification_ts_update
CREATE INDEX dhcp6_subnet_idx1 ON dhcp6_subnet (modification_ts);
CREATE INDEX dhcp6_subnet_idx2 ON dhcp6_subnet (shared_network_name);
-
-
-- Create a table that holds all address pools in IPv6.
CREATE TABLE dhcp6_pool (
id SERIAL PRIMARY KEY NOT NULL,
@@ -1233,7 +1222,6 @@ CREATE TRIGGER dhcp6_pool_modification_ts_update
AFTER UPDATE ON dhcp6_pool
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-- And now the same, but for PD pools.
CREATE TABLE dhcp6_pd_pool (
id SERIAL PRIMARY KEY NOT NULL,
@@ -1256,8 +1244,6 @@ CREATE TRIGGER dhcp6_pd_pool_modification_ts_update
AFTER UPDATE ON dhcp6_pd_pool
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-
CREATE TABLE dhcp6_subnet_server (
subnet_id BIGINT NOT NULL,
server_id BIGINT NOT NULL,
@@ -1275,8 +1261,6 @@ CREATE TRIGGER dhcp6_subnet_server_modification_ts_update
AFTER UPDATE ON dhcp6_subnet_server
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-
-- Create table for storing global DHCPv6 parameters.
CREATE TABLE dhcp6_global_parameter (
id SERIAL PRIMARY KEY NOT NULL,
@@ -1294,7 +1278,6 @@ CREATE TRIGGER dhcp6_global_parameter_modification_ts_update
AFTER UPDATE ON dhcp6_global_parameter
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
CREATE TABLE dhcp6_global_parameter_server (
parameter_id BIGINT NOT NULL,
server_id BIGINT NOT NULL,
@@ -1311,7 +1294,6 @@ CREATE TRIGGER dhcp6_global_parameter_server_modification_ts_update
AFTER UPDATE ON dhcp6_global_parameter_server
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-- Alter table for storing DHCPv6 options.
ALTER TABLE dhcp6_options
ADD COLUMN shared_network_name VARCHAR(128) DEFAULT NULL,
@@ -1346,8 +1328,6 @@ CREATE TRIGGER dhcp6_options_server_modification_ts_update
AFTER UPDATE ON dhcp6_options_server
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-
-- This table is for storing IPv6 option definitions
CREATE TABLE dhcp6_option_def (
id SERIAL PRIMARY KEY UNIQUE NOT NULL,
@@ -1367,7 +1347,6 @@ CREATE TRIGGER dhcp6_option_def_modification_ts_update
AFTER UPDATE ON dhcp6_option_def
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-- and another table for storing relationship between option definitions and servers.
CREATE TABLE dhcp6_option_def_server (
option_def_id BIGINT NOT NULL REFERENCES dhcp6_option_def (id) ON DELETE CASCADE ON UPDATE NO ACTION,
@@ -1379,7 +1358,6 @@ CREATE TRIGGER dhcp6_option_def_server_modification_ts_update
AFTER UPDATE ON dhcp6_option_def_server
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-- Now create two tables for audit revisions...
CREATE TABLE dhcp6_audit_revision (
id SERIAL PRIMARY KEY NOT NULL,
@@ -1391,7 +1369,6 @@ CREATE TRIGGER dhcp6_audit_revision_modification_ts_update
AFTER UPDATE ON dhcp6_audit_revision
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-- ... and the DHCPv6 audit itself.
CREATE TABLE dhcp6_audit (
id SERIAL UNIQUE NOT NULL,
@@ -1410,7 +1387,6 @@ CREATE TRIGGER dhcp6_audit_modification_ts_update
CREATE INDEX dhcp6_audit_idx1 ON dhcp6_audit (modification_type);
CREATE INDEX dhcp6_audit_idx2 ON dhcp6_audit (revision_id);
-
-- Create table for DHCPv4 servers
CREATE TABLE dhcp4_server (
id SERIAL PRIMARY KEY NOT NULL,
@@ -1458,7 +1434,6 @@ CREATE TRIGGER dhcp4_global_parameter_server_modification_ts_update
AFTER UPDATE ON dhcp4_global_parameter_server
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-- Create a table for storing IPv4 shared networks
CREATE TABLE dhcp4_shared_network (
id SERIAL PRIMARY KEY NOT NULL,
@@ -1504,8 +1479,6 @@ CREATE TRIGGER dhcp4_shared_network_modification_ts_update
AFTER UPDATE ON dhcp4_shared_network
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-
-- Now we need to create a relationship between defined shared networks and the servers
CREATE TABLE dhcp4_shared_network_server (
shared_network_id BIGINT NOT NULL,
@@ -1520,8 +1493,6 @@ CREATE TABLE dhcp4_shared_network_server (
CREATE INDEX dhcp4_shared_network_server_idx1 ON dhcp4_shared_network_server (modification_ts);
CREATE INDEX dhcp4_shared_network_server_idx2 ON dhcp4_shared_network_server (server_id);
-
-
-- Create a list of IPv4 subnets
CREATE TABLE dhcp4_subnet (
subnet_id BIGINT PRIMARY KEY NOT NULL,
@@ -1573,8 +1544,6 @@ CREATE TRIGGER dhcp4_subnet_modification_ts_update
CREATE INDEX dhcp4_subnet_idx1 ON dhcp4_subnet (modification_ts);
CREATE INDEX dhcp4_subnet_idx2 ON dhcp4_subnet (shared_network_name);
-
-
CREATE TABLE dhcp4_subnet_server (
subnet_id BIGINT NOT NULL,
server_id BIGINT NOT NULL,
@@ -1592,8 +1561,6 @@ CREATE TRIGGER dhcp4_subnet_server_modification_ts_update
AFTER UPDATE ON dhcp4_subnet_server
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-
-- Create a table that holds all address pools in IPv4.
CREATE TABLE dhcp4_pool (
id SERIAL PRIMARY KEY NOT NULL,
@@ -1613,7 +1580,6 @@ CREATE TRIGGER dhcp4_pool_modification_ts_update
AFTER UPDATE ON dhcp4_pool
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-- ALTER table for storing DHCPv4 options.
ALTER TABLE dhcp4_options
ADD COLUMN shared_network_name VARCHAR(128) DEFAULT NULL,
@@ -1628,8 +1594,6 @@ CREATE TRIGGER dhcp4_options_modification_ts_update
AFTER UPDATE ON dhcp4_options
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-
-- Now create a table for associating defined v4 options with servers.
CREATE TABLE dhcp4_options_server (
option_id BIGINT NOT NULL,
@@ -1647,8 +1611,6 @@ CREATE TRIGGER dhcp4_options_server_modification_ts_update
AFTER UPDATE ON dhcp4_options_server
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-
-- This table is for storing IPv4 option definitions
CREATE TABLE dhcp4_option_def (
id SERIAL PRIMARY KEY UNIQUE NOT NULL,
@@ -1668,7 +1630,6 @@ CREATE TRIGGER dhcp4_option_def_modification_ts_update
AFTER UPDATE ON dhcp4_option_def
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-- and another table for storing relationship between option definitions and servers.
CREATE TABLE dhcp4_option_def_server (
option_def_id BIGINT NOT NULL REFERENCES dhcp6_option_def (id) ON DELETE CASCADE ON UPDATE NO ACTION,
@@ -1680,8 +1641,6 @@ CREATE TRIGGER dhcp4_option_def_server_modification_ts_update
AFTER UPDATE ON dhcp4_option_def_server
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-
-- Now create two tables for audit revisions...
CREATE TABLE dhcp4_audit_revision (
id SERIAL PRIMARY KEY NOT NULL,
@@ -1693,7 +1652,6 @@ CREATE TRIGGER dhcp4_audit_revision_modification_ts_update
AFTER UPDATE ON dhcp4_audit_revision
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-- ... and the DHCPv4 audit itself.
CREATE TABLE dhcp4_audit (
id SERIAL UNIQUE NOT NULL,
@@ -1712,7 +1670,6 @@ CREATE TRIGGER dhcp4_audit_modification_ts_update
CREATE INDEX dhcp4_audit_idx1 ON dhcp4_audit (modification_type);
CREATE INDEX dhcp4_audit_idx2 ON dhcp4_audit (revision_id);
-
-- Stores a TEXT value to a session variable
-- name name of session variable to set
-- value TEXT value to store
@@ -1766,7 +1723,6 @@ BEGIN
END;$$
LANGUAGE plpgsql;
-
-- Fetches a text value from the session configuration.
-- param name name of the session variable to fetch
-- If the name is not found it returns NULL.
@@ -1841,7 +1797,6 @@ BEGIN
END;$$
LANGUAGE plpgsql;
-
-- -----------------------------------------------------
-- Stored procedure which creates a new entry in the
-- dhcp4_audit_revision table and sets appropriate session
@@ -2008,7 +1963,6 @@ CREATE TABLE IF NOT EXISTS dhcp4_client_class_order (
CREATE INDEX key_dhcp4_client_class_order_index on dhcp4_client_class_order (order_index);
-
-- -----------------------------------------------------------------------
-- Stored procedure positioning an inserted or updated client class
-- within the class hierarchy, depending on the value of the
@@ -2303,7 +2257,6 @@ BEGIN
RETURN;
END;$$;
-
-- -----------------------------------------------------------------------
-- Trigger verifying if class dependency is met. It includes checking
-- if referenced classes exist, are associated with the same server
@@ -2908,7 +2861,6 @@ BEGIN
RETURN;
END;$$;
-
-- -----------------------------------------------------------------------
-- Trigger verifying if class dependency is met. It includes checking
-- if referenced classes exist, are associated with the same server
@@ -3098,7 +3050,6 @@ CREATE TRIGGER dhcp4_global_parameter_AINS
AFTER INSERT ON dhcp4_global_parameter
FOR EACH ROW EXECUTE PROCEDURE func_dhcp4_global_parameter_AINS();
-
-- Trigger function for dhcp4_global_parameter_AUPD called AFTER UPDATE on dhcp4_global_parameter
CREATE OR REPLACE FUNCTION func_dhcp4_global_parameter_AUPD() RETURNS TRIGGER AS $dhcp4_global_parameter_AUPD$
BEGIN
@@ -3112,7 +3063,6 @@ CREATE TRIGGER dhcp4_global_parameter_AUPD
AFTER UPDATE ON dhcp4_global_parameter
FOR EACH ROW EXECUTE PROCEDURE func_dhcp4_global_parameter_AUPD();
-
-- Trigger function for dhcp4_global_parameter_ADEL called AFTER DELETE on dhcp4_global_parameter
CREATE OR REPLACE FUNCTION func_dhcp4_global_parameter_ADEL() RETURNS TRIGGER AS $dhcp4_global_parameter_ADEL$
BEGIN
@@ -3139,7 +3089,6 @@ CREATE TRIGGER dhcp4_subnet_AINS
AFTER INSERT ON dhcp4_subnet
FOR EACH ROW EXECUTE PROCEDURE func_dhcp4_subnet_AINS();
-
-- Trigger function for dhcp4_subnet_AUPD called AFTER UPDATE on dhcp4_subnet
CREATE OR REPLACE FUNCTION func_dhcp4_subnet_AUPD() RETURNS TRIGGER AS $dhcp4_subnet_AUPD$
BEGIN
@@ -3153,7 +3102,6 @@ CREATE TRIGGER dhcp4_subnet_AUPD
AFTER UPDATE ON dhcp4_subnet
FOR EACH ROW EXECUTE PROCEDURE func_dhcp4_subnet_AUPD();
-
-- Trigger function for dhcp4_shared_network_AINS called AFTER INSERT on dhcp4_shared_network
CREATE OR REPLACE FUNCTION func_dhcp4_shared_network_AINS() RETURNS TRIGGER AS $dhcp4_shared_network_AINS$
BEGIN
@@ -3339,7 +3287,6 @@ CREATE TRIGGER dhcp4_options_AINS
AFTER INSERT ON dhcp4_options
FOR EACH ROW EXECUTE PROCEDURE func_dhcp4_options_AINS();
-
-- Trigger function for dhcp4_options_AUPD called AFTER UPDATE on dhcp4_options
CREATE OR REPLACE FUNCTION func_dhcp4_options_AUPD() RETURNS TRIGGER AS $dhcp4_options_AUPD$
BEGIN
@@ -3619,7 +3566,6 @@ CREATE TRIGGER dhcp6_options_AUPD
AFTER UPDATE ON dhcp6_options
FOR EACH ROW EXECUTE PROCEDURE func_dhcp6_options_AUPD();
-
-- Trigger function for dhcp6_options_ADEL called AFTER DELETE on dhcp6_options
CREATE OR REPLACE FUNCTION func_dhcp6_options_ADEL() RETURNS TRIGGER AS $dhcp6_options_ADEL$
BEGIN
@@ -3635,7 +3581,6 @@ CREATE TRIGGER dhcp6_options_ADEL
AFTER DELETE ON dhcp6_options
FOR EACH ROW EXECUTE PROCEDURE func_dhcp6_options_ADEL();
-
-- Trigger function for dhcp4_server_AINS called AFTER INSERT on dhcp4_server
CREATE OR REPLACE FUNCTION func_dhcp4_server_AINS() RETURNS TRIGGER AS $dhcp4_server_AINS$
BEGIN
@@ -3649,7 +3594,6 @@ CREATE TRIGGER dhcp4_server_AINS
AFTER INSERT ON dhcp4_server
FOR EACH ROW EXECUTE PROCEDURE func_dhcp4_server_AINS();
-
-- Trigger function for dhcp4_server_AUPD called AFTER UPDATE on dhcp4_server
CREATE OR REPLACE FUNCTION func_dhcp4_server_AUPD() RETURNS TRIGGER AS $dhcp4_server_AUPD$
BEGIN
@@ -3663,7 +3607,6 @@ CREATE TRIGGER dhcp4_server_AUPD
AFTER UPDATE ON dhcp4_server
FOR EACH ROW EXECUTE PROCEDURE func_dhcp4_server_AUPD();
-
-- Trigger function for dhcp4_server_ADEL called AFTER DELETE on dhcp4_server
CREATE OR REPLACE FUNCTION func_dhcp4_server_ADEL() RETURNS TRIGGER AS $dhcp4_server_ADEL$
BEGIN
@@ -3677,7 +3620,6 @@ CREATE TRIGGER dhcp4_server_ADEL
AFTER DELETE ON dhcp4_server
FOR EACH ROW EXECUTE PROCEDURE func_dhcp4_server_ADEL();
-
-- Trigger function for dhcp6_server_AINS called AFTER INSERT on dhcp6_server
CREATE OR REPLACE FUNCTION func_dhcp6_server_AINS() RETURNS TRIGGER AS $dhcp6_server_AINS$
BEGIN
@@ -3691,7 +3633,6 @@ CREATE TRIGGER dhcp6_server_AINS
AFTER INSERT ON dhcp6_server
FOR EACH ROW EXECUTE PROCEDURE func_dhcp6_server_AINS();
-
-- Trigger function for dhcp6_server_AUPD called AFTER UPDATE on dhcp6_server
CREATE OR REPLACE FUNCTION func_dhcp6_server_AUPD() RETURNS TRIGGER AS $dhcp6_server_AUPD$
BEGIN
@@ -3785,14 +3726,16 @@ END;
$dhcp6_pd_pool_BDEL$
LANGUAGE plpgsql;
--- Update the schema version number
+-- Set schema 7.0 version.
UPDATE schema_version
SET version = '7', minor = '0';
-- Schema 7.0 specification ends here.
--- This starts schema update to 8.0. It adds a few missing elements for CB and
--- functions for kea-admin's lease-dump and lease-upload commands.
+-- Upgrade to schema 8.0 begins here:
+
+-- Add a few missing elements for CB and functions for kea-admin's lease-dump
+-- and lease-upload commands.
-- -----------------------------------------------------------------------
-- Extend the table holding DHCPv4 option definitions with a nullable
@@ -4258,13 +4201,13 @@ BEGIN
END
$$ LANGUAGE plpgsql;
--- Update the schema version number.
+-- Set schema 8.0 version.
UPDATE schema_version
SET version = '8', minor = '0';
-- Schema 8.0 specification ends here.
--- This starts schema update to 9.0.
+-- Upgrade to schema 9.0 begins here:
-- Add missing cascade to constraint on dhcp4/6_subnet_server tables.
ALTER TABLE dhcp4_subnet_server
@@ -4510,13 +4453,14 @@ BEGIN
END;$$
LANGUAGE plpgsql;
--- Update the schema version number.
+-- Set schema 9.0 version.
UPDATE schema_version
SET version = '9', minor = '0';
-- Schema 9.0 specification ends here.
--- This starts schema update to 10.0.
+-- Upgrade to schema 10.0 begins here:
+
-- It adds corrections for client classes for CB
-- Replace setClientClass4Order():
@@ -4805,13 +4749,13 @@ END;
$dhcp6_client_class_check_dependency_BINS$
LANGUAGE plpgsql;
--- Update the schema version number.
+-- Set schema 10.0 version.
UPDATE schema_version
SET version = '10', minor = '0';
-- Schema 10.0 specification ends here.
--- This starts schema update to 11.0.
+-- Upgrade to schema 11.0 begins here:
-- Replace createOptionAuditDHCP6() with a version corrected
-- where clause when scope is 6 (i.e. PD pool)
@@ -4917,13 +4861,13 @@ BEGIN
RETURN;
END;$$;
--- Update the schema version number.
+-- Set schema 11.0 version.
UPDATE schema_version
SET version = '11', minor = '0';
-- Schema 11.0 specification ends here.
--- This line starts the schema upgrade to version 12.
+-- Upgrade to schema 12.0 begins here:
-- Modify shared-network-name foreign key constraint on dhcp4_subnet to not perform
-- the update when the network is deleted the cascaded update will not execute
@@ -4981,13 +4925,13 @@ LANGUAGE plpgsql;
ALTER TABLE dhcp4_client_class ADD COLUMN user_context JSON DEFAULT NULL;
ALTER TABLE dhcp6_client_class ADD COLUMN user_context JSON DEFAULT NULL;
--- Update the schema version number.
+-- Set schema 12.0 version.
UPDATE schema_version
SET version = '12', minor = '0';
--- This line concludes the schema upgrade to version 12.
+-- Schema 12.0 specification ends here.
--- This line starts the schema upgrade to version 13.
+-- Upgrade to schema 13.0 begins here:
-- JSON functions --
@@ -5620,13 +5564,13 @@ CREATE UNIQUE INDEX key_dhcp6_identifier_subnet_id ON hosts
(dhcp_identifier ASC, dhcp_identifier_type ASC, dhcp6_subnet_id ASC)
WHERE (dhcp6_subnet_id IS NOT NULL);
--- Update the schema version number.
+-- Set schema 13.0 version.
UPDATE schema_version
SET version = '13', minor = '0';
--- This line concludes the schema upgrade to version 13.
+-- Schema 13.0 specification ends here.
--- This line starts the schema upgrade to version 14.
+-- Upgrade to schema 14.0 begins here:
-- Add cancelled (aka never-send) column to option tables.
@@ -5643,18 +5587,18 @@ ALTER TABLE dhcp4_subnet
ALTER TABLE dhcp4_client_class
ADD COLUMN offer_lifetime BIGINT DEFAULT NULL;
--- Update the schema version number.
+-- Set schema 14.0 version.
UPDATE schema_version
SET version = '14', minor = '0';
--- This line concludes the schema upgrade to version 14.
+-- Schema 14.0 specification ends here.
--- This line starts the schema upgrade to version 15.
+-- Upgrade to schema 15.0 begins here:
-- Add relay and remote id columns to DHCPv4 leases.
--
-- Note: these columns are only used for indexes, in particular they are
--- not exported by lease4 dump as values are also in the user context
+-- not exported by lease4 dump as values are also in the user context
ALTER TABLE lease4
ADD COLUMN relay_id BYTEA DEFAULT NULL,
ADD COLUMN remote_id BYTEA DEFAULT NULL;
@@ -5663,11 +5607,21 @@ ALTER TABLE lease4
CREATE INDEX lease4_by_relay_id ON lease4 (relay_id);
CREATE INDEX lease4_by_remote_id ON lease4 (remote_id);
--- Update the schema version number.
+-- Set schema 15.0 version.
UPDATE schema_version
SET version = '15', minor = '0';
--- This line concludes the schema upgrade to version 15.
+-- Schema 15.0 specification ends here.
+
+-- Upgrade to schema 16.0 begins here:
+
+UPDATE lease6 SET duid = E'\\x000000' WHERE duid = E'\\x00';
+
+-- Set schema 16.0 version.
+UPDATE schema_version
+ SET version = '16', minor = '0';
+
+-- Schema 16.0 specification ends here.
-- This line starts the schema upgrade to version 16.
diff --git a/src/share/database/scripts/pgsql/upgrade_001.0_to_002.0.sh.in b/src/share/database/scripts/pgsql/upgrade_001.0_to_002.0.sh.in
index 1e6d806611..e5348b6ca9 100644
--- a/src/share/database/scripts/pgsql/upgrade_001.0_to_002.0.sh.in
+++ b/src/share/database/scripts/pgsql/upgrade_001.0_to_002.0.sh.in
@@ -34,6 +34,9 @@ if [ "$VERSION" != "1.0" ]; then
fi
psql "$@" >/dev/null <<EOF
+
+-- Upgrade to schema 2.0 begins here:
+
-- Add state column to the lease4 table.
ALTER TABLE lease4
ADD COLUMN state INT8 DEFAULT 0;
@@ -169,5 +172,10 @@ CREATE FUNCTION lease6DumpData() RETURNS
START TRANSACTION;
UPDATE schema_version
SET version = '2', minor = '0';
+
+-- Schema 2.0 specification ends here.
+
+-- Commit the script transaction
COMMIT;
+
EOF
diff --git a/src/share/database/scripts/pgsql/upgrade_003.1_to_003.2.sh.in b/src/share/database/scripts/pgsql/upgrade_003.1_to_003.2.sh.in
index d2dff8ca24..757e90c251 100644
--- a/src/share/database/scripts/pgsql/upgrade_003.1_to_003.2.sh.in
+++ b/src/share/database/scripts/pgsql/upgrade_003.1_to_003.2.sh.in
@@ -37,6 +37,8 @@ psql "$@" >/dev/null <<EOF
START TRANSACTION;
+-- Upgrade to schema 3.2 begins here:
+
-- Remove constraints which perform too restrictive checks on the inserted
-- host reservations. We want to be able to insert host reservations which
-- include no specific IPv4 address or those that have repeating subnet
diff --git a/src/share/database/scripts/pgsql/upgrade_003.2_to_003.3.sh.in b/src/share/database/scripts/pgsql/upgrade_003.2_to_003.3.sh.in
index 87b6b128d8..c6d7b16c10 100644
--- a/src/share/database/scripts/pgsql/upgrade_003.2_to_003.3.sh.in
+++ b/src/share/database/scripts/pgsql/upgrade_003.2_to_003.3.sh.in
@@ -37,6 +37,8 @@ psql "$@" >/dev/null <<EOF
START TRANSACTION;
+-- Upgrade to schema 3.3 begins here:
+
-- Change subnet ID columns type to BIGINT to match lease4/6 tables
ALTER TABLE hosts ALTER COLUMN dhcp4_subnet_id TYPE BIGINT;
ALTER TABLE hosts ALTER COLUMN dhcp6_subnet_id TYPE BIGINT;
diff --git a/src/share/database/scripts/pgsql/upgrade_003.3_to_004.0.sh.in b/src/share/database/scripts/pgsql/upgrade_003.3_to_004.0.sh.in
index 0a4c1f4c11..f9a1754745 100644
--- a/src/share/database/scripts/pgsql/upgrade_003.3_to_004.0.sh.in
+++ b/src/share/database/scripts/pgsql/upgrade_003.3_to_004.0.sh.in
@@ -37,6 +37,8 @@ psql "$@" >/dev/null <<EOF
START TRANSACTION;
+-- Upgrade to schema 4.0 begins here:
+
-- Add a column holding hosts for user context.
ALTER TABLE hosts ADD COLUMN user_context TEXT;
diff --git a/src/share/database/scripts/pgsql/upgrade_004.0_to_005.0.sh.in b/src/share/database/scripts/pgsql/upgrade_004.0_to_005.0.sh.in
index 994dd8fb26..a64ffecc04 100644
--- a/src/share/database/scripts/pgsql/upgrade_004.0_to_005.0.sh.in
+++ b/src/share/database/scripts/pgsql/upgrade_004.0_to_005.0.sh.in
@@ -37,6 +37,8 @@ psql "$@" >/dev/null <<EOF
START TRANSACTION;
+-- Upgrade to schema 5.0 begins here:
+
-- Add a column holding leases for user context.
ALTER TABLE lease4 ADD COLUMN user_context TEXT;
ALTER TABLE lease6 ADD COLUMN user_context TEXT;
diff --git a/src/share/database/scripts/pgsql/upgrade_005.0_to_005.1.sh.in b/src/share/database/scripts/pgsql/upgrade_005.0_to_005.1.sh.in
index 9db6f4b8ef..3883178ef1 100644
--- a/src/share/database/scripts/pgsql/upgrade_005.0_to_005.1.sh.in
+++ b/src/share/database/scripts/pgsql/upgrade_005.0_to_005.1.sh.in
@@ -37,6 +37,8 @@ psql "$@" >/dev/null <<EOF
START TRANSACTION;
+-- Upgrade to schema 5.1 begins here:
+
-- Put the auth key in hexadecimal (double size but far more user friendly).
ALTER TABLE hosts ALTER COLUMN auth_key TYPE VARCHAR(32);
@@ -44,7 +46,7 @@ ALTER TABLE hosts ALTER COLUMN auth_key TYPE VARCHAR(32);
UPDATE schema_version
SET version = '5', minor = '1';
--- Schema 5.1a specification ends here.
+-- Schema 5.1 specification ends here.
-- Commit the script transaction
COMMIT;
diff --git a/src/share/database/scripts/pgsql/upgrade_005.1_to_006.0.sh.in b/src/share/database/scripts/pgsql/upgrade_005.1_to_006.0.sh.in
index 55a7827e6e..356562c0e6 100644
--- a/src/share/database/scripts/pgsql/upgrade_005.1_to_006.0.sh.in
+++ b/src/share/database/scripts/pgsql/upgrade_005.1_to_006.0.sh.in
@@ -37,6 +37,8 @@ psql "$@" >/dev/null <<EOF
START TRANSACTION;
+-- Upgrade to schema 6.0 begins here:
+
-- Create a lower case hostname index for hosts.
CREATE INDEX hosts_by_hostname ON hosts (lower(hostname))
WHERE hostname IS NOT NULL;
@@ -63,7 +65,7 @@ WHERE hostname IS NOT NULL;
UPDATE schema_version
SET version = '6', minor = '0';
--- Schema 5.1a specification ends here.
+-- Schema 6.0 specification ends here.
-- Commit the script transaction
COMMIT;
diff --git a/src/share/database/scripts/pgsql/upgrade_006.0_to_006.1.sh.in b/src/share/database/scripts/pgsql/upgrade_006.0_to_006.1.sh.in
index b1f651e792..beaf8b6f5d 100644
--- a/src/share/database/scripts/pgsql/upgrade_006.0_to_006.1.sh.in
+++ b/src/share/database/scripts/pgsql/upgrade_006.0_to_006.1.sh.in
@@ -37,6 +37,8 @@ psql "$@" >/dev/null <<EOF
START TRANSACTION;
+-- Upgrade to schema 6.1 begins here:
+
-- Fix v4 update trigger procedure
CREATE OR REPLACE FUNCTION proc_stat_lease4_update () RETURNS trigger AS \$stat_lease4_update\$
BEGIN
diff --git a/src/share/database/scripts/pgsql/upgrade_006.1_to_006.2.sh.in b/src/share/database/scripts/pgsql/upgrade_006.1_to_006.2.sh.in
index 730fe66f85..11776f6838 100644
--- a/src/share/database/scripts/pgsql/upgrade_006.1_to_006.2.sh.in
+++ b/src/share/database/scripts/pgsql/upgrade_006.1_to_006.2.sh.in
@@ -35,6 +35,8 @@ fi
psql "$@" >/dev/null <<EOF
+-- Upgrade to schema 6.2 begins here:
+
-- Starting from this version we allow specifying multiple IP reservations
-- for the same address in certain DHCP configurations. The server may check
-- uniqueness of the IP addresses on its own. This is no longer checked at
@@ -59,7 +61,7 @@ ALTER TABLE ipv6_reservations DROP CONSTRAINT IF EXISTS key_dhcp6_address_prefix
CREATE INDEX key_dhcp6_address_prefix_len
ON ipv6_reservations (address ASC, prefix_len ASC);
--- Update the schema version number
+-- Set 6.2 schema version.
UPDATE schema_version
SET version = '6', minor = '2';
diff --git a/src/share/database/scripts/pgsql/upgrade_006.2_to_007.0.sh.in b/src/share/database/scripts/pgsql/upgrade_006.2_to_007.0.sh.in
index 74cc95cc37..e39f99bdd1 100644
--- a/src/share/database/scripts/pgsql/upgrade_006.2_to_007.0.sh.in
+++ b/src/share/database/scripts/pgsql/upgrade_006.2_to_007.0.sh.in
@@ -37,8 +37,9 @@ psql "$@" >/dev/null <<EOF
START TRANSACTION;
--- This starts schema update to 7.0. It adds a lot (20+) of tables for the config backend.
+-- Upgrade to schema 7.0 begins here:
+-- Add a lot (20+) of tables for the config backend.
-- Adding on update trigger in MySQL is as easy as using this column definition in CREATE TABLE:
-- modification_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
@@ -57,7 +58,6 @@ CREATE OR REPLACE FUNCTION modification_ts_update()
-- Second, we need to specify which language it was written in.
\$modification_ts_update\$ LANGUAGE plpgsql;
-
-- Create table modification and insert values for modification types.
CREATE TABLE modification (
id smallint NOT NULL,
@@ -66,8 +66,6 @@ CREATE TABLE modification (
);
INSERT INTO modification VALUES (0,'create'), (1,'update'), (2,'delete');
-
-
-- Now create the table that holds different parameter data types.
CREATE TABLE parameter_data_type (
id smallint NOT NULL,
@@ -80,8 +78,6 @@ INSERT INTO parameter_data_type VALUES
(2,'boolean'),
(4,'string');
-
-
-- This table doesn't exist in MySQL. However, it's nice to have an enum that explains what the values
-- in ddns_replace_client_name field in the dhcp{4,6}_shared_network table means.
CREATE TABLE ddns_replace_client_name_types (
@@ -95,8 +91,6 @@ INSERT INTO ddns_replace_client_name_types (type, name) VALUES
(2, 'RCM_WHEN_PRESENT'),
(3, 'RCM_WHEN_NOT_PRESENT');
-
-
-- Create table for DHCPv6 servers
CREATE TABLE dhcp6_server (
id SERIAL PRIMARY KEY NOT NULL,
@@ -156,8 +150,6 @@ CREATE TRIGGER dhcp6_shared_network_modification_ts_update
AFTER UPDATE ON dhcp6_shared_network
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-
-- Now we need to create a relationship between defined shared networks and the servers
CREATE TABLE dhcp6_shared_network_server (
shared_network_id BIGINT NOT NULL,
@@ -172,8 +164,6 @@ CREATE TABLE dhcp6_shared_network_server (
CREATE INDEX dhcp6_shared_network_server_idx1 ON dhcp6_shared_network_server (modification_ts);
CREATE INDEX dhcp6_shared_network_server_idx2 ON dhcp6_shared_network_server (server_id);
-
-
-- Create a list of IPv6 subnets
CREATE TABLE dhcp6_subnet (
subnet_id BIGINT PRIMARY KEY NOT NULL,
@@ -222,8 +212,6 @@ CREATE TRIGGER dhcp6_subnet_modification_ts_update
CREATE INDEX dhcp6_subnet_idx1 ON dhcp6_subnet (modification_ts);
CREATE INDEX dhcp6_subnet_idx2 ON dhcp6_subnet (shared_network_name);
-
-
-- Create a table that holds all address pools in IPv6.
CREATE TABLE dhcp6_pool (
id SERIAL PRIMARY KEY NOT NULL,
@@ -243,7 +231,6 @@ CREATE TRIGGER dhcp6_pool_modification_ts_update
AFTER UPDATE ON dhcp6_pool
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-- And now the same, but for PD pools.
CREATE TABLE dhcp6_pd_pool (
id SERIAL PRIMARY KEY NOT NULL,
@@ -266,8 +253,6 @@ CREATE TRIGGER dhcp6_pd_pool_modification_ts_update
AFTER UPDATE ON dhcp6_pd_pool
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-
CREATE TABLE dhcp6_subnet_server (
subnet_id BIGINT NOT NULL,
server_id BIGINT NOT NULL,
@@ -285,8 +270,6 @@ CREATE TRIGGER dhcp6_subnet_server_modification_ts_update
AFTER UPDATE ON dhcp6_subnet_server
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-
-- Create table for storing global DHCPv6 parameters.
CREATE TABLE dhcp6_global_parameter (
id SERIAL PRIMARY KEY NOT NULL,
@@ -304,7 +287,6 @@ CREATE TRIGGER dhcp6_global_parameter_modification_ts_update
AFTER UPDATE ON dhcp6_global_parameter
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
CREATE TABLE dhcp6_global_parameter_server (
parameter_id BIGINT NOT NULL,
server_id BIGINT NOT NULL,
@@ -320,7 +302,6 @@ CREATE TRIGGER dhcp6_global_parameter_server_modification_ts_update
AFTER UPDATE ON dhcp6_global_parameter_server
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-- Create a table for storing DHCPv6 options.
ALTER TABLE dhcp6_options
ADD COLUMN shared_network_name VARCHAR(128) DEFAULT NULL,
@@ -354,8 +335,6 @@ CREATE TRIGGER dhcp6_options_server_modification_ts_update
AFTER UPDATE ON dhcp6_options_server
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-
-- This table is for storing IPv6 option definitions
CREATE TABLE dhcp6_option_def (
id SERIAL PRIMARY KEY UNIQUE NOT NULL,
@@ -375,7 +354,6 @@ CREATE TRIGGER dhcp6_option_def_modification_ts_update
AFTER UPDATE ON dhcp6_option_def
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-- and another table for storing relationship between option definitions and servers.
CREATE TABLE dhcp6_option_def_server (
option_def_id BIGINT NOT NULL REFERENCES dhcp6_option_def (id) ON DELETE CASCADE ON UPDATE NO ACTION,
@@ -387,7 +365,6 @@ CREATE TRIGGER dhcp6_option_def_server_modification_ts_update
AFTER UPDATE ON dhcp6_option_def_server
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-- Now create two tables for audit revisions...
CREATE TABLE dhcp6_audit_revision (
id SERIAL PRIMARY KEY NOT NULL,
@@ -399,7 +376,6 @@ CREATE TRIGGER dhcp6_audit_revision_modification_ts_update
AFTER UPDATE ON dhcp6_audit_revision
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-- ... and the DHCPv6 audit itself.
CREATE TABLE dhcp6_audit (
id SERIAL UNIQUE NOT NULL,
@@ -418,7 +394,6 @@ CREATE TRIGGER dhcp6_audit_modification_ts_update
CREATE INDEX dhcp6_audit_idx1 ON dhcp6_audit (modification_type);
CREATE INDEX dhcp6_audit_idx2 ON dhcp6_audit (revision_id);
-
-- Create table for DHCPv4 servers
CREATE TABLE dhcp4_server (
id SERIAL PRIMARY KEY NOT NULL,
@@ -466,7 +441,6 @@ CREATE TRIGGER dhcp4_global_parameter_server_modification_ts_update
AFTER UPDATE ON dhcp4_global_parameter_server
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-- Create a table for storing IPv4 shared networks
CREATE TABLE dhcp4_shared_network (
id SERIAL PRIMARY KEY NOT NULL,
@@ -512,8 +486,6 @@ CREATE TRIGGER dhcp4_shared_network_modification_ts_update
AFTER UPDATE ON dhcp4_shared_network
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-
-- Now we need to create a relationship between defined shared networks and the servers
CREATE TABLE dhcp4_shared_network_server (
shared_network_id BIGINT NOT NULL,
@@ -528,8 +500,6 @@ CREATE TABLE dhcp4_shared_network_server (
CREATE INDEX dhcp4_shared_network_server_idx1 ON dhcp4_shared_network_server (modification_ts);
CREATE INDEX dhcp4_shared_network_server_idx2 ON dhcp4_shared_network_server (server_id);
-
-
-- Create a list of IPv4 subnets
CREATE TABLE dhcp4_subnet (
subnet_id BIGINT PRIMARY KEY NOT NULL,
@@ -581,8 +551,6 @@ CREATE TRIGGER dhcp4_subnet_modification_ts_update
CREATE INDEX dhcp4_subnet_idx1 ON dhcp4_subnet (modification_ts);
CREATE INDEX dhcp4_subnet_idx2 ON dhcp4_subnet (shared_network_name);
-
-
CREATE TABLE dhcp4_subnet_server (
subnet_id BIGINT NOT NULL,
server_id BIGINT NOT NULL,
@@ -600,8 +568,6 @@ CREATE TRIGGER dhcp4_subnet_server_modification_ts_update
AFTER UPDATE ON dhcp4_subnet_server
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-
-- Create a table that holds all address pools in IPv4.
CREATE TABLE dhcp4_pool (
id SERIAL PRIMARY KEY NOT NULL,
@@ -621,7 +587,6 @@ CREATE TRIGGER dhcp4_pool_modification_ts_update
AFTER UPDATE ON dhcp4_pool
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-- Create a table for storing DHCPv4 options.
ALTER TABLE dhcp4_options
ADD COLUMN shared_network_name VARCHAR(128) DEFAULT NULL,
@@ -636,8 +601,6 @@ CREATE TRIGGER dhcp4_options_modification_ts_update
AFTER UPDATE ON dhcp4_options
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-
-- Now create a table for associating defined v4 options with servers.
CREATE TABLE dhcp4_options_server (
option_id BIGINT NOT NULL,
@@ -655,8 +618,6 @@ CREATE TRIGGER dhcp4_options_server_modification_ts_update
AFTER UPDATE ON dhcp4_options_server
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-
-- This table is for storing IPv4 option definitions
CREATE TABLE dhcp4_option_def (
id SERIAL PRIMARY KEY UNIQUE NOT NULL,
@@ -676,7 +637,6 @@ CREATE TRIGGER dhcp4_option_def_modification_ts_update
AFTER UPDATE ON dhcp4_option_def
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-- and another table for storing relationship between option definitions and servers.
CREATE TABLE dhcp4_option_def_server (
option_def_id BIGINT NOT NULL REFERENCES dhcp6_option_def (id) ON DELETE CASCADE ON UPDATE NO ACTION,
@@ -688,8 +648,6 @@ CREATE TRIGGER dhcp4_option_def_server_modification_ts_update
AFTER UPDATE ON dhcp4_option_def_server
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-
-- Now create two tables for audit revisions...
CREATE TABLE dhcp4_audit_revision (
id SERIAL PRIMARY KEY NOT NULL,
@@ -701,7 +659,6 @@ CREATE TRIGGER dhcp4_audit_revision_modification_ts_update
AFTER UPDATE ON dhcp4_audit_revision
FOR EACH ROW EXECUTE PROCEDURE modification_ts_update();
-
-- ... and the DHCPv4 audit itself.
CREATE TABLE dhcp4_audit (
id SERIAL UNIQUE NOT NULL,
@@ -773,7 +730,6 @@ BEGIN
END;\$\$
LANGUAGE plpgsql;
-
-- Fetches a text value from the session configuration.
-- param name name of the session variable to fetch
-- If the name is not found it returns NULL.
@@ -848,7 +804,6 @@ BEGIN
END;\$\$
LANGUAGE plpgsql;
-
-- -----------------------------------------------------
-- Stored procedure which creates a new entry in the
-- dhcp4_audit_revision table and sets appropriate session
@@ -1015,7 +970,6 @@ CREATE TABLE IF NOT EXISTS dhcp4_client_class_order (
CREATE INDEX key_dhcp4_client_class_order_index on dhcp4_client_class_order (order_index);
-
-- -----------------------------------------------------------------------
-- Stored procedure positioning an inserted or updated client class
-- within the class hierarchy, depending on the value of the
@@ -1310,7 +1264,6 @@ BEGIN
RETURN;
END;\$\$;
-
-- -----------------------------------------------------------------------
-- Trigger verifying if class dependency is met. It includes checking
-- if referenced classes exist, are associated with the same server
@@ -1915,7 +1868,6 @@ BEGIN
RETURN;
END;\$\$;
-
-- -----------------------------------------------------------------------
-- Trigger verifying if class dependency is met. It includes checking
-- if referenced classes exist, are associated with the same server
@@ -2105,7 +2057,6 @@ CREATE TRIGGER dhcp4_global_parameter_AINS
AFTER INSERT ON dhcp4_global_parameter
FOR EACH ROW EXECUTE PROCEDURE func_dhcp4_global_parameter_AINS();
-
-- Trigger function for dhcp4_global_parameter_AUPD called AFTER UPDATE on dhcp4_global_parameter
CREATE OR REPLACE FUNCTION func_dhcp4_global_parameter_AUPD() RETURNS TRIGGER AS \$dhcp4_global_parameter_AUPD\$
BEGIN
@@ -2119,7 +2070,6 @@ CREATE TRIGGER dhcp4_global_parameter_AUPD
AFTER UPDATE ON dhcp4_global_parameter
FOR EACH ROW EXECUTE PROCEDURE func_dhcp4_global_parameter_AUPD();
-
-- Trigger function for dhcp4_global_parameter_ADEL called AFTER DELETE on dhcp4_global_parameter
CREATE OR REPLACE FUNCTION func_dhcp4_global_parameter_ADEL() RETURNS TRIGGER AS \$dhcp4_global_parameter_ADEL\$
BEGIN
@@ -2146,7 +2096,6 @@ CREATE TRIGGER dhcp4_subnet_AINS
AFTER INSERT ON dhcp4_subnet
FOR EACH ROW EXECUTE PROCEDURE func_dhcp4_subnet_AINS();
-
-- Trigger function for dhcp4_subnet_AUPD called AFTER UPDATE on dhcp4_subnet
CREATE OR REPLACE FUNCTION func_dhcp4_subnet_AUPD() RETURNS TRIGGER AS \$dhcp4_subnet_AUPD\$
BEGIN
@@ -2160,7 +2109,6 @@ CREATE TRIGGER dhcp4_subnet_AUPD
AFTER UPDATE ON dhcp4_subnet
FOR EACH ROW EXECUTE PROCEDURE func_dhcp4_subnet_AUPD();
-
-- Trigger function for dhcp4_shared_network_AINS called AFTER INSERT on dhcp4_shared_network
CREATE OR REPLACE FUNCTION func_dhcp4_shared_network_AINS() RETURNS TRIGGER AS \$dhcp4_shared_network_AINS\$
BEGIN
@@ -2346,7 +2294,6 @@ CREATE TRIGGER dhcp4_options_AINS
AFTER INSERT ON dhcp4_options
FOR EACH ROW EXECUTE PROCEDURE func_dhcp4_options_AINS();
-
-- Trigger function for dhcp4_options_AUPD called AFTER UPDATE on dhcp4_options
CREATE OR REPLACE FUNCTION func_dhcp4_options_AUPD() RETURNS TRIGGER AS \$dhcp4_options_AUPD\$
BEGIN
@@ -2626,7 +2573,6 @@ CREATE TRIGGER dhcp6_options_AUPD
AFTER UPDATE ON dhcp6_options
FOR EACH ROW EXECUTE PROCEDURE func_dhcp6_options_AUPD();
-
-- Trigger function for dhcp6_options_ADEL called AFTER DELETE on dhcp6_options
CREATE OR REPLACE FUNCTION func_dhcp6_options_ADEL() RETURNS TRIGGER AS \$dhcp6_options_ADEL\$
BEGIN
@@ -2642,7 +2588,6 @@ CREATE TRIGGER dhcp6_options_ADEL
AFTER DELETE ON dhcp6_options
FOR EACH ROW EXECUTE PROCEDURE func_dhcp6_options_ADEL();
-
-- Trigger function for dhcp4_server_AINS called AFTER INSERT on dhcp4_server
CREATE OR REPLACE FUNCTION func_dhcp4_server_AINS() RETURNS TRIGGER AS \$dhcp4_server_AINS\$
BEGIN
@@ -2656,7 +2601,6 @@ CREATE TRIGGER dhcp4_server_AINS
AFTER INSERT ON dhcp4_server
FOR EACH ROW EXECUTE PROCEDURE func_dhcp4_server_AINS();
-
-- Trigger function for dhcp4_server_AUPD called AFTER UPDATE on dhcp4_server
CREATE OR REPLACE FUNCTION func_dhcp4_server_AUPD() RETURNS TRIGGER AS \$dhcp4_server_AUPD\$
BEGIN
@@ -2670,7 +2614,6 @@ CREATE TRIGGER dhcp4_server_AUPD
AFTER UPDATE ON dhcp4_server
FOR EACH ROW EXECUTE PROCEDURE func_dhcp4_server_AUPD();
-
-- Trigger function for dhcp4_server_ADEL called AFTER DELETE on dhcp4_server
CREATE OR REPLACE FUNCTION func_dhcp4_server_ADEL() RETURNS TRIGGER AS \$dhcp4_server_ADEL\$
BEGIN
@@ -2684,7 +2627,6 @@ CREATE TRIGGER dhcp4_server_ADEL
AFTER DELETE ON dhcp4_server
FOR EACH ROW EXECUTE PROCEDURE func_dhcp4_server_ADEL();
-
-- Trigger function for dhcp6_server_AINS called AFTER INSERT on dhcp6_server
CREATE OR REPLACE FUNCTION func_dhcp6_server_AINS() RETURNS TRIGGER AS \$dhcp6_server_AINS\$
BEGIN
@@ -2698,7 +2640,6 @@ CREATE TRIGGER dhcp6_server_AINS
AFTER INSERT ON dhcp6_server
FOR EACH ROW EXECUTE PROCEDURE func_dhcp6_server_AINS();
-
-- Trigger function for dhcp6_server_AUPD called AFTER UPDATE on dhcp6_server
CREATE OR REPLACE FUNCTION func_dhcp6_server_AUPD() RETURNS TRIGGER AS \$dhcp6_server_AUPD\$
BEGIN
@@ -2712,7 +2653,6 @@ CREATE TRIGGER dhcp6_server_AUPD
AFTER UPDATE ON dhcp6_server
FOR EACH ROW EXECUTE PROCEDURE func_dhcp6_server_AUPD();
-
-- Trigger function for dhcp6_server_ADEL called AFTER DELETE on dhcp6_server
CREATE OR REPLACE FUNCTION func_dhcp6_server_ADEL() RETURNS TRIGGER AS \$dhcp6_server_ADEL\$
BEGIN
@@ -2726,7 +2666,6 @@ CREATE TRIGGER dhcp6_server_ADEL
AFTER DELETE ON dhcp6_server
FOR EACH ROW EXECUTE PROCEDURE func_dhcp6_server_ADEL();
-
-- Trigger function for dhcp4_shared_network_BDEL called BEFORE DELETE on dhcp4_shared_network
CREATE OR REPLACE FUNCTION func_dhcp4_shared_network_BDEL() RETURNS TRIGGER AS \$dhcp4_shared_network_BDEL\$
BEGIN
@@ -2795,7 +2734,7 @@ END;
\$dhcp6_pd_pool_BDEL\$
LANGUAGE plpgsql;
--- Update the schema version number
+-- Set 7.0 schema version.
UPDATE schema_version
SET version = '7', minor = '0';
diff --git a/src/share/database/scripts/pgsql/upgrade_007_to_008.sh.in b/src/share/database/scripts/pgsql/upgrade_007_to_008.sh.in
index c03ae728be..c08150ebbc 100644
--- a/src/share/database/scripts/pgsql/upgrade_007_to_008.sh.in
+++ b/src/share/database/scripts/pgsql/upgrade_007_to_008.sh.in
@@ -36,8 +36,10 @@ fi
psql "$@" >/dev/null <<EOF
START TRANSACTION;
--- This starts schema update to 8.0. It adds a few missing elements for CB and
--- functions for kea-admin's lease-dump and lease-upload commands.
+-- Upgrade to schema 8.0 begins here:
+
+-- Adds a few missing elements for CB and functions for kea-admin's lease-dump
+-- and lease-upload commands.
-- -----------------------------------------------------------------------
-- Extend the table holding DHCPv4 option definitions with a nullable
@@ -504,7 +506,7 @@ BEGIN
END
\$\$ LANGUAGE plpgsql;
--- Update the schema version number.
+-- Set 8.0 schema version.
UPDATE schema_version
SET version = '8', minor = '0';
diff --git a/src/share/database/scripts/pgsql/upgrade_008_to_009.sh.in b/src/share/database/scripts/pgsql/upgrade_008_to_009.sh.in
index 5c3632a15e..c6a470b85f 100644
--- a/src/share/database/scripts/pgsql/upgrade_008_to_009.sh.in
+++ b/src/share/database/scripts/pgsql/upgrade_008_to_009.sh.in
@@ -36,7 +36,7 @@ fi
psql "$@" >/dev/null <<EOF
START TRANSACTION;
--- This starts schema update to 9.0.
+-- Upgrade to schema 9.0 begins here:
-- Add missing cascade to constraint on dhcp4/6_subnet_server tables.
ALTER TABLE dhcp4_subnet_server
@@ -282,10 +282,12 @@ BEGIN
END;\$\$
LANGUAGE plpgsql;
--- Update the schema version number.
+-- Set 9.0 schema version.
UPDATE schema_version
SET version = '9', minor = '0';
+-- Schema 9.0 specification ends here.
+
-- Commit the script transaction.
COMMIT;
diff --git a/src/share/database/scripts/pgsql/upgrade_009_to_010.sh.in b/src/share/database/scripts/pgsql/upgrade_009_to_010.sh.in
index 38ffa6b8cb..5bdb52ae52 100644
--- a/src/share/database/scripts/pgsql/upgrade_009_to_010.sh.in
+++ b/src/share/database/scripts/pgsql/upgrade_009_to_010.sh.in
@@ -36,7 +36,8 @@ fi
psql "$@" >/dev/null <<EOF
START TRANSACTION;
--- This starts schema update to 10.0.
+-- Upgrade to schema 10.0 begins here:
+
-- It adds corrections for client classes for CB
-- Replace setClientClass4Order():
@@ -325,10 +326,12 @@ END;
\$dhcp6_client_class_check_dependency_BINS\$
LANGUAGE plpgsql;
--- Update the schema version number.
+-- Set 10.0 schema version.
UPDATE schema_version
SET version = '10', minor = '0';
+-- Schema 10.0 specification ends here.
+
-- Commit the script transaction.
COMMIT;
diff --git a/src/share/database/scripts/pgsql/upgrade_010_to_011.sh.in b/src/share/database/scripts/pgsql/upgrade_010_to_011.sh.in
index 690f8d103b..772ec2f10f 100644
--- a/src/share/database/scripts/pgsql/upgrade_010_to_011.sh.in
+++ b/src/share/database/scripts/pgsql/upgrade_010_to_011.sh.in
@@ -36,7 +36,7 @@ fi
psql "$@" >/dev/null <<EOF
START TRANSACTION;
--- This starts schema update to 11.0.
+-- Upgrade to schema 11.0 begins here:
-- Replace createOptionAuditDHCP6() with a version corrected
-- where clause when scope is 6 (i.e. PD pool)
@@ -142,10 +142,12 @@ BEGIN
RETURN;
END;\$\$;
--- Update the schema version number.
+-- Set 11.0 schema version.
UPDATE schema_version
SET version = '11', minor = '0';
+-- Schema 11.0 specification ends here.
+
-- Commit the script transaction.
COMMIT;
diff --git a/src/share/database/scripts/pgsql/upgrade_011_to_012.sh.in b/src/share/database/scripts/pgsql/upgrade_011_to_012.sh.in
index 5805fce98c..d3a672258c 100644
--- a/src/share/database/scripts/pgsql/upgrade_011_to_012.sh.in
+++ b/src/share/database/scripts/pgsql/upgrade_011_to_012.sh.in
@@ -36,7 +36,7 @@ fi
psql "$@" >/dev/null <<EOF
START TRANSACTION;
--- This line starts the schema upgrade to version 12.
+-- Upgrade to schema 12.0 begins here:
-- Modify shared-network-name foreign key constraint on dhcp4_subnet to not perform
-- the update when the network is deleted the cascaded update will not execute
@@ -94,11 +94,11 @@ LANGUAGE plpgsql;
ALTER TABLE dhcp4_client_class ADD COLUMN user_context JSON DEFAULT NULL;
ALTER TABLE dhcp6_client_class ADD COLUMN user_context JSON DEFAULT NULL;
--- Update the schema version number.
+-- Set 12.0 schema version.
UPDATE schema_version
SET version = '12', minor = '0';
--- This line concludes the schema upgrade to version 12.
+-- Schema 12.0 specification ends here.
-- Commit the script transaction.
COMMIT;
diff --git a/src/share/database/scripts/pgsql/upgrade_012_to_013.sh.in b/src/share/database/scripts/pgsql/upgrade_012_to_013.sh.in
index 776c6d194f..03053b8740 100644
--- a/src/share/database/scripts/pgsql/upgrade_012_to_013.sh.in
+++ b/src/share/database/scripts/pgsql/upgrade_012_to_013.sh.in
@@ -36,7 +36,7 @@ fi
psql "$@" >/dev/null <<EOF
START TRANSACTION;
--- This line starts the schema upgrade to version 13.
+-- Upgrade to schema 13.0 begins here:
-- JSON functions --
@@ -669,11 +669,11 @@ CREATE UNIQUE INDEX key_dhcp6_identifier_subnet_id ON hosts
(dhcp_identifier ASC, dhcp_identifier_type ASC, dhcp6_subnet_id ASC)
WHERE (dhcp6_subnet_id IS NOT NULL);
--- Update the schema version number.
+-- Set 13.0 schema version.
UPDATE schema_version
SET version = '13', minor = '0';
--- This line concludes the schema upgrade to version 13.
+-- Schema 13.0 specification ends here.
-- Commit the script transaction.
COMMIT;
diff --git a/src/share/database/scripts/pgsql/upgrade_013_to_014.sh.in b/src/share/database/scripts/pgsql/upgrade_013_to_014.sh.in
index 5ea1cb02b8..413b82eec5 100644
--- a/src/share/database/scripts/pgsql/upgrade_013_to_014.sh.in
+++ b/src/share/database/scripts/pgsql/upgrade_013_to_014.sh.in
@@ -36,7 +36,7 @@ fi
psql "$@" >/dev/null <<EOF
START TRANSACTION;
--- This line starts the schema upgrade to version 14.
+-- Upgrade to schema 14.0 begins here:
-- Add cancelled (aka never-send) column to option tables.
@@ -53,11 +53,11 @@ ALTER TABLE dhcp4_subnet
ALTER TABLE dhcp4_client_class
ADD COLUMN offer_lifetime BIGINT DEFAULT NULL;
--- Update the schema version number.
+-- Set 14.0 schema version.
UPDATE schema_version
SET version = '14', minor = '0';
--- This line concludes the schema upgrade to version 14.
+-- Schema 14.0 specification ends here.
-- Commit the script transaction.
COMMIT;
diff --git a/src/share/database/scripts/pgsql/upgrade_014_to_015.sh.in b/src/share/database/scripts/pgsql/upgrade_014_to_015.sh.in
index 420e07f5b4..99056aeee4 100644
--- a/src/share/database/scripts/pgsql/upgrade_014_to_015.sh.in
+++ b/src/share/database/scripts/pgsql/upgrade_014_to_015.sh.in
@@ -36,12 +36,12 @@ fi
psql "$@" >/dev/null <<EOF
START TRANSACTION;
--- This line starts the schema upgrade to version 15.
+-- Upgrade to schema 15.0 begins here:
-- Add relay and remote id columns to DHCPv4 leases.
--
-- Note: these columns are only used for indexes, in particular they are
--- not exported by lease4 dump as values are also in the user context
+-- not exported by lease4 dump as values are also in the user context
ALTER TABLE lease4
ADD COLUMN relay_id BYTEA DEFAULT NULL,
ADD COLUMN remote_id BYTEA DEFAULT NULL;
@@ -50,11 +50,11 @@ ALTER TABLE lease4
CREATE INDEX lease4_by_relay_id ON lease4 (relay_id);
CREATE INDEX lease4_by_remote_id ON lease4 (remote_id);
--- Update the schema version number.
+-- Set 15.0 schema version.
UPDATE schema_version
SET version = '15', minor = '0';
--- This line concludes the schema upgrade to version 15.
+-- Schema 15.0 specification ends here.
-- Commit the script transaction.
COMMIT;
diff --git a/src/share/database/scripts/pgsql/upgrade_015_to_016.sh.in b/src/share/database/scripts/pgsql/upgrade_015_to_016.sh.in
index c123873579..e48acf52d2 100644
--- a/src/share/database/scripts/pgsql/upgrade_015_to_016.sh.in
+++ b/src/share/database/scripts/pgsql/upgrade_015_to_016.sh.in
@@ -36,7 +36,7 @@ fi
psql "$@" >/dev/null <<EOF
START TRANSACTION;
--- This line starts the schema upgrade to version 16.
+-- Upgrade to schema 16.0 begins here:
-- Add the allocator column to the DHCPv4 tables.
ALTER TABLE dhcp4_subnet ADD COLUMN allocator TEXT DEFAULT NULL;
@@ -50,11 +50,13 @@ ALTER TABLE dhcp6_subnet ADD COLUMN pd_allocator TEXT DEFAULT NULL;
ALTER TABLE dhcp6_shared_network ADD COLUMN allocator TEXT DEFAULT NULL;
ALTER TABLE dhcp6_shared_network ADD COLUMN pd_allocator TEXT DEFAULT NULL;
--- Update the schema version number.
+-- Set 16.0 schema version.
UPDATE schema_version
SET version = '16', minor = '0';
--- This line concludes the schema upgrade to version 16.
+-- Schema 16.0 specification ends here.
+
+UPDATE lease6 SET duid = E'\\\\x000000' WHERE duid = E'\\\\x00';
-- Commit the script transaction.
COMMIT;