diff options
author | 2016-10-20 17:25:50 +0000 | |
---|---|---|
committer | 2016-10-20 17:25:50 +0000 | |
commit | 2dff962a51f8f7be825fa874e1b1880eb329823f (patch) | |
tree | b95358338fe4580cf9a5ed83c6746bd22b25d3f4 | |
parent | Make the test faster. Move all the packet matching code into the (diff) | |
download | wireguard-openbsd-2dff962a51f8f7be825fa874e1b1880eb329823f.tar.xz wireguard-openbsd-2dff962a51f8f7be825fa874e1b1880eb329823f.zip |
Replace fork() and sleep() with a Python thread for sniffing packets.
This reduces test execution time from 1m20.34s to 0m37.32s.
-rw-r--r-- | regress/sys/net/pf_forward/ping6_mtu.py | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/regress/sys/net/pf_forward/ping6_mtu.py b/regress/sys/net/pf_forward/ping6_mtu.py index e1eba8ad59e..0d9a8d433cd 100644 --- a/regress/sys/net/pf_forward/ping6_mtu.py +++ b/regress/sys/net/pf_forward/ping6_mtu.py @@ -2,11 +2,24 @@ # check wether path mtu to dst is as expected import os +import threading from addr import * from scapy.all import * # usage: ping6_mtu src dst size icmp6-size +# 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] + srcaddr=sys.argv[1] dstaddr=sys.argv[2] size=int(sys.argv[3]) @@ -18,18 +31,12 @@ ip=hdr/payload iplen=IPv6(str(ip)).plen 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 "+srcaddr+" and icmp6") -if len(ans) == 0: - print "no packet sniffed" - exit(2) -a=ans[0] +sniffer = Sniff1(); +sniffer.filter = "ip6 and dst %s and icmp6" % srcaddr +sniffer.start() +sendp(eth, iface=SRC_IF) +sniffer.join(timeout=5) +a = sniffer.packet if a and a.type == ETH_P_IPV6 and \ ipv6nh[a.payload.nh] == 'ICMPv6' and \ |