Blame SOURCES/0004-tests-shell-Check-overhead-in-iptables-save-and-rest.patch

a1bd1a
From e7a2e0f70ed69c7b1ed1b4e6474ccf0924f81b23 Mon Sep 17 00:00:00 2001
a1bd1a
From: Phil Sutter <phil@nwl.cc>
a1bd1a
Date: Thu, 2 Jun 2022 13:44:45 +0200
a1bd1a
Subject: [PATCH] tests: shell: Check overhead in iptables-save and -restore
a1bd1a
a1bd1a
Some repeated calls have been reduced recently, assert this in a test
a1bd1a
evaluating strace output.
a1bd1a
a1bd1a
Signed-off-by: Phil Sutter <phil@nwl.cc>
a1bd1a
(cherry picked from commit 0416ae5dea134b33e22c97e68b64010d679debe1)
a1bd1a
---
a1bd1a
 .../shell/testcases/ipt-save/0007-overhead_0  | 37 +++++++++++++++++++
a1bd1a
 1 file changed, 37 insertions(+)
a1bd1a
 create mode 100755 iptables/tests/shell/testcases/ipt-save/0007-overhead_0
a1bd1a
a1bd1a
diff --git a/iptables/tests/shell/testcases/ipt-save/0007-overhead_0 b/iptables/tests/shell/testcases/ipt-save/0007-overhead_0
a1bd1a
new file mode 100755
a1bd1a
index 0000000000000..b86d71f209471
a1bd1a
--- /dev/null
a1bd1a
+++ b/iptables/tests/shell/testcases/ipt-save/0007-overhead_0
a1bd1a
@@ -0,0 +1,37 @@
a1bd1a
+#!/bin/bash
a1bd1a
+
a1bd1a
+# Test recent performance improvements in iptables-save due to reduced
a1bd1a
+# overhead.
a1bd1a
+
a1bd1a
+strace --version >/dev/null || { echo "skip for missing strace"; exit 0; }
a1bd1a
+
a1bd1a
+RULESET=$(
a1bd1a
+	echo "*filter"
a1bd1a
+	for ((i = 0; i < 100; i++)); do
a1bd1a
+		echo ":mychain$i -"
a1bd1a
+		echo "-A FORWARD -p tcp --dport 22 -j mychain$i"
a1bd1a
+	done
a1bd1a
+	echo "COMMIT"
a1bd1a
+)
a1bd1a
+
a1bd1a
+RESTORE_STRACE=$(strace $XT_MULTI iptables-restore <<< "$RULESET" 2>&1 >/dev/null)
a1bd1a
+SAVE_STRACE=$(strace $XT_MULTI iptables-save 2>&1 >/dev/null)
a1bd1a
+
a1bd1a
+do_grep() { # (name, threshold, pattern)
a1bd1a
+	local cnt=$(grep -c "$3")
a1bd1a
+	[[ $cnt -le $2 ]] && return 0
a1bd1a
+	echo "ERROR: Too many $3 lookups for $1: $cnt > $2"
a1bd1a
+	exit 1
a1bd1a
+}
a1bd1a
+
a1bd1a
+# iptables prefers hard-coded protocol names instead of looking them up first
a1bd1a
+
a1bd1a
+do_grep "$XT_MULTI iptables-restore" 0 /etc/protocols <<< "$RESTORE_STRACE"
a1bd1a
+do_grep "$XT_MULTI iptables-save" 0 /etc/protocols <<< "$SAVE_STRACE"
a1bd1a
+
a1bd1a
+# iptables-nft-save pointlessly checked whether chain jumps are targets
a1bd1a
+
a1bd1a
+do_grep "$XT_MULTI iptables-restore" 10 libxt_ <<< "$RESTORE_STRACE"
a1bd1a
+do_grep "$XT_MULTI iptables-save" 10 libxt_ <<< "$SAVE_STRACE"
a1bd1a
+
a1bd1a
+exit 0
a1bd1a
-- 
a1bd1a
2.34.1
a1bd1a