]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
datatype: take endianess into account in symbolic_constant_print()
authorPatrick McHardy <kaber@trash.net>
Mon, 18 Aug 2014 23:21:59 +0000 (00:21 +0100)
committerPatrick McHardy <kaber@trash.net>
Mon, 18 Aug 2014 23:21:59 +0000 (00:21 +0100)
symbolic_constant_print() uses mpz_cmp_ui() to find the matching symbol.
Since GMP internally treats all values as being in host byte, this
doesn't work when the constant value is non-host byteorder, such as
the ethernet protocol type.

Export the expression's value in its original byteorder for comparison
to fix this.

Signed-off-by: Patrick McHardy <kaber@trash.net>
src/datatype.c

index 55af2278b3edaf192387d7b817418eedb559dc92..36d59859e2ef33e18f09fb4b4a4d6dfc94e2805e 100644 (file)
@@ -132,9 +132,15 @@ void symbolic_constant_print(const struct symbol_table *tbl,
                             const struct expr *expr)
 {
        const struct symbolic_constant *s;
+       uint64_t val = 0;
+
+       /* Export the data in the correct byteorder for comparison */
+       assert(expr->len / BITS_PER_BYTE <= sizeof(val));
+       mpz_export_data(&val, expr->value, expr->byteorder,
+                       expr->len / BITS_PER_BYTE);
 
        for (s = tbl->symbols; s->identifier != NULL; s++) {
-               if (!mpz_cmp_ui(expr->value, s->value))
+               if (val == s->value)
                        break;
        }