[nft PATCH 11/15] evaluate: Fix key byteorder value in range sets/maps

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In interval sets/maps, elements are always Big Endian, set
key->byteorder accordingly. This becomes relevant when dumping set
elements for debug output.

Signed-off-by: Phil Sutter <phil@xxxxxx>
---
 src/evaluate.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/evaluate.c b/src/evaluate.c
index fbf3aa8d19139..983808d65714b 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -1617,9 +1617,12 @@ static int expr_evaluate_map(struct eval_ctx *ctx, struct expr **expr)
 	map->flags |= EXPR_F_CONSTANT;
 
 	/* Data for range lookups needs to be in big endian order */
-	if (map->mappings->set->flags & NFT_SET_INTERVAL &&
-	    byteorder_conversion(ctx, &map->map, BYTEORDER_BIG_ENDIAN) < 0)
-		return -1;
+	if (map->mappings->set->flags & NFT_SET_INTERVAL) {
+		if (byteorder_conversion(ctx, &map->map,
+					 BYTEORDER_BIG_ENDIAN) < 0)
+			return -1;
+		map->mappings->set->key->byteorder = BYTEORDER_BIG_ENDIAN;
+	}
 
 	return 0;
 }
@@ -2077,10 +2080,14 @@ static int expr_evaluate_relational(struct eval_ctx *ctx, struct expr **expr)
 				return expr_error(ctx->msgs, left,
 						  "specify either ip or ip6 for address matching");
 
+			if (!(right->set->flags & NFT_SET_INTERVAL))
+				break;
+
 			/* 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)
+			if (byteorder_conversion(ctx, &rel->left,
+						 BYTEORDER_BIG_ENDIAN) < 0)
 				return -1;
+			right->set->key->byteorder = BYTEORDER_BIG_ENDIAN;
 			break;
 		case EXPR_CONCAT:
 			return expr_binary_error(ctx->msgs, left, right,
@@ -3759,9 +3766,12 @@ static int stmt_evaluate_objref_map(struct eval_ctx *ctx, struct stmt *stmt)
 	map->flags |= EXPR_F_CONSTANT;
 
 	/* Data for range lookups needs to be in big endian order */
-	if (map->mappings->set->flags & NFT_SET_INTERVAL &&
-	    byteorder_conversion(ctx, &map->map, BYTEORDER_BIG_ENDIAN) < 0)
-		return -1;
+	if (map->mappings->set->flags & NFT_SET_INTERVAL) {
+		if (byteorder_conversion(ctx, &map->map,
+					 BYTEORDER_BIG_ENDIAN) < 0)
+			return -1;
+		map->mappings->set->key->byteorder = BYTEORDER_BIG_ENDIAN;
+	}
 
 	return 0;
 }
-- 
2.33.0




[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux