// return verification status
virtual bool configure(SnortConfig*) { return true; }
virtual void show(SnortConfig*) { }
+ virtual void update(SnortConfig*, const char*) { }
// packet thread functions
// tinit, tterm called on default policy instance only
}
SnortConfig* old = snort_conf;
- SnortConfig* sc = Snort::get_reloaded_policy(old, fname);
+ SnortConfig* sc = Snort::get_updated_policy(old, fname, nullptr);
if ( !sc )
{
return 0;
}
+int main_delete_inspector(lua_State* L)
+{
+ if ( Swapper::get_reload_in_progress() )
+ {
+ current_request->respond("== delete pending; retry\n");
+ return 0;
+ }
+ const char* iname = nullptr;
+
+ if ( L )
+ {
+ Lua::ManageStack(L, 1);
+ iname = luaL_checkstring(L, 1);
+ }
+
+ if ( iname and *iname )
+ current_request->respond(".. deleting inspector\n");
+ else
+ {
+ current_request->respond("== inspector name required\n");
+ return 0;
+ }
+
+ SnortConfig* old = snort_conf;
+ SnortConfig* sc = Snort::get_updated_policy(old, nullptr, iname);
+
+ if ( !sc )
+ {
+ current_request->respond("== reload failed\n");
+ return 0;
+ }
+ snort_conf = sc;
+ proc_stats.inspector_deletions++;
+
+ bool from_shell = ( L != nullptr );
+ current_request->respond(".. deleted inspector\n", from_shell);
+ broadcast(get_command(new ACSwap(new Swapper(old, sc)), from_shell));
+
+ return 0;
+}
+
int main_process(lua_State* L)
{
const char* f = lua_tostring(L, 1);
const char* get_prompt();
// commands provided by the snort module
+int main_delete_inspector(lua_State* = nullptr);
int main_dump_stats(lua_State* = nullptr);
int main_rotate_stats(lua_State* = nullptr);
int main_reload_config(lua_State* = nullptr);
return sc;
}
-SnortConfig* Snort::get_reloaded_policy(SnortConfig* other_conf, const char* fname)
+SnortConfig* Snort::get_updated_policy(SnortConfig* other_conf, const char* fname, const char* iname)
{
reloading = true;
SnortConfig* sc = new SnortConfig(other_conf);
- Shell sh = Shell(fname);
- sh.configure(sc);
- if ( ModuleManager::get_errors() || !sc->verify() )
+ if ( fname )
{
- sc->cloned = true;
- InspectorManager::update_policy(other_conf);
- delete sc;
- set_policies(other_conf);
- reloading = false;
- return nullptr;
+ Shell sh = Shell(fname);
+ sh.configure(sc);
+
+ if ( ModuleManager::get_errors() || !sc->verify() )
+ {
+ sc->cloned = true;
+ InspectorManager::update_policy(other_conf);
+ delete sc;
+ set_policies(other_conf);
+ reloading = false;
+ return nullptr;
+ }
+ }
+
+ if ( iname )
+ {
+ if ( !InspectorManager::delete_inspector(sc, iname) )
+ {
+ sc->cloned = true;
+ InspectorManager::update_policy(other_conf);
+ delete sc;
+ set_policies(other_conf);
+ reloading = false;
+ return nullptr;
+ }
}
if ( !InspectorManager::configure(sc, true) )
{
public:
static SnortConfig* get_reload_config(const char* fname);
- static SnortConfig* get_reloaded_policy(SnortConfig*, const char* fname);
+ static SnortConfig* get_updated_policy(SnortConfig*, const char* fname, const char* iname);
static void setup(int argc, char* argv[]);
static bool drop_privileges();
static void do_pidfile();
if (conf->obfuscation_net.get_family() != 0)
memcpy(&obfuscation_net, &conf->obfuscation_net, sizeof(obfuscation_net));
-
}
// merge in everything from the command line config
{ nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
};
+static const Parameter s_delete[] =
+{
+ { "inspector", Parameter::PT_STRING, nullptr, nullptr,
+ "name of inspector to delete" },
+
+ { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
+};
+
static const Command snort_cmds[] =
{
{ "show_plugins", main_dump_plugins, nullptr, "show available plugins" },
+ { "delete_inspector", main_delete_inspector, s_delete, "delete an inspector from the default policy" },
{ "dump_stats", main_dump_stats, nullptr, "show summary statistics" },
{ "rotate_stats", main_rotate_stats, nullptr, "roll perfmonitor log files" },
{ "reload_config", main_reload_config, s_reload, "load new configuration" },
enum ReloadType {
RELOAD_TYPE_NONE = 0,
+ RELOAD_TYPE_DELETED,
RELOAD_TYPE_REENABLED,
RELOAD_TYPE_NEW,
RELOAD_TYPE_MAX
bool is_reloaded()
{ return ((reload_type == RELOAD_TYPE_REENABLED) or
+ (reload_type == RELOAD_TYPE_DELETED) or
(reload_type == RELOAD_TYPE_NEW)); }
ReloadType get_reload_type()
return p->get_api()->type;
}
+bool InspectorManager::delete_inspector(SnortConfig* sc, const char* iname)
+{
+ bool ok = false;
+ if ( sc->policy_map->inspection_policy.size() )
+ {
+ FrameworkPolicy* fp = sc->policy_map->inspection_policy[0]->framework_policy;
+ std::vector<PHInstance*>::iterator old_it;
+
+ if ( get_instance(fp, iname, false, old_it) )
+ {
+ (*old_it)->set_reloaded(RELOAD_TYPE_DELETED);
+ fp->ilist.erase(old_it);
+ ok = true;
+ std::vector<PHInstance*>::iterator bind_it;
+ if ( get_instance(fp, "binder", false, bind_it) )
+ {
+ (*bind_it)->handler->update(sc, iname);
+ }
+ }
+ }
+
+ return ok;
+}
+
void InspectorManager::free_inspector(Inspector* p)
{
p->get_api()->dtor(p);
static void instantiate(
const InspectApi*, Module*, SnortConfig*, const char* name = nullptr);
+ static bool delete_inspector(SnortConfig* sc, const char* iname);
static void free_inspector(Inspector*);
static InspectSsnFunc get_session(uint16_t proto);
void show(SnortConfig*) override
{ LogMessage("Binder\n"); }
+ void update(SnortConfig*, const char*) override;
+
bool configure(SnortConfig*) override;
void eval(Packet*) override;
return true;
}
+void Binder::update(SnortConfig* sc, const char* name)
+{
+ vector<Binding*>::iterator it;
+ for ( it = bindings.begin(); it != bindings.end(); ++it )
+ {
+ const char* key;
+ Binding *pb = *it;
+ if ( pb->use.svc.empty() )
+ key = pb->use.name.c_str();
+ else
+ key = pb->use.svc.c_str();
+ if ( !strcmp(key, name) )
+ {
+ bindings.erase(it);
+ delete pb;
+ return;
+ }
+ }
+}
+
// FIXIT-M need to consider binding of ips rules / policy
// possibly split bindings into these categories
void Binder::eval(Packet* p)
{ "signals", "total signals processed" },
{ "conf_reloads", "number of times configuration was reloaded" },
{ "policy_reloads", "number of times policies were reloaded" },
+ { "inspector_deletions", "number of times inspectors were deleted" },
{ "daq_reloads", "number of times daq configuration was reloaded" },
{ "attribute_table_reloads", "number of times hosts table was reloaded" },
{ "attribute_table_hosts", "total number of hosts in table" },
PegCount signals;
PegCount conf_reloads;
PegCount policy_reloads;
+ PegCount inspector_deletions;
PegCount daq_reloads;
PegCount attribute_table_reloads;
PegCount attribute_table_hosts;