From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH] src: add datatype->describe()
Date: Wed, 24 Mar 2021 17:19:32 +0100 [thread overview]
Message-ID: <20210324161932.16387-1-pablo@netfilter.org> (raw)
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.
Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1503
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/datatype.h | 1 +
src/datatype.c | 15 +++++++++++++++
src/expression.c | 2 ++
3 files changed, 18 insertions(+)
diff --git a/include/datatype.h b/include/datatype.h
index 1061a389b0f0..a16f8f2bf5c4 100644
--- a/include/datatype.h
+++ b/include/datatype.h
@@ -164,6 +164,7 @@ struct datatype {
struct error_record *(*parse)(struct parse_ctx *ctx,
const struct expr *sym,
struct expr **res);
+ void (*describe)(struct output_ctx *octx);
const struct symbol_table *sym_tbl;
unsigned int refcnt;
};
diff --git a/src/datatype.c b/src/datatype.c
index 7382307e9909..461ee33754b8 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 < 255; 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 0c5276d1118d..9fdf23d98446 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);
}
}
--
2.30.2
reply other threads:[~2021-03-24 16:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210324161932.16387-1-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).