summaryrefslogtreecommitdiff
path: root/regress/sys
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2016-10-20 18:17:05 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2016-10-20 18:17:05 +0000
commita1232db782076c0e2f61211f0733f3f7c453eea0 (patch)
tree821a4597fd415e37d2bbca5a2e7631a7369caa5f /regress/sys
parent7d5ac3cb7b4e35b462f6c56e59aedd12b05daa37 (diff)
Replace fork() and sleep() with a Python thread for sniffing packets.
This reduces test execution time from 2m21.95s to 1m09.80s.
Diffstat (limited to 'regress/sys')
-rw-r--r--regress/sys/net/pf_fragment/frag.py24
-rw-r--r--regress/sys/net/pf_fragment/frag6.py24
-rw-r--r--regress/sys/net/pf_fragment/frag6_cutnew.py26
-rw-r--r--regress/sys/net/pf_fragment/frag6_cutold.py26
-rw-r--r--regress/sys/net/pf_fragment/frag6_dropnew.py26
-rw-r--r--regress/sys/net/pf_fragment/frag6_dropold.py26
-rw-r--r--regress/sys/net/pf_fragment/frag6_ext.py24
-rw-r--r--regress/sys/net/pf_fragment/frag_cutnew.py24
-rw-r--r--regress/sys/net/pf_fragment/frag_cutold.py24
-rw-r--r--regress/sys/net/pf_fragment/frag_dropnew.py24
-rw-r--r--regress/sys/net/pf_fragment/frag_dropold.py24
-rw-r--r--regress/sys/net/pf_fragment/ping6_mtu_1300.py32
12 files changed, 212 insertions, 92 deletions
diff --git a/regress/sys/net/pf_fragment/frag.py b/regress/sys/net/pf_fragment/frag.py
index a9abb99013d..c66b8160e9d 100644
--- a/regress/sys/net/pf_fragment/frag.py
+++ b/regress/sys/net/pf_fragment/frag.py
@@ -2,9 +2,20 @@
# send 2 non-overlapping ping fragments
import os
+import threading
from addr import *
from scapy.all import *
+class Sniff1(threading.Thread):
+ filter = None
+ captured = None
+ packet = None
+ def run(self):
+ self.captured = sniff(iface=SRC_IF, filter=self.filter,
+ count=1, timeout=3)
+ if self.captured:
+ self.packet = self.captured[0]
+
dstaddr=sys.argv[1]
pid=os.getpid() & 0xffff
payload="ABCDEFGHIJKLOMNO"
@@ -17,14 +28,13 @@ eth=[]
eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt0)
eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt1)
-if os.fork() == 0:
- time.sleep(1)
- sendp(eth, iface=SRC_IF)
- os._exit(0)
+sniffer = Sniff1();
+sniffer.filter = "ip and src %s and dst %s and icmp" % (dstaddr, SRC_OUT)
+sniffer.start()
+sendp(eth, iface=SRC_IF)
+sniffer.join(timeout=5)
+a = sniffer.packet
-ans=sniff(iface=SRC_IF, timeout=3, filter=
- "ip and src "+dstaddr+" and dst "+SRC_OUT+" and icmp")
-a=ans[0]
if a and a.type == ETH_P_IP and \
a.payload.proto == 1 and \
a.payload.frag == 0 and a.payload.flags == 0 and \
diff --git a/regress/sys/net/pf_fragment/frag6.py b/regress/sys/net/pf_fragment/frag6.py
index 3834634eaa1..81259afd3bb 100644
--- a/regress/sys/net/pf_fragment/frag6.py
+++ b/regress/sys/net/pf_fragment/frag6.py
@@ -2,9 +2,20 @@
# send 2 non-overlapping ping6 fragments
import os
+import threading
from addr import *
from scapy.all import *
+class Sniff1(threading.Thread):
+ filter = None
+ captured = None
+ packet = None
+ def run(self):
+ self.captured = sniff(iface=SRC_IF, filter=self.filter,
+ count=1, timeout=3)
+ if self.captured:
+ self.packet = self.captured[0]
+
dstaddr=sys.argv[1]
pid=os.getpid() & 0xffff
payload="ABCDEFGHIJKLOMNO"
@@ -17,14 +28,13 @@ eth=[]
eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt0)
eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt1)
-if os.fork() == 0:
- time.sleep(1)
- sendp(eth, iface=SRC_IF)
- os._exit(0)
+sniffer = Sniff1();
+sniffer.filter = "ip6 and src %s and dst %s and icmp6" % (dstaddr, SRC_OUT6)
+sniffer.start()
+sendp(eth, iface=SRC_IF)
+sniffer.join(timeout=5)
+a = sniffer.packet
-ans=sniff(iface=SRC_IF, timeout=3, filter=
- "ip6 and src "+dstaddr+" and dst "+SRC_OUT6+" and icmp6")
-a=ans[0]
if a and a.type == ETH_P_IPV6 and \
ipv6nh[a.payload.nh] == 'ICMPv6' and \
icmp6types[a.payload.payload.type] == 'Echo Reply':
diff --git a/regress/sys/net/pf_fragment/frag6_cutnew.py b/regress/sys/net/pf_fragment/frag6_cutnew.py
index 99ef2b0e25d..d0b4dc9f331 100644
--- a/regress/sys/net/pf_fragment/frag6_cutnew.py
+++ b/regress/sys/net/pf_fragment/frag6_cutnew.py
@@ -7,9 +7,20 @@
# RFC 5722 drop overlapping fragments
import os
+import threading
from addr import *
from scapy.all import *
+class Sniff1(threading.Thread):
+ filter = None
+ captured = None
+ packet = None
+ def run(self):
+ self.captured = sniff(iface=SRC_IF, filter=self.filter,
+ count=1, timeout=3)
+ if self.captured:
+ self.packet = self.captured[0]
+
dstaddr=sys.argv[1]
pid=os.getpid() & 0xffff
payload="ABCDEFGHIJKLOMNO"
@@ -23,17 +34,16 @@ eth=[]
eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt0)
eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt1)
-if os.fork() == 0:
- time.sleep(1)
- sendp(eth, iface=SRC_IF)
- os._exit(0)
+sniffer = Sniff1();
+sniffer.filter = "ip6 and src %s and dst %s and icmp6" % (dstaddr, SRC_OUT6)
+sniffer.start()
+sendp(eth, iface=SRC_IF)
+sniffer.join(timeout=5)
+a = sniffer.packet
-ans=sniff(iface=SRC_IF, timeout=3, filter=
- "ip6 and src "+dstaddr+" and dst "+SRC_OUT6+" and icmp6")
-if len(ans) == 0:
+if a is None:
print "no reply"
exit(0)
-a=ans[0]
if a and a.type == ETH_P_IPV6 and \
ipv6nh[a.payload.nh] == 'ICMPv6' and \
icmp6types[a.payload.payload.type] == 'Echo Reply':
diff --git a/regress/sys/net/pf_fragment/frag6_cutold.py b/regress/sys/net/pf_fragment/frag6_cutold.py
index e9e6a81ec4e..5822b2369fc 100644
--- a/regress/sys/net/pf_fragment/frag6_cutold.py
+++ b/regress/sys/net/pf_fragment/frag6_cutold.py
@@ -7,9 +7,20 @@
# RFC 5722 drop overlapping fragments
import os
+import threading
from addr import *
from scapy.all import *
+class Sniff1(threading.Thread):
+ filter = None
+ captured = None
+ packet = None
+ def run(self):
+ self.captured = sniff(iface=SRC_IF, filter=self.filter,
+ count=1, timeout=3)
+ if self.captured:
+ self.packet = self.captured[0]
+
dstaddr=sys.argv[1]
pid=os.getpid() & 0xffff
payload="ABCDEFGHIJKLOMNO"
@@ -23,17 +34,16 @@ eth=[]
eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt1)
eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt0)
-if os.fork() == 0:
- time.sleep(1)
- sendp(eth, iface=SRC_IF)
- os._exit(0)
+sniffer = Sniff1();
+sniffer.filter = "ip6 and src %s and dst %s and icmp6" % (dstaddr, SRC_OUT6)
+sniffer.start()
+sendp(eth, iface=SRC_IF)
+sniffer.join(timeout=5)
+a = sniffer.packet
-ans=sniff(iface=SRC_IF, timeout=3, filter=
- "ip6 and src "+dstaddr+" and dst "+SRC_OUT6+" and icmp6")
-if len(ans) == 0:
+if a is None:
print "no reply"
exit(0)
-a=ans[0]
if a and a.type == ETH_P_IPV6 and \
ipv6nh[a.payload.nh] == 'ICMPv6' and \
icmp6types[a.payload.payload.type] == 'Echo Reply':
diff --git a/regress/sys/net/pf_fragment/frag6_dropnew.py b/regress/sys/net/pf_fragment/frag6_dropnew.py
index 4cb54513c9e..37164707d10 100644
--- a/regress/sys/net/pf_fragment/frag6_dropnew.py
+++ b/regress/sys/net/pf_fragment/frag6_dropnew.py
@@ -8,9 +8,20 @@
# RFC 5722 drop overlapping fragments
import os
+import threading
from addr import *
from scapy.all import *
+class Sniff1(threading.Thread):
+ filter = None
+ captured = None
+ packet = None
+ def run(self):
+ self.captured = sniff(iface=SRC_IF, filter=self.filter,
+ count=1, timeout=3)
+ if self.captured:
+ self.packet = self.captured[0]
+
dstaddr=sys.argv[1]
pid=os.getpid() & 0xffff
payload="ABCDEFGHIJKLOMNOQRSTUVWX"
@@ -27,17 +38,16 @@ eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt2)
eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt1)
eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt0)
-if os.fork() == 0:
- time.sleep(1)
- sendp(eth, iface=SRC_IF)
- os._exit(0)
+sniffer = Sniff1();
+sniffer.filter = "ip6 and src %s and dst %s and icmp6" % (dstaddr, SRC_OUT6)
+sniffer.start()
+sendp(eth, iface=SRC_IF)
+sniffer.join(timeout=5)
+a = sniffer.packet
-ans=sniff(iface=SRC_IF, timeout=3, filter=
- "ip6 and src "+dstaddr+" and dst "+SRC_OUT6+" and icmp6")
-if len(ans) == 0:
+if a is None:
print "no reply"
exit(0)
-a=ans[0]
if a and a.type == ETH_P_IPV6 and \
ipv6nh[a.payload.nh] == 'ICMPv6' and \
icmp6types[a.payload.payload.type] == 'Echo Reply':
diff --git a/regress/sys/net/pf_fragment/frag6_dropold.py b/regress/sys/net/pf_fragment/frag6_dropold.py
index 895ea8191ac..f2e847adec5 100644
--- a/regress/sys/net/pf_fragment/frag6_dropold.py
+++ b/regress/sys/net/pf_fragment/frag6_dropold.py
@@ -8,9 +8,20 @@
# RFC 5722 drop overlapping fragments
import os
+import threading
from addr import *
from scapy.all import *
+class Sniff1(threading.Thread):
+ filter = None
+ captured = None
+ packet = None
+ def run(self):
+ self.captured = sniff(iface=SRC_IF, filter=self.filter,
+ count=1, timeout=3)
+ if self.captured:
+ self.packet = self.captured[0]
+
dstaddr=sys.argv[1]
pid=os.getpid() & 0xffff
payload="ABCDEFGHIJKLOMNOQRSTUVWX"
@@ -27,17 +38,16 @@ eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt0)
eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt1)
eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt2)
-if os.fork() == 0:
- time.sleep(1)
- sendp(eth, iface=SRC_IF)
- os._exit(0)
+sniffer = Sniff1();
+sniffer.filter = "ip6 and src %s and dst %s and icmp6" % (dstaddr, SRC_OUT6)
+sniffer.start()
+sendp(eth, iface=SRC_IF)
+sniffer.join(timeout=5)
+a = sniffer.packet
-ans=sniff(iface=SRC_IF, timeout=3, filter=
- "ip6 and src "+dstaddr+" and dst "+SRC_OUT6+" and icmp6")
-if len(ans) == 0:
+if a is None:
print "no reply"
exit(0)
-a=ans[0]
if a and a.type == ETH_P_IPV6 and \
ipv6nh[a.payload.nh] == 'ICMPv6' and \
icmp6types[a.payload.payload.type] == 'Echo Reply':
diff --git a/regress/sys/net/pf_fragment/frag6_ext.py b/regress/sys/net/pf_fragment/frag6_ext.py
index 72e1bd5f6f6..21f1d1cf1f5 100644
--- a/regress/sys/net/pf_fragment/frag6_ext.py
+++ b/regress/sys/net/pf_fragment/frag6_ext.py
@@ -2,9 +2,20 @@
# send 2 ping6 fragments with hop-by-hop extension header
import os
+import threading
from addr import *
from scapy.all import *
+class Sniff1(threading.Thread):
+ filter = None
+ captured = None
+ packet = None
+ def run(self):
+ self.captured = sniff(iface=SRC_IF, filter=self.filter,
+ count=1, timeout=3)
+ if self.captured:
+ self.packet = self.captured[0]
+
dstaddr=sys.argv[1]
pid=os.getpid() & 0xffff
payload="ABCDEFGHIJKLOMNO"
@@ -17,14 +28,13 @@ eth=[]
eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt0)
eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt1)
-if os.fork() == 0:
- time.sleep(1)
- sendp(eth, iface=SRC_IF)
- os._exit(0)
+sniffer = Sniff1();
+sniffer.filter = "ip6 and src %s and dst %s and icmp6" % (dstaddr, SRC_OUT6)
+sniffer.start()
+sendp(eth, iface=SRC_IF)
+sniffer.join(timeout=5)
+a = sniffer.packet
-ans=sniff(iface=SRC_IF, timeout=3, filter=
- "ip6 and src "+dstaddr+" and dst "+SRC_OUT6+" and icmp6")
-a=ans[0]
if a and a.type == ETH_P_IPV6 and \
ipv6nh[a.payload.nh] == 'ICMPv6' and \
icmp6types[a.payload.payload.type] == 'Echo Reply':
diff --git a/regress/sys/net/pf_fragment/frag_cutnew.py b/regress/sys/net/pf_fragment/frag_cutnew.py
index 600d524e5b7..3a36dd9e42c 100644
--- a/regress/sys/net/pf_fragment/frag_cutnew.py
+++ b/regress/sys/net/pf_fragment/frag_cutnew.py
@@ -10,9 +10,20 @@
# Newer data wins.
import os
+import threading
from addr import *
from scapy.all import *
+class Sniff1(threading.Thread):
+ filter = None
+ captured = None
+ packet = None
+ def run(self):
+ self.captured = sniff(iface=SRC_IF, filter=self.filter,
+ count=1, timeout=3)
+ if self.captured:
+ self.packet = self.captured[0]
+
dstaddr=sys.argv[1]
pid=os.getpid() & 0xffff
payload="ABCDEFGHIJKLOMNO"
@@ -26,14 +37,13 @@ eth=[]
eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt0)
eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt1)
-if os.fork() == 0:
- time.sleep(1)
- sendp(eth, iface=SRC_IF)
- os._exit(0)
+sniffer = Sniff1();
+sniffer.filter = "ip and src %s and dst %s and icmp" % (dstaddr, SRC_OUT)
+sniffer.start()
+sendp(eth, iface=SRC_IF)
+sniffer.join(timeout=5)
+a = sniffer.packet
-ans=sniff(iface=SRC_IF, timeout=3, filter=
- "ip and src "+dstaddr+" and dst "+SRC_OUT+" and icmp")
-a=ans[0]
if a and a.type == ETH_P_IP and \
a.payload.proto == 1 and \
a.payload.frag == 0 and a.payload.flags == 0 and \
diff --git a/regress/sys/net/pf_fragment/frag_cutold.py b/regress/sys/net/pf_fragment/frag_cutold.py
index 5cf10af0d91..c43ba45dac3 100644
--- a/regress/sys/net/pf_fragment/frag_cutold.py
+++ b/regress/sys/net/pf_fragment/frag_cutold.py
@@ -11,9 +11,20 @@
# to be dropped in the end, meaning it will come again.
import os
+import threading
from addr import *
from scapy.all import *
+class Sniff1(threading.Thread):
+ filter = None
+ captured = None
+ packet = None
+ def run(self):
+ self.captured = sniff(iface=SRC_IF, filter=self.filter,
+ count=1, timeout=3)
+ if self.captured:
+ self.packet = self.captured[0]
+
dstaddr=sys.argv[1]
pid=os.getpid() & 0xffff
payload="ABCDEFGHIJKLOMNO"
@@ -27,14 +38,13 @@ eth=[]
eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt1)
eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt0)
-if os.fork() == 0:
- time.sleep(1)
- sendp(eth, iface=SRC_IF)
- os._exit(0)
+sniffer = Sniff1();
+sniffer.filter = "ip and src %s and dst %s and icmp" % (dstaddr, SRC_OUT)
+sniffer.start()
+sendp(eth, iface=SRC_IF)
+sniffer.join(timeout=5)
+a = sniffer.packet
-ans=sniff(iface=SRC_IF, timeout=3, filter=
- "ip and src "+dstaddr+" and dst "+SRC_OUT+" and icmp")
-a=ans[0]
if a and a.type == ETH_P_IP and \
a.payload.proto == 1 and \
a.payload.frag == 0 and a.payload.flags == 0 and \
diff --git a/regress/sys/net/pf_fragment/frag_dropnew.py b/regress/sys/net/pf_fragment/frag_dropnew.py
index 2aadd8df2f4..f26743f69b6 100644
--- a/regress/sys/net/pf_fragment/frag_dropnew.py
+++ b/regress/sys/net/pf_fragment/frag_dropnew.py
@@ -12,9 +12,20 @@
# 'Nearer' traffic wins.
import os
+import threading
from addr import *
from scapy.all import *
+class Sniff1(threading.Thread):
+ filter = None
+ captured = None
+ packet = None
+ def run(self):
+ self.captured = sniff(iface=SRC_IF, filter=self.filter,
+ count=1, timeout=3)
+ if self.captured:
+ self.packet = self.captured[0]
+
dstaddr=sys.argv[1]
pid=os.getpid() & 0xffff
payload="ABCDEFGHIJKLOMNOQRSTUVWX"
@@ -31,14 +42,13 @@ eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt2)
eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt1)
eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt0)
-if os.fork() == 0:
- time.sleep(1)
- sendp(eth, iface=SRC_IF)
- os._exit(0)
+sniffer = Sniff1();
+sniffer.filter = "ip and src %s and dst %s and icmp" % (dstaddr, SRC_OUT)
+sniffer.start()
+sendp(eth, iface=SRC_IF)
+sniffer.join(timeout=5)
+a = sniffer.packet
-ans=sniff(iface=SRC_IF, timeout=3, filter=
- "ip and src "+dstaddr+" and dst "+SRC_OUT+" and icmp")
-a=ans[0]
if a and a.type == ETH_P_IP and \
a.payload.proto == 1 and \
a.payload.frag == 0 and a.payload.flags == 0 and \
diff --git a/regress/sys/net/pf_fragment/frag_dropold.py b/regress/sys/net/pf_fragment/frag_dropold.py
index 938c616ca95..cbe17d162fe 100644
--- a/regress/sys/net/pf_fragment/frag_dropold.py
+++ b/regress/sys/net/pf_fragment/frag_dropold.py
@@ -12,9 +12,20 @@
# trying to overwrite a very small part of the full packet.
import os
+import threading
from addr import *
from scapy.all import *
+class Sniff1(threading.Thread):
+ filter = None
+ captured = None
+ packet = None
+ def run(self):
+ self.captured = sniff(iface=SRC_IF, filter=self.filter,
+ count=1, timeout=3)
+ if self.captured:
+ self.packet = self.captured[0]
+
dstaddr=sys.argv[1]
pid=os.getpid() & 0xffff
payload="ABCDEFGHIJKLOMNOQRSTUVWX"
@@ -31,14 +42,13 @@ eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt0)
eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt1)
eth.append(Ether(src=SRC_MAC, dst=PF_MAC)/pkt2)
-if os.fork() == 0:
- time.sleep(1)
- sendp(eth, iface=SRC_IF)
- os._exit(0)
+sniffer = Sniff1();
+sniffer.filter = "ip and src %s and dst %s and icmp" % (dstaddr, SRC_OUT)
+sniffer.start()
+sendp(eth, iface=SRC_IF)
+sniffer.join(timeout=5)
+a = sniffer.packet
-ans=sniff(iface=SRC_IF, timeout=3, filter=
- "ip and src "+dstaddr+" and dst "+SRC_OUT+" and icmp")
-a=ans[0]
if a and a.type == ETH_P_IP and \
a.payload.proto == 1 and \
a.payload.frag == 0 and a.payload.flags == 0 and \
diff --git a/regress/sys/net/pf_fragment/ping6_mtu_1300.py b/regress/sys/net/pf_fragment/ping6_mtu_1300.py
index d5c78a75e98..1a038224a59 100644
--- a/regress/sys/net/pf_fragment/ping6_mtu_1300.py
+++ b/regress/sys/net/pf_fragment/ping6_mtu_1300.py
@@ -2,9 +2,22 @@
# check wether path mtu to dst is 1300
import os
+import threading
from addr import *
from scapy.all import *
+# work around the broken sniffing of packages with bad checksum
+#a=srp1(eth, iface=SRC_IF, timeout=2)
+class Sniff1(threading.Thread):
+ filter = None
+ captured = None
+ packet = None
+ def run(self):
+ self.captured = sniff(iface=SRC_IF, filter=self.filter,
+ count=1, timeout=3)
+ if self.captured:
+ self.packet = self.captured[0]
+
dstaddr=sys.argv[1]
pid=os.getpid() & 0xffff
hdr=IPv6(src=SRC_OUT6, dst=dstaddr)/ICMPv6EchoRequest(id=pid)
@@ -12,19 +25,16 @@ payload="a" * (1400 - len(str(hdr)))
ip=hdr/payload
eth=Ether(src=SRC_MAC, dst=PF_MAC)/ip
-# work around the broken sniffing of packages with bad checksum
-#a=srp1(eth, iface=SRC_IF, timeout=2)
-if os.fork() == 0:
- time.sleep(1)
- sendp(eth, iface=SRC_IF)
- os._exit(0)
-ans=sniff(iface=SRC_IF, timeout=3, filter=
- "ip6 and dst "+SRC_OUT6+" and icmp6")
-if len(ans) == 0:
+sniffer = Sniff1();
+sniffer.filter = "ip6 and dst %s and icmp6" % SRC_OUT6
+sniffer.start()
+sendp(eth, iface=SRC_IF)
+sniffer.join(timeout=5)
+a = sniffer.packet
+
+if a is None:
print "no packet sniffed"
exit(2)
-a=ans[0]
-
if a and a.type == ETH_P_IPV6 and \
ipv6nh[a.payload.nh] == 'ICMPv6' and \
icmp6types[a.payload.payload.type] == 'Packet too big':