]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
evaluate: make byteorder conversion on string base type a no-op
authorFlorian Westphal <fw@strlen.de>
Sat, 9 Apr 2022 13:58:24 +0000 (15:58 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 13 Apr 2022 11:43:22 +0000 (13:43 +0200)
Prerequisite for support of interface names in interval sets:
 table inet filter {
set s {
type ifname
flags interval
elements = { "foo" }
}
chain input {
type filter hook input priority filter; policy accept;
iifname @s counter
}
 }

Will yield: "Byteorder mismatch: meta expected big endian, got host endian".
This is because of:

 /* Data for range lookups needs to be in big endian order */
 if (right->set->flags & NFT_SET_INTERVAL &&
   byteorder_conversion(ctx, &rel->left, BYTEORDER_BIG_ENDIAN) < 0)

It doesn't make sense to me to add checks to all callers of
byteorder_conversion(), so treat this similar to EXPR_CONCAT and turn
TYPE_STRING byteorder change into a no-op.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/evaluate.c

index 6b3b63662411065ddebdd3e900a2f4ab7b01154f..d5ae071add1f8ceefcfd57def205807476ccb1b3 100644 (file)
@@ -138,6 +138,7 @@ static enum ops byteorder_conversion_op(struct expr *expr,
 static int byteorder_conversion(struct eval_ctx *ctx, struct expr **expr,
                                enum byteorder byteorder)
 {
+       enum datatypes basetype;
        enum ops op;
 
        assert(!expr_is_constant(*expr) || expr_is_singleton(*expr));
@@ -149,11 +150,19 @@ static int byteorder_conversion(struct eval_ctx *ctx, struct expr **expr,
        if ((*expr)->etype == EXPR_CONCAT)
                return 0;
 
-       if (expr_basetype(*expr)->type != TYPE_INTEGER)
+       basetype = expr_basetype(*expr)->type;
+       switch (basetype) {
+       case TYPE_INTEGER:
+               break;
+       case TYPE_STRING:
+               return 0;
+       default:
                return expr_error(ctx->msgs, *expr,
-                                 "Byteorder mismatch: expected %s, got %s",
+                                 "Byteorder mismatch: %s expected %s, %s got %s",
                                  byteorder_names[byteorder],
+                                 expr_name(*expr),
                                  byteorder_names[(*expr)->byteorder]);
+       }
 
        if (expr_is_constant(*expr) || (*expr)->len / BITS_PER_BYTE < 2)
                (*expr)->byteorder = byteorder;