summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoe Stringer <joe@ovn.org>2016-12-22 10:58:25 -0800
committerJoe Stringer <joe@ovn.org>2017-01-03 09:32:58 -0800
commit40c7b2fc0d181155ea87a962a522d48f4166370b (patch)
tree12ef207e5f2c2fd0ff1490301f1556cf7b2e9059 /tests
parentc26ed9c251c2fb9e2139eb1cc50258255cf16d01 (diff)
downloadopenvswitch-40c7b2fc0d181155ea87a962a522d48f4166370b.tar.gz
lib: Add support for tftp ct helper.
The kernel datapath provides support for TFTP helpers, so add support for this ALG to the commandline and OpenFlow encoding/decoding. Signed-off-by: Joe Stringer <joe@ovn.org> Acked-by: Daniele Di Proietto <diproiettod@vmware.com> Acked-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/atlocal.in26
-rw-r--r--tests/odp.at1
-rw-r--r--tests/ofp-actions.at3
-rw-r--r--tests/system-traffic.at84
-rwxr-xr-xtests/test-l7.py32
5 files changed, 128 insertions, 18 deletions
diff --git a/tests/atlocal.in b/tests/atlocal.in
index 5b151c3d8..c0b28938c 100644
--- a/tests/atlocal.in
+++ b/tests/atlocal.in
@@ -117,12 +117,24 @@ if test "$IS_WIN32" = "yes"; then
HAVE_PYTHON3="no"
fi
-if test "$HAVE_PYTHON" = "yes" \
- && test "x`$PYTHON $abs_top_srcdir/tests/test-l7.py --help | grep 'ftp'`" != x; then
- HAVE_PYFTPDLIB="yes"
-else
- HAVE_PYFTPDLIB="no"
-fi
+find_l7_lib()
+{
+ set +x
+ var=HAVE_`echo "$1" | tr '[a-z]' '[A-Z]'`
+ if test "$HAVE_PYTHON" = "yes"; then
+ result=$($PYTHON $abs_top_srcdir/tests/test-l7.py --help | grep "$1")
+ if test "x${result}" != x; then
+ eval ${var}="yes"
+ else
+ eval ${var}="no"
+ fi
+ else
+ eval ${var}="no"
+ fi
+}
+
+find_l7_lib ftp
+find_l7_lib tftp
# Look for a commnand in the system. If it is found, defines
# HAVE_COMMAND="yes", otherwise HAVE_COMMAND="no".
@@ -148,6 +160,8 @@ else
NC_EOF_OPT="-q 1"
fi
+CURL_OPT="-g -v --max-time 1 --retry 2 --retry-delay 1 --connect-timeout 1"
+
# Turn off proxies.
unset http_proxy
unset https_proxy
diff --git a/tests/odp.at b/tests/odp.at
index 64aabe1d6..019897c2d 100644
--- a/tests/odp.at
+++ b/tests/odp.at
@@ -320,6 +320,7 @@ ct(commit,zone=5)
ct(commit,mark=0xa0a0a0a0/0xfefefefe)
ct(commit,label=0x1234567890abcdef1234567890abcdef/0xf1f2f3f4f5f6f7f8f9f0fafbfcfdfeff)
ct(commit,helper=ftp)
+ct(commit,helper=tftp)
ct(nat)
ct(commit,nat(src))
ct(commit,nat(dst))
diff --git a/tests/ofp-actions.at b/tests/ofp-actions.at
index db7385489..3881f9f82 100644
--- a/tests/ofp-actions.at
+++ b/tests/ofp-actions.at
@@ -201,6 +201,9 @@ ffff 0018 00002320 0007 001f 00010004 000000000000f009
# actions=ct(alg=ftp)
ffff 0018 00002320 0023 0000 00000000 0000 FF 000000 0015
+# actions=ct(alg=tftp)
+ffff 0018 00002320 0023 0000 00000000 0000 FF 000000 0045
+
# actions=ct(commit,nat(src))
ffff 0028 00002320 0023 0001 00000000 0000 FF 000000 0000 dnl
ffff 0010 00002320 0024 00 00 0001 0000
diff --git a/tests/system-traffic.at b/tests/system-traffic.at
index a5023d38e..29dd6d632 100644
--- a/tests/system-traffic.at
+++ b/tests/system-traffic.at
@@ -1987,7 +1987,7 @@ OVS_TRAFFIC_VSWITCHD_STOP
AT_CLEANUP
AT_SETUP([conntrack - FTP])
-AT_SKIP_IF([test $HAVE_PYFTPDLIB = no])
+AT_SKIP_IF([test $HAVE_FTP = no])
CHECK_CONNTRACK()
CHECK_CONNTRACK_ALG()
OVS_TRAFFIC_VSWITCHD_START()
@@ -2072,7 +2072,7 @@ OVS_TRAFFIC_VSWITCHD_STOP
AT_CLEANUP
AT_SETUP([conntrack - FTP over IPv6])
-AT_SKIP_IF([test $HAVE_PYFTPDLIB = no])
+AT_SKIP_IF([test $HAVE_FTP = no])
CHECK_CONNTRACK()
CHECK_CONNTRACK_ALG()
OVS_TRAFFIC_VSWITCHD_START()
@@ -2127,7 +2127,7 @@ OVS_TRAFFIC_VSWITCHD_STOP
AT_CLEANUP
AT_SETUP([conntrack - FTP with multiple expectations])
-AT_SKIP_IF([test $HAVE_PYFTPDLIB = no])
+AT_SKIP_IF([test $HAVE_FTP = no])
CHECK_CONNTRACK()
CHECK_CONNTRACK_ALG()
OVS_TRAFFIC_VSWITCHD_START()
@@ -2192,6 +2192,80 @@ tcp,orig=(src=10.1.1.1,dst=10.1.1.2,sport=<cleared>,dport=<cleared>),reply=(src=
OVS_TRAFFIC_VSWITCHD_STOP
AT_CLEANUP
+AT_SETUP([conntrack - TFTP])
+AT_SKIP_IF([test $HAVE_TFTP = no])
+CHECK_CONNTRACK()
+CHECK_CONNTRACK_ALG()
+OVS_TRAFFIC_VSWITCHD_START()
+
+ADD_NAMESPACES(at_ns0, at_ns1)
+
+ADD_VETH(p0, at_ns0, br0, "10.1.1.1/24")
+ADD_VETH(p1, at_ns1, br0, "10.1.1.2/24")
+
+dnl Allow any traffic from ns0->ns1. Only allow nd, return traffic from ns1->ns0.
+AT_DATA([flows1.txt], [dnl
+table=0,priority=1,action=drop
+table=0,priority=10,arp,action=normal
+table=0,priority=10,icmp,action=normal
+table=0,priority=100,in_port=1,udp,action=ct(alg=tftp,commit),2
+table=0,priority=100,in_port=2,udp,action=ct(table=1)
+table=1,in_port=2,udp,ct_state=+trk+est,action=1
+table=1,in_port=2,udp,ct_state=+trk+rel,action=1
+])
+
+dnl Similar policy but without allowing all traffic from ns0->ns1.
+AT_DATA([flows2.txt], [dnl
+table=0,priority=1,action=drop
+table=0,priority=10,arp,action=normal
+table=0,priority=10,icmp,action=normal
+
+dnl Allow outgoing UDP connections, and treat them as TFTP
+table=0,priority=100,in_port=1,udp,action=ct(table=1)
+table=1,in_port=1,udp,ct_state=+trk+new-rel,action=ct(commit,alg=tftp),2
+table=1,in_port=1,udp,ct_state=+trk+new+rel,action=ct(commit),2
+table=1,in_port=1,udp,ct_state=+trk+est,action=2
+
+dnl Allow incoming TFTP data connections and responses to existing connections
+table=0,priority=100,in_port=2,udp,action=ct(table=1)
+table=1,in_port=2,udp,ct_state=+trk+est,action=1
+table=1,in_port=2,udp,ct_state=+trk+new+rel,action=1
+])
+
+AT_CHECK([ovs-ofctl --bundle replace-flows br0 flows1.txt])
+
+OVS_START_L7([at_ns0], [tftp])
+OVS_START_L7([at_ns1], [tftp])
+
+dnl TFTP requests from p1->p0 should fail due to network failure.
+NS_CHECK_EXEC([at_ns1], [[curl $CURL_OPT tftp://10.1.1.1/flows1.txt -o foo 2>curl0.log]], [28])
+AT_CHECK([ovs-appctl dpctl/dump-conntrack | FORMAT_CT(10.1.1.1)], [0], [dnl
+])
+
+dnl TFTP requests from p0->p1 should work fine.
+NS_CHECK_EXEC([at_ns0], [[curl $CURL_OPT tftp://10.1.1.2/flows1.txt -o foo 2>curl1.log]])
+AT_CHECK([ovs-appctl dpctl/dump-conntrack | FORMAT_CT(10.1.1.2)], [0], [dnl
+udp,orig=(src=10.1.1.1,dst=10.1.1.2,sport=<cleared>,dport=<cleared>),reply=(src=10.1.1.2,dst=10.1.1.1,sport=<cleared>,dport=<cleared>),helper=tftp
+])
+
+dnl Try the second set of flows.
+AT_CHECK([ovs-ofctl --bundle replace-flows br0 flows2.txt])
+AT_CHECK([ovs-appctl dpctl/flush-conntrack])
+
+dnl TFTP requests from p1->p0 should fail due to network failure.
+NS_CHECK_EXEC([at_ns1], [[curl $CURL_OPT tftp://10.1.1.1/flows1.txt -o foo 2>curl2.log]], [28])
+AT_CHECK([ovs-appctl dpctl/dump-conntrack | FORMAT_CT(10.1.1.1)], [0], [dnl
+])
+
+dnl TFTP requests from p0->p1 should work fine.
+NS_CHECK_EXEC([at_ns0], [[curl $CURL_OPT tftp://10.1.1.2/flows1.txt -o foo 2>curl3.log]])
+AT_CHECK([ovs-appctl dpctl/dump-conntrack | FORMAT_CT(10.1.1.2)], [0], [dnl
+udp,orig=(src=10.1.1.1,dst=10.1.1.2,sport=<cleared>,dport=<cleared>),reply=(src=10.1.1.2,dst=10.1.1.1,sport=<cleared>,dport=<cleared>),helper=tftp
+])
+
+OVS_TRAFFIC_VSWITCHD_STOP
+AT_CLEANUP
+
AT_BANNER([conntrack - NAT])
AT_SETUP([conntrack - simple SNAT])
@@ -2524,7 +2598,7 @@ dnl Checks the implementation of conntrack with FTP ALGs in combination with
dnl NAT, using the provided flow table.
m4_define([CHECK_FTP_NAT],
[AT_SETUP([conntrack - FTP NAT $1])
- AT_SKIP_IF([test $HAVE_PYFTPDLIB = no])
+ AT_SKIP_IF([test $HAVE_FTP = no])
CHECK_CONNTRACK()
CHECK_CONNTRACK_NAT()
@@ -2736,7 +2810,7 @@ AT_CLEANUP
AT_SETUP([conntrack - IPv6 FTP with NAT])
-AT_SKIP_IF([test $HAVE_PYFTPDLIB = no])
+AT_SKIP_IF([test $HAVE_FTP = no])
CHECK_CONNTRACK()
CHECK_CONNTRACK_NAT()
OVS_TRAFFIC_VSWITCHD_START()
diff --git a/tests/test-l7.py b/tests/test-l7.py
index aed34f411..e5f473b56 100755
--- a/tests/test-l7.py
+++ b/tests/test-l7.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2015 Nicira, Inc.
+# Copyright (c) 2015, 2016 Nicira, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -48,24 +48,42 @@ def get_ftpd():
return server
+def get_tftpd():
+ try:
+ from tftpy import TftpServer, TftpShared
+
+ class OVSTFTPServer(TftpServer):
+ def __init__(self, listen, handler=None):
+ (ip, port) = listen
+ self.ip = ip
+ self.port = port
+ TftpServer.__init__(self, tftproot='./')
+
+ def serve_forever(self):
+ self.listen(self.ip, self.port)
+ server = [OVSTFTPServer, None, TftpShared.DEF_TFTP_PORT]
+ except ImportError:
+ server = None
+ pass
+ return server
+
+
def main():
SERVERS = {
'http': [TCPServer, SimpleHTTPRequestHandler, 80],
'http6': [TCPServerV6, SimpleHTTPRequestHandler, 80],
+ 'ftp': get_ftpd(),
+ 'tftp': get_tftpd(),
}
- ftpd = get_ftpd()
- if ftpd is not None:
- SERVERS['ftp'] = ftpd
-
- protocols = [srv for srv in SERVERS]
+ protocols = [srv for srv in SERVERS if SERVERS[srv] is not None]
parser = argparse.ArgumentParser(
description='Run basic application servers.')
parser.add_argument('proto', default='http', nargs='?',
help='protocol to serve (%s)' % protocols)
args = parser.parse_args()
- if args.proto not in SERVERS:
+ if args.proto not in protocols:
parser.print_help()
exit(1)