Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA89DC3F2C6 for ; Tue, 3 Mar 2020 09:48:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C075120848 for ; Tue, 3 Mar 2020 09:48:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=azazel.net header.i=@azazel.net header.b="oFOqjgku" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728070AbgCCJsq (ORCPT ); Tue, 3 Mar 2020 04:48:46 -0500 Received: from kadath.azazel.net ([81.187.231.250]:40792 "EHLO kadath.azazel.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727412AbgCCJsq (ORCPT ); Tue, 3 Mar 2020 04:48:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=azazel.net; s=20190108; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject :Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=xM30wAf15CzJW7piyc9upjLZtczSsdj2dBzPuyHC6Rk=; b=oFOqjgku228Pe1Amle6Yu5icLN KKAPWpkKGchXjS8y87BYGB6EmeUikIj9xhaKrUk+tkgncoXJgOHqWtUOy4CLewlR0DUbiESgbl28M bzwSipV5MthGkTLmN8xUfkiSnD9Sq6jnAnERMdWT9QPygW25197I3IDMurxK5+801+EbsyxPc5Fne GC03kb+W1SjRI2jquM1DtW5Ee8v4Ue8EstMp/UOQYGHgjGVCefLcO/kwvIflnsNVhtqmVzOY1qKY6 XTP/6FE1QjvZPCC6i01vccM/rhWJQ5bF8Nb1U2/fLarCZQbDg5Uob6dxJ31EyPiz+GsoL3+R9T00I urdkRvdw==; Received: from [2001:8b0:fb7d:d6d7:2e4d:54ff:fe4b:a9ae] (helo=ulthar.dreamlands) by kadath.azazel.net with esmtp (Exim 4.92) (envelope-from ) id 1j94AO-00081M-NL; Tue, 03 Mar 2020 09:48:44 +0000 From: Jeremy Sowden To: Pablo Neira Ayuso , Florian Westphal Cc: Netfilter Devel Subject: [PATCH nft v3 00/18] Support for boolean binops with variable RHS operands. Date: Tue, 3 Mar 2020 09:48:26 +0000 Message-Id: <20200303094844.26694-1-jeremy@azazel.net> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:8b0:fb7d:d6d7:2e4d:54ff:fe4b:a9ae X-SA-Exim-Mail-From: jeremy@azazel.net X-SA-Exim-Scanned: No (on kadath.azazel.net); SAEximRunCond expanded to false Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org Kernel support for passing mask and xor values for bitwise boolean operations via registers allows us to support boolean binop's with variable RHS operands: XOR expressions pass the xor value in a register; AND expressions pass the mask value in a register; OR expressions pass both mask and xor values in registers. NB, OR expressions are converted to `(a & (b ^ 1)) ^ b` during linearization (in patch 9), because it makes both linearization and delinearization a lot simpler. However, it involves rearranging and allocating expressions after the evaluation phase. Since nothing else does this, AFAICS, I'm not sure whether it's the right thing to do. The patch-set comprises four parts: 1 - 7: some tidying and bug-fixes; 8 - 10: support for variable RHS operands; 11 - 15: updates to linearization and delinearization of payload expressions to work correctly with variable RHS operands; 16 - 18: some new shell and Python test-cases. Changes since v2: * patch 11 updated to stop binop length being clobbered during evaluation, instead of working around it during linearization. Changes since v1: * patch 05 updated to treat short values as constant, rather than doing nothing with them. Jeremy Sowden (18): evaluate: add separate variables for lshift and xor binops. evaluate: simplify calculation of payload size. evaluate: don't evaluate payloads twice. evaluate: convert the byte-order of payload statement arguments. evaluate: no need to swap byte-order for values of fewer than 16 bits. netlink_delinearize: set shift RHS byte-order. src: fix leaks. include: update nf_tables.h. src: support (de)linearization of bitwise op's with variable right operands. evaluate: allow boolean binop expressions with variable righthand arguments. evaluate: don't clobber binop bitmask lengths. netlink_delinearize: fix typo. netlink_delinearize: refactor stmt_payload_binop_postprocess. netlink_delinearize: add support for processing variable payload statement arguments. netlink_delinearize: add postprocessing for payload binops. tests: shell: remove stray debug flag. tests: shell: add variable binop RHS tests. tests: py: add variable binop RHS tests. include/expression.h | 1 + include/linux/netfilter/nf_tables.h | 4 + src/evaluate.c | 77 ++-- src/netlink_delinearize.c | 370 +++++++++++++----- src/netlink_linearize.c | 95 ++++- tests/py/any/ct.t | 1 + tests/py/any/ct.t.json | 37 ++ tests/py/any/ct.t.payload | 33 ++ tests/py/any/meta.t.payload | 4 - tests/py/inet/tcp.t | 2 + tests/py/inet/tcp.t.json | 46 ++- tests/py/inet/tcp.t.payload | 68 ++++ tests/py/ip/ip.t | 3 + tests/py/ip/ip.t.json | 66 ++++ tests/py/ip/ip.t.payload | 26 ++ tests/py/ip/ip.t.payload.bridge | 30 ++ tests/py/ip/ip.t.payload.inet | 30 ++ tests/py/ip/ip.t.payload.netdev | 30 ++ tests/shell/testcases/chains/0040mark_shift_0 | 2 +- tests/shell/testcases/chains/0040mark_shift_2 | 11 + .../testcases/chains/0041payload_variable_0 | 11 + .../testcases/chains/0041payload_variable_1 | 11 + .../testcases/chains/0041payload_variable_2 | 11 + .../testcases/chains/0041payload_variable_3 | 11 + .../chains/dumps/0040mark_shift_2.nft | 6 + .../chains/dumps/0041payload_variable_0.nft | 6 + .../chains/dumps/0041payload_variable_1.nft | 6 + .../chains/dumps/0041payload_variable_2.nft | 6 + .../chains/dumps/0041payload_variable_3.nft | 6 + 29 files changed, 873 insertions(+), 137 deletions(-) create mode 100755 tests/shell/testcases/chains/0040mark_shift_2 create mode 100755 tests/shell/testcases/chains/0041payload_variable_0 create mode 100755 tests/shell/testcases/chains/0041payload_variable_1 create mode 100755 tests/shell/testcases/chains/0041payload_variable_2 create mode 100755 tests/shell/testcases/chains/0041payload_variable_3 create mode 100644 tests/shell/testcases/chains/dumps/0040mark_shift_2.nft create mode 100644 tests/shell/testcases/chains/dumps/0041payload_variable_0.nft create mode 100644 tests/shell/testcases/chains/dumps/0041payload_variable_1.nft create mode 100644 tests/shell/testcases/chains/dumps/0041payload_variable_2.nft create mode 100644 tests/shell/testcases/chains/dumps/0041payload_variable_3.nft -- 2.25.1