aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeonid Evdokimov <leon@darkk.net.ru>2025-01-02 09:30:06 +0000
committerKristof Provost <kp@FreeBSD.org>2025-01-02 12:34:50 +0000
commit0749d8134300b8e3c956e161890ab496247d2542 (patch)
tree566b44e8b84fbd7b751549b376f4f94c684ec4f5
parentb2d2a78ad80ec68d4a17f5aef97d21686cb1e29b (diff)
pf tests: check cleared time when zeroing stats for table addresses
Verify that we reset the cleared time when we zero an address' counters in a table. PR: 282877, 282984 Reviewed by: kp MFC after: 2 weeks Signed-off-by: Leonid Evdokimov <leon@darkk.net.ru> Differential Revision: https://reviews.freebsd.org/D48242
-rw-r--r--tests/sys/netpfil/pf/table.sh33
1 files changed, 31 insertions, 2 deletions
diff --git a/tests/sys/netpfil/pf/table.sh b/tests/sys/netpfil/pf/table.sh
index 62c9d66d80ce..f655463f3c03 100644
--- a/tests/sys/netpfil/pf/table.sh
+++ b/tests/sys/netpfil/pf/table.sh
@@ -116,6 +116,20 @@ zero_one_head()
atf_set require.user root
}
+pft_cleared_ctime()
+{
+ jexec "$1" pfctl -t "$2" -vvT show | awk -v ip="$3" '
+ ($1 == ip) { m = 1 }
+ ($1 == "Cleared:" && m) {
+ sub("[[:space:]]*Cleared:[[:space:]]*", ""); print; exit }'
+}
+
+ctime_to_unixtime()
+{
+ # NB: it's not TZ=UTC, it's TZ=/etc/localtime
+ date -jf '%a %b %d %H:%M:%S %Y' "$1" '+%s'
+}
+
zero_one_body()
{
epair_send=$(vnet_mkepair)
@@ -145,16 +159,31 @@ zero_one_body()
-o match:'Out/Pass:.*'"$TABLE_STATS_NONZERO_REGEXP" \
jexec alcatraz pfctl -t foo -T show -vv
+ local uniq base ts1 ts3
+ uniq=`jexec alcatraz pfctl -t foo -vvT show | sort -u | grep -c Cleared`
+ atf_check_equal 1 "$uniq" # time they were added
+
+ base=`pft_cleared_ctime alcatraz foo 192.0.2.1`
+
atf_check -s exit:0 -e ignore \
jexec alcatraz pfctl -t foo -T zero 192.0.2.3
+ ts1=`pft_cleared_ctime alcatraz foo 192.0.2.1`
+ atf_check_equal "$base" "$ts1"
+
+ ts3=`pft_cleared_ctime alcatraz foo 192.0.2.3`
+ atf_check test "$ts1" != "$ts3"
+
+ ts1=`ctime_to_unixtime "$ts1"`
+ ts3=`ctime_to_unixtime "$ts3"`
+ atf_check test $(( "$ts3" - "$ts1" )) -lt 10 # (3 pings * 2) + epsilon
+ atf_check test "$ts1" -lt "$ts3"
+
# We now have a zeroed and a non-zeroed counter, so both patterns
# should match
atf_check -s exit:0 -e ignore \
-o match:'In/Pass:.*'"$TABLE_STATS_NONZERO_REGEXP" \
-o match:'Out/Pass:.*'"$TABLE_STATS_NONZERO_REGEXP" \
- jexec alcatraz pfctl -t foo -T show -vv
- atf_check -s exit:0 -e ignore \
-o match:'In/Pass:.*'"$TABLE_STATS_ZERO_REGEXP" \
-o match:'Out/Pass:.*'"$TABLE_STATS_ZERO_REGEXP" \
jexec alcatraz pfctl -t foo -T show -vv