summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2021-11-02 14:07:04 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2021-11-03 12:48:19 +0100
commit6ad2058da66affc105d325e45ff82fd5b5cac41e (patch)
tree75818a002b868664c01ebaf39ae4a3370643c727 /src
parent8f3048954d40da8240cf5ff07b84d5c2e66f9066 (diff)
datatype: add xinteger_type alias to print in hexadecimal
Add an alias of the integer type to print raw payload expressions in hexadecimal. Update tests/py. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src')
-rw-r--r--src/datatype.c16
-rw-r--r--src/payload.c2
2 files changed, 17 insertions, 1 deletions
diff --git a/src/datatype.c b/src/datatype.c
index b849f708..a06c3996 100644
--- a/src/datatype.c
+++ b/src/datatype.c
@@ -410,6 +410,22 @@ const struct datatype integer_type = {
.parse = integer_type_parse,
};
+static void xinteger_type_print(const struct expr *expr, struct output_ctx *octx)
+{
+ nft_gmp_print(octx, "0x%Zx", expr->value);
+}
+
+/* Alias of integer_type to print raw payload expressions in hexadecimal. */
+const struct datatype xinteger_type = {
+ .type = TYPE_INTEGER,
+ .name = "integer",
+ .desc = "integer",
+ .basetype = &integer_type,
+ .print = xinteger_type_print,
+ .json = integer_type_json,
+ .parse = integer_type_parse,
+};
+
static void string_type_print(const struct expr *expr, struct output_ctx *octx)
{
unsigned int len = div_round_up(expr->len, BITS_PER_BYTE);
diff --git a/src/payload.c b/src/payload.c
index c662900b..d9e0d425 100644
--- a/src/payload.c
+++ b/src/payload.c
@@ -269,7 +269,7 @@ void payload_init_raw(struct expr *expr, enum proto_bases base,
expr->payload.base = base;
expr->payload.offset = offset;
expr->len = len;
- expr->dtype = &integer_type;
+ expr->dtype = &xinteger_type;
if (base != PROTO_BASE_TRANSPORT_HDR)
return;