dfilter: restore support for identifiers using hyphen

Restores support for filters such as "mac-lte", that was broken
in 330d408328.

This means we are not able to support arithmetic expressions with binary
minus without spaces.

$ dftest 'tcp.port == 1-2'
dftest: "1-2" is not a valid number.
This commit is contained in:
João Valverde 2022-04-05 15:38:20 +01:00
parent 454552c149
commit 7ed5d5036e
2 changed files with 12 additions and 2 deletions

View File

@ -98,7 +98,7 @@ static gboolean parse_charconst(dfwork_t *dfw, const char *s, unsigned long *val
%}
WORD_CHAR [[:alnum:]_]
WORD_CHAR [[:alnum:]_-]
hex2 [[:xdigit:]]{2}
MacAddress {hex2}:{hex2}:{hex2}:{hex2}:{hex2}:{hex2}|{hex2}-{hex2}-{hex2}-{hex2}-{hex2}-{hex2}|{hex2}\.{hex2}\.{hex2}\.{hex2}\.{hex2}\.{hex2}
@ -388,7 +388,7 @@ v6-cidr-prefix \/[[:digit:]]{1,3}
return set_lval_str(TOKEN_LITERAL, yytext);
}
[:.]?{WORD_CHAR}+(\.{WORD_CHAR}+)* {
[:.]?[[:alnum:]_]{WORD_CHAR}*(\.{WORD_CHAR}+)* {
/* Identifier or literal or unparsed. */
if (yytext[0] == '.')
return set_lval_str(TOKEN_IDENTIFIER, yytext);

View File

@ -212,5 +212,15 @@ class case_arithmetic(unittest.TestCase):
checkDFilterCount(dfilter, 2)
def test_sub_2(self, checkDFilterCount):
dfilter = "udp.dstport == 68 - 1"
checkDFilterCount(dfilter, 2)
def test_sub_3(self, checkDFilterFail):
# Minus operator requires spaces around it.
error = '"68-1" is not a valid number.'
dfilter = "udp.dstport == 68-1"
checkDFilterFail(dfilter, error)
def test_sub_4(self, checkDFilterCount):
dfilter = "udp.length == ip.len - 20"
checkDFilterCount(dfilter, 4)