Linux netfilter at some point inverted the meaning of the '--ctdir reply'
and newer netfilter implementations now expect '--ctdir original'
instead and vice-versa.
We probe for this netfilter change via an IMCP message over loopback and 3
filtering rules applied to INPUT. If the sent byte arrives, the newer
netfilter implementation has been detected and we convert the strings
in the iptables output to now match that inversion implemented by libvirt.
The downside of this is that probing of libvirt and this test tool are
independent and this test tool will only work correctly for all cases
if used with libvirt probing for 'ctdir inversion' as well.
Signed-off-by: Stefan Berger <stefanb(a)linux.vnet.ibm.com>
---
scripts/nwfilter/nwfilter2vmtest.sh | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
Index: libvirt-tck/scripts/nwfilter/nwfilter2vmtest.sh
===================================================================
--- libvirt-tck.orig/scripts/nwfilter/nwfilter2vmtest.sh
+++ libvirt-tck/scripts/nwfilter/nwfilter2vmtest.sh
@@ -28,6 +28,10 @@ FLAG_LIBVIRT_TEST="$((1<<3))"
FLAG_TAP_TEST="$((1<<4))"
FLAG_FORCE_CLEAN="$((1<<5))"
+# --ctdir original vs. --ctdir reply's meaning was inverted in
+# netfilter at some point. We probe for it.
+IPTABLES_CTRDIR_CORRECTED=0
+
failctr=0
passctr=0
attachfailctr=0
@@ -100,6 +104,15 @@ mktmpdir() {
return 0
}
+probeIptablesCtdir() {
+ iptables -I INPUT 1 -i lo -p icmp -m state --state ESTABLISHED -j ACCEPT
+ iptables -I INPUT 2 -i lo -p icmp -m conntrack --ctdir ORIGINAL -j ACCEPT
+ iptables -I INPUT 3 -i lo -p icmp -j DROP
+ IPTABLES_CTDIR_CORRECTED=$(ping 127.0.0.1 -c 1 | sed -n 's/.*,
\([0-9]*\) received,.*/\1/p')
+ iptables -D INPUT -i lo -p icmp -m state --state ESTABLISHED -j ACCEPT
+ iptables -D INPUT -i lo -p icmp -m conntrack --ctdir ORIGINAL -j ACCEPT
+ iptables -D INPUT -i lo -p icmp -j DROP
+}
checkExpectedOutput() {
xmlfile="$1"
@@ -160,6 +173,14 @@ checkExpectedOutput() {
break
fi
+ if [ $IPTABLES_CTDIR_CORRECTED -ne 0 ]; then
+ #change --ctdir ORIGINAL to --ctdir REPLY
+ #and --ctdir REPLY to --ctdir ORIGINAL
+ sed -i "s/ctdir[ ]*ORIGINAL/ctdir _REPLY/" ${tmpfile}
+ sed -i "s/ctdir[ ]*REPLY/ctdir ORIGINAL/" ${tmpfile}
+ sed -i "s/ctdir _REPLY/ctdir REPLY/" ${tmpfile}
+ fi
+
diff -w ${tmpfile} ${tmpfile2} >/dev/null
if [ $? -ne 0 ]; then
@@ -551,6 +572,8 @@ main() {
echo "This script will only run on Linux."
fi
exit 1;
+ else
+ probeIptablesCtdir
fi
if [ $(($flags & $FLAG_TAP_TEST)) -ne 0 ]; then