]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
netlink_delinearize: correct type and byte-order of shifts
authorJeremy Sowden <jeremy@azazel.net>
Thu, 23 Mar 2023 16:58:44 +0000 (17:58 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 28 Mar 2023 08:31:53 +0000 (10:31 +0200)
Downgrade to base type integer instead of the specific type from the
expression that is used in the shift operation.

Without this, listing a rule like:

  ct mark set ip dscp lshift 2 or 0x10

will return:

  ct mark set ip dscp << 2 | cs2

because the type of the OR's right operand will be transitively derived
from `ip dscp`.  However, this is not valid syntax:

  # nft add rule t c ct mark set ip dscp '<<' 2 '|' cs2
  Error: Could not parse integer
  add rule t c ct mark set ip dscp << 2 | cs2
                                          ^^^

Use xinteger_type to print the output in hexadecimal.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/netlink_delinearize.c

index 3d383669cb1c5c5e42e3a13649debe9742741533..fd166eb15c011caa8e77ae32eb848ecde8abd904 100644 (file)
@@ -2822,8 +2822,17 @@ static void expr_postprocess(struct rule_pp_ctx *ctx, struct expr **exprp)
                }
                expr_postprocess(ctx, &expr->right);
 
-               expr_set_type(expr, expr->left->dtype,
-                             expr->left->byteorder);
+               switch (expr->op) {
+               case OP_LSHIFT:
+               case OP_RSHIFT:
+                       expr_set_type(expr, &xinteger_type,
+                                     BYTEORDER_HOST_ENDIAN);
+                       break;
+               default:
+                       expr_set_type(expr, expr->left->dtype,
+                                     expr->left->byteorder);
+               }
+
                break;
        case EXPR_RELATIONAL:
                switch (expr->left->etype) {