GET_MODIFIED_SUBNETS4_UNASSIGNED,
GET_SHARED_NETWORK_SUBNETS4,
GET_POOL4_RANGE,
+ GET_POOL4_RANGE_ANY,
GET_SHARED_NETWORK4_NAME_NO_TAG,
GET_SHARED_NETWORK4_NAME_ANY,
GET_SHARED_NETWORK4_NAME_UNASSIGNED,
PoolCollection pools;
std::vector<uint64_t> pool_ids;
- auto tags = server_selector.getTags();
- for (auto tag : tags) {
- MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag.get()),
- MySqlBinding::createInteger<uint32_t>(pool_start_address.toUint32()),
- MySqlBinding::createInteger<uint32_t>(pool_end_address.toUint32())
- };
+ if (server_selector.amAny()) {
+ MySqlBindingCollection in_bindings = {
+ MySqlBinding::createInteger<uint32_t>(pool_start_address.toUint32()),
+ MySqlBinding::createInteger<uint32_t>(pool_end_address.toUint32())
+ };
+ getPools(GET_POOL4_RANGE_ANY, in_bindings, pools, pool_ids);
- getPools(GET_POOL4_RANGE, in_bindings, pools, pool_ids);
- // Break if something is found?
+ } else {
+ auto tags = server_selector.getTags();
+ for (auto tag : tags) {
+ MySqlBindingCollection in_bindings = {
+ MySqlBinding::createString(tag.get()),
+ MySqlBinding::createInteger<uint32_t>(pool_start_address.toUint32()),
+ MySqlBinding::createInteger<uint32_t>(pool_end_address.toUint32())
+ };
+
+ getPools(GET_POOL4_RANGE, in_bindings, pools, pool_ids);
+ // Break if something is found?
+ }
}
if (!pools.empty()) {
MYSQL_GET_SUBNET4_ANY(WHERE s.shared_network_name = ?)
},
- // Select pool by address range.
+ // Select pool by address range for a server.
{ MySqlConfigBackendDHCPv4Impl::GET_POOL4_RANGE,
- "SELECT"
- " p.id,"
- " p.start_address,"
- " p.end_address,"
- " p.subnet_id,"
- " p.client_class,"
- " p.require_client_classes,"
- " p.user_context,"
- " p.modification_ts,"
- " x.option_id,"
- " x.code,"
- " x.value,"
- " x.formatted_value,"
- " x.space,"
- " x.persistent,"
- " x.dhcp4_subnet_id,"
- " x.scope_id,"
- " x.user_context,"
- " x.shared_network_name,"
- " x.pool_id,"
- " x.modification_ts "
- "FROM dhcp4_pool AS p "
- "INNER JOIN dhcp4_subnet_server AS s ON p.subnet_id = s.subnet_id "
- "INNER JOIN dhcp4_server AS srv "
- " ON (s.server_id = srv.id) OR (s.server_id = 1) "
- "LEFT JOIN dhcp4_options AS x ON x.scope_id = 5 AND p.id = x.pool_id "
- "WHERE (srv.tag = ? OR srv.id = 1) "
- " AND p.start_address = ? AND p.end_address = ? "
- "ORDER BY p.id, x.option_id"
+ MYSQL_GET_POOL4_RANGE_WITH_TAG(WHERE (srv.tag = ? OR srv.id = 1) AND p.start_address = ? \
+ AND p.end_address = ?)
+ },
+
+ // Select pool by address range for any server
+ { MySqlConfigBackendDHCPv4Impl::GET_POOL4_RANGE_ANY,
+ MYSQL_GET_POOL4_RANGE_NO_TAG(WHERE p.start_address = ? AND p.end_address = ?)
},
// Select shared network by name.
GET_MODIFIED_SUBNETS6_UNASSIGNED,
GET_SHARED_NETWORK_SUBNETS6,
GET_POOL6_RANGE,
+ GET_POOL6_RANGE_ANY,
GET_PD_POOL,
+ GET_PD_POOL_ANY,
GET_SHARED_NETWORK6_NAME_NO_TAG,
GET_SHARED_NETWORK6_NAME_ANY,
GET_SHARED_NETWORK6_NAME_UNASSIGNED,
PoolCollection pools;
std::vector<uint64_t> pool_ids;
- auto tags = server_selector.getTags();
- for (auto tag : tags) {
+ if (server_selector.amAny()) {
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag.get()),
- MySqlBinding::createString(pool_start_address.toText()),
- MySqlBinding::createString(pool_end_address.toText())
+ MySqlBinding::createString(pool_start_address.toText()),
+ MySqlBinding::createString(pool_end_address.toText())
};
+ getPools(GET_POOL6_RANGE_ANY, in_bindings, pools, pool_ids);
- getPools(GET_POOL6_RANGE, in_bindings, pools, pool_ids);
+ } else {
+ auto tags = server_selector.getTags();
+ for (auto tag : tags) {
+ MySqlBindingCollection in_bindings = {
+ MySqlBinding::createString(tag.get()),
+ MySqlBinding::createString(pool_start_address.toText()),
+ MySqlBinding::createString(pool_end_address.toText())
+ };
+ getPools(GET_POOL6_RANGE, in_bindings, pools, pool_ids);
- // Return upon the first pool found.
- if (!pools.empty()) {
- pool_id = pool_ids[0];
- return (boost::dynamic_pointer_cast<Pool6>(*pools.begin()));
}
}
+ // Return upon the first pool found.
+ if (!pools.empty()) {
+ pool_id = pool_ids[0];
+ return (boost::dynamic_pointer_cast<Pool6>(*pools.begin()));
+ }
+
pool_id = 0;
return (Pool6Ptr());
}
PoolCollection pd_pools;
std::vector<uint64_t> pd_pool_ids;
- auto tags = server_selector.getTags();
- for (auto tag : tags) {
+ if (server_selector.amAny()) {
MySqlBindingCollection in_bindings = {
- MySqlBinding::createString(tag.get()),
MySqlBinding::createString(pd_pool_prefix.toText()),
MySqlBinding::createInteger<uint8_t>(pd_pool_prefix_length)
};
+ getPdPools(GET_PD_POOL_ANY, in_bindings, pd_pools, pd_pool_ids);
- getPdPools(GET_PD_POOL, in_bindings, pd_pools, pd_pool_ids);
- // Break if something is found?
+ } else {
+ auto tags = server_selector.getTags();
+ for (auto tag : tags) {
+ MySqlBindingCollection in_bindings = {
+ MySqlBinding::createString(tag.get()),
+ MySqlBinding::createString(pd_pool_prefix.toText()),
+ MySqlBinding::createInteger<uint8_t>(pd_pool_prefix_length)
+ };
+ getPdPools(GET_PD_POOL, in_bindings, pd_pools, pd_pool_ids);
+ }
}
if (!pd_pools.empty()) {
" (unassigned) is unsupported at the moment");
}
- auto tag = getServerTag(server_selector,
- "creating or updating subnet level option");
-
MySqlBindingCollection in_bindings = {
MySqlBinding::createInteger<uint16_t>(option->option_->getType()),
createOptionValueBinding(option),
MYSQL_GET_SUBNET6_ANY(WHERE s.shared_network_name = ?)
},
- // Select pool by address range.
+ // Select pool by address range for a server.
{ MySqlConfigBackendDHCPv6Impl::GET_POOL6_RANGE,
- "SELECT"
- " p.id,"
- " p.start_address,"
- " p.end_address,"
- " p.subnet_id,"
- " p.client_class,"
- " p.require_client_classes,"
- " p.user_context,"
- " p.modification_ts,"
- " x.option_id,"
- " x.code,"
- " x.value,"
- " x.formatted_value,"
- " x.space,"
- " x.persistent,"
- " x.dhcp6_subnet_id,"
- " x.scope_id,"
- " x.user_context,"
- " x.shared_network_name,"
- " x.pool_id,"
- " x.modification_ts,"
- " x.pd_pool_id "
- "FROM dhcp6_pool AS p "
- "INNER JOIN dhcp6_subnet_server AS s ON p.subnet_id = s.subnet_id "
- "INNER JOIN dhcp6_server AS srv "
- " ON (s.server_id = srv.id) OR (s.server_id = 1) "
- "LEFT JOIN dhcp6_options AS x ON x.scope_id = 5 AND p.id = x.pool_id "
- "WHERE (srv.tag = ? OR srv.id = 1) "
- " AND p.start_address = ? AND p.end_address = ? "
- "ORDER BY p.id, x.option_id"
- },
-
- // Select prefix delegation pool.
+ MYSQL_GET_POOL6_RANGE_WITH_TAG(WHERE (srv.tag = ? OR srv.id = 1) AND p.start_address = ? \
+ AND p.end_address = ?)
+ },
+
+ // Select pool by address range for any server.
+ { MySqlConfigBackendDHCPv6Impl::GET_POOL6_RANGE_ANY,
+ MYSQL_GET_POOL6_RANGE_NO_TAG(WHERE p.start_address = ? AND p.end_address = ?)
+ },
+
+ // Select prefix delegation pool for a server.
{ MySqlConfigBackendDHCPv6Impl::GET_PD_POOL,
- "SELECT"
- " p.id,"
- " p.prefix,"
- " p.prefix_length,"
- " p.delegated_prefix_length,"
- " p.subnet_id,"
- " p.excluded_prefix,"
- " p.excluded_prefix_length,"
- " p.client_class,"
- " p.require_client_classes,"
- " p.user_context,"
- " p.modification_ts,"
- " x.option_id,"
- " x.code,"
- " x.value,"
- " x.formatted_value,"
- " x.space,"
- " x.persistent,"
- " x.dhcp6_subnet_id,"
- " x.scope_id,"
- " x.user_context,"
- " x.shared_network_name,"
- " x.pool_id,"
- " x.modification_ts,"
- " x.pd_pool_id "
- "FROM dhcp6_pd_pool AS p "
- "INNER JOIN dhcp6_subnet_server AS s ON p.subnet_id = s.subnet_id "
- "INNER JOIN dhcp6_server AS srv "
- " ON (s.server_id = srv.id) OR (s.server_id = 1) "
- "LEFT JOIN dhcp6_options AS x ON x.scope_id = 6 AND p.id = x.pd_pool_id "
- "WHERE (srv.tag = ? OR srv.id = 1) "
- " AND p.prefix = ? AND p.prefix_length = ? "
- "ORDER BY p.id, x.option_id"
+ MYSQL_GET_PD_POOL_WITH_TAG(WHERE (srv.tag = ? OR srv.id = 1) \
+ AND p.prefix = ? AND p.prefix_length = ?)
+ },
+
+ // Select prefix delegation pool for any server.
+ { MySqlConfigBackendDHCPv6Impl::GET_PD_POOL_ANY,
+ MYSQL_GET_PD_POOL_NO_TAG(WHERE p.prefix = ? AND p.prefix_length = ?)
},
// Select shared network by name.
#endif
+#ifndef MYSQL_GET_POOL4_COMMON
+#define MYSQL_GET_POOL4_COMMON(server_join, ...) \
+ "SELECT" \
+ " p.id," \
+ " p.start_address," \
+ " p.end_address," \
+ " p.subnet_id," \
+ " p.client_class," \
+ " p.require_client_classes," \
+ " p.user_context," \
+ " p.modification_ts," \
+ " x.option_id," \
+ " x.code," \
+ " x.value," \
+ " x.formatted_value," \
+ " x.space," \
+ " x.persistent," \
+ " x.dhcp4_subnet_id," \
+ " x.scope_id," \
+ " x.user_context," \
+ " x.shared_network_name," \
+ " x.pool_id," \
+ " x.modification_ts " \
+ "FROM dhcp4_pool AS p " \
+ server_join \
+ "LEFT JOIN dhcp4_options AS x ON x.scope_id = 5 AND p.id = x.pool_id " \
+ #__VA_ARGS__ \
+ " ORDER BY p.id, x.option_id"
+
+#define MYSQL_GET_POOL4_RANGE_WITH_TAG(...) \
+ MYSQL_GET_POOL4_COMMON( \
+ "INNER JOIN dhcp4_subnet_server AS s ON p.subnet_id = s.subnet_id " \
+ "INNER JOIN dhcp4_server AS srv " \
+ " ON (s.server_id = srv.id) OR (s.server_id = 1) ", \
+ __VA_ARGS__)
+
+#define MYSQL_GET_POOL4_RANGE_NO_TAG(...) \
+ MYSQL_GET_POOL4_COMMON("", __VA_ARGS__)
+#endif
+
+#ifndef MYSQL_GET_POOL6_COMMON
+#define MYSQL_GET_POOL6_COMMON(server_join, ...) \
+ "SELECT" \
+ " p.id," \
+ " p.start_address," \
+ " p.end_address," \
+ " p.subnet_id," \
+ " p.client_class," \
+ " p.require_client_classes," \
+ " p.user_context," \
+ " p.modification_ts," \
+ " x.option_id," \
+ " x.code," \
+ " x.value," \
+ " x.formatted_value," \
+ " x.space," \
+ " x.persistent," \
+ " x.dhcp6_subnet_id," \
+ " x.scope_id," \
+ " x.user_context," \
+ " x.shared_network_name," \
+ " x.pool_id," \
+ " x.modification_ts," \
+ " x.pd_pool_id " \
+ "FROM dhcp6_pool AS p " \
+ server_join \
+ "LEFT JOIN dhcp6_options AS x ON x.scope_id = 5 AND p.id = x.pool_id " \
+ #__VA_ARGS__ \
+ " ORDER BY p.id, x.option_id"
+
+#define MYSQL_GET_POOL6_RANGE_WITH_TAG(...) \
+ MYSQL_GET_POOL6_COMMON( \
+ "INNER JOIN dhcp6_subnet_server AS s ON p.subnet_id = s.subnet_id " \
+ "INNER JOIN dhcp6_server AS srv " \
+ " ON (s.server_id = srv.id) OR (s.server_id = 1) ", \
+ __VA_ARGS__)
+
+#define MYSQL_GET_POOL6_RANGE_NO_TAG(...) \
+ MYSQL_GET_POOL6_COMMON("", __VA_ARGS__)
+#endif
+
+#ifndef MYSQL_GET_PD_POOL_COMMON
+#define MYSQL_GET_PD_POOL_COMMON(server_join, ...) \
+ "SELECT" \
+ " p.id," \
+ " p.prefix," \
+ " p.prefix_length," \
+ " p.delegated_prefix_length," \
+ " p.subnet_id," \
+ " p.excluded_prefix," \
+ " p.excluded_prefix_length," \
+ " p.client_class," \
+ " p.require_client_classes," \
+ " p.user_context," \
+ " p.modification_ts," \
+ " x.option_id," \
+ " x.code," \
+ " x.value," \
+ " x.formatted_value," \
+ " x.space," \
+ " x.persistent," \
+ " x.dhcp6_subnet_id," \
+ " x.scope_id," \
+ " x.user_context," \
+ " x.shared_network_name," \
+ " x.pool_id," \
+ " x.modification_ts," \
+ " x.pd_pool_id " \
+ "FROM dhcp6_pd_pool AS p " \
+ server_join \
+ "LEFT JOIN dhcp6_options AS x ON x.scope_id = 6 AND p.id = x.pd_pool_id " \
+ #__VA_ARGS__ \
+ " ORDER BY p.id, x.option_id" \
+
+#define MYSQL_GET_PD_POOL_WITH_TAG(...) \
+ MYSQL_GET_PD_POOL_COMMON( \
+ "INNER JOIN dhcp6_subnet_server AS s ON p.subnet_id = s.subnet_id " \
+ "INNER JOIN dhcp6_server AS srv " \
+ " ON (s.server_id = srv.id) OR (s.server_id = 1) ", \
+ __VA_ARGS__)
+
+#define MYSQL_GET_PD_POOL_NO_TAG(...) \
+ MYSQL_GET_PD_POOL_COMMON("", __VA_ARGS__)
+#endif
+
#ifndef MYSQL_GET_SHARED_NETWORK4
#define MYSQL_GET_SHARED_NETWORK4_COMMON(server_join, ...) \
"SELECT" \
#ifndef MYSQL_DELETE_OPTION_POOL_RANGE
#define MYSQL_DELETE_OPTION_POOL_RANGE(table_prefix, ...) \
"DELETE o FROM " #table_prefix "_options AS o " \
- "INNER JOIN " #table_prefix "_options_server AS a" \
- " ON o.option_id = a.option_id " \
- "INNER JOIN " #table_prefix "_server AS s" \
- " ON a.server_id = s.id " \
"WHERE " #__VA_ARGS__ \
" AND o.pool_id = " \
" (SELECT id FROM " #table_prefix "_pool" \
#ifndef MYSQL_DELETE_OPTION_PD_POOL
#define MYSQL_DELETE_OPTION_PD_POOL(...) \
"DELETE o FROM dhcp6_options AS o " \
- "INNER JOIN dhcp6_options_server AS a" \
- " ON o.option_id = a.option_id " \
- "INNER JOIN dhcp6_server AS s" \
- " ON a.server_id = s.id " \
"WHERE " #__VA_ARGS__ \
" AND o.pd_pool_id = " \
" (SELECT id FROM dhcp6_pd_pool" \
ASSERT_EQ(3, countRows("dhcp4_options"));
opt_boot_file_name->persistent_ = !opt_boot_file_name->persistent_;
- cbptr_->createUpdateOption4(ServerSelector::ALL(), subnet->getID(),
+ cbptr_->createUpdateOption4(ServerSelector::ANY(), subnet->getID(),
opt_boot_file_name);
returned_subnet = cbptr_->getSubnet4(ServerSelector::ANY(),
const PoolPtr pool = subnet->getPool(Lease::TYPE_V4, IOAddress("192.0.2.10"));
ASSERT_TRUE(pool);
OptionDescriptorPtr opt_boot_file_name = test_options_[0];
- cbptr_->createUpdateOption4(ServerSelector::ALL(),
+ cbptr_->createUpdateOption4(ServerSelector::ANY(),
pool->getFirstAddress(),
pool->getLastAddress(),
opt_boot_file_name);
// Modify the option and update it in the database.
opt_boot_file_name->persistent_ = !opt_boot_file_name->persistent_;
- cbptr_->createUpdateOption4(ServerSelector::ALL(),
+ cbptr_->createUpdateOption4(ServerSelector::ANY(),
pool->getFirstAddress(),
pool->getLastAddress(),
opt_boot_file_name);
ASSERT_EQ(0, countRows("dhcp4_options"));
OptionDescriptorPtr opt_boot_file_name = test_options_[0];
- cbptr_->createUpdateOption4(ServerSelector::ALL(),
+ cbptr_->createUpdateOption4(ServerSelector::ANY(),
shared_network->getName(),
opt_boot_file_name);
ASSERT_EQ(1, countRows("dhcp4_options"));
opt_boot_file_name->persistent_ = !opt_boot_file_name->persistent_;
- cbptr_->createUpdateOption4(ServerSelector::ALL(),
+ cbptr_->createUpdateOption4(ServerSelector::ANY(),
shared_network->getName(),
opt_boot_file_name);
ASSERT_EQ(4, countRows("dhcp6_options"));
OptionDescriptorPtr opt_posix_timezone = test_options_[0];
- cbptr_->createUpdateOption6(ServerSelector::ALL(), subnet->getID(),
+ cbptr_->createUpdateOption6(ServerSelector::ANY(), subnet->getID(),
opt_posix_timezone);
returned_subnet = cbptr_->getSubnet6(ServerSelector::ALL(),
ASSERT_EQ(5, countRows("dhcp6_options"));
opt_posix_timezone->persistent_ = !opt_posix_timezone->persistent_;
- cbptr_->createUpdateOption6(ServerSelector::ALL(), subnet->getID(),
+ cbptr_->createUpdateOption6(ServerSelector::ANY(), subnet->getID(),
opt_posix_timezone);
returned_subnet = cbptr_->getSubnet6(ServerSelector::ALL(),
IOAddress("2001:db8::10"));
ASSERT_TRUE(pool);
OptionDescriptorPtr opt_posix_timezone = test_options_[0];
- cbptr_->createUpdateOption6(ServerSelector::ALL(),
+ cbptr_->createUpdateOption6(ServerSelector::ANY(),
pool->getFirstAddress(),
pool->getLastAddress(),
opt_posix_timezone);
// Modify the option and update it in the database.
opt_posix_timezone->persistent_ = !opt_posix_timezone->persistent_;
- cbptr_->createUpdateOption6(ServerSelector::ALL(),
+ cbptr_->createUpdateOption6(ServerSelector::ANY(),
pool->getFirstAddress(),
pool->getLastAddress(),
opt_posix_timezone);
OptionDescriptorPtr opt_posix_timezone = test_options_[0];
int pd_pool_len = prefixLengthFromRange(pd_pool->getFirstAddress(),
pd_pool->getLastAddress());
- cbptr_->createUpdateOption6(ServerSelector::ALL(),
+ cbptr_->createUpdateOption6(ServerSelector::ANY(),
pd_pool->getFirstAddress(),
static_cast<uint8_t>(pd_pool_len),
opt_posix_timezone);
// Modify the option and update it in the database.
opt_posix_timezone->persistent_ = !opt_posix_timezone->persistent_;
- cbptr_->createUpdateOption6(ServerSelector::ALL(),
+ cbptr_->createUpdateOption6(ServerSelector::ANY(),
pd_pool->getFirstAddress(),
static_cast<uint8_t>(pd_pool_len),
opt_posix_timezone);
ASSERT_EQ(0, countRows("dhcp6_options"));
OptionDescriptorPtr opt_posix_timezone = test_options_[0];
- cbptr_->createUpdateOption6(ServerSelector::ALL(),
+ cbptr_->createUpdateOption6(ServerSelector::ANY(),
shared_network->getName(),
opt_posix_timezone);
ASSERT_EQ(1, countRows("dhcp6_options"));
opt_posix_timezone->persistent_ = !opt_posix_timezone->persistent_;
- cbptr_->createUpdateOption6(ServerSelector::ALL(),
+ cbptr_->createUpdateOption6(ServerSelector::ANY(),
shared_network->getName(),
opt_posix_timezone);