summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2021-03-24 17:19:32 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2021-03-25 12:12:13 +0100
commita3e215d7f68f41556912c33b3dcf12781f6b9b59 (patch)
tree8ed2f03a0ed14fe85634beea17ed3ab3195f4a05 /src
parent8e6cc9f373854ed580156ec6f01bcd97786fa9f7 (diff)
src: add datatype->describe()
As an alternative to print the datatype values when no symbol table is available. Use it to print protocols available via getprotobynumber() which actually refers to /etc/protocols. Not very efficient, getprotobynumber() causes a series of open()/close() calls on /etc/protocols, but this is called from a non-critical path. Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1503 Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src')
-rw-r--r--src/datatype.c15
-rw-r--r--src/expression.c2
2 files changed, 17 insertions, 0 deletions
diff --git a/src/datatype.c b/src/datatype.c
index 7382307e..fae1aa26 100644
--- a/src/datatype.c
+++ b/src/datatype.c
@@ -619,6 +619,20 @@ static void inet_protocol_type_print(const struct expr *expr,
integer_type_print(expr, octx);
}
+static void inet_protocol_type_describe(struct output_ctx *octx)
+{
+ struct protoent *p;
+ uint8_t protonum;
+
+ for (protonum = 0; protonum < UINT8_MAX; protonum++) {
+ p = getprotobynumber(protonum);
+ if (!p)
+ continue;
+
+ nft_print(octx, "\t%-30s\t%u\n", p->p_name, protonum);
+ }
+}
+
static struct error_record *inet_protocol_type_parse(struct parse_ctx *ctx,
const struct expr *sym,
struct expr **res)
@@ -658,6 +672,7 @@ const struct datatype inet_protocol_type = {
.print = inet_protocol_type_print,
.json = inet_protocol_type_json,
.parse = inet_protocol_type_parse,
+ .describe = inet_protocol_type_describe,
};
static void inet_service_print(const struct expr *expr, struct output_ctx *octx)
diff --git a/src/expression.c b/src/expression.c
index 0c5276d1..9fdf23d9 100644
--- a/src/expression.c
+++ b/src/expression.c
@@ -172,6 +172,8 @@ void expr_describe(const struct expr *expr, struct output_ctx *octx)
nft_print(octx, "(in hexadecimal):\n");
symbol_table_print(edtype->sym_tbl, edtype,
expr->byteorder, octx);
+ } else if (edtype->describe) {
+ edtype->describe(octx);
}
}