Skip to content

Commit

Permalink
Cleanup grammar. Fix error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
phaag committed Jul 20, 2024
1 parent a253e80 commit 3a9908e
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 40 deletions.
2 changes: 2 additions & 0 deletions src/libnfdump/filter/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ typedef enum {
BGP_NEXT,
DIR_INGRESS,
DIR_EGRESS,
DIR_CLIENT,
DIR_SERVER,
SRC_ROUTER
} direction_t;

Expand Down
79 changes: 43 additions & 36 deletions src/libnfdump/filter/grammar.y
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static int AddMAC(direction_t direction, char *macString);

static int AddEthertype(uint64_t etherType);

static int AddLatency(char *type, uint16_t comp, uint64_t number);
static int AddLatency(direction_t direction, uint16_t comp, uint64_t number);

static int AddASAString(char *event, char *asaStr);

Expand Down Expand Up @@ -177,6 +177,7 @@ static int AddASList(direction_t direction, void *U64List);
%token ANY NOT IDENT COUNT
%token IP IPV4 IPV6 IPTTL NET
%token SRC DST IN OUT PREV NEXT BGP ROUTER INGRESS EGRESS
%token CLIENT SERVER
%token NAT XLATE TUN
%token ENGINE ENGINETYPE ENGINEID EXPORTER
%token DURATION PPS BPS BPP FLAGS
Expand Down Expand Up @@ -224,7 +225,7 @@ term: ANY { /* this is an unconditionally true expression, as a filter applies i

| ENGINETYPE comp NUMBER {
$$.self = AddEngineNum("type", $2.comp, $3); if ( $$.self < 0 ) YYABORT;
}
}

| ENGINEID comp NUMBER {
$$.self = AddEngineNum("id", $2.comp, $3); if ( $$.self < 0 ) YYABORT;
Expand All @@ -234,21 +235,21 @@ term: ANY { /* this is an unconditionally true expression, as a filter applies i
$$.self = AddEngineNum($2, $3.comp, $4); if ( $$.self < 0 ) YYABORT;
}

| EXPORTER STRING comp NUMBER {
$$.self = AddExporterNum($2, $3.comp, $4); if ( $$.self < 0 ) YYABORT;
| EXPORTER STRING comp NUMBER {
$$.self = AddExporterNum($2, $3.comp, $4); if ( $$.self < 0 ) YYABORT;
}

| dqual PROTO NUMBER {
$$.self = AddProto($1.direction, NULL, $3); if ( $$.self < 0 ) YYABORT;
}
| dqual PROTO NUMBER {
$$.self = AddProto($1.direction, NULL, $3); if ( $$.self < 0 ) YYABORT;
}

| dqual PROTO STRING {
$$.self = AddProto($1.direction, $3, 0); if ( $$.self < 0 ) YYABORT;
}
| dqual PROTO STRING {
$$.self = AddProto($1.direction, $3, 0); if ( $$.self < 0 ) YYABORT;
}

| dqual PROTO ICMP {
$$.self = AddProto($1.direction, "icmp", 0); if ( $$.self < 0 ) YYABORT;
}
| dqual PROTO ICMP {
$$.self = AddProto($1.direction, "icmp", 0); if ( $$.self < 0 ) YYABORT;
}

| dqual PORT comp NUMBER {
$$.self = AddPortNumber($1.direction, $3.comp, $4); if ( $$.self < 0 ) YYABORT;
Expand All @@ -275,20 +276,20 @@ term: ANY { /* this is an unconditionally true expression, as a filter applies i
}

| dqual TOS comp NUMBER {
$$.self = AddTosNumber($1.direction, $3.comp, $4); if ( $$.self < 0 ) YYABORT;
$$.self = AddTosNumber($1.direction, $3.comp, $4); if ( $$.self < 0 ) YYABORT;
}

| IPTTL comp NUMBER {
$$.self = AddIPttl($2.comp, $3); if ( $$.self < 0 ) YYABORT;
$$.self = AddIPttl($2.comp, $3); if ( $$.self < 0 ) YYABORT;
}

| FWDSTAT comp NUMBER {
$$.self = AddFwdStatNum($2.comp, $3); if ( $$.self < 0 ) YYABORT;
$$.self = AddFwdStatNum($2.comp, $3); if ( $$.self < 0 ) YYABORT;
}

| FWDSTAT STRING {
$$.self = AddFwdStatString($2); if ( $$.self < 0 ) YYABORT;
}
$$.self = AddFwdStatString($2); if ( $$.self < 0 ) YYABORT;
}

| DURATION comp NUMBER {
$$.self = NewElement(EXgenericFlowID, 0, SIZEmsecLast, $3, $2.comp, FUNC_DURATION, NULLPtr);
Expand Down Expand Up @@ -356,7 +357,7 @@ term: ANY { /* this is an unconditionally true expression, as a filter applies i

| FLOWDIR dqual {
$$.self = AddFlowDir($2.direction, -1); if ( $$.self < 0 ) YYABORT;
}
}

| MPLS STRING comp NUMBER {
$$.self = AddMPLS($2, $3.comp, $4); if ( $$.self < 0 ) YYABORT;
Expand All @@ -370,8 +371,8 @@ term: ANY { /* this is an unconditionally true expression, as a filter applies i
$$.self = AddMAC($1.direction, $3); if ( $$.self < 0 ) YYABORT;
}

| STRING LATENCY comp NUMBER {
$$.self = AddLatency($1, $3.comp, $4); if ( $$.self < 0 ) YYABORT;
| dqual LATENCY comp NUMBER {
$$.self = AddLatency($1.direction, $3.comp, $4); if ( $$.self < 0 ) YYABORT;
}

| ASA STRING STRING {
Expand Down Expand Up @@ -521,28 +522,30 @@ comp: { $$.comp = CMP_EQ; }
;

/* direction qualifiers for direction related elements or specifier for elements */
dqual: { $$.direction = DIR_UNSPEC; }
| SRC { $$.direction = DIR_SRC; }
| DST { $$.direction = DIR_DST; }
dqual: { $$.direction = DIR_UNSPEC; }
| SRC { $$.direction = DIR_SRC; }
| DST { $$.direction = DIR_DST; }
| SRC NAT { $$.direction = DIR_SRC_NAT; }
| DST NAT { $$.direction = DIR_DST_NAT; }
| DST NAT { $$.direction = DIR_DST_NAT; }
| SRC TUN { $$.direction = DIR_SRC_TUN; }
| DST TUN { $$.direction = DIR_DST_TUN; }
| DST TUN { $$.direction = DIR_DST_TUN; }
| NAT { $$.direction = DIR_UNSPEC_NAT; }
| TUN { $$.direction = DIR_UNSPEC_TUN; }
| IN { $$.direction = DIR_IN; }
| OUT { $$.direction = DIR_OUT; }
| IN { $$.direction = DIR_IN; }
| OUT { $$.direction = DIR_OUT; }
| IN SRC { $$.direction = DIR_IN_SRC; }
| IN DST { $$.direction = DIR_IN_DST; }
| OUT SRC { $$.direction = DIR_OUT_SRC; }
| OUT DST { $$.direction = DIR_OUT_DST; }
| INGRESS { $$.direction = DIR_INGRESS; }
| EGRESS { $$.direction = DIR_EGRESS; }
| CLIENT { $$.direction = DIR_CLIENT; }
| SERVER { $$.direction = DIR_SERVER; }
| PREV { $$.direction = DIR_PREV; }
| NEXT { $$.direction = DIR_NEXT; }
| BGP NEXT { $$.direction = BGP_NEXT; }
| BGP NEXT { $$.direction = BGP_NEXT; }
| ROUTER { $$.direction = SRC_ROUTER; }
| EXPORTER { $$.direction = SRC_ROUTER; }
| EXPORTER { $$.direction = SRC_ROUTER; }
;

expr: term { $$ = $1.self; }
Expand Down Expand Up @@ -1061,16 +1064,20 @@ static int AddMAC(direction_t direction, char *macString) {
return -1;
} // End of AddMAC

static int AddLatency(char *type, uint16_t comp, uint64_t number) {
static int AddLatency(direction_t direction, uint16_t comp, uint64_t number) {

int ret = -1;
if ( strcasecmp(type, "client") == 0 ) {
switch (direction) {
case DIR_CLIENT:
ret = NewElement(EXlatencyID, OFFusecClientNwDelay, SIZEusecClientNwDelay, number, comp, FUNC_NONE, NULLPtr);
} if ( strcasecmp(type, "server") == 0 ) {
break;
case DIR_SERVER:
ret = NewElement(EXlatencyID, OFFusecServerNwDelay, SIZEusecServerNwDelay, number, comp, FUNC_NONE, NULLPtr);
} if ( strcasecmp(type, "app") == 0 ) {
ret = NewElement(EXlatencyID, OFFusecApplLatency, SIZEusecApplLatency, number, comp, FUNC_NONE, NULLPtr);
}
break;
// case XXX ret = NewElement(EXlatencyID, OFFusecApplLatency, SIZEusecApplLatency, number, comp, FUNC_NONE, NULLPtr);
default:
yyprintf("Unknown latency argument");
}

return ret;
} // End of AddLatency
Expand Down
2 changes: 2 additions & 0 deletions src/libnfdump/filter/scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ xlate { return NAT; }
tun { return TUN; }
ingress { return INGRESS;}
egress { return EGRESS; }
client { return CLIENT; }
server { return SERVER; }

and { return AND; }
or { return OR; }
Expand Down
2 changes: 1 addition & 1 deletion src/libnffile/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ double t(void) {
/*
** usleep(3) implemented with select.
*/
void xsleep(suseconds_t usec) {
void xsleep(useconds_t usec) {
struct timeval tv;

tv.tv_sec = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/libnffile/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ typedef struct timeWindow_s {

double t(void);

void xsleep(suseconds_t usec);
void xsleep(useconds_t usec);

void CheckArgLen(char *arg, size_t len);

Expand Down
4 changes: 2 additions & 2 deletions src/test/nftest.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,10 @@ static void runTest(void) {

CheckFilter("client latency 11", recordHandle, 1);
CheckFilter("server latency 22", recordHandle, 1);
CheckFilter("app latency 33", recordHandle, 1);
// CheckFilter("app latency 33", recordHandle, 1);
CheckFilter("client latency 12", recordHandle, 0);
CheckFilter("server latency 23", recordHandle, 0);
CheckFilter("app latency 34", recordHandle, 0);
// CheckFilter("app latency 34", recordHandle, 0);
CheckFilter("client latency < 11", recordHandle, 0);
CheckFilter("client latency > 11", recordHandle, 0);

Expand Down

0 comments on commit 3a9908e

Please sign in to comment.