else
current_request->respond("== reload failed - bad config\n");
+ HostAttributesManager::load_failure_cleanup();
return 0;
}
- if ( !sc->attribute_hosts_file.empty() )
- {
- if ( !HostAttributesManager::load_hosts_file(sc, sc->attribute_hosts_file.c_str()) )
- current_request->respond("== reload failed - host attributes file failed to load\n");
- }
-
int32_t num_hosts = HostAttributesManager::get_num_host_entries();
if ( num_hosts >= 0 )
LogMessage( "host attribute table: %d hosts loaded\n", num_hosts);
// hosts module
//-------------------------------------------------------------------------
-class HostAttributesReloadTuner : public snort::ReloadResourceTuner
-{
-public:
- HostAttributesReloadTuner() = default;
-
- bool tinit() override
- {
- HostAttributesManager::initialize();
- return true;
- }
-
- bool tune_packet_context() override
- { return true; }
-
- bool tune_idle_context() override
- { return true; }
-};
-
static const Parameter service_params[] =
{
{ "name", Parameter::PT_STRING, nullptr, nullptr,
host.reset();
host = nullptr;
}
- else if ( !idx && !strcmp(fqn, "hosts"))
- {
- if ( HostAttributesManager::activate() )
- {
- if ( Snort::is_reloading() )
- sc->register_reload_resource_tuner(new HostAttributesReloadTuner);
- }
- }
return true;
}
if ( !HostAttributesManager::load_hosts_file(sc, sc->attribute_hosts_file.c_str()) )
ParseError("host attributes file failed to load\n");
}
+ HostAttributesManager::activate(sc);
// Must be after CodecManager::instantiate()
if ( !InspectorManager::configure(sc) )
}
InspectorManager::update_policy(sc);
+
+ if ( !sc->attribute_hosts_file.empty() )
+ {
+ if ( !HostAttributesManager::load_hosts_file(sc, sc->attribute_hosts_file.c_str()) )
+ LogMessage("== WARNING: host attributes file failed to load\n");
+ }
+ HostAttributesManager::activate(sc);
+
reloading = false;
parser_term(sc);
#include "hash/lru_cache_shared.h"
#include "main/shell.h"
+#include "main/snort.h"
#include "main/snort_config.h"
#include "main/thread.h"
typedef HostLruSharedCache<snort::SfIp, HostAttributesDescriptor, HostAttributesCacheKey> HostAttributesSharedCache;
+class HostAttributesReloadTuner : public snort::ReloadResourceTuner
+{
+public:
+ HostAttributesReloadTuner() = default;
+
+ bool tinit() override
+ {
+ HostAttributesManager::initialize();
+ return true;
+ }
+
+ bool tune_packet_context() override
+ { return true; }
+
+ bool tune_idle_context() override
+ { return true; }
+};
+
static THREAD_LOCAL HostAttributesSharedCache* active_cache = nullptr;
static HostAttributesSharedCache* swap_cache = nullptr;
static HostAttributesSharedCache* next_cache = nullptr;
Shell sh(fname);
if ( sh.configure(sc, false, true) )
+ {
+ activate(sc);
return true;
+ }
// loading of host file failed...
- delete next_cache;
- next_cache = nullptr;
+ load_failure_cleanup();
return false;
}
return next_cache->find_else_insert(host->get_ip_addr(), host, true);
}
-bool HostAttributesManager::activate()
+void HostAttributesManager::activate(SnortConfig* sc)
{
+ if ( next_cache == nullptr )
+ return;
old_cache = active_cache;
active_cache = next_cache;
swap_cache = next_cache;
next_cache = nullptr;
- return ( active_cache != old_cache ) ? true : false;
+ if( active_cache != old_cache and Snort::is_reloading() )
+ sc->register_reload_resource_tuner(new HostAttributesReloadTuner);
}
void HostAttributesManager::initialize()
{ active_cache = swap_cache; }
+void HostAttributesManager::load_failure_cleanup()
+{
+ delete next_cache;
+ next_cache = nullptr;
+}
+
void HostAttributesManager::swap_cleanup()
-{ delete old_cache; }
+{
+ delete old_cache;
+ old_cache = nullptr;
+}
void HostAttributesManager::term()
{ delete active_cache; }
{
public:
static bool load_hosts_file(snort::SnortConfig*, const char* fname);
- static bool activate();
+ static void activate(snort::SnortConfig*);
static void initialize();
static void swap_cleanup();
+ static void load_failure_cleanup();
static void term();
static bool add_host(HostAttributesEntry, snort::SnortConfig*);