Remove unused rule creation from a file
parent
e1145d70b2
commit
58cbcd8181
|
@ -117,24 +117,6 @@ void BaseAggregator::postReconfiguration()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* initializes aggregator module and creates hashtable
|
||||
* @param rulefile filename with rules to import
|
||||
* @param inactiveTimeout minimum buffer time for flows in hashtable
|
||||
* @param activeTimeout maximum buffer time for flows in hashtable
|
||||
*/
|
||||
void BaseAggregator::buildAggregator(char* rulefile, uint16_t inactiveTimeout, uint16_t activeTimeout, uint8_t hashbits)
|
||||
{
|
||||
Rules* rules = new Rules(rulefile);
|
||||
|
||||
if (!rules) {
|
||||
THROWEXCEPTION("could not parse rules file %s", rulefile);
|
||||
}
|
||||
buildAggregator(rules, inactiveTimeout, activeTimeout, hashbits);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* initializes aggregator module and creates hashtable
|
||||
* @param rules rules to use for creation of hashtables
|
||||
|
|
|
@ -36,7 +36,6 @@ public:
|
|||
virtual ~BaseAggregator();
|
||||
|
||||
void buildAggregator(Rules* rules, uint16_t inactiveTimeout, uint16_t activeTimeout, uint8_t hashbits);
|
||||
void buildAggregator(char* rulefile, uint16_t inactiveTimeout, uint16_t activeTimeout, uint8_t hashbits);
|
||||
|
||||
// events from Module
|
||||
virtual void preReconfiguration();
|
||||
|
|
|
@ -245,139 +245,6 @@ Rules::~Rules() {
|
|||
Rules::Rules() : count(0) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads in a ruleset from the specified file
|
||||
*/
|
||||
Rules::Rules(char* fname) {
|
||||
FILE* f;
|
||||
char buf[MAX_LINE_LEN];
|
||||
char* p;
|
||||
int lineNo = 0;
|
||||
int block = 0;
|
||||
|
||||
count = 0;
|
||||
|
||||
Rule* currentRule = new Rule();
|
||||
|
||||
Rule::Field* ruleField = new Rule::Field();
|
||||
|
||||
f = fopen(fname, "r");
|
||||
assert(f);
|
||||
|
||||
while (fgets(buf, sizeof(buf), f)) {
|
||||
lineNo++;
|
||||
if (strlen(buf) < 3) continue;
|
||||
if (*buf == '#') continue;
|
||||
p = buf;
|
||||
char* col1 = get_next_token(&p, " \t\n");
|
||||
char* modifier = get_next_token(&p, " \t\n");
|
||||
char* field = get_next_token(&p, " \t\n");
|
||||
get_next_token(&p, " \t\n");
|
||||
char* pattern = get_next_token(&p, " \t\n");
|
||||
|
||||
if (col1 && *col1 != 0) {
|
||||
if(strcmp(col1,"Aggregate")) {
|
||||
msg(MSG_ERROR, "Unparsable block %s, o.%d", fname, lineNo);
|
||||
block = 0;
|
||||
continue;
|
||||
}
|
||||
/* Start of new Rule */
|
||||
block=1;
|
||||
if (currentRule->fieldCount > 0) {
|
||||
rule[count++] = currentRule;
|
||||
currentRule = new Rule();
|
||||
}
|
||||
currentRule->id=modifier?atoi(modifier):0;
|
||||
currentRule->preceding=field?atoi(field):0;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!col1 || !block) {
|
||||
msg(MSG_ERROR, "Unparseable line in %s, l.%d", fname, lineNo);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!field) {
|
||||
msg(MSG_ERROR, "Incomplete line in %s, l.%d", fname, lineNo);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (parseModifier(modifier, &ruleField->modifier) != 0) {
|
||||
msg(MSG_ERROR, "Bad modifier \"%s\" in %s, l.%d", modifier, fname, lineNo);
|
||||
continue;
|
||||
}
|
||||
|
||||
const ipfix_identifier* ipfixid = ipfix_name_lookup(field);
|
||||
if (!ipfixid) {
|
||||
msg(MSG_ERROR, "Bad field type \"%s\" in %s, l.%d", field, fname, lineNo);
|
||||
continue;
|
||||
}
|
||||
ruleField->type = InformationElement::IeInfo(ipfixid->id, ipfixid->pen);
|
||||
|
||||
if (ruleField->type.length == 0) {
|
||||
msg(MSG_ERROR, "Bad field type \"%s\" in %s, l.%d", field, fname, lineNo);
|
||||
continue;
|
||||
}
|
||||
if ((ruleField->type.id == IPFIX_TYPEID_sourceIPv4Address) || (ruleField->type.id == IPFIX_TYPEID_destinationIPv4Address)) {
|
||||
ruleField->type.length++; // for additional mask field
|
||||
}
|
||||
|
||||
ruleField->pattern = NULL;
|
||||
if (pattern)
|
||||
switch (ruleField->type.id) {
|
||||
case IPFIX_TYPEID_protocolIdentifier:
|
||||
if (parseProtoPattern(pattern, &ruleField->pattern, &ruleField->type.length) != 0) {
|
||||
msg(MSG_ERROR, "Bad protocol pattern \"%s\" in %s, l.%d", pattern, fname, lineNo);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case IPFIX_TYPEID_sourceIPv4Address:
|
||||
case IPFIX_TYPEID_destinationIPv4Address:
|
||||
if (parseIPv4Pattern(pattern, &ruleField->pattern, &ruleField->type.length) != 0) {
|
||||
msg(MSG_ERROR, "Bad IPv4 pattern \"%s\" in %s, l.%d", pattern, fname, lineNo);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case IPFIX_TYPEID_sourceTransportPort:
|
||||
case IPFIX_TYPEID_udpSourcePort:
|
||||
case IPFIX_TYPEID_tcpSourcePort:
|
||||
case IPFIX_TYPEID_destinationTransportPort:
|
||||
case IPFIX_TYPEID_udpDestinationPort:
|
||||
case IPFIX_TYPEID_tcpDestinationPort:
|
||||
if (parsePortPattern(pattern, &ruleField->pattern, &ruleField->type.length) != 0) {
|
||||
msg(MSG_ERROR, "Bad PortRanges pattern \"%s\" in %s, l.%d", pattern, fname, lineNo);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case IPFIX_TYPEID_tcpControlBits:
|
||||
if (parseTcpFlags(pattern, &ruleField->pattern, &ruleField->type.length) != 0) {
|
||||
msg(MSG_ERROR, "Bad TCP flags pattern \"%s\" in %s, l.%d", pattern, fname, lineNo);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
msg(MSG_ERROR, "Fields of type \"%s\" cannot be matched against a pattern %s, l.%d", field, fname, lineNo);
|
||||
continue;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
currentRule->field[currentRule->fieldCount++] = ruleField;
|
||||
ruleField = new Rule::Field();
|
||||
}
|
||||
if (currentRule->fieldCount > 0) {
|
||||
rule[count++] = currentRule;
|
||||
currentRule = new Rule();
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
/* tidy up */
|
||||
delete ruleField;
|
||||
delete currentRule;
|
||||
}
|
||||
|
||||
bool operator==(const Rules &rhs, const Rules &lhs) {
|
||||
if (rhs.count != lhs.count) return false;
|
||||
|
||||
|
|
|
@ -36,7 +36,6 @@
|
|||
class Rules {
|
||||
public:
|
||||
Rules();
|
||||
Rules(char* fname);
|
||||
~Rules();
|
||||
friend bool operator==(const Rules &rhs, const Rules &lhs);
|
||||
friend bool operator!=(const Rules &rhs, const Rules &lhs);
|
||||
|
|
Loading…
Reference in New Issue