From patchwork Mon Apr 1 11:00:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pablo Neira Ayuso X-Patchwork-Id: 1918444 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.48.161; helo=sy.mirrors.kernel.org; envelope-from=netfilter-devel+bounces-1570-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [147.75.48.161]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V7SjW2N4sz1yYM for ; Mon, 1 Apr 2024 22:00:47 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 70C2FB21368 for ; Mon, 1 Apr 2024 11:00:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2833F1CD22; Mon, 1 Apr 2024 11:00:42 +0000 (UTC) X-Original-To: netfilter-devel@vger.kernel.org Received: from mail.netfilter.org (mail.netfilter.org [217.70.188.207]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6B6DC2030A for ; Mon, 1 Apr 2024 11:00:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.188.207 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711969241; cv=none; b=jZJnIdLEoC4LuMc0M9+Or/EwETOEmMBZ0k8RxTsjqQb3fvPX/Jrx6O8RZ9WvXX4ELXHwDBvqq4bMHFiKazXDaNk6WvC+NuevqIz199hqpoOnsaptIoaTibgPug37sRBHwU8E7gmmePaTtEYNinwJEdfzk0TJ/DUbM4Ec+vEhYw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711969241; c=relaxed/simple; bh=77xgveLj/gY1UyFx5RypOfNlCHQ/czHhbCmnSisJz4Y=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=kfF5kUk/e4kbP0Xy2RJrYGuGKsNPU8BJBTXA0OSrgT1U7xantohWMcvoKm3xphKcyEvLICXn36mJDtNGSwalW9wsof+1Pxm9pEYqO8LjARak9OrF2BXQILOlpHB7m3iPEbBAOxKsMwfdxgiP3gAvfNZK/4k/q2+Cryw9bYwJeAc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=netfilter.org; spf=pass smtp.mailfrom=netfilter.org; arc=none smtp.client-ip=217.70.188.207 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=netfilter.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=netfilter.org From: Pablo Neira Ayuso 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 Message-Id: <20240401110022.167239-1-pablo@netfilter.org> X-Mailer: git-send-email 2.30.2 Precedence: bulk X-Mailing-List: netfilter-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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