From: Marcin Siodelski Date: Mon, 27 May 2019 12:18:16 +0000 (+0200) Subject: [#628,!341] interface-id is supported by the mysql_cb. X-Git-Tag: Kea-1.6.0-beta~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c1eabee5428b56a2b8b0fcaa8ce195c9b418c019;p=thirdparty%2Fkea.git [#628,!341] interface-id is supported by the mysql_cb. --- diff --git a/src/bin/admin/tests/mysql_tests.sh.in b/src/bin/admin/tests/mysql_tests.sh.in index 9d9e9d83bb..48f14363a7 100644 --- a/src/bin/admin/tests/mysql_tests.sh.in +++ b/src/bin/admin/tests/mysql_tests.sh.in @@ -563,7 +563,7 @@ EOF run_statement "dhcp6_option_def_server" "$qry" # table: dhcp6_shared_network - qry="select id, name, client_class, interface, modification_ts, preferred_lifetime, rapid_commit, rebind_timer, relay, renew_timer, require_client_classes, reservation_mode, user_context, valid_lifetime, calculate_tee_times, t1_percent, t2_percent from dhcp6_shared_network" + qry="select id, name, client_class, interface, modification_ts, preferred_lifetime, rapid_commit, rebind_timer, relay, renew_timer, require_client_classes, reservation_mode, user_context, valid_lifetime, calculate_tee_times, t1_percent, t2_percent, interface_id from dhcp6_shared_network" run_statement "dhcp6_shared_network" "$qry" # table: dhcp6_shared_network_server @@ -571,7 +571,7 @@ EOF run_statement "dhcp6_shared_network" "$qry" # table: dhcp6_subnet - qry="select subnet_prefix, client_class, interface, modification_ts, preferred_lifetime, rapid_commit, rebind_timer, relay, renew_timer, require_client_classes, reservation_mode, shared_network_name, subnet_id, user_context, valid_lifetime, calculate_tee_times, t1_percent, t2_percent from dhcp6_subnet" + qry="select subnet_prefix, client_class, interface, modification_ts, preferred_lifetime, rapid_commit, rebind_timer, relay, renew_timer, require_client_classes, reservation_mode, shared_network_name, subnet_id, user_context, valid_lifetime, calculate_tee_times, t1_percent, t2_percent, interface_id from dhcp6_subnet" run_statement "dhcp6_subnet" "$qry" # table: dhcp6_subnet_server diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc index a15c0a838e..789ae7e06f 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc @@ -307,6 +307,7 @@ public: MySqlBinding::createInteger(), // calculate_tee_times MySqlBinding::createInteger(), // t1_percent MySqlBinding::createInteger(), // t2_percent + MySqlBinding::createBlob(INTERFACE_ID_BUF_LENGTH), // interface_id MySqlBinding::createString(SERVER_TAG_BUF_LENGTH) // server_tag }; @@ -458,8 +459,18 @@ public: last_subnet->setT2Percent(out_bindings[67]->getFloat()); } + // interface_id + if (!out_bindings[68]->amNull()) { + auto iface_id_data = out_bindings[68]->getBlob(); + if (!iface_id_data.empty()) { + OptionPtr opt_iface_id(new Option(Option::V6, D6O_INTERFACE_ID, + iface_id_data)); + last_subnet->setInterfaceId(opt_iface_id); + } + } + // server_tag - last_subnet->setServerTag(out_bindings[68]->getString()); + last_subnet->setServerTag(out_bindings[69]->getString()); // Subnet ready. Add it to the list. subnets.push_back(last_subnet); @@ -910,6 +921,17 @@ public: shared_network_binding = MySqlBinding::createNull(); } + // Create the binding holding interface_id. + MySqlBindingPtr interface_id_binding = MySqlBinding::createNull(); + auto opt_iface_id = subnet->getInterfaceId(); + if (opt_iface_id) { + auto iface_id_data = opt_iface_id->getData(); + if (!iface_id_data.empty()) { + interface_id_binding = MySqlBinding::createBlob(iface_id_data.begin(), + iface_id_data.end()); + } + } + // Create input bindings. MySqlBindingCollection in_bindings = { MySqlBinding::createInteger(subnet->getID()), @@ -929,7 +951,8 @@ public: createBinding(subnet->getValid(Network::Inheritance::NONE)), MySqlBinding::condCreateBool(subnet->getCalculateTeeTimes(Network::Inheritance::NONE)), MySqlBinding::condCreateFloat(subnet->getT1Percent(Network::Inheritance::NONE)), - MySqlBinding::condCreateFloat(subnet->getT2Percent(Network::Inheritance::NONE)) + MySqlBinding::condCreateFloat(subnet->getT2Percent(Network::Inheritance::NONE)), + interface_id_binding }; MySqlTransaction transaction(conn_); @@ -1193,6 +1216,7 @@ public: MySqlBinding::createInteger(), // calculate_tee_times MySqlBinding::createInteger(), // t1_percent MySqlBinding::createInteger(), // t2_percent + MySqlBinding::createBlob(INTERFACE_ID_BUF_LENGTH), // interface_id MySqlBinding::createString(SERVER_TAG_BUF_LENGTH) // server_tag }; @@ -1314,8 +1338,18 @@ public: last_network->setT2Percent(out_bindings[29]->getFloat()); } + // interface_id + if (!out_bindings[30]->amNull()) { + auto iface_id_data = out_bindings[30]->getBlob(); + if (!iface_id_data.empty()) { + OptionPtr opt_iface_id(new Option(Option::V6, D6O_INTERFACE_ID, + iface_id_data)); + last_network->setInterfaceId(opt_iface_id); + } + } + // server_tag - last_network->setServerTag(out_bindings[30]->getString()); + last_network->setServerTag(out_bindings[31]->getString()); shared_networks.push_back(last_network); } @@ -1425,6 +1459,17 @@ public: hr_mode_binding = MySqlBinding::createNull(); } + // Create the binding holding interface_id. + MySqlBindingPtr interface_id_binding = MySqlBinding::createNull(); + auto opt_iface_id = shared_network->getInterfaceId(); + if (opt_iface_id) { + auto iface_id_data = opt_iface_id->getData(); + if (!iface_id_data.empty()) { + interface_id_binding = MySqlBinding::createBlob(iface_id_data.begin(), + iface_id_data.end()); + } + } + MySqlBindingCollection in_bindings = { MySqlBinding::createString(shared_network->getName()), MySqlBinding::condCreateString(shared_network->getClientClass(Network::Inheritance::NONE)), @@ -1441,7 +1486,8 @@ public: createBinding(shared_network->getValid(Network::Inheritance::NONE)), MySqlBinding::condCreateBool(shared_network->getCalculateTeeTimes(Network::Inheritance::NONE)), MySqlBinding::condCreateFloat(shared_network->getT1Percent(Network::Inheritance::NONE)), - MySqlBinding::condCreateFloat(shared_network->getT2Percent(Network::Inheritance::NONE)) + MySqlBinding::condCreateFloat(shared_network->getT2Percent(Network::Inheritance::NONE)), + interface_id_binding }; MySqlTransaction transaction(conn_); @@ -2317,8 +2363,9 @@ TaggedStatementArray tagged_statements = { { " valid_lifetime," " calculate_tee_times," " t1_percent," - " t2_percent " - ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" }, + " t2_percent," + " interface_id" + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" }, // Insert association of the subnet with a server. { MySqlConfigBackendDHCPv6Impl::INSERT_SUBNET6_SERVER, @@ -2353,8 +2400,9 @@ TaggedStatementArray tagged_statements = { { " valid_lifetime," " calculate_tee_times," " t1_percent," - " t2_percent " - ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" }, + " t2_percent," + " interface_id" + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" }, // Insert association of the shared network with a server. { MySqlConfigBackendDHCPv6Impl::INSERT_SHARED_NETWORK6_SERVER, @@ -2406,7 +2454,8 @@ TaggedStatementArray tagged_statements = { { " valid_lifetime = ?," " calculate_tee_times = ?," " t1_percent = ?," - " t2_percent = ? " + " t2_percent = ?," + " interface_id = ? " "WHERE subnet_id = ? OR subnet_prefix = ?" }, // Update existing shared network. @@ -2427,7 +2476,8 @@ TaggedStatementArray tagged_statements = { { " valid_lifetime = ?," " calculate_tee_times = ?," " t1_percent = ?," - " t2_percent = ? " + " t2_percent = ?," + " interface_id = ? " "WHERE name = ?" }, // Update existing option definition. diff --git a/src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h b/src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h index 9891efe0d3..748ea3ce8c 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h +++ b/src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h @@ -188,6 +188,7 @@ namespace { " s.calculate_tee_times," \ " s.t1_percent," \ " s.t2_percent," \ + " s.interface_id," \ " srv.tag " \ "FROM dhcp6_subnet AS s " \ "INNER JOIN dhcp6_subnet_server AS a " \ @@ -282,6 +283,7 @@ namespace { " n.calculate_tee_times," \ " n.t1_percent," \ " n.t2_percent," \ + " n.interface_id," \ " s.tag " \ "FROM dhcp6_shared_network AS n " \ "INNER JOIN dhcp6_shared_network_server AS a " \ diff --git a/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc b/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc index ebef76a34c..cceee99257 100644 --- a/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc +++ b/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc @@ -87,6 +87,8 @@ public: // First subnet includes all parameters. std::string interface_id_text = "whale"; OptionBuffer interface_id(interface_id_text.begin(), interface_id_text.end()); + OptionPtr opt_interface_id(new Option(Option::V6, D6O_INTERFACE_ID, + interface_id)); ElementPtr user_context = Element::createMap(); user_context->set("foo", Element::create("bar")); @@ -94,6 +96,7 @@ public: 64, 30, 40, 50, 60, 1024)); subnet->allowClientClass("home"); subnet->setIface("eth1"); + subnet->setInterfaceId(opt_interface_id); subnet->setT2(323212); subnet->addRelayAddress(IOAddress("2001:db8:1::2")); subnet->addRelayAddress(IOAddress("2001:db8:3::4")); @@ -206,9 +209,16 @@ public: ElementPtr user_context = Element::createMap(); user_context->set("foo", Element::create("bar")); + std::string interface_id_text = "fish"; + OptionBuffer interface_id(interface_id_text.begin(), + interface_id_text.end()); + OptionPtr opt_interface_id(new Option(Option::V6, D6O_INTERFACE_ID, + interface_id)); + SharedNetwork6Ptr shared_network(new SharedNetwork6("level1")); shared_network->allowClientClass("foo"); shared_network->setIface("eth1"); + shared_network->setInterfaceId(opt_interface_id); shared_network->setT2(323212); shared_network->addRelayAddress(IOAddress("2001:db8:1::2")); shared_network->addRelayAddress(IOAddress("2001:db8:3::4")); diff --git a/src/lib/config_backend/constants.h b/src/lib/config_backend/constants.h index 8cbd993ca5..81a6307436 100644 --- a/src/lib/config_backend/constants.h +++ b/src/lib/config_backend/constants.h @@ -34,6 +34,8 @@ constexpr unsigned long CLIENT_CLASS_BUF_LENGTH = 128; constexpr unsigned long INTERFACE_BUF_LENGTH = 128; +constexpr unsigned long INTERFACE_ID_BUF_LENGTH = 128; + constexpr unsigned long RELAY_BUF_LENGTH = 65536; constexpr unsigned long REQUIRE_CLIENT_CLASSES_BUF_LENGTH = 65536; diff --git a/src/share/database/scripts/mysql/dhcpdb_create.mysql b/src/share/database/scripts/mysql/dhcpdb_create.mysql index a18874dac7..f39e4be2c2 100644 --- a/src/share/database/scripts/mysql/dhcpdb_create.mysql +++ b/src/share/database/scripts/mysql/dhcpdb_create.mysql @@ -1373,7 +1373,8 @@ ALTER TABLE dhcp4_shared_network ALTER TABLE dhcp6_subnet ADD COLUMN calculate_tee_times TINYINT(1) DEFAULT NULL, ADD COLUMN t1_percent FLOAT DEFAULT NULL, - ADD COLUMN t2_percent FLOAT DEFAULT NULL; + ADD COLUMN t2_percent FLOAT DEFAULT NULL, + ADD COLUMN interface_id VARBINARY(128) DEFAULT NULL; ALTER TABLE dhcp6_subnet MODIFY COLUMN reservation_mode TINYINT(3) DEFAULT NULL; @@ -1384,7 +1385,8 @@ ALTER TABLE dhcp6_subnet ALTER TABLE dhcp6_shared_network ADD COLUMN calculate_tee_times TINYINT(1) DEFAULT NULL, ADD COLUMN t1_percent FLOAT DEFAULT NULL, - ADD COLUMN t2_percent FLOAT DEFAULT NULL; + ADD COLUMN t2_percent FLOAT DEFAULT NULL, + ADD COLUMN interface_id VARBINARY(128) DEFAULT NULL; ALTER TABLE dhcp6_shared_network MODIFY COLUMN reservation_mode TINYINT(3) DEFAULT NULL; diff --git a/src/share/database/scripts/mysql/upgrade_7.0_to_8.0.sh.in b/src/share/database/scripts/mysql/upgrade_7.0_to_8.0.sh.in index 989f677893..ec4f45acc0 100644 --- a/src/share/database/scripts/mysql/upgrade_7.0_to_8.0.sh.in +++ b/src/share/database/scripts/mysql/upgrade_7.0_to_8.0.sh.in @@ -56,7 +56,8 @@ ALTER TABLE dhcp4_shared_network ALTER TABLE dhcp6_subnet ADD COLUMN calculate_tee_times TINYINT(1) DEFAULT NULL, ADD COLUMN t1_percent FLOAT DEFAULT NULL, - ADD COLUMN t2_percent FLOAT DEFAULT NULL; + ADD COLUMN t2_percent FLOAT DEFAULT NULL, + ADD COLUMN interface_id VARCHAR(128) DEFAULT NULL; ALTER TABLE dhcp6_subnet MODIFY COLUMN reservation_mode TINYINT(3) DEFAULT NULL; @@ -67,7 +68,8 @@ ALTER TABLE dhcp6_subnet ALTER TABLE dhcp6_shared_network ADD COLUMN calculate_tee_times TINYINT(1) DEFAULT NULL, ADD COLUMN t1_percent FLOAT DEFAULT NULL, - ADD COLUMN t2_percent FLOAT DEFAULT NULL; + ADD COLUMN t2_percent FLOAT DEFAULT NULL, + ADD COLUMN interface_id VARCHAR(128) DEFAULT NULL; ALTER TABLE dhcp6_shared_network MODIFY COLUMN reservation_mode TINYINT(3) DEFAULT NULL;