summaryrefslogtreecommitdiffstats
path: root/src/datatype.c
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2023-12-22 17:00:44 +0100
committerPhil Sutter <phil@nwl.cc>2024-01-02 18:29:51 +0100
commit17cef81a8d1d119f457a01214a86e2c0e883ce8f (patch)
treebec6cf88905a9895e6fdffad9e63c2905effde4f /src/datatype.c
parentd9badd39deb7e2f9509be75e83477ab0a0bf2740 (diff)
datatype: Describe rt symbol tables
Implement a symbol_table_print() wrapper for the run-time populated rt_symbol_tables which formats output similar to expr_describe() and includes the data source. Since these tables reside in struct output_ctx there is no implicit connection between data type and therefore providing callbacks for relevant datat types which feed the data into said wrapper is a simpler solution than extending expr_describe() itself. Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'src/datatype.c')
-rw-r--r--src/datatype.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/datatype.c b/src/datatype.c
index 4d867798..3b19ae8e 100644
--- a/src/datatype.c
+++ b/src/datatype.c
@@ -946,6 +946,33 @@ void rt_symbol_table_free(const struct symbol_table *tbl)
free_const(tbl);
}
+void rt_symbol_table_describe(struct output_ctx *octx, const char *name,
+ const struct symbol_table *tbl,
+ const struct datatype *type)
+{
+ char *path = NULL;
+ FILE *f;
+
+ if (!tbl || !tbl->symbols[0].identifier)
+ return;
+
+ f = open_iproute2_db(name, &path);
+ if (f)
+ fclose(f);
+ if (!path && asprintf(&path, "%s%s",
+ name[0] == '/' ? "" : "unknown location of ",
+ name) < 0)
+ return;
+
+ nft_print(octx, "\npre-defined symbolic constants from %s ", path);
+ if (tbl->base == BASE_DECIMAL)
+ nft_print(octx, "(in decimal):\n");
+ else
+ nft_print(octx, "(in hexadecimal):\n");
+ symbol_table_print(tbl, type, type->byteorder, octx);
+ free(path);
+}
+
void mark_table_init(struct nft_ctx *ctx)
{
ctx->output.tbl.mark = rt_symbol_table_init("rt_marks");
@@ -968,10 +995,17 @@ static struct error_record *mark_type_parse(struct parse_ctx *ctx,
return symbolic_constant_parse(ctx, sym, ctx->tbl->mark, res);
}
+static void mark_type_describe(struct output_ctx *octx)
+{
+ rt_symbol_table_describe(octx, "rt_marks",
+ octx->tbl.mark, &mark_type);
+}
+
const struct datatype mark_type = {
.type = TYPE_MARK,
.name = "mark",
.desc = "packet mark",
+ .describe = mark_type_describe,
.size = 4 * BITS_PER_BYTE,
.byteorder = BYTEORDER_HOST_ENDIAN,
.basetype = &integer_type,