Merge in SNORT/snort3 from ~VHORBAN/snort3:fix_config_option_handling_for_suppress_module to master
Squashed commit of the following:
commit
099db62ee3f27240572b9007f3365e4e9e768bae
Author: Volodymyr Horban <vhorban@cisco.com>
Date: Sun May 15 17:00:51 2022 +0300
filters: add correct handling of by_src and by_dst
Thanks to Albert O'Balsam for reporting the bug.
-- don't want to any of see these
{ gid = 1, sid = 1 },
- -- don't want to see these for a given server
+ -- don't want to see anything for a given host
+ { track = 'by_dst', ip = '1.2.3.4' }
+
+ -- don't want to see these for a given host
{ gid = 1, sid = 2, track = 'by_dst', ip = '1.2.3.4' },
}
--]]
bool SuppressModule::end(const char*, int idx, SnortConfig* sc)
{
- if ( idx && sfthreshold_create(sc, sc->threshold_config, &thdx, get_network_policy()->policy_id) )
+ if ( !idx )
+ return true;
+
+ if ( thdx.gen_id == 0 and thdx.sig_id >= 1 )
{
- ParseError("bad suppress configuration [%d]", idx);
+ ParseError("bad or incomplete gid:sid pair [%d]", idx);
return false;
}
+
+ if ( ( thdx.tracking == 0 and thdx.ip_address ) or ( thdx.tracking > 0 and !thdx.ip_address ) )
+ {
+ ParseError("incomplete pair of track and IP [%d]", idx);
+ return false;
+ }
+
+ if ( sfthreshold_create(sc, sc->threshold_config, &thdx, get_network_policy()->policy_id) )
+ {
+ ParseError("threshold object cannot be created from the given parameters [%d]", idx);
+ return false;
+ }
+
return true;
}
#include <algorithm>
#include <cassert>
#include <iostream>
+#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
cout << ": " << p->help;
- if ( const char* r = p->get_range() )
- cout << " { " << r << " }";
+ const char* range = p->get_range();
+ if ( !range )
+ {
+ cout << endl;
+ return;
+ }
+
+ if ( strcmp(p->get_type(), "enum" ) != 0 )
+ cout << " { " << range << " }";
+ else
+ {
+ std::stringstream ss(range);
+ std::string word;
+ cout << " { ";
+ while ( ss >> word )
+ {
+ if ( word != "|" )
+ std::cout << "'" << word << "'";
+ else
+ std::cout << " " << word << " ";
+ }
+ cout << " }";
+ }
cout << endl;
}