From c3d57114f119b89ec0caa0b4dfa8527826a38792 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Thu, 13 May 2021 01:34:01 +0200 Subject: parser_bison: add shortcut syntax for matching flags without binary operations This patch adds the following shortcut syntax: expression flags / flags instead of: expression and flags == flags For example: tcp flags syn,ack / syn,ack,fin,rst ^^^^^^^ ^^^^^^^^^^^^^^^ value mask instead of: tcp flags and (syn|ack|fin|rst) == syn|ack The second list of comma-separated flags represents the mask which are examined and the first list of comma-separated flags must be set. You can also use the != operator with this syntax: tcp flags != fin,rst / syn,ack,fin,rst This shortcut is based on the prefix notation, but it is also similar to the iptables tcp matching syntax. This patch introduces the flagcmp expression to print the tcp flags in this new notation. The delinearize path transforms the binary expression to this new flagcmp expression whenever possible. Signed-off-by: Pablo Neira Ayuso --- src/json.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/json.c') diff --git a/src/json.c b/src/json.c index b4197b2f..69ca9697 100644 --- a/src/json.c +++ b/src/json.c @@ -479,6 +479,20 @@ static json_t *table_print_json(const struct table *table) return json_pack("{s:o}", "table", root); } +json_t *flagcmp_expr_json(const struct expr *expr, struct output_ctx *octx) +{ + json_t *left; + + left = json_pack("{s:[o, o]}", expr_op_symbols[OP_AND], + expr_print_json(expr->flagcmp.expr, octx), + expr_print_json(expr->flagcmp.mask, octx)); + + return json_pack("{s:{s:s, s:o, s:o}}", "match", + "op", expr_op_symbols[expr->op] ? : "in", + "left", left, + "right", expr_print_json(expr->flagcmp.value, octx)); +} + json_t *binop_expr_json(const struct expr *expr, struct output_ctx *octx) { return json_pack("{s:[o, o]}", expr_op_symbols[expr->op], -- cgit v1.2.3