Skip to contentSkip to conversation

datatype: default to display bitmask in hexadecimal

PATCH New Pablo Neira Ayuso 1 participant 2 messages Jun 5, 2015 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/2 datatype: default to display bitmask in hexadecimal

Instead of a plain integer.

This updates integer_type_print() to look up some basefmt in the change of datatype, the first we find will be used to format the output.

---
 src/datatype.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
src/datatype.c +9 -2
index f93337b..82a7753 100644
@@ -260,15 +260,22 @@ const struct datatype bitmask_type = {
 	.type		= TYPE_BITMASK,
 	.name		= "bitmask",
 	.desc		= "bitmask",
+	.basefmt	= "0x%Zx",
 	.basetype	= &integer_type,
 };
 
 static void integer_type_print(const struct expr *expr)
 {
+	const struct datatype *dtype = expr->dtype;
 	const char *fmt = "%Zu";
 
-	if (expr->dtype->basefmt != NULL)
-		fmt = expr->dtype->basefmt;
+	do {
+		if (dtype->basefmt != NULL) {
+			fmt = dtype->basefmt;
+			break;
+		}
+	} while ((dtype = dtype->basetype));
+
 	gmp_printf(fmt, expr->value);
 }
 
Signature · 1 line
1.7.10.4
author maintainer
#1 lore raw

PATCH 2/2 proto: use bitmask_type for comp flags

I think flags should be displayed in hexadecimal and should be handled as a bitmask.

inet/comp.t: WARNING: line: 15: 'nft add rule ip test-ip4 input comp flags 0x00': 'comp flags 0x00' mismatches 'comp flags 0'
inet/comp.t: WARNING: line: 16: 'nft add rule ip test-ip4 input comp flags != 0x23': 'comp flags != 0x23' mismatches 'comp flags != 35'
inet/comp.t: WARNING: line: 17: 'nft add rule ip test-ip4 input comp flags 0x33-0x45': 'comp flags 0x33-0x45' mismatches 'comp flags 51-69'
inet/comp.t: WARNING: line: 18: 'nft add rule ip test-ip4 input comp flags != 0x33-0x45': 'comp flags != 0x33-0x45' mismatches 'comp flags != 51-69' inet/comp.t: WARNING: line: 19: 'nft add rule ip test-ip4 input comp flags {0x33, 0x55, 0x67, 0x88}': 'comp flags {0x33, 0x55, 0x67, 0x88}' mismatches 'comp flags { 103, 85, 51, 136}' inet/comp.t: WARNING: line: 21: 'nft add rule ip test-ip4 input comp flags { 0x33-0x55}': 'comp flags { 0x33-0x55}' mismatches 'comp flags { 51-85}'

rfc3173 says that this is unused for future use, but I think this should be printed as hexadecimal in any case.

---
 src/proto.c                  |    2 +-
 tests/regression/inet/comp.t |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
src/proto.c +1 -1
index 7dc7b3e..6302016 100644
@@ -272,7 +272,7 @@ const struct proto_desc proto_comp = {
 	},
 	.templates	= {
 		[COMPHDR_NEXTHDR]	= INET_PROTOCOL("nexthdr", struct ip_comp_hdr, nexthdr),
-		[COMPHDR_FLAGS]		= COMPHDR_FIELD("flags", flags),
+		[COMPHDR_FLAGS]		= HDR_TEMPLATE("flags", &bitmask_type, struct ip_comp_hdr, flags),
 		[COMPHDR_CPI]		= COMPHDR_FIELD("cpi", cpi),
 	},
 };
tests/regression/inet/comp.t +1 -1
index afdc63f..f4753bb 100644
@@ -12,7 +12,7 @@ comp nexthdr != esp;ok;comp nexthdr != 50
 # comp flags ## 8-bit field.  Reserved for future use.  MUST be set to zero.
 
 # Bug comp flags: to list. List the decimal value.
-comp flags 0x00;ok
+comp flags 0x0;ok
 comp flags != 0x23;ok
 comp flags 0x33-0x45;ok
 comp flags != 0x33-0x45;ok
Signature · 1 line
1.7.10.4