From: Francis Dupont Date: Wed, 11 Sep 2019 18:08:14 +0000 (+0200) Subject: [897-add-infinite-valid-lifetime] Checkpoint: updated MySQL CB code (todo unit tests) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f264ac5fb59154fa0bb225b281254dfb34accd5f;p=thirdparty%2Fkea.git [897-add-infinite-valid-lifetime] Checkpoint: updated MySQL CB code (todo unit tests) --- diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc index bec9a1ccf0..17348f4924 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc @@ -310,6 +310,7 @@ public: MySqlBinding::createString(CLIENT_CLASS_BUF_LENGTH), // pool: client_class MySqlBinding::createString(REQUIRE_CLIENT_CLASSES_BUF_LENGTH), // pool: require_client_classes MySqlBinding::createString(USER_CONTEXT_BUF_LENGTH), // pool: user_context + MySqlBinding::createInteger(), // allow_static_leases MySqlBinding::createString(SERVER_TAG_BUF_LENGTH) // server_tag }; @@ -425,6 +426,7 @@ public: last_subnet->addRelayAddress(IOAddress(relay_element->get(i)->stringValue())); } } + // require_client_classes ElementPtr require_element = out_bindings[14]->getJSON(); if (require_element) { @@ -488,7 +490,12 @@ public: // pool client_class, require_client_classes and user_context - // server_tag at 58 + // allow_static_leases + if (!out_bindings[58]->amNull()) { + last_subnet->setAllowStaticLeases(out_bindings[58]->getBool()); + } + + // server_tag at 59 // Subnet ready. Add it to the list. auto ret = subnets.push_back(last_subnet); @@ -502,9 +509,9 @@ public: } // Check for new server tags. - if (!out_bindings[58]->amNull() && - (last_tag != out_bindings[58]->getString())) { - last_tag = out_bindings[58]->getString(); + if (!out_bindings[59]->amNull() && + (last_tag != out_bindings[59]->getString())) { + last_tag = out_bindings[59]->getString(); if (!last_tag.empty() && !last_subnet->hasServerTag(ServerTag(last_tag))) { last_subnet->setServerTag(last_tag); } @@ -962,7 +969,8 @@ public: MySqlBinding::condCreateBool(subnet->getCalculateTeeTimes(Network::Inheritance::NONE)), MySqlBinding::condCreateFloat(subnet->getT1Percent(Network::Inheritance::NONE)), MySqlBinding::condCreateFloat(subnet->getT2Percent(Network::Inheritance::NONE)), - MySqlBinding::condCreateBool(subnet->getAuthoritative(Network::Inheritance::NONE)) + MySqlBinding::condCreateBool(subnet->getAuthoritative(Network::Inheritance::NONE)), + MySqlBinding::condCreateBool(subnet->getAllowStaticLeases(Network::Inheritance::NONE)), }; MySqlTransaction transaction(conn_); @@ -1200,6 +1208,7 @@ public: MySqlBinding::createString(SERVER_HOSTNAME_BUF_LENGTH), // server_hostname MySqlBinding::createInteger(), // min_valid_lifetime MySqlBinding::createInteger(), // max_valid_lifetime + MySqlBinding::createInteger(), // allow_static_leases MySqlBinding::createString(SERVER_TAG_BUF_LENGTH) // server_tag }; @@ -1346,6 +1355,11 @@ public: // {min,max}_valid_lifetime + // allow_static_leases + if (!out_bindings[34]->amNull()) { + last_network->setAllowStaticLeases(out_bindings[34]->getBool()); + } + // Add the shared network. auto ret = shared_networks.push_back(last_network); @@ -1358,9 +1372,9 @@ public: } // Check for new server tags. - if (!out_bindings[34]->amNull() && - (last_tag != out_bindings[34]->getString())) { - last_tag = out_bindings[34]->getString(); + if (!out_bindings[35]->amNull() && + (last_tag != out_bindings[35]->getString())) { + last_tag = out_bindings[35]->getString(); if (!last_tag.empty() && !last_network->hasServerTag(ServerTag(last_tag))) { last_network->setServerTag(last_tag); } @@ -1507,7 +1521,8 @@ public: MySqlBinding::condCreateBool(shared_network->getAuthoritative(Network::Inheritance::NONE)), MySqlBinding::condCreateString(shared_network->getFilename(Network::Inheritance::NONE)), MySqlBinding::condCreateIPv4Address(shared_network->getSiaddr(Network::Inheritance::NONE)), - MySqlBinding::condCreateString(shared_network->getSname(Network::Inheritance::NONE)) + MySqlBinding::condCreateString(shared_network->getSname(Network::Inheritance::NONE)), + MySqlBinding::condCreateBool(shared_network->getAllowStaticLeases(Network::Inheritance::NONE)) }; MySqlTransaction transaction(conn_); @@ -2348,9 +2363,10 @@ TaggedStatementArray tagged_statements = { { " calculate_tee_times," " t1_percent," " t2_percent," - " authoritative" + " authoritative," + " allow_static_leases" ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?," - "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" }, + "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" }, // Insert association of the subnet with a server. { MySqlConfigBackendDHCPv4Impl::INSERT_SUBNET4_SERVER, @@ -2385,9 +2401,10 @@ TaggedStatementArray tagged_statements = { { " authoritative," " boot_file_name," " next_server," - " server_hostname" + " server_hostname," + " allow_static_leases" ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?," - " ?, ?, ?, ?, ?, ?, ?, ?, ?)" }, + " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" }, // Insert association of the shared network with a server. { MySqlConfigBackendDHCPv4Impl::INSERT_SHARED_NETWORK4_SERVER, @@ -2452,7 +2469,8 @@ TaggedStatementArray tagged_statements = { { " calculate_tee_times = ?," " t1_percent = ?," " t2_percent = ?," - " authoritative = ? " + " authoritative = ?," + " allow_static_leases = ? " "WHERE subnet_id = ? OR subnet_prefix = ?" }, // Update existing shared network. @@ -2478,7 +2496,8 @@ TaggedStatementArray tagged_statements = { { " authoritative = ?," " boot_file_name = ?," " next_server = ?," - " server_hostname = ? " + " server_hostname = ?," + " allow_static_leases = ? " "WHERE name = ?" }, // Update existing option definition. diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc index 14ffaf363c..f04dd1e1e7 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc @@ -344,6 +344,7 @@ public: MySqlBinding::createString(CLIENT_CLASS_BUF_LENGTH), // pd pool: client_class MySqlBinding::createString(REQUIRE_CLIENT_CLASSES_BUF_LENGTH), // pd pool: require_client_classes MySqlBinding::createString(USER_CONTEXT_BUF_LENGTH), // pd pool: user_context + MySqlBinding::createInteger(), // allow_static_leases MySqlBinding::createString(SERVER_TAG_BUF_LENGTH) // server_tag }; @@ -525,7 +526,12 @@ public: // 79 is pd pool require_client_classes // 80 is pd pool user_context - // server_tag (81 / last) + // allow_static_leases (81) + if (!out_bindings[81]->amNull()) { + last_subnet->setAllowStaticLeases(out_bindings[81]->getBool()); + } + + // server_tag (82 / last) // Subnet ready. Add it to the list. auto ret = subnets.push_back(last_subnet); @@ -539,9 +545,9 @@ public: } // Check for new server tags. - if (!out_bindings[81]->amNull() && - (last_tag != out_bindings[81]->getString())) { - last_tag = out_bindings[81]->getString(); + if (!out_bindings[82]->amNull() && + (last_tag != out_bindings[82]->getString())) { + last_tag = out_bindings[82]->getString(); if (!last_tag.empty() && !last_subnet->hasServerTag(ServerTag(last_tag))) { last_subnet->setServerTag(last_tag); } @@ -1210,6 +1216,7 @@ public: MySqlBinding::condCreateBool(subnet->getCalculateTeeTimes(Network::Inheritance::NONE)), MySqlBinding::condCreateFloat(subnet->getT1Percent(Network::Inheritance::NONE)), MySqlBinding::condCreateFloat(subnet->getT2Percent(Network::Inheritance::NONE)), + MySqlBinding::condCreateBool(subnet->getAllowStaticLeases(Network::Inheritance::NONE)), interface_id_binding }; @@ -1524,6 +1531,7 @@ public: MySqlBinding::createInteger(), // max_preferred_lifetime MySqlBinding::createInteger(), // min_valid_lifetime MySqlBinding::createInteger(), // max_valid_lifetime + MySqlBinding::createInteger(), // allow_static_leases MySqlBinding::createString(SERVER_TAG_BUF_LENGTH) // server_tag }; @@ -1669,6 +1677,11 @@ public: // {min,max)_valid_lifetime + // allow_static_leases + if (!out_bindings[35]->amNull()) { + last_network->setAllowStaticLeases(out_bindings[35]->getBool()); + } + // Add the shared network. auto ret = shared_networks.push_back(last_network); @@ -1692,9 +1705,9 @@ public: } // Check for new server tags. - if (!out_bindings[35]->amNull() && - (last_tag != out_bindings[35]->getString())) { - last_tag = out_bindings[35]->getString(); + if (!out_bindings[36]->amNull() && + (last_tag != out_bindings[36]->getString())) { + last_tag = out_bindings[36]->getString(); if (!last_tag.empty() && !last_network->hasServerTag(ServerTag(last_tag))) { last_network->setServerTag(last_tag); } @@ -1841,6 +1854,7 @@ public: 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::condCreateBool(shared_network->getAllowStaticLeases(Network::Inheritance::NONE)), interface_id_binding }; @@ -2807,9 +2821,10 @@ TaggedStatementArray tagged_statements = { { " calculate_tee_times," " t1_percent," " t2_percent," + " allow_static_leases," " interface_id" ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?," - " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" }, + " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" }, // Insert association of the subnet with a server. { MySqlConfigBackendDHCPv6Impl::INSERT_SUBNET6_SERVER, @@ -2849,9 +2864,10 @@ TaggedStatementArray tagged_statements = { { " calculate_tee_times," " t1_percent," " t2_percent," + " allow_static_leases," " interface_id" ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?," - " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" }, + " ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" }, // Insert association of the shared network with a server. { MySqlConfigBackendDHCPv6Impl::INSERT_SHARED_NETWORK6_SERVER, @@ -2913,6 +2929,7 @@ TaggedStatementArray tagged_statements = { { " calculate_tee_times = ?," " t1_percent = ?," " t2_percent = ?," + " allow_static_leases = ?," " interface_id = ? " "WHERE subnet_id = ? OR subnet_prefix = ?" }, @@ -2939,6 +2956,7 @@ TaggedStatementArray tagged_statements = { { " calculate_tee_times = ?," " t1_percent = ?," " t2_percent = ?," + " allow_static_leases = ?," " interface_id = ? " "WHERE name = ?" }, 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 7353a145b1..45ca9821a4 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h +++ b/src/hooks/dhcp/mysql_cb/mysql_query_macros_dhcp.h @@ -109,6 +109,7 @@ namespace { " p.client_class," \ " p.require_client_classes," \ " p.user_context," \ + " s.allow_static_leases," \ " srv.tag " \ "FROM dhcp4_subnet AS s " \ server_join \ @@ -228,6 +229,7 @@ namespace { " d.client_class," \ " d.require_client_classes," \ " d.user_context," \ + " s.allow_static_leases," \ " srv.tag " \ "FROM dhcp6_subnet AS s " \ server_join \ @@ -427,6 +429,7 @@ namespace { " n.server_hostname," \ " n.min_valid_lifetime," \ " n.max_valid_lifetime," \ + " n.allow_static_leases," \ " s.tag " \ "FROM dhcp4_shared_network AS n " \ server_join \ @@ -498,6 +501,7 @@ namespace { " n.max_preferred_lifetime," \ " n.min_valid_lifetime," \ " n.max_valid_lifetime," \ + " n.allow_static_leases," \ " s.tag " \ "FROM dhcp6_shared_network AS n " \ server_join \