dfilter: Add support for negation of arithmetic expressions

This commit is contained in:
João Valverde 2022-12-22 18:31:32 +00:00
parent 5dcefc7777
commit 4e1211de90
5 changed files with 10 additions and 4 deletions

View File

@ -60,6 +60,8 @@ The following features are new (or have been significantly updated) since versio
This can be useful to filter on malformed UTF-8 strings, among other use cases where it is necessary to
look at the field's raw data.
* Negation (unary minus) now works with any display filter arithmetic expression.
* ciscodump support Cisco IOS XE 17.x
// === Removed Features and Support

View File

@ -438,7 +438,7 @@ dfvm_dump_str(wmem_allocator_t *alloc, dfilter_t *df, gboolean print_references)
break;
case DFVM_UNARY_MINUS:
wmem_strbuf_append_printf(buf, "%05d %s\t\t-%s -> %s\n",
wmem_strbuf_append_printf(buf, "%05d %s\t-%s -> %s\n",
id, opcode_str, arg1_str, arg2_str);
break;

View File

@ -234,12 +234,12 @@ arithmetic_expr(T) ::= entity(N).
T = N;
}
arithmetic_expr(T) ::= PLUS entity(N). [UNARY_PLUS]
arithmetic_expr(T) ::= PLUS arithmetic_expr(N). [UNARY_PLUS]
{
T = N;
}
arithmetic_expr(T) ::= MINUS(M) entity(N). [UNARY_MINUS]
arithmetic_expr(T) ::= MINUS(M) arithmetic_expr(N). [UNARY_MINUS]
{
T = M;
sttype_oper_set1(T, STNODE_OP_UNARY_MINUS, N);

View File

@ -1206,7 +1206,7 @@ check_arithmetic_expr(dfwork_t *dfw, stnode_t *st_node, ftenum_t lhs_ftype)
}
if (st_op == STNODE_OP_UNARY_MINUS) {
ftype1 = check_arithmetic_entity(dfw, st_arg1, lhs_ftype);
ftype1 = check_arithmetic_expr(dfw, st_arg1, lhs_ftype);
if (!ftype_can_unary_minus(ftype1)) {
FAIL(dfw, st_arg1, "%s %s.",
ftype_name(ftype1), op_to_error_msg(st_op));

View File

@ -232,6 +232,10 @@ class case_unary_minus(unittest.TestCase):
dfilter = "-2 == tcp.dstport"
checkDFilterFail(dfilter, error)
def test_unary_4(self, checkDFilterCount):
dfilter = "tcp.window_size_scalefactor == -{tcp.dstport * 20}"
checkDFilterCount(dfilter, 0)
@fixtures.uses_fixtures
class case_arithmetic(unittest.TestCase):
trace_file = "dhcp.pcap"