Merge pull request #135 from constcast/fix-match-proto-parsing

Fix for parseProtoInformation
master
Lothar Braun 2020-04-27 10:14:47 +02:00 committed by GitHub
commit 9ff81ed021
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 6 deletions

View File

@ -111,7 +111,7 @@ int parseModifier(const char* s, Rule::Field::Modifier* modifier) {
* parses the given string
* @return 0 if successful
*/
int parseProtoPattern(char* s, IpfixRecord::Data** fdata, InformationElement::IeLength* length) {
int parseProtoPattern(const char* s, IpfixRecord::Data** fdata, InformationElement::IeLength* length) {
int proto = -1;
if (strcmp(s, "ICMP") == 0) proto = IPFIX_protocolIdentifier_ICMP;
if (strcmp(s, "TCP") == 0) proto = IPFIX_protocolIdentifier_TCP;
@ -121,8 +121,10 @@ int parseProtoPattern(char* s, IpfixRecord::Data** fdata, InformationElement::Ie
if (proto == -1)
{
proto = atoi(s);
if((proto < 0) && (proto > 255)) return -1;
char* end;
errno = 0;
proto = strtol(s, &end, 10);
if(end == s || *end != 0 || errno != 0 || (proto < 0) || (proto > 255)) return -1;
}
*length = 1;

View File

@ -45,7 +45,7 @@ class Rules {
};
int parseModifier(const char* s, Rule::Field::Modifier* modifier);
int parseProtoPattern(char* s, IpfixRecord::Data** fdata, InformationElement::IeLength* length);
int parseProtoPattern(const char* s, IpfixRecord::Data** fdata, InformationElement::IeLength* length);
int parseIPv4Pattern(char* s, IpfixRecord::Data** fdata, InformationElement::IeLength* length);
int parsePortPattern(char* s, IpfixRecord::Data** fdata, InformationElement::IeLength* length);
int parseTcpFlags(char* s, IpfixRecord::Data** fdata, InformationElement::IeLength* length);

View File

@ -56,3 +56,4 @@ IF (JOURNALD_FOUND)
ENDIF (JOURNALD_FOUND)
ADD_TEST(example_2 example_code_2)
ADD_TEST(mtutest mtutest)

View File

@ -4,6 +4,8 @@
#include <dirent.h>
#include <cstdlib>
#include <cstring>
#include <map>
#include "modules/ipfix/aggregator/Rules.hpp"
ConfigTester::ConfigTester()
{
@ -29,15 +31,19 @@ ConfigTester::~ConfigTester()
Test::TestResult ConfigTester::execTest()
{
test_Rules_parseProtoPattern();
// TODO: The following tests need to be fixed before we can reenable them.
/*
for (unsigned i = 0; i != configFiles.size(); ++i) {
testConfig(configFiles[i]);
}
*/
return PASSED;
}
void ConfigTester::testConfig(const std::string& configFile)
{
std::string vermontCommand = "../vermont -ddddd -f test_configs/" + configFile;
std::string vermontCommand = "../../../vermont -ddddd -f test_configs/" + configFile;
std::string generatedOutput = "gen_output/" + configFile;
std::string expectedOutput = "exp_output/" + configFile;
@ -47,3 +53,26 @@ void ConfigTester::testConfig(const std::string& configFile)
REQUIRE(system(vermontCommand.c_str()) == 0);
REQUIRE(system(diffCommand.c_str()) == 0);
}
void ConfigTester::test_Rules_parseProtoPattern()
{
std::map<std::string, int> testPatterns;
testPatterns["ICMP"] = 0;
testPatterns["TCP" ] = 0;
testPatterns["UDP"] = 0;
testPatterns["RAW"] = 0;
testPatterns["17"] = 0;
testPatterns["-1"] = -1;
testPatterns["256"] = -1;
testPatterns["SOMETHING_INVALID"] = -1;
testPatterns[""] = -1;
testPatterns["155SOMETHING_INVALID"] = -1;
for (std::map<std::string, int>::iterator i = testPatterns.begin(); i != testPatterns.end(); ++i) {
IpfixRecord::Data* d;
InformationElement::IeLength l;
int ret = parseProtoPattern(i->first.c_str(), &d, &l);
if (ret != -1)
free(d);
REQUIRE(ret == i->second);
}
}

View File

@ -14,6 +14,7 @@ public:
virtual TestResult execTest();
private:
void test_Rules_parseProtoPattern();
void testConfig(const std::string& configFile);
std::vector<std::string> configFiles;
};

View File

@ -29,7 +29,7 @@ int main(int argc, char* argv[])
testSuite.add(new BloomFilterTestSuite());
testSuite.add(new ConnectionFilterTestSuite());
#endif
//testSuite.add(new ConfigTester());
testSuite.add(new ConfigTester());
testSuite.run();