[libvirt] [PATCH v2] [TCK] nwfilter: probe for inverted ctdir

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@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() { + # below gawk works for "2\.6\.39.*"; any non-digit immediately + # after '39' will be ignored + rev=$(uname -r | gawk -F. '{print $1 * 1000000 + $2 * 1000 + $3 }') + # 2.6.39 had the correction + if [ $rev -ge 2006039 ]; then + IPTABLES_CTDIR_CORRECTED=1 + fi +} 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

On 05/16/2013 10:02 AM, Stefan Berger wrote:
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.
Such is life - running newer TCK against older libvirt will thus potentially expose the bugs in that older libvirt, unless it is also on the older kernel.
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
--- scripts/nwfilter/nwfilter2vmtest.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
ACK. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 05/16/2013 04:07 PM, Eric Blake wrote:
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. Such is life - running newer TCK against older libvirt will thus
On 05/16/2013 10:02 AM, Stefan Berger wrote: potentially expose the bugs in that older libvirt, unless it is also on the older kernel.
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
--- scripts/nwfilter/nwfilter2vmtest.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
ACK.
Pushed (fixed the commit message a bit to reflect kernel version probing)

On Thu, May 16, 2013 at 02:07:31PM -0600, Eric Blake wrote:
On 05/16/2013 10:02 AM, Stefan Berger wrote:
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.
Such is life - running newer TCK against older libvirt will thus potentially expose the bugs in that older libvirt, unless it is also on the older kernel.
That is actually a good thing, because it demonstrates to the person running the test suite that their version of libvirt has a bug. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (3)
-
Daniel P. Berrange
-
Eric Blake
-
Stefan Berger