Skip to content

Commit

Permalink
Fix #560 - geo filter containing keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
phaag committed Aug 27, 2024
1 parent dfb736f commit ae52e09
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/libnfdump/filter/grammar.y
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,10 @@ static int AddASList(direction_t direction, void *U64List);
%token DURATION PPS BPS BPP FLAGS
%token PROTO PORT AS IF VLAN MPLS MAC ICMP ICMPTYPE ICMPCODE
%token PACKETS BYTES FLOWS ETHERTYPE
%token MASK FLOWDIR TOS FWDSTAT LATENCY ASA ACL PAYLOAD GEO VRF
%token MASK FLOWDIR TOS FWDSTAT LATENCY ASA ACL PAYLOAD VRF
%token OBSERVATION PF
%token <s> STRING
%token <s> GEOSTRING
%token <value> NUMBER
%type <value> expr
%type <param> dqual term comp
Expand Down Expand Up @@ -426,8 +427,8 @@ term: ANY { /* this is an unconditionally true expression, as a filter applies i
$$.self = AddPayload($2, $3, $4); if ( $$.self < 0 ) YYABORT;
}

| dqual GEO STRING {
$$.self = AddGeo($1.direction, $3); if ( $$.self < 0 ) YYABORT;
| dqual GEOSTRING {
$$.self = AddGeo($1.direction, $2); if ( $$.self < 0 ) YYABORT;
}

| OBSERVATION STRING STRING comp NUMBER {
Expand Down Expand Up @@ -1352,6 +1353,7 @@ static int AddPayload(char *type, char *arg, char *opt) {

static int AddGeo(direction_t direction, char *geo) {

geo += 4;
if ( strlen(geo) != 2 ) {
yyprintf("Unknown Geo country: %s. Need a two letter country code.", geo);
return -1;
Expand Down
15 changes: 9 additions & 6 deletions src/libnfdump/filter/scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ not|"!" { return NOT; }
"<" { return LT; }
">=" { return GE; }
"<=" { return LE; }
"eq" { return EQ; }
"gt" { return GT; }
"lt" { return LT; }
"ge" { return GE; }
"le" { return LE; }
"eq" { return EQ; }
"gt" { return GT; }
"lt" { return LT; }
"ge" { return GE; }
"le" { return LE; }

"engine" { return ENGINE; }
"engine-type" { return ENGINETYPE; }
Expand Down Expand Up @@ -190,7 +190,6 @@ not|"!" { return NOT; }
"asa" { return ASA; }
"acl" { return ACL; }
"payload" { return PAYLOAD; }
"geo" { return GEO; }
"vrf" { return VRF; }
"pf" { return PF; }

Expand All @@ -214,6 +213,10 @@ not|"!" { return NOT; }
yylval.s = stripQuotes(yytext);
return STRING;
}
geo\ [a-zA-Z]{2} {
yylval.s = stripQuotes(yytext);
return GEOSTRING;
}
\n { lineno++; }
. { return yytext[0]; }
Expand Down

0 comments on commit ae52e09

Please sign in to comment.