From: Francis Dupont Date: Sun, 16 Jun 2019 22:28:54 +0000 (+0200) Subject: [659-how-configure-client-class-for-pools-in-db] Made getPool methods handle server... X-Git-Tag: Kea-1.6.0~41^2~56 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46c5692543bf78536ccc406cec7c3ae75ba80b93;p=thirdparty%2Fkea.git [659-how-configure-client-class-for-pools-in-db] Made getPool methods handle server selector --- diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc index fb70995b1b..1eecc99ec2 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc @@ -811,18 +811,23 @@ public: /// @param pool_end_address Upper bound pool address. /// @param pool_id Pool identifier for the returned pool. /// @return Pointer to the pool or null if no such pool found. - Pool4Ptr getPool4(const ServerSelector& /* server_selector */, + Pool4Ptr getPool4(const ServerSelector& server_selector, const IOAddress& pool_start_address, const IOAddress& pool_end_address, uint64_t& pool_id) { - MySqlBindingCollection in_bindings = { - MySqlBinding::createInteger(pool_start_address.toUint32()), - MySqlBinding::createInteger(pool_end_address.toUint32()) - }; - PoolCollection pools; std::vector pool_ids; - getPools(GET_POOL4_RANGE, in_bindings, pools, pool_ids); + + auto tags = getServerTags(server_selector); + for (auto tag : tags) { + MySqlBindingCollection in_bindings = { + MySqlBinding::createString(tag), + MySqlBinding::createInteger(pool_start_address.toUint32()), + MySqlBinding::createInteger(pool_end_address.toUint32()) + }; + + getPools(GET_POOL4_RANGE, in_bindings, pools, pool_ids); + } if (!pools.empty()) { pool_id = pool_ids[0]; @@ -2212,8 +2217,12 @@ TaggedStatementArray tagged_statements = { { " 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 p.start_address = ? AND p.end_address = ? " + "WHERE (srv.tag = ? OR srv.id = 1) " + " AND p.start_address = ? AND p.end_address = ? " "ORDER BY p.id, x.option_id" }, diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc index 7eb155c1ac..93912f6266 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.cc @@ -1024,18 +1024,23 @@ public: /// @param pool_end_address Upper bound pool address. /// @param pool_id Pool identifier for the returned pool. /// @return Pointer to the pool or null if no such pool found. - Pool6Ptr getPool6(const ServerSelector& /* server_selector */, + Pool6Ptr getPool6(const ServerSelector& server_selector, const IOAddress& pool_start_address, const IOAddress& pool_end_address, uint64_t& pool_id) { - MySqlBindingCollection in_bindings = { - MySqlBinding::createString(pool_start_address.toText()), - MySqlBinding::createString(pool_end_address.toText()) - }; - PoolCollection pools; std::vector pool_ids; - getPools(GET_POOL6_RANGE, in_bindings, pools, pool_ids); + + auto tags = getServerTags(server_selector); + for (auto tag : tags) { + MySqlBindingCollection in_bindings = { + MySqlBinding::createString(tag), + MySqlBinding::createString(pool_start_address.toText()), + MySqlBinding::createString(pool_end_address.toText()) + }; + + getPools(GET_POOL6_RANGE, in_bindings, pools, pool_ids); + } if (!pools.empty()) { pool_id = pool_ids[0]; @@ -1054,18 +1059,23 @@ public: /// @param pd_pool_prefix_length Length of the pd pool prefix. /// @param pd_pool_id Pool identifier for the returned pool. /// @return Pointer to the pool or null if no such pool found. - Pool6Ptr getPdPool6(const ServerSelector& /* server_selector */, + Pool6Ptr getPdPool6(const ServerSelector& server_selector, const asiolink::IOAddress& pd_pool_prefix, const uint8_t pd_pool_prefix_length, uint64_t& pd_pool_id) { - MySqlBindingCollection in_bindings = { - MySqlBinding::createString(pd_pool_prefix.toText()), - MySqlBinding::createInteger(pd_pool_prefix_length) - }; - PoolCollection pd_pools; std::vector pd_pool_ids; - getPdPools(GET_PD_POOL, in_bindings, pd_pools, pd_pool_ids); + + auto tags = getServerTags(server_selector); + for (auto tag : tags) { + MySqlBindingCollection in_bindings = { + MySqlBinding::createString(tag), + MySqlBinding::createString(pd_pool_prefix.toText()), + MySqlBinding::createInteger(pd_pool_prefix_length) + }; + + getPdPools(GET_PD_POOL, in_bindings, pd_pools, pd_pool_ids); + } if (!pd_pools.empty()) { pd_pool_id = pd_pool_ids[0]; @@ -2642,8 +2652,12 @@ TaggedStatementArray tagged_statements = { { " 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 p.start_address = ? AND p.end_address = ? " + "WHERE (srv.tag = ? OR srv.id = 1) " + " AND p.start_address = ? AND p.end_address = ? " "ORDER BY p.id, x.option_id" }, @@ -2675,8 +2689,12 @@ TaggedStatementArray tagged_statements = { { " 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 p.prefix = ? AND p.prefix_length = ? " + "WHERE (srv.tag = ? OR srv.id = 1) " + " AND p.prefix = ? AND p.prefix_length = ? " "ORDER BY p.id, x.option_id" },