[RFC] netlink: do not alter set element width

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxx>
---
 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




[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux