]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
testsuite: Add a first ss test validating ssfilter
authorPhil Sutter <phil@nwl.cc>
Tue, 14 Aug 2018 12:18:08 +0000 (14:18 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Wed, 15 Aug 2018 21:25:18 +0000 (14:25 -0700)
This tests a few ssfilter expressions by selecting sockets from a TCP
dump file. The dump was created using the following command:

| ss -ntaD testsuite/tests/ss/ss1.dump

It is fed into ss via TCPDIAG_FILE environment variable.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
testsuite/tests/ss/ss1.dump [new file with mode: 0644]
testsuite/tests/ss/ssfilter.t [new file with mode: 0755]

diff --git a/testsuite/tests/ss/ss1.dump b/testsuite/tests/ss/ss1.dump
new file mode 100644 (file)
index 0000000..9c27323
Binary files /dev/null and b/testsuite/tests/ss/ss1.dump differ
diff --git a/testsuite/tests/ss/ssfilter.t b/testsuite/tests/ss/ssfilter.t
new file mode 100755 (executable)
index 0000000..e74f176
--- /dev/null
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+. lib/generic.sh
+
+# % ./misc/ss -Htna
+# LISTEN  0    128    0.0.0.0:22       0.0.0.0:*
+# ESTAB   0    0     10.0.0.1:22      10.0.0.1:36266
+# ESTAB   0    0     10.0.0.1:36266   10.0.0.1:22
+# ESTAB   0    0     10.0.0.1:22      10.0.0.2:50312
+export TCPDIAG_FILE="$(dirname $0)/ss1.dump"
+
+ts_log "[Testing ssfilter]"
+
+ts_ss "$0" "Match dport = 22" -Htna dport = 22
+test_on "ESTAB    0           0                 10.0.0.1:36266           10.0.0.1:22"
+
+ts_ss "$0" "Match dport 22" -Htna dport 22
+test_on "ESTAB    0           0                 10.0.0.1:36266           10.0.0.1:22"
+
+ts_ss "$0" "Match (dport)" -Htna '( dport = 22 )'
+test_on "ESTAB    0           0                 10.0.0.1:36266           10.0.0.1:22"
+
+ts_ss "$0" "Match src = 0.0.0.0" -Htna src = 0.0.0.0
+test_on "LISTEN     0           128                0.0.0.0:22             0.0.0.0:*"
+
+ts_ss "$0" "Match src 0.0.0.0" -Htna src 0.0.0.0
+test_on "LISTEN     0           128                0.0.0.0:22             0.0.0.0:*"
+
+ts_ss "$0" "Match src sport" -Htna src 0.0.0.0 sport = 22
+test_on "LISTEN     0           128                0.0.0.0:22             0.0.0.0:*"
+
+ts_ss "$0" "Match src and sport" -Htna src 0.0.0.0 and sport = 22
+test_on "LISTEN     0           128                0.0.0.0:22             0.0.0.0:*"
+
+ts_ss "$0" "Match src and sport and dport" -Htna src 10.0.0.1 and sport = 22 and dport = 50312
+test_on "ESTAB    0           0                 10.0.0.1:22           10.0.0.2:50312"
+
+ts_ss "$0" "Match src and sport and (dport)" -Htna 'src 10.0.0.1 and sport = 22 and ( dport = 50312 )'
+test_on "ESTAB    0           0                 10.0.0.1:22           10.0.0.2:50312"
+
+ts_ss "$0" "Match src and (sport and dport)" -Htna 'src 10.0.0.1 and ( sport = 22 and dport = 50312 )'
+test_on "ESTAB    0           0                 10.0.0.1:22           10.0.0.2:50312"
+
+ts_ss "$0" "Match (src and sport) and dport" -Htna '( src 10.0.0.1 and sport = 22 ) and dport = 50312'
+test_on "ESTAB    0           0                 10.0.0.1:22           10.0.0.2:50312"
+
+ts_ss "$0" "Match (src or src) and dst" -Htna '( src 0.0.0.0 or src 10.0.0.1 ) and dst 10.0.0.2'
+test_on "ESTAB    0           0                 10.0.0.1:22           10.0.0.2:50312"