netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Elise Lennion <elise.lennion@gmail.com>
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH nft] datatype: Display pre-defined inet_service values in host byte order
Date: Mon, 5 Dec 2016 22:30:38 -0200	[thread overview]
Message-ID: <20161206003037.GA7097@lennorien.com> (raw)

nft describe displays, to the user, which values are available for a selector,
then the values should be in host byte order.

Reported-by: Pablo Neira Ayuso <pablo@netfilter.org>
Fixes: ccc5da470e76 ("datatype: Replace getnameinfo() by internal lookup table")
Signed-off-by: Elise Lennion <elise.lennion@gmail.com>
---
 include/datatype.h |  3 ++-
 src/datatype.c     | 14 +++++++++++---
 src/expression.c   |  3 ++-
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/include/datatype.h b/include/datatype.h
index d4fe817..a7db1df 100644
--- a/include/datatype.h
+++ b/include/datatype.h
@@ -191,7 +191,8 @@ extern struct error_record *symbolic_constant_parse(const struct expr *sym,
 extern void symbolic_constant_print(const struct symbol_table *tbl,
 				    const struct expr *expr, bool quotes);
 extern void symbol_table_print(const struct symbol_table *tbl,
-			       const struct datatype *dtype);
+			       const struct datatype *dtype,
+			       enum byteorder byteorder);
 
 extern struct symbol_table *rt_symbol_table_init(const char *filename);
 extern void rt_symbol_table_free(struct symbol_table *tbl);
diff --git a/src/datatype.c b/src/datatype.c
index b5d73bc..4f98a83 100644
--- a/src/datatype.c
+++ b/src/datatype.c
@@ -181,14 +181,22 @@ void symbolic_constant_print(const struct symbol_table *tbl,
 }
 
 void symbol_table_print(const struct symbol_table *tbl,
-			const struct datatype *dtype)
+			const struct datatype *dtype,
+			enum byteorder byteorder)
 {
 	const struct symbolic_constant *s;
 	unsigned int size = 2 * dtype->size / BITS_PER_BYTE;
+	long unsigned int value;
+
+	for (s = tbl->symbols; s->identifier != NULL; s++) {
+		if (byteorder == BYTEORDER_BIG_ENDIAN)
+			value = __constant_ntohs(s->value);
+		else
+			value = s->value;
 
-	for (s = tbl->symbols; s->identifier != NULL; s++)
 		printf("\t%-30s\t0x%.*" PRIx64 "\n",
-		       s->identifier, size, s->value);
+		       s->identifier, size, value);
+	}
 }
 
 static void invalid_type_print(const struct expr *expr)
diff --git a/src/expression.c b/src/expression.c
index a10af5d..2aada77 100644
--- a/src/expression.c
+++ b/src/expression.c
@@ -115,7 +115,8 @@ void expr_describe(const struct expr *expr)
 
 	if (expr->dtype->sym_tbl != NULL) {
 		printf("\npre-defined symbolic constants:\n");
-		symbol_table_print(expr->dtype->sym_tbl, expr->dtype);
+		symbol_table_print(expr->dtype->sym_tbl, expr->dtype,
+				   expr->byteorder);
 	}
 }
 
-- 
2.7.4


             reply	other threads:[~2016-12-06  0:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-06  0:30 Elise Lennion [this message]
2016-12-06 10:00 ` [PATCH nft] datatype: Display pre-defined inet_service values in host byte order Pablo Neira Ayuso

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=20161206003037.GA7097@lennorien.com \
    --to=elise.lennion@gmail.com \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.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).