Skip to contentSkip to conversation

segtree: zap element statement when decomposing interval

PATCH New Pablo Neira Ayuso 1 participant 1 message Jul 6, 2020 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 segtree: zap element statement when decomposing interval

Otherwise, interval sets do not display element statement such as counters.

Fixes 6d80e0f15492 ("src: support for counter in set definition")
---
 src/segtree.c                                 | 16 ++++++++++++++++
 .../testcases/sets/0051set_interval_counter_0 | 19 +++++++++++++++++++
 .../sets/dumps/0051set_interval_counter_0.nft | 13 +++++++++++++
 3 files changed, 48 insertions(+)
 create mode 100755 tests/shell/testcases/sets/0051set_interval_counter_0
 create mode 100644 tests/shell/testcases/sets/dumps/0051set_interval_counter_0.nft
src/segtree.c +16 -0
index b6ca6083ea0b..c143a6a74a21 100644
@@ -1027,6 +1027,10 @@ void interval_map_decompose(struct expr *set)
 					tmp->timeout = low->left->timeout;
 				if (low->left->expiration)
 					tmp->expiration = low->left->expiration;
+				if (low->left->stmt) {
+					tmp->stmt = low->left->stmt;
+					low->left->stmt = NULL;
+				}
 
 				tmp = mapping_expr_alloc(&tmp->location, tmp,
 							 expr_clone(low->right));
@@ -1037,6 +1041,10 @@ void interval_map_decompose(struct expr *set)
 					tmp->timeout = low->timeout;
 				if (low->expiration)
 					tmp->expiration = low->expiration;
+				if (low->left->stmt) {
+					tmp->stmt = low->stmt;
+					low->stmt = NULL;
+				}
 			}
 
 			compound_expr_add(set, tmp);
@@ -1059,6 +1067,10 @@ void interval_map_decompose(struct expr *set)
 					prefix->timeout = low->left->timeout;
 				if (low->left->expiration)
 					prefix->expiration = low->left->expiration;
+				if (low->left->stmt) {
+					prefix->stmt = low->left->stmt;
+					low->left->stmt = NULL;
+				}
 
 				prefix = mapping_expr_alloc(&low->location, prefix,
 							    expr_clone(low->right));
@@ -1069,6 +1081,10 @@ void interval_map_decompose(struct expr *set)
 					prefix->timeout = low->timeout;
 				if (low->expiration)
 					prefix->expiration = low->expiration;
+				if (low->stmt) {
+					prefix->stmt = low->stmt;
+					low->stmt = NULL;
+				}
 			}
 
 			compound_expr_add(set, prefix);
tests/shell/testcases/sets/0051set_interval_counter_0 new file +19 -0
new file mode 100755
index 000000000000..ea90e264bfcc
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+set -e
+
+EXPECTED="table ip x {
+	set s {
+		type ipv4_addr
+		flags interval
+		counter
+		elements = { 192.168.2.0/24 }
+	}
+
+	chain y {
+		type filter hook output priority filter; policy accept;
+		ip daddr @s
+	}
+}"
+
+$NFT -f - <<< "$EXPECTED"
tests/shell/testcases/sets/dumps/0051set_interval_counter_0.nft new file +13 -0
new file mode 100644
index 000000000000..fd488a76432f
@@ -0,0 +1,13 @@
+table ip x {
+	set s {
+		type ipv4_addr
+		flags interval
+		counter
+		elements = { 192.168.2.0/24 counter packets 0 bytes 0 }
+	}
+
+	chain y {
+		type filter hook output priority filter; policy accept;
+		ip daddr @s
+	}
+}
Signature · 1 line
2.20.1