Netfilter-Devel Archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH nft] netlink_delinearize: unused code in reverse cross-day meta hour range
Date: Mon,  1 Apr 2024 13:00:22 +0200	[thread overview]
Message-ID: <20240401110022.167239-1-pablo@netfilter.org> (raw)

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")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 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

diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c
index 5a4cf1b88110..24dfb3116eab 100644
--- a/src/netlink_delinearize.c
+++ b/src/netlink_delinearize.c
@@ -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 */
diff --git a/tests/shell/testcases/listing/dumps/meta_time.nft b/tests/shell/testcases/listing/dumps/meta_time.nft
deleted file mode 100644
index 9121aef59169..000000000000
--- a/tests/shell/testcases/listing/dumps/meta_time.nft
+++ /dev/null
@@ -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"
-	}
-}
diff --git a/tests/shell/testcases/listing/dumps/meta_time.nodump b/tests/shell/testcases/listing/dumps/meta_time.nodump
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/tests/shell/testcases/listing/meta_time b/tests/shell/testcases/listing/meta_time
index 39fa43874ea9..96a9d5570fd1 100755
--- a/tests/shell/testcases/listing/meta_time
+++ b/tests/shell/testcases/listing/meta_time
@@ -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
-- 
2.30.2


                 reply	other threads:[~2024-04-01 11:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240401110022.167239-1-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).