From: Razvan Becheriu Date: Mon, 13 Mar 2023 18:00:19 +0000 (+0200) Subject: [#2786] 255 bytes client_id and 130 bytes duid X-Git-Tag: Kea-2.3.8~164 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa5492d4b7064e425ecb5313d2496acef736d363;p=thirdparty%2Fkea.git [#2786] 255 bytes client_id and 130 bytes duid --- 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ˎxampleˌom,38:30,2,{ "a": 1, "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ˎxampleˌom,38:30,2,{ "a": 1, "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ˎxampleˌom,0,{"a":1,"b":2}' } memfile_data_v6() { - printf '::10,32:30,30,1678900000,40,50,1,60,70,1,1,oneˎxampleˌom,38:30,0,{"a":1,"b":2},90,16' + printf '::10,32:30:33,30,1678900000,40,50,1,60,70,1,1,oneˎxampleˌom,38:30,0,{"a":1,"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 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 duid_; + std::vector 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, &Client::duid_ + Client, std::vector, &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& vec = context->clientid_->getDuid(); + const std::vector& 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& vec = context->clientid_->getDuid(); + const std::vector& 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(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 @@ -100,6 +100,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, @@ -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 #include #include -#include #include #include #include @@ -20,37 +19,24 @@ namespace isc { namespace dhcp { -DUID::DUID(const std::vector& 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& data) : IdentifierType<3, 130>(data) { +} - duid_ = std::vector(data, data + len); +DUID::DUID(const uint8_t* data, size_t len) : IdentifierType<3, 130>(data, len) { } const std::vector& 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(type)); } else { @@ -60,90 +46,28 @@ DUID::DUIDType DUID::getType() const { DUID DUID::fromText(const std::string& text) { - std::vector binary; - util::str::decodeFormattedHexString(text, binary); - return (DUID(binary)); + return (DUID(IdentifierType::fromText(text))); } const DUID& DUID::EMPTY() { - static std::vector 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::const_iterator it = duid_.begin(); - it != duid_.end(); ++it) { - if (delim) { - tmp << ":"; - } - tmp << std::setw(2) << std::setfill('0') << static_cast(*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& data) : IdentifierType<2, 255>(data) { } -// Constructor based on vector -ClientId::ClientId(const std::vector& 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& 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 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 +#include #include #include #include @@ -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 IdentifierBaseTypePtr; + +template +class IdentifierType : public IdentifierBaseType { +public: + + /// @brief Constructor from vector + /// + /// @param data The data used to create the IdentifierType + IdentifierType(const std::vector& 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(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(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 fromText(const std::string& text) { + std::vector 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 data_; +}; + /// @brief Shared pointer to a DUID class DUID; typedef boost::shared_ptr DuidPtr; @@ -24,15 +135,16 @@ typedef boost::shared_ptr 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& duid); + /// + /// @param data The data used to create the DUID + DUID(const std::vector& 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 duid_; }; /// @brief Forward declaration to the @c ClientId class. @@ -108,30 +211,31 @@ typedef boost::shared_ptr 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 - ClientId(const std::vector& clientid); + /// + /// @param data The data used to create the ClientId + ClientId(const std::vector& 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& 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 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': -// ~/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 data2(data1, data1 + sizeof(data1)); - scoped_ptr duid1(new DUID(data1, sizeof(data1))); - scoped_ptr duid2(new DUID(data2)); + boost::scoped_ptr duid1(new DUID(data1, sizeof(data1))); + boost::scoped_ptr duid2(new DUID(data2)); vector 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 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 duidmaxsize1(new DUID(data, MAX_DUID_LEN)); - scoped_ptr duidmaxsize2(new DUID(data2)); + boost::scoped_ptr duidmaxsize1(new DUID(data, DUID::MAX_DUID_LEN)); + boost::scoped_ptr duidmaxsize2(new DUID(data2)); EXPECT_THROW( - scoped_ptr toolarge1(new DUID(data, MAX_DUID_LEN + 1)), + boost::scoped_ptr toolarge1(new DUID(data, DUID::MAX_DUID_LEN + 1)), BadValue); // that's one too much data2.push_back(128); EXPECT_THROW( - scoped_ptr toolarge2(new DUID(data2)), + boost::scoped_ptr toolarge2(new DUID(data2)), BadValue); // empty duids are not allowed vector empty; EXPECT_THROW( - scoped_ptr emptyDuid(new DUID(empty)), + boost::scoped_ptr emptyDuid(new DUID(empty)), BadValue); EXPECT_THROW( - scoped_ptr emptyDuid2(new DUID(data, 0)), + boost::scoped_ptr 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_llt(new DUID(llt, sizeof(llt))); - scoped_ptr duid_en(new DUID(en, sizeof(en))); - scoped_ptr duid_ll(new DUID(ll, sizeof(ll))); - scoped_ptr duid_uuid(new DUID(uuid, sizeof(uuid))); - scoped_ptr duid_invalid(new DUID(invalid, sizeof(invalid))); + boost::scoped_ptr duid_llt(new DUID(llt, sizeof(llt))); + boost::scoped_ptr duid_en(new DUID(en, sizeof(en))); + boost::scoped_ptr duid_ll(new DUID(ll, sizeof(ll))); + boost::scoped_ptr duid_uuid(new DUID(uuid, sizeof(uuid))); + boost::scoped_ptr 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; + boost::scoped_ptr 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({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 duid1(new DUID(data1, sizeof(data1))); - scoped_ptr duid2(new DUID(data2, sizeof(data2))); - scoped_ptr duid3(new DUID(data3, sizeof(data3))); - scoped_ptr duid4(new DUID(data4, sizeof(data4))); + boost::scoped_ptr duid1(new DUID(data1, sizeof(data1))); + boost::scoped_ptr duid2(new DUID(data2, sizeof(data2))); + boost::scoped_ptr duid3(new DUID(data3, sizeof(data3))); + boost::scoped_ptr duid4(new DUID(data4, sizeof(data4))); EXPECT_TRUE(*duid1 == *duid4); EXPECT_FALSE(*duid1 == *duid2); @@ -212,12 +204,12 @@ TEST(ClientIdTest, constructor) { vector data2(data1, data1 + sizeof(data1)); // checks for C-style constructor (uint8_t * + len) - scoped_ptr id1(new ClientId(data1, sizeof(data1))); + boost::scoped_ptr id1(new ClientId(data1, sizeof(data1))); vector vecdata = id1->getClientId(); EXPECT_TRUE(data2 == vecdata); // checks for vector-based constructor - scoped_ptr id2(new ClientId(data2)); + boost::scoped_ptr 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 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(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 duidmaxsize1(new ClientId(data, MAX_CLIENT_ID_LEN)); - scoped_ptr duidmaxsize2(new ClientId(data2)); + boost::scoped_ptr duidmaxsize1(new ClientId(data, ClientId::MAX_CLIENT_ID_LEN)); + boost::scoped_ptr duidmaxsize2(new ClientId(data2)); EXPECT_THROW( - scoped_ptr toolarge1(new ClientId(data, MAX_CLIENT_ID_LEN + 1)), + boost::scoped_ptr 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 toolarge2(new ClientId(data2)), + boost::scoped_ptr toolarge2(new ClientId(data2)), BadValue); // empty client-ids are not allowed vector empty; EXPECT_THROW( - scoped_ptr empty_client_id1(new ClientId(empty)), + boost::scoped_ptr empty_client_id1(new ClientId(empty)), BadValue); EXPECT_THROW( - scoped_ptr empty_client_id2(new ClientId(data, 0)), + boost::scoped_ptr empty_client_id2(new ClientId(data, 0)), BadValue); // client-id must be at least 2 bytes long vector shorty(1,17); // just a single byte with value 17 EXPECT_THROW( - scoped_ptr too_short_client_id1(new ClientId(shorty)), + boost::scoped_ptr too_short_client_id1(new ClientId(shorty)), BadValue); EXPECT_THROW( - scoped_ptr too_short_client_id1(new ClientId(data, 1)), + boost::scoped_ptr 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 id1(new ClientId(data1, sizeof(data1))); - scoped_ptr id2(new ClientId(data2, sizeof(data2))); - scoped_ptr id3(new ClientId(data3, sizeof(data3))); - scoped_ptr id4(new ClientId(data4, sizeof(data4))); + boost::scoped_ptr id1(new ClientId(data1, sizeof(data1))); + boost::scoped_ptr id2(new ClientId(data2, sizeof(data2))); + boost::scoped_ptr id3(new ClientId(data3, sizeof(data3))); + boost::scoped_ptr 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 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 duid_data(128, 1); + std::vector 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(&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(dhcp_identifier_buffer_), &(host->getIdentifier())[0], @@ -422,7 +422,7 @@ public: bind_[0].buffer = reinterpret_cast(&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(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(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(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(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(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(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(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 clientid_vec(i, i); + for (uint16_t i = client_id_min; i <= client_id_max; i += 16) { + uint8_t data = static_cast(i); + vector 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 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 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, ',', ','), + state, + REPLACE(user_context, ',', ',') + ); +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, ',', ','), + UNHEX(REPLACE(hwaddr, ':', '')), + state, + REPLACE(user_context, ',', ','), + 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 "$@" </dev/null </dev/null </dev/null </dev/null </dev/null </dev/null </dev/null </dev/null </dev/null </dev/null </dev/null </dev/null </dev/null </dev/null </dev/null </dev/null </dev/null </dev/null </dev/null <