Skip to contentSkip to conversation

netlink_delinearize: unused code in reverse cross-day meta hour range

PATCH New Pablo Neira Ayuso 1 participant 1 message Apr 1, 2024 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 netlink_delinearize: unused code in reverse cross-day meta hour range

f8f32deda31d ("meta: Introduce new conditions 'time', 'day' and 'hour'") reverses a cross-day range expressed as "22:00"-"02:00" UTC time into != "02:00"-"22:00" so meta hour ranges works.

Listing is however confusing, hence, 44d144cd593e ("netlink_delinearize:
reverse cross-day meta hour range") introduces code to reverse a cross-day.

However, it also adds code to reverse a range in == to-from form (assuming OP_IMPLICIT) which is never exercised from the listing path because the range expression is not currently used, instead two instructions (cmp gte and cmp lte) are used to represent the range. Remove this branch otherwise a reversed notation will be used to display meta hour ranges once the range instruction is to represent this.

While at it, unreliable test dump:

tests/shell/testcases/listing/dumps/meta_time.nft

and move the cross-day check to the test script.

Fixes 44d144cd593e ("netlink_delinearize: reverse cross-day meta hour range")
---
 src/netlink_delinearize.c                     | 12 +++----
 .../testcases/listing/dumps/meta_time.nft     | 32 -------------------
 .../testcases/listing/dumps/meta_time.nodump  |  0
 tests/shell/testcases/listing/meta_time       |  8 +++++
 4 files changed, 12 insertions(+), 40 deletions(-)
 delete mode 100644 tests/shell/testcases/listing/dumps/meta_time.nft
 create mode 100644 tests/shell/testcases/listing/dumps/meta_time.nodump
src/netlink_delinearize.c +4 -8
index 5a4cf1b88110..24dfb3116eab 100644
@@ -2858,14 +2858,10 @@ static void expr_postprocess(struct rule_pp_ctx *ctx, struct expr **exprp)
 				 * is a cross-day range.
 				 */
 				if (mpz_cmp(range->left->value,
-					    range->right->value) <= 0) {
-					if (expr->op == OP_NEQ) {
-		                                range_expr_swap_values(range);
-		                                expr->op = OP_IMPLICIT;
-					} else if (expr->op == OP_IMPLICIT) {
-		                                range_expr_swap_values(range);
-					        expr->op = OP_NEG;
-					}
+					    range->right->value) <= 0 &&
+				    expr->op == OP_NEQ) {
+					range_expr_swap_values(range);
+					expr->op = OP_IMPLICIT;
 				}
 			}
 			/* fallthrough */
tests/shell/testcases/listing/dumps/meta_time.nft deleted +0 -32
deleted file mode 100644
index 9121aef59169..000000000000
@@ -1,32 +0,0 @@
-table ip t {
-	chain c {
-		meta hour "01:00"-"01:59"
-		meta hour "02:00"-"02:59"
-		meta hour "03:00"-"03:59"
-		meta hour "04:00"-"04:59"
-		meta hour "05:00"-"05:59"
-		meta hour "06:00"-"06:59"
-		meta hour "07:00"-"07:59"
-		meta hour "08:00"-"08:59"
-		meta hour "09:00"-"09:59"
-		meta hour "10:00"-"10:59"
-		meta hour "11:00"-"11:59"
-		meta hour "12:00"-"12:59"
-		meta hour "13:00"-"13:59"
-		meta hour "14:00"-"14:59"
-		meta hour "15:00"-"15:59"
-		meta hour "16:00"-"16:59"
-		meta hour "17:00"-"17:59"
-		meta hour "18:00"-"18:59"
-		meta hour "19:00"-"19:59"
-		meta hour "20:00"-"20:59"
-		meta hour "21:00"-"21:59"
-		meta hour "22:00"-"22:59"
-		meta hour "23:00"-"23:59"
-		meta hour "00:00"-"00:59"
-		meta hour "04:00"-"15:00"
-		meta hour "05:00"-"16:00"
-		meta hour "06:00"-"17:00"
-		meta hour "07:00"-"18:00"
-	}
-}
tests/shell/testcases/listing/dumps/meta_time.nodump new file +0 -0
new file mode 100644
index 000000000000..e69de29bb2d1
tests/shell/testcases/listing/meta_time +8 -0
index 39fa43874ea9..96a9d5570fd1 100755
@@ -53,7 +53,15 @@ printf "\t\tmeta hour \"%02d:%02d\"-\"%02d:%02d\"\n" 0 0 0 59 >> "$TMP1"
 
 check_decode UTC-1
 
+$NFT flush chain t c
 TZ=EADT $NFT add rule t c meta hour "03:00"-"14:00"
 TZ=EADT $NFT add rule t c meta hour "04:00"-"15:00"
 TZ=EADT $NFT add rule t c meta hour "05:00"-"16:00"
 TZ=EADT $NFT add rule t c meta hour "06:00"-"17:00"
+
+printf "\t\tmeta hour \"%02d:%02d\"-\"%02d:%02d\"\n" 3 0 14 0 > "$TMP1"
+printf "\t\tmeta hour \"%02d:%02d\"-\"%02d:%02d\"\n" 4 0 15 0 >> "$TMP1"
+printf "\t\tmeta hour \"%02d:%02d\"-\"%02d:%02d\"\n" 5 0 16 0 >> "$TMP1"
+printf "\t\tmeta hour \"%02d:%02d\"-\"%02d:%02d\"\n" 6 0 17 0 >> "$TMP1"
+
+check_decode EADT
Signature · 1 line
2.30.2