Re: [PATCH nf] nft_set_rbtree: Don't account for expired elements on insertion

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

 



Signed-off-by: Stefano Brivio<sbrivio@xxxxxxxxxx>
---
  .../testcases/sets/0044interval_overlap_0     | 81 ++++++++++++++-----
  1 file changed, 61 insertions(+), 20 deletions(-)

diff --git a/tests/shell/testcases/sets/0044interval_overlap_0 b/tests/shell/testcases/sets/0044interval_overlap_0
index fad92ddcf356..16f661a00116 100755
--- a/tests/shell/testcases/sets/0044interval_overlap_0
+++ b/tests/shell/testcases/sets/0044interval_overlap_0
@@ -7,6 +7,13 @@
  #   existing one
  # - for concatenated ranges, the new element is less specific than any existing
  #   overlapping element, as elements are evaluated in order of insertion
+#
+# Then, repeat the test with a set configured for 1s timeout, checking that:
+# - we can insert all the elements as described above
+# - once the timeout has expired, we can insert all the elements again, and old
+#   elements are not present
+# - before the timeout expires again, we can re-add elements that are not
+#   expected to fail, but old elements might be present
# Accept Interval List
  intervals_simple="
@@ -39,28 +46,62 @@ intervals_concat="
  	y	15-20 . 49-61	0-2 . 0-3, 10-20 . 30-40, 15-20 . 50-60, 3-9 . 4-29, 15-20 . 49-61
  "
-$NFT add table t
-$NFT add set t s '{ type inet_service ; flags interval ; }'
-$NFT add set t c '{ type inet_service . inet_service ; flags interval ; }'
+match_elements() {
+	skip=0
+	n=0
+	out=
+	for a in $($NFT list set t ${1})}; do
+		[ ${n} -eq 0 ] && [ "${a}" = "elements" ] && n=1
+		[ ${n} -eq 1 ] && [ "${a}" = "=" ]	  && n=2
+		[ ${n} -eq 2 ] && [ "${a}" = "{" ]	  && n=3 && continue
+		[ ${n} -lt 3 ] 					 && continue
+
+		[ "${a}" = "}" ]				 && break
+
+		[ ${skip} -eq 1 ] && skip=0 && out="${out},"	 && continue
+		[ "${a}" = "expires" ] && skip=1		 && continue
+
+		[ -n "${out}" ] && out="${out} ${a}" || out="${a}"
+	done
+	[ "${out%,}" = "${2}" ]
+}
-IFS='
+add_elements() {
+	set="s"
+	IFS='	
  '
-set="s"
-for t in ${intervals_simple} switch ${intervals_concat}; do
-	[ "${t}" = "switch" ] && set="c"         && continue
-	[ -z "${pass}" ]      && pass="${t}"     && continue
-	[ -z "${interval}" ]  && interval="${t}" && continue
+	for t in ${intervals_simple} switch ${intervals_concat}; do
+		unset IFS
+		[ "${t}" = "switch" ] && set="c"         && continue
+		[ -z "${pass}" ]      && pass="${t}"     && continue
+		[ -z "${interval}" ]  && interval="${t}" && continue
- if [ "${pass}" = "y" ]; then
-		$NFT add element t ${set} "{ ${interval} }"
-	else
-		! $NFT add element t ${set} "{ ${interval} }" 2>/dev/null
-	fi
-	$NFT list set t ${set} | tr -d '\n\t' | tr -s ' ' | \
-		grep -q "elements = { ${t} }"
+		if [ "${pass}" = "y" ]; then
+			$NFT add element t ${set} "{ ${interval} }"
+		else
+			! $NFT add element t ${set} "{ ${interval} }" 2>/dev/null
+		fi
- pass=
-	interval=
-done
+		[ "${1}" != "nomatch" ] && match_elements "${set}" "${t}"
-unset IFS
+		pass=
+		interval=
+		IFS='	
+'
+	done
+	unset IFS
+}
+
+$NFT add table t
+$NFT add set t s '{ type inet_service ; flags interval ; }'
+$NFT add set t c '{ type inet_service . inet_service ; flags interval ; }'
+add_elements
+
+$NFT flush ruleset
+$NFT add table t
+$NFT add set t s '{ type inet_service ; flags interval,timeout; timeout 1s; gc-interval 1s; }'
+$NFT add set t c '{ type inet_service . inet_service ; flags interval,timeout ; timeout 1s; gc-interval 1s; }'
+add_elements
+sleep 1
+add_elements
+add_elements nomatch

Hello All,

Is there any way I can track this change so I know what kernel version to expect it in?  Pardon my ignorance, but I'm new to Linux kernel changes.  I have familiarity with change requests, so if I can follow this on GitHub or some other tracking system, that would be great.

Thanks!
-MikeD



[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux