Skip to contentSkip to conversation

datatype: Display pre-defined inet_service values in decimal base

PATCH Applied Elise Lennion 2 participants 2 messages Dec 10, 2016 – Dec 11, 2016 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 datatype: Display pre-defined inet_service values in decimal base

because the convention is to represent ports in base 10.

gcc-workaround is no longer needed and was removed.

---
 include/datatype.h | 18 +++++++++++++++++-
 src/datatype.c     |  7 +++++--
 src/services.c     |  3 ++-
 3 files changed, 24 insertions(+), 4 deletions(-)
include/datatype.h +17 -1
index a7db1df..cf76fcf 100644
@@ -176,12 +176,28 @@ struct symbolic_constant {
 #define SYMBOL_LIST_END	(struct symbolic_constant) { }
 
 /**
+ * enum base
+ *
+ * @BASE_HEXADECIMAL:	hexadecimal
+ * @BASE_DECIMAL:	decimal
+ * @BASE_OCTAL:		octal
+ * @BASE_BINARY:	binary
+ */
+enum base {
+	BASE_HEXADECIMAL,
+	BASE_DECIMAL,
+	BASE_OCTAL,
+	BASE_BINARY,
+};
+
+/**
  * struct symbol_table - type construction from symbolic values
  *
+ * @base:	base of symbols representation
  * @symbols:	the symbols
  */
 struct symbol_table {
-	int				gcc_workaround;
+	enum base 			base;
 	struct symbolic_constant	symbols[];
 };
 
src/datatype.c +5 -2
index 5600efc..ec0b120 100644
@@ -204,8 +204,11 @@ void symbol_table_print(const struct symbol_table *tbl,
 		if (byteorder == BYTEORDER_BIG_ENDIAN)
 			switch_byteorder(&value, len);
 
-		printf("\t%-30s\t0x%.*" PRIx64 "\n",
-		       s->identifier, 2 * len, value);
+		if (tbl->base == BASE_DECIMAL)
+			printf("\t%-30s\t%20lu\n", s->identifier, value);
+		else
+			printf("\t%-30s\t0x%.*" PRIx64 "\n",
+			       s->identifier, 2 * len, value);
 	}
 }
 
src/services.c +2 -1
index 0ba195e..83c2672 100644
@@ -2,7 +2,8 @@
 #include <datatype.h>
 
 const struct symbol_table inet_service_tbl = {
-	.symbols =	{
+	.base		= BASE_DECIMAL,
+	.symbols	= {
 		SYMBOL("tcpmux",		__constant_htons(1)),
 		SYMBOL("echo",			__constant_htons(7)),
 		SYMBOL("discard",		__constant_htons(9)),
Signature · 1 line
2.7.4
maintainer Applied
#1 lore raw
Quoted 3 lines · Elise Lennion

because the convention is to represent ports in base 10.

gcc-workaround is no longer needed and was removed.

Applied, thanks Elise.

It would be good if you can send a follow up patch to modified this message that nft describe prints:

pre-defined symbolic constants:

to:

pre-defined symbolic constants (in hexadecimal):
^^^^^^^^^^^^^^^^

So the user knows how we express it.

Please, also review all existing symbol tables and add the base to them, I guess a bit of googling should lead you to the right convention dependending on the datatype, in case of doubt, make a summary and ask for feedback on the mailing list.

Thanks.