diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2020-12-25 14:25:59 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2020-12-25 14:25:59 +0000 |
commit | 267aeb6b90184505fce826bfe632dbc7f8490f04 (patch) | |
tree | b7a1020645b6019647d86b1da8364849f948e6a0 /regress | |
parent | 8f73ecc72c45997ce262149bed3b2bfd2ce9554b (diff) |
Switch to scapy with python 3.
Diffstat (limited to 'regress')
-rw-r--r-- | regress/sbin/slaacd/IfInfo.py | 9 | ||||
-rw-r--r-- | regress/sbin/slaacd/Makefile | 9 | ||||
-rw-r--r-- | regress/sbin/slaacd/Slaacctl.py | 10 | ||||
-rw-r--r-- | regress/sbin/slaacd/process_ra.py | 7 | ||||
-rw-r--r-- | regress/sbin/slaacd/sniff_sol.py | 24 |
5 files changed, 32 insertions, 27 deletions
diff --git a/regress/sbin/slaacd/IfInfo.py b/regress/sbin/slaacd/IfInfo.py index 39c0a90bc29..ecf0b85efda 100644 --- a/regress/sbin/slaacd/IfInfo.py +++ b/regress/sbin/slaacd/IfInfo.py @@ -1,5 +1,7 @@ -# $OpenBSD: IfInfo.py,v 1.1 2017/10/11 17:21:44 florian Exp $ +# $OpenBSD: IfInfo.py,v 1.2 2020/12/25 14:25:58 bluhm Exp $ + # Copyright (c) 2017 Florian Obser <florian@openbsd.org> +# Copyright (c) 2020 Alexander Bluhm <bluhm@openbsd.org> # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above @@ -22,7 +24,8 @@ class IfInfo(object): self.ifname = ifname self.mac = None self.ll = None - self.out = subprocess.check_output(['ifconfig', ifname]) + self.out = subprocess.check_output(['ifconfig', ifname], + encoding='UTF-8') self.parse(self.out) def __str__(self): @@ -30,7 +33,7 @@ class IfInfo(object): self.mac, self.ll) def parse(self, str): - lines = str.split("\n") + lines = str.splitlines() for line in lines: lladdr = re.match("^\s+lladdr (.+)", line) link_local = re.match("^\s+inet6 ([^%]+)", line) diff --git a/regress/sbin/slaacd/Makefile b/regress/sbin/slaacd/Makefile index 965f454b307..d79249b7495 100644 --- a/regress/sbin/slaacd/Makefile +++ b/regress/sbin/slaacd/Makefile @@ -1,8 +1,7 @@ -# $OpenBSD: Makefile,v 1.7 2020/12/17 00:51:12 bluhm Exp $ +# $OpenBSD: Makefile,v 1.8 2020/12/25 14:25:58 bluhm Exp $ # The following ports must be installed: # -# python-2.7 interpreted object-oriented programming language # scapy powerful interactive packet manipulation in python RTABLE ?= 1 @@ -20,7 +19,7 @@ INTERFACES != sh -c "ifconfig ${PAIR1} 2>/dev/null; \ .if ! exists(/usr/local/bin/python2) || ! exists(/usr/local/bin/scapy) regress: - @echo install python and the scapy module for additional tests + @echo Install py3-scapy package to run this regress. @echo SKIPPED .endif @@ -38,9 +37,9 @@ regress: # Set variables so that make runs with and without obj directory. # Only do that if necessary to keep visible output short. .if ${.CURDIR} == ${.OBJDIR} -PYTHON = python2.7 -B -u ./ +PYTHON = python3 -B -u ./ .else -PYTHON = python2.7 -B -u ${.CURDIR}/ +PYTHON = python3 -B -u ${.CURDIR}/ .endif REGRESS_SETUP += setup diff --git a/regress/sbin/slaacd/Slaacctl.py b/regress/sbin/slaacd/Slaacctl.py index 0eb42996003..7a290006e0a 100644 --- a/regress/sbin/slaacd/Slaacctl.py +++ b/regress/sbin/slaacd/Slaacctl.py @@ -1,5 +1,7 @@ -# $OpenBSD: Slaacctl.py,v 1.2 2019/12/27 09:17:07 florian Exp $ +# $OpenBSD: Slaacctl.py,v 1.3 2020/12/25 14:25:58 bluhm Exp $ + # Copyright (c) 2017 Florian Obser <florian@openbsd.org> +# Copyright (c) 2020 Alexander Bluhm <bluhm@openbsd.org> # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above @@ -32,7 +34,7 @@ class ShowInterface(object): self.def_router_proposals = [] self.rdns_proposals = [] self.out = subprocess.check_output(['slaacctl', '-s', self.sock, - 'sh', 'in', self.ifname]) + 'sh', 'in', self.ifname], encoding='UTF-8') self.parse(self.out) def __str__(self): @@ -57,10 +59,10 @@ class ShowInterface(object): addr_proposal = None def_router_proposal = None rdns_proposal = None - lines = str.split("\n") + lines = str.splitlines() for line in lines: if self.debug == 1: - print line + print(line) if re.match("^\s*$", line): pass elif state == 'START': diff --git a/regress/sbin/slaacd/process_ra.py b/regress/sbin/slaacd/process_ra.py index 5ee501b95f5..bc14855b63b 100644 --- a/regress/sbin/slaacd/process_ra.py +++ b/regress/sbin/slaacd/process_ra.py @@ -1,3 +1,6 @@ +#!/usr/local/bin/python3 +# $OpenBSD: process_ra.py,v 1.3 2020/12/25 14:25:58 bluhm Exp $ + from IfInfo import IfInfo from Slaacctl import ShowInterface import subprocess @@ -5,7 +8,6 @@ import sys from scapy.all import * import unittest - rtadv_if = IfInfo(sys.argv[1]) slaac_if = IfInfo(sys.argv[2]) sock = sys.argv[3] @@ -26,7 +28,6 @@ sendp(p, iface=rtadv_if.ifname, verbose=0) slaac_show_interface = ShowInterface(slaac_if.ifname, sock, debug=0) - class TestRouterAdvertisementParsing(unittest.TestCase): def test_number_ras(self): self.assertEqual(len(slaac_show_interface.RAs), 1) @@ -50,5 +51,5 @@ if __name__ == '__main__': suite = unittest.TestLoader().loadTestsFromTestCase( TestRouterAdvertisementParsing) if not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful(): - print slaac_show_interface + print(slaac_show_interface) sys.exit(1) diff --git a/regress/sbin/slaacd/sniff_sol.py b/regress/sbin/slaacd/sniff_sol.py index 649b6381e55..0a04005e412 100644 --- a/regress/sbin/slaacd/sniff_sol.py +++ b/regress/sbin/slaacd/sniff_sol.py @@ -1,6 +1,6 @@ -#!/usr/local/bin/python2.7 +#!/usr/local/bin/python3 +# $OpenBSD: sniff_sol.py,v 1.2 2020/12/25 14:25:58 bluhm Exp $ -# $OpenBSD: sniff_sol.py,v 1.1 2017/08/25 17:02:13 florian Exp $ # Copyright (c) 2017 Florian Obser <florian@openbsd.org> # # Permission to use, copy, modify, and distribute this software for any @@ -57,38 +57,38 @@ executor.join(timeout=30) p = sniffer.p if p is None: - print "no packet sniffed" + print("no packet sniffed") exit(2) if p.type != ETH_P_IPV6: - print "unexpected ethertype: {0}".format(p.type) + print("unexpected ethertype: {0}".format(p.type)) exit(1) if not p.payload.nh in ipv6nh or ipv6nh[p.payload.nh] != 'ICMPv6': - print "unexpected next header: {0}".format(p.payload.nh) + print("unexpected next header: {0}".format(p.payload.nh)) exit(1) if p[IPv6].hlim != 255: - print "invalid hlim: {0}".format(p[IPv6].hlim) + print("invalid hlim: {0}".format(p[IPv6].hlim)) exit(1) if p[IPv6].dst != 'ff02::2': - print "invalid IPv6 destination: {0}".format(p[IPv6].dst) + print("invalid IPv6 destination: {0}".format(p[IPv6].dst)) exit(1) if 'ICMPv6ND_RS' not in p[IPv6]: - print "no router solicitation found" + print("no router solicitation found") exit(1) if 'ICMPv6NDOptSrcLLAddr' not in p[IPv6][ICMPv6ND_RS]: - print "no Source Link-Layer Address option" + print("no Source Link-Layer Address option") exit(1) if p[Ether].src != p[IPv6][ICMPv6ND_RS].lladdr: - print "src mac ({0}) != lladdr option ({0})".format(p[Ether].src, - p[IPv6][ICMPv6ND_RS].lladdr) + print("src mac ({0}) != lladdr option ({0})".format(p[Ether].src, + p[IPv6][ICMPv6ND_RS].lladdr)) exit(1) -print "received router solicitation" +print("received router solicitation") exit(0) |