diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2016-10-20 17:25:51 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2016-10-20 17:25:51 +0000 |
commit | 672a2aa9aa36418bdc8b25edf42ed1c52fa2a4cc (patch) | |
tree | a8bb356b6c73ef74b314dccd23b18296493c25e3 /regress/sys | |
parent | 189a77ec62a32f6517741d8a0155b7c1858e4816 (diff) |
Replace fork() and sleep() with a Python thread for sniffing packets.
This reduces test execution time from 1m20.34s to 0m37.32s.
Diffstat (limited to 'regress/sys')
-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 \ |