33 boost::scoped_ptr<HostMgr>&
34 HostMgr::getHostMgrPtr() {
35 static boost::scoped_ptr<HostMgr> host_mgr_ptr;
36 return (host_mgr_ptr);
41 getHostMgrPtr().reset(
new HostMgr());
56 getHostMgrPtr()->alternate_sources_.clear();
61 if (alternate_sources_.empty()) {
64 return (alternate_sources_[0]);
69 if (getHostMgrPtr()->cache_ptr_) {
73 if (sources.empty()) {
77 boost::dynamic_pointer_cast<CacheHostDataSource>(sources[0]);
79 getHostMgrPtr()->cache_ptr_ = cache_ptr;
82 .arg(cache_ptr->getType());
91 boost::scoped_ptr<HostMgr>& host_mgr_ptr = getHostMgrPtr();
95 return (*host_mgr_ptr);
100 const uint8_t* identifier_begin,
101 const size_t identifier_len)
const {
105 for (
auto source : alternate_sources_) {
107 source->getAll(identifier_type, identifier_begin, identifier_len);
108 hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
117 for (
auto source : alternate_sources_) {
119 hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
127 const uint8_t* identifier_begin,
128 const size_t identifier_len)
const {
129 ConstHostPtr host = getCfgHosts()->get4(subnet_id, identifier_type,
130 identifier_begin, identifier_len);
134 if (host || alternate_sources_.empty()) {
139 HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_IDENTIFIER)
146 for (
auto source : alternate_sources_) {
147 host = source->get4(subnet_id, identifier_type,
148 identifier_begin, identifier_len);
152 HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_IDENTIFIER_HOST)
157 .arg(source->getType())
158 .arg(host->toText());
160 if (source != cache_ptr_) {
167 HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_IDENTIFIER_NULL)
177 const uint8_t* identifier_begin,
178 const size_t identifier_len)
const {
180 identifier_begin, identifier_len);
181 if (host && host->getNegative()) {
183 }
else if (!host && negative_caching_) {
184 cacheNegative(subnet_id,
SubnetID(SUBNET_ID_UNUSED),
185 identifier_type, identifier_begin, identifier_len);
193 ConstHostPtr host = getCfgHosts()->get4(subnet_id, address);
194 if (host || alternate_sources_.empty()) {
198 HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_ADDRESS4)
201 for (
auto source : alternate_sources_) {
202 host = source->get4(subnet_id, address);
203 if (host && host->getNegative()) {
206 if (host && source != cache_ptr_) {
219 ConstHostPtr host = getCfgHosts()->get6(prefix, prefix_len);
220 if (host || alternate_sources_.empty()) {
225 .arg(
static_cast<int>(prefix_len));
226 for (
auto source : alternate_sources_) {
227 host = source->get6(prefix, prefix_len);
228 if (host && host->getNegative()) {
231 if (host && source != cache_ptr_) {
244 const uint8_t* identifier_begin,
245 const size_t identifier_len)
const {
246 ConstHostPtr host = getCfgHosts()->get6(subnet_id, identifier_type,
247 identifier_begin, identifier_len);
248 if (host || alternate_sources_.empty()) {
253 HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_IDENTIFIER)
258 for (
auto source : alternate_sources_) {
259 host = source->get6(subnet_id, identifier_type,
260 identifier_begin, identifier_len);
264 HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_IDENTIFIER_HOST)
269 .arg(source->getType())
270 .arg(host->toText());
272 if (source != cache_ptr_) {
280 HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_IDENTIFIER_NULL)
291 const uint8_t* identifier_begin,
292 const size_t identifier_len)
const {
294 identifier_begin, identifier_len);
295 if (host && host->getNegative()) {
297 }
else if (!host && negative_caching_) {
298 cacheNegative(
SubnetID(SUBNET_ID_UNUSED), subnet_id,
299 identifier_type, identifier_begin, identifier_len);
307 ConstHostPtr host = getCfgHosts()->get6(subnet_id, addr);
308 if (host || alternate_sources_.empty()) {
312 HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_ADDRESS6)
315 for (
auto source : alternate_sources_) {
316 host = source->get6(subnet_id, addr);
317 if (host && host->getNegative()) {
320 if (host && source != cache_ptr_) {
332 if (alternate_sources_.empty()) {
334 "no hosts-database configured.");
336 for (
auto source : alternate_sources_) {
347 if (alternate_sources_.empty()) {
349 "no hosts-database configured.");
352 for (
auto source : alternate_sources_) {
353 if (source->del(subnet_id, addr)) {
362 const uint8_t* identifier_begin,
const size_t identifier_len) {
363 if (alternate_sources_.empty()) {
365 "no hosts-database configured.");
368 for (
auto source : alternate_sources_) {
369 if (source->del4(subnet_id, identifier_type,
370 identifier_begin, identifier_len)) {
379 const uint8_t* identifier_begin,
const size_t identifier_len) {
380 if (alternate_sources_.empty()) {
382 "no alternate host data source present");
385 for (
auto source : alternate_sources_) {
386 if (source->del6(subnet_id, identifier_type,
387 identifier_begin, identifier_len)) {
398 if (!host || host->getNegative()) {
403 cache_ptr_->insert(host,
true);
411 const uint8_t* identifier_begin,
412 const size_t identifier_len)
const {
413 if (cache_ptr_ && negative_caching_) {
414 HostPtr host(
new Host(identifier_begin, identifier_len,
416 ipv4_subnet_id, ipv6_subnet_id,
418 host->setNegative(
true);
421 cache_ptr_->insert(host,
false);