netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Braun <michael-dev@fami-braun.de>
To: netfilter-devel@vger.kernel.org
Cc: Michael Braun <michael-dev@fami-braun.de>
Subject: [RFC] netlink: do not alter set element width
Date: Tue,  5 May 2020 11:41:19 +0200	[thread overview]
Message-ID: <20200505094119.26407-1-michael-dev@fami-braun.de> (raw)

Consider the following rulset

table bridge t {
        set nodhcpvlan {
                typeof vlan id
                elements = { 1 }
        }

        chain c1 {
                vlan id != @nodhcpvlan vlan type arp counter packets 0 bytes 0 jump c2
                vlan id != @nodhcpvlan vlan type ip counter packets 0 bytes 0 jump c2
        }

        chain c2 {
        }
}

This results for nft list ruleset in
  nft: netlink_delinearize.c:1945: binop_adjust_one: Assertion `value->len >= binop->right->len' failed.

This is due to binop_adjust_one setting value->len to left->len, which
is shorther than right->len.

Additionally, it does not seem correct to alter set elements from parsing a rule,
so remove that part all together.

Signed-off-by: Michael Braun <michael-dev@fami-braun.de>
---
 src/netlink_delinearize.c                | 18 ------------------
 tests/shell/testcases/sets/typeof_sets_1 | 22 ++++++++++++++++++++++
 2 files changed, 22 insertions(+), 18 deletions(-)
 create mode 100755 tests/shell/testcases/sets/typeof_sets_1

diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c
index f721d15c..877c0d44 100644
--- a/src/netlink_delinearize.c
+++ b/src/netlink_delinearize.c
@@ -1959,29 +1959,11 @@ static void binop_adjust_one(const struct expr *binop, struct expr *value,
 static void __binop_adjust(const struct expr *binop, struct expr *right,
 			   unsigned int shift)
 {
-	struct expr *i;
-
 	switch (right->etype) {
 	case EXPR_VALUE:
 		binop_adjust_one(binop, right, shift);
 		break;
 	case EXPR_SET_REF:
-		list_for_each_entry(i, &right->set->init->expressions, list) {
-			switch (i->key->etype) {
-			case EXPR_VALUE:
-				binop_adjust_one(binop, i->key, shift);
-				break;
-			case EXPR_RANGE:
-				binop_adjust_one(binop, i->key->left, shift);
-				binop_adjust_one(binop, i->key->right, shift);
-				break;
-			case EXPR_SET_ELEM:
-				__binop_adjust(binop, i->key->key, shift);
-				break;
-			default:
-				BUG("unknown expression type %s\n", expr_name(i->key));
-			}
-		}
 		break;
 	case EXPR_RANGE:
 		binop_adjust_one(binop, right->left, shift);
diff --git a/tests/shell/testcases/sets/typeof_sets_1 b/tests/shell/testcases/sets/typeof_sets_1
new file mode 100755
index 00000000..359ae109
--- /dev/null
+++ b/tests/shell/testcases/sets/typeof_sets_1
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+# regression test for corner case in netlink_delinearize
+
+EXPECTED="table bridge t {
+        set nodhcpvlan {
+                typeof vlan id
+                elements = { 1 }
+        }
+
+        chain c1 {
+                vlan id != @nodhcpvlan vlan type arp counter packets 0 bytes 0 jump c2
+                vlan id != @nodhcpvlan vlan type ip counter packets 0 bytes 0 jump c2
+        }
+
+        chain c2 {
+        }
+}"
+
+set -e
+$NFT -f - <<< $EXPECTED
+
-- 
2.20.1


                 reply	other threads:[~2020-05-05  9:41 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=20200505094119.26407-1-michael-dev@fami-braun.de \
    --to=michael-dev@fami-braun.de \
    --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 NNTP newsgroup(s).