summaryrefslogtreecommitdiffstats
path: root/regress/sys/net/pf_fragment/frag6.py
diff options
context:
space:
mode:
authorbluhm <bluhm@openbsd.org>2016-10-20 18:17:04 +0000
committerbluhm <bluhm@openbsd.org>2016-10-20 18:17:04 +0000
commit1eb14a7b0bc3b5681b840e407a76766b8df6b31d (patch)
tree1c8e7847fe95657cef58169b6fe22ea5ca915fe8 /regress/sys/net/pf_fragment/frag6.py
parentUpdate to tzdata2016h from from ftp.iana.org. (diff)
downloadwireguard-openbsd-1eb14a7b0bc3b5681b840e407a76766b8df6b31d.tar.xz
wireguard-openbsd-1eb14a7b0bc3b5681b840e407a76766b8df6b31d.zip
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/net/pf_fragment/frag6.py')
-rw-r--r--regress/sys/net/pf_fragment/frag6.py24
1 files changed, 17 insertions, 7 deletions
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':