typedef unsigned char uuid_t[16];
#endif
+#include <algorithm>
#include <memory>
#include <unordered_map>
#include <vector>
void set_cloned(bool state)
{ cloned = state; }
+ const Shell* get_shell_by_policy(unsigned id) const
+ {
+ auto it = std::find_if(std::begin(shell_map), std::end(shell_map),
+ [=](auto&& p) { return p.second->ips and p.second->ips->policy_id == id; });
+
+ return (it == std::end(shell_map)) ? nullptr : it->first;
+ }
+
private:
std::vector<Shell*> shells;
std::vector<InspectionPolicy*> inspection_policy;
parse_rule_print();
}
+void ShowPolicyStats(const SnortConfig* sc)
+{
+ std::unordered_map<PolicyId, int> stats;
+ std::multimap<PolicyId, std::tuple<const char*, int>> sorted_stats;
+
+ if ( !sc->otn_map )
+ return;
+
+ for (auto node = sc->otn_map->find_first(); node; node = sc->otn_map->find_next())
+ {
+ const OptTreeNode* otn = (const OptTreeNode*)node->data;
+ if ( !otn )
+ continue;
+
+ for (PolicyId id = 0; id < otn->proto_node_num; id++)
+ {
+ const auto rtn = getRtnFromOtn(otn, id);
+
+ if ( rtn and rtn->enabled() )
+ stats[id]++;
+ }
+ }
+
+ for (const auto& s : stats)
+ {
+ auto shell = sc->policy_map->get_shell_by_policy(s.first);
+ if ( !shell )
+ continue;
+
+ auto file = shell->get_file();
+ if ( !file or !file[0] )
+ continue;
+
+ auto policy = sc->policy_map->get_ips_policy(s.first);
+ auto id = policy ? policy->user_policy_id : 0;
+
+ sorted_stats.emplace(id, std::make_tuple(file, s.second));
+ }
+
+ if ( !sorted_stats.size() )
+ return;
+
+ LogLabel("ips policies");
+ LogMessage("%16s%16s%8s\n", "id", "rules enabled", "file");
+
+ for (const auto& s : sorted_stats)
+ {
+ auto file = std::get<0>(s.second);
+ auto rules_count = std::get<1>(s.second);
+ LogMessage("%16u%16d%4s%s\n", s.first, rules_count, " ", file);
+ }
+}
+
/****************************************************************************
*
* Function: CreateRuleType
snort::SnortConfig* ParseSnortConf(const snort::SnortConfig*, const char* fname = nullptr,
bool is_fatal = true);
void ParseRules(snort::SnortConfig*);
+void ShowPolicyStats(const snort::SnortConfig*);
char* ProcessFileOption(snort::SnortConfig*, const char*);
void SetRuleStates(snort::SnortConfig*);