From 21cbab5b6ffec409d5677802bcd1172d0d1cd990 Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Sun, 13 Oct 2019 00:17:52 +0200 Subject: expression: extend 'nft describe' to allow listing data types nft describe ct_status before: symbol expression, datatype invalid (invalid), 0 bits after: datatype ct_status (conntrack status) (basetype bitmask, integer), 32 bits pre-defined symbolic constants (in hexadecimal): expected 0x00000001 seen-reply 0x00000002 [..] Signed-off-by: Florian Westphal Acked-by: Pablo Neira Ayuso --- src/expression.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/expression.c b/src/expression.c index cb49e0b7..e456010f 100644 --- a/src/expression.c +++ b/src/expression.c @@ -122,11 +122,24 @@ const char *expr_name(const struct expr *e) void expr_describe(const struct expr *expr, struct output_ctx *octx) { - const struct datatype *dtype = expr->dtype; + const struct datatype *dtype = expr->dtype, *edtype = NULL; + unsigned int len = expr->len; const char *delim = ""; - nft_print(octx, "%s expression, datatype %s (%s)", - expr_name(expr), dtype->name, dtype->desc); + if (dtype == &invalid_type && + expr->etype == EXPR_SYMBOL) + edtype = datatype_lookup_byname(expr->identifier); + + if (edtype) { + dtype = edtype; + nft_print(octx, "datatype %s (%s)", + dtype->name, dtype->desc); + len = dtype->size; + } else { + nft_print(octx, "%s expression, datatype %s (%s)", + expr_name(expr), dtype->name, dtype->desc); + } + if (dtype->basetype != NULL) { nft_print(octx, " (basetype "); for (dtype = dtype->basetype; dtype != NULL; @@ -138,23 +151,26 @@ void expr_describe(const struct expr *expr, struct output_ctx *octx) } if (expr_basetype(expr)->type == TYPE_STRING) { - if (expr->len) + if (len) nft_print(octx, ", %u characters", - expr->len / BITS_PER_BYTE); + len / BITS_PER_BYTE); else nft_print(octx, ", dynamic length"); } else - nft_print(octx, ", %u bits", expr->len); + nft_print(octx, ", %u bits", len); + + if (!edtype) + edtype = expr->dtype; nft_print(octx, "\n"); - if (expr->dtype->sym_tbl != NULL) { + if (edtype->sym_tbl != NULL) { nft_print(octx, "\npre-defined symbolic constants "); - if (expr->dtype->sym_tbl->base == BASE_DECIMAL) + if (edtype->sym_tbl->base == BASE_DECIMAL) nft_print(octx, "(in decimal):\n"); else nft_print(octx, "(in hexadecimal):\n"); - symbol_table_print(expr->dtype->sym_tbl, expr->dtype, + symbol_table_print(edtype->sym_tbl, edtype, expr->byteorder, octx); } } -- cgit v1.2.3